aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-10-31 12:43:59 -0400
committerAlexander Pickering <alex@cogarr.net>2018-10-31 12:43:59 -0400
commit9e9be703c8f1c58c76fd2051dd6fa6ce49a7a306 (patch)
tree4df0478902e8653e91139764d5964831dcb9b525
parent6e5697a125973bca83d368364e088777d23f824a (diff)
downloadbrokengine-9e9be703c8f1c58c76fd2051dd6fa6ce49a7a306.tar.gz
brokengine-9e9be703c8f1c58c76fd2051dd6fa6ce49a7a306.tar.bz2
brokengine-9e9be703c8f1c58c76fd2051dd6fa6ce49a7a306.zip
Started on unit tests
Added a GAME.exit() function Added some bare bones unit tests
-rw-r--r--busted.spec37
-rw-r--r--spec/headless/deviceinit.lua92
-rw-r--r--spec/headless/init.lua2
-rw-r--r--spec/test1_spec.lua58
-rw-r--r--src/client/lua_api/load_game.cpp13
5 files changed, 202 insertions, 0 deletions
diff --git a/busted.spec b/busted.spec
new file mode 100644
index 0000000..9399ee4
--- /dev/null
+++ b/busted.spec
@@ -0,0 +1,37 @@
+
+local function create_test_file(str)
+
+end
+
+describe("brokengine",function()
+ describe("gui library",function()
+ for k,v in pairs({
+ "button",
+ "checkbox",
+ "colorselector",
+ "combobox",
+ "contextmenu",
+ "editbox",
+ "fileopen",
+ "image",
+ "imagelist",
+ "inoutfader",
+ "listbox",
+ "meshviewer",
+ "scrollbar",
+ "spinbox",
+ "statictext",
+ "tab",
+ "tabcontrol",
+ "table",
+ "toolbar",
+ "treeview",
+ "treeviewnode",
+ "window"
+ }) do
+ it(string.format("should be able to create a %s",v),function()
+
+ end)
+ end
+ end)
+end)
diff --git a/spec/headless/deviceinit.lua b/spec/headless/deviceinit.lua
new file mode 100644
index 0000000..7e913cd
--- /dev/null
+++ b/spec/headless/deviceinit.lua
@@ -0,0 +1,92 @@
+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
new file mode 100644
index 0000000..86425cd
--- /dev/null
+++ b/spec/headless/init.lua
@@ -0,0 +1,2 @@
+assert(scrh)
+GAME.exit()
diff --git a/spec/test1_spec.lua b/spec/test1_spec.lua
new file mode 100644
index 0000000..bcb5756
--- /dev/null
+++ b/spec/test1_spec.lua
@@ -0,0 +1,58 @@
+print("Hello, world!")
+
+function rungame()
+ f = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r")
+ d = f:read("*all")
+ f:close()
+ return d
+end
+
+function writegame(...)
+ f = io.open("spec/headless/init.lua","w")
+ data = {...}
+ data[#data + 1] = "\nGAME.exit()\n"
+ f:write(table.concat(data))
+ f:close()
+end
+
+function assert_game_runs()
+ assert.truthy(rungame():find("\nGoodbye\n$"))
+end
+
+describe("Brok[en]gine",function()
+ it("should run",function()
+ writegame()
+ d = rungame()
+ assert_game_runs()
+ end)
+ it("should provide a lua environment",function()
+ writegame("print(\"Hello from lua!\")")
+ d = rungame()
+ assert.truthy(d:find("\nHello from lua!\n"))
+ end)
+
+ 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
+ it("should provide functions to make gui " .. k,function()
+ writegame("assert(gui." .. v .. ")")
+ assert_game_runs()
+ end)
+ end
+
+ it("should provide functions to get the width and height of the screen",function()
+ writegame("assert(scrw)")
+ assert_game_runs()
+ writegame("assert(scrh)")
+ assert_game_runs()
+ end)
+end)
diff --git a/src/client/lua_api/load_game.cpp b/src/client/lua_api/load_game.cpp
index 92cb2d5..469b219 100644
--- a/src/client/lua_api/load_game.cpp
+++ b/src/client/lua_api/load_game.cpp
@@ -18,7 +18,20 @@ using namespace irr;
using namespace gui;
using namespace core;
+extern IrrlichtDevice* device;
+
+//exit()
+int exit_game(lua_State *L){
+ device->closeDevice();
+ return 0;
+}
+
void load_gamefuncs(lua_State* L){
lua_newtable(L);
lua_setglobal(L,"GAME");
+
+ lua_getglobal(L,"GAME");
+ lua_pushcfunction(L,exit_game);
+ lua_setfield(L,-2,"exit");
+ lua_pop(L,1);
}