BTD
build-test-deploy Development Environment

Best practices

Complete example TestIupRobot can be called from the console (and from the appropriate directory as lua test.lua TestIupRobot.
local test = require('btd.lua.testapi')
local testIup = require('btd.lua.testiup')
local IupRobot = require('btd.lua.iuprobot')
local GuiSequencer = require('btd.lua.guisequencer')

local robot = IupRobot(0.02,0.1)    -- 20 ms update interval and 100 ms event queue wait time
robot.demo = true                   -- visual feedback on

TestIupRobot = {}

-- only allow one instance of IUP at any one time
-- (or mark required test methods individually, see unit testing)
TestIupRobot.Serial = true

-- (optional) abort test class if one (serialised) test method fails
TestIupRobot.Abort = true

function TestIupRobot:setUp()
  dofile('iupbutton.wlua')
end

function TestIupRobot:test_click()
  local seq = GuiSequencer()
  -- go from current cursor position to button in 2 s, print (on console) a confirmation message and wait 5 s
  seq:append({robot.gotoCenter,robot,button,2},{nil,print,'cursor should be above button'},{robot.timer,robot,5})
  -- click button during 1 s, print (on console) a confirmation message, wait 5 s and test will terminate
  seq:append({robot.leftClick,robot,1},{nil,print,'button should have been clicked'},{robot.timer,robot,5})
  local function idleLoop()
    return function()
      if seq:execute() then
        if seq.step == 1 and seq.ok then
          -- here, code to be executed after finishing step 1 of sequence
          -- WILL ONLY BE ACTIVE FOR ONE IDLE LOOP SCAN !!!
          test.equals(2,2) -- obviously
        elseif seq.step == 2 and seq.ok then
          -- here, code to be executed after finishing step 1 of sequence
          -- WILL ONLY BE ACTIVE FOR ONE IDLE LOOP SCAN !!!
          test.equals(1,3) -- is this correct ?
          -- test.equals(3,3) -- this is correct
        end
        -- while the GUI should remain active
        return iup.DEFAULT
      else
        -- end the GUI
        return iup.CLOSE
      end
    end
  end
  -- any test initialisation code here
  print('testing will start')
  test.equals(1,1) -- obviously
  -- start GUI idle loop
  testIup.iupLoop(idleLoop())
  -- any test clean up or final results (will only be evaluatied if 'test.equals(1,3' is 'corrected'
  print('testing has ended')
end