Merge lp:~compiz-team/compiz/compiz.tests_1042537.3 into lp:compiz/0.9.8

Proposed by Sam Spilsbury
Status: Merged
Approved by: Daniel van Vugt
Approved revision: 3375
Merged at revision: 3387
Proposed branch: lp:~compiz-team/compiz/compiz.tests_1042537.3
Merge into: lp:compiz/0.9.8
Prerequisite: lp:~compiz-team/compiz/compiz.revert_3353
Diff against target: 4180 lines (+2643/-618)
31 files modified
compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c (+1/-1)
compizconfig/gsettings/tests/test_gsettings_conformance.cpp (+3/-1)
compizconfig/libcompizconfig/include/ccs-defs.h (+3/-0)
compizconfig/libcompizconfig/include/ccs.h (+32/-25)
compizconfig/libcompizconfig/src/CMakeLists.txt (+16/-0)
compizconfig/libcompizconfig/src/ccs-private.h (+0/-3)
compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.c (+241/-10)
compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.h (+12/-0)
compizconfig/libcompizconfig/src/ccs_text_file.c (+212/-0)
compizconfig/libcompizconfig/src/ccs_text_file.h (+49/-0)
compizconfig/libcompizconfig/src/ccs_text_file_interface.c (+50/-0)
compizconfig/libcompizconfig/src/ccs_text_file_interface.h (+67/-0)
compizconfig/libcompizconfig/src/main.c (+131/-265)
compizconfig/libcompizconfig/tests/CMakeLists.txt (+20/-1)
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp (+21/-18)
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_settings_upgrade_internal.cpp (+725/-12)
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_text_file.cpp (+49/-0)
compizconfig/mocks/libcompizconfig/CMakeLists.txt (+11/-0)
compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h (+3/-3)
compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h (+15/-15)
compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h (+18/-18)
compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.cpp (+104/-0)
compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.h (+84/-0)
compizconfig/tests/compizconfig_backend_concept_test.h (+49/-246)
compizconfig/tests/compizconfig_ccs_item_in_list_matcher.h (+106/-0)
compizconfig/tests/compizconfig_ccs_list_equality.h (+74/-0)
compizconfig/tests/compizconfig_ccs_list_wrapper.h (+199/-0)
compizconfig/tests/compizconfig_ccs_list_wrapper.h.moved (+199/-0)
compizconfig/tests/compizconfig_ccs_mocked_allocator.h (+22/-0)
compizconfig/tests/compizconfig_ccs_setting_value_operators.h (+105/-0)
compizconfig/tests/compizconfig_test_value_combiners.h (+22/-0)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.tests_1042537.3
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Tim Penhey (community) Approve
jenkins (community) continuous-integration Approve
Review via email: mp+125993@code.launchpad.net

This proposal supersedes a proposal from 2012-09-10.

Commit message

Put some tests in place for the upgrade code, and optimized the upgrade code in the meantime. Fixes bug 1042537

Description of the change

Put some tests in place for the upgrade code, and optimized the upgrade code in the meantime (some parts of the upgrade code were also totally broken too. Fixed them).

cleanups:
 1) constified part of the interface
 2) fix copyright headers
 3) split out text file read/write code into its own class

This branch was accidentally merged for some reason. I've reverted it and re-proposed it here.

To post a comment you must log in.
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: Approve (continuous-integration)
Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

My first throught is why oh why does

compiz::config::impl::CCSSettingValueListWrapper start with CCS? This prefix is surely no longer needed.

Seems weird to me that you would have a magic length number instead of just calling strlen
  static const char *upgrade = "upgrade";
  static const unsigned int upgrade_str_len = 7; // why not initialize to strlen(upgrade)?

Oh, have I mentioned how much I hate C?

You don't need to include both gtest and gmock. <gmock/gmock.h> includes gtest.h.

None of these comments are blockers to merging.

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

> My first throught is why oh why does
>
> compiz::config::impl::CCSSettingValueListWrapper start with CCS? This prefix
> is surely no longer needed.

You are correct. Shall I remove these here or in a follow up MP based on this one?

>
> Seems weird to me that you would have a magic length number instead of just
> calling strlen
> static const char *upgrade = "upgrade";
> static const unsigned int upgrade_str_len = 7; // why not initialize to
> strlen(upgrade)?

Could also work I guess.

>
> Oh, have I mentioned how much I hate C?

Careful. :)

>
> You don't need to include both gtest and gmock. <gmock/gmock.h> includes
> gtest.h.
>
> None of these comments are blockers to merging.

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

As far as I can tell, this is not required for quantal. So please repropose it after we've branched for 0.9.9.

review: Needs Resubmitting
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

As discussed, this is required for Q, so resubmitted to 0.9.8.4

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tim Penhey (thumper) wrote :

Given the need to get the gsettings stuff under test nicely for Q, I feel we need this.

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

I can't break it at least. Even under valgrind.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c'
2--- compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c 2012-09-10 01:05:28 +0000
3+++ compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c 2012-09-24 12:00:13 +0000
4@@ -343,7 +343,7 @@
5 {
6 CCSSetting *s = (CCSSetting *) iter->data;
7
8- char *name = ccsSettingGetName (s);
9+ const char *name = ccsSettingGetName (s);
10 char *underscores_as_dashes = translateUnderscoresToDashesForGSettings (name);
11
12 if (g_ascii_strncasecmp (underscores_as_dashes, keyName, strlen (keyName)) == 0)
13
14=== modified file 'compizconfig/gsettings/tests/test_gsettings_conformance.cpp'
15--- compizconfig/gsettings/tests/test_gsettings_conformance.cpp 2012-09-10 01:05:28 +0000
16+++ compizconfig/gsettings/tests/test_gsettings_conformance.cpp 2012-09-24 12:00:13 +0000
17@@ -19,6 +19,8 @@
18 using ::testing::Pointee;
19 using ::testing::ReturnNull;
20
21+namespace cci = compiz::config::impl;
22+
23 CCSIntegration *
24 ccsMockIntegrationBackendNew (CCSObjectAllocationInterface *ai);
25
26@@ -302,7 +304,7 @@
27 {
28 GVariant *variant = NULL;
29
30- const CCSListWrapper::Ptr &lw (boost::get <CCSListWrapper::Ptr> (value));
31+ const cci::SettingValueListWrapper::Ptr &lw (boost::get <cci::SettingValueListWrapper::Ptr> (value));
32
33 if (writeListValue (*lw, lw->type (), &variant))
34 writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant);
35
36=== modified file 'compizconfig/libcompizconfig/include/ccs-defs.h'
37--- compizconfig/libcompizconfig/include/ccs-defs.h 2012-09-10 01:05:28 +0000
38+++ compizconfig/libcompizconfig/include/ccs-defs.h 2012-09-24 12:00:13 +0000
39@@ -88,6 +88,9 @@
40 ccsFree##type (d); \
41 } \
42
43+#define GET_PRIVATE(Private, obj) \
44+ (Private *) ccsObjectGetPrivate (obj);
45+
46 COMPIZCONFIG_END_DECLS
47
48 #endif
49
50=== modified file 'compizconfig/libcompizconfig/include/ccs.h'
51--- compizconfig/libcompizconfig/include/ccs.h 2012-09-10 01:05:28 +0000
52+++ compizconfig/libcompizconfig/include/ccs.h 2012-09-24 12:00:13 +0000
53@@ -135,7 +135,7 @@
54 typedef void (*CCSContextSetPrivatePtr) (CCSContext *context, void *ptr);
55 typedef Bool (*CCSContextLoadPlugin) (CCSContext *context, char *name);
56 typedef CCSPlugin * (*CCSContextFindPlugin) (CCSContext *context, const char *name);
57-typedef Bool (*CCSContextPluginIsActive) (CCSContext *context, char *name);
58+typedef Bool (*CCSContextPluginIsActive) (CCSContext *context, const char *name);
59 typedef CCSPluginList (*CCSContextGetActivePluginList) (CCSContext *context);
60 typedef CCSStringList (*CCSContextGetSortedPluginStringList) (CCSContext *context);
61 typedef Bool (*CCSContextSetBackend) (CCSContext *context, char *name);
62@@ -223,11 +223,11 @@
63 };
64
65 /* CCSPluginInterface */
66-typedef char * (*CCSPluginGetName) (CCSPlugin *plugin);
67-typedef char * (*CCSPluginGetShortDesc) (CCSPlugin *plugin);
68-typedef char * (*CCSPluginGetLongDesc) (CCSPlugin *plugin);
69-typedef char * (*CCSPluginGetHints) (CCSPlugin *plugin);
70-typedef char * (*CCSPluginGetCategory) (CCSPlugin *plugin);
71+typedef const char * (*CCSPluginGetName) (CCSPlugin *plugin);
72+typedef const char * (*CCSPluginGetShortDesc) (CCSPlugin *plugin);
73+typedef const char * (*CCSPluginGetLongDesc) (CCSPlugin *plugin);
74+typedef const char * (*CCSPluginGetHints) (CCSPlugin *plugin);
75+typedef const char * (*CCSPluginGetCategory) (CCSPlugin *plugin);
76
77 typedef CCSStringList (*CCSPluginGetLoadAfter) (CCSPlugin *plugin);
78 typedef CCSStringList (*CCSPluginGetLoadBefore) (CCSPlugin *plugin);
79@@ -276,11 +276,11 @@
80 };
81
82 /* CCSPlugin accessor functions */
83-char * ccsPluginGetName (CCSPlugin *plugin);
84-char * ccsPluginGetShortDesc (CCSPlugin *plugin);
85-char * ccsPluginGetLongDesc (CCSPlugin *plugin);
86-char * ccsPluginGetHints (CCSPlugin *plugin);
87-char * ccsPluginGetCategory (CCSPlugin *plugin);
88+const char * ccsPluginGetName (CCSPlugin *plugin);
89+const char * ccsPluginGetShortDesc (CCSPlugin *plugin);
90+const char * ccsPluginGetLongDesc (CCSPlugin *plugin);
91+const char * ccsPluginGetHints (CCSPlugin *plugin);
92+const char * ccsPluginGetCategory (CCSPlugin *plugin);
93
94 CCSStringList ccsPluginGetLoadAfter (CCSPlugin *plugin);
95 CCSStringList ccsPluginGetLoadBefore (CCSPlugin *plugin);
96@@ -465,14 +465,14 @@
97 };
98
99 /* Interface for CCSSetting */
100-char * ccsSettingGetName (CCSSetting *setting);
101-char * ccsSettingGetShortDesc (CCSSetting *setting);
102-char * ccsSettingGetLongDesc (CCSSetting *setting);
103+const char * ccsSettingGetName (CCSSetting *setting);
104+const char * ccsSettingGetShortDesc (CCSSetting *setting);
105+const char * ccsSettingGetLongDesc (CCSSetting *setting);
106 CCSSettingType ccsSettingGetType (CCSSetting *setting);
107 CCSSettingInfo * ccsSettingGetInfo (CCSSetting *setting);
108-char * ccsSettingGetGroup (CCSSetting *setting);
109-char * ccsSettingGetSubGroup (CCSSetting *setting);
110-char * ccsSettingGetHints (CCSSetting *setting);
111+const char * ccsSettingGetGroup (CCSSetting *setting);
112+const char * ccsSettingGetSubGroup (CCSSetting *setting);
113+const char * ccsSettingGetHints (CCSSetting *setting);
114 CCSSettingValue * ccsSettingGetDefaultValue (CCSSetting *setting);
115 CCSSettingValue *ccsSettingGetValue (CCSSetting *setting);
116 Bool ccsSettingGetIsDefault (CCSSetting *setting);
117@@ -558,14 +558,14 @@
118 /* Checks if a setting is readable by backends */
119 Bool ccsSettingIsReadableByBackend (CCSSetting *setting);
120
121-typedef char * (*CCSSettingGetName) (CCSSetting *);
122-typedef char * (*CCSSettingGetShortDesc) (CCSSetting *);
123-typedef char * (*CCSSettingGetLongDesc) (CCSSetting *);
124+typedef const char * (*CCSSettingGetName) (CCSSetting *);
125+typedef const char * (*CCSSettingGetShortDesc) (CCSSetting *);
126+typedef const char * (*CCSSettingGetLongDesc) (CCSSetting *);
127 typedef CCSSettingType (*CCSSettingGetType) (CCSSetting *);
128 typedef CCSSettingInfo * (*CCSSettingGetInfo) (CCSSetting *);
129-typedef char * (*CCSSettingGetGroup) (CCSSetting *);
130-typedef char * (*CCSSettingGetSubGroup) (CCSSetting *);
131-typedef char * (*CCSSettingGetHints) (CCSSetting *);
132+typedef const char * (*CCSSettingGetGroup) (CCSSetting *);
133+typedef const char * (*CCSSettingGetSubGroup) (CCSSetting *);
134+typedef const char * (*CCSSettingGetHints) (CCSSetting *);
135 typedef CCSSettingValue * (*CCSSettingGetDefaultValue) (CCSSetting *setting);
136 typedef CCSSettingValue * (*CCSSettingGetValue) (CCSSetting *setting);
137 typedef Bool (*CCSSettingGetIsDefault) (CCSSetting *);
138@@ -697,8 +697,7 @@
139
140 /* Returns TRUE if the named plugin is in the context and marked as currently
141 active in Compiz, FALSE otherwise. */
142-Bool ccsPluginIsActive (CCSContext *context,
143- char *name);
144+Bool ccsPluginIsActive(CCSContext *context, const char *name);
145
146 void ccsFreeContext (CCSContext *context);
147 void ccsFreePlugin (CCSPlugin *plugin);
148@@ -1080,6 +1079,14 @@
149
150 CCSStrExtensionList ccsGetPluginStrExtensions (CCSPlugin *plugin);
151
152+Bool
153+ccsCheckValueEq (const CCSSettingValue *rhs,
154+ CCSSettingType rhsType,
155+ CCSSettingInfo *rhsInfo,
156+ const CCSSettingValue *lhs,
157+ CCSSettingType lhsType,
158+ CCSSettingInfo *lhsInfo);
159+
160 COMPIZCONFIG_END_DECLS
161
162 #endif
163
164=== modified file 'compizconfig/libcompizconfig/src/CMakeLists.txt'
165--- compizconfig/libcompizconfig/src/CMakeLists.txt 2012-09-10 01:05:28 +0000
166+++ compizconfig/libcompizconfig/src/CMakeLists.txt 2012-09-24 12:00:13 +0000
167@@ -51,6 +51,21 @@
168 endif (HAVE_INOTIFY)
169
170 add_library (
171+ ccs_text_file_interface STATIC
172+ ccs_text_file_interface.c
173+)
174+
175+add_library (
176+ ccs_text_file STATIC
177+ ccs_text_file.c
178+)
179+
180+target_link_libraries (
181+ ccs_text_file
182+ ccs_text_file_interface
183+)
184+
185+add_library (
186 ccs_settings_upgrade_internal STATIC
187 ccs_settings_upgrade_internal.c
188 )
189@@ -75,6 +90,7 @@
190 m
191 dl
192 ccs_settings_upgrade_internal
193+ ccs_text_file
194 )
195
196 #
197
198=== modified file 'compizconfig/libcompizconfig/src/ccs-private.h'
199--- compizconfig/libcompizconfig/src/ccs-private.h 2012-09-10 01:05:28 +0000
200+++ compizconfig/libcompizconfig/src/ccs-private.h 2012-09-24 12:00:13 +0000
201@@ -25,9 +25,6 @@
202 #include <ccs.h>
203 #include <ccs-backend.h>
204
205-#define GET_PRIVATE(Private, obj) \
206- (Private *) ccsObjectGetPrivate (obj);
207-
208 extern Bool basicMetadata;
209
210 typedef struct _CCSContextPrivate
211
212=== modified file 'compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.c'
213--- compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.c 2012-09-10 01:05:28 +0000
214+++ compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.c 2012-09-24 12:00:13 +0000
215@@ -20,8 +20,8 @@
216 * Authored By:
217 * Sam Spilsbury <sam.spilsbury@canonical.com>
218 */
219-
220 #include "ccs_settings_upgrade_internal.h"
221+#include <ccs.h>
222 #include <string.h>
223 #include <errno.h>
224 #include <stdlib.h>
225@@ -44,13 +44,10 @@
226 int foundNumber,
227 void *userData)
228 {
229- static const char *UPGRADE = "upgrade";
230- static const unsigned int UPGRADE_STR_LEN = 7;
231-
232- if (strncmp (tokenThree, UPGRADE, UPGRADE_STR_LEN))
233- return FALSE;
234-
235- return TRUE;
236+ static const char *upgrade = "upgrade";
237+ static const unsigned int upgrade_str_len = 7;
238+
239+ return strncmp (tokenThree, upgrade, upgrade_str_len) == 0;
240 }
241
242 typedef struct _FillDomainNumAndProfileData
243@@ -121,8 +118,6 @@
244 userData))
245 success = TRUE;
246 }
247- else if (errno)
248- perror ("sscanf");
249
250 tok = nexttok;
251 free (bit);
252@@ -166,3 +161,239 @@
253
254 return 0;
255 }
256+
257+void
258+ccsUpgradeClearValues (CCSSettingList clearSettings)
259+{
260+ CCSSettingList sl = clearSettings;
261+
262+ while (sl)
263+ {
264+ CCSSetting *tempSetting = (CCSSetting *) sl->data;
265+ CCSSetting *setting;
266+ CCSPlugin *plugin = ccsSettingGetParent (tempSetting);
267+ const char *name = ccsSettingGetName (tempSetting);
268+
269+ setting = ccsFindSetting (plugin, name);
270+
271+ if (setting)
272+ {
273+ CCSSettingInfo *tempInfo = ccsSettingGetInfo (tempSetting);
274+ CCSSettingType tType = ccsSettingGetType (tempSetting);
275+ CCSSettingType sType = ccsSettingGetType (setting);
276+ CCSSettingInfo *info = ccsSettingGetInfo (setting);
277+
278+ if (sType != tType)
279+ {
280+ ccsWarning ("Attempted to upgrade setting %s with wrong type", name);
281+ sl = sl->next;
282+ continue;
283+ }
284+
285+ if (sType != TypeList)
286+ {
287+ if (ccsCheckValueEq (ccsSettingGetValue (setting),
288+ sType,
289+ info,
290+ ccsSettingGetValue (tempSetting),
291+ tType,
292+ tempInfo))
293+ {
294+ ccsDebug ("Resetting %s to default", name);
295+ ccsResetToDefault (setting, TRUE);
296+ }
297+ else
298+ {
299+ ccsDebug ("Skipping processing of %s", name);
300+ }
301+ }
302+ else
303+ {
304+ unsigned int count = 0;
305+ /* Try and remove any specified items from the list */
306+ CCSSettingValueList l = ccsSettingGetValue (tempSetting)->value.asList;
307+ CCSSettingValueList nl = ccsCopyList (ccsSettingGetValue (setting)->value.asList, setting);
308+ CCSSettingInfo *info = ccsSettingGetInfo (setting);
309+
310+ while (l)
311+ {
312+ CCSSettingValueList olv = nl;
313+
314+ while (olv)
315+ {
316+ CCSSettingValue *lv = (CCSSettingValue *) l->data;
317+ CCSSettingValue *olvv = (CCSSettingValue *) olv->data;
318+
319+ /* Break if we found a matching value, so that we can
320+ * remove it from the list */
321+ if (ccsCheckValueEq (lv,
322+ info->forList.listType,
323+ info,
324+ olvv,
325+ info->forList.listType,
326+ info))
327+ break;
328+
329+ olv = olv->next;
330+ }
331+
332+ /* We found a matching value, remove it */
333+ if (olv)
334+ {
335+ count++;
336+ nl = ccsSettingValueListRemove (nl, olv->data, TRUE);
337+ }
338+
339+ l = l->next;
340+ }
341+
342+ ccsDebug ("Removed %i items from %s", count, name);
343+ ccsSetList (setting, nl, TRUE);
344+ ccsSettingValueListFree (nl, TRUE);
345+ }
346+ }
347+
348+ sl = sl->next;
349+ }
350+}
351+
352+void
353+ccsUpgradeAddValues (CCSSettingList addSettings)
354+{
355+ CCSSettingList sl = addSettings;
356+
357+ while (sl)
358+ {
359+ CCSSetting *tempSetting = (CCSSetting *) sl->data;
360+ CCSSetting *setting;
361+ CCSPlugin *plugin = ccsSettingGetParent (tempSetting);
362+ const char *name = ccsSettingGetName (tempSetting);
363+
364+ setting = ccsFindSetting (plugin, name);
365+
366+ if (setting)
367+ {
368+ const CCSSettingType tempSettingType = ccsSettingGetType (tempSetting);
369+ const CCSSettingType actualSettingType = ccsSettingGetType (setting);
370+
371+ if (tempSettingType != actualSettingType)
372+ {
373+ ccsWarning ("Attempted to upgrade setting %s with wrong type", name);
374+ sl = sl->next;
375+ continue;
376+ }
377+
378+ ccsDebug ("Overriding value %s", name);
379+ if (tempSettingType != TypeList)
380+ ccsSetValue (setting, ccsSettingGetValue (tempSetting), TRUE);
381+ else
382+ {
383+ unsigned int count = 0;
384+ /* Try and apppend any new items to the list */
385+ CCSSettingValueList l = ccsSettingGetValue (tempSetting)->value.asList;
386+ CCSSettingValueList nl = ccsCopyList (ccsSettingGetValue (setting)->value.asList, setting);
387+ CCSSettingInfo *info = ccsSettingGetInfo (setting);
388+
389+ while (l)
390+ {
391+ CCSSettingValueList olv = nl;
392+
393+ while (olv)
394+ {
395+ CCSSettingValue *lv = (CCSSettingValue *) l->data;
396+ CCSSettingValue *olvv = (CCSSettingValue *) olv->data;
397+
398+ /* Break if we find the same value, as it was in the list
399+ * already */
400+ if (ccsCheckValueEq (lv,
401+ info->forList.listType,
402+ info,
403+ olvv,
404+ info->forList.listType,
405+ info))
406+ break;
407+
408+ olv = olv->next;
409+ }
410+
411+ /* If olv is NULL then the value was not in the original
412+ * list and we should append the value to nl */
413+ if (!olv)
414+ {
415+ count++;
416+ nl = ccsSettingValueListAppend (nl, l->data);
417+ }
418+
419+ l = l->next;
420+ }
421+
422+ ccsDebug ("Appending %i items to %s", count, name);
423+ ccsSetList (setting, nl, TRUE);
424+ }
425+ }
426+ else
427+ {
428+ ccsDebug ("Value %s not found!", name);
429+ }
430+
431+ sl = sl->next;
432+ }
433+}
434+
435+void
436+ccsUpgradeReplaceValues (CCSSettingList replaceFromValueSettings,
437+ CCSSettingList replaceToValueSettings)
438+{
439+ CCSSettingList sl = replaceFromValueSettings;
440+
441+ while (sl)
442+ {
443+ CCSSetting *tempSetting = (CCSSetting *) sl->data;
444+ CCSSetting *setting;
445+ CCSPlugin *plugin = ccsSettingGetParent (tempSetting);
446+ const char *name = ccsSettingGetName (tempSetting);
447+
448+ setting = ccsFindSetting (plugin, name);
449+
450+ if (setting)
451+ {
452+ CCSSettingValue *value = ccsSettingGetValue (setting);
453+ CCSSettingType realType = ccsSettingGetType (setting);
454+ CCSSettingInfo *realInfo = ccsSettingGetInfo (setting);
455+ CCSSettingValue *tempValue = ccsSettingGetValue (tempSetting);
456+ CCSSettingType tempType = ccsSettingGetType (tempSetting);
457+ CCSSettingInfo *tempInfo = ccsSettingGetInfo (tempSetting);
458+
459+ if (ccsCheckValueEq (value,
460+ realType,
461+ realInfo,
462+ tempValue,
463+ tempType,
464+ tempInfo))
465+ {
466+ CCSSettingList rl = replaceToValueSettings;
467+
468+ while (rl)
469+ {
470+ CCSSetting *rsetting = (CCSSetting *) rl->data;
471+ const char *replaceToSettingName = ccsSettingGetName (rsetting);
472+
473+ if (strcmp (replaceToSettingName, name) == 0)
474+ {
475+ ccsDebug ("Matched and replaced %s", name);
476+ ccsSetValue (setting, ccsSettingGetValue (rsetting), TRUE);
477+ break;
478+ }
479+
480+ rl = rl->next;
481+ }
482+ }
483+ else
484+ {
485+ ccsDebug ("Skipping processing of %s", name);
486+ }
487+ }
488+
489+ sl = sl->next;
490+ }
491+}
492
493=== modified file 'compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.h'
494--- compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.h 2012-09-10 01:05:28 +0000
495+++ compizconfig/libcompizconfig/src/ccs_settings_upgrade_internal.h 2012-09-24 12:00:13 +0000
496@@ -27,6 +27,8 @@
497
498 COMPIZCONFIG_BEGIN_DECLS
499
500+typedef struct _CCSSettingList * CCSSettingList;
501+
502 Bool
503 ccsUpgradeGetDomainNumAndProfile (const char *name,
504 char **domain,
505@@ -36,6 +38,16 @@
506 int
507 ccsUpgradeNameFilter (const char *name);
508
509+void
510+ccsUpgradeClearValues (CCSSettingList clearSettings);
511+
512+void
513+ccsUpgradeAddValues (CCSSettingList addSettings);
514+
515+void
516+ccsUpgradeReplaceValues (CCSSettingList replaceFromValueSettings,
517+ CCSSettingList replaceToValueSettings);
518+
519 COMPIZCONFIG_END_DECLS
520
521 #endif
522
523=== added file 'compizconfig/libcompizconfig/src/ccs_text_file.c'
524--- compizconfig/libcompizconfig/src/ccs_text_file.c 1970-01-01 00:00:00 +0000
525+++ compizconfig/libcompizconfig/src/ccs_text_file.c 2012-09-24 12:00:13 +0000
526@@ -0,0 +1,212 @@
527+/*
528+ * Compiz configuration system library
529+ *
530+ * ccs_text_file.c
531+ *
532+ * Copyright (C) 2012 Canonical Ltd.
533+ *
534+ * This library is free software; you can redistribute it and/or
535+ * modify it under the terms of the GNU Lesser General Public
536+ * License as published by the Free Software Foundation; either
537+ * version 2.1 of the License, or (at your option) any later version.
538+
539+ * This library is distributed in the hope that it will be useful,
540+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
541+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
542+ * Lesser General Public License for more details.
543+
544+ * You should have received a copy of the GNU Lesser General Public
545+ * License along with this library; if not, write to the Free Software
546+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
547+ *
548+ * Authored By:
549+ * Sam Spilsbury <sam.spilsbury@canonical.com>
550+ */
551+
552+#include <stdio.h>
553+#include <stdlib.h>
554+#include <string.h>
555+
556+#include <ccs-defs.h>
557+#include <ccs-object.h>
558+#include <ccs_text_file_interface.h>
559+#include <ccs_text_file.h>
560+
561+typedef struct _CCSUnixTextFilePrivate CCSUnixTextFilePrivate;
562+
563+struct _CCSUnixTextFilePrivate
564+{
565+ FILE *unixFile;
566+};
567+
568+static void
569+freeAndFinalizeCCSTextFile (CCSTextFile *file,
570+ CCSObjectAllocationInterface *ai)
571+{
572+ ccsObjectFinalize (file);
573+ (*ai->free_) (ai->allocator, file);
574+}
575+
576+static char *
577+ccsUnixTextFileReadFromStart (CCSTextFile *textFile)
578+{
579+ CCSUnixTextFilePrivate *priv = GET_PRIVATE (CCSUnixTextFilePrivate, textFile);
580+ FILE *completedUpgrades = priv->unixFile;
581+
582+ char *cuBuffer;
583+ unsigned int cuSize;
584+ size_t cuReadSize;
585+
586+ fseek (completedUpgrades, 0, SEEK_END);
587+ cuSize = ftell (completedUpgrades);
588+ rewind (completedUpgrades);
589+
590+ cuBuffer = calloc (cuSize + 1, sizeof (char));
591+
592+ if (!cuBuffer)
593+ return NULL;
594+
595+ cuReadSize = fread (cuBuffer, 1, cuSize, completedUpgrades);
596+
597+ /*
598+ ccsWarning ("Couldn't read completed upgrades file!");
599+ */
600+ if (cuReadSize != cuSize)
601+ {
602+ free (cuBuffer);
603+ return NULL;
604+ }
605+
606+ cuBuffer[cuSize] = '\0';
607+
608+ return cuBuffer;
609+}
610+
611+static Bool
612+ccsUnixTextFileAppendString (CCSTextFile *textFile, const char *str)
613+{
614+ CCSUnixTextFilePrivate *priv = GET_PRIVATE (CCSUnixTextFilePrivate, textFile);
615+ FILE *completedUpgrades = priv->unixFile;
616+
617+ fprintf (completedUpgrades, "%s\n", str);
618+ return TRUE;
619+}
620+
621+static void
622+ccsUnixFreeTextFile (CCSTextFile *textFile)
623+{
624+ CCSUnixTextFilePrivate *priv = GET_PRIVATE (CCSUnixTextFilePrivate, textFile);
625+
626+ fclose (priv->unixFile);
627+ priv->unixFile = NULL;
628+
629+ freeAndFinalizeCCSTextFile (textFile,
630+ textFile->object.object_allocation);
631+}
632+
633+CCSTextFileInterface ccsUnixTextFileInterface =
634+{
635+ ccsUnixTextFileReadFromStart,
636+ ccsUnixTextFileAppendString,
637+ ccsUnixFreeTextFile
638+};
639+
640+const char * CCS_UNIX_TEXT_FILE_OPEN_MODE_READONLY = "r";
641+const char * CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITE = "r+";
642+const char * CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITECREATE = "a+";
643+
644+static FILE *
645+openUnixFile (CCSTextFile *textFile,
646+ CCSObjectAllocationInterface *ai,
647+ const char *path,
648+ const char *openMode)
649+{
650+ FILE *file = fopen (path, openMode);
651+
652+ if (!file)
653+ {
654+ ccsObjectFinalize (textFile);
655+ (*ai->free_) (ai->allocator, textFile);
656+ return NULL;
657+ }
658+
659+ return file;
660+}
661+
662+
663+static CCSUnixTextFilePrivate *
664+allocateCCSUnixTextFilePrivate (CCSTextFile *file,
665+ CCSObjectAllocationInterface *ai)
666+{
667+ CCSUnixTextFilePrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSUnixTextFilePrivate));
668+
669+ if (!priv)
670+ {
671+ freeAndFinalizeCCSTextFile (file, ai);
672+ return NULL;
673+ }
674+
675+ return priv;
676+}
677+
678+static CCSTextFile *
679+allocateCCSTextFile (CCSObjectAllocationInterface *ai)
680+{
681+ CCSTextFile *textFile = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSTextFile));
682+
683+ if (!textFile)
684+ return NULL;
685+
686+ ccsObjectInit (textFile, ai);
687+
688+ return textFile;
689+}
690+
691+CCSTextFile *
692+ccsUnixTextFileNew (const char *path,
693+ CCSTextFileOpenMode openMode,
694+ CCSObjectAllocationInterface *ai)
695+{
696+ const char *fopenMode = NULL;
697+
698+ switch (openMode)
699+ {
700+ case ReadOnly:
701+ fopenMode = CCS_UNIX_TEXT_FILE_OPEN_MODE_READONLY;
702+ break;
703+ case ReadWrite:
704+ fopenMode = CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITE;
705+ break;
706+ case ReadWriteCreate:
707+ fopenMode = CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITECREATE;
708+ break;
709+ }
710+
711+ CCSTextFile *textFile = allocateCCSTextFile (ai);
712+
713+ if (!textFile)
714+ return NULL;
715+
716+ CCSUnixTextFilePrivate *priv = allocateCCSUnixTextFilePrivate (textFile, ai);
717+
718+ if (!priv)
719+ return NULL;
720+
721+ ccsObjectSetPrivate (textFile, (CCSPrivate *) priv);
722+
723+ FILE *unixFile = openUnixFile (textFile,
724+ ai,
725+ path,
726+ fopenMode);
727+
728+ if (!unixFile)
729+ return NULL;
730+
731+ priv->unixFile = unixFile;
732+
733+ ccsObjectAddInterface (textFile, (const CCSInterface *) &ccsUnixTextFileInterface,
734+ GET_INTERFACE_TYPE (CCSTextFileInterface));
735+ ccsObjectRef (textFile);
736+
737+ return textFile;
738+}
739
740=== added file 'compizconfig/libcompizconfig/src/ccs_text_file.h'
741--- compizconfig/libcompizconfig/src/ccs_text_file.h 1970-01-01 00:00:00 +0000
742+++ compizconfig/libcompizconfig/src/ccs_text_file.h 2012-09-24 12:00:13 +0000
743@@ -0,0 +1,49 @@
744+/*
745+ * Compiz configuration system library
746+ *
747+ * ccs_text_file.h
748+ *
749+ * Copyright (C) 2012 Canonical Ltd.
750+ *
751+ * This library is free software; you can redistribute it and/or
752+ * modify it under the terms of the GNU Lesser General Public
753+ * License as published by the Free Software Foundation; either
754+ * version 2.1 of the License, or (at your option) any later version.
755+
756+ * This library is distributed in the hope that it will be useful,
757+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
758+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
759+ * Lesser General Public License for more details.
760+
761+ * You should have received a copy of the GNU Lesser General Public
762+ * License along with this library; if not, write to the Free Software
763+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
764+ *
765+ * Authored By:
766+ * Sam Spilsbury <sam.spilsbury@canonical.com>
767+ */
768+#ifndef CCS_TEXT_FILE_H
769+#define CCS_TEXT_FILE_H
770+
771+#include <ccs-defs.h>
772+
773+COMPIZCONFIG_BEGIN_DECLS
774+
775+typedef struct _CCSTextFile CCSTextFile;
776+typedef struct _CCSObjectAllocationInterface CCSObjectAllocationInterface;
777+
778+typedef enum _CCSTextFileOpenMode
779+{
780+ ReadOnly = 1,
781+ ReadWrite = 2,
782+ ReadWriteCreate = 3
783+} CCSTextFileOpenMode;
784+
785+CCSTextFile *
786+ccsUnixTextFileNew (const char *path,
787+ CCSTextFileOpenMode openMode,
788+ CCSObjectAllocationInterface *ai);
789+
790+COMPIZCONFIG_END_DECLS
791+
792+#endif
793
794=== added file 'compizconfig/libcompizconfig/src/ccs_text_file_interface.c'
795--- compizconfig/libcompizconfig/src/ccs_text_file_interface.c 1970-01-01 00:00:00 +0000
796+++ compizconfig/libcompizconfig/src/ccs_text_file_interface.c 2012-09-24 12:00:13 +0000
797@@ -0,0 +1,50 @@
798+/*
799+ * Compiz configuration system library
800+ *
801+ * ccs_text_file_interface.c
802+ *
803+ * Copyright (C) 2012 Canonical Ltd.
804+ *
805+ * This library is free software; you can redistribute it and/or
806+ * modify it under the terms of the GNU Lesser General Public
807+ * License as published by the Free Software Foundation; either
808+ * version 2.1 of the License, or (at your option) any later version.
809+
810+ * This library is distributed in the hope that it will be useful,
811+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
812+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
813+ * Lesser General Public License for more details.
814+
815+ * You should have received a copy of the GNU Lesser General Public
816+ * License along with this library; if not, write to the Free Software
817+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
818+ *
819+ * Authored By:
820+ * Sam Spilsbury <sam.spilsbury@canonical.com>
821+ */
822+
823+#include <ccs-defs.h>
824+#include <ccs-object.h>
825+#include <ccs_text_file_interface.h>
826+#include <ccs_text_file.h>
827+
828+INTERFACE_TYPE (CCSTextFileInterface);
829+CCSREF_OBJ (TextFile, CCSTextFile);
830+
831+char *
832+ccsTextFileReadFromStart (CCSTextFile *file)
833+{
834+ return (*(GET_INTERFACE (CCSTextFileInterface, file))->readFromStart) (file);
835+}
836+
837+Bool
838+ccsTextFileAppendString (CCSTextFile *file, const char *str)
839+{
840+ return (*(GET_INTERFACE (CCSTextFileInterface, file))->appendString) (file, str);
841+}
842+
843+void
844+ccsFreeTextFile (CCSTextFile *file)
845+{
846+ return (*(GET_INTERFACE (CCSTextFileInterface, file))->free) (file);
847+}
848
849=== added file 'compizconfig/libcompizconfig/src/ccs_text_file_interface.h'
850--- compizconfig/libcompizconfig/src/ccs_text_file_interface.h 1970-01-01 00:00:00 +0000
851+++ compizconfig/libcompizconfig/src/ccs_text_file_interface.h 2012-09-24 12:00:13 +0000
852@@ -0,0 +1,67 @@
853+/*
854+ * Compiz configuration system library
855+ *
856+ * ccs_text_file_interface.h
857+ *
858+ * Copyright (C) 2012 Canonical Ltd.
859+ *
860+ * This library is free software; you can redistribute it and/or
861+ * modify it under the terms of the GNU Lesser General Public
862+ * License as published by the Free Software Foundation; either
863+ * version 2.1 of the License, or (at your option) any later version.
864+
865+ * This library is distributed in the hope that it will be useful,
866+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
867+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
868+ * Lesser General Public License for more details.
869+
870+ * You should have received a copy of the GNU Lesser General Public
871+ * License along with this library; if not, write to the Free Software
872+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
873+ *
874+ * Authored By:
875+ * Sam Spilsbury <sam.spilsbury@canonical.com>
876+ */
877+#ifndef CCS_TEXT_FILE_INTERFACE_H
878+#define CCS_TEXT_FILE_INTERFACE_H
879+
880+#include <ccs-defs.h>
881+#include <ccs-object.h>
882+
883+COMPIZCONFIG_BEGIN_DECLS
884+
885+typedef struct _CCSTextFile CCSTextFile;
886+typedef struct _CCSTextFileInterface CCSTextFileInterface;
887+
888+typedef char * (*CCSReadTextFileFromStart) (CCSTextFile *file);
889+typedef Bool (*CCSAppendStringToTextFile) (CCSTextFile *file, const char *str);
890+typedef void (*CCSFreeTextFile) (CCSTextFile *file);
891+
892+struct _CCSTextFileInterface
893+{
894+ CCSReadTextFileFromStart readFromStart;
895+ CCSAppendStringToTextFile appendString;
896+ CCSFreeTextFile free;
897+};
898+
899+struct _CCSTextFile
900+{
901+ CCSObject object;
902+};
903+
904+CCSREF_HDR (TextFile, CCSTextFile);
905+
906+char *
907+ccsTextFileReadFromStart (CCSTextFile *);
908+
909+Bool
910+ccsTextFileAppendString (CCSTextFile *, const char *);
911+
912+void
913+ccsFreeTextFile (CCSTextFile *);
914+
915+unsigned int ccsCCSTextFileInterfaceGetType ();
916+
917+COMPIZCONFIG_END_DECLS
918+
919+#endif
920
921=== modified file 'compizconfig/libcompizconfig/src/main.c'
922--- compizconfig/libcompizconfig/src/main.c 2012-09-10 14:23:28 +0000
923+++ compizconfig/libcompizconfig/src/main.c 2012-09-24 12:00:13 +0000
924@@ -39,6 +39,8 @@
925 #include "ccs-private.h"
926 #include "iniparser.h"
927 #include "ccs_settings_upgrade_internal.h"
928+#include "ccs_text_file_interface.h"
929+#include "ccs_text_file.h"
930
931 static void * wrapRealloc (void *o, void *a , size_t b)
932 {
933@@ -622,7 +624,7 @@
934 }
935
936 Bool
937-ccsPluginIsActiveDefault (CCSContext * context, char *name)
938+ccsPluginIsActiveDefault (CCSContext * context, const char *name)
939 {
940 CCSPlugin *plugin;
941
942@@ -636,7 +638,7 @@
943 }
944
945 Bool
946-ccsPluginIsActive (CCSContext *context, char *name)
947+ccsPluginIsActive (CCSContext *context, const char *name)
948 {
949 return (*(GET_INTERFACE (CCSContextInterface, context))->contextPluginIsActive) (context, name);
950 }
951@@ -904,7 +906,9 @@
952
953 ccsFreeSettingValueCommon (v, type);
954
955- if (v != ccsSettingGetDefaultValue (v->parent))
956+ /* List children cannot be a default value */
957+ if (v->isListChild ||
958+ v != ccsSettingGetDefaultValue (v->parent))
959 free (v);
960 }
961
962@@ -2037,20 +2041,25 @@
963 }
964
965 Bool
966-ccsCheckValueEq (CCSSettingValue *rhs, CCSSettingValue *lhs)
967+ccsCheckValueEq (const CCSSettingValue *rhs,
968+ CCSSettingType rhsType,
969+ CCSSettingInfo *rhsInfo,
970+ const CCSSettingValue *lhs,
971+ CCSSettingType lhsType,
972+ CCSSettingInfo *lhsInfo)
973 {
974 CCSSettingType type;
975
976- if (ccsSettingGetType (rhs->parent) != ccsSettingGetType (lhs->parent))
977+ if (rhsType != lhsType)
978 {
979 ccsWarning ("Attempted to check equality between mismatched types!");
980 return FALSE;
981 }
982
983 if (rhs->isListChild)
984- type = ccsSettingGetInfo (rhs->parent)->forList.listType;
985+ type = rhsInfo->forList.listType;
986 else
987- type = ccsSettingGetType (rhs->parent);
988+ type = rhsType;
989
990 switch (type)
991 {
992@@ -2080,14 +2089,14 @@
993 case TypeList:
994 {
995 return ccsCompareLists (lhs->value.asList, rhs->value.asList,
996- ccsSettingGetInfo (lhs->parent)->forList);
997+ lhsInfo->forList);
998
999 }
1000 default:
1001 break;
1002 }
1003
1004- ccsWarning ("Failed to process type %i", ccsSettingGetType (lhs->parent));
1005+ ccsWarning ("Failed to check equality for value with type %i", lhsType);
1006 return FALSE;
1007 }
1008
1009@@ -2455,6 +2464,7 @@
1010 CCSSettingValueList
1011 ccsCopyList (CCSSettingValueList l1, CCSSetting * setting)
1012 {
1013+ CCSSettingInfo *info = ccsSettingGetInfo (setting);
1014 CCSSettingValueList l2 = NULL;
1015
1016 while (l1)
1017@@ -2467,7 +2477,7 @@
1018 value->parent = setting;
1019 value->isListChild = TRUE;
1020
1021- switch (ccsSettingGetInfo (setting)->forList.listType)
1022+ switch (info->forList.listType)
1023 {
1024 case TypeInt:
1025 value->value.asInt = l1->data->value.asInt;
1026@@ -4572,198 +4582,45 @@
1027 return FALSE;
1028 }
1029
1030+void
1031+ccsCollectSettingsToUpgrade (CCSContext *context,
1032+ IniDictionary *dict,
1033+ CCSSettingsUpgrade *upgrade)
1034+{
1035+ CCSPluginList pl = ccsContextGetPlugins (context);
1036+
1037+ while (pl)
1038+ {
1039+ CCSPlugin *plugin = (CCSPlugin *) pl->data;
1040+ CCSSettingList sl = ccsGetPluginSettings (plugin);
1041+
1042+ while (sl)
1043+ {
1044+ CCSSetting *setting = sl->data;
1045+
1046+ ccsProcessSettingMinus (dict, context, upgrade, setting);
1047+ ccsProcessSettingPlus (dict, context, upgrade, setting);
1048+
1049+ sl = sl->next;
1050+ }
1051+
1052+ pl = pl->next;
1053+ }
1054+}
1055+
1056 Bool
1057 ccsProcessUpgrade (CCSContext *context,
1058 CCSSettingsUpgrade *upgrade)
1059 {
1060- CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context);
1061-
1062 IniDictionary *dict = ccsIniOpen (upgrade->file);
1063- CCSPluginList pl = cPrivate->plugins;
1064- CCSSettingList sl;
1065
1066 ccsSetProfile (context, upgrade->profile);
1067
1068- while (pl)
1069- {
1070- sl = ccsGetPluginSettings ((CCSPlugin *) pl->data);
1071-
1072- while (sl)
1073- {
1074- CCSSetting *setting = sl->data;
1075-
1076- ccsProcessSettingMinus (dict, context, upgrade, setting);
1077- ccsProcessSettingPlus (dict, context, upgrade, setting);
1078-
1079- sl = sl->next;
1080- }
1081-
1082- pl = pl->next;
1083- }
1084-
1085- sl = upgrade->clearValueSettings;
1086-
1087- while (sl)
1088- {
1089- CCSSetting *tempSetting = (CCSSetting *) sl->data;
1090- CCSSetting *setting;
1091- CCSPlugin *plugin = ccsSettingGetParent (tempSetting);
1092- const char *name = ccsSettingGetName (tempSetting);
1093-
1094- setting = ccsFindSetting (plugin, name);
1095-
1096- if (setting)
1097- {
1098- if (ccsSettingGetType (setting) != TypeList)
1099- {
1100- if (ccsSettingGetValue (setting) == ccsSettingGetValue (tempSetting))
1101- {
1102- ccsDebug ("Resetting %s to default", ccsSettingGetName ((CCSSetting *) sl->data));
1103- ccsResetToDefault (setting, TRUE);
1104- }
1105- else
1106- {
1107- ccsDebug ("Skipping processing of %s", ccsSettingGetName ((CCSSetting *) sl->data));
1108- }
1109- }
1110- else
1111- {
1112- unsigned int count = 0;
1113- /* Try and remove any specified items from the list */
1114- CCSSettingValueList l = ccsSettingGetValue (tempSetting)->value.asList;
1115- CCSSettingValueList nl = ccsCopyList (ccsSettingGetValue (setting)->value.asList, setting);
1116-
1117- while (l)
1118- {
1119- CCSSettingValueList olv = nl;
1120-
1121- while (olv)
1122- {
1123- CCSSettingValue *lv = (CCSSettingValue *) l->data;
1124- CCSSettingValue *olvv = (CCSSettingValue *) olv->data;
1125-
1126- if (ccsCheckValueEq (lv, olvv))
1127- break;
1128-
1129- olv = olv->next;
1130- }
1131-
1132- if (olv)
1133- {
1134- count++;
1135- nl = ccsSettingValueListRemove (nl, olv->data, TRUE);
1136- }
1137-
1138- l = l->next;
1139- }
1140-
1141- ccsDebug ("Removed %i items from %s", count, ccsSettingGetName (setting));
1142- ccsSetList (setting, nl, TRUE);
1143-
1144- }
1145- }
1146-
1147- sl = sl->next;
1148- }
1149-
1150- sl = upgrade->addValueSettings;
1151-
1152- while (sl)
1153- {
1154- CCSSetting *tempSetting = (CCSSetting *) sl->data;
1155- CCSSetting *setting;
1156- CCSPlugin *plugin = ccsSettingGetParent (tempSetting);
1157- const char *name = ccsSettingGetName (tempSetting);
1158-
1159- setting = ccsFindSetting (plugin, name);
1160-
1161- if (setting)
1162- {
1163- ccsDebug ("Overriding value %s", ccsSettingGetName ((CCSSetting *) sl->data));
1164- if (ccsSettingGetType (setting) != TypeList)
1165- ccsSetValue (setting, ccsSettingGetValue (tempSetting), TRUE);
1166- else
1167- {
1168- unsigned int count = 0;
1169- /* Try and apppend any new items to the list */
1170- CCSSettingValueList l = ccsSettingGetValue (tempSetting)->value.asList;
1171- CCSSettingValueList nl = ccsCopyList (ccsSettingGetValue (setting)->value.asList, setting);
1172-
1173- while (l)
1174- {
1175- CCSSettingValueList olv = nl;
1176-
1177- while (olv)
1178- {
1179- CCSSettingValue *lv = (CCSSettingValue *) l->data;
1180- CCSSettingValue *olvv = (CCSSettingValue *) olv->data;
1181-
1182- if (ccsCheckValueEq (lv, olvv))
1183- break;
1184-
1185- olv = olv->next;
1186- }
1187-
1188- if (!olv)
1189- {
1190- count++;
1191- nl = ccsSettingValueListAppend (nl, l->data);
1192- }
1193-
1194- l = l->next;
1195- }
1196-
1197- ccsDebug ("Appending %i items to %s", count, ccsSettingGetName (setting));
1198- ccsSetList (setting, nl, TRUE);
1199- }
1200- }
1201- else
1202- {
1203- ccsDebug ("Value %s not found!", ccsSettingGetName ((CCSSetting *) sl->data));
1204- }
1205-
1206- sl = sl->next;
1207- }
1208-
1209- sl = upgrade->replaceFromValueSettings;
1210-
1211- while (sl)
1212- {
1213- CCSSetting *tempSetting = (CCSSetting *) sl->data;
1214- CCSSetting *setting;
1215- CCSPlugin *plugin = ccsSettingGetParent (tempSetting);
1216- const char *name = ccsSettingGetName (tempSetting);
1217-
1218- setting = ccsFindSetting (plugin, name);
1219-
1220- if (setting)
1221- {
1222- if (ccsSettingGetValue (setting) == ccsSettingGetValue (tempSetting))
1223- {
1224- CCSSettingList rl = upgrade->replaceToValueSettings;
1225-
1226- while (rl)
1227- {
1228- CCSSetting *rsetting = (CCSSetting *) rl->data;
1229-
1230- if (strcmp (ccsSettingGetName (rsetting), ccsSettingGetName (setting)) == 0)
1231- {
1232- ccsDebug ("Matched and replaced %s", ccsSettingGetName (setting));
1233- ccsSetValue (setting, ccsSettingGetValue (rsetting), TRUE);
1234- break;
1235- }
1236-
1237- rl = rl->next;
1238- }
1239- }
1240- else
1241- {
1242- ccsDebug ("Skipping processing of %s", ccsSettingGetName ((CCSSetting *) sl->data));
1243- }
1244- }
1245-
1246- sl = sl->next;
1247- }
1248+ ccsCollectSettingsToUpgrade (context, dict, upgrade);
1249+ ccsUpgradeClearValues (upgrade->clearValueSettings);
1250+ ccsUpgradeAddValues (upgrade->addValueSettings);
1251+ ccsUpgradeReplaceValues (upgrade->replaceFromValueSettings,
1252+ upgrade->replaceToValueSettings);
1253
1254 upgrade->clearValueSettings = ccsSettingListFree (upgrade->clearValueSettings, TRUE);
1255 upgrade->addValueSettings = ccsSettingListFree (upgrade->addValueSettings, TRUE);
1256@@ -4810,7 +4667,7 @@
1257 *
1258 */
1259 CCSSettingsUpgrade *
1260-ccsSettingsUpgradeNew (char *path, const char *name)
1261+ccsSettingsUpgradeNew (const char *path, const char *name)
1262 {
1263 CCSSettingsUpgrade *upgrade = calloc (1, sizeof (CCSSettingsUpgrade));
1264 char *upgradeName = strdup (name);
1265@@ -4822,9 +4679,9 @@
1266 upgradeName = strdup (name);
1267
1268 if (!ccsUpgradeGetDomainNumAndProfile (upgradeName,
1269- &upgrade->domain,
1270- &upgrade->num,
1271- &upgrade->profile))
1272+ &upgrade->domain,
1273+ &upgrade->num,
1274+ &upgrade->profile))
1275 {
1276 ccsFreeUpgrade (upgrade);
1277 upgrade = NULL;
1278@@ -4835,41 +4692,35 @@
1279 return upgrade;
1280 }
1281
1282-static FILE *
1283+static CCSTextFile *
1284+ccsUnixOpenDoneSettingsUpgradeFile (const char *path)
1285+{
1286+ return ccsUnixTextFileNew (path,
1287+ ReadWriteCreate,
1288+ &ccsDefaultObjectAllocator);
1289+}
1290+
1291+
1292+
1293+static CCSTextFile *
1294 ccsGetDoneSettingsUpgradeFile (const char *home)
1295 {
1296 char *dupath = NULL;
1297- FILE *completedUpgrades = NULL;
1298+ CCSTextFile *completedUpgrades = NULL;
1299
1300 if (asprintf (&dupath, "%s/.config/compiz-1/compizconfig/done_upgrades", home) == -1)
1301 return NULL;
1302
1303- completedUpgrades = fopen (dupath, "a+");
1304+ completedUpgrades = ccsUnixOpenDoneSettingsUpgradeFile (dupath);
1305 free (dupath);
1306
1307 return completedUpgrades;
1308 }
1309
1310 static char *
1311-ccsReadCompletedUpgradesIntoString (FILE *completedUpgrades)
1312+ccsReadCompletedUpgradesIntoString (CCSTextFile *completedUpgrades)
1313 {
1314- char *cuBuffer;
1315- unsigned int cuSize;
1316- size_t cuReadSize;
1317-
1318- fseek (completedUpgrades, 0, SEEK_END);
1319- cuSize = ftell (completedUpgrades);
1320- rewind (completedUpgrades);
1321-
1322- cuBuffer = calloc (cuSize + 1, sizeof (char));
1323- cuReadSize = fread (cuBuffer, 1, cuSize, completedUpgrades);
1324-
1325- if (cuReadSize != cuSize)
1326- ccsWarning ("Couldn't read completed upgrades file!");
1327-
1328- cuBuffer[cuSize] = '\0';
1329-
1330- return cuBuffer;
1331+ return ccsTextFileReadFromStart (completedUpgrades);
1332 }
1333
1334 static unsigned int
1335@@ -4906,7 +4757,7 @@
1336 ccsProcessUpgradeOnce (CCSContext *context,
1337 CCSSettingsUpgrade *upgrade,
1338 const char *upgradeName,
1339- FILE *completedUpgrades)
1340+ CCSTextFile *completedUpgrades)
1341 {
1342 ccsDebug ("Processing upgrade %s\n profile: %s\n number: %i\n domain: %s",
1343 upgradeName,
1344@@ -4919,17 +4770,46 @@
1345 ccsWriteAutoSortedPluginList (context);
1346 ccsDebug ("Completed upgrade %s", upgradeName);
1347
1348- fprintf (completedUpgrades, "%s\n", upgradeName);
1349+ ccsTextFileAppendString (completedUpgrades, upgradeName);
1350 ccsFreeUpgrade (upgrade);
1351 }
1352
1353+static const char * CCS_UPGRADE_PATH = DATADIR "/compizconfig/upgrades";
1354+
1355+static void
1356+ccsApplyUnappliedUpgrades (CCSContext *context,
1357+ struct dirent **nameList,
1358+ unsigned int nFile,
1359+ const char *completedUpradesContents,
1360+ CCSTextFile *completedUpgrades)
1361+{
1362+ int i = 0;
1363+ const char *path = CCS_UPGRADE_PATH;
1364+
1365+ for (i = 0; i < nFile; i++)
1366+ {
1367+ CCSSettingsUpgrade *upgrade = NULL;
1368+ const char *upgradeName = nameList[i]->d_name;
1369+
1370+ if (ccsShouldSkipUpgrade (upgradeName,
1371+ completedUpradesContents))
1372+ continue;
1373+
1374+ upgrade = ccsSettingsUpgradeNew (path, upgradeName);
1375+
1376+ ccsProcessUpgradeOnce (context, upgrade, upgradeName, completedUpgrades);
1377+
1378+ free (nameList[i]);
1379+ }
1380+}
1381+
1382 Bool
1383 ccsCheckForSettingsUpgradeDefault (CCSContext *context)
1384 {
1385 struct dirent **nameList = NULL;
1386- int nFile, i;
1387- char *path = DATADIR "/compizconfig/upgrades/";
1388- FILE *completedUpgrades;
1389+ int nFile;
1390+ const char *path = CCS_UPGRADE_PATH;
1391+ CCSTextFile *completedUpgrades;
1392 char *cuBuffer = NULL;
1393 char *home = getenv ("HOME");
1394
1395@@ -4945,7 +4825,7 @@
1396
1397 if (!cuBuffer)
1398 {
1399- fclose (completedUpgrades);
1400+ ccsTextFileUnref (completedUpgrades);
1401 ccsWarning ("Error opening done_upgrades");
1402 return FALSE;
1403 }
1404@@ -4955,27 +4835,13 @@
1405 if (!nFile || !nameList)
1406 {
1407 free (cuBuffer);
1408- fclose (completedUpgrades);
1409+ ccsTextFileUnref (completedUpgrades);
1410 return FALSE;
1411 }
1412
1413- for (i = 0; i < nFile; i++)
1414- {
1415- CCSSettingsUpgrade *upgrade = NULL;
1416- const char *upgradeName = nameList[i]->d_name;
1417-
1418- if (ccsShouldSkipUpgrade (upgradeName,
1419- cuBuffer))
1420- continue;
1421-
1422- upgrade = ccsSettingsUpgradeNew (path, upgradeName);
1423-
1424- ccsProcessUpgradeOnce (context, upgrade, upgradeName, completedUpgrades);
1425-
1426- free (nameList[i]);
1427- }
1428-
1429- fclose (completedUpgrades);
1430+ ccsApplyUnappliedUpgrades (context, nameList, nFile, cuBuffer, completedUpgrades);
1431+
1432+ ccsTextFileUnref (completedUpgrades);
1433 free (cuBuffer);
1434
1435 if (nameList != NULL)
1436@@ -5165,7 +5031,7 @@
1437 return (*(GET_INTERFACE (CCSContextInterface, context))->contextImportFromFile) (context, fileName, overwriteNonDefault);
1438 }
1439
1440-char *
1441+const char *
1442 ccsPluginGetNameDefault (CCSPlugin *plugin)
1443 {
1444 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);
1445@@ -5173,28 +5039,28 @@
1446 return pPrivate->name;
1447 }
1448
1449-char * ccsPluginGetShortDescDefault (CCSPlugin *plugin)
1450+const char * ccsPluginGetShortDescDefault (CCSPlugin *plugin)
1451 {
1452 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);
1453
1454 return pPrivate->shortDesc;
1455 }
1456
1457-char * ccsPluginGetLongDescDefault (CCSPlugin *plugin)
1458+const char * ccsPluginGetLongDescDefault (CCSPlugin *plugin)
1459 {
1460 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);
1461
1462 return pPrivate->longDesc;
1463 }
1464
1465-char * ccsPluginGetHintsDefault (CCSPlugin *plugin)
1466+const char * ccsPluginGetHintsDefault (CCSPlugin *plugin)
1467 {
1468 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);
1469
1470 return pPrivate->hints;
1471 }
1472
1473-char * ccsPluginGetCategoryDefault (CCSPlugin *plugin)
1474+const char * ccsPluginGetCategoryDefault (CCSPlugin *plugin)
1475 {
1476 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);
1477
1478@@ -5270,27 +5136,27 @@
1479 }
1480
1481 /* CCSPlugin accessor functions */
1482-char * ccsPluginGetName (CCSPlugin *plugin)
1483+const char * ccsPluginGetName (CCSPlugin *plugin)
1484 {
1485 return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetName) (plugin);
1486 }
1487
1488-char * ccsPluginGetShortDesc (CCSPlugin *plugin)
1489+const char * ccsPluginGetShortDesc (CCSPlugin *plugin)
1490 {
1491 return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetShortDesc) (plugin);
1492 }
1493
1494-char * ccsPluginGetLongDesc (CCSPlugin *plugin)
1495+const char * ccsPluginGetLongDesc (CCSPlugin *plugin)
1496 {
1497 return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetLongDesc) (plugin);
1498 }
1499
1500-char * ccsPluginGetHints (CCSPlugin *plugin)
1501+const char * ccsPluginGetHints (CCSPlugin *plugin)
1502 {
1503 return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetHints) (plugin);
1504 }
1505
1506-char * ccsPluginGetCategory (CCSPlugin *plugin)
1507+const char * ccsPluginGetCategory (CCSPlugin *plugin)
1508 {
1509 return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetCategory) (plugin);
1510 }
1511@@ -5370,18 +5236,18 @@
1512 return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetPluginGroups) (plugin);
1513 }
1514
1515-char * ccsSettingGetName (CCSSetting *setting)
1516+const char * ccsSettingGetName (CCSSetting *setting)
1517 {
1518 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetName) (setting);
1519 }
1520
1521-char * ccsSettingGetShortDesc (CCSSetting *setting)
1522+const char * ccsSettingGetShortDesc (CCSSetting *setting)
1523
1524 {
1525 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetShortDesc) (setting);
1526 }
1527
1528-char * ccsSettingGetLongDesc (CCSSetting *setting)
1529+const char * ccsSettingGetLongDesc (CCSSetting *setting)
1530 {
1531 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetLongDesc) (setting);
1532 }
1533@@ -5396,17 +5262,17 @@
1534 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetInfo) (setting);
1535 }
1536
1537-char * ccsSettingGetGroup (CCSSetting *setting)
1538+const char * ccsSettingGetGroup (CCSSetting *setting)
1539 {
1540 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetGroup) (setting);
1541 }
1542
1543-char * ccsSettingGetSubGroup (CCSSetting *setting)
1544+const char * ccsSettingGetSubGroup (CCSSetting *setting)
1545 {
1546 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetSubGroup) (setting);
1547 }
1548
1549-char * ccsSettingGetHints (CCSSetting *setting)
1550+const char * ccsSettingGetHints (CCSSetting *setting)
1551 {
1552 return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingGetHints) (setting);
1553 }
1554@@ -5527,7 +5393,7 @@
1555 }
1556
1557 /* Interface for CCSSetting */
1558-char *
1559+const char *
1560 ccsSettingGetNameDefault (CCSSetting *setting)
1561 {
1562 CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting);
1563@@ -5535,14 +5401,14 @@
1564 return sPrivate->name;
1565 }
1566
1567-char * ccsSettingGetShortDescDefault (CCSSetting *setting)
1568+const char * ccsSettingGetShortDescDefault (CCSSetting *setting)
1569 {
1570 CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting);
1571
1572 return sPrivate->shortDesc;
1573 }
1574
1575-char * ccsSettingGetLongDescDefault (CCSSetting *setting)
1576+const char * ccsSettingGetLongDescDefault (CCSSetting *setting)
1577 {
1578 CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting);
1579
1580@@ -5563,21 +5429,21 @@
1581 return &sPrivate->info;
1582 }
1583
1584-char * ccsSettingGetGroupDefault (CCSSetting *setting)
1585+const char * ccsSettingGetGroupDefault (CCSSetting *setting)
1586 {
1587 CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting);
1588
1589 return sPrivate->group;
1590 }
1591
1592-char * ccsSettingGetSubGroupDefault (CCSSetting *setting)
1593+const char * ccsSettingGetSubGroupDefault (CCSSetting *setting)
1594 {
1595 CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting);
1596
1597 return sPrivate->subGroup;
1598 }
1599
1600-char * ccsSettingGetHintsDefault (CCSSetting *setting)
1601+const char * ccsSettingGetHintsDefault (CCSSetting *setting)
1602 {
1603 CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting);
1604
1605
1606=== modified file 'compizconfig/libcompizconfig/tests/CMakeLists.txt'
1607--- compizconfig/libcompizconfig/tests/CMakeLists.txt 2012-09-10 07:42:57 +0000
1608+++ compizconfig/libcompizconfig/tests/CMakeLists.txt 2012-09-24 12:00:13 +0000
1609@@ -7,6 +7,7 @@
1610 link_directories (${CMAKE_INSTALL_PREFIX}/lib)
1611 link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig)
1612 link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../tests/)
1613+link_directories (${CMAKE_CURRENT_BINARY_DIR}/../src/)
1614
1615 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
1616
1617@@ -25,6 +26,9 @@
1618 add_executable (compizconfig_test_ccs_backend
1619 ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp)
1620
1621+add_executable (compizconfig_test_ccs_text_file
1622+ ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_text_file.cpp)
1623+
1624 add_executable (compizconfig_test_ccs_mock_backend_conformance
1625 ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp)
1626
1627@@ -102,12 +106,26 @@
1628 compizconfig_ccs_plugin_mock
1629 compizconfig_ccs_setting_mock)
1630
1631+target_link_libraries (compizconfig_test_ccs_text_file
1632+ ${GTEST_BOTH_LIBRARIES}
1633+ ${GMOCK_LIBRARY}
1634+ ${GMOCK_MAIN_LIBRARY}
1635+ ${CMAKE_THREAD_LIBS_INIT}
1636+ ${LIBCOMPIZCONFIG_LIBRARIES}
1637+ ccs_text_file_interface
1638+ compizconfig_ccs_text_file_mock
1639+ compizconfig)
1640+
1641 target_link_libraries (compizconfig_test_ccs_upgrade_internal
1642 ${GTEST_BOTH_LIBRARIES}
1643 ${GMOCK_LIBRARY}
1644 ${GMOCK_MAIN_LIBRARY}
1645 ${CMAKE_THREAD_LIBS_INIT}
1646- ccs_settings_upgrade_internal
1647+ ccs_settings_upgrade_internal
1648+ compizconfig
1649+ compizconfig_ccs_context_mock
1650+ compizconfig_ccs_plugin_mock
1651+ compizconfig_ccs_setting_mock
1652 )
1653
1654 compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig)
1655@@ -115,4 +133,5 @@
1656 compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock)
1657 compiz_discover_tests (compizconfig_test_ccs_setting COVERAGE compizconfig_ccs_setting_mock)
1658 compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock)
1659+compiz_discover_tests (compizconfig_test_ccs_text_file COVERAGE ccs_text_file_interface compizconfig_ccs_text_file_mock)
1660 compiz_discover_tests (compizconfig_test_ccs_upgrade_internal COVERAGE ccs_settings_upgrade_internal)
1661
1662=== modified file 'compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp'
1663--- compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp 2012-09-10 01:05:28 +0000
1664+++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp 2012-09-24 12:00:13 +0000
1665@@ -212,7 +212,7 @@
1666 const std::string &key,
1667 CCSSetting *setting)
1668 {
1669- CCSListWrapper::Ptr lw (ValueForKeyRetreival <boost::shared_ptr <CCSListWrapper> > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues));
1670+ cci::SettingValueListWrapper::Ptr lw (ValueForKeyRetreival <boost::shared_ptr <cci::SettingValueListWrapper> > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues));
1671
1672 return ccsCopyList (*lw, lw->setting ().get ());
1673 }
1674@@ -373,15 +373,14 @@
1675 EXPECT_CALL (*gmockSetting, getName ());
1676 EXPECT_CALL (*gmockSetting, getParent ());
1677
1678+ testing::Cardinality cardinality;
1679+
1680 if (type == TypeList)
1681- {
1682- EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1));
1683- EXPECT_CALL (*gmockSetting, getDefaultValue ()).Times (AtLeast (1));
1684- }
1685+ cardinality = ::testing::AtLeast (1);
1686 else
1687- {
1688- EXPECT_CALL (*gmockSetting, getType ());
1689- }
1690+ cardinality = ::testing::AtMost (1);
1691+
1692+ EXPECT_CALL (*gmockSetting, getType ()).Times (cardinality);
1693 }
1694
1695 void PostWrite (CCSContextGMock *gmockContext,
1696@@ -688,12 +687,15 @@
1697 break;
1698
1699 case TypeList:
1700- ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, setting),
1701- true,
1702- ccsSettingGetInfo (setting)->forList.listType,
1703- boost::shared_ptr <CCSSettingInfo> (),
1704- boost::shared_ptr <CCSSetting> (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE);
1705- break;
1706+ ccsSetList (setting,
1707+ cci::SettingValueListWrapper (ReadListAtKey (plugin, key, setting),
1708+ cci::Deep,
1709+ ccsSettingGetInfo (setting)->forList.listType,
1710+ boost::shared_ptr <CCSSettingInfo> (),
1711+ boost::shared_ptr <CCSSetting> (setting,
1712+ boost::bind (doNothingWithCCSSetting, _1))),
1713+ FALSE);
1714+ break;
1715
1716 default:
1717
1718@@ -785,10 +787,11 @@
1719 ccsGetList (setting, &vList);
1720 listCopy = ccsCopyList (vList, setting);
1721
1722- WriteListAtKey (plugin, key, VariantTypes (boost::make_shared <CCSListWrapper> (listCopy, true,
1723- ccsSettingGetInfo (setting)->forList.listType,
1724- boost::shared_ptr <CCSSettingInfo> (),
1725- boost::shared_ptr <CCSSetting> (setting, boost::bind (doNothingWithCCSSetting, _1)))));
1726+ WriteListAtKey (plugin, key, VariantTypes (boost::make_shared <cci::SettingValueListWrapper> (listCopy,
1727+ cci::Deep,
1728+ ccsSettingGetInfo (setting)->forList.listType,
1729+ boost::shared_ptr <CCSSettingInfo> (),
1730+ boost::shared_ptr <CCSSetting> (setting, boost::bind (doNothingWithCCSSetting, _1)))));
1731 break;
1732 }
1733 default:
1734
1735=== modified file 'compizconfig/libcompizconfig/tests/compizconfig_test_ccs_settings_upgrade_internal.cpp'
1736--- compizconfig/libcompizconfig/tests/compizconfig_test_ccs_settings_upgrade_internal.cpp 2012-09-10 01:05:28 +0000
1737+++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_settings_upgrade_internal.cpp 2012-09-24 12:00:13 +0000
1738@@ -1,10 +1,62 @@
1739+/*
1740+ * Compiz configuration system library
1741+ *
1742+ * Copyright (C) 2012 Canonical Ltd.
1743+ *
1744+ * This library is free software; you can redistribute it and/or
1745+ * modify it under the terms of the GNU Lesser General Public
1746+ * License as published by the Free Software Foundation; either
1747+ * version 2.1 of the License, or (at your option) any later version.
1748+
1749+ * This library is distributed in the hope that it will be useful,
1750+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1751+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1752+ * Lesser General Public License for more details.
1753+
1754+ * You should have received a copy of the GNU Lesser General Public
1755+ * License along with this library; if not, write to the Free Software
1756+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1757+ *
1758+ * Authored By:
1759+ * Sam Spilsbury <sam.spilsbury@canonical.com>
1760+ */
1761+#include <tr1/tuple>
1762+
1763 #include <gtest/gtest.h>
1764 #include <gmock/gmock.h>
1765
1766+#include <boost/make_shared.hpp>
1767+#include <boost/shared_ptr.hpp>
1768+#include <boost/bind.hpp>
1769+
1770+#include <ccs.h>
1771+
1772+#include "compizconfig_ccs_context_mock.h"
1773+#include "compizconfig_ccs_plugin_mock.h"
1774+#include "compizconfig_ccs_setting_mock.h"
1775+
1776 #include "ccs_settings_upgrade_internal.h"
1777 #include "gtest_shared_characterwrapper.h"
1778+#include "gtest_shared_autodestroy.h"
1779+#include "compizconfig_ccs_list_equality.h"
1780+#include "compizconfig_ccs_item_in_list_matcher.h"
1781+#include "compizconfig_ccs_list_wrapper.h"
1782+#include "compizconfig_ccs_setting_value_operators.h"
1783
1784 using ::testing::IsNull;
1785+using ::testing::Eq;
1786+using ::testing::Return;
1787+using ::testing::AtLeast;
1788+using ::testing::_;
1789+using ::testing::AllOf;
1790+using ::testing::Not;
1791+using ::testing::Matcher;
1792+using ::testing::MakeMatcher;
1793+using ::testing::MatcherInterface;
1794+using ::testing::Pointee;
1795+
1796+namespace cc = compiz::config;
1797+namespace cci = compiz::config::impl;
1798
1799 class CCSSettingsUpgradeInternalTest :
1800 public ::testing::Test
1801@@ -15,6 +67,7 @@
1802 {
1803 static const std::string CCS_SETTINGS_UPGRADE_TEST_CORRECT_FILENAME = "org.compiz.general.1.upgrade";
1804 static const std::string CCS_SETTINGS_UPGRADE_TEST_INCORRECT_FILENAME = "1.upgra";
1805+ static const std::string CCS_SETTINGS_UPGRADE_TEST_VERY_INCORRECT_FILENAME = "1";
1806 static const std::string CCS_SETTINGS_UPGRADE_TEST_CORRECT_DOMAIN = "org.compiz";
1807 static const std::string CCS_SETTINGS_UPGRADE_TEST_CORRECT_PROFILE = "general";
1808 static const unsigned int CCS_SETTINGS_UPGRADE_TEST_CORRECT_NUM = 1;
1809@@ -23,7 +76,7 @@
1810 MATCHER(BoolTrue, "Bool True") { if (arg) return true; else return false; }
1811 MATCHER(BoolFalse, "Bool False") { if (!arg) return true; else return false; }
1812
1813-TEST_F (CCSSettingsUpgradeInternalTest, TestDetokenizeAndSetValues)
1814+TEST (CCSSettingsUpgradeInternalTest, TestDetokenizeAndSetValues)
1815 {
1816 char *profileName = NULL;
1817 char *domainName = NULL;
1818@@ -43,7 +96,7 @@
1819 EXPECT_EQ (num, CCS_SETTINGS_UPGRADE_TEST_CORRECT_NUM);
1820 }
1821
1822-TEST_F (CCSSettingsUpgradeInternalTest, TestDetokenizeAndSetValuesReturnsFalseIfInvalid)
1823+TEST (CCSSettingsUpgradeInternalTest, TestDetokenizeAndSetValuesReturnsFalseIfInvalid)
1824 {
1825 char *profileName = NULL;
1826 char *domainName = NULL;
1827@@ -57,14 +110,674 @@
1828
1829 EXPECT_THAT (profileName, IsNull ());
1830 EXPECT_THAT (domainName, IsNull ());
1831-}
1832-
1833-TEST_F (CCSSettingsUpgradeInternalTest, TestDetokenizeAndReturnTrueForUpgradeFileName)
1834-{
1835- EXPECT_THAT (ccsUpgradeNameFilter (CCS_SETTINGS_UPGRADE_TEST_CORRECT_FILENAME.c_str ()), BoolTrue ());
1836-}
1837-
1838-TEST_F (CCSSettingsUpgradeInternalTest, TestDetokenizeAndReturnFalseForNoUpgradeFileName)
1839-{
1840- EXPECT_THAT (ccsUpgradeNameFilter (CCS_SETTINGS_UPGRADE_TEST_CORRECT_FILENAME.c_str ()), BoolTrue ());
1841+
1842+ EXPECT_THAT (ccsUpgradeGetDomainNumAndProfile (CCS_SETTINGS_UPGRADE_TEST_VERY_INCORRECT_FILENAME.c_str (),
1843+ &domainName,
1844+ &num,
1845+ &profileName), BoolFalse ());
1846+
1847+ EXPECT_THAT (profileName, IsNull ());
1848+ EXPECT_THAT (domainName, IsNull ());
1849+}
1850+
1851+TEST (CCSSettingsUpgradeInternalTest, TestDetokenizeAndReturnTrueForUpgradeFileName)
1852+{
1853+ EXPECT_THAT (ccsUpgradeNameFilter (CCS_SETTINGS_UPGRADE_TEST_CORRECT_FILENAME.c_str ()), BoolTrue ());
1854+}
1855+
1856+TEST (CCSSettingsUpgradeInternalTest, TestDetokenizeAndReturnFalseForNoUpgradeFileName)
1857+{
1858+ EXPECT_THAT (ccsUpgradeNameFilter (CCS_SETTINGS_UPGRADE_TEST_INCORRECT_FILENAME.c_str ()), BoolFalse ());
1859+ EXPECT_THAT (ccsUpgradeNameFilter (CCS_SETTINGS_UPGRADE_TEST_VERY_INCORRECT_FILENAME.c_str ()), BoolFalse ());
1860+}
1861+
1862+namespace
1863+{
1864+ const std::string CCS_SETTINGS_UPGRADE_TEST_MOCK_PLUGIN_NAME = "mock";
1865+ const std::string CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE = "setting_one";
1866+ const std::string CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_TWO = "setting_two";
1867+
1868+ typedef std::tr1::tuple <boost::shared_ptr <CCSSetting>,
1869+ CCSSettingGMock *> MockedSetting;
1870+
1871+ inline CCSSetting * Real (MockedSetting &ms) { return (std::tr1::get <0> (ms)).get (); }
1872+ inline CCSSettingGMock & Mock (MockedSetting &ms) { return *(std::tr1::get <1> (ms)); }
1873+}
1874+
1875+class CCSSettingsUpgradeTestWithMockContext :
1876+ public ::testing::Test
1877+{
1878+ public:
1879+
1880+ typedef enum _AddMode
1881+ {
1882+ DoNotAddSettingToPlugin,
1883+ AddSettingToPlugin
1884+ } AddMode;
1885+
1886+ virtual void SetUp ()
1887+ {
1888+ context = AutoDestroy <CCSContext> (ccsMockContextNew (),
1889+ ccsFreeMockContext);
1890+ plugin = AutoDestroy <CCSPlugin> (ccsMockPluginNew (),
1891+ ccsFreeMockPlugin);
1892+
1893+ ON_CALL (MockPlugin (), getName ())
1894+ .WillByDefault (
1895+ Return (
1896+
1897+ CCS_SETTINGS_UPGRADE_TEST_MOCK_PLUGIN_NAME.c_str ()));
1898+
1899+ ON_CALL (MockPlugin (), getContext ())
1900+ .WillByDefault (
1901+ Return (
1902+ context.get ()));
1903+ }
1904+
1905+ CCSPluginGMock & MockPlugin ()
1906+ {
1907+ return *(reinterpret_cast <CCSPluginGMock *> (ccsObjectGetPrivate (plugin.get ())));
1908+ }
1909+
1910+ CCSContextGMock & MockContext ()
1911+ {
1912+ return *(reinterpret_cast <CCSContextGMock *> (ccsObjectGetPrivate (context.get ())));
1913+ }
1914+
1915+ void InitializeValueCommon (CCSSettingValue &value,
1916+ CCSSetting *setting)
1917+ {
1918+ value.parent = setting;
1919+ value.refCount = 1;
1920+ }
1921+
1922+ void InitializeValueForSetting (CCSSettingValue &value,
1923+ CCSSetting *setting)
1924+ {
1925+ InitializeValueCommon (value, setting);
1926+ value.isListChild = FALSE;
1927+ }
1928+
1929+
1930+ MockedSetting
1931+ SpawnSetting (const std::string &name,
1932+ CCSSettingType type,
1933+ AddMode addMode = AddSettingToPlugin)
1934+ {
1935+ boost::shared_ptr <CCSSetting> setting (ccsMockSettingNew (),
1936+ ccsSettingUnref);
1937+
1938+ CCSSettingGMock *gmockSetting = reinterpret_cast <CCSSettingGMock *> (ccsObjectGetPrivate (setting.get ()));
1939+
1940+ ON_CALL (*gmockSetting, getName ())
1941+ .WillByDefault (
1942+ Return (
1943+ name.c_str ()));
1944+ ON_CALL (*gmockSetting, getType ())
1945+ .WillByDefault (
1946+ Return (
1947+ type));
1948+
1949+ ON_CALL (*gmockSetting, getParent ())
1950+ .WillByDefault (
1951+ Return (
1952+ plugin.get ()));
1953+
1954+ if (addMode == AddSettingToPlugin)
1955+ {
1956+ ON_CALL (MockPlugin (), findSetting (Eq (name.c_str ())))
1957+ .WillByDefault (
1958+ Return (
1959+ setting.get ()));
1960+ }
1961+
1962+ return MockedSetting (setting, gmockSetting);
1963+ }
1964+
1965+ private:
1966+
1967+ boost::shared_ptr <CCSContext> context;
1968+ boost::shared_ptr <CCSPlugin> plugin;
1969+};
1970+
1971+namespace
1972+{
1973+ class CCSSettingValueMatcher :
1974+ public ::testing::MatcherInterface <CCSSettingValue>
1975+ {
1976+ public:
1977+
1978+ CCSSettingValueMatcher (const CCSSettingValue &match,
1979+ CCSSettingType type,
1980+ CCSSettingInfo *info) :
1981+ mMatch (match),
1982+ mType (type),
1983+ mInfo (info)
1984+ {
1985+ }
1986+
1987+ virtual bool MatchAndExplain (CCSSettingValue x, MatchResultListener *listener) const
1988+ {
1989+ if (ccsCheckValueEq (&x,
1990+ mType,
1991+ mInfo,
1992+ &mMatch,
1993+ mType,
1994+ mInfo))
1995+ return true;
1996+ return false;
1997+ }
1998+
1999+ virtual void DescribeTo (std::ostream *os) const
2000+ {
2001+ *os << "Value Matches";
2002+ }
2003+
2004+ virtual void DescribeNegationTo (std::ostream *os) const
2005+ {
2006+ *os << "Value does not Match";
2007+ }
2008+
2009+ private:
2010+
2011+ const CCSSettingValue &mMatch;
2012+ CCSSettingType mType;
2013+ CCSSettingInfo *mInfo;
2014+ };
2015+
2016+ Matcher <CCSSettingValue>
2017+ SettingValueMatch (const CCSSettingValue &match,
2018+ CCSSettingType type,
2019+ CCSSettingInfo *info)
2020+ {
2021+ return MakeMatcher (new CCSSettingValueMatcher (match, type, info));
2022+ }
2023+
2024+ typedef boost::shared_ptr <cc::ListWrapper <CCSSettingList, CCSSetting *> > CCSSettingListWrapperPtr;
2025+
2026+ CCSSettingListWrapperPtr
2027+ constructSettingListWrapper (CCSSettingList list,
2028+ cci::ListStorageType storageType)
2029+ {
2030+ return boost::make_shared <cci::ListWrapper <CCSSettingList, CCSSetting *> > (list,
2031+ ccsSettingListFree,
2032+ ccsSettingListAppend,
2033+ ccsSettingListRemove,
2034+ storageType);
2035+ }
2036+}
2037+
2038+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestNoClearValuesSettingNotFound)
2039+{
2040+ MockedSetting settingOne (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2041+ TypeInt,
2042+ DoNotAddSettingToPlugin));
2043+
2044+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)));
2045+ EXPECT_CALL (Mock (settingOne), getParent ());
2046+ EXPECT_CALL (Mock (settingOne), getName ());
2047+
2048+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (settingOne)),
2049+ cci::Shallow));
2050+
2051+ ccsUpgradeClearValues (*list);
2052+}
2053+
2054+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestClearValuesInListNonListType)
2055+{
2056+ MockedSetting resetSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2057+ TypeInt,
2058+ DoNotAddSettingToPlugin));
2059+ MockedSetting settingToReset (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2060+ TypeInt));
2061+ CCSSettingValue valueToReset;
2062+ CCSSettingValue valueResetIdentifier;
2063+
2064+ InitializeValueForSetting (valueToReset, Real (settingToReset));
2065+ InitializeValueForSetting (valueResetIdentifier, Real (resetSettingIdentifier));
2066+
2067+ valueToReset.value.asInt = 7;
2068+ valueResetIdentifier.value.asInt = 7;
2069+
2070+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (resetSettingIdentifier)),
2071+ cci::Shallow));
2072+
2073+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2074+ .WillOnce (Return (Real (settingToReset)));
2075+ EXPECT_CALL (Mock (resetSettingIdentifier), getParent ());
2076+ EXPECT_CALL (Mock (resetSettingIdentifier), getName ());
2077+
2078+ CCSSettingInfo info;
2079+
2080+ info.forInt.max = 0;
2081+ info.forInt.min = 10;
2082+
2083+ /* ccsCheckValueEq needs to know the type and info about this type */
2084+ EXPECT_CALL (Mock (settingToReset), getType ()).Times (AtLeast (1));
2085+ EXPECT_CALL (Mock (resetSettingIdentifier), getType ()).Times (AtLeast (1));
2086+
2087+ EXPECT_CALL (Mock (settingToReset), getInfo ()).WillRepeatedly (Return (&info));
2088+ EXPECT_CALL (Mock (resetSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2089+
2090+ EXPECT_CALL (Mock (resetSettingIdentifier), getValue ()).WillOnce (Return (&valueResetIdentifier));
2091+ EXPECT_CALL (Mock (settingToReset), getValue ()).WillOnce (Return (&valueToReset));
2092+
2093+ EXPECT_CALL (Mock (settingToReset), resetToDefault (BoolTrue ()));
2094+
2095+ ccsUpgradeClearValues (*list);
2096+}
2097+
2098+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestClearValuesInListNonListTypeNotMatched)
2099+{
2100+ MockedSetting resetSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2101+ TypeInt,
2102+ DoNotAddSettingToPlugin));
2103+ MockedSetting settingToReset (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2104+ TypeInt));
2105+ CCSSettingValue valueToReset;
2106+ CCSSettingValue valueResetIdentifier;
2107+
2108+ InitializeValueForSetting (valueToReset, Real (settingToReset));
2109+ InitializeValueForSetting (valueResetIdentifier, Real (resetSettingIdentifier));
2110+
2111+ valueToReset.value.asInt = 2;
2112+ valueResetIdentifier.value.asInt = 7;
2113+
2114+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (resetSettingIdentifier)),
2115+ cci::Shallow));
2116+
2117+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2118+ .WillOnce (Return (Real (settingToReset)));
2119+ EXPECT_CALL (Mock (resetSettingIdentifier), getParent ());
2120+ EXPECT_CALL (Mock (resetSettingIdentifier), getName ());
2121+
2122+ CCSSettingInfo info;
2123+
2124+ info.forInt.max = 0;
2125+ info.forInt.min = 10;
2126+
2127+ /* ccsCheckValueEq needs to know the type and info about this type */
2128+ EXPECT_CALL (Mock (settingToReset), getType ()).Times (AtLeast (1));
2129+ EXPECT_CALL (Mock (resetSettingIdentifier), getType ()).Times (AtLeast (1));
2130+
2131+ EXPECT_CALL (Mock (settingToReset), getInfo ()).WillRepeatedly (Return (&info));
2132+ EXPECT_CALL (Mock (resetSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2133+
2134+ EXPECT_CALL (Mock (resetSettingIdentifier), getValue ()).WillOnce (Return (&valueResetIdentifier));
2135+ EXPECT_CALL (Mock (settingToReset), getValue ()).WillOnce (Return (&valueToReset));
2136+
2137+ ccsUpgradeClearValues (*list);
2138+}
2139+
2140+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestNoAddValuesSettingNotFound)
2141+{
2142+ MockedSetting settingOne (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2143+ TypeInt,
2144+ DoNotAddSettingToPlugin));
2145+
2146+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)));
2147+ EXPECT_CALL (Mock (settingOne), getParent ());
2148+ EXPECT_CALL (Mock (settingOne), getName ());
2149+
2150+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (settingOne)),
2151+ cci::Shallow));
2152+
2153+ ccsUpgradeAddValues (*list);
2154+}
2155+
2156+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestAddValuesInListNonListType)
2157+{
2158+ MockedSetting addSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2159+ TypeInt,
2160+ DoNotAddSettingToPlugin));
2161+ MockedSetting settingToBeChanged (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2162+ TypeInt));
2163+ CCSSettingValue valueToReset;
2164+ CCSSettingValue valueResetIdentifier;
2165+
2166+ InitializeValueForSetting (valueToReset, Real (settingToBeChanged));
2167+ InitializeValueForSetting (valueResetIdentifier, Real (addSettingIdentifier));
2168+
2169+ valueToReset.value.asInt = 7;
2170+ valueResetIdentifier.value.asInt = 7;
2171+
2172+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (addSettingIdentifier)),
2173+ cci::Shallow));
2174+
2175+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2176+ .WillOnce (Return (Real (settingToBeChanged)));
2177+ EXPECT_CALL (Mock (addSettingIdentifier), getParent ());
2178+ EXPECT_CALL (Mock (addSettingIdentifier), getName ());
2179+
2180+ CCSSettingInfo info;
2181+
2182+ info.forInt.max = 0;
2183+ info.forInt.min = 10;
2184+
2185+ /* ccsCheckValueEq needs to know the type and info about this type */
2186+ EXPECT_CALL (Mock (settingToBeChanged), getType ()).Times (AtLeast (1));
2187+ EXPECT_CALL (Mock (addSettingIdentifier), getType ()).Times (AtLeast (1));
2188+
2189+ EXPECT_CALL (Mock (settingToBeChanged), getInfo ()).WillRepeatedly (Return (&info));
2190+ EXPECT_CALL (Mock (addSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2191+
2192+ EXPECT_CALL (Mock (addSettingIdentifier), getValue ()).WillOnce (Return (&valueResetIdentifier));
2193+
2194+ EXPECT_CALL (Mock (settingToBeChanged), setValue (Pointee (SettingValueMatch (valueResetIdentifier,
2195+ TypeInt,
2196+ &info)), BoolTrue ()));
2197+
2198+ ccsUpgradeAddValues (*list);
2199+}
2200+
2201+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestNoReplaceValuesSettingNotFound)
2202+{
2203+ MockedSetting fromSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2204+ TypeInt,
2205+ DoNotAddSettingToPlugin));
2206+ MockedSetting toSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2207+ TypeInt,
2208+ DoNotAddSettingToPlugin));
2209+
2210+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)));
2211+ EXPECT_CALL (Mock (fromSettingIdentifier), getParent ());
2212+ EXPECT_CALL (Mock (fromSettingIdentifier), getName ());
2213+
2214+ CCSSettingListWrapperPtr replaceFromValueSettings (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (fromSettingIdentifier)),
2215+ cci::Shallow));
2216+ CCSSettingListWrapperPtr replaceToValueSettings (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (toSettingIdentifier)),
2217+ cci::Shallow));
2218+
2219+
2220+ ccsUpgradeReplaceValues (*replaceFromValueSettings,
2221+ *replaceToValueSettings);
2222+}
2223+
2224+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestReplaceValuesInListNonListType)
2225+{
2226+ MockedSetting fromSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2227+ TypeInt,
2228+ DoNotAddSettingToPlugin));
2229+ MockedSetting toSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2230+ TypeInt,
2231+ DoNotAddSettingToPlugin));
2232+ MockedSetting settingToBeChanged (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2233+ TypeInt));
2234+ CCSSettingValue settingToBeChangedValue;
2235+ CCSSettingValue fromSettingIdentifierValue;
2236+ CCSSettingValue toSettingIdentifierValue;
2237+
2238+ InitializeValueForSetting (settingToBeChangedValue, Real (settingToBeChanged));
2239+ InitializeValueForSetting (fromSettingIdentifierValue, Real (fromSettingIdentifier));
2240+ InitializeValueForSetting (toSettingIdentifierValue, Real (toSettingIdentifier));
2241+
2242+ settingToBeChangedValue.value.asInt = 7;
2243+ fromSettingIdentifierValue.value.asInt = 7;
2244+ toSettingIdentifierValue.value.asInt = 8;
2245+
2246+ CCSSettingListWrapperPtr replaceFromValueSettings (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (fromSettingIdentifier)),
2247+ cci::Shallow));
2248+ CCSSettingListWrapperPtr replaceToValueSettings (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (toSettingIdentifier)),
2249+ cci::Shallow));
2250+
2251+
2252+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2253+ .WillOnce (Return (Real (settingToBeChanged)));
2254+ EXPECT_CALL (Mock (fromSettingIdentifier), getParent ());
2255+ EXPECT_CALL (Mock (fromSettingIdentifier), getName ());
2256+ EXPECT_CALL (Mock (toSettingIdentifier), getName ());
2257+
2258+ CCSSettingInfo info;
2259+
2260+ info.forInt.max = 0;
2261+ info.forInt.min = 10;
2262+
2263+ /* ccsCheckValueEq needs to know the type and info about this type */
2264+ EXPECT_CALL (Mock (settingToBeChanged), getType ()).Times (AtLeast (1));
2265+ EXPECT_CALL (Mock (fromSettingIdentifier), getType ()).Times (AtLeast (1));
2266+
2267+ EXPECT_CALL (Mock (settingToBeChanged), getInfo ()).WillRepeatedly (Return (&info));
2268+ EXPECT_CALL (Mock (fromSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2269+ EXPECT_CALL (Mock (toSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2270+
2271+ EXPECT_CALL (Mock (settingToBeChanged), getValue ()).WillOnce (Return (&settingToBeChangedValue));
2272+ EXPECT_CALL (Mock (fromSettingIdentifier), getValue ()).WillOnce (Return (&fromSettingIdentifierValue));
2273+ EXPECT_CALL (Mock (toSettingIdentifier), getValue ()).WillOnce (Return (&toSettingIdentifierValue));
2274+
2275+
2276+ EXPECT_CALL (Mock (settingToBeChanged), setValue (Pointee (SettingValueMatch (toSettingIdentifierValue,
2277+ TypeInt,
2278+ &info)), BoolTrue ()));
2279+
2280+ ccsUpgradeReplaceValues (*replaceFromValueSettings,
2281+ *replaceToValueSettings);
2282+}
2283+
2284+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestReplaceValuesInListNonListTypeNoMatch)
2285+{
2286+ MockedSetting fromSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2287+ TypeInt,
2288+ DoNotAddSettingToPlugin));
2289+ MockedSetting toSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2290+ TypeInt,
2291+ DoNotAddSettingToPlugin));
2292+ MockedSetting settingToBeChanged (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2293+ TypeInt));
2294+ CCSSettingValue settingToBeChangedValue;
2295+ CCSSettingValue fromSettingIdentifierValue;
2296+ CCSSettingValue toSettingIdentifierValue;
2297+
2298+ InitializeValueForSetting (settingToBeChangedValue, Real (settingToBeChanged));
2299+ InitializeValueForSetting (fromSettingIdentifierValue, Real (fromSettingIdentifier));
2300+ InitializeValueForSetting (toSettingIdentifierValue, Real (toSettingIdentifier));
2301+
2302+ settingToBeChangedValue.value.asInt = 6;
2303+ fromSettingIdentifierValue.value.asInt = 7;
2304+ toSettingIdentifierValue.value.asInt = 8;
2305+
2306+ CCSSettingListWrapperPtr replaceFromValueSettings (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (fromSettingIdentifier)),
2307+ cci::Shallow));
2308+ CCSSettingListWrapperPtr replaceToValueSettings (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (toSettingIdentifier)),
2309+ cci::Shallow));
2310+
2311+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2312+ .WillOnce (Return (Real (settingToBeChanged)));
2313+ EXPECT_CALL (Mock (fromSettingIdentifier), getParent ());
2314+ EXPECT_CALL (Mock (fromSettingIdentifier), getName ());
2315+
2316+ CCSSettingInfo info;
2317+
2318+ info.forInt.max = 0;
2319+ info.forInt.min = 10;
2320+
2321+ /* ccsCheckValueEq needs to know the type and info about this type */
2322+ EXPECT_CALL (Mock (settingToBeChanged), getType ()).Times (AtLeast (1));
2323+ EXPECT_CALL (Mock (fromSettingIdentifier), getType ()).Times (AtLeast (1));
2324+
2325+ EXPECT_CALL (Mock (settingToBeChanged), getInfo ()).WillRepeatedly (Return (&info));
2326+ EXPECT_CALL (Mock (fromSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2327+ EXPECT_CALL (Mock (toSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2328+
2329+ EXPECT_CALL (Mock (settingToBeChanged), getValue ()).WillOnce (Return (&settingToBeChangedValue));
2330+ EXPECT_CALL (Mock (fromSettingIdentifier), getValue ()).WillOnce (Return (&fromSettingIdentifierValue));
2331+
2332+ ccsUpgradeReplaceValues (*replaceFromValueSettings,
2333+ *replaceToValueSettings);
2334+}
2335+
2336+namespace
2337+{
2338+ boost::shared_ptr <CCSString>
2339+ newOwnedCCSStringFromStaticCharArray (const char *cStr)
2340+ {
2341+ CCSString *string = reinterpret_cast <CCSString *> (calloc (1, sizeof (CCSString)));
2342+ boost::shared_ptr <CCSString> str (string,
2343+ ccsStringUnref);
2344+
2345+ str->value = strdup (cStr);
2346+ ccsStringRef (str.get ());
2347+ return str;
2348+ }
2349+
2350+ void
2351+ ccsStringListDeepFree (CCSStringList list)
2352+ {
2353+ ccsStringListFree (list, TRUE);
2354+ }
2355+
2356+ void
2357+ ccsSettingValueListDeepFree (CCSSettingValueList list)
2358+ {
2359+ ccsSettingValueListFree (list, TRUE);
2360+ }
2361+
2362+ void
2363+ ccsSettingValueListShallowFree (CCSSettingValueList list)
2364+ {
2365+ ccsSettingValueListFree (list, FALSE);
2366+ }
2367+
2368+ typedef boost::shared_ptr <cc::ListWrapper <CCSStringList, CCSString *> > CCSStringListWrapperPtr;
2369+
2370+ CCSStringListWrapperPtr
2371+ constructStrListWrapper (CCSStringList list,
2372+ cci::ListStorageType storageType)
2373+ {
2374+ return boost::make_shared <cci::ListWrapper <CCSStringList, CCSString *> > (list,
2375+ ccsStringListFree,
2376+ ccsStringListAppend,
2377+ ccsStringListRemove,
2378+ storageType);
2379+ }
2380+}
2381+
2382+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestAddValuesInListAppendsValuesToListFromList)
2383+{
2384+ const std::string valueOne ("value_one");
2385+ const std::string valueThree ("value_three");
2386+ MockedSetting appendSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2387+ TypeList,
2388+ DoNotAddSettingToPlugin));
2389+ MockedSetting settingToAppendValuesTo (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2390+ TypeList));
2391+
2392+ boost::shared_ptr <CCSString> stringToAppendOne (newOwnedCCSStringFromStaticCharArray (valueOne.c_str ()));
2393+ boost::shared_ptr <CCSString> stringInBothLists (newOwnedCCSStringFromStaticCharArray (valueThree.c_str ()));
2394+
2395+ CCSStringListWrapperPtr settingsStrList (constructStrListWrapper (ccsStringListAppend (NULL, stringInBothLists.get ()),
2396+ cci::Shallow));
2397+
2398+
2399+ boost::shared_ptr <_CCSSettingValueList> settingStrValueList (AutoDestroy (ccsGetValueListFromStringList (*settingsStrList,
2400+ Real (settingToAppendValuesTo)),
2401+ ccsSettingValueListDeepFree));
2402+
2403+ CCSStringListWrapperPtr appendStrList (constructStrListWrapper (ccsStringListAppend (NULL, stringInBothLists.get ()),
2404+ cci::Shallow));
2405+ appendStrList->append (stringToAppendOne.get ());
2406+
2407+ boost::shared_ptr <_CCSSettingValueList> appendStrValueList (AutoDestroy (ccsGetValueListFromStringList (*appendStrList,
2408+ Real (appendSettingIdentifier)),
2409+ ccsSettingValueListDeepFree));
2410+
2411+
2412+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (appendSettingIdentifier)),
2413+ cci::Shallow));
2414+
2415+ CCSSettingValue valueToHaveSubValuesAdded;
2416+ CCSSettingValue valueSubValuesAddIdentifiers;
2417+
2418+ InitializeValueForSetting (valueToHaveSubValuesAdded, Real (settingToAppendValuesTo));
2419+ InitializeValueForSetting (valueSubValuesAddIdentifiers, Real (appendSettingIdentifier));
2420+
2421+ valueToHaveSubValuesAdded.value.asList = settingStrValueList.get ();
2422+ valueSubValuesAddIdentifiers.value.asList = appendStrValueList.get ();
2423+
2424+ CCSSettingInfo info;
2425+
2426+ info.forList.listType = TypeString;
2427+
2428+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2429+ .WillOnce (Return (Real (settingToAppendValuesTo)));
2430+ EXPECT_CALL (Mock (appendSettingIdentifier), getParent ());
2431+ EXPECT_CALL (Mock (appendSettingIdentifier), getName ());
2432+ EXPECT_CALL (Mock (appendSettingIdentifier), getType ()).Times (AtLeast (1));
2433+ EXPECT_CALL (Mock (settingToAppendValuesTo), getType ()).Times (AtLeast (1));
2434+ EXPECT_CALL (Mock (appendSettingIdentifier), getValue ()).WillOnce (Return (&valueSubValuesAddIdentifiers));
2435+ EXPECT_CALL (Mock (settingToAppendValuesTo), getValue ()).WillOnce (Return (&valueToHaveSubValuesAdded));
2436+ EXPECT_CALL (Mock (settingToAppendValuesTo), getInfo ()).WillRepeatedly (Return (&info));
2437+ EXPECT_CALL (Mock (appendSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2438+
2439+ const CCSSettingValue &appendedStringInListValue = *appendStrValueList->next->data;
2440+
2441+ EXPECT_CALL (Mock (settingToAppendValuesTo), setList (
2442+ IsSettingValueInSettingValueCCSList (
2443+ SettingValueMatch (appendedStringInListValue, TypeString, &info)), BoolTrue ()));
2444+
2445+ ccsUpgradeAddValues (*list);
2446+}
2447+
2448+TEST_F (CCSSettingsUpgradeTestWithMockContext, TestClearValuesInListRemovesValuesFromList)
2449+{
2450+ const std::string valueOne ("value_one");
2451+ const std::string valueThree ("value_three");
2452+ MockedSetting resetSettingIdentifier (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2453+ TypeList,
2454+ DoNotAddSettingToPlugin));
2455+ MockedSetting settingToRemoveValuesFrom (SpawnSetting (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE,
2456+ TypeList));
2457+
2458+ boost::shared_ptr <CCSString> stringForRemovalOne (newOwnedCCSStringFromStaticCharArray (valueOne.c_str ()));
2459+ boost::shared_ptr <CCSString> stringNotRemoved (newOwnedCCSStringFromStaticCharArray (valueThree.c_str ()));
2460+
2461+ CCSStringListWrapperPtr settingsStrList (constructStrListWrapper (ccsStringListAppend (NULL, stringForRemovalOne.get ()),
2462+ cci::Shallow));
2463+ settingsStrList->append (stringNotRemoved.get ());
2464+
2465+ boost::shared_ptr <_CCSSettingValueList> settingStrValueList (AutoDestroy (ccsGetValueListFromStringList (*settingsStrList,
2466+ Real (settingToRemoveValuesFrom)),
2467+ ccsSettingValueListDeepFree));
2468+
2469+ CCSStringListWrapperPtr removeStrList (constructStrListWrapper (ccsStringListAppend (NULL, stringForRemovalOne.get ()),
2470+ cci::Shallow));
2471+
2472+ boost::shared_ptr <_CCSSettingValueList> removeStrValueList (AutoDestroy (ccsGetValueListFromStringList (*removeStrList,
2473+ Real (resetSettingIdentifier)),
2474+ ccsSettingValueListDeepFree));
2475+
2476+ CCSSettingListWrapperPtr list (constructSettingListWrapper (ccsSettingListAppend (NULL, Real (resetSettingIdentifier)),
2477+ cci::Shallow));
2478+
2479+ CCSSettingValue valueToHaveSubValuesRemoved;
2480+ CCSSettingValue valueSubValuesResetIdentifiers;
2481+
2482+ InitializeValueForSetting (valueToHaveSubValuesRemoved, Real (settingToRemoveValuesFrom));
2483+ InitializeValueForSetting (valueSubValuesResetIdentifiers, Real (resetSettingIdentifier));
2484+
2485+ valueToHaveSubValuesRemoved.value.asList = settingStrValueList.get ();
2486+ valueSubValuesResetIdentifiers.value.asList = removeStrValueList.get ();
2487+
2488+ CCSSettingInfo info;
2489+
2490+ info.forList.listType = TypeString;
2491+
2492+ EXPECT_CALL (MockPlugin (), findSetting (Eq (CCS_SETTINGS_UPGRADE_TEST_MOCK_SETTING_NAME_ONE)))
2493+ .WillOnce (Return (Real (settingToRemoveValuesFrom)));
2494+ EXPECT_CALL (Mock (resetSettingIdentifier), getParent ());
2495+ EXPECT_CALL (Mock (resetSettingIdentifier), getName ());
2496+ EXPECT_CALL (Mock (resetSettingIdentifier), getType ()).Times (AtLeast (1));
2497+ EXPECT_CALL (Mock (settingToRemoveValuesFrom), getType ()).Times (AtLeast (1));
2498+ EXPECT_CALL (Mock (resetSettingIdentifier), getValue ()).WillOnce (Return (&valueSubValuesResetIdentifiers));
2499+ EXPECT_CALL (Mock (settingToRemoveValuesFrom), getValue ()).WillOnce (Return (&valueToHaveSubValuesRemoved));
2500+ EXPECT_CALL (Mock (settingToRemoveValuesFrom), getInfo ()).WillRepeatedly (Return (&info));
2501+ EXPECT_CALL (Mock (resetSettingIdentifier), getInfo ()).WillRepeatedly (Return (&info));
2502+
2503+ const CCSSettingValue &removedStringInListValue = *removeStrValueList->data;
2504+
2505+ EXPECT_CALL (Mock (settingToRemoveValuesFrom), setList (
2506+ Not (
2507+ IsSettingValueInSettingValueCCSList (
2508+ SettingValueMatch (removedStringInListValue, TypeString, &info))), BoolTrue ()));
2509+
2510+ ccsUpgradeClearValues (*list);
2511 }
2512
2513=== added file 'compizconfig/libcompizconfig/tests/compizconfig_test_ccs_text_file.cpp'
2514--- compizconfig/libcompizconfig/tests/compizconfig_test_ccs_text_file.cpp 1970-01-01 00:00:00 +0000
2515+++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_text_file.cpp 2012-09-24 12:00:13 +0000
2516@@ -0,0 +1,49 @@
2517+#include <cstring>
2518+
2519+#include <gtest/gtest.h>
2520+#include <gmock/gmock.h>
2521+
2522+#include <boost/shared_ptr.hpp>
2523+#include <boost/bind.hpp>
2524+
2525+#include <ccs.h>
2526+
2527+#include "ccs_text_file_interface.h"
2528+#include "compizconfig_ccs_text_file_mock.h"
2529+
2530+#include <gtest_shared_characterwrapper.h>
2531+#include <gtest_shared_autodestroy.h>
2532+
2533+using ::testing::_;
2534+using ::testing::Return;
2535+using ::testing::Eq;
2536+
2537+class CCSTextFileTest :
2538+ public ::testing::Test
2539+{
2540+};
2541+
2542+namespace
2543+{
2544+ const std::string CCS_TEXT_FILE_TESTING_CONTENTS;
2545+ const std::string CCS_TEXT_FILE_APPEND_CONTENTS;
2546+}
2547+
2548+MATCHER(BoolTrue, "Boolean True") { if (arg) return true; else return false; }
2549+
2550+TEST(CCSTextFileTest, TestMock)
2551+{
2552+ boost::shared_ptr <CCSTextFile> textFile (AutoDestroy (ccsMockTextFileNew (&ccsDefaultObjectAllocator),
2553+ ccsTextFileUnref));
2554+ CCSTextFileGMock *mock = reinterpret_cast <CCSTextFileGMock *> (ccsObjectGetPrivate (textFile));
2555+
2556+ CharacterWrapper temporaryFileContents (strdup (CCS_TEXT_FILE_TESTING_CONTENTS.c_str ()));
2557+ char *temporaryFileContentsC = temporaryFileContents;
2558+
2559+ EXPECT_CALL (*mock, readFromStart ()).WillOnce (Return (temporaryFileContentsC));
2560+ EXPECT_CALL (*mock, appendString (Eq (CCS_TEXT_FILE_APPEND_CONTENTS))).WillOnce (Return (TRUE));
2561+ EXPECT_CALL (*mock, free ());
2562+
2563+ EXPECT_THAT (ccsTextFileReadFromStart (textFile.get ()), Eq (CCS_TEXT_FILE_TESTING_CONTENTS));
2564+ EXPECT_THAT (ccsTextFileAppendString (textFile.get (), CCS_TEXT_FILE_APPEND_CONTENTS.c_str ()), BoolTrue ());
2565+}
2566
2567=== modified file 'compizconfig/mocks/libcompizconfig/CMakeLists.txt'
2568--- compizconfig/mocks/libcompizconfig/CMakeLists.txt 2012-09-10 01:05:28 +0000
2569+++ compizconfig/mocks/libcompizconfig/CMakeLists.txt 2012-09-24 12:00:13 +0000
2570@@ -1,6 +1,8 @@
2571 include_directories (${GTEST_INCLUDE_DIRS})
2572 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/include)
2573+include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/src)
2574 link_directories (${CMAKE_INSTALL_PREFIX}/lib)
2575+link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/src)
2576
2577 if (HAVE_PROTOBUF)
2578 set (LIBCOMPIZCONFIG_LIBRARIES
2579@@ -20,6 +22,9 @@
2580 add_library (compizconfig_ccs_backend_mock
2581 ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_backend_mock.cpp)
2582
2583+add_library (compizconfig_ccs_text_file_mock
2584+ ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_text_file_mock.cpp)
2585+
2586 target_link_libraries (compizconfig_ccs_context_mock
2587 ${GTEST_BOTH_LIBRARIES}
2588 ${GMOCK_LIBRARY}
2589@@ -51,3 +56,9 @@
2590 ${CMAKE_THREAD_LIBS_INIT}
2591 ${LIBCOMPIZCONFIG_LIBRARIES}
2592 compizconfig)
2593+
2594+target_link_libraries (compizconfig_ccs_text_file_mock
2595+ ${GTEST_BOTH_LIBRARIES}
2596+ ${GMOCK_LIBRARY}
2597+ ${GMOCK_MAIN_LIBRARY}
2598+ ${CMAKE_THREAD_LIBS_INIT})
2599
2600=== modified file 'compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h'
2601--- compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h 2012-09-10 01:05:28 +0000
2602+++ compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h 2012-09-24 12:00:13 +0000
2603@@ -23,7 +23,7 @@
2604 virtual void setPrivatePtr (void *) = 0;
2605 virtual Bool loadPlugin (char *name) = 0;
2606 virtual CCSPlugin * findPlugin (const char *name) = 0;
2607- virtual Bool pluginIsActive (char *name) = 0;
2608+ virtual Bool pluginIsActive (const char *name) = 0;
2609 virtual CCSPluginList getActivePluginList () = 0;
2610 virtual CCSStringList getSortedPluginStringList () = 0;
2611 virtual const char * getBackend () = 0;
2612@@ -71,7 +71,7 @@
2613 MOCK_METHOD1 (setPrivatePtr, void (void *));
2614 MOCK_METHOD1 (loadPlugin, Bool (char *));
2615 MOCK_METHOD1 (findPlugin, CCSPlugin * (const char *));
2616- MOCK_METHOD1 (pluginIsActive, Bool (char *));
2617+ MOCK_METHOD1 (pluginIsActive, Bool (const char *));
2618 MOCK_METHOD0 (getActivePluginList, CCSPluginList ());
2619 MOCK_METHOD0 (getSortedPluginStringList, CCSStringList ());
2620 MOCK_METHOD0 (getBackend, const char * ());
2621@@ -163,7 +163,7 @@
2622 }
2623
2624 static Bool
2625- ccsPluginIsActive (CCSContext *context, char *name)
2626+ ccsPluginIsActive (CCSContext *context, const char *name)
2627 {
2628 return ((CCSContextGMock *) ccsObjectGetPrivate (context))->pluginIsActive (name);
2629 }
2630
2631=== modified file 'compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h'
2632--- compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h 2012-09-10 01:05:28 +0000
2633+++ compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h 2012-09-24 12:00:13 +0000
2634@@ -12,11 +12,11 @@
2635
2636 virtual ~CCSPluginGMockInterface () {};
2637
2638- virtual char * getName () = 0;
2639- virtual char * getShortDesc () = 0;
2640- virtual char * getLongDesc () = 0;
2641- virtual char * getHints () = 0;
2642- virtual char * getCategory () = 0;
2643+ virtual const char * getName () = 0;
2644+ virtual const char * getShortDesc () = 0;
2645+ virtual const char * getLongDesc () = 0;
2646+ virtual const char * getHints () = 0;
2647+ virtual const char * getCategory () = 0;
2648 virtual CCSStringList getLoadAfter () = 0;
2649 virtual CCSStringList getLoadBefore () = 0;
2650 virtual CCSStringList getRequiresPlugins () = 0;
2651@@ -47,11 +47,11 @@
2652 plugin () { return mPlugin; }
2653
2654 /* Mock implementations */
2655- MOCK_METHOD0 (getName, char * ());
2656- MOCK_METHOD0 (getShortDesc, char * ());
2657- MOCK_METHOD0 (getLongDesc, char * ());
2658- MOCK_METHOD0 (getHints, char * ());
2659- MOCK_METHOD0 (getCategory, char * ());
2660+ MOCK_METHOD0 (getName, const char * ());
2661+ MOCK_METHOD0 (getShortDesc, const char * ());
2662+ MOCK_METHOD0 (getLongDesc, const char * ());
2663+ MOCK_METHOD0 (getHints, const char * ());
2664+ MOCK_METHOD0 (getCategory, const char * ());
2665 MOCK_METHOD0 (getLoadAfter, CCSStringList ());
2666 MOCK_METHOD0 (getLoadBefore, CCSStringList ());
2667 MOCK_METHOD0 (getRequiresPlugins, CCSStringList ());
2668@@ -74,27 +74,27 @@
2669 public:
2670
2671 /* Thunking C to C++ */
2672- static char * ccsPluginGetName (CCSPlugin *plugin)
2673+ static const char * ccsPluginGetName (CCSPlugin *plugin)
2674 {
2675 return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getName ();
2676 }
2677
2678- static char * ccsPluginGetShortDesc (CCSPlugin *plugin)
2679+ static const char * ccsPluginGetShortDesc (CCSPlugin *plugin)
2680 {
2681 return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getShortDesc ();
2682 }
2683
2684- static char * ccsPluginGetLongDesc (CCSPlugin *plugin)
2685+ static const char * ccsPluginGetLongDesc (CCSPlugin *plugin)
2686 {
2687 return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getLongDesc ();
2688 }
2689
2690- static char * ccsPluginGetHints (CCSPlugin *plugin)
2691+ static const char * ccsPluginGetHints (CCSPlugin *plugin)
2692 {
2693 return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getHints ();
2694 }
2695
2696- static char * ccsPluginGetCategory (CCSPlugin *plugin)
2697+ static const char * ccsPluginGetCategory (CCSPlugin *plugin)
2698 {
2699 return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getCategory ();
2700 }
2701
2702=== modified file 'compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h'
2703--- compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h 2012-09-10 01:05:28 +0000
2704+++ compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h 2012-09-24 12:00:13 +0000
2705@@ -19,14 +19,14 @@
2706
2707 virtual ~CCSSettingGMockInterface () {};
2708
2709- virtual char * getName () = 0;
2710- virtual char * getShortDesc () = 0;
2711- virtual char * getLongDesc () = 0;
2712+ virtual const char * getName () = 0;
2713+ virtual const char * getShortDesc () = 0;
2714+ virtual const char * getLongDesc () = 0;
2715 virtual CCSSettingType getType () = 0;
2716 virtual CCSSettingInfo * getInfo () = 0;
2717- virtual char * getGroup () = 0;
2718- virtual char * getSubGroup () = 0;
2719- virtual char * getHints () = 0;
2720+ virtual const char * getGroup () = 0;
2721+ virtual const char * getSubGroup () = 0;
2722+ virtual const char * getHints () = 0;
2723 virtual CCSSettingValue * getDefaultValue () = 0;
2724 virtual CCSSettingValue * getValue () = 0;
2725 virtual Bool getIsDefault () = 0;
2726@@ -78,14 +78,14 @@
2727
2728 CCSSetting * setting () { return mSetting; }
2729
2730- MOCK_METHOD0 (getName, char * ());
2731- MOCK_METHOD0 (getShortDesc, char * ());
2732- MOCK_METHOD0 (getLongDesc, char * ());
2733+ MOCK_METHOD0 (getName, const char * ());
2734+ MOCK_METHOD0 (getShortDesc, const char * ());
2735+ MOCK_METHOD0 (getLongDesc, const char * ());
2736 MOCK_METHOD0 (getType, CCSSettingType ());
2737 MOCK_METHOD0 (getInfo, CCSSettingInfo * ());
2738- MOCK_METHOD0 (getGroup, char * ());
2739- MOCK_METHOD0 (getSubGroup, char * ());
2740- MOCK_METHOD0 (getHints, char * ());
2741+ MOCK_METHOD0 (getGroup, const char * ());
2742+ MOCK_METHOD0 (getSubGroup, const char * ());
2743+ MOCK_METHOD0 (getHints, const char * ());
2744 MOCK_METHOD0 (getDefaultValue, CCSSettingValue * ());
2745 MOCK_METHOD0 (getValue, CCSSettingValue * ());
2746 MOCK_METHOD0 (getIsDefault, Bool ());
2747@@ -291,18 +291,18 @@
2748 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->isReadOnly ();
2749 }
2750
2751- static char * ccsSettingGetName (CCSSetting *setting)
2752+ static const char * ccsSettingGetName (CCSSetting *setting)
2753 {
2754 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getName ();
2755 }
2756
2757- static char * ccsSettingGetShortDesc (CCSSetting *setting)
2758+ static const char * ccsSettingGetShortDesc (CCSSetting *setting)
2759
2760 {
2761 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getShortDesc ();
2762 }
2763
2764- static char * ccsSettingGetLongDesc (CCSSetting *setting)
2765+ static const char * ccsSettingGetLongDesc (CCSSetting *setting)
2766 {
2767 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getLongDesc ();
2768 }
2769@@ -317,17 +317,17 @@
2770 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getInfo ();
2771 }
2772
2773- static char * ccsSettingGetGroup (CCSSetting *setting)
2774+ static const char * ccsSettingGetGroup (CCSSetting *setting)
2775 {
2776 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getGroup ();
2777 }
2778
2779- static char * ccsSettingGetSubGroup (CCSSetting *setting)
2780+ static const char * ccsSettingGetSubGroup (CCSSetting *setting)
2781 {
2782 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getSubGroup ();
2783 }
2784
2785- static char * ccsSettingGetHints (CCSSetting *setting)
2786+ static const char * ccsSettingGetHints (CCSSetting *setting)
2787 {
2788 return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->getHints ();
2789 }
2790
2791=== added file 'compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.cpp'
2792--- compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.cpp 1970-01-01 00:00:00 +0000
2793+++ compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.cpp 2012-09-24 12:00:13 +0000
2794@@ -0,0 +1,104 @@
2795+/*
2796+ * Compiz configuration system library
2797+ *
2798+ * Copyright (C) 2012 Canonical Ltd.
2799+ *
2800+ * This library is free software; you can redistribute it and/or
2801+ * modify it under the terms of the GNU Lesser General Public
2802+ * License as published by the Free Software Foundation; either
2803+ * version 2.1 of the License, or (at your option) any later version.
2804+
2805+ * This library is distributed in the hope that it will be useful,
2806+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2807+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2808+ * Lesser General Public License for more details.
2809+
2810+ * You should have received a copy of the GNU Lesser General Public
2811+ * License along with this library; if not, write to the Free Software
2812+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2813+ *
2814+ * Authored By:
2815+ * Sam Spilsbury <sam.spilsbury@canonical.com>
2816+ */
2817+#include <gtest/gtest.h>
2818+#include <gmock/gmock.h>
2819+
2820+#include <ccs-object.h>
2821+#include <ccs_text_file_interface.h>
2822+#include "compizconfig_ccs_text_file_mock.h"
2823+
2824+const CCSTextFileInterface ccsMockTextFileInterface =
2825+{
2826+ CCSTextFileGMock::ccsTextFileReadFromStart,
2827+ CCSTextFileGMock::ccsTextFileAppendString,
2828+ CCSTextFileGMock::ccsFreeTextFile
2829+};
2830+
2831+static void
2832+finalizeAndFreeTextFile (CCSTextFile *textFile)
2833+{
2834+ CCSObjectAllocationInterface *ai = textFile->object.object_allocation;
2835+
2836+ ccsObjectFinalize (textFile);
2837+ (*ai->free_) (ai->allocator, textFile);
2838+}
2839+
2840+void
2841+ccsFreeMockTextFile (CCSTextFile *textFile)
2842+{
2843+ CCSTextFileGMock *gmock = reinterpret_cast <CCSTextFileGMock *> (ccsObjectGetPrivate (textFile));
2844+ delete gmock;
2845+
2846+ ccsObjectSetPrivate (textFile, NULL);
2847+ finalizeAndFreeTextFile (textFile);
2848+
2849+}
2850+
2851+static CCSTextFileGMock *
2852+newCCSTextFileGMockInterface (CCSTextFile *textFile)
2853+{
2854+ CCSTextFileGMock *gmock = new CCSTextFileGMock ();
2855+
2856+ if (!gmock)
2857+ {
2858+ finalizeAndFreeTextFile (textFile);
2859+ return NULL;
2860+ }
2861+
2862+ return gmock;
2863+}
2864+
2865+static CCSTextFile *
2866+allocateCCSTextFile (CCSObjectAllocationInterface *ai)
2867+{
2868+ CCSTextFile *textFile = reinterpret_cast <CCSTextFile *> ((*ai->calloc_) (ai->allocator, 1, sizeof (CCSTextFile)));
2869+
2870+ if (!textFile)
2871+ return NULL;
2872+
2873+ ccsObjectInit (textFile, ai);
2874+
2875+ return textFile;
2876+}
2877+
2878+CCSTextFile *
2879+ccsMockTextFileNew (CCSObjectAllocationInterface *ai)
2880+{
2881+ CCSTextFile *textFile = allocateCCSTextFile (ai);
2882+
2883+ if (!textFile)
2884+ return NULL;
2885+
2886+ CCSTextFileGMock *gmock = newCCSTextFileGMockInterface (textFile);
2887+
2888+ if (!gmock)
2889+ return NULL;
2890+
2891+ ccsObjectSetPrivate (textFile, (CCSPrivate *) gmock);
2892+ ccsObjectAddInterface (textFile,
2893+ (const CCSInterface *) &ccsMockTextFileInterface,
2894+ GET_INTERFACE_TYPE (CCSTextFileInterface));
2895+ ccsObjectRef (textFile);
2896+
2897+ return textFile;
2898+}
2899
2900=== added file 'compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.h'
2901--- compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.h 1970-01-01 00:00:00 +0000
2902+++ compizconfig/mocks/libcompizconfig/compizconfig_ccs_text_file_mock.h 2012-09-24 12:00:13 +0000
2903@@ -0,0 +1,84 @@
2904+/*
2905+ * Compiz configuration system library
2906+ *
2907+ * Copyright (C) 2012 Canonical Ltd.
2908+ *
2909+ * This library is free software; you can redistribute it and/or
2910+ * modify it under the terms of the GNU Lesser General Public
2911+ * License as published by the Free Software Foundation; either
2912+ * version 2.1 of the License, or (at your option) any later version.
2913+
2914+ * This library is distributed in the hope that it will be useful,
2915+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2916+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2917+ * Lesser General Public License for more details.
2918+
2919+ * You should have received a copy of the GNU Lesser General Public
2920+ * License along with this library; if not, write to the Free Software
2921+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2922+ *
2923+ * Authored By:
2924+ * Sam Spilsbury <sam.spilsbury@canonical.com>
2925+ */
2926+#ifndef COMPIZCONFIG_CCS_TEST_FILE_MOCK_H
2927+#define COMPIZCONFIG_CCS_TEST_FILE_MOCK_H
2928+
2929+#include <gtest/gtest.h>
2930+#include <gmock/gmock.h>
2931+
2932+#include <ccs-object.h>
2933+#include <ccs-defs.h>
2934+
2935+COMPIZCONFIG_BEGIN_DECLS
2936+
2937+typedef struct _CCSTextFile CCSTextFile;
2938+typedef struct _CCSObjectAllocationInterface CCSObjectAllocationInterface;
2939+
2940+CCSTextFile * ccsMockTextFileNew (CCSObjectAllocationInterface *ai);
2941+void ccsFreeMockTextFile (CCSTextFile *);
2942+
2943+COMPIZCONFIG_END_DECLS
2944+
2945+class CCSTextFileGMockInterface
2946+{
2947+ public:
2948+
2949+ virtual ~CCSTextFileGMockInterface () {}
2950+ virtual char * readFromStart () = 0;
2951+ virtual Bool appendString (const char *) = 0;
2952+ virtual void free () = 0;
2953+};
2954+
2955+class CCSTextFileGMock :
2956+ public CCSTextFileGMockInterface
2957+{
2958+ public:
2959+
2960+ MOCK_METHOD0 (readFromStart, char * ());
2961+ MOCK_METHOD1 (appendString, Bool (const char *));
2962+ MOCK_METHOD0 (free, void ());
2963+
2964+ public:
2965+
2966+ static char *
2967+ ccsTextFileReadFromStart (CCSTextFile *file)
2968+ {
2969+ return reinterpret_cast <CCSTextFileGMock *> (ccsObjectGetPrivate (file))->readFromStart ();
2970+ }
2971+
2972+ static Bool
2973+ ccsTextFileAppendString (CCSTextFile *file, const char *str)
2974+ {
2975+ return reinterpret_cast <CCSTextFileGMock *> (ccsObjectGetPrivate (file))->appendString (str);
2976+ }
2977+
2978+ static void
2979+ ccsFreeTextFile (CCSTextFile *file)
2980+ {
2981+ reinterpret_cast <CCSTextFileGMock *> (ccsObjectGetPrivate (file))->free ();
2982+ ccsFreeMockTextFile (file);
2983+ }
2984+
2985+};
2986+
2987+#endif
2988
2989=== modified file 'compizconfig/tests/compizconfig_backend_concept_test.h'
2990--- compizconfig/tests/compizconfig_backend_concept_test.h 2012-09-10 01:05:28 +0000
2991+++ compizconfig/tests/compizconfig_backend_concept_test.h 2012-09-24 12:00:13 +0000
2992@@ -1,3 +1,25 @@
2993+/*
2994+ * Compiz configuration system library
2995+ *
2996+ * Copyright (C) 2012 Canonical Ltd.
2997+ *
2998+ * This library is free software; you can redistribute it and/or
2999+ * modify it under the terms of the GNU Lesser General Public
3000+ * License as published by the Free Software Foundation; either
3001+ * version 2.1 of the License, or (at your option) any later version.
3002+
3003+ * This library is distributed in the hope that it will be useful,
3004+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3005+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3006+ * Lesser General Public License for more details.
3007+
3008+ * You should have received a copy of the GNU Lesser General Public
3009+ * License along with this library; if not, write to the Free Software
3010+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3011+ *
3012+ * Authored By:
3013+ * Sam Spilsbury <sam.spilsbury@canonical.com>
3014+ */
3015 #ifndef _COMPIZCONFIG_CCS_BACKEND_CONCEPT_TEST
3016 #define _COMPIZCONFIG_CCS_BACKEND_CONCEPT_TEST
3017
3018@@ -24,6 +46,10 @@
3019
3020 #include "gtest_shared_characterwrapper.h"
3021 #include "compizconfig_test_value_combiners.h"
3022+#include "compizconfig_ccs_setting_value_operators.h"
3023+#include "compizconfig_ccs_item_in_list_matcher.h"
3024+#include "compizconfig_ccs_list_equality.h"
3025+#include "compizconfig_ccs_list_wrapper.h"
3026
3027 using ::testing::Eq;
3028 using ::testing::IsNull;
3029@@ -41,221 +67,6 @@
3030 MATCHER(IsTrue, "Is True") { if (arg) return true; else return false; }
3031 MATCHER(IsFalse, "Is False") { if (!arg) return true; else return false; }
3032
3033-class ListEqualityMatcher :
3034- public MatcherInterface <CCSSettingValueList>
3035-{
3036- public:
3037-
3038- ListEqualityMatcher (CCSSettingListInfo info,
3039- CCSSettingValueList cmp) :
3040- mInfo (info),
3041- mCmp (cmp)
3042- {
3043- }
3044-
3045- virtual bool MatchAndExplain (CCSSettingValueList x, MatchResultListener *listener) const
3046- {
3047- return ccsCompareLists (x, mCmp, mInfo);
3048- }
3049-
3050- virtual void DescribeTo (std::ostream *os) const
3051- {
3052- *os << "lists are equal";
3053- }
3054-
3055- virtual void DescribeNegationTo (std::ostream *os) const
3056- {
3057- *os << "lists are not equal";
3058- }
3059-
3060- private:
3061-
3062- CCSSettingListInfo mInfo;
3063- CCSSettingValueList mCmp;
3064-};
3065-
3066-Matcher<CCSSettingValueList> ListEqual (CCSSettingListInfo info,
3067- CCSSettingValueList cmp)
3068-{
3069- return MakeMatcher (new ListEqualityMatcher (info, cmp));
3070-}
3071-
3072-bool
3073-operator== (const CCSSettingColorValue &lhs,
3074- const CCSSettingColorValue &rhs)
3075-{
3076- if (ccsIsEqualColor (lhs, rhs))
3077- return true;
3078- return false;
3079-}
3080-
3081-::std::ostream &
3082-operator<< (::std::ostream &os, const CCSSettingColorValue &v)
3083-{
3084- return os << "Red: " << std::hex << v.color.red << "Blue: " << std::hex << v.color.blue << "Green: " << v.color.green << "Alpha: " << v.color.alpha
3085- << std::dec << std::endl;
3086-}
3087-
3088-bool
3089-operator== (const CCSSettingKeyValue &lhs,
3090- const CCSSettingKeyValue &rhs)
3091-{
3092- if (ccsIsEqualKey (lhs, rhs))
3093- return true;
3094- return false;
3095-}
3096-
3097-::std::ostream &
3098-operator<< (::std::ostream &os, const CCSSettingKeyValue &v)
3099-{
3100- return os << "Keysym: " << v.keysym << " KeyModMask " << std::hex << v.keyModMask << std::dec << std::endl;
3101-}
3102-
3103-bool
3104-operator== (const CCSSettingButtonValue &lhs,
3105- const CCSSettingButtonValue &rhs)
3106-{
3107- if (ccsIsEqualButton (lhs, rhs))
3108- return true;
3109- return false;
3110-}
3111-
3112-::std::ostream &
3113-operator<< (::std::ostream &os, const CCSSettingButtonValue &v)
3114-{
3115- return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl;
3116-}
3117-
3118-bool
3119-operator== (const CCSString &lhs,
3120- const std::string &rhs)
3121-{
3122- if (rhs == lhs.value)
3123- return true;
3124-
3125- return false;
3126-}
3127-
3128-bool
3129-operator== (const std::string &lhs,
3130- const CCSString &rhs)
3131-{
3132- if (lhs == rhs.value)
3133- return true;
3134-
3135- return false;
3136-}
3137-
3138-::std::ostream &
3139-operator<< (::std::ostream &os, CCSString &string)
3140-{
3141- os << string.value << std::endl;
3142- return os;
3143-}
3144-
3145-class CCSListWrapper :
3146- boost::noncopyable
3147-{
3148- public:
3149-
3150- typedef boost::shared_ptr <CCSListWrapper> Ptr;
3151-
3152- CCSListWrapper (CCSSettingValueList list,
3153- bool freeItems,
3154- CCSSettingType type,
3155- const boost::shared_ptr <CCSSettingInfo> &listInfo,
3156- const boost::shared_ptr <CCSSetting> &settingReference) :
3157- mList (list),
3158- mFreeItems (freeItems),
3159- mType (type),
3160- mListInfo (listInfo),
3161- mSettingReference (settingReference)
3162- {
3163- }
3164-
3165- CCSSettingType type () { return mType; }
3166-
3167- operator CCSSettingValueList ()
3168- {
3169- return mList;
3170- }
3171-
3172- operator CCSSettingValueList () const
3173- {
3174- return mList;
3175- }
3176-
3177- ~CCSListWrapper ()
3178- {
3179- ccsSettingValueListFree (mList, mFreeItems ? TRUE : FALSE);
3180- }
3181-
3182- const boost::shared_ptr <CCSSetting> &
3183- setting ()
3184- {
3185- return mSettingReference;
3186- }
3187-
3188- private:
3189-
3190- CCSSettingValueList mList;
3191- bool mFreeItems;
3192- CCSSettingType mType;
3193- boost::shared_ptr <CCSSettingInfo> mListInfo;
3194- boost::shared_ptr <CCSSetting> mSettingReference;
3195-};
3196-
3197-template <typename I, typename L>
3198-class ItemInCCSListMatcher :
3199- public ::testing::MatcherInterface <L>
3200-{
3201- public:
3202-
3203- ItemInCCSListMatcher (const Matcher<I> &matcher) :
3204- mMatcher (matcher)
3205- {
3206- }
3207-
3208- virtual bool MatchAndExplain (L list, MatchResultListener *listener) const
3209- {
3210- L iter = list;
3211-
3212- while (iter)
3213- {
3214- if (mMatcher.MatchAndExplain ((*(reinterpret_cast <I *> (iter->data))), listener))
3215- return true;
3216-
3217- iter = iter->next;
3218- }
3219-
3220- return false;
3221- }
3222-
3223- virtual void DescribeTo (std::ostream *os) const
3224- {
3225- *os << "found in list (";
3226- mMatcher.DescribeTo (os);
3227- *os << ")";
3228- }
3229-
3230- virtual void DescribeNegationTo (std::ostream *os) const
3231- {
3232- *os << "not found in list (";
3233- mMatcher.DescribeNegationTo (os);
3234- *os << ")";
3235- }
3236-
3237- private:
3238-
3239- const Matcher<I> & mMatcher;
3240-};
3241-
3242-template <typename I, typename L>
3243-Matcher<L> IsItemInCCSList (const Matcher<I> &matcher)
3244-{
3245- return MakeMatcher (new ItemInCCSListMatcher <I, L> (matcher));
3246-}
3247-
3248 namespace
3249 {
3250 bool ccsStringCmp (const CCSString &a, const CCSString &b)
3251@@ -264,6 +75,9 @@
3252 }
3253 }
3254
3255+namespace cci = compiz::config::impl;
3256+namespace cc = compiz::config;
3257+
3258 typedef boost::variant <bool,
3259 int,
3260 float,
3261@@ -272,7 +86,7 @@
3262 CCSSettingKeyValue,
3263 CCSSettingButtonValue,
3264 unsigned int,
3265- CCSListWrapper::Ptr> VariantTypes;
3266+ cci::SettingValueListWrapper::Ptr> VariantTypes;
3267
3268 class CCSSettingsConceptTestEnvironmentInterface
3269 {
3270@@ -617,13 +431,13 @@
3271 const CCSBackendConceptTestEnvironmentInterface::Ptr &env)
3272 {
3273 CCSSettingGMock *gmock (getSettingGMockFromSetting (setting));
3274- CCSSettingValueList list = *(boost::get <boost::shared_ptr <CCSListWrapper> > (value));
3275+ CCSSettingValueList list = *(boost::get <boost::shared_ptr <cci::SettingValueListWrapper> > (value));
3276
3277 EXPECT_CALL (*gmock, getInfo ());
3278
3279 CCSSettingInfo *info = ccsSettingGetInfo (setting.get ());
3280
3281- info->forList.listType = (boost::get <boost::shared_ptr <CCSListWrapper> > (value))->type ();
3282+ info->forList.listType = (boost::get <boost::shared_ptr <cci::SettingValueListWrapper> > (value))->type ();
3283
3284 EXPECT_CALL (*gmock, getInfo ()).Times (AtLeast (1));
3285 EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll (
3286@@ -632,11 +446,11 @@
3287 Return (TRUE)));
3288 write ();
3289
3290- EXPECT_THAT (CCSListWrapper (env->ReadListAtKey (plugin, key, setting.get ()),
3291- true,
3292- info->forList.listType,
3293- boost::shared_ptr <CCSSettingInfo> (),
3294- setting),
3295+ EXPECT_THAT (cci::SettingValueListWrapper (env->ReadListAtKey (plugin, key, setting.get ()),
3296+ cci::Deep,
3297+ info->forList.listType,
3298+ boost::shared_ptr <CCSSettingInfo> (),
3299+ setting),
3300 ListEqual (info->forList, list));
3301 }
3302
3303@@ -704,11 +518,11 @@
3304
3305 void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value)
3306 {
3307- globalListInfo.forList.listType = (boost::get <boost::shared_ptr <CCSListWrapper> > (value))->type ();
3308+ globalListInfo.forList.listType = (boost::get <boost::shared_ptr <cci::SettingValueListWrapper> > (value))->type ();
3309 globalListInfo.forList.listInfo = NULL;
3310
3311 ON_CALL (*gmock, getInfo ()).WillByDefault (Return (&globalListInfo));
3312- EXPECT_CALL (*gmock, setList (ListEqual (globalListInfo.forList, *(boost::get <boost::shared_ptr <CCSListWrapper> > (value))), _));
3313+ EXPECT_CALL (*gmock, setList (ListEqual (globalListInfo.forList, *(boost::get <boost::shared_ptr <cci::SettingValueListWrapper> > (value))), _));
3314 }
3315
3316 }
3317@@ -960,12 +774,12 @@
3318
3319 typedef boost::function <CCSSettingValueList (CCSSetting *)> ConstructorFunc;
3320
3321-CCSListWrapper::Ptr
3322+cci::SettingValueListWrapper::Ptr
3323 CCSListConstructionExpectationsSetter (const ConstructorFunc &c,
3324 CCSSettingType type,
3325- bool freeItems)
3326+ cci::ListStorageType storageType)
3327 {
3328- boost::function <void (CCSSetting *)> f (boost::bind (ccsFreeMockSetting, _1));
3329+ boost::function <void (CCSSetting *)> f (boost::bind (ccsSettingUnref, _1));
3330 boost::shared_ptr <CCSSetting> mockSetting (ccsNiceMockSettingNew (), f);
3331 NiceMock <CCSSettingGMock> *gmockSetting = reinterpret_cast <NiceMock <CCSSettingGMock> *> (ccsObjectGetPrivate (mockSetting.get ()));
3332
3333@@ -977,7 +791,7 @@
3334
3335 ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (listInfo.get ()));
3336 ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ());
3337- return boost::make_shared <CCSListWrapper> (c (mockSetting.get ()), freeItems, type, listInfo, mockSetting);
3338+ return boost::make_shared <cci::SettingValueListWrapper> (c (mockSetting.get ()), storageType, type, listInfo, mockSetting);
3339 }
3340
3341 template <typename I>
3342@@ -1073,7 +887,7 @@
3343 "TestEdge"),
3344 boost::make_shared <ConceptParam> (backendEnvFactory,
3345 VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::integer, _1),
3346- TypeInt, true)),
3347+ TypeInt, cci::Deep)),
3348 &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey,
3349 TypeList,
3350 "int_list_setting",
3351@@ -1082,7 +896,7 @@
3352 "TestListInt"),
3353 boost::make_shared <ConceptParam> (backendEnvFactory,
3354 VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::doubleprecision, _1),
3355- TypeFloat, true)),
3356+ TypeFloat, cci::Deep)),
3357 &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey,
3358 TypeList,
3359 "float_list_setting",
3360@@ -1091,7 +905,7 @@
3361 "TestListFloat"),
3362 boost::make_shared <ConceptParam> (backendEnvFactory,
3363 VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::boolean, _1),
3364- TypeBool, true)),
3365+ TypeBool, cci::Deep)),
3366 &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey,
3367 TypeList,
3368 "bool_list_setting",
3369@@ -1100,7 +914,7 @@
3370 "TestListBool"),
3371 boost::make_shared <ConceptParam> (backendEnvFactory,
3372 VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::string, _1),
3373- TypeString, true)),
3374+ TypeString, cci::Deep)),
3375 &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey,
3376 TypeList,
3377 "string_list_setting",
3378@@ -1109,7 +923,7 @@
3379 "TestListString"),
3380 boost::make_shared <ConceptParam> (backendEnvFactory,
3381 VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::match, _1),
3382- TypeMatch, true)),
3383+ TypeMatch, cci::Deep)),
3384 &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey,
3385 TypeList,
3386 "match_list_setting",
3387@@ -1118,7 +932,7 @@
3388 "TestListMatch"),
3389 boost::make_shared <ConceptParam> (backendEnvFactory,
3390 VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::color, _1),
3391- TypeColor, true)),
3392+ TypeColor, cci::Deep)),
3393 &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey,
3394 TypeList,
3395 "color_list_setting",
3396@@ -1336,17 +1150,6 @@
3397 const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar");
3398 const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAZ ("baz");
3399
3400-/* A workaround for templates inside of macros not
3401- * expanding correctly */
3402-namespace
3403-{
3404- Matcher <CCSStringList>
3405- IsStringItemInStringCCSList (const Matcher <CCSString> &matcher)
3406- {
3407- return IsItemInCCSList <CCSString, CCSStringList> (matcher);
3408- }
3409-}
3410-
3411 TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles)
3412 {
3413 CCSBackend *backend = GetBackend ();
3414
3415=== added file 'compizconfig/tests/compizconfig_ccs_item_in_list_matcher.h'
3416--- compizconfig/tests/compizconfig_ccs_item_in_list_matcher.h 1970-01-01 00:00:00 +0000
3417+++ compizconfig/tests/compizconfig_ccs_item_in_list_matcher.h 2012-09-24 12:00:13 +0000
3418@@ -0,0 +1,106 @@
3419+/*
3420+ * Compiz configuration system library
3421+ *
3422+ * Copyright (C) 2012 Canonical Ltd.
3423+ *
3424+ * This library is free software; you can redistribute it and/or
3425+ * modify it under the terms of the GNU Lesser General Public
3426+ * License as published by the Free Software Foundation; either
3427+ * version 2.1 of the License, or (at your option) any later version.
3428+
3429+ * This library is distributed in the hope that it will be useful,
3430+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3431+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3432+ * Lesser General Public License for more details.
3433+
3434+ * You should have received a copy of the GNU Lesser General Public
3435+ * License along with this library; if not, write to the Free Software
3436+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3437+ *
3438+ * Authored By:
3439+ * Sam Spilsbury <sam.spilsbury@canonical.com>
3440+ */
3441+#ifndef _COMPIZCONFIG_CCS_ITEM_IN_LIST_MATCHER_H
3442+#define _COMPIZCONFIG_CCS_ITEM_IN_LIST_MATCHER_H
3443+
3444+using ::testing::Matcher;
3445+using ::testing::MatcherInterface;
3446+using ::testing::MatchResultListener;
3447+using ::testing::MakeMatcher;
3448+
3449+template <typename I, typename L>
3450+class ItemInCCSListMatcher :
3451+ public ::testing::MatcherInterface <L>
3452+{
3453+ public:
3454+
3455+ ItemInCCSListMatcher (const Matcher<I> &matcher) :
3456+ mMatcher (matcher)
3457+ {
3458+ }
3459+
3460+ virtual bool MatchAndExplain (L list, MatchResultListener *listener) const
3461+ {
3462+ L iter = list;
3463+
3464+ while (iter)
3465+ {
3466+ const I &i = *(reinterpret_cast <I *> (iter->data));
3467+
3468+ if (mMatcher.MatchAndExplain (i, listener))
3469+ return true;
3470+
3471+ iter = iter->next;
3472+ }
3473+
3474+ return false;
3475+ }
3476+
3477+ virtual void DescribeTo (std::ostream *os) const
3478+ {
3479+ *os << "found in list (";
3480+ mMatcher.DescribeTo (os);
3481+ *os << ")";
3482+ }
3483+
3484+ virtual void DescribeNegationTo (std::ostream *os) const
3485+ {
3486+ *os << "not found in list (";
3487+ mMatcher.DescribeNegationTo (os);
3488+ *os << ")";
3489+ }
3490+
3491+ private:
3492+
3493+ Matcher<I> mMatcher;
3494+};
3495+
3496+template <typename I, typename L>
3497+Matcher<L> IsItemInCCSList (const Matcher<I> &matcher)
3498+{
3499+ return MakeMatcher (new ItemInCCSListMatcher <I, L> (matcher));
3500+}
3501+
3502+typedef struct _CCSString CCSString;
3503+typedef struct _CCSStringList * CCSStringList;
3504+typedef struct _CCSSettingValue CCSSettingValue;
3505+typedef struct _CCSSettingValueList * CCSSettingValueList;
3506+
3507+/* A workaround for templates inside of macros not
3508+ * expanding correctly */
3509+namespace
3510+{
3511+ Matcher <CCSStringList>
3512+ IsStringItemInStringCCSList (const Matcher <CCSString> &matcher)
3513+ {
3514+ return IsItemInCCSList <CCSString, CCSStringList> (matcher);
3515+ }
3516+
3517+ Matcher <CCSSettingValueList>
3518+ IsSettingValueInSettingValueCCSList (const Matcher <CCSSettingValue> &matcher)
3519+ {
3520+ return IsItemInCCSList <CCSSettingValue, CCSSettingValueList> (matcher);
3521+ }
3522+}
3523+
3524+#endif
3525
3526=== added file 'compizconfig/tests/compizconfig_ccs_list_equality.h'
3527--- compizconfig/tests/compizconfig_ccs_list_equality.h 1970-01-01 00:00:00 +0000
3528+++ compizconfig/tests/compizconfig_ccs_list_equality.h 2012-09-24 12:00:13 +0000
3529@@ -0,0 +1,74 @@
3530+/*
3531+ * Compiz configuration system library
3532+ *
3533+ * Copyright (C) 2012 Canonical Ltd.
3534+ *
3535+ * This library is free software; you can redistribute it and/or
3536+ * modify it under the terms of the GNU Lesser General Public
3537+ * License as published by the Free Software Foundation; either
3538+ * version 2.1 of the License, or (at your option) any later version.
3539+
3540+ * This library is distributed in the hope that it will be useful,
3541+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3542+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3543+ * Lesser General Public License for more details.
3544+
3545+ * You should have received a copy of the GNU Lesser General Public
3546+ * License along with this library; if not, write to the Free Software
3547+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3548+ *
3549+ * Authored By:
3550+ * Sam Spilsbury <sam.spilsbury@canonical.com>
3551+ */
3552+#ifndef _COMPIZCONFIG_CCS_LIST_EQUALITY_H
3553+#define _COMPIZCONFIG_CCS_LIST_EQUALITY_H
3554+
3555+#include <iosfwd>
3556+#include <gtest/gtest.h>
3557+#include <gmock/gmock.h>
3558+
3559+using ::testing::MatcherInterface;
3560+using ::testing::MatchResultListener;
3561+using ::testing::MakeMatcher;
3562+using ::testing::Matcher;
3563+
3564+class ListEqualityMatcher :
3565+ public MatcherInterface <CCSSettingValueList>
3566+{
3567+ public:
3568+
3569+ ListEqualityMatcher (CCSSettingListInfo info,
3570+ CCSSettingValueList cmp) :
3571+ mInfo (info),
3572+ mCmp (cmp)
3573+ {
3574+ }
3575+
3576+ virtual bool MatchAndExplain (CCSSettingValueList x, MatchResultListener *listener) const
3577+ {
3578+ return ccsCompareLists (x, mCmp, mInfo);
3579+ }
3580+
3581+ virtual void DescribeTo (std::ostream *os) const
3582+ {
3583+ *os << "lists are equal";
3584+ }
3585+
3586+ virtual void DescribeNegationTo (std::ostream *os) const
3587+ {
3588+ *os << "lists are not equal";
3589+ }
3590+
3591+ private:
3592+
3593+ CCSSettingListInfo mInfo;
3594+ CCSSettingValueList mCmp;
3595+};
3596+
3597+Matcher<CCSSettingValueList> ListEqual (CCSSettingListInfo info,
3598+ CCSSettingValueList cmp)
3599+{
3600+ return MakeMatcher (new ListEqualityMatcher (info, cmp));
3601+}
3602+
3603+#endif
3604
3605=== added file 'compizconfig/tests/compizconfig_ccs_list_wrapper.h'
3606--- compizconfig/tests/compizconfig_ccs_list_wrapper.h 1970-01-01 00:00:00 +0000
3607+++ compizconfig/tests/compizconfig_ccs_list_wrapper.h 2012-09-24 12:00:13 +0000
3608@@ -0,0 +1,199 @@
3609+/*
3610+ * Compiz configuration system library
3611+ *
3612+ * Copyright (C) 2012 Canonical Ltd.
3613+ *
3614+ * This library is free software; you can redistribute it and/or
3615+ * modify it under the terms of the GNU Lesser General Public
3616+ * License as published by the Free Software Foundation; either
3617+ * version 2.1 of the License, or (at your option) any later version.
3618+
3619+ * This library is distributed in the hope that it will be useful,
3620+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3621+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3622+ * Lesser General Public License for more details.
3623+
3624+ * You should have received a copy of the GNU Lesser General Public
3625+ * License along with this library; if not, write to the Free Software
3626+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3627+ *
3628+ * Authored By:
3629+ * Sam Spilsbury <sam.spilsbury@canonical.com>
3630+ */
3631+#ifndef _COMPIZCONFIG_CCS_LIST_WRAPPER_H
3632+#define _COMPIZCONFIG_CCS_LIST_WRAPPER_H
3633+
3634+#include <ccs-defs.h>
3635+#include <ccs-setting-types.h>
3636+
3637+#include <boost/shared_ptr.hpp>
3638+#include <boost/noncopyable.hpp>
3639+
3640+typedef struct _CCSSettingValueList * CCSSettingValueList;
3641+typedef struct _CCSSetting CCSSetting;
3642+typedef union _CCSSettingInfo CCSSettingInfo;
3643+typedef struct _CCSSettingValue CCSSettingValue;
3644+
3645+CCSSettingValueList ccsSettingValueListFree (CCSSettingValueList, Bool);
3646+CCSSettingValueList ccsSettingValueListAppend (CCSSettingValueList, CCSSettingValue *);
3647+CCSSettingValueList ccsSettingValueListRemove (CCSSettingValueList, CCSSettingValue *);
3648+
3649+namespace compiz
3650+{
3651+ namespace config
3652+ {
3653+ template <typename ListType, typename DataType>
3654+ class ListWrapper :
3655+ boost::noncopyable
3656+ {
3657+ public:
3658+
3659+ virtual ~ListWrapper () {}
3660+
3661+ virtual ListWrapper<ListType, DataType> & append (const DataType &) = 0;
3662+ virtual ListWrapper<ListType, DataType> & remove (const DataType &) = 0;
3663+
3664+ virtual operator const ListType & () const = 0;
3665+ virtual operator ListType & () = 0;
3666+ };
3667+
3668+ namespace impl
3669+ {
3670+ namespace cc = compiz::config;
3671+ namespace cci = compiz::config::impl;
3672+
3673+ typedef enum _ListStorageType
3674+ {
3675+ Shallow = 0,
3676+ Deep = 1
3677+ } ListStorageType;
3678+
3679+ template <typename ListType, typename DataType>
3680+ class ListWrapper :
3681+ public cc::ListWrapper <ListType, DataType>
3682+ {
3683+ public:
3684+
3685+ typedef ListType (*ListTypeFreeFunc) (ListType, Bool);
3686+ typedef ListType (*ListTypeAppendFunc) (ListType, DataType);
3687+ typedef ListType (*ListTypeRemoveFunc) (ListType, DataType, Bool);
3688+
3689+ ListWrapper (const ListType &list,
3690+ ListTypeFreeFunc freeFunc,
3691+ ListTypeAppendFunc appendFunc,
3692+ ListTypeRemoveFunc removeFunc,
3693+ ListStorageType storageType) :
3694+ mList (list),
3695+ mFree (freeFunc),
3696+ mAppend (appendFunc),
3697+ mRemove (removeFunc),
3698+ mStorageType (storageType)
3699+ {
3700+ };
3701+
3702+ cc::ListWrapper<ListType, DataType> & append (DataType const &data)
3703+ {
3704+ mList = (*mAppend) (mList, data);
3705+ return *this;
3706+ }
3707+
3708+ cc::ListWrapper<ListType, DataType> & remove (DataType const &data)
3709+ {
3710+ Bool freeObj = (mStorageType == Deep);
3711+ mList = (*mRemove) (mList, data, freeObj);
3712+ return *this;
3713+ }
3714+
3715+ operator const ListType & () const
3716+ {
3717+ return mList;
3718+ }
3719+
3720+ operator ListType & ()
3721+ {
3722+ return mList;
3723+ }
3724+
3725+ ~ListWrapper ()
3726+ {
3727+ Bool freeObj = (mStorageType == Deep);
3728+
3729+ (*mFree) (mList, freeObj);
3730+ }
3731+
3732+ private:
3733+
3734+ ListType mList;
3735+ ListTypeFreeFunc mFree;
3736+ ListTypeAppendFunc mAppend;
3737+ ListTypeRemoveFunc mRemove;
3738+ ListStorageType mStorageType;
3739+ };
3740+
3741+ class SettingValueListWrapper :
3742+ public compiz::config::ListWrapper <CCSSettingValueList, CCSSettingValue *>
3743+ {
3744+ public:
3745+
3746+ typedef boost::shared_ptr <SettingValueListWrapper> Ptr;
3747+
3748+ SettingValueListWrapper (CCSSettingValueList list,
3749+ ListStorageType storageType,
3750+ CCSSettingType type,
3751+ const boost::shared_ptr <CCSSettingInfo> &listInfo,
3752+ const boost::shared_ptr <CCSSetting> &settingReference) :
3753+ mType (type),
3754+ mListInfo (listInfo),
3755+ mSettingReference (settingReference),
3756+ mListWrapper (list,
3757+ ccsSettingValueListFree,
3758+ ccsSettingValueListAppend,
3759+ ccsSettingValueListRemove,
3760+ storageType)
3761+ {
3762+ }
3763+
3764+ CCSSettingType type ()
3765+ {
3766+ return mType;
3767+ }
3768+
3769+ cc::ListWrapper <CCSSettingValueList, CCSSettingValue *> & append (CCSSettingValue * const &value)
3770+ {
3771+ return mListWrapper.append (value);
3772+ }
3773+
3774+ cc::ListWrapper <CCSSettingValueList, CCSSettingValue *> & remove (CCSSettingValue * const &value)
3775+ {
3776+ return mListWrapper.remove (value);
3777+ }
3778+
3779+ operator const CCSSettingValueList & () const
3780+ {
3781+ return mListWrapper;
3782+ }
3783+
3784+ operator CCSSettingValueList & ()
3785+ {
3786+ return mListWrapper;
3787+ }
3788+
3789+ const boost::shared_ptr <CCSSetting> & setting ()
3790+ {
3791+ return mSettingReference;
3792+ }
3793+
3794+ private:
3795+
3796+ CCSSettingType mType;
3797+ boost::shared_ptr <CCSSettingInfo> mListInfo;
3798+ boost::shared_ptr <CCSSetting> mSettingReference;
3799+ cci::ListWrapper <CCSSettingValueList, CCSSettingValue *> mListWrapper;
3800+ };
3801+ }
3802+ }
3803+}
3804+
3805+
3806+
3807+#endif
3808
3809=== added file 'compizconfig/tests/compizconfig_ccs_list_wrapper.h.moved'
3810--- compizconfig/tests/compizconfig_ccs_list_wrapper.h.moved 1970-01-01 00:00:00 +0000
3811+++ compizconfig/tests/compizconfig_ccs_list_wrapper.h.moved 2012-09-24 12:00:13 +0000
3812@@ -0,0 +1,199 @@
3813+/*
3814+ * Compiz configuration system library
3815+ *
3816+ * Copyright (C) 2012 Canonical Ltd.
3817+ *
3818+ * This library is free software; you can redistribute it and/or
3819+ * modify it under the terms of the GNU Lesser General Public
3820+ * License as published by the Free Software Foundation; either
3821+ * version 2.1 of the License, or (at your option) any later version.
3822+
3823+ * This library is distributed in the hope that it will be useful,
3824+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3825+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3826+ * Lesser General Public License for more details.
3827+
3828+ * You should have received a copy of the GNU Lesser General Public
3829+ * License along with this library; if not, write to the Free Software
3830+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3831+ *
3832+ * Authored By:
3833+ * Sam Spilsbury <sam.spilsbury@canonical.com>
3834+ */
3835+#ifndef _COMPIZCONFIG_CCS_LIST_WRAPPER_H
3836+#define _COMPIZCONFIG_CCS_LIST_WRAPPER_H
3837+
3838+#include <ccs-defs.h>
3839+#include <ccs-setting-types.h>
3840+
3841+#include <boost/shared_ptr.hpp>
3842+#include <boost/noncopyable.hpp>
3843+
3844+typedef struct _CCSSettingValueList * CCSSettingValueList;
3845+typedef struct _CCSSetting CCSSetting;
3846+typedef union _CCSSettingInfo CCSSettingInfo;
3847+typedef struct _CCSSettingValue CCSSettingValue;
3848+
3849+CCSSettingValueList ccsSettingValueListFree (CCSSettingValueList, Bool);
3850+CCSSettingValueList ccsSettingValueListAppend (CCSSettingValueList, CCSSettingValue *);
3851+CCSSettingValueList ccsSettingValueListRemove (CCSSettingValueList, CCSSettingValue *);
3852+
3853+namespace compiz
3854+{
3855+ namespace config
3856+ {
3857+ template <typename ListType, typename DataType>
3858+ class ListWrapper :
3859+ boost::noncopyable
3860+ {
3861+ public:
3862+
3863+ virtual ~ListWrapper () {}
3864+
3865+ virtual ListWrapper<ListType, DataType> & append (const DataType &) = 0;
3866+ virtual ListWrapper<ListType, DataType> & remove (const DataType &) = 0;
3867+
3868+ virtual operator const ListType & () const = 0;
3869+ virtual operator ListType & () = 0;
3870+ };
3871+
3872+ namespace impl
3873+ {
3874+ namespace cc = compiz::config;
3875+ namespace cci = compiz::config::impl;
3876+
3877+ typedef enum _ListStorageType
3878+ {
3879+ Shallow = 0,
3880+ Deep = 1
3881+ } ListStorageType;
3882+
3883+ template <typename ListType, typename DataType>
3884+ class ListWrapper :
3885+ public cc::ListWrapper <ListType, DataType>
3886+ {
3887+ public:
3888+
3889+ typedef ListType (*ListTypeFreeFunc) (ListType, Bool);
3890+ typedef ListType (*ListTypeAppendFunc) (ListType, DataType);
3891+ typedef ListType (*ListTypeRemoveFunc) (ListType, DataType, Bool);
3892+
3893+ ListWrapper (const ListType &list,
3894+ ListTypeFreeFunc freeFunc,
3895+ ListTypeAppendFunc appendFunc,
3896+ ListTypeRemoveFunc removeFunc,
3897+ ListStorageType storageType) :
3898+ mList (list),
3899+ mFree (freeFunc),
3900+ mAppend (appendFunc),
3901+ mRemove (removeFunc),
3902+ mStorageType (storageType)
3903+ {
3904+ };
3905+
3906+ cc::ListWrapper<ListType, DataType> & append (DataType const &data)
3907+ {
3908+ mList = (*mAppend) (mList, data);
3909+ return *this;
3910+ }
3911+
3912+ cc::ListWrapper<ListType, DataType> & remove (DataType const &data)
3913+ {
3914+ Bool freeObj = (mStorageType == Deep);
3915+ mList = (*mRemove) (mList, data, freeObj);
3916+ return *this;
3917+ }
3918+
3919+ operator const ListType & () const
3920+ {
3921+ return mList;
3922+ }
3923+
3924+ operator ListType & ()
3925+ {
3926+ return mList;
3927+ }
3928+
3929+ ~ListWrapper ()
3930+ {
3931+ Bool freeObj = (mStorageType == Deep);
3932+
3933+ (*mFree) (mList, freeObj);
3934+ }
3935+
3936+ private:
3937+
3938+ ListType mList;
3939+ ListTypeFreeFunc mFree;
3940+ ListTypeAppendFunc mAppend;
3941+ ListTypeRemoveFunc mRemove;
3942+ ListStorageType mStorageType;
3943+ };
3944+
3945+ class SettingValueListWrapper :
3946+ public compiz::config::ListWrapper <CCSSettingValueList, CCSSettingValue *>
3947+ {
3948+ public:
3949+
3950+ typedef boost::shared_ptr <SettingValueListWrapper> Ptr;
3951+
3952+ SettingValueListWrapper (CCSSettingValueList list,
3953+ ListStorageType storageType,
3954+ CCSSettingType type,
3955+ const boost::shared_ptr <CCSSettingInfo> &listInfo,
3956+ const boost::shared_ptr <CCSSetting> &settingReference) :
3957+ mType (type),
3958+ mListInfo (listInfo),
3959+ mSettingReference (settingReference),
3960+ mListWrapper (list,
3961+ ccsSettingValueListFree,
3962+ ccsSettingValueListAppend,
3963+ ccsSettingValueListRemove,
3964+ storageType)
3965+ {
3966+ }
3967+
3968+ CCSSettingType type ()
3969+ {
3970+ return mType;
3971+ }
3972+
3973+ cc::ListWrapper <CCSSettingValueList, CCSSettingValue *> & append (CCSSettingValue * const &value)
3974+ {
3975+ return mListWrapper.append (value);
3976+ }
3977+
3978+ cc::ListWrapper <CCSSettingValueList, CCSSettingValue *> & remove (CCSSettingValue * const &value)
3979+ {
3980+ return mListWrapper.remove (value);
3981+ }
3982+
3983+ operator const CCSSettingValueList & () const
3984+ {
3985+ return mListWrapper;
3986+ }
3987+
3988+ operator CCSSettingValueList & ()
3989+ {
3990+ return mListWrapper;
3991+ }
3992+
3993+ const boost::shared_ptr <CCSSetting> & setting ()
3994+ {
3995+ return mSettingReference;
3996+ }
3997+
3998+ private:
3999+
4000+ CCSSettingType mType;
4001+ boost::shared_ptr <CCSSettingInfo> mListInfo;
4002+ boost::shared_ptr <CCSSetting> mSettingReference;
4003+ cci::ListWrapper <CCSSettingValueList, CCSSettingValue *> mListWrapper;
4004+ };
4005+ }
4006+ }
4007+}
4008+
4009+
4010+
4011+#endif
4012
4013=== modified file 'compizconfig/tests/compizconfig_ccs_mocked_allocator.h'
4014--- compizconfig/tests/compizconfig_ccs_mocked_allocator.h 2012-09-10 01:05:28 +0000
4015+++ compizconfig/tests/compizconfig_ccs_mocked_allocator.h 2012-09-24 12:00:13 +0000
4016@@ -1,3 +1,25 @@
4017+/*
4018+ * Compiz configuration system library
4019+ *
4020+ * Copyright (C) 2012 Canonical Ltd.
4021+ *
4022+ * This library is free software; you can redistribute it and/or
4023+ * modify it under the terms of the GNU Lesser General Public
4024+ * License as published by the Free Software Foundation; either
4025+ * version 2.1 of the License, or (at your option) any later version.
4026+
4027+ * This library is distributed in the hope that it will be useful,
4028+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4029+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4030+ * Lesser General Public License for more details.
4031+
4032+ * You should have received a copy of the GNU Lesser General Public
4033+ * License along with this library; if not, write to the Free Software
4034+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4035+ *
4036+ * Authored By:
4037+ * Sam Spilsbury <sam.spilsbury@canonical.com>
4038+ */
4039 #ifndef _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H
4040 #define _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H
4041
4042
4043=== added file 'compizconfig/tests/compizconfig_ccs_setting_value_operators.h'
4044--- compizconfig/tests/compizconfig_ccs_setting_value_operators.h 1970-01-01 00:00:00 +0000
4045+++ compizconfig/tests/compizconfig_ccs_setting_value_operators.h 2012-09-24 12:00:13 +0000
4046@@ -0,0 +1,105 @@
4047+/*
4048+ * Compiz configuration system library
4049+ *
4050+ * Copyright (C) 2012 Canonical Ltd.
4051+ *
4052+ * This library is free software; you can redistribute it and/or
4053+ * modify it under the terms of the GNU Lesser General Public
4054+ * License as published by the Free Software Foundation; either
4055+ * version 2.1 of the License, or (at your option) any later version.
4056+
4057+ * This library is distributed in the hope that it will be useful,
4058+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4059+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4060+ * Lesser General Public License for more details.
4061+
4062+ * You should have received a copy of the GNU Lesser General Public
4063+ * License along with this library; if not, write to the Free Software
4064+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4065+ *
4066+ * Authored By:
4067+ * Sam Spilsbury <sam.spilsbury@canonical.com>
4068+ */
4069+#ifndef _COMPIZCONFIG_CCS_SETTING_VALUE_OPERATORS_H
4070+#define _COMPIZCONFIG_CCS_SETTING_VALUE_OPERATORS_H
4071+
4072+#include <ccs.h>
4073+
4074+bool
4075+operator== (const CCSSettingColorValue &lhs,
4076+ const CCSSettingColorValue &rhs)
4077+{
4078+ if (ccsIsEqualColor (lhs, rhs))
4079+ return true;
4080+ return false;
4081+}
4082+
4083+std::ostream &
4084+operator<< (std::ostream &os, const CCSSettingColorValue &v)
4085+{
4086+ return os << "Red: " << std::hex << v.color.red << "Blue: " << std::hex << v.color.blue << "Green: " << v.color.green << "Alpha: " << v.color.alpha
4087+ << std::dec << std::endl;
4088+}
4089+
4090+bool
4091+operator== (const CCSSettingKeyValue &lhs,
4092+ const CCSSettingKeyValue &rhs)
4093+{
4094+ if (ccsIsEqualKey (lhs, rhs))
4095+ return true;
4096+ return false;
4097+}
4098+
4099+std::ostream &
4100+operator<< (std::ostream &os, const CCSSettingKeyValue &v)
4101+{
4102+ return os << "Keysym: " << v.keysym << " KeyModMask " << std::hex << v.keyModMask << std::dec << std::endl;
4103+}
4104+
4105+bool
4106+operator== (const CCSSettingButtonValue &lhs,
4107+ const CCSSettingButtonValue &rhs)
4108+{
4109+ if (ccsIsEqualButton (lhs, rhs))
4110+ return true;
4111+ return false;
4112+}
4113+
4114+std::ostream &
4115+operator<< (std::ostream &os, const CCSSettingButtonValue &v)
4116+{
4117+ return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl;
4118+}
4119+
4120+bool
4121+operator== (const CCSString &lhs,
4122+ const std::string &rhs)
4123+{
4124+ if (rhs == lhs.value)
4125+ return true;
4126+
4127+ return false;
4128+}
4129+
4130+bool
4131+operator== (const std::string &lhs,
4132+ const CCSString &rhs)
4133+{
4134+ return rhs == lhs;
4135+}
4136+
4137+bool
4138+operator== (const std::string &rhs,
4139+ CCSString *lhs)
4140+{
4141+ return *lhs == rhs;
4142+}
4143+
4144+std::ostream &
4145+operator<< (std::ostream &os, CCSString &string)
4146+{
4147+ os << string.value << std::endl;
4148+ return os;
4149+}
4150+
4151+#endif
4152
4153=== modified file 'compizconfig/tests/compizconfig_test_value_combiners.h'
4154--- compizconfig/tests/compizconfig_test_value_combiners.h 2012-09-10 01:05:28 +0000
4155+++ compizconfig/tests/compizconfig_test_value_combiners.h 2012-09-24 12:00:13 +0000
4156@@ -1,3 +1,25 @@
4157+/*
4158+ * Compiz configuration system library
4159+ *
4160+ * Copyright (C) 2012 Canonical Ltd.
4161+ *
4162+ * This library is free software; you can redistribute it and/or
4163+ * modify it under the terms of the GNU Lesser General Public
4164+ * License as published by the Free Software Foundation; either
4165+ * version 2.1 of the License, or (at your option) any later version.
4166+
4167+ * This library is distributed in the hope that it will be useful,
4168+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4169+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4170+ * Lesser General Public License for more details.
4171+
4172+ * You should have received a copy of the GNU Lesser General Public
4173+ * License along with this library; if not, write to the Free Software
4174+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4175+ *
4176+ * Authored By:
4177+ * Sam Spilsbury <sam.spilsbury@canonical.com>
4178+ */
4179 #ifndef _COMPIZCONFIG_TEST_VALUE_COMBINERS_H
4180 #define _COMPIZCONFIG_TEST_VALUE_COMBINERS_H
4181

Subscribers

People subscribed via source and target branches