1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
-- {{{ Table printing
function table_tostring (tt)
if type(tt) == "table" then
local sb = {}
local first = true
table.insert(sb, "{ ");
for key, value in pairs (tt) do
if first then first = false else table.insert(sb, ", ") end
if "number" == type (key) then
table.insert(sb, table_tostring (value))
else
table.insert(sb, key)
table.insert(sb, "=")
table.insert(sb, table_tostring (value))
end
end
table.insert(sb, " }");
return table.concat(sb)
elseif type (tt) == "number" then
return tostring(tt)
else
return '"' .. tostring(tt) .. '"'
end
end
function print_tables(str,t)
print(str .. ":")
for key, value in ipairs(t) do
print(" " .. key .. ": " .. table_tostring(value))
end
end
-- }}}
-- {{{ Table compare
-- Second table tree may contain some indices that the first does not contain.
function table_compare(table, super)
if not ( type(table) == type(super) ) then
return false
end
if not ( type(table) == "table" ) then
return table == super
end
for key, value in pairs(table) do
if not table_compare(value, super[key]) then return false end
end
return true
end
-- }}}
-- {{{ mock notion context
notioncore = {
load_module = function() return 1 end,
rootwin = function() return nil end,
screens_updated = function(root) return 1 end
}
function dopath()
end
_G["mod_xinerama"] = {
query_screens = function() end
}
-- }}}
-- load xinerama module lua code
dofile('mod_xinerama.lua')
function do_test(fn_name, input, output)
print("\nTesting:" .. fn_name)
print_tables("Input", input)
local ret = mod_xinerama[fn_name](input)
print_tables("Output", ret)
assert(table_compare(output, ret))
end
-- now perform some tests:
-- {{{ merge_contained_screens
do_test("merge_contained_screens",{
{x=0,y=0,w=800,h=600}
},{
{x=0,y=0,w=800,h=600}
})
do_test("merge_contained_screens",{
{x=0,y=0,w=800,h=600},
{x=0,y=0,w=800,h=600},
},{
{x=0,y=0,w=800,h=600}
})
do_test("merge_contained_screens",{
{x=0,y=0,w=800,h=600},
{x=100,y=100,w=600,h=400},
},{
{x=0,y=0,w=800,h=600}
})
do_test("merge_contained_screens",{
{x=0,y=0,w=800,h=600},
{x=100,y=100,w=800,h=600},
},{
{x=0,y=0,w=800,h=600},
{x=100,y=100,w=800,h=600},
})
-- }}}
-- {{{ merge_overlapping_screens
do_test("merge_overlapping_screens",{
{x=0,y=0,w=800,h=600}
},{
{x=0,y=0,w=800,h=600}
})
do_test("merge_overlapping_screens",{
{x=0,y=0,w=800,h=600},
{x=0,y=0,w=800,h=600},
},{
{x=0,y=0,w=800,h=600}
})
do_test("merge_overlapping_screens",{
{x=0,y=0,w=800,h=600},
{x=100,y=100,w=600,h=400},
},{
{x=0,y=0,w=800,h=600}
})
do_test("merge_overlapping_screens",{
{x=0,y=0,w=800,h=600},
{x=100,y=100,w=800,h=600},
},{
{x=0,y=0,w=900,h=700}
})
--[[
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
0 ____________________
1 | | | |
2 | | | |
3 | ~~~~~|~~~~
4 | _______|________
5 | | | |
6 ~~~~~~~~~~~~~~~~ |
7 | |
8 | |
9 | |
0 ~~~~~~~~~~~~~~~~
]]--
do_test("merge_overlapping_screens",{
{x=0,y=0,w=800,h=600},
{x=400,y=400,w=800,h=600},
{x=500,y=0,w=500,h=300}
},{
{x=0,y=0,w=1200,h=1000}
})
--[[
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
0 ________________ ______
1 | | | |
2 | | | |
3 | | ~~~~~~
4 | _______|________
5 | | | |
6 ~~~~~~~~~~~~~~~~ |
7 | |
8 | |
9 | |
0 ~~~~~~~~~~~~~~~~
]]--
do_test("merge_overlapping_screens",{
{x=0,y=0,w=800,h=600},
{x=900,y=100,w=300,h=300},
{x=400,y=400,w=800,h=600}
},{
{x=0,y=0,w=1200,h=1000}
})
do_test("merge_overlapping_screens_alternative",{
{x=0,y=0,w=800,h=600},
{x=400,y=400,w=800,h=600},
{x=900,y=100,w=300,h=300}
},{
{x=0,y=0,w=1200,h=1000},
{x=900,y=100,w=300,h=300}
})
|