From 01cb132cac0e46f129a3c65f6dabbae9e05dd4e7 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sat, 21 Jul 2012 16:25:33 +0200 Subject: [PATCH] Integration/regression testing for mod_xrandr --- test/integration/runtests.lua | 4 +- test/integration/xinerama/02_removed_display.lua | 4 +- test/integration/xrandr/.fakexinerama | 3 + test/integration/xrandr/.notion/cfg_notion.lua | 105 +++++++++++++++++++++ .../integration/xrandr/.notion/mod_xrandr_mock.lua | 41 ++++++++ test/integration/xrandr/01_remove_display.lua | 37 ++++++++ test/integration/xrandr/02_removed_display.lua | 16 ++++ test/integration/xrandr/03_new_screen_has_ws.lua | 20 ++++ test/integration/xrandr/fakexinerama-1monitor | 2 + test/integration/xrandr/fakexinerama-2monitors | 3 + 10 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 test/integration/xrandr/.fakexinerama create mode 100644 test/integration/xrandr/.notion/cfg_notion.lua create mode 100644 test/integration/xrandr/.notion/mod_xrandr_mock.lua create mode 100644 test/integration/xrandr/01_remove_display.lua create mode 100644 test/integration/xrandr/02_removed_display.lua create mode 100644 test/integration/xrandr/03_new_screen_has_ws.lua create mode 100644 test/integration/xrandr/fakexinerama-1monitor create mode 100644 test/integration/xrandr/fakexinerama-2monitors diff --git a/test/integration/runtests.lua b/test/integration/runtests.lua index f9c6cf5c..c43bead4 100644 --- a/test/integration/runtests.lua +++ b/test/integration/runtests.lua @@ -23,12 +23,14 @@ sleep(1) print '(Hopefully) started Xdummy.' -local testsets = { 'basic_test', 'xinerama' } +local testsets = { 'basic_test', 'xinerama', 'xrandr' } local errors = 0 for i,testset in ipairs(testsets) do posix.setenv('HOME', testset); + + os.execute("rm -r " .. testset .. "/.notion/default-session--7") print ('Starting notion in ./' .. testset .. '...') local notionpid = posix.fork() diff --git a/test/integration/xinerama/02_removed_display.lua b/test/integration/xinerama/02_removed_display.lua index 15707433..90c2337b 100644 --- a/test/integration/xinerama/02_removed_display.lua +++ b/test/integration/xinerama/02_removed_display.lua @@ -1,7 +1,7 @@ mod_xinerama.refresh(); -if (notioncore.find_screen_id(1) ~= Nil) then - return "New number of screens should be 1, found " .. (notioncore.find_screen_id(1):name()) +if notioncore.find_screen_id(1) then + return "New number of screens should be 1, found ", notioncore.find_screen_id(1):name() end os.execute("cp xinerama/fakexinerama-2monitors xinerama/.fakexinerama"); diff --git a/test/integration/xrandr/.fakexinerama b/test/integration/xrandr/.fakexinerama new file mode 100644 index 00000000..13380fbc --- /dev/null +++ b/test/integration/xrandr/.fakexinerama @@ -0,0 +1,3 @@ +2 +0 0 1280 960 +1280 0 1280 1024 diff --git a/test/integration/xrandr/.notion/cfg_notion.lua b/test/integration/xrandr/.notion/cfg_notion.lua new file mode 100644 index 00000000..41c90e98 --- /dev/null +++ b/test/integration/xrandr/.notion/cfg_notion.lua @@ -0,0 +1,105 @@ +-- +-- Notion main configuration file +-- +-- This file only includes some settings that are rather frequently altered. +-- The rest of the settings are in cfg_notioncore.lua and individual modules' +-- configuration files (cfg_modulename.lua). +-- +-- When any binding and other customisations that you want are minor, it is +-- recommended that you include them in a copy of this file in ~/.notion/. +-- Simply create or copy the relevant settings at the end of this file (from +-- the other files), recalling that a key can be unbound by passing 'nil' +-- (without the quotes) as the callback. For more information, please see +-- the Notion configuration manual available from the Notion Web page. +-- + +-- Set default modifiers. Alt should usually be mapped to Mod1 on +-- XFree86-based systems. The flying window keys are probably Mod3 +-- or Mod4; see the output of 'xmodmap'. +--META="Mod1+" +--ALTMETA="" + +-- Terminal emulator +--XTERM="xterm" + +-- Some basic settings +ioncore.set{ + -- Maximum delay between clicks in milliseconds to be considered a + -- double click. + --dblclick_delay=250, + + -- For keyboard resize, time (in milliseconds) to wait after latest + -- key press before automatically leaving resize mode (and doing + -- the resize in case of non-opaque move). + --kbresize_delay=1500, + + -- Opaque resize? + --opaque_resize=false, + + -- Movement commands warp the pointer to frames instead of just + -- changing focus. Enabled by default. + --warp=true, + + -- Switch frames to display newly mapped windows + --switchto=true, + + -- Default index for windows in frames: one of 'last', 'next' (for + -- after current), or 'next-act' (for after current and anything with + -- activity right after it). + --frame_default_index='next', + + -- Auto-unsqueeze transients/menus/queries. + --unsqueeze=true, + + -- Display notification tooltips for activity on hidden workspace. + --screen_notify=true, + + -- Automatically save layout on restart and exit. + --autosave_layout=true, +} + + +-- Load default settings. The file cfg_defaults loads all the files +-- commented out below, except mod_dock. If you do not want to load +-- something, comment out this line, and uncomment the lines corresponding +-- the the modules or configuration files that you want, below. +-- The modules' configuration files correspond to the names of the +-- modules with 'mod' replaced by 'cfg'. +dopath("cfg_defaults") + +-- Load configuration of the Notion 'core'. Most bindings are here. +--dopath("cfg_notioncore") + +-- Load some kludges to make apps behave better. +--dopath("cfg_kludges") + +-- Define some layouts. +--dopath("cfg_layouts") + +-- Load some modules. Bindings and other configuration specific to modules +-- are in the files cfg_modulename.lua. +--dopath("mod_query") +--dopath("mod_menu") +--dopath("mod_tiling") +--dopath("mod_statusbar") +--dopath("mod_dock") +--dopath("mod_sp") +--dopath("mod_notionflux") +dopath("mod_xrandr") +dopath("mod_xrandr_mock") + +-- +-- Common customisations +-- + +-- Uncommenting the following lines should get you plain-old-menus instead +-- of query-menus. + +--defbindings("WScreen", { +-- kpress(ALTMETA.."F12", "mod_menu.menu(_, _sub, 'mainmenu', {big=true})"), +--}) +-- +--defbindings("WMPlex.toplevel", { +-- kpress(META.."M", "mod_menu.menu(_, _sub, 'ctxmenu')"), +--}) + diff --git a/test/integration/xrandr/.notion/mod_xrandr_mock.lua b/test/integration/xrandr/.notion/mod_xrandr_mock.lua new file mode 100644 index 00000000..f557f375 --- /dev/null +++ b/test/integration/xrandr/.notion/mod_xrandr_mock.lua @@ -0,0 +1,41 @@ +-- overwrite some methods in mod_xrandr to mock it +print('Mocking RandR inplementation') + +local outputOne = { name = 'ONE', x = 0, y = 0, w = 1280, h = 960 } +local outputTwo = { name = 'TWO', x = 1280, y = 0, w = 1280, h = 1024 } + +local n_screens = 2 + +function mod_xrandr.get_outputs(reg) + if reg:geom().x == 0 then + return { ONE = outputOne } + elseif n_screens > 1 then + return { TWO = outputTwo } + else + return {} + end +end + +function mod_xrandr.get_all_outputs() + if n_screens > 1 then + return { ONE = outputOne, TWO = outputTwo } + else + return { ONE = outputOne } + end +end + +function mx_names(mx) + local result = '' + mx:mx_i(function(child) result = result .. child:name() .. ', ' return true end) + return result +end + +mod_xrandr_mock = {} +function mod_xrandr_mock.set_number_of_screens(n) + n_screens = n + if n == 1 then + os.execute("cp xrandr/fakexinerama-1monitor xrandr/.fakexinerama") + else + os.execute("cp xrandr/fakexinerama-2monitors xrandr/.fakexinerama") + end +end diff --git a/test/integration/xrandr/01_remove_display.lua b/test/integration/xrandr/01_remove_display.lua new file mode 100644 index 00000000..f8a556b6 --- /dev/null +++ b/test/integration/xrandr/01_remove_display.lua @@ -0,0 +1,37 @@ +if not notioncore.find_screen_id(0) then + return "Initial number of screens should be 2, first screen not found" +elseif not notioncore.find_screen_id(1) then + return "Initial number of screens should be 2, second screen not found" +elseif notioncore.find_screen_id(2) then + return "Initial number of screens should be 2, third screen found" +end + +if notioncore.find_screen_id(0):mx_count() ~= 1 then + return "Initial screen 0 should have 1 workspace instead of " .. notioncore.find_screen_id(0):mx_count() +end +print ('Screen 0: ' .. notioncore.find_screen_id(0):mx_nth(0):name() ) +if notioncore.find_screen_id(1):mx_count() ~= 1 then + return "Initial screen 1 should have 1 workspace instead of " .. notioncore.find_screen_id(1):mx_count() +end +print ('Screen 1: ' .. notioncore.find_screen_id(1):mx_nth(0):name()) + +os.execute("cp xrandr/fakexinerama-2monitors xrandr/.fakexinerama") + +print('Updating layout when there is 2 screens present') +-- Removing screens happens asynchronously, so we just check we start with 2 screens, +-- remove one, and then leave checking that one was removed up to the next test. +mod_xrandr.screenlayoutupdated() + +if notioncore.find_screen_id(0):mx_count() ~= 1 then + return "After updating screen 0 should have 1 workspaces instead of " .. + notioncore.find_screen_id(0):mx_count() .. ": " .. mx_names(notioncore.find_screen_id(0)) +end +if notioncore.find_screen_id(1):mx_count() ~= 1 then + return "After updating screen 1 should have 1 workspace instead of " .. notioncore.find_screen_id(1):mx_count() +end + +print('Removing one screen and updating layout') +mod_xrandr_mock.set_number_of_screens(1) +mod_xrandr.screenlayoutupdated() + +return "ok" diff --git a/test/integration/xrandr/02_removed_display.lua b/test/integration/xrandr/02_removed_display.lua new file mode 100644 index 00000000..28e90f9d --- /dev/null +++ b/test/integration/xrandr/02_removed_display.lua @@ -0,0 +1,16 @@ +mod_xrandr.screenlayoutupdated() + +if notioncore.find_screen_id(1) then + return "New number of screens should be 1, found ", notioncore.find_screen_id(1):name() +end + +if notioncore.find_screen_id(0):mx_count() ~= 2 then + return "Remaining screen should have 2 workspaces instead of " .. notioncore.find_screen_id(0):mx_count() .. + ': ' .. mx_names(notioncore.find_screen_id(0)) +end + +print('Restoring second display and updating layout') +mod_xrandr_mock.set_number_of_screens(2) +mod_xrandr.screenlayoutupdated() + +return "ok" diff --git a/test/integration/xrandr/03_new_screen_has_ws.lua b/test/integration/xrandr/03_new_screen_has_ws.lua new file mode 100644 index 00000000..6f208d8a --- /dev/null +++ b/test/integration/xrandr/03_new_screen_has_ws.lua @@ -0,0 +1,20 @@ +mod_xrandr.screenlayoutupdated() + +if (notioncore.find_screen_id(1) == Nil) then + return "Number of screens should be 2, again at the start of this test" +end + +if (notioncore.find_screen_id(0):mx_count() < 1) then + return "Screen 0 had no workspaces!" +elseif (notioncore.find_screen_id(1):mx_count() < 1) then + return "Screen 1 had no workspaces!" +end + +if notioncore.find_screen_id(0):mx_nth(0):name() ~= 'WGroupWS' then + return "First workspace not correctly returned to first screen" +end +if notioncore.find_screen_id(1):mx_nth(0):name() ~= 'WGroupWS<1>' then + return "Second workspace not correctly returned to second screen" +end + +return "ok" diff --git a/test/integration/xrandr/fakexinerama-1monitor b/test/integration/xrandr/fakexinerama-1monitor new file mode 100644 index 00000000..3387eabf --- /dev/null +++ b/test/integration/xrandr/fakexinerama-1monitor @@ -0,0 +1,2 @@ +1 +0 0 1280 960 diff --git a/test/integration/xrandr/fakexinerama-2monitors b/test/integration/xrandr/fakexinerama-2monitors new file mode 100644 index 00000000..13380fbc --- /dev/null +++ b/test/integration/xrandr/fakexinerama-2monitors @@ -0,0 +1,3 @@ +2 +0 0 1280 960 +1280 0 1280 1024 -- 2.11.4.GIT