Merge lp:~compiz-team/compiz/compiz.fix_1058577 into lp:compiz/0.9.9
- compiz.fix_1058577
- Merge into 0.9.9
Status: | Merged |
---|---|
Approved by: | Daniel van Vugt |
Approved revision: | 3408 |
Merged at revision: | 3413 |
Proposed branch: | lp:~compiz-team/compiz/compiz.fix_1058577 |
Merge into: | lp:compiz/0.9.9 |
Diff against target: |
500 lines (+371/-26) 5 files modified
compizconfig/libcompizconfig/src/bindings.c (+52/-26) compizconfig/libcompizconfig/src/ccs-modifier-list-inl.h (+50/-0) compizconfig/libcompizconfig/src/ccs-private.h (+19/-0) compizconfig/libcompizconfig/tests/CMakeLists.txt (+12/-0) compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp (+238/-0) |
To merge this branch: | bzr merge lp:~compiz-team/compiz/compiz.fix_1058577 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel van Vugt | Approve | ||
jenkins (community) | continuous-integration | Needs Fixing | |
Sam Spilsbury | Approve | ||
Review via email: mp+128924@code.launchpad.net |
This proposal supersedes a proposal from 2012-10-10.
Commit message
Added tests for the StringToModifiers and ModifiersToString code, move the
code which detects <Primary> as ControlMask upstream and use two functions to
ensure that duplicates aren't added.
Fixes Jenkins failures. (LP: #1058577)
Description of the change
Added tests for the StringToModifiers and ModifiersToString code, move the code which detects <Primary> as ControlMask upstream and use two functions to ensure that duplicates aren't added.
Two tests were failing in bug 1058577 because both <Control> and <Primary> were added to the modifier string instead of just <Control>.
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:3407
http://
Executed test runs:
FAILURE: http://
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal | # |
Sorry, but gcc sucks at template error messages:
[ 40%] Building CXX object compizconfig/
In file included from /usr/include/
/usr/include/
/usr/include/
/usr/include/
/home/dan/
/usr/include/
/home/dan/
/home/dan/
In file included from /usr/include/
/usr/include/
/usr/include/
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
> Sorry, but gcc sucks at template error messages:
>
> [ 40%] Building CXX object compizconfig/
> zconfig_
> In file included from /usr/include/
> from /usr/include/
> from /home/dan/
> g/tests/
> /usr/include/
> std::vector<_Tp, _Alloc>
> _Args&& ...) [with _Args = {{anonymous}
> {anonymous}
> std::allocator<
> = __gnu_cxx:
> std::vector<
> _Alloc>
> /usr/include/
> std::vector<_Tp, _Alloc>
> {{anonymous}
> std::allocator<
> /usr/include/
> std::vector<_Tp, _Alloc>
> [with _Tp = {anonymous}
> std::allocator<
> _Alloc>::value_type = {anonymous}
> /home/dan/
> est_ccs_
> /usr/include/
> ‘{anonymous}
> {anonymous}
> /home/dan/
> est_ccs_
> {anonymous}
> implicitly deleted because the default definition would be ill-formed:
> /home/dan/
> est_ccs_
> std::basic_
> _Traits, _Alloc>& std::basic_
> std::basic_
> std::char_
> std::basic_
> discards qualifiers [-fpermissive]
> In file included from /usr/include/
> from /usr/include/
> from /home/dan/
> g/tests/
> /usr/include/
> _BI2 std::__
> std::random_
> {anonymous}
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal | # |
And I tried clang to get better error messages. But hit bug 1060804 instead.
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
I cannot reproduce this compiler error but I've implemented copying semantics for the offending struct.
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal | # |
Seems OK now.
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:3408
http://
Executed test runs:
FAILURE: http://
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
Note that tarmac will probably reject this due to the distro patch
Unity Merger (unity-merger) wrote : Posted in a previous version of this proposal | # |
The Jenkins job https:/
Not merging it.
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
I think jenkins is using the new packaging repo with the removed conflicting patch, resubmitting.
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
As above
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:3408
http://
Executed test runs:
FAILURE: http://
Sam Spilsbury (smspillaz) : | # |
jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Continuous integration, rev:3408
http://
Executed test runs:
FAILURE: http://
Daniel van Vugt (vanvugt) wrote : | # |
Isn't this the same revision I approved already in a different submission?
Daniel van Vugt (vanvugt) wrote : | # |
P.S. Jenkins can't ever pass until the similar distro patch is removed from lp:ubuntu/compiz: primary_
jenkins (martin-mrazik+qa) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Sam Spilsbury (smspillaz) wrote : | # |
Right, although we've changed the packaging repo used for jenkins to lp:~compiz-team/compiz/ubuntu , although its still failing and the publisher is broken so we can't see why
Daniel van Vugt (vanvugt) wrote : | # |
OK, I have hacked away the offending reference to primary_
Try again.
Preview Diff
1 | === modified file 'compizconfig/libcompizconfig/src/bindings.c' | |||
2 | --- compizconfig/libcompizconfig/src/bindings.c 2012-09-25 06:12:24 +0000 | |||
3 | +++ compizconfig/libcompizconfig/src/bindings.c 2012-10-10 12:52:21 +0000 | |||
4 | @@ -38,14 +38,7 @@ | |||
5 | 38 | #include <X11/Xlib.h> | 38 | #include <X11/Xlib.h> |
6 | 39 | 39 | ||
7 | 40 | #include <ccs.h> | 40 | #include <ccs.h> |
16 | 41 | 41 | #include <ccs-modifier-list-inl.h> | |
9 | 42 | #define CompAltMask (1 << 16) | ||
10 | 43 | #define CompMetaMask (1 << 17) | ||
11 | 44 | #define CompSuperMask (1 << 18) | ||
12 | 45 | #define CompHyperMask (1 << 19) | ||
13 | 46 | #define CompModeSwitchMask (1 << 20) | ||
14 | 47 | #define CompNumLockMask (1 << 21) | ||
15 | 48 | #define CompScrollLockMask (1 << 22) | ||
17 | 49 | 42 | ||
18 | 50 | #define SCREEN_EDGE_LEFT (1 << 0) | 43 | #define SCREEN_EDGE_LEFT (1 << 0) |
19 | 51 | #define SCREEN_EDGE_RIGHT (1 << 1) | 44 | #define SCREEN_EDGE_RIGHT (1 << 1) |
20 | @@ -56,15 +49,10 @@ | |||
21 | 56 | #define SCREEN_EDGE_BOTTOMLEFT (1 << 6) | 49 | #define SCREEN_EDGE_BOTTOMLEFT (1 << 6) |
22 | 57 | #define SCREEN_EDGE_BOTTOMRIGHT (1 << 7) | 50 | #define SCREEN_EDGE_BOTTOMRIGHT (1 << 7) |
23 | 58 | 51 | ||
31 | 59 | struct _Modifier | 52 | struct _Modifier modifierList[] = { |
25 | 60 | { | ||
26 | 61 | char *name; | ||
27 | 62 | int modifier; | ||
28 | 63 | } | ||
29 | 64 | |||
30 | 65 | modifierList[] = { | ||
32 | 66 | { "<Shift>", ShiftMask }, | 53 | { "<Shift>", ShiftMask }, |
33 | 67 | { "<Control>", ControlMask }, | 54 | { "<Control>", ControlMask }, |
34 | 55 | { "<Primary>", ControlMask }, | ||
35 | 68 | { "<Mod1>", Mod1Mask }, | 56 | { "<Mod1>", Mod1Mask }, |
36 | 69 | { "<Mod2>", Mod2Mask }, | 57 | { "<Mod2>", Mod2Mask }, |
37 | 70 | { "<Mod3>", Mod3Mask }, | 58 | { "<Mod3>", Mod3Mask }, |
38 | @@ -77,8 +65,6 @@ | |||
39 | 77 | { "<ModeSwitch>", CompModeSwitchMask }, | 65 | { "<ModeSwitch>", CompModeSwitchMask }, |
40 | 78 | }; | 66 | }; |
41 | 79 | 67 | ||
42 | 80 | #define N_MODIFIERS (sizeof (modifierList) / sizeof (struct _Modifier)) | ||
43 | 81 | |||
44 | 82 | struct _Edge { | 68 | struct _Edge { |
45 | 83 | char *name; | 69 | char *name; |
46 | 84 | char *modName; | 70 | char *modName; |
47 | @@ -98,9 +84,15 @@ | |||
48 | 98 | 84 | ||
49 | 99 | #define N_EDGES (sizeof (edgeList) / sizeof (edgeList[0])) | 85 | #define N_EDGES (sizeof (edgeList) / sizeof (edgeList[0])) |
50 | 100 | 86 | ||
51 | 87 | unsigned int | ||
52 | 88 | ccsInternalUtilNumModifiers () | ||
53 | 89 | { | ||
54 | 90 | return sizeof (modifierList) / sizeof (struct _Modifier); | ||
55 | 91 | } | ||
56 | 92 | |||
57 | 101 | static char * | 93 | static char * |
60 | 102 | stringAppend (char *s, | 94 | stringAppend (char *s, |
61 | 103 | char *a) | 95 | const char *a) |
62 | 104 | { | 96 | { |
63 | 105 | char *r; | 97 | char *r; |
64 | 106 | int len; | 98 | int len; |
65 | @@ -133,16 +125,48 @@ | |||
66 | 133 | return s; | 125 | return s; |
67 | 134 | } | 126 | } |
68 | 135 | 127 | ||
69 | 128 | void | ||
70 | 129 | ccsAddKeybindingMaskToString (char **bindingString, | ||
71 | 130 | unsigned int matchBindingMask, | ||
72 | 131 | unsigned int *addedBindingMask, | ||
73 | 132 | unsigned int addBindingMask, | ||
74 | 133 | const char *addBindingString) | ||
75 | 134 | { | ||
76 | 135 | if (addBindingMask & matchBindingMask && | ||
77 | 136 | !(*addedBindingMask & addBindingMask)) | ||
78 | 137 | { | ||
79 | 138 | *bindingString = stringAppend (*bindingString, addBindingString); | ||
80 | 139 | *addedBindingMask |= addBindingMask; | ||
81 | 140 | } | ||
82 | 141 | } | ||
83 | 142 | |||
84 | 143 | |||
85 | 144 | void | ||
86 | 145 | ccsAddStringToKeybindingMask (unsigned int *bindingMask, | ||
87 | 146 | const char *bindingString, | ||
88 | 147 | unsigned int addBindingMask, | ||
89 | 148 | const char *addBindingString) | ||
90 | 149 | { | ||
91 | 150 | if (strcasestr (bindingString, addBindingString)) | ||
92 | 151 | { | ||
93 | 152 | *bindingMask |= addBindingMask; | ||
94 | 153 | } | ||
95 | 154 | } | ||
96 | 155 | |||
97 | 136 | char * | 156 | char * |
98 | 137 | ccsModifiersToString (unsigned int modMask) | 157 | ccsModifiersToString (unsigned int modMask) |
99 | 138 | { | 158 | { |
101 | 139 | char *binding = NULL; | 159 | char *binding = NULL; |
102 | 160 | unsigned int addedBindings = 0; | ||
103 | 140 | int i; | 161 | int i; |
104 | 141 | 162 | ||
106 | 142 | for (i = 0; i < N_MODIFIERS; i++) | 163 | for (i = 0; i < ccsInternalUtilNumModifiers (); i++) |
107 | 143 | { | 164 | { |
110 | 144 | if (modMask & modifierList[i].modifier) | 165 | ccsAddKeybindingMaskToString (&binding, |
111 | 145 | binding = stringAppend (binding, modifierList[i].name); | 166 | modMask, |
112 | 167 | &addedBindings, | ||
113 | 168 | modifierList[i].modifier, | ||
114 | 169 | modifierList[i].name); | ||
115 | 146 | } | 170 | } |
116 | 147 | 171 | ||
117 | 148 | return binding; | 172 | return binding; |
118 | @@ -235,10 +259,12 @@ | |||
119 | 235 | unsigned int mods = 0; | 259 | unsigned int mods = 0; |
120 | 236 | int i; | 260 | int i; |
121 | 237 | 261 | ||
123 | 238 | for (i = 0; i < N_MODIFIERS; i++) | 262 | for (i = 0; i < ccsInternalUtilNumModifiers (); i++) |
124 | 239 | { | 263 | { |
127 | 240 | if (strcasestr (binding, modifierList[i].name)) | 264 | ccsAddStringToKeybindingMask (&mods, |
128 | 241 | mods |= modifierList[i].modifier; | 265 | binding, |
129 | 266 | modifierList[i].modifier, | ||
130 | 267 | modifierList[i].name); | ||
131 | 242 | } | 268 | } |
132 | 243 | 269 | ||
133 | 244 | return mods; | 270 | return mods; |
134 | 245 | 271 | ||
135 | === added file 'compizconfig/libcompizconfig/src/ccs-modifier-list-inl.h' | |||
136 | --- compizconfig/libcompizconfig/src/ccs-modifier-list-inl.h 1970-01-01 00:00:00 +0000 | |||
137 | +++ compizconfig/libcompizconfig/src/ccs-modifier-list-inl.h 2012-10-10 12:52:21 +0000 | |||
138 | @@ -0,0 +1,50 @@ | |||
139 | 1 | /* | ||
140 | 2 | * Compiz configuration system library | ||
141 | 3 | * | ||
142 | 4 | * Copyright (C) 2007 Danny Baumann <maniac@opencompositing.org> | ||
143 | 5 | * | ||
144 | 6 | * This library is free software; you can redistribute it and/or | ||
145 | 7 | * modify it under the terms of the GNU Lesser General Public | ||
146 | 8 | * License as published by the Free Software Foundation; either | ||
147 | 9 | * version 2.1 of the License, or (at your option) any later version. | ||
148 | 10 | |||
149 | 11 | * This library is distributed in the hope that it will be useful, | ||
150 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
151 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
152 | 14 | * Lesser General Public License for more details. | ||
153 | 15 | |||
154 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
155 | 17 | * License along with this library; if not, write to the Free Software | ||
156 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
157 | 19 | */ | ||
158 | 20 | |||
159 | 21 | #ifndef _CCS_MODIFIER_LIST_INL_H | ||
160 | 22 | #define _CCS_MODIFIER_LIST_INL_H | ||
161 | 23 | |||
162 | 24 | #include <ccs-defs.h> | ||
163 | 25 | |||
164 | 26 | COMPIZCONFIG_BEGIN_DECLS | ||
165 | 27 | |||
166 | 28 | #include <X11/X.h> | ||
167 | 29 | #include <X11/Xlib.h> | ||
168 | 30 | |||
169 | 31 | #define CompAltMask (1 << 16) | ||
170 | 32 | #define CompMetaMask (1 << 17) | ||
171 | 33 | #define CompSuperMask (1 << 18) | ||
172 | 34 | #define CompHyperMask (1 << 19) | ||
173 | 35 | #define CompModeSwitchMask (1 << 20) | ||
174 | 36 | #define CompNumLockMask (1 << 21) | ||
175 | 37 | #define CompScrollLockMask (1 << 22) | ||
176 | 38 | |||
177 | 39 | struct _Modifier | ||
178 | 40 | { | ||
179 | 41 | char *name; | ||
180 | 42 | int modifier; | ||
181 | 43 | }; | ||
182 | 44 | |||
183 | 45 | extern struct _Modifier modifierList[]; | ||
184 | 46 | unsigned int ccsInternalUtilNumModifiers (); | ||
185 | 47 | |||
186 | 48 | COMPIZCONFIG_END_DECLS | ||
187 | 49 | |||
188 | 50 | #endif | ||
189 | 0 | 51 | ||
190 | === modified file 'compizconfig/libcompizconfig/src/ccs-private.h' | |||
191 | --- compizconfig/libcompizconfig/src/ccs-private.h 2012-09-10 01:06:55 +0000 | |||
192 | +++ compizconfig/libcompizconfig/src/ccs-private.h 2012-10-10 12:52:21 +0000 | |||
193 | @@ -22,6 +22,10 @@ | |||
194 | 22 | #ifndef CCS_PRIVATE_H | 22 | #ifndef CCS_PRIVATE_H |
195 | 23 | #define CSS_PRIVATE_H | 23 | #define CSS_PRIVATE_H |
196 | 24 | 24 | ||
197 | 25 | #include <ccs-defs.h> | ||
198 | 26 | |||
199 | 27 | COMPIZCONFIG_BEGIN_DECLS | ||
200 | 28 | |||
201 | 25 | #include <ccs.h> | 29 | #include <ccs.h> |
202 | 26 | #include <ccs-backend.h> | 30 | #include <ccs-backend.h> |
203 | 27 | 31 | ||
204 | @@ -158,4 +162,19 @@ | |||
205 | 158 | unsigned int ccsAddConfigWatch (CCSContext *context, | 162 | unsigned int ccsAddConfigWatch (CCSContext *context, |
206 | 159 | FileWatchCallbackProc callback); | 163 | FileWatchCallbackProc callback); |
207 | 160 | 164 | ||
208 | 165 | void | ||
209 | 166 | ccsAddKeybindingMaskToString (char **bindingString, | ||
210 | 167 | unsigned int matchBindingMask, | ||
211 | 168 | unsigned int *addedBindingMask, | ||
212 | 169 | unsigned int addBindingMask, | ||
213 | 170 | const char *addBindingString); | ||
214 | 171 | |||
215 | 172 | void | ||
216 | 173 | ccsAddStringToKeybindingMask (unsigned int *bindingMask, | ||
217 | 174 | const char *bindingString, | ||
218 | 175 | unsigned int addBindingMask, | ||
219 | 176 | const char *addBindingString); | ||
220 | 177 | |||
221 | 178 | COMPIZCONFIG_END_DECLS | ||
222 | 179 | |||
223 | 161 | #endif | 180 | #endif |
224 | 162 | 181 | ||
225 | === modified file 'compizconfig/libcompizconfig/tests/CMakeLists.txt' | |||
226 | --- compizconfig/libcompizconfig/tests/CMakeLists.txt 2012-09-25 08:39:18 +0000 | |||
227 | +++ compizconfig/libcompizconfig/tests/CMakeLists.txt 2012-10-10 12:52:21 +0000 | |||
228 | @@ -32,6 +32,9 @@ | |||
229 | 32 | add_executable (compizconfig_test_ccs_mock_backend_conformance | 32 | add_executable (compizconfig_test_ccs_mock_backend_conformance |
230 | 33 | ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp) | 33 | ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp) |
231 | 34 | 34 | ||
232 | 35 | add_executable (compizconfig_test_ccs_util | ||
233 | 36 | ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_util.cpp) | ||
234 | 37 | |||
235 | 35 | add_executable (compizconfig_test_ccs_upgrade_internal | 38 | add_executable (compizconfig_test_ccs_upgrade_internal |
236 | 36 | ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_settings_upgrade_internal.cpp) | 39 | ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_settings_upgrade_internal.cpp) |
237 | 37 | 40 | ||
238 | @@ -136,6 +139,14 @@ | |||
239 | 136 | compizconfig_ccs_setting_value_matcher | 139 | compizconfig_ccs_setting_value_matcher |
240 | 137 | ) | 140 | ) |
241 | 138 | 141 | ||
242 | 142 | target_link_libraries (compizconfig_test_ccs_util | ||
243 | 143 | ${GTEST_BOTH_LIBRARIES} | ||
244 | 144 | ${GMOCK_LIBRARY} | ||
245 | 145 | ${GMOCK_MAIN_LIBRARY} | ||
246 | 146 | ${CMAKE_THREAD_LIBS_INIT} | ||
247 | 147 | compizconfig | ||
248 | 148 | ) | ||
249 | 149 | |||
250 | 139 | compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) | 150 | compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) |
251 | 140 | compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock) | 151 | compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock) |
252 | 141 | compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock) | 152 | compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock) |
253 | @@ -143,3 +154,4 @@ | |||
254 | 143 | compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock) | 154 | compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock) |
255 | 144 | compiz_discover_tests (compizconfig_test_ccs_text_file COVERAGE ccs_text_file_interface compizconfig_ccs_text_file_mock) | 155 | compiz_discover_tests (compizconfig_test_ccs_text_file COVERAGE ccs_text_file_interface compizconfig_ccs_text_file_mock) |
256 | 145 | compiz_discover_tests (compizconfig_test_ccs_upgrade_internal COVERAGE ccs_settings_upgrade_internal) | 156 | compiz_discover_tests (compizconfig_test_ccs_upgrade_internal COVERAGE ccs_settings_upgrade_internal) |
257 | 157 | compiz_discover_tests (compizconfig_test_ccs_util COVERAGE compizconfig) | ||
258 | 146 | 158 | ||
259 | === added file 'compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp' | |||
260 | --- compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp 1970-01-01 00:00:00 +0000 | |||
261 | +++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp 2012-10-10 12:52:21 +0000 | |||
262 | @@ -0,0 +1,238 @@ | |||
263 | 1 | /* | ||
264 | 2 | * Compiz configuration system library | ||
265 | 3 | * | ||
266 | 4 | * Copyright (C) 2007 Dennis Kasprzyk <onestone@opencompositing.org> | ||
267 | 5 | * Copyright (C) 2007 Danny Baumann <maniac@opencompositing.org> | ||
268 | 6 | * | ||
269 | 7 | * This library is free software; you can redistribute it and/or | ||
270 | 8 | * modify it under the terms of the GNU Lesser General Public | ||
271 | 9 | * License as published by the Free Software Foundation; either | ||
272 | 10 | * version 2.1 of the License, or (at your option) any later version. | ||
273 | 11 | |||
274 | 12 | * This library is distributed in the hope that it will be useful, | ||
275 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
276 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
277 | 15 | * Lesser General Public License for more details. | ||
278 | 16 | |||
279 | 17 | * You should have received a copy of the GNU Lesser General Public | ||
280 | 18 | * License along with this library; if not, write to the Free Software | ||
281 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
282 | 20 | */ | ||
283 | 21 | |||
284 | 22 | #include <gtest/gtest.h> | ||
285 | 23 | #include <gtest_shared_characterwrapper.h> | ||
286 | 24 | |||
287 | 25 | #include <ccs.h> | ||
288 | 26 | #include <ccs-private.h> | ||
289 | 27 | #include <ccs-modifier-list-inl.h> | ||
290 | 28 | |||
291 | 29 | using ::testing::WithParamInterface; | ||
292 | 30 | |||
293 | 31 | namespace | ||
294 | 32 | { | ||
295 | 33 | const std::string firstBindingString = "<First>"; | ||
296 | 34 | const std::string secondBindingString = "<Second>"; | ||
297 | 35 | |||
298 | 36 | const unsigned int firstBindingMask = (1 << 0); | ||
299 | 37 | const unsigned int secondBindingMask = (1 << 1); | ||
300 | 38 | } | ||
301 | 39 | |||
302 | 40 | TEST (CCSUtilTest, TestAddKeybindingMaskToStringInitial) | ||
303 | 41 | { | ||
304 | 42 | char *bindingStringChar = NULL; | ||
305 | 43 | unsigned int addedBindingMask = 0; | ||
306 | 44 | |||
307 | 45 | ccsAddKeybindingMaskToString (&bindingStringChar, | ||
308 | 46 | firstBindingMask, | ||
309 | 47 | &addedBindingMask, | ||
310 | 48 | firstBindingMask, | ||
311 | 49 | firstBindingString.c_str ()); | ||
312 | 50 | |||
313 | 51 | CharacterWrapper bindingString (bindingStringChar); | ||
314 | 52 | |||
315 | 53 | EXPECT_EQ (firstBindingString, bindingStringChar); | ||
316 | 54 | EXPECT_EQ (addedBindingMask, firstBindingMask); | ||
317 | 55 | } | ||
318 | 56 | |||
319 | 57 | TEST (CCSUtilTest, TestAddKeybindingMaskToStringNoDuplicates) | ||
320 | 58 | { | ||
321 | 59 | char *bindingStringChar = NULL; | ||
322 | 60 | unsigned int addedBindingMask = 0; | ||
323 | 61 | |||
324 | 62 | ccsAddKeybindingMaskToString (&bindingStringChar, | ||
325 | 63 | firstBindingMask, | ||
326 | 64 | &addedBindingMask, | ||
327 | 65 | firstBindingMask, | ||
328 | 66 | firstBindingString.c_str ()); | ||
329 | 67 | |||
330 | 68 | ccsAddKeybindingMaskToString (&bindingStringChar, | ||
331 | 69 | firstBindingMask, | ||
332 | 70 | &addedBindingMask, | ||
333 | 71 | firstBindingMask, | ||
334 | 72 | secondBindingString.c_str ()); | ||
335 | 73 | |||
336 | 74 | CharacterWrapper bindingString (bindingStringChar); | ||
337 | 75 | |||
338 | 76 | EXPECT_EQ (firstBindingString, bindingStringChar); | ||
339 | 77 | EXPECT_EQ (addedBindingMask, firstBindingMask); | ||
340 | 78 | } | ||
341 | 79 | |||
342 | 80 | TEST (CCSUtilTest, TestAddStringToKeybindingMask) | ||
343 | 81 | { | ||
344 | 82 | unsigned int bindingMask = 0; | ||
345 | 83 | |||
346 | 84 | ccsAddStringToKeybindingMask (&bindingMask, | ||
347 | 85 | firstBindingString.c_str (), | ||
348 | 86 | firstBindingMask, | ||
349 | 87 | firstBindingString.c_str ()); | ||
350 | 88 | |||
351 | 89 | EXPECT_EQ (bindingMask, firstBindingMask); | ||
352 | 90 | } | ||
353 | 91 | |||
354 | 92 | namespace | ||
355 | 93 | { | ||
356 | 94 | class ModifierParam | ||
357 | 95 | { | ||
358 | 96 | public: | ||
359 | 97 | |||
360 | 98 | ModifierParam (const char *modifierString, | ||
361 | 99 | unsigned int modifierMask, | ||
362 | 100 | bool match) : | ||
363 | 101 | mModifierString (modifierString), | ||
364 | 102 | mModifierMask (modifierMask), | ||
365 | 103 | mMatch (match) | ||
366 | 104 | { | ||
367 | 105 | } | ||
368 | 106 | |||
369 | 107 | ModifierParam (const ModifierParam ¶m) : | ||
370 | 108 | mModifierString (param.mModifierString), | ||
371 | 109 | mModifierMask (param.mModifierMask), | ||
372 | 110 | mMatch (param.mMatch) | ||
373 | 111 | { | ||
374 | 112 | } | ||
375 | 113 | |||
376 | 114 | friend void swap (ModifierParam &lhs, ModifierParam &rhs) | ||
377 | 115 | { | ||
378 | 116 | using std::swap; | ||
379 | 117 | |||
380 | 118 | swap (lhs.mMatch, rhs.mMatch); | ||
381 | 119 | swap (lhs.mModifierMask, rhs.mModifierMask); | ||
382 | 120 | swap (lhs.mModifierString, rhs.mModifierString); | ||
383 | 121 | } | ||
384 | 122 | |||
385 | 123 | ModifierParam & | ||
386 | 124 | operator= (const ModifierParam &other) | ||
387 | 125 | { | ||
388 | 126 | ModifierParam to (other); | ||
389 | 127 | swap (*this, to); | ||
390 | 128 | return *this; | ||
391 | 129 | } | ||
392 | 130 | |||
393 | 131 | std::string mModifierString; | ||
394 | 132 | unsigned int mModifierMask; | ||
395 | 133 | bool mMatch; | ||
396 | 134 | }; | ||
397 | 135 | |||
398 | 136 | ::testing::internal::ParamGenerator<ModifierParam> | ||
399 | 137 | GenerateModifierParams () | ||
400 | 138 | { | ||
401 | 139 | std::vector <ModifierParam> params; | ||
402 | 140 | params.reserve (ccsInternalUtilNumModifiers () * | ||
403 | 141 | ccsInternalUtilNumModifiers ()); | ||
404 | 142 | |||
405 | 143 | for (unsigned int i = 0; i < ccsInternalUtilNumModifiers (); ++i) | ||
406 | 144 | { | ||
407 | 145 | if (modifierList[i].name == std::string ("<Primary>")) | ||
408 | 146 | continue; | ||
409 | 147 | |||
410 | 148 | for (unsigned int j = 0; j < ccsInternalUtilNumModifiers (); ++j) | ||
411 | 149 | { | ||
412 | 150 | const bool modifierMatch = modifierList[i].modifier == | ||
413 | 151 | modifierList[j].modifier; | ||
414 | 152 | |||
415 | 153 | params.push_back (ModifierParam (modifierList[i].name, | ||
416 | 154 | modifierList[j].modifier, | ||
417 | 155 | modifierMatch)); | ||
418 | 156 | } | ||
419 | 157 | } | ||
420 | 158 | |||
421 | 159 | return ::testing::ValuesIn (params); | ||
422 | 160 | } | ||
423 | 161 | |||
424 | 162 | bool | ||
425 | 163 | CheckModifierListSanity () | ||
426 | 164 | { | ||
427 | 165 | return (modifierList[0].modifier != | ||
428 | 166 | modifierList[1].modifier) && | ||
429 | 167 | (std::string (modifierList[0].name) != | ||
430 | 168 | std::string (modifierList[1].name)); | ||
431 | 169 | } | ||
432 | 170 | |||
433 | 171 | const char *modifierSanityMsg = "This test requires the name and modifier " \ | ||
434 | 172 | "value in modifierList[0] and " \ | ||
435 | 173 | "modifierList[1] to be different " \ | ||
436 | 174 | "to work correctly"; | ||
437 | 175 | } | ||
438 | 176 | |||
439 | 177 | class CCSUtilModifiersTest : | ||
440 | 178 | public ::testing::Test, | ||
441 | 179 | public WithParamInterface <ModifierParam> | ||
442 | 180 | { | ||
443 | 181 | }; | ||
444 | 182 | |||
445 | 183 | TEST_P (CCSUtilModifiersTest, TestModifiersToString) | ||
446 | 184 | { | ||
447 | 185 | CharacterWrapper modifierString (ccsModifiersToString (GetParam ().mModifierMask)); | ||
448 | 186 | char *modifierStringChar = modifierString; | ||
449 | 187 | /* Force "<Primary>" to test as "<Control>" as "<Primary>" | ||
450 | 188 | * should never be reachable */ | ||
451 | 189 | const std::string expectedModifierString (GetParam ().mModifierString != | ||
452 | 190 | std::string ("<Primary>") ? | ||
453 | 191 | GetParam ().mModifierString : | ||
454 | 192 | "<Control>"); | ||
455 | 193 | |||
456 | 194 | if (GetParam ().mMatch) | ||
457 | 195 | EXPECT_EQ (expectedModifierString, modifierStringChar); | ||
458 | 196 | else | ||
459 | 197 | EXPECT_NE (expectedModifierString, modifierStringChar); | ||
460 | 198 | } | ||
461 | 199 | |||
462 | 200 | TEST_P (CCSUtilModifiersTest, TestStringToModifiers) | ||
463 | 201 | { | ||
464 | 202 | unsigned int modifierMask (ccsStringToModifiers (GetParam ().mModifierString.c_str ())); | ||
465 | 203 | |||
466 | 204 | if (GetParam ().mMatch) | ||
467 | 205 | EXPECT_EQ (GetParam ().mModifierMask, modifierMask); | ||
468 | 206 | else | ||
469 | 207 | EXPECT_NE (GetParam ().mModifierMask, modifierMask); | ||
470 | 208 | } | ||
471 | 209 | |||
472 | 210 | INSTANTIATE_TEST_CASE_P (CCSRealModifiers, CCSUtilModifiersTest, | ||
473 | 211 | GenerateModifierParams ()); | ||
474 | 212 | |||
475 | 213 | TEST (CCSUtilModifierTest, TestMultiModifierToString) | ||
476 | 214 | { | ||
477 | 215 | ASSERT_TRUE (CheckModifierListSanity ()) << modifierSanityMsg; | ||
478 | 216 | |||
479 | 217 | const unsigned int modifierMask = modifierList[0].modifier | | ||
480 | 218 | modifierList[1].modifier; | ||
481 | 219 | const std::string expectedModifierString = std::string (modifierList[0].name) + | ||
482 | 220 | std::string (modifierList[1].name); | ||
483 | 221 | CharacterWrapper modifierString (ccsModifiersToString (modifierMask)); | ||
484 | 222 | const char *modifierStringChar = modifierString; | ||
485 | 223 | |||
486 | 224 | EXPECT_EQ (expectedModifierString, modifierStringChar); | ||
487 | 225 | } | ||
488 | 226 | |||
489 | 227 | TEST (CCSUtilModifierTest, TestMultiStringToModifier) | ||
490 | 228 | { | ||
491 | 229 | ASSERT_TRUE (CheckModifierListSanity ()) << modifierSanityMsg; | ||
492 | 230 | |||
493 | 231 | const unsigned int expectedModifierMask = modifierList[0].modifier | | ||
494 | 232 | modifierList[1].modifier; | ||
495 | 233 | const std::string modifierString = std::string (modifierList[0].name) + | ||
496 | 234 | std::string (modifierList[1].name); | ||
497 | 235 | unsigned int modifierMask = (ccsStringToModifiers (modifierString.c_str ())); | ||
498 | 236 | |||
499 | 237 | EXPECT_EQ (expectedModifierMask, modifierMask); | ||
500 | 238 | } |
Note, jenkins will probably mark this needs fixing because of conflicts with a distro patch. That distro patch should be dropped as its effectively made redundant by this branch.