--do return end --local test = require("u-test") if not package.path:find("spec/%?%.lua;") then print("including spec") package.path = "./spec/?.lua;" .. package.path end local common = require("common") _G.assert = assert describe("gui library", 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 it("should have a function to create " .. k,function() common.writegame("assert(gui." .. v .. ")") common.assert_game_runs() end) end it("should have a function to check the screen's width",function() common.writegame("assert(scrw)") common.assert_game_runs() end) it("should have a function to check the screen's height", function() common.writegame("assert(scrh)") common.assert_game_runs() end) end) local protocols = { "PAIR", "BUS", "PUB", "SUB", "PULL", "PUSH", "REQ", "REP", "RESPOND", "SURVEY" } describe("network library",function() for _,v in pairs(protocols) do it("should have a constant for the " .. v .. " protocol",function() common.writegame(string.format("assert(net.%s)",v)) common.assert_game_runs() end) end it("should have a function to create a new socket",function() common.writegame("assert(net.newsocket)") common.assert_game_runs() end) for _,v in pairs(protocols) do for _,j in pairs{"bind","connect","send"} do it(string.format("should be able to create a %s socket with a %s method",v,j)) common.writegame(string.format([[ local socket = net.newsocket(net.%s) assert(socket.%s) assert(type(socket.%s) == "function") ]],v,j,j)) common.assert_game_runs() end end it("should be able to set up a PAIR connection and send data through #smoke",function() common.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 local i = os.time() local game_exit = GAME.exit function GAME.tick() if has_ponged then game_exit() end if i - os.time() > 5 then error("Failed") end end GAME.exit = function(...) end -- only exit when we pong, not before. ]]) common.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) ]]) common.assert_both_run() end) end)