1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
do return end
local test = require("u-test")
function rungame()
f = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r")
d = f:read("*all")
f:close()
return d
end
function runboth()
f1 = io.popen("bin\\server\\bin\\brokengine_server.exe spec/server","r")
f2 = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r")
d1 = f1:read("*all")
d2 = f2:read("*all")
f1:close()
f2:close()
return d1, d2
end
function writegame(...)
f = io.open("spec/headless/init.lua","w")
data = {"GAME.crashy()"}
for _,v in pairs({...}) do
data[#data + 1] = v
end
data[#data + 1] = "\nGAME.exit()\n"
f:write(table.concat(data,"\n"))
f:close()
end
function writeserver(...)
f = io.open("spec/server/init.lua","w")
data = {...}
--data[#data + 1] = "\nGAME.exit()\n"
f:write(table.concat(data,"\n"))
f:close()
end
function assert_game_runs()
test.is_not_nil(rungame():find("\nGoodbye\n$"))
end
function assert_both_run()
local a,b = runboth()
test.is_not_nil(a:find("\nGoodbye\n$"))
test.is_not_nil(b:find("\nGoodbye\n$"))
end
test.game_runs = function()
writegame("")
assert_game_runs()
end
test.gui.elements_exist = function()
for k,v in pairs({
buttons = "newbutton",
checkboxes = "newcheckbox",
colorselectors = "newcolorselector",
editboxes = "neweditbox",
openfiledialogs = "newfileopendialog",
images = "newiguiimage",
labels = "newlabel",
spinboxes = "newspinbox",
treeviews = "newtreeview",
windows = "newwindow",
}) do
writegame("assert(gui." .. v .. ")")
assert_game_runs()
end
end
test.gui.screen_functions = function()
writegame("assert(scrw)")
assert_game_runs()
writegame("assert(scrh)")
assert_game_runs()
end
--#define PAIR 1
--#define BUS 2
--#define PUB 3
--#define SUB 4
--#define PULL 5
--#define PUSH 6
--#define REQ 7
--#define REP 8
--#define RESPOND 9
--#define SURVEY 10
local protocols = {
"PAIR", "BUS", "PUB", "SUB", "PULL", "PUSH", "REQ", "REP", "RESPOND", "SURVEY"
}
test.net.protocols_exist = function()
for k,v in pairs(protocols) do
writegame(string.format("assert(net.%s)",v))
assert_game_runs()
end
end
for _,sockettype in pairs(protocols) do
for _,func in pairs({
"bind","connect","send"
}) do
test.net[sockettype .. "_socket_has_" .. func .. "_function"] = function()
writegame(string.format([[
local socket = net.newsocket(net.%s)
assert(socket.%s)
assert(type(socket.%s) == "function")
]],sockettype,func,func))
assert_game_runs()
end
end
end
--test.net.functions_exist = function()
--writegame("assert(net.newsocket and type(net.newsocket == 'function'))")
--assert_game_runs()
--for _,sockettype in pairs(protocols) do
--for _,func in pairs({
--}) do
--writegame(string.format([[
--local socket = net.newsocket(net.%s)
--assert(socket.%s)
--assert(type(socket.%s) == "function")
--]],sockettype,func,func))
--assert_game_runs()
--end
--end
--end
test.net.protocol_pair = function()
writeserver([[
local has_ponged = false
local socket = net.newsocket(net.PAIR)
socket:bind("tcp://127.0.0.1:5555")
function socket:receive(stream)
print("Socket receive triggered")
has_ponged = true
local message = stream:readstring()
assert(message == "ping")
socket:send(function(stream2)
stream2:writestring("pong")
end)
end
function GAME.tick()
if has_ponged then
GAME.exit()
end
end
]])
writegame([[
local socket = net.newsocket(net.PAIR)
socket:connect("tcp://127.0.0.1:5555")
function socket:receive(stream)
local message = stream:readstring()
assert(message == "pong")
end
socket:send(function(stream)
stream:writestring("ping")
end)
]])
assert_both_run()
end
--test.net.protocol_pubsub = function()
--writeserver([[
--local counter = 0
--local max_count = 10000 --How long to live for,
----since we can't detect when the user
----sends the message
--local socket = net.newsocket(net.PUB)
--socket:bind("tcp://127.0.0.1:5555")
--function GAME.tick()
--if counter < max_count then
--counter = counter + 1
--socket:send(function(stream)
--stream:writestring("ping")
--end)
--else
--GAME.exit()
--end
--end
--]])
--writegame([[
--local socket = net.newsocket(net.SUB)
--socket:connect("tcp://127.0.0.1:5555")
--local oldgameexit = GAME.exit
--socket:receive(function(stream)
--assert(stream:readstring() == "ping")
--oldgameexit()
--end)
--function GAME.exit() return end --Stop the client from exiting
--]])
--end
test.summary()
|