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