Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes outdated interactive tests #277

Merged
merged 1 commit into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/interactive/canvasresize/canvasresize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ end

function canvasresize_input(iotbl)
if (iotbl.kind == "digital" and iotbl.active) then
if (keysym[iotbl.keysym] == "F1") then
local label = keysym.tolabel(iotbl.keysym)
if (label == "F1") then
resize_video_canvas(VRESW * 2, VRESH * 2);
b = fill_surface(200, 200, 0, 255, 0);
show_image(b);
move_image(b, VRESW, VRESH, 200);
elseif (keysym[iotbl.keysym] == "F2") then
elseif (label == "F2") then
zap_resource("test.png");
save_screenshot("test.png", 1, WORLDID);
end
Expand Down
3 changes: 2 additions & 1 deletion tests/interactive/eventtest/eventtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ function digital_str(iotbl)
end

function translate_str(iotbl)
local label = symtable.tolabel(iotbl.keysym)
table.insert(translatetbl, string.format("dev(%d:%d)%d[%s] => %s, %s, %s, %s",
iotbl.devid, iotbl.subid, iotbl.number,
table.concat(decode_modifiers(iotbl.modifiers),","),
iotbl.keysym, iotbl.active and "press" or "release",
symtable[iotbl.keysym] and symtable[iotbl.keysym] or "_nil",
label or "_nil",
iotbl.utf8)
);

Expand Down
20 changes: 13 additions & 7 deletions tests/interactive/failover/failover.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
function failover()
a = list_games({})
symtbl = system_load("builtin/keyboard.lua")();

a = list_targets();

if (#a == 0) then
return shutdown("no targets found, can not run the test");
end

system_context_size(10);
pop_video_context();

fsrvs = {};

for i=1,2 do
local vid = launch_target(
a[math.random(#a)].gameid, LAUNCH_INTERNAL, cb);
a[math.random(#a)], LAUNCH_INTERNAL, cb);
table.insert(fsrvs, vid);
print(#fsrvs);
end
Expand Down Expand Up @@ -59,24 +64,25 @@ function failover_adopt(id)
end

function failover_input(iotbl)
local label = symtbl.tolabel(iotbl.keysym)
if (iotbl.kind == "digital" and iotbl.translated and iotbl.active) then
if (symtbl[iotbl.keysym] == "1") then
if (label == "1") then
local img = color_surface(32, 32,
math.random(127) + 127, math.random(127) + 127, 0);
show_image(img);
move_image(img, math.random(VRESW), math.random(VRESH));

elseif (symtbl[iotbl.keysym] == "2") then
elseif (label == "2") then
print("request collapse");
x_p = 0;
y_p = 0;
fsrvs = {};
system_collapse();
elseif (symtbl[iotbl.keysym] == "3") then
elseif (label == "3") then
system_collapse("failadopt");
elseif (symtbl[iotbl.keysym] == "4") then
elseif (label == "4") then
this_should_trigger_perror();
elseif (symtbl[iotbl.keysym] == "5") then
elseif (label == "5") then
print("pacify", #fsrvs);
for i=1,#fsrvs do
target_pacify(fsrvs[i]);
Expand Down
25 changes: 13 additions & 12 deletions tests/interactive/imagetest/imagetest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,46 +121,47 @@ end

function imagetest_input(inputtbl)
if (inputtbl.kind == "digital" and inputtbl.translated and inputtbl.active) then
if (symtable[ inputtbl.keysym ] == "ESCAPE") then
local label = symtable.tolabel(inputtbl.keysym)
if (label == "ESCAPE") then
shutdown();
elseif (symtable[ inputtbl.keysym ] == "1") then
elseif (label == "1") then
print("Running instancing test");
instancing_test();
elseif (symtable[ inputtbl.keysym ] == "2") then
elseif (label == "2") then
print("Running Z order/limit test");
zordervidlim(false);
elseif (symtable[ inputtbl.keysym ] == "3") then
elseif (label == "3") then
print("Running image loading stress");
zordervidlim(true);
elseif (symtable[ inputtbl.keysym ] == "4") then
elseif (label == "4") then
print("Double stacksize for next layer");
stacksize = stacksize * 2;
system_context_size(stacksize);
elseif (symtable[ inputtbl.keysym ] == "l") then
elseif (label == "l") then
print("Loading image into context");
local vid = imagefun("imagetest.png");
resize_image(vid, 64, 64);
move_image(vid, math.random(VRESW - 64), math.random(VRESH - 64), 0);
order_image(vid, 0);
show_image(vid);
elseif (symtable[ inputtbl.keysym ] == "s") then
elseif (label == "s") then
text_vid = BADID;
print("Stack push => " .. tostring ( push_video_context() ) );
elseif (symtable[ inputtbl.keysym ] == "d") then
elseif (label == "d") then
num, vid = storepush_video_context();
show_image(vid);

print("Stack push store => " .. tostring(num) .. " => " .. tostring(vid));
elseif (symtable[ inputtbl.keysym ] == "f") then
elseif (label == "f") then
num, vid = storepop_video_context();
show_image(vid);
print("Stack pop store => " .. tostring(num) .. " => " .. tostring(vid));
elseif (symtable[ inputtbl.keysym ] == "p") then
elseif (label == "p") then
print("Stack pop => " .. tostring ( pop_video_context() ) );
elseif (symtable[inputtbl.keysym] == "a") then
elseif (label == "a") then
print("Switching image mode\n");
imagefun = imagefun == load_image and load_image_asynch or load_image
elseif (symtable[inputtbl.keysym] == "r") then
elseif (label == "r") then
local tbl = {};
for i=1,(256 * 256) do
table.insert(tbl, math.random(255));
Expand Down
13 changes: 7 additions & 6 deletions tests/interactive/kbdtest/kbdtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ end

function kbdtest_input(inp)
if (inp.translated and inp.active) then
local label = symtable.tolabel(inp.keysym)
last_event = 500;
table.insert(history, {
CLOCK, inp.devid, inp.subid, inp.keysym,
symtable[inp.keysym] and symtable[inp.keysym] or ""
label or ""
}
);
if (#history > 10) then
Expand All @@ -72,15 +73,15 @@ function kbdtest_input(inp)
upd_period();
end

if (symtable[inp.keysym] == "F1") then
if (label == "F1") then
uprd(-per, -del);
elseif (symtable[inp.keysym] == "F2") then
elseif (label == "F2") then
uprd(20, 0);
elseif (symtable[inp.keysym] == "F3") then
elseif (label == "F3") then
uprd(-20, 0);
elseif (symtable[inp.keysym] == "F4") then
elseif (label == "F4") then
uprd(0, 20);
elseif (symtable[inp.keysym] == "F5") then
elseif (label == "F5") then
uprd(0, -20);
end
end
Expand Down
13 changes: 7 additions & 6 deletions tests/interactive/mdispcl/mdispcl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ end
--
-- Event callback for display configuration hotplug
--
function mdispcl_display_state(state, arg)
function mdispcl_display_state(state, displayid)
if (state == "added") then
table.insert(active_displays, arg[1].displayid);
map_video_display(WORLDID, arg[1].displayid);
table.insert(active_displays, displayid);
map_video_display(WORLDID, displayid);

elseif (state == "removed") then

for k,v in ipairs(active_displays) do
if (v == arg) then
if (v == displayid) then
table.remove(active_displays, k);
break;
end
Expand All @@ -81,8 +81,9 @@ function mdispcl_display_state(state, arg)
end

function mdispcl_input(iotbl)
local label = symtable.tolabel(iotbl.keysym)
if (iotbl.translated and iotbl.active and
dispatch[symtable[iotbl.keysym]]) then
dispatch[symtable[iotbl.keysym]]();
dispatch[label]) then
dispatch[label]();
end
end
9 changes: 5 additions & 4 deletions tests/interactive/mdispwm/mdispwm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ meta_key = "LCTRL";

function mdispwm()
system_load("scripts/composition_surface.lua")();
system_load("scripts/mouse.lua")();
system_load("builtin/mouse.lua")();
symtable = system_load("builtin/keyboard.lua")();

-- ugly red square as mouse cursor
Expand Down Expand Up @@ -125,20 +125,21 @@ function mdispwm_input(iotbl)
end

elseif (iotbl.translated) then
local label = symtable.tolabel(iotbl.keysym)
-- propagate meta-key state (for resize / drag / etc.)
if (symtable[ iotbl.keysym ] == meta_key) then
if (label == meta_key) then
wm.meta = iotbl.active and true or nil;

-- spawn a random color surface for testing
elseif (symtable[ iotbl.keysym ] == "F11" and iotbl.active) then
elseif (label == "F11" and iotbl.active) then
surf = color_surface(128, 128, math.random(128)+127,
math.random(128)+127, math.random(128)+127);

local wnd = wm:add_window(surf, {});
wnd:set_border(1);

-- delete the selected window
elseif (symtable[ iotbl.keysym ] == "DELETE" and
elseif (label == "DELETE" and
wm.meta == true and wm.selected and iotbl.active) then

wm.selected:destroy();
Expand Down
13 changes: 7 additions & 6 deletions tests/interactive/movietest/movietest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ end
function movietest_input( inputtbl )

if (inputtbl.kind == "digital" and inputtbl.translated and inputtbl.active) then
if (symtable[ inputtbl.keysym ] == "d") then
local label = symtable.tolabel(inputtbl.keysym)
if (label == "d") then

elseif (symtable[ inputtbl.keysym ] == "s") then
elseif (label == "s") then
vid, aid = launch_decode("movietest.avi");
img.last = vid;
move_image(vid, cursor.x, cursor.y);
show_image(vid);

elseif (symtable[ inputtbl.keysym ] == "p") then
elseif (label == "p") then
pause_movie(img.last);

elseif (symtable[ inputtbl.keysym ] == "w") then
elseif (label == "w") then
width = 128 + math.random(1024);
height = 128 + math.random(1024);
print("Requesting:", "capture:" .. webcam_ind, tostring(width) .. "x" .. tostring(height));
Expand All @@ -100,9 +101,9 @@ end );
move_image(vid, cursor.x, cursor.y);
show_image(vid);

elseif (symtable[ inputtbl.keysym] == "r") then
elseif (label == "r") then
resume_movie(img.last);
elseif (symtable[ inputtbl.keysym] == "ESCAPE") then
elseif (label == "ESCAPE") then
shutdown();
end

Expand Down
2 changes: 1 addition & 1 deletion tests/interactive/outputs/outputs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function outputs()
end

function outputs_input(iotbl)
local sym = symtable[iotbl.keysym];
local sym = symtable.tolabel(iotbl.keysym);
if (iotbl.active and sym and sym == " ") then
modes[mode_ind](false);
mode_ind = mode_ind + 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/interactive/picktest/picktest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function picktest_input(iotbl)
print("done\n");
elseif (iotbl.kind == "digital") then
if (iotbl.translated) then
local sym = symtable[iotbl.keysym];
local sym = symtable.tolabel(iotbl.keysym);

if (iotbl.active) then
if (sym == "UP") then
Expand Down
5 changes: 3 additions & 2 deletions tests/interactive/rtdensity/rtdensity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ end
delta = 0;
function rtdensity_input(iotbl)
if (iotbl.digital and iotbl.active) then
if (iotbl.translated and symtable[iotbl.keysym]) then
if (symtable[iotbl.keysym] == "m") then
local label = symtable.tolabel(iotbl.keysym)
if (iotbl.translated and label) then
if (label == "m") then
print("switching to 1");
local lst = rendertarget_vids(rt_2);
for k,v in ipairs(lst) do
Expand Down
10 changes: 5 additions & 5 deletions tests/interactive/scan/scan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end

function scan_input(iotbl)
if (iotbl.translated and iotbl.active) then
local sym = symtable[iotbl.keysym];
local sym = symtable.tolabel(iotbl.keysym);
if (sym == "F1") then
local modes = video_displaymodes(0);
mode = modes[math.random(1, #modes)];
Expand Down Expand Up @@ -68,9 +68,9 @@ function scan_input(iotbl)
end
end

function scan_display_state(a, b)
if (a == "added") then
video_displaymodes(b[1].displayid, b[1].modeid);
map_video_display(WORLDID, b[1].displayid);
function scan_display_state(event, displayid)
if (event == "added") then
video_displaymodes(displayid);
map_video_display(WORLDID, displayid);
end
end
7 changes: 4 additions & 3 deletions tests/interactive/segtest/segtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ end

function segtest_input(iotbl)
if (iotbl.kind == "digital" and iotbl.active) then
if (symtable[iotbl.keysym] == "F10") then
local label = symtable.tolabel(iotbl.keysym)
if (label == "F10") then
print("dropping main seg");
delete_image(test);
elseif(symtable[iotbl.keysym] == "F9") then
elseif(label == "F9") then
print("dropping alt seg");
delete_image(newvid);
elseif (symtable[iotbl.keysym] == "F8") then
elseif (label == "F8") then
target_alloc("mykey", seg2);
else
print("input to:", newvid);
Expand Down
6 changes: 3 additions & 3 deletions tests/interactive/soundtest/soundtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end

function soundtest_input( inputtbl )
if (inputtbl.kind == "digital" and inputtbl.active and inputtbl.translated) then
local sym = symtable[ inputtbl.keysym ]
local sym = symtable.tolabel(inputtbl.keysym)
local num = tonumber(sym)

if num and tones[num] then
Expand All @@ -97,7 +97,7 @@ function soundtest_input( inputtbl )
print("play", playback)
play_audio(playback, 1.0, queue_next)

elseif (symtable[ inputtbl.keysym ] == "f") then
elseif (sym == "f") then
if (sample_countdown > 0) then
sample_countdown = 0;
print("disabling sample spam");
Expand All @@ -106,7 +106,7 @@ function soundtest_input( inputtbl )
sample_countdown = 15;
end

elseif (symtable[ inputtbl.keysym ] == "ESCAPE") then
elseif (sym == "ESCAPE") then
shutdown();
end
end
Expand Down
2 changes: 1 addition & 1 deletion tests/interactive/switcher/switcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end

function switcher_input(iotbl)
if (iotbl.translated) then
local key = symtable [ iotbl.keysym ]
local key = symtable.tolabel(iotbl.keysym)
local num = tonumber(key)
if (num and list[num]) then
pop_video_context()
Expand Down