aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/headless/deviceinit.lua92
-rw-r--r--spec/headless/init.lua2
-rw-r--r--spec/test1_spec.lua5
-rw-r--r--spec/test2_spec.lua195
-rw-r--r--spec/test3_spec.lua86
5 files changed, 285 insertions, 95 deletions
diff --git a/spec/headless/deviceinit.lua b/spec/headless/deviceinit.lua
deleted file mode 100644
index 7e913cd..0000000
--- a/spec/headless/deviceinit.lua
+++ /dev/null
@@ -1,92 +0,0 @@
-print("device init called")
-return {
- --[[
- Anti-Alias
- Should the window use fullscreen anti aliasing
- Default:16
- ]]
- ["Anti Alias"] = 16,
- --[[
- Bits Per Pixel
- The minimum bits per pixel of the color buffer in fullscreen. Ignored in window mode.
- Default:16
- ]]
- ["Bits Per Pixel"] = 16,
- --[[
- Device Type
- Options:
- WIN32 - Only avaliable on windows desktops
- WINCE - Only avaliable on windows mobile
- COCOA - Only avaliable on OSX
- X11 - Avaliable on Linux, Solaris, BSD, anyone that uses X11
- SDL - Avaliable on most systems
- CONSOLE - Usually avaliable, but can only render text
- BEST - Automatically choose the best device.
- Default:Best
- ]]
- ["Device Type"] = "BEST",
- --[[
- Display Adapter
- Pick which graphics card is used for rendering when there is more than one.
- Default:0
- ]]
- ["Display Adapter"] = 0,
- --[[
- Double Buffer
- Should the window use doublebuffering?
- Default:false
- ]]
- ["Double Buffer"] = true,
- --[[
- Multithreaded
- Should the display use multiple threads?
- Default:false
- ]]
- ["Multithreaded"] = false,
- --[[
- Driver Type
- The video driver used to render graphics
- Options:
- NULL - You probably don't want this one
- SOFTWARE - Donate your computer to a mueseum
- BURNINGS - a software alternative
- D3D8 - Direct 3D 8 Win32 only
- D3D9 - Direct 3D 9 Win32 only
- OPENGL - Open GL
- (vulkan support comming soon... maybe.)
- Default:OPENGL
- ]]
- ["Driver Type"] = "NULL",
- --[[
- Fullscreen
- Should the window be fullscreen?
- Default:false
- ]]
- ["Fullscreen"] = false,
- --[[
- Stencil buffer
- Should the stencil buffer be enabled?
- Default:false
- ]]
- ["Stencil Buffer"] = true,
- --[[
- Stereo Buffer
- Should the window use stereo buffers?
- Default:false
- ]]
- ["Stereo Buffer"] = false,
- --[[
- Vertical Sync
- Should the frame wait to be displayed to screen before starting the next draw?
- Enable this if you are getting graphical artifacts
- Default:false
- ]]
- ["VSync"] = true,
- --[[
- Window Width/height
- Adjusts the size of the window.
- Default: 640,480
- ]]
- ["Window Width"] = 640,
- ["Window Height"] = 480,
-}
diff --git a/spec/headless/init.lua b/spec/headless/init.lua
deleted file mode 100644
index 86425cd..0000000
--- a/spec/headless/init.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-assert(scrh)
-GAME.exit()
diff --git a/spec/test1_spec.lua b/spec/test1_spec.lua
index bcb5756..9844204 100644
--- a/spec/test1_spec.lua
+++ b/spec/test1_spec.lua
@@ -9,7 +9,10 @@ end
function writegame(...)
f = io.open("spec/headless/init.lua","w")
- data = {...}
+ data = {"GAME.crashy()"}
+ for _,v in pairs({...}) do
+ data[#data + 1] = v
+ end
data[#data + 1] = "\nGAME.exit()\n"
f:write(table.concat(data))
f:close()
diff --git a/spec/test2_spec.lua b/spec/test2_spec.lua
new file mode 100644
index 0000000..6b90878
--- /dev/null
+++ b/spec/test2_spec.lua
@@ -0,0 +1,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()
diff --git a/spec/test3_spec.lua b/spec/test3_spec.lua
new file mode 100644
index 0000000..e30a0ca
--- /dev/null
+++ b/spec/test3_spec.lua
@@ -0,0 +1,86 @@
+
+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()
+ --print("Running both")
+ f1 = io.popen("bin\\server\\bin\\brokengine_server.exe spec/server","r")
+ f2 = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r")
+ --print("Both ran...")
+ d1 = f1:read("*all")
+ d2 = f2:read("*all")
+ --print("Both read all")
+ f1:close()
+ f2:close()
+ --print("returning")
+ 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()
+ assert.is_not_nil(a:find("\nGoodbye\n$"))
+ assert.is_not_nil(b:find("\nGoodbye\n$"))
+end
+describe("networking",function()
+ it("should communicate with PAIR sockets",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
+ ]])
+ --print("writing game...")
+ 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)
+ ]])
+ --print("asserting both run...")
+ assert_both_run()
+ end)
+end)