Merge lp:~smspillaz/compiz-core/compiz-core.constrainment-tests into lp:compiz-core/0.9.5
- compiz-core.constrainment-tests
- Merge into 0.9.5
Proposed by
Sam Spilsbury
Status: | Merged |
---|---|
Merged at revision: | 2926 |
Proposed branch: | lp:~smspillaz/compiz-core/compiz-core.constrainment-tests |
Merge into: | lp:compiz-core/0.9.5 |
Prerequisite: | lp:~smspillaz/compiz-core/compiz-core.extents-tests |
Diff against target: |
678 lines (+589/-0) (has conflicts) 11 files modified
include/core/size.h (+11/-0) plugins/CMakeLists.txt (+1/-0) src/CMakeLists.txt (+4/-0) src/window/CMakeLists.txt (+1/-0) src/window/constrainment/CMakeLists.txt (+72/-0) src/window/constrainment/include/core/windowconstrainment.h (+57/-0) src/window/constrainment/src/windowconstrainment.cpp (+161/-0) src/window/constrainment/tests/CMakeLists.txt (+19/-0) src/window/constrainment/tests/test-window-constrainment.cpp (+26/-0) src/window/constrainment/tests/test-window-constrainment.h (+39/-0) src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp (+198/-0) Text conflict in src/CMakeLists.txt |
To merge this branch: | bzr merge lp:~smspillaz/compiz-core/compiz-core.constrainment-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Approve | ||
Review via email:
|
Commit message
Description of the change
Added tests for constrainment to XSizeHints
To post a comment you must log in.
- 2924. By Sam Spilsbury
-
Merged compiz-
core.extents- tests into compiz- core.constrainm ent-tests.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'include/core/size.h' |
2 | --- include/core/size.h 2010-03-24 09:37:19 +0000 |
3 | +++ include/core/size.h 2012-01-20 09:51:38 +0000 |
4 | @@ -50,6 +50,17 @@ |
5 | typedef std::list<CompSize> list; |
6 | typedef std::list<CompSize *> ptrList; |
7 | |
8 | + bool operator== (const CompSize &other) const |
9 | + { |
10 | + return (this->mWidth == other.mWidth && |
11 | + this->mHeight == other.mHeight); |
12 | + } |
13 | + |
14 | + bool operator!= (const CompSize &other) const |
15 | + { |
16 | + return !(*this == other); |
17 | + } |
18 | + |
19 | private: |
20 | int mWidth, mHeight; |
21 | }; |
22 | |
23 | === modified file 'plugins/CMakeLists.txt' |
24 | --- plugins/CMakeLists.txt 2012-01-20 09:51:37 +0000 |
25 | +++ plugins/CMakeLists.txt 2012-01-20 09:51:38 +0000 |
26 | @@ -19,6 +19,7 @@ |
27 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/geometry/include |
28 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/geometry-saver/include |
29 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/extents/include |
30 | + ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/constrainment/include |
31 | ${CMAKE_CURRENT_SOURCE_DIR}/../logmessage/include |
32 | ) |
33 | |
34 | |
35 | === modified file 'src/CMakeLists.txt' |
36 | --- src/CMakeLists.txt 2012-01-20 09:51:37 +0000 |
37 | +++ src/CMakeLists.txt 2012-01-20 09:51:38 +0000 |
38 | @@ -58,6 +58,9 @@ |
39 | |
40 | ${CMAKE_CURRENT_SOURCE_DIR}/window/extents/include |
41 | ${CMAKE_CURRENT_SOURCE_DIR}/window/extents/src |
42 | + |
43 | + ${CMAKE_CURRENT_SOURCE_DIR}/window/constrainment/include |
44 | + ${CMAKE_CURRENT_SOURCE_DIR}/window/constrainment/src |
45 | ) |
46 | |
47 | add_definitions ( |
48 | @@ -157,6 +160,7 @@ |
49 | compiz_window_geometry |
50 | compiz_window_geometry_saver |
51 | compiz_window_extents |
52 | + compiz_window_constrainment |
53 | # ${CORE_MOD_LIBRARIES} |
54 | >>>>>>> MERGE-SOURCE |
55 | ) |
56 | |
57 | === modified file 'src/window/CMakeLists.txt' |
58 | --- src/window/CMakeLists.txt 2012-01-20 09:51:37 +0000 |
59 | +++ src/window/CMakeLists.txt 2012-01-20 09:51:38 +0000 |
60 | @@ -1,3 +1,4 @@ |
61 | add_subdirectory (geometry) |
62 | add_subdirectory (geometry-saver) |
63 | add_subdirectory (extents) |
64 | +add_subdirectory (constrainment) |
65 | |
66 | === added directory 'src/window/constrainment' |
67 | === added file 'src/window/constrainment/CMakeLists.txt' |
68 | --- src/window/constrainment/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
69 | +++ src/window/constrainment/CMakeLists.txt 2012-01-20 09:51:38 +0000 |
70 | @@ -0,0 +1,72 @@ |
71 | +pkg_check_modules ( |
72 | + GLIBMM |
73 | + REQUIRED |
74 | + glibmm-2.4 glib-2.0 |
75 | +) |
76 | + |
77 | +INCLUDE_DIRECTORIES ( |
78 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
79 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
80 | + |
81 | + ${compiz_SOURCE_DIR}/include |
82 | + |
83 | + ${compiz_SOURCE_DIR}/src/point/include |
84 | + ${compiz_SOURCE_DIR}/src/rect/include |
85 | + ${compiz_SOURCE_DIR}/src/window/geometry/include |
86 | + ${compiz_SOURCE_DIR}/src/window/geometry-saver/include |
87 | + ${Boost_INCLUDE_DIRS} |
88 | + |
89 | + ${GLIBMM_INCLUDE_DIRS} |
90 | +) |
91 | + |
92 | +LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS}) |
93 | + |
94 | +SET ( |
95 | + PUBLIC_HEADERS |
96 | + ${CMAKE_CURRENT_SOURCE_DIR}/include/core/windowconstrainment.h |
97 | +) |
98 | + |
99 | +SET ( |
100 | + PRIVATE_HEADERS |
101 | +) |
102 | + |
103 | +SET( |
104 | + SRCS |
105 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/windowconstrainment.cpp |
106 | +) |
107 | + |
108 | +ADD_LIBRARY( |
109 | + compiz_window_constrainment STATIC |
110 | + |
111 | + ${SRCS} |
112 | + |
113 | + ${PUBLIC_HEADERS} |
114 | + ${PRIVATE_HEADERS} |
115 | +) |
116 | + |
117 | +ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests ) |
118 | + |
119 | +SET_TARGET_PROPERTIES( |
120 | + compiz_window_constrainment PROPERTIES |
121 | + PUBLIC_HEADER "${PUBLIC_HEADERS}" |
122 | + COMPILE_FLAGS "-fPIC" |
123 | +) |
124 | + |
125 | +INSTALL( |
126 | + TARGETS compiz_window_constrainment |
127 | + RUNTIME DESTINATION bin |
128 | + LIBRARY DESTINATION lib |
129 | + ARCHIVE DESTINATION lib |
130 | + PUBLIC_HEADER DESTINATION include/compiz/core |
131 | +) |
132 | + |
133 | + |
134 | + |
135 | +TARGET_LINK_LIBRARIES( |
136 | + compiz_window_constrainment |
137 | + compiz_window_geometry |
138 | + compiz_point |
139 | + compiz_rect |
140 | + |
141 | + ${GLIBMM_LIBRARIES} |
142 | +) |
143 | |
144 | === added directory 'src/window/constrainment/include' |
145 | === added directory 'src/window/constrainment/include/core' |
146 | === added file 'src/window/constrainment/include/core/windowconstrainment.h' |
147 | --- src/window/constrainment/include/core/windowconstrainment.h 1970-01-01 00:00:00 +0000 |
148 | +++ src/window/constrainment/include/core/windowconstrainment.h 2012-01-20 09:51:38 +0000 |
149 | @@ -0,0 +1,57 @@ |
150 | +/* |
151 | + * Copyright © 2008 Dennis Kasprzyk |
152 | + * Copyright © 2007 Novell, Inc. |
153 | + * |
154 | + * Permission to use, copy, modify, distribute, and sell this software |
155 | + * and its documentation for any purpose is hereby granted without |
156 | + * fee, provided that the above copyright notice appear in all copies |
157 | + * and that both that copyright notice and this permission notice |
158 | + * appear in supporting documentation, and that the name of |
159 | + * Dennis Kasprzyk not be used in advertising or publicity pertaining to |
160 | + * distribution of the software without specific, written prior permission. |
161 | + * Dennis Kasprzyk makes no representations about the suitability of this |
162 | + * software for any purpose. It is provided "as is" without express or |
163 | + * implied warranty. |
164 | + * |
165 | + * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
166 | + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
167 | + * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
168 | + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
169 | + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
170 | + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
171 | + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
172 | + * |
173 | + * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org> |
174 | + * David Reveman <davidr@novell.com> |
175 | + */ |
176 | + |
177 | +#ifndef _COMPWINDOWCONSTRAINMENT_H |
178 | +#define _COMPWINDOWCONSTRAINMENT_H |
179 | + |
180 | +#include <inttypes.h> |
181 | +#include <core/size.h> |
182 | +#include <core/rect.h> |
183 | +#include <X11/Xlib.h> |
184 | +#include <X11/Xutil.h> |
185 | +#include <limits> |
186 | + |
187 | +namespace compiz |
188 | +{ |
189 | +namespace window |
190 | +{ |
191 | + |
192 | +namespace constrainment |
193 | +{ |
194 | +const unsigned int PVertResizeInc = (1 << 0); |
195 | +const unsigned int PHorzResizeInc = (1 << 1); |
196 | + |
197 | +CompSize constrainToHints (const XSizeHints &hints, |
198 | + const CompSize &size, |
199 | + unsigned int ignoreHints, |
200 | + unsigned int resizeIgnoreHints); |
201 | +} |
202 | + |
203 | +} |
204 | +} |
205 | + |
206 | +#endif |
207 | |
208 | === added directory 'src/window/constrainment/src' |
209 | === added file 'src/window/constrainment/src/windowconstrainment.cpp' |
210 | --- src/window/constrainment/src/windowconstrainment.cpp 1970-01-01 00:00:00 +0000 |
211 | +++ src/window/constrainment/src/windowconstrainment.cpp 2012-01-20 09:51:38 +0000 |
212 | @@ -0,0 +1,161 @@ |
213 | +/* |
214 | + * Copyright © 2005 Novell, Inc. |
215 | + * |
216 | + * Permission to use, copy, modify, distribute, and sell this software |
217 | + * and its documentation for any purpose is hereby granted without |
218 | + * fee, provided that the above copyright notice appear in all copies |
219 | + * and that both that copyright notice and this permission notice |
220 | + * appear in supporting documentation, and that the name of |
221 | + * Novell, Inc. not be used in advertising or publicity pertaining to |
222 | + * distribution of the software without specific, written prior permission. |
223 | + * Novell, Inc. makes no representations about the suitability of this |
224 | + * software for any purpose. It is provided "as is" without express or |
225 | + * implied warranty. |
226 | + * |
227 | + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
228 | + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
229 | + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
230 | + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
231 | + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
232 | + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
233 | + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
234 | + * |
235 | + * Author: David Reveman <davidr@novell.com> |
236 | + */ |
237 | + |
238 | +#include <core/windowconstrainment.h> |
239 | + |
240 | +static inline int constrainmentFloor (int value, int base) |
241 | +{ |
242 | + return (value / base) * base; |
243 | +} |
244 | + |
245 | +static inline uint64_t constrainment64Floor (uint64_t value, uint64_t base) |
246 | +{ |
247 | + return (value / base) * base; |
248 | +} |
249 | + |
250 | +static inline float constrainmentClamp(float x, float a, float b) |
251 | +{ |
252 | + return x < a ? a : (x > b ? b : x); |
253 | +} |
254 | + |
255 | +CompSize |
256 | +compiz::window::constrainment::constrainToHints (const XSizeHints &hints, |
257 | + const CompSize &size, |
258 | + unsigned int ignoreHints, |
259 | + unsigned int resizeIgnoreHints) |
260 | +{ |
261 | + int width = size.width (); |
262 | + int height = size.height (); |
263 | + int min_width = 1; |
264 | + int min_height = 1; |
265 | + int base_width = 1; |
266 | + int base_height = 1; |
267 | + int xinc = 1; |
268 | + int yinc = 1; |
269 | + int max_width = std::numeric_limits <short>::max (); |
270 | + int max_height = std::numeric_limits <short>::max (); |
271 | + long flags = hints.flags & ~ignoreHints; |
272 | + long resizeIncFlags = (flags & PResizeInc) ? (~resizeIgnoreHints) : 0; |
273 | + |
274 | + /* Ater gdk_window_constrain_size(), which is partially borrowed from fvwm. |
275 | + * |
276 | + * Copyright 1993, Robert Nation |
277 | + * You may use this code for any purpose, as long as the original |
278 | + * copyright remains in the source code and all documentation |
279 | + * |
280 | + * which in turn borrows parts of the algorithm from uwm |
281 | + */ |
282 | + |
283 | + if ((flags & PBaseSize) && (flags & PMinSize)) |
284 | + { |
285 | + base_width = std::max (1, hints.base_width); |
286 | + base_height = std::max (1, hints.base_height); |
287 | + min_width = std::max (1, hints.min_width); |
288 | + min_height = std::max (1, hints.min_height); |
289 | + } |
290 | + else if (flags & PBaseSize) |
291 | + { |
292 | + base_width = std::max (1, hints.base_width); |
293 | + base_height = std::max (1, hints.base_height); |
294 | + min_width = std::max (1, hints.base_width); |
295 | + min_height = std::max (1, hints.base_height); |
296 | + } |
297 | + else if (flags & PMinSize) |
298 | + { |
299 | + base_width = std::max (1, hints.min_width); |
300 | + base_height = std::max (1, hints.min_height); |
301 | + min_width = std::max (1, hints.min_width); |
302 | + min_height = std::max (1, hints.min_height); |
303 | + } |
304 | + |
305 | + if (flags & PMaxSize) |
306 | + { |
307 | + max_width = std::max (1, hints.max_width); |
308 | + max_height = std::max (1, hints.max_height); |
309 | + } |
310 | + |
311 | + if (resizeIncFlags & PHorzResizeInc) |
312 | + xinc = std::max (xinc, hints.width_inc); |
313 | + |
314 | + if (resizeIncFlags & PVertResizeInc) |
315 | + yinc = std::max (yinc, hints.height_inc); |
316 | + |
317 | + /* clamp width and height to min and max values */ |
318 | + width = constrainmentClamp (width, min_width, max_width); |
319 | + height = constrainmentClamp (height, min_height, max_height); |
320 | + |
321 | + /* shrink to base + N * inc */ |
322 | + width = base_width + constrainmentFloor (width - base_width, xinc); |
323 | + height = base_height + constrainmentFloor (height - base_height, yinc); |
324 | + |
325 | + /* constrain aspect ratio, according to: |
326 | + * |
327 | + * min_aspect.x width max_aspect.x |
328 | + * ------------ <= -------- <= ----------- |
329 | + * min_aspect.y height max_aspect.y |
330 | + */ |
331 | + if ((flags & PAspect) && hints.min_aspect.y > 0 && hints.max_aspect.x > 0) |
332 | + { |
333 | + /* Use 64 bit arithmetic to prevent overflow */ |
334 | + |
335 | + uint64_t min_aspect_x = hints.min_aspect.x; |
336 | + uint64_t min_aspect_y = hints.min_aspect.y; |
337 | + uint64_t max_aspect_x = hints.max_aspect.x; |
338 | + uint64_t max_aspect_y = hints.max_aspect.y; |
339 | + uint64_t delta; |
340 | + |
341 | + if (min_aspect_x * height > width * min_aspect_y) |
342 | + { |
343 | + delta = constrainment64Floor (height - width * min_aspect_y / min_aspect_x, |
344 | + yinc); |
345 | + if (height - (int) delta >= min_height) |
346 | + height -= delta; |
347 | + else |
348 | + { |
349 | + delta = constrainment64Floor (height * min_aspect_x / min_aspect_y - width, |
350 | + xinc); |
351 | + if (width + (int) delta <= max_width) |
352 | + width += delta; |
353 | + } |
354 | + } |
355 | + |
356 | + if (width * max_aspect_y > max_aspect_x * height) |
357 | + { |
358 | + delta = constrainment64Floor (width - height * max_aspect_x / max_aspect_y, |
359 | + xinc); |
360 | + if (width - (int) delta >= min_width) |
361 | + width -= delta; |
362 | + else |
363 | + { |
364 | + delta = constrainment64Floor (width * min_aspect_y / min_aspect_x - height, |
365 | + yinc); |
366 | + if (height + (int) delta <= max_height) |
367 | + height += delta; |
368 | + } |
369 | + } |
370 | + } |
371 | + |
372 | + return CompSize (width, height); |
373 | +} |
374 | |
375 | === added directory 'src/window/constrainment/tests' |
376 | === added file 'src/window/constrainment/tests/CMakeLists.txt' |
377 | --- src/window/constrainment/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
378 | +++ src/window/constrainment/tests/CMakeLists.txt 2012-01-20 09:51:38 +0000 |
379 | @@ -0,0 +1,19 @@ |
380 | +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
381 | + |
382 | +add_library (compiz_window_constrainment_test |
383 | + ${CMAKE_CURRENT_SOURCE_DIR}/test-window-constrainment.cpp) |
384 | + |
385 | +add_executable (compiz_test_window_constrainment_to_hints |
386 | + ${CMAKE_CURRENT_SOURCE_DIR}/to-hints/src/test-window-constrainment-to-hints.cpp |
387 | + ${compiz_SOURCE_DIR}/src/size.cpp) |
388 | + |
389 | +target_link_libraries (compiz_test_window_constrainment_to_hints |
390 | + compiz_window_constrainment_test |
391 | + compiz_window_constrainment |
392 | + ${GTEST_BOTH_LIBRARIES} |
393 | + ${GMOCK_LIBRARY} |
394 | + ${GMOCK_MAIN_LIBRARY} |
395 | + ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. |
396 | + ) |
397 | + |
398 | +add_test (compiz_window_constrainment_to_hints compiz_test_window_constrainment_to_hints) |
399 | |
400 | === added file 'src/window/constrainment/tests/test-window-constrainment.cpp' |
401 | --- src/window/constrainment/tests/test-window-constrainment.cpp 1970-01-01 00:00:00 +0000 |
402 | +++ src/window/constrainment/tests/test-window-constrainment.cpp 2012-01-20 09:51:38 +0000 |
403 | @@ -0,0 +1,26 @@ |
404 | +/* |
405 | + * Copyright © 2011 Canonical Ltd. |
406 | + * |
407 | + * Permission to use, copy, modify, distribute, and sell this software |
408 | + * and its documentation for any purpose is hereby granted without |
409 | + * fee, provided that the above copyright notice appear in all copies |
410 | + * and that both that copyright notice and this permission notice |
411 | + * appear in supporting documentation, and that the name of |
412 | + * Canonical Ltd. not be used in advertising or publicity pertaining to |
413 | + * distribution of the software without specific, written prior permission. |
414 | + * Canonical Ltd. makes no representations about the suitability of this |
415 | + * software for any purpose. It is provided "as is" without express or |
416 | + * implied warranty. |
417 | + * |
418 | + * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
419 | + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
420 | + * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
421 | + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
422 | + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
423 | + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
424 | + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
425 | + * |
426 | + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> |
427 | + */ |
428 | + |
429 | +#include "test-window-constrainment.h" |
430 | |
431 | === added file 'src/window/constrainment/tests/test-window-constrainment.h' |
432 | --- src/window/constrainment/tests/test-window-constrainment.h 1970-01-01 00:00:00 +0000 |
433 | +++ src/window/constrainment/tests/test-window-constrainment.h 2012-01-20 09:51:38 +0000 |
434 | @@ -0,0 +1,39 @@ |
435 | +/* |
436 | + * Copyright © 2011 Canonical Ltd. |
437 | + * |
438 | + * Permission to use, copy, modify, distribute, and sell this software |
439 | + * and its documentation for any purpose is hereby granted without |
440 | + * fee, provided that the above copyright notice appear in all copies |
441 | + * and that both that copyright notice and this permission notice |
442 | + * appear in supporting documentation, and that the name of |
443 | + * Canonical Ltd. not be used in advertising or publicity pertaining to |
444 | + * distribution of the software without specific, written prior permission. |
445 | + * Canonical Ltd. makes no representations about the suitability of this |
446 | + * software for any purpose. It is provided "as is" without express or |
447 | + * implied warranty. |
448 | + * |
449 | + * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
450 | + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
451 | + * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
452 | + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
453 | + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
454 | + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
455 | + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
456 | + * |
457 | + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> |
458 | + */ |
459 | + |
460 | +#ifndef _COMPIZ_TEST_WINDOW_CONSTRAINMENT_H |
461 | +#define _COMPIZ_TEST_WINDOW_CONSTRAINMENT_H |
462 | + |
463 | +#include <gtest/gtest.h> |
464 | +#include <core/windowconstrainment.h> |
465 | +#include <core/windowgeometry.h> |
466 | +#include <iostream> |
467 | +#include <boost/bind.hpp> |
468 | + |
469 | +class CompWindowConstrainmentTest : public ::testing::Test |
470 | +{ |
471 | +}; |
472 | + |
473 | +#endif |
474 | |
475 | === added directory 'src/window/constrainment/tests/to-hints' |
476 | === added directory 'src/window/constrainment/tests/to-hints/src' |
477 | === added file 'src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp' |
478 | --- src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp 1970-01-01 00:00:00 +0000 |
479 | +++ src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp 2012-01-20 09:51:38 +0000 |
480 | @@ -0,0 +1,198 @@ |
481 | +/* |
482 | + * Copyright © 2011 Canonical Ltd. |
483 | + * |
484 | + * Permission to use, copy, modify, distribute, and sell this software |
485 | + * and its documentation for any purpose is hereby granted without |
486 | + * fee, provided that the above copyright notice appear in all copies |
487 | + * and that both that copyright notice and this permission notice |
488 | + * appear in supporting documentation, and that the name of |
489 | + * Canonical Ltd. not be used in advertising or publicity pertaining to |
490 | + * distribution of the software without specific, written prior permission. |
491 | + * Canonical Ltd. makes no representations about the suitability of this |
492 | + * software for any purpose. It is provided "as is" without express or |
493 | + * implied warranty. |
494 | + * |
495 | + * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
496 | + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
497 | + * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
498 | + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
499 | + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
500 | + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
501 | + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
502 | + * |
503 | + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> |
504 | + */ |
505 | + |
506 | +#include "test-window-constrainment.h" |
507 | +#include <cstring> |
508 | + |
509 | +class CompWindowConstrainmentTestToHints : |
510 | + public CompWindowConstrainmentTest |
511 | +{ |
512 | +}; |
513 | + |
514 | +TEST_F (CompWindowConstrainmentTestToHints, ToHints) |
515 | +{ |
516 | + /* No hints, size is the same */ |
517 | + XSizeHints hints; |
518 | + CompSize size (1000, 1000); |
519 | + |
520 | + memset (&hints, 0, sizeof (XSizeHints)); |
521 | + |
522 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
523 | + |
524 | + EXPECT_EQ (size, CompSize (1000, 1000)); |
525 | + |
526 | + /* Minimum size specified, constrain to minimum size */ |
527 | + size = CompSize (100, 100); |
528 | + memset (&hints, 0, sizeof (XSizeHints)); |
529 | + |
530 | + hints.flags |= PMinSize; |
531 | + hints.min_width = 500; |
532 | + hints.min_height = 500; |
533 | + |
534 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
535 | + |
536 | + EXPECT_EQ (size, CompSize (500, 500)); |
537 | + |
538 | + /* Base size specified, constrain to base size as minimum size */ |
539 | + size = CompSize (100, 100); |
540 | + memset (&hints, 0, sizeof (XSizeHints)); |
541 | + |
542 | + hints.flags |= PBaseSize; |
543 | + hints.base_width = 500; |
544 | + hints.base_height = 500; |
545 | + |
546 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
547 | + |
548 | + EXPECT_EQ (size, CompSize (500, 500)); |
549 | + |
550 | + /* Minimum and base size specified, constrain to min size as minimum size */ |
551 | + size = CompSize (100, 100); |
552 | + memset (&hints, 0, sizeof (XSizeHints)); |
553 | + |
554 | + hints.flags |= PBaseSize | PMinSize; |
555 | + hints.base_width = 700; |
556 | + hints.base_height = 700; |
557 | + hints.min_width = 500; |
558 | + hints.min_height = 500; |
559 | + |
560 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
561 | + |
562 | + EXPECT_EQ (size, CompSize (500, 500)); |
563 | + |
564 | + /* Maximum size specified, constrain to minimum size */ |
565 | + size = CompSize (1000, 1000); |
566 | + memset (&hints, 0, sizeof (XSizeHints)); |
567 | + |
568 | + hints.flags |= PMaxSize; |
569 | + hints.max_width = 500; |
570 | + hints.max_height = 500; |
571 | + |
572 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
573 | + |
574 | + EXPECT_EQ (size, CompSize (500, 500)); |
575 | + |
576 | + /* Resize flags specified, constrain to closest low step of |
577 | + * increments for size specified */ |
578 | + size = CompSize (1002, 1002); |
579 | + memset (&hints, 0, sizeof (XSizeHints)); |
580 | + |
581 | + hints.flags |= PBaseSize | PResizeInc; |
582 | + hints.base_width = 500; |
583 | + hints.base_height = 500; |
584 | + hints.width_inc = 5; |
585 | + hints.height_inc = 5; |
586 | + |
587 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
588 | + |
589 | + EXPECT_EQ (size, CompSize (1000, 1000)); |
590 | + |
591 | + /* Resize flags specified, constrain to closest low step of |
592 | + * increments for size specified */ |
593 | + size = CompSize (1004, 1004); |
594 | + memset (&hints, 0, sizeof (XSizeHints)); |
595 | + |
596 | + hints.flags |= PBaseSize | PResizeInc; |
597 | + hints.base_width = 500; |
598 | + hints.base_height = 500; |
599 | + hints.width_inc = 5; |
600 | + hints.height_inc = 5; |
601 | + |
602 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
603 | + |
604 | + EXPECT_EQ (size, CompSize (1000, 1000)); |
605 | + |
606 | + /* Resize flags specified, constrain to closest low step of |
607 | + * increments for size specified */ |
608 | + size = CompSize (1006, 1006); |
609 | + memset (&hints, 0, sizeof (XSizeHints)); |
610 | + |
611 | + hints.flags |= PBaseSize | PResizeInc; |
612 | + hints.base_width = 500; |
613 | + hints.base_height = 500; |
614 | + hints.width_inc = 5; |
615 | + hints.height_inc = 5; |
616 | + |
617 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
618 | + |
619 | + EXPECT_EQ (size, CompSize (1005, 1005)); |
620 | + |
621 | + /* Don't require constrainment on width */ |
622 | + size = CompSize (1002, 1002); |
623 | + memset (&hints, 0, sizeof (XSizeHints)); |
624 | + |
625 | + hints.flags |= PBaseSize | PResizeInc; |
626 | + hints.base_width = 500; |
627 | + hints.base_height = 500; |
628 | + hints.width_inc = 5; |
629 | + hints.height_inc = 5; |
630 | + |
631 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, compiz::window::constrainment::PHorzResizeInc); |
632 | + |
633 | + EXPECT_EQ (size, CompSize (1002, 1000)); |
634 | + |
635 | + /* Don't require constrainment on height */ |
636 | + size = CompSize (1002, 1002); |
637 | + memset (&hints, 0, sizeof (XSizeHints)); |
638 | + |
639 | + hints.flags |= PBaseSize | PResizeInc; |
640 | + hints.base_width = 500; |
641 | + hints.base_height = 500; |
642 | + hints.width_inc = 5; |
643 | + hints.height_inc = 5; |
644 | + |
645 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, compiz::window::constrainment::PVertResizeInc); |
646 | + |
647 | + EXPECT_EQ (size, CompSize (1000, 1002)); |
648 | + |
649 | + /* Aspect ratios - don't allow sizes less than 1:2 or more than 2:5 |
650 | + * clamping to the largest size */ |
651 | + size = CompSize (4000, 5000); |
652 | + memset (&hints, 0, sizeof (XSizeHints)); |
653 | + |
654 | + hints.flags |= PAspect; |
655 | + hints.min_aspect.x = 1; |
656 | + hints.min_aspect.y = 2; |
657 | + hints.max_aspect.x = 2; |
658 | + hints.max_aspect.y = 5; |
659 | + |
660 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
661 | + |
662 | + EXPECT_EQ (size, CompSize (2000, 5000)); |
663 | + |
664 | + /* Aspect ratios - don't allow sizes less than 1:2 or more than 2:5 |
665 | + * clamping to the largest size */ |
666 | + size = CompSize (12, 20); |
667 | + memset (&hints, 0, sizeof (XSizeHints)); |
668 | + |
669 | + hints.flags |= PAspect; |
670 | + hints.min_aspect.x = 1; |
671 | + hints.min_aspect.y = 2; |
672 | + hints.max_aspect.x = 2; |
673 | + hints.max_aspect.y = 5; |
674 | + |
675 | + size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0); |
676 | + |
677 | + EXPECT_EQ (size, CompSize (8, 20)); |
678 | +} |
Same issues about redundant "boilerplate" for tests.
Also "#include <iostream>" is totally unnecessary (and one of those headers one should always try to avoid - especially in header files).
But lets land and deal with test architecture as a separate thing.