Merge lp:~compiz-team/compiz/compiz.fix_1058577 into lp:compiz/0.9.9

Proposed by Sam Spilsbury
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
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>.

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

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.

Revision history for this message
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal
Download full text (5.3 KiB)

Sorry, but gcc sucks at template error messages:

[ 40%] Building CXX object compizconfig/libcompizconfig/tests/CMakeFiles/compizconfig_test_ccs_util.dir/compizconfig_test_ccs_util.cpp.o
In file included from /usr/include/c++/4.6/vector:70:0,
                 from /usr/include/gtest/gtest.h:55,
                 from /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp:22:
/usr/include/c++/4.6/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {{anonymous}::ModifierParam}, _Tp = {anonymous}::ModifierParam, _Alloc = std::allocator<{anonymous}::ModifierParam>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<{anonymous}::ModifierParam*, std::vector<{anonymous}::ModifierParam> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = {anonymous}::ModifierParam*]’:
/usr/include/c++/4.6/bits/vector.tcc:102:4: instantiated from ‘void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {{anonymous}::ModifierParam}, _Tp = {anonymous}::ModifierParam, _Alloc = std::allocator<{anonymous}::ModifierParam>]’
/usr/include/c++/4.6/bits/stl_vector.h:840:9: instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = {anonymous}::ModifierParam, _Alloc = std::allocator<{anonymous}::ModifierParam>, std::vector<_Tp, _Alloc>::value_type = {anonymous}::ModifierParam]’
/home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp:131:22: instantiated from here
/usr/include/c++/4.6/bits/vector.tcc:319:4: error: use of deleted function ‘{anonymous}::ModifierParam& {anonymous}::ModifierParam::operator=(const {anonymous}::ModifierParam&)’
/home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp:94:11: error: ‘{anonymous}::ModifierParam& {anonymous}::ModifierParam::operator=(const {anonymous}::ModifierParam&)’ is implicitly deleted because the default definition would be ill-formed:
/home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp:94:11: error: passing ‘const string {aka const std::basic_string<char>}’ as ‘this’ argument of ‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>]’ discards qualifiers [-fpermissive]
In file included from /usr/include/c++/4.6/vector:61:0,
                 from /usr/include/gtest/gtest.h:55,
                 from /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp:22:
/usr/include/c++/4.6/bits/stl_algobase.h: In static member function ‘static _BI2 std::__copy_move_backward<true, false, std::random_access_iterator_tag>::__copy_move_b(_BI1, _BI1, _BI2) [with _BI1 = {anonymous}::ModifierParam*, _BI2 = {anonymous}::ModifierParam*]’:
/usr/include/c++/4.6/bits/stl_algobase.h:581:18: instantiated from ‘_BI2 std::_...

Read more...

review: Needs Fixing
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal
Download full text (5.6 KiB)

> Sorry, but gcc sucks at template error messages:
>
> [ 40%] Building CXX object compizconfig/libcompizconfig/tests/CMakeFiles/compi
> zconfig_test_ccs_util.dir/compizconfig_test_ccs_util.cpp.o
> In file included from /usr/include/c++/4.6/vector:70:0,
> from /usr/include/gtest/gtest.h:55,
> from /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfi
> g/tests/compizconfig_test_ccs_util.cpp:22:
> /usr/include/c++/4.6/bits/vector.tcc: In member function ‘void
> std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator,
> _Args&& ...) [with _Args = {{anonymous}::ModifierParam}, _Tp =
> {anonymous}::ModifierParam, _Alloc =
> std::allocator<{anonymous}::ModifierParam>, std::vector<_Tp, _Alloc>::iterator
> = __gnu_cxx::__normal_iterator<{anonymous}::ModifierParam*,
> std::vector<{anonymous}::ModifierParam> >, typename std::_Vector_base<_Tp,
> _Alloc>::_Tp_alloc_type::pointer = {anonymous}::ModifierParam*]’:
> /usr/include/c++/4.6/bits/vector.tcc:102:4: instantiated from ‘void
> std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args =
> {{anonymous}::ModifierParam}, _Tp = {anonymous}::ModifierParam, _Alloc =
> std::allocator<{anonymous}::ModifierParam>]’
> /usr/include/c++/4.6/bits/stl_vector.h:840:9: instantiated from ‘void
> std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&)
> [with _Tp = {anonymous}::ModifierParam, _Alloc =
> std::allocator<{anonymous}::ModifierParam>, std::vector<_Tp,
> _Alloc>::value_type = {anonymous}::ModifierParam]’
> /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_t
> est_ccs_util.cpp:131:22: instantiated from here
> /usr/include/c++/4.6/bits/vector.tcc:319:4: error: use of deleted function
> ‘{anonymous}::ModifierParam& {anonymous}::ModifierParam::operator=(const
> {anonymous}::ModifierParam&)’
> /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_t
> est_ccs_util.cpp:94:11: error: ‘{anonymous}::ModifierParam&
> {anonymous}::ModifierParam::operator=(const {anonymous}::ModifierParam&)’ is
> implicitly deleted because the default definition would be ill-formed:
> /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfig/tests/compizconfig_t
> est_ccs_util.cpp:94:11: error: passing ‘const string {aka const
> std::basic_string<char>}’ as ‘this’ argument of ‘std::basic_string<_CharT,
> _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const
> std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits =
> std::char_traits<char>, _Alloc = std::allocator<char>,
> std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>]’
> discards qualifiers [-fpermissive]
> In file included from /usr/include/c++/4.6/vector:61:0,
> from /usr/include/gtest/gtest.h:55,
> from /home/dan/bzr/compiz/tmp.577/compizconfig/libcompizconfi
> g/tests/compizconfig_test_ccs_util.cpp:22:
> /usr/include/c++/4.6/bits/stl_algobase.h: In static member function ‘static
> _BI2 std::__copy_move_backward<true, false,
> std::random_access_iterator_tag>::__copy_move_b(_BI1, _BI1, _BI2) [with _BI1 =
> {anonymous}::ModifierParam*, _BI2 = {anony...

Read more...

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal

Seems OK now.

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

Note that tarmac will probably reject this due to the distro patch

Revision history for this message
Unity Merger (unity-merger) wrote : Posted in a previous version of this proposal

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-compiz-core/308/console reported an error when processing this lp:~compiz-team/compiz/compiz.fix_1058577 branch.
Not merging it.

Revision history for this message
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.

Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

As above

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Isn't this the same revision I approved already in a different submission?

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

P.S. Jenkins can't ever pass until the similar distro patch is removed from lp:ubuntu/compiz: primary_is_control.patch

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
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

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

OK, I have hacked away the offending reference to primary_is_control.patch in lp:~compiz-team/compiz/ubuntu

Try again.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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 #include <X11/Xlib.h>
6
7 #include <ccs.h>
8-
9-#define CompAltMask (1 << 16)
10-#define CompMetaMask (1 << 17)
11-#define CompSuperMask (1 << 18)
12-#define CompHyperMask (1 << 19)
13-#define CompModeSwitchMask (1 << 20)
14-#define CompNumLockMask (1 << 21)
15-#define CompScrollLockMask (1 << 22)
16+#include <ccs-modifier-list-inl.h>
17
18 #define SCREEN_EDGE_LEFT (1 << 0)
19 #define SCREEN_EDGE_RIGHT (1 << 1)
20@@ -56,15 +49,10 @@
21 #define SCREEN_EDGE_BOTTOMLEFT (1 << 6)
22 #define SCREEN_EDGE_BOTTOMRIGHT (1 << 7)
23
24-struct _Modifier
25-{
26- char *name;
27- int modifier;
28-}
29-
30-modifierList[] = {
31+struct _Modifier modifierList[] = {
32 { "<Shift>", ShiftMask },
33 { "<Control>", ControlMask },
34+ { "<Primary>", ControlMask },
35 { "<Mod1>", Mod1Mask },
36 { "<Mod2>", Mod2Mask },
37 { "<Mod3>", Mod3Mask },
38@@ -77,8 +65,6 @@
39 { "<ModeSwitch>", CompModeSwitchMask },
40 };
41
42-#define N_MODIFIERS (sizeof (modifierList) / sizeof (struct _Modifier))
43-
44 struct _Edge {
45 char *name;
46 char *modName;
47@@ -98,9 +84,15 @@
48
49 #define N_EDGES (sizeof (edgeList) / sizeof (edgeList[0]))
50
51+unsigned int
52+ccsInternalUtilNumModifiers ()
53+{
54+ return sizeof (modifierList) / sizeof (struct _Modifier);
55+}
56+
57 static char *
58-stringAppend (char *s,
59- char *a)
60+stringAppend (char *s,
61+ const char *a)
62 {
63 char *r;
64 int len;
65@@ -133,16 +125,48 @@
66 return s;
67 }
68
69+void
70+ccsAddKeybindingMaskToString (char **bindingString,
71+ unsigned int matchBindingMask,
72+ unsigned int *addedBindingMask,
73+ unsigned int addBindingMask,
74+ const char *addBindingString)
75+{
76+ if (addBindingMask & matchBindingMask &&
77+ !(*addedBindingMask & addBindingMask))
78+ {
79+ *bindingString = stringAppend (*bindingString, addBindingString);
80+ *addedBindingMask |= addBindingMask;
81+ }
82+}
83+
84+
85+void
86+ccsAddStringToKeybindingMask (unsigned int *bindingMask,
87+ const char *bindingString,
88+ unsigned int addBindingMask,
89+ const char *addBindingString)
90+{
91+ if (strcasestr (bindingString, addBindingString))
92+ {
93+ *bindingMask |= addBindingMask;
94+ }
95+}
96+
97 char *
98 ccsModifiersToString (unsigned int modMask)
99 {
100- char *binding = NULL;
101+ char *binding = NULL;
102+ unsigned int addedBindings = 0;
103 int i;
104
105- for (i = 0; i < N_MODIFIERS; i++)
106+ for (i = 0; i < ccsInternalUtilNumModifiers (); i++)
107 {
108- if (modMask & modifierList[i].modifier)
109- binding = stringAppend (binding, modifierList[i].name);
110+ ccsAddKeybindingMaskToString (&binding,
111+ modMask,
112+ &addedBindings,
113+ modifierList[i].modifier,
114+ modifierList[i].name);
115 }
116
117 return binding;
118@@ -235,10 +259,12 @@
119 unsigned int mods = 0;
120 int i;
121
122- for (i = 0; i < N_MODIFIERS; i++)
123+ for (i = 0; i < ccsInternalUtilNumModifiers (); i++)
124 {
125- if (strcasestr (binding, modifierList[i].name))
126- mods |= modifierList[i].modifier;
127+ ccsAddStringToKeybindingMask (&mods,
128+ binding,
129+ modifierList[i].modifier,
130+ modifierList[i].name);
131 }
132
133 return mods;
134
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+/*
140+ * Compiz configuration system library
141+ *
142+ * Copyright (C) 2007 Danny Baumann <maniac@opencompositing.org>
143+ *
144+ * This library is free software; you can redistribute it and/or
145+ * modify it under the terms of the GNU Lesser General Public
146+ * License as published by the Free Software Foundation; either
147+ * version 2.1 of the License, or (at your option) any later version.
148+
149+ * This library is distributed in the hope that it will be useful,
150+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
151+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
152+ * Lesser General Public License for more details.
153+
154+ * You should have received a copy of the GNU Lesser General Public
155+ * License along with this library; if not, write to the Free Software
156+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
157+ */
158+
159+#ifndef _CCS_MODIFIER_LIST_INL_H
160+#define _CCS_MODIFIER_LIST_INL_H
161+
162+#include <ccs-defs.h>
163+
164+COMPIZCONFIG_BEGIN_DECLS
165+
166+#include <X11/X.h>
167+#include <X11/Xlib.h>
168+
169+#define CompAltMask (1 << 16)
170+#define CompMetaMask (1 << 17)
171+#define CompSuperMask (1 << 18)
172+#define CompHyperMask (1 << 19)
173+#define CompModeSwitchMask (1 << 20)
174+#define CompNumLockMask (1 << 21)
175+#define CompScrollLockMask (1 << 22)
176+
177+struct _Modifier
178+{
179+ char *name;
180+ int modifier;
181+};
182+
183+extern struct _Modifier modifierList[];
184+unsigned int ccsInternalUtilNumModifiers ();
185+
186+COMPIZCONFIG_END_DECLS
187+
188+#endif
189
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 #ifndef CCS_PRIVATE_H
195 #define CSS_PRIVATE_H
196
197+#include <ccs-defs.h>
198+
199+COMPIZCONFIG_BEGIN_DECLS
200+
201 #include <ccs.h>
202 #include <ccs-backend.h>
203
204@@ -158,4 +162,19 @@
205 unsigned int ccsAddConfigWatch (CCSContext *context,
206 FileWatchCallbackProc callback);
207
208+void
209+ccsAddKeybindingMaskToString (char **bindingString,
210+ unsigned int matchBindingMask,
211+ unsigned int *addedBindingMask,
212+ unsigned int addBindingMask,
213+ const char *addBindingString);
214+
215+void
216+ccsAddStringToKeybindingMask (unsigned int *bindingMask,
217+ const char *bindingString,
218+ unsigned int addBindingMask,
219+ const char *addBindingString);
220+
221+COMPIZCONFIG_END_DECLS
222+
223 #endif
224
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 add_executable (compizconfig_test_ccs_mock_backend_conformance
230 ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp)
231
232+add_executable (compizconfig_test_ccs_util
233+ ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_util.cpp)
234+
235 add_executable (compizconfig_test_ccs_upgrade_internal
236 ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_settings_upgrade_internal.cpp)
237
238@@ -136,6 +139,14 @@
239 compizconfig_ccs_setting_value_matcher
240 )
241
242+target_link_libraries (compizconfig_test_ccs_util
243+ ${GTEST_BOTH_LIBRARIES}
244+ ${GMOCK_LIBRARY}
245+ ${GMOCK_MAIN_LIBRARY}
246+ ${CMAKE_THREAD_LIBS_INIT}
247+ compizconfig
248+)
249+
250 compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig)
251 compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock)
252 compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock)
253@@ -143,3 +154,4 @@
254 compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock)
255 compiz_discover_tests (compizconfig_test_ccs_text_file COVERAGE ccs_text_file_interface compizconfig_ccs_text_file_mock)
256 compiz_discover_tests (compizconfig_test_ccs_upgrade_internal COVERAGE ccs_settings_upgrade_internal)
257+compiz_discover_tests (compizconfig_test_ccs_util COVERAGE compizconfig)
258
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+/*
264+ * Compiz configuration system library
265+ *
266+ * Copyright (C) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
267+ * Copyright (C) 2007 Danny Baumann <maniac@opencompositing.org>
268+ *
269+ * This library is free software; you can redistribute it and/or
270+ * modify it under the terms of the GNU Lesser General Public
271+ * License as published by the Free Software Foundation; either
272+ * version 2.1 of the License, or (at your option) any later version.
273+
274+ * This library is distributed in the hope that it will be useful,
275+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
276+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
277+ * Lesser General Public License for more details.
278+
279+ * You should have received a copy of the GNU Lesser General Public
280+ * License along with this library; if not, write to the Free Software
281+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
282+ */
283+
284+#include <gtest/gtest.h>
285+#include <gtest_shared_characterwrapper.h>
286+
287+#include <ccs.h>
288+#include <ccs-private.h>
289+#include <ccs-modifier-list-inl.h>
290+
291+using ::testing::WithParamInterface;
292+
293+namespace
294+{
295+ const std::string firstBindingString = "<First>";
296+ const std::string secondBindingString = "<Second>";
297+
298+ const unsigned int firstBindingMask = (1 << 0);
299+ const unsigned int secondBindingMask = (1 << 1);
300+}
301+
302+TEST (CCSUtilTest, TestAddKeybindingMaskToStringInitial)
303+{
304+ char *bindingStringChar = NULL;
305+ unsigned int addedBindingMask = 0;
306+
307+ ccsAddKeybindingMaskToString (&bindingStringChar,
308+ firstBindingMask,
309+ &addedBindingMask,
310+ firstBindingMask,
311+ firstBindingString.c_str ());
312+
313+ CharacterWrapper bindingString (bindingStringChar);
314+
315+ EXPECT_EQ (firstBindingString, bindingStringChar);
316+ EXPECT_EQ (addedBindingMask, firstBindingMask);
317+}
318+
319+TEST (CCSUtilTest, TestAddKeybindingMaskToStringNoDuplicates)
320+{
321+ char *bindingStringChar = NULL;
322+ unsigned int addedBindingMask = 0;
323+
324+ ccsAddKeybindingMaskToString (&bindingStringChar,
325+ firstBindingMask,
326+ &addedBindingMask,
327+ firstBindingMask,
328+ firstBindingString.c_str ());
329+
330+ ccsAddKeybindingMaskToString (&bindingStringChar,
331+ firstBindingMask,
332+ &addedBindingMask,
333+ firstBindingMask,
334+ secondBindingString.c_str ());
335+
336+ CharacterWrapper bindingString (bindingStringChar);
337+
338+ EXPECT_EQ (firstBindingString, bindingStringChar);
339+ EXPECT_EQ (addedBindingMask, firstBindingMask);
340+}
341+
342+TEST (CCSUtilTest, TestAddStringToKeybindingMask)
343+{
344+ unsigned int bindingMask = 0;
345+
346+ ccsAddStringToKeybindingMask (&bindingMask,
347+ firstBindingString.c_str (),
348+ firstBindingMask,
349+ firstBindingString.c_str ());
350+
351+ EXPECT_EQ (bindingMask, firstBindingMask);
352+}
353+
354+namespace
355+{
356+ class ModifierParam
357+ {
358+ public:
359+
360+ ModifierParam (const char *modifierString,
361+ unsigned int modifierMask,
362+ bool match) :
363+ mModifierString (modifierString),
364+ mModifierMask (modifierMask),
365+ mMatch (match)
366+ {
367+ }
368+
369+ ModifierParam (const ModifierParam &param) :
370+ mModifierString (param.mModifierString),
371+ mModifierMask (param.mModifierMask),
372+ mMatch (param.mMatch)
373+ {
374+ }
375+
376+ friend void swap (ModifierParam &lhs, ModifierParam &rhs)
377+ {
378+ using std::swap;
379+
380+ swap (lhs.mMatch, rhs.mMatch);
381+ swap (lhs.mModifierMask, rhs.mModifierMask);
382+ swap (lhs.mModifierString, rhs.mModifierString);
383+ }
384+
385+ ModifierParam &
386+ operator= (const ModifierParam &other)
387+ {
388+ ModifierParam to (other);
389+ swap (*this, to);
390+ return *this;
391+ }
392+
393+ std::string mModifierString;
394+ unsigned int mModifierMask;
395+ bool mMatch;
396+ };
397+
398+ ::testing::internal::ParamGenerator<ModifierParam>
399+ GenerateModifierParams ()
400+ {
401+ std::vector <ModifierParam> params;
402+ params.reserve (ccsInternalUtilNumModifiers () *
403+ ccsInternalUtilNumModifiers ());
404+
405+ for (unsigned int i = 0; i < ccsInternalUtilNumModifiers (); ++i)
406+ {
407+ if (modifierList[i].name == std::string ("<Primary>"))
408+ continue;
409+
410+ for (unsigned int j = 0; j < ccsInternalUtilNumModifiers (); ++j)
411+ {
412+ const bool modifierMatch = modifierList[i].modifier ==
413+ modifierList[j].modifier;
414+
415+ params.push_back (ModifierParam (modifierList[i].name,
416+ modifierList[j].modifier,
417+ modifierMatch));
418+ }
419+ }
420+
421+ return ::testing::ValuesIn (params);
422+ }
423+
424+ bool
425+ CheckModifierListSanity ()
426+ {
427+ return (modifierList[0].modifier !=
428+ modifierList[1].modifier) &&
429+ (std::string (modifierList[0].name) !=
430+ std::string (modifierList[1].name));
431+ }
432+
433+ const char *modifierSanityMsg = "This test requires the name and modifier " \
434+ "value in modifierList[0] and " \
435+ "modifierList[1] to be different " \
436+ "to work correctly";
437+}
438+
439+class CCSUtilModifiersTest :
440+ public ::testing::Test,
441+ public WithParamInterface <ModifierParam>
442+{
443+};
444+
445+TEST_P (CCSUtilModifiersTest, TestModifiersToString)
446+{
447+ CharacterWrapper modifierString (ccsModifiersToString (GetParam ().mModifierMask));
448+ char *modifierStringChar = modifierString;
449+ /* Force "<Primary>" to test as "<Control>" as "<Primary>"
450+ * should never be reachable */
451+ const std::string expectedModifierString (GetParam ().mModifierString !=
452+ std::string ("<Primary>") ?
453+ GetParam ().mModifierString :
454+ "<Control>");
455+
456+ if (GetParam ().mMatch)
457+ EXPECT_EQ (expectedModifierString, modifierStringChar);
458+ else
459+ EXPECT_NE (expectedModifierString, modifierStringChar);
460+}
461+
462+TEST_P (CCSUtilModifiersTest, TestStringToModifiers)
463+{
464+ unsigned int modifierMask (ccsStringToModifiers (GetParam ().mModifierString.c_str ()));
465+
466+ if (GetParam ().mMatch)
467+ EXPECT_EQ (GetParam ().mModifierMask, modifierMask);
468+ else
469+ EXPECT_NE (GetParam ().mModifierMask, modifierMask);
470+}
471+
472+INSTANTIATE_TEST_CASE_P (CCSRealModifiers, CCSUtilModifiersTest,
473+ GenerateModifierParams ());
474+
475+TEST (CCSUtilModifierTest, TestMultiModifierToString)
476+{
477+ ASSERT_TRUE (CheckModifierListSanity ()) << modifierSanityMsg;
478+
479+ const unsigned int modifierMask = modifierList[0].modifier |
480+ modifierList[1].modifier;
481+ const std::string expectedModifierString = std::string (modifierList[0].name) +
482+ std::string (modifierList[1].name);
483+ CharacterWrapper modifierString (ccsModifiersToString (modifierMask));
484+ const char *modifierStringChar = modifierString;
485+
486+ EXPECT_EQ (expectedModifierString, modifierStringChar);
487+}
488+
489+TEST (CCSUtilModifierTest, TestMultiStringToModifier)
490+{
491+ ASSERT_TRUE (CheckModifierListSanity ()) << modifierSanityMsg;
492+
493+ const unsigned int expectedModifierMask = modifierList[0].modifier |
494+ modifierList[1].modifier;
495+ const std::string modifierString = std::string (modifierList[0].name) +
496+ std::string (modifierList[1].name);
497+ unsigned int modifierMask = (ccsStringToModifiers (modifierString.c_str ()));
498+
499+ EXPECT_EQ (expectedModifierMask, modifierMask);
500+}

Subscribers

People subscribed via source and target branches