Merge lp:~compiz-team/compiz/compiz.fix_1063617.7 into lp:compiz/0.9.9

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1063617.7
Merge into: lp:compiz/0.9.9
Diff against target: 1299 lines (+1031/-109)
5 files modified
compizconfig/libcompizconfig/include/ccs.h (+14/-3)
compizconfig/libcompizconfig/src/compiz.cpp (+0/-55)
compizconfig/libcompizconfig/src/main.c (+129/-50)
compizconfig/libcompizconfig/tests/CMakeLists.txt (+2/-1)
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp (+886/-0)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1063617.7
Reviewer Review Type Date Requested Status
Compiz Maintainers Pending
Review via email: mp+136855@code.launchpad.net

This proposal has been superseded by a proposal from 2012-11-29.

Commit message

Provided test fixtures for testing the setting ccsSet* functions

DefaultImplSetParam provides a "parameter" for testing different setting
types exposed through DefaultImplSetParamInterface .
DefaultImplSetFailureParam provides a "parameter" for testing failure
cases.

The test fixtures in this case set up some default values through the
stubInitializeSettingDefaultValue and stubInitializeSettingInfo
functions. This is verified through MockInitializerFuncsWithDelegators

Description of the change

This is about preparing a fix for (LP: #1063617).

(LP: #1063617) is really complicated. The problem is that there is a feedback loop between integrated keys and normal keys which can cause the integrated keys to read from normal keys which will be out of date or incorrect because they were never updated.

A part of that problem is that we need to have more information in the backends as to why setting a key to a particular value failed or succeeded.

Provided test fixtures for testing the setting ccsSet* functions

DefaultImplSetParam provides a "parameter" for testing different setting
types exposed through DefaultImplSetParamInterface .
DefaultImplSetFailureParam provides a "parameter" for testing failure
cases.

The test fixtures in this case set up some default values through the
stubInitializeSettingDefaultValue and stubInitializeSettingInfo
functions. This is verified through MockInitializerFuncsWithDelegators

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

(Its just in the WIP queue until the other changes to compiz go through)

3493. By Sam Spilsbury

Merged compiz.fix_1063617.6 into compiz.fix_1063617.7.

3494. By Sam Spilsbury

Merged compiz.fix_1063617.6 into compiz.fix_1063617.7.

3495. By Sam Spilsbury

Merged compiz.fix_1063617.6 into compiz.fix_1063617.7.

3496. By Sam Spilsbury

Clean up some class names

3497. By Sam Spilsbury

Don't use a namespace, use a better name for SetParam's impl instead

3498. By Sam Spilsbury

Merged compiz.fix_1063617.6 into compiz.fix_1063617.7.

3499. By Sam Spilsbury

Merged compiz.fix_1063617.6 into compiz.fix_1063617.7.

3500. By Sam Spilsbury

Merged compiz.fix_1063617.6 into compiz.fix_1063617.7.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'compizconfig/libcompizconfig/include/ccs.h'
2--- compizconfig/libcompizconfig/include/ccs.h 2012-11-27 03:59:26 +0000
3+++ compizconfig/libcompizconfig/include/ccs.h 2012-11-29 07:58:20 +0000
4@@ -722,6 +722,8 @@
5 void ccsFreeSetting (CCSSetting *setting);
6 void ccsFreeGroup (CCSGroup *group);
7 void ccsFreeSubGroup (CCSSubGroup *subGroup);
8+void ccsCleanupSettingInfo (CCSSettingInfo *info,
9+ CCSSettingType type);
10 void ccsFreeSettingValue (CCSSettingValue *value);
11 void ccsFreeSettingValueWithType (CCSSettingValue *v,
12 CCSSettingType type);
13@@ -792,9 +794,18 @@
14
15 /* Deep copy setting value */
16 CCSSettingValue *
17-ccsCopyValue (CCSSettingValue *orig,
18- CCSSettingType type,
19- CCSSettingInfo *info);
20+ccsCopyValue (const CCSSettingValue *orig,
21+ CCSSettingType type,
22+ CCSSettingInfo *info);
23+Bool
24+ccsCopyValueInto (const CCSSettingValue *from,
25+ CCSSettingValue *to,
26+ CCSSettingType type,
27+ CCSSettingInfo *info);
28+
29+/* Deep copy setting info */
30+void
31+ccsCopyInfo (const CCSSettingInfo *from, CCSSettingInfo *to, CCSSettingType type);
32
33 /* Converts an array of data items to a setting value list. Behaves similar
34 to ccsGetListFromStringArray */
35
36=== modified file 'compizconfig/libcompizconfig/src/compiz.cpp'
37--- compizconfig/libcompizconfig/src/compiz.cpp 2012-11-24 11:18:52 +0000
38+++ compizconfig/libcompizconfig/src/compiz.cpp 2012-11-29 07:58:20 +0000
39@@ -658,61 +658,6 @@
40 }
41 }
42
43-CCSSetting *
44-ccsSettingDefaultImplNew (CCSPlugin *plugin,
45- const char *name,
46- CCSSettingType type,
47- const char *shortDesc,
48- const char *longDesc,
49- const char *hints,
50- const char *group,
51- const char *subGroup,
52- CCSSettingDefaultValueInitializerFunc valueInit,
53- void *valueInitData,
54- CCSSettingInfoInitializerFunc infoInit,
55- void *infoInitData,
56- CCSObjectAllocationInterface *ai,
57- const CCSInterfaceTable *interfaces)
58-{
59- CCSSetting *setting = (CCSSetting *) calloc (1, sizeof (CCSSetting));
60-
61- if (!setting)
62- return NULL;
63-
64- ccsObjectInit (setting, ai);
65-
66- CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) (*ai->calloc_) (ai->allocator, 1, sizeof (CCSSettingPrivate));
67-
68- if (!sPrivate)
69- {
70- free (setting);
71- return NULL;
72- }
73-
74- ccsObjectSetPrivate (setting, (CCSPrivate *) sPrivate);
75- ccsObjectAddInterface (setting, (CCSInterface *) interfaces->settingInterface, GET_INTERFACE_TYPE (CCSSettingInterface));
76- ccsSettingRef (setting);
77-
78- sPrivate->parent = plugin;
79- sPrivate->isDefault = TRUE;
80- sPrivate->name = strdup (name);
81-
82- sPrivate->shortDesc = strdup (shortDesc);
83- sPrivate->longDesc = strdup (longDesc);
84- sPrivate->group = strdup (group);
85- sPrivate->hints = strdup (hints);
86- sPrivate->subGroup = strdup (subGroup);
87-
88- sPrivate->type = type;
89- sPrivate->value = &sPrivate->defaultValue;
90- sPrivate->defaultValue.parent = setting;
91-
92- (*infoInit) (type, &sPrivate->info, infoInitData);
93- (*valueInit) (type, &sPrivate->info, &sPrivate->defaultValue, valueInitData);
94-
95- return setting;
96-}
97-
98 static void
99 addOptionForPluginPB (CCSPlugin * plugin,
100 const char * name,
101
102=== modified file 'compizconfig/libcompizconfig/src/main.c'
103--- compizconfig/libcompizconfig/src/main.c 2012-11-24 10:01:33 +0000
104+++ compizconfig/libcompizconfig/src/main.c 2012-11-29 07:58:20 +0000
105@@ -800,6 +800,29 @@
106 free (p);
107 }
108
109+void
110+ccsCleanupSettingInfo (CCSSettingInfo *info,
111+ CCSSettingType type)
112+{
113+ switch (type)
114+ {
115+ case TypeInt:
116+ ccsIntDescListFree (info->forInt.desc, TRUE);
117+ break;
118+ case TypeString:
119+ ccsStrRestrictionListFree (info->forString.restriction, TRUE);
120+ break;
121+ case TypeList:
122+ if (info->forList.listType == TypeInt)
123+ ccsIntDescListFree (info->forList.listInfo->
124+ forInt.desc, TRUE);
125+ free (info->forList.listInfo);
126+ break;
127+ default:
128+ break;
129+ }
130+}
131+
132 static void
133 ccsFreeSettingDefault (CCSSetting *s)
134 {
135@@ -812,30 +835,13 @@
136 free (sPrivate->subGroup);
137 free (sPrivate->hints);
138
139- switch (sPrivate->type)
140- {
141- case TypeInt:
142- ccsIntDescListFree (sPrivate->info.forInt.desc, TRUE);
143- break;
144- case TypeString:
145- ccsStrRestrictionListFree (sPrivate->info.forString.restriction, TRUE);
146- break;
147- case TypeList:
148- if (sPrivate->info.forList.listType == TypeInt)
149- ccsIntDescListFree (sPrivate->info.forList.listInfo->
150- forInt.desc, TRUE);
151- free (sPrivate->info.forList.listInfo);
152- //ccsSettingValueListFree (sPrivate->value->value.asList, TRUE);
153- break;
154- default:
155- break;
156- }
157-
158 if (&sPrivate->defaultValue != sPrivate->value)
159 {
160 ccsFreeSettingValue (sPrivate->value);
161 }
162
163+ ccsCleanupSettingInfo (&sPrivate->info, sPrivate->type);
164+
165 ccsFreeSettingValue (&sPrivate->defaultValue);
166
167 ccsObjectFinalize (s);
168@@ -1819,10 +1825,10 @@
169 return TRUE;
170 }
171
172-static void
173-copyInfo (CCSSettingInfo *from, CCSSettingInfo *to, CCSSettingType type)
174+void
175+ccsCopyInfo (const CCSSettingInfo *from, CCSSettingInfo *to, CCSSettingType type)
176 {
177- memcpy (from, to, sizeof (CCSSettingInfo));
178+ memcpy (to, from, sizeof (CCSSettingInfo));
179
180 switch (type)
181 {
182@@ -1896,7 +1902,7 @@
183 {
184 to->forList.listInfo = calloc (1, sizeof (CCSSettingInfo));
185
186- copyInfo (from->forList.listInfo, to->forList.listInfo, from->forList.listType);
187+ ccsCopyInfo (from->forList.listInfo, to->forList.listInfo, from->forList.listType);
188 }
189
190 break;
191@@ -1997,7 +2003,7 @@
192 }
193
194 copyValue (&fromPrivate->defaultValue, &toPrivate->defaultValue);
195- copyInfo (&fromPrivate->info, &toPrivate->info, fromPrivate->type);
196+ ccsCopyInfo (&fromPrivate->info, &toPrivate->info, fromPrivate->type);
197
198 toPrivate->defaultValue.parent = to;
199 toPrivate->privatePtr = NULL;
200@@ -2468,63 +2474,81 @@
201 return TRUE;
202 }
203
204-CCSSettingValue *
205-ccsCopyValue (CCSSettingValue *orig,
206- CCSSettingType type,
207- CCSSettingInfo *info)
208+Bool
209+ccsCopyValueInto (const CCSSettingValue *from,
210+ CCSSettingValue *to,
211+ CCSSettingType type,
212+ CCSSettingInfo *info)
213 {
214- CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue));
215-
216- if (!value)
217- return NULL;
218-
219- value->refCount = 1;
220- value->parent = orig->parent;
221- value->isListChild = orig->isListChild;
222-
223- CCSSettingType vType = value->isListChild ? info->forList.listType : type;
224+ to->parent = from->parent;
225+ to->isListChild = from->isListChild;
226+
227+ CCSSettingType vType = to->isListChild ? info->forList.listType : type;
228
229 switch (vType)
230 {
231 case TypeInt:
232- value->value.asInt = orig->value.asInt;
233+ to->value.asInt = from->value.asInt;
234 break;
235 case TypeBool:
236- value->value.asBool = orig->value.asBool;
237+ to->value.asBool = from->value.asBool;
238 break;
239 case TypeFloat:
240- value->value.asFloat = orig->value.asFloat;
241+ to->value.asFloat = from->value.asFloat;
242 break;
243 case TypeString:
244- value->value.asString = strdup (orig->value.asString);
245+ to->value.asString = strdup (from->value.asString);
246 break;
247 case TypeMatch:
248- value->value.asMatch = strdup (orig->value.asMatch);
249+ to->value.asMatch = strdup (from->value.asMatch);
250 break;
251 case TypeKey:
252- memcpy (&value->value.asKey, &orig->value.asKey,
253+ memcpy (&to->value.asKey, &from->value.asKey,
254 sizeof (CCSSettingKeyValue));
255 break;
256 case TypeButton:
257- memcpy (&value->value.asButton, &orig->value.asButton,
258+ memcpy (&to->value.asButton, &from->value.asButton,
259 sizeof (CCSSettingButtonValue));
260 break;
261 case TypeEdge:
262- value->value.asEdge = orig->value.asEdge;
263+ to->value.asEdge = from->value.asEdge;
264 break;
265 case TypeBell:
266- value->value.asBell = orig->value.asBell;
267+ to->value.asBell = from->value.asBell;
268 break;
269 case TypeColor:
270- memcpy (&value->value.asColor, &orig->value.asColor,
271+ memcpy (&to->value.asColor, &from->value.asColor,
272 sizeof (CCSSettingColorValue));
273 break;
274+ case TypeList:
275+ assert (from->parent != NULL);
276+ to->value.asList = ccsCopyList (from->value.asList, from->parent);
277 default:
278- free (value);
279- return NULL;
280+ ccsError ("unexpected setting type in ccsCopyValueInto");
281+ return FALSE;
282 break;
283 }
284
285+ return TRUE;
286+}
287+
288+CCSSettingValue *
289+ccsCopyValue (const CCSSettingValue *orig,
290+ CCSSettingType type,
291+ CCSSettingInfo *info)
292+{
293+ CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue));
294+
295+ if (!value)
296+ return NULL;
297+
298+ value->refCount = 1;
299+ if (!ccsCopyValueInto (orig, value, type, info))
300+ {
301+ free (value);
302+ return NULL;
303+ }
304+
305 return value;
306 }
307
308@@ -5568,6 +5592,61 @@
309 (*(GET_INTERFACE (CCSIntegratedSettingInterface, setting))->free) (setting);
310 }
311
312+CCSSetting *
313+ccsSettingDefaultImplNew (CCSPlugin *plugin,
314+ const char *name,
315+ CCSSettingType type,
316+ const char *shortDesc,
317+ const char *longDesc,
318+ const char *hints,
319+ const char *group,
320+ const char *subGroup,
321+ CCSSettingDefaultValueInitializerFunc valueInit,
322+ void *valueInitData,
323+ CCSSettingInfoInitializerFunc infoInit,
324+ void *infoInitData,
325+ CCSObjectAllocationInterface *ai,
326+ const CCSInterfaceTable *interfaces)
327+{
328+ CCSSetting *setting = (CCSSetting *) calloc (1, sizeof (CCSSetting));
329+
330+ if (!setting)
331+ return NULL;
332+
333+ ccsObjectInit (setting, ai);
334+
335+ CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) (*ai->calloc_) (ai->allocator, 1, sizeof (CCSSettingPrivate));
336+
337+ if (!sPrivate)
338+ {
339+ free (setting);
340+ return NULL;
341+ }
342+
343+ ccsObjectSetPrivate (setting, (CCSPrivate *) sPrivate);
344+ ccsObjectAddInterface (setting, (CCSInterface *) interfaces->settingInterface, GET_INTERFACE_TYPE (CCSSettingInterface));
345+ ccsSettingRef (setting);
346+
347+ sPrivate->parent = plugin;
348+ sPrivate->isDefault = TRUE;
349+ sPrivate->name = strdup (name);
350+
351+ sPrivate->shortDesc = strdup (shortDesc);
352+ sPrivate->longDesc = strdup (longDesc);
353+ sPrivate->group = strdup (group);
354+ sPrivate->hints = strdup (hints);
355+ sPrivate->subGroup = strdup (subGroup);
356+
357+ sPrivate->type = type;
358+ sPrivate->value = &sPrivate->defaultValue;
359+ sPrivate->defaultValue.parent = setting;
360+
361+ (*infoInit) (type, &sPrivate->info, infoInitData);
362+ (*valueInit) (type, &sPrivate->info, &sPrivate->defaultValue, valueInitData);
363+
364+ return setting;
365+}
366+
367 /* CCSSharedIntegratedSettingInfo implementation */
368
369 typedef struct _CCSSharedIntegratedSettingInfoPrivate CCSSharedIntegratedSettingInfoPrivate;
370
371=== modified file 'compizconfig/libcompizconfig/tests/CMakeLists.txt'
372--- compizconfig/libcompizconfig/tests/CMakeLists.txt 2012-09-29 14:33:53 +0000
373+++ compizconfig/libcompizconfig/tests/CMakeLists.txt 2012-11-29 07:58:20 +0000
374@@ -113,7 +113,8 @@
375 compizconfig
376 compizconfig_ccs_context_mock
377 compizconfig_ccs_plugin_mock
378- compizconfig_ccs_setting_mock)
379+ compizconfig_ccs_setting_mock
380+ compizconfig_ccs_list_wrapper)
381
382 target_link_libraries (compizconfig_test_ccs_text_file
383 ${GTEST_BOTH_LIBRARIES}
384
385=== modified file 'compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp'
386--- compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp 2012-11-24 11:18:52 +0000
387+++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp 2012-11-29 07:58:20 +0000
388@@ -26,14 +26,24 @@
389 #include <boost/make_shared.hpp>
390 #include <boost/function.hpp>
391
392+#include <X11/Xlib.h>
393+
394 #include <ccs.h>
395
396 #include "compizconfig_ccs_setting_mock.h"
397 #include "compizconfig_ccs_plugin_mock.h"
398+#include "compizconfig_ccs_list_wrapper.h"
399+
400+namespace cci = compiz::config::impl;
401+namespace cc = compiz::config;
402
403 using ::testing::_;
404 using ::testing::Return;
405 using ::testing::InSequence;
406+using ::testing::WithArgs;
407+using ::testing::WithParamInterface;
408+using ::testing::Invoke;
409+using ::testing::ReturnNull;
410
411 TEST(CCSSettingTest, TestMock)
412 {
413@@ -134,6 +144,11 @@
414
415 namespace
416 {
417+
418+typedef boost::shared_ptr <CCSSettingInfo> CCSSettingInfoPtr;
419+typedef boost::shared_ptr <CCSSettingValue> CCSSettingValuePtr;
420+typedef boost::shared_ptr <CCSSetting> CCSSettingPtr;
421+
422 class MockInitializerFuncs
423 {
424 public:
425@@ -250,3 +265,874 @@
426 EXPECT_EQ (ccsSettingGetParent (setting.get ()),
427 plugin.get ());
428 }
429+
430+namespace
431+{
432+
433+/* Used to copy different raw values */
434+template <typename SettingValueType>
435+class CopyRawValueBase
436+{
437+ public:
438+
439+ CopyRawValueBase (const SettingValueType &value) :
440+ mValue (value)
441+ {
442+ }
443+
444+ protected:
445+
446+ const SettingValueType &mValue;
447+};
448+
449+template <typename SettingValueType>
450+class CopyRawValue :
451+ public CopyRawValueBase <SettingValueType>
452+{
453+ public:
454+
455+ typedef SettingValueType ReturnType;
456+ typedef CopyRawValueBase <SettingValueType> Parent;
457+
458+ CopyRawValue (const SettingValueType &value) :
459+ CopyRawValueBase <SettingValueType> (value)
460+ {
461+ }
462+
463+ SettingValueType operator () ()
464+ {
465+ return Parent::mValue;
466+ }
467+};
468+
469+template <>
470+class CopyRawValue <const char *> :
471+ public CopyRawValueBase <const char *>
472+{
473+ public:
474+
475+ typedef const char * ReturnType;
476+ typedef CopyRawValueBase <const char *> Parent;
477+
478+ CopyRawValue (const char * value) :
479+ CopyRawValueBase <const char *> (value)
480+ {
481+ }
482+
483+ ReturnType operator () ()
484+ {
485+ /* XXX: Valgrind complains here that mValue is uninitialized, but
486+ * verification using gdb confirms that isn't true */
487+ return strdup (Parent::mValue);
488+ }
489+};
490+
491+template <>
492+class CopyRawValue <cci::SettingValueListWrapper::Ptr> :
493+ public CopyRawValueBase <cci::SettingValueListWrapper::Ptr>
494+{
495+ public:
496+
497+ typedef CCSSettingValueList ReturnType;
498+ typedef CopyRawValueBase <cci::SettingValueListWrapper::Ptr> Parent;
499+
500+ CopyRawValue (const cci::SettingValueListWrapper::Ptr &value) :
501+ CopyRawValueBase <cci::SettingValueListWrapper::Ptr> (value)
502+ {
503+ }
504+
505+ ReturnType operator () ()
506+ {
507+ return ccsCopyList (*Parent::mValue,
508+ Parent::mValue->setting ().get ());
509+ }
510+};
511+
512+CCSSettingValue *
513+NewCCSSettingValue ()
514+{
515+ CCSSettingValue *value =
516+ reinterpret_cast <CCSSettingValue *> (
517+ calloc (1, sizeof (CCSSettingValue)));
518+
519+ value->refCount = 1;
520+
521+ return value;
522+}
523+
524+template <typename SettingValueType>
525+CCSSettingValue *
526+RawValueToCCSValue (const SettingValueType &value)
527+{
528+ typedef typename CopyRawValue <SettingValueType>::ReturnType UnionType;
529+
530+ CCSSettingValue *settingValue = NewCCSSettingValue ();
531+ UnionType *unionMember =
532+ reinterpret_cast <UnionType *> (&settingValue->value);
533+
534+ *unionMember = (CopyRawValue <SettingValueType> (value)) ();
535+
536+ return settingValue;
537+}
538+
539+template <typename SettingValueType>
540+CCSSettingValuePtr
541+RawValueToListValue (const SettingValueType &value)
542+{
543+ return ListValueToSettingValueList (RawValueToCCSValue (value));
544+}
545+
546+class ContainedValueGenerator
547+{
548+ private:
549+
550+ const CCSSettingValuePtr &
551+ InitializedSpawnedValue (const CCSSettingValuePtr &value,
552+ CCSSettingType type,
553+ const CCSSettingInfoPtr &info)
554+ {
555+ const CCSSettingPtr &setting (GetSetting (type, info));
556+ value->parent = setting.get ();
557+ mContainedValues.push_back (value);
558+
559+ return mContainedValues.back ();
560+ }
561+
562+ public:
563+
564+ template <typename SettingValueType>
565+ const CCSSettingValuePtr &
566+ SpawnValueForInfoAndType (const SettingValueType &rawValue,
567+ CCSSettingType type,
568+ const CCSSettingInfoPtr &info)
569+ {
570+
571+ CCSSettingValuePtr value (AutoDestroy (RawValueToCCSValue <SettingValueType> (rawValue),
572+ ccsSettingValueUnref));
573+
574+ return InitializedSpawnedValue (value, type, info);
575+ }
576+
577+ const CCSSettingPtr &
578+ GetSetting (CCSSettingType type,
579+ const CCSSettingInfoPtr &info)
580+ {
581+ if (!mSetting)
582+ SetupMockSetting (type, info);
583+
584+ return mSetting;
585+ }
586+
587+ private:
588+
589+ void SetupMockSetting (CCSSettingType type,
590+ const CCSSettingInfoPtr &info)
591+ {
592+ mSetting = AutoDestroy (ccsMockSettingNew (),
593+ ccsSettingUnref);
594+
595+ CCSSettingGMock *settingMock =
596+ reinterpret_cast <CCSSettingGMock *> (
597+ ccsObjectGetPrivate (mSetting.get ()));
598+
599+ EXPECT_CALL (*settingMock, getType ())
600+ .WillRepeatedly (Return (type));
601+
602+ EXPECT_CALL (*settingMock, getInfo ())
603+ .WillRepeatedly (Return (info.get ()));
604+
605+ EXPECT_CALL (*settingMock, getDefaultValue ())
606+ .WillRepeatedly (ReturnNull ());
607+ }
608+
609+ /* This must always be before the value
610+ * as the values hold a weak reference to
611+ * it */
612+ CCSSettingPtr mSetting;
613+ std::vector <CCSSettingValuePtr> mContainedValues;
614+
615+};
616+
617+/* ValueContainer Interface */
618+template <typename SettingValueType>
619+class ValueContainer
620+{
621+ public:
622+
623+ typedef boost::shared_ptr <ValueContainer> Ptr;
624+
625+ virtual const SettingValueType &
626+ getRawValue (CCSSettingType type,
627+ const CCSSettingInfoPtr &info) = 0;
628+ virtual const CCSSettingValuePtr &
629+ getContainedValue (CCSSettingType type,
630+ const CCSSettingInfoPtr &info) = 0;
631+};
632+
633+class NormalValueContainerBase
634+{
635+ protected:
636+
637+ ContainedValueGenerator mContainedValueGenerator;
638+ CCSSettingValuePtr mContainedValue;
639+};
640+
641+template <typename SettingValueType>
642+class NormalValueContainer :
643+ public NormalValueContainerBase,
644+ public ValueContainer <SettingValueType>
645+{
646+ public:
647+
648+ NormalValueContainer (const SettingValueType &value) :
649+ mRawValue (value)
650+ {
651+ }
652+
653+ const SettingValueType &
654+ getRawValue (CCSSettingType type,
655+ const CCSSettingInfoPtr &info)
656+ {
657+ return mRawValue;
658+ }
659+
660+ const CCSSettingValuePtr &
661+ getContainedValue (CCSSettingType type,
662+ const CCSSettingInfoPtr &info)
663+ {
664+ if (!mContainedValue)
665+ mContainedValue = mContainedValueGenerator.SpawnValueForInfoAndType (mRawValue,
666+ type,
667+ info);
668+
669+ return mContainedValue;
670+ }
671+
672+ private:
673+
674+ const SettingValueType &mRawValue;
675+};
676+
677+template <typename SettingValueType>
678+typename NormalValueContainer <SettingValueType>::Ptr
679+ContainNormal (const SettingValueType &value)
680+{
681+ return boost::make_shared <NormalValueContainer <SettingValueType> > (value);
682+}
683+
684+class ListValueContainerBase :
685+ public ValueContainer <CCSSettingValueList>
686+{
687+ protected:
688+
689+ const CCSSettingValuePtr &
690+ getContainedValue (CCSSettingType type,
691+ const CCSSettingInfoPtr &info)
692+ {
693+ if (!mContainedWrapper)
694+ {
695+ const cci::SettingValueListWrapper::Ptr &wrapper (SetupWrapper (type, info));
696+
697+ mContainedWrapper =
698+ mContainedValueGenerator.SpawnValueForInfoAndType (wrapper,
699+ type,
700+ info);
701+ }
702+
703+ return mContainedWrapper;
704+ }
705+
706+ const CCSSettingValueList &
707+ getRawValue (CCSSettingType type,
708+ const CCSSettingInfoPtr &info)
709+ {
710+ const cci::SettingValueListWrapper::Ptr &wrapper (SetupWrapper (type, info));
711+
712+ return *wrapper;
713+ }
714+
715+ cci::SettingValueListWrapper::Ptr mWrapper;
716+
717+ /* ccsFreeSettingValue has an implicit
718+ * dependency on mWrapper (CCSSettingValue -> CCSSetting ->
719+ * CCSSettingInfo -> cci::SettingValueListWrapper), these should
720+ * be kept after mWrapper here */
721+ ContainedValueGenerator mContainedValueGenerator;
722+ CCSSettingValuePtr mContainedWrapper;
723+
724+ private:
725+
726+ const cci::SettingValueListWrapper::Ptr &
727+ SetupWrapper (CCSSettingType type,
728+ const CCSSettingInfoPtr &info)
729+ {
730+ if (!mWrapper)
731+ {
732+ const CCSSettingPtr &setting (mContainedValueGenerator.GetSetting (type, info));
733+ CCSSettingValue *value = GetValueForListWrapper ();
734+
735+ value->parent = setting.get ();
736+ value->isListChild = TRUE;
737+ mWrapper.reset (new cci::SettingValueListWrapper (NULL,
738+ cci::Deep,
739+ type,
740+ info,
741+ setting));
742+ mWrapper->append (value);
743+ }
744+
745+ return mWrapper;
746+ }
747+
748+ virtual CCSSettingValue * GetValueForListWrapper () = 0;
749+};
750+
751+template <typename SettingValueType>
752+class ListValueContainer :
753+ public ListValueContainerBase
754+{
755+ public:
756+
757+ ListValueContainer (const SettingValueType &value) :
758+ mRawChildValue (value)
759+ {
760+ }
761+
762+ private:
763+
764+ CCSSettingValue * GetValueForListWrapper ()
765+ {
766+ return RawValueToCCSValue (mRawChildValue);
767+ }
768+
769+ const SettingValueType &mRawChildValue;
770+};
771+
772+template <typename SettingValueType>
773+typename ValueContainer <CCSSettingValueList>::Ptr
774+ContainList (const SettingValueType &value)
775+{
776+ return boost::make_shared <ListValueContainer <SettingValueType> > (value);
777+}
778+
779+class DefaultImplSetParamInterface
780+{
781+ public:
782+
783+ typedef boost::shared_ptr <DefaultImplSetParamInterface> Ptr;
784+ typedef boost::function <void (MockInitializerFuncs &funcs)> SetUpSettingFunc;
785+
786+ virtual ~DefaultImplSetParamInterface () {};
787+
788+ virtual void SetUpSetting (const SetUpSettingFunc &func) = 0;
789+ virtual void TearDownSetting () = 0;
790+ virtual CCSSettingType GetSettingType () = 0;
791+ virtual void SetUpParam (const CCSSettingPtr &) = 0;
792+ virtual Bool setWithInvalidType () = 0;
793+ virtual Bool setToFailValue () = 0;
794+ virtual Bool setToNonDefaultValue () = 0;
795+ virtual Bool setToDefaultValue () = 0;
796+};
797+
798+void stubInitializeSettingInfo (CCSSettingType type,
799+ CCSSettingInfo *copyToInfo,
800+ void *data)
801+{
802+ CCSSettingInfo *copyFromInfo = reinterpret_cast <CCSSettingInfo *> (data);
803+
804+ ccsCopyInfo (copyFromInfo, copyToInfo, type);
805+}
806+
807+void stubInitializeSettingDefaultValue (CCSSettingType type,
808+ CCSSettingInfo *info,
809+ CCSSettingValue *copyToValue,
810+ void *data)
811+{
812+ CCSSettingValue *copyFromValue = reinterpret_cast <CCSSettingValue *> (data);
813+ CCSSetting *oldParentForOtherValue = copyFromValue->parent;
814+
815+ /* Change the parent to this setting that's being initialized
816+ * as that needs to go into the setting's default value as
817+ * the parent entry */
818+ copyFromValue->parent = copyToValue->parent;
819+ ccsCopyValueInto (copyFromValue, copyToValue, type, info);
820+
821+ /* Restore the old parent */
822+ copyFromValue->parent = oldParentForOtherValue;
823+}
824+
825+class MockInitializerFuncsWithDelegators :
826+ public MockInitializerFuncs
827+{
828+ public:
829+
830+ MockInitializerFuncsWithDelegators (CCSSettingInfo *info,
831+ CCSSettingValue *value) :
832+ MockInitializerFuncs (),
833+ mInfo (info),
834+ mValue (value)
835+ {
836+ ON_CALL (*this, initializeInfo (_, _, _))
837+ .WillByDefault (WithArgs <0, 1> (
838+ Invoke (this,
839+ &MockInitializerFuncsWithDelegators::initializeInfoDelegator)));
840+
841+ ON_CALL (*this, initializeDefaultValue (_, _, _, _))
842+ .WillByDefault (WithArgs <0, 1, 2> (
843+ Invoke (this,
844+ &MockInitializerFuncsWithDelegators::initializeValueDelegator)));
845+ }
846+
847+ void initializeInfoDelegator (CCSSettingType type,
848+ CCSSettingInfo *info)
849+ {
850+ stubInitializeSettingInfo (type, info, reinterpret_cast <void *> (mInfo));
851+ }
852+
853+ void initializeValueDelegator (CCSSettingType type,
854+ CCSSettingInfo *info,
855+ CCSSettingValue *value)
856+ {
857+ stubInitializeSettingDefaultValue (type, info, value,
858+ reinterpret_cast <void *> (mValue));
859+ }
860+
861+ CCSSettingInfo *mInfo;
862+ CCSSettingValue *mValue;
863+};
864+
865+template <typename SettingValueType>
866+struct SettingMutators
867+{
868+ typedef Bool (*SetFunction) (CCSSetting *setting,
869+ SettingValueType data,
870+ Bool);
871+ typedef Bool (*GetFunction) (CCSSetting *setting,
872+ SettingValueType *);
873+};
874+
875+class DefaultImplSetParamBase :
876+ public DefaultImplSetParamInterface
877+{
878+ public:
879+
880+ DefaultImplSetParamBase (const CCSSettingInfoPtr &info,
881+ CCSSettingType type) :
882+ mInfo (info),
883+ mType (type)
884+ {
885+ }
886+
887+ virtual void TearDownSetting ()
888+ {
889+ if (mSetting)
890+ setToDefaultValue ();
891+ }
892+
893+ void InitializeDefaultsForSetting (const SetUpSettingFunc &func)
894+ {
895+ MockInitializerFuncsWithDelegators mockInitializers (mInfo.get (), mValue.get ());
896+
897+ func (mockInitializers);
898+ }
899+
900+ void TakeReferenceToCreatedSetting (const CCSSettingPtr &setting)
901+ {
902+ mSetting = setting;
903+ }
904+
905+ const CCSSettingInterface * RedirectSettingInterface ()
906+ {
907+ const CCSSettingInterface *settingInterface =
908+ GET_INTERFACE (CCSSettingInterface, mSetting.get ());
909+ CCSSettingInterface tmpSettingInterface = *settingInterface;
910+
911+ tmpSettingInterface.settingGetType =
912+ DefaultImplSetParamBase::returnIncorrectSettingType;
913+
914+ ccsObjectRemoveInterface (mSetting.get (),
915+ GET_INTERFACE_TYPE (CCSSettingInterface));
916+ ccsObjectAddInterface (mSetting.get (),
917+ (const CCSInterface *) &tmpSettingInterface,
918+ GET_INTERFACE_TYPE (CCSSettingInterface));
919+
920+ return settingInterface;
921+ }
922+
923+ void RestoreSettingInterface (const CCSSettingInterface *settingInterface)
924+ {
925+ /* Restore the old interface */
926+ ccsObjectRemoveInterface (mSetting.get (),
927+ GET_INTERFACE_TYPE (CCSSettingInterface));
928+ ccsObjectAddInterface (mSetting.get (),
929+ (const CCSInterface *) settingInterface,
930+ GET_INTERFACE_TYPE (CCSSettingInterface));
931+ }
932+
933+ virtual Bool setToFailValue ()
934+ {
935+ return TRUE;
936+ }
937+
938+ virtual CCSSettingType GetSettingType ()
939+ {
940+ return mType;
941+ }
942+
943+ protected:
944+
945+ CCSSettingInfoPtr mInfo;
946+ CCSSettingValuePtr mValue;
947+ CCSSettingType mType;
948+ CCSSettingPtr mSetting;
949+
950+ private:
951+
952+ static const CCSSettingType incorrectSettingType = TypeNum;
953+ static CCSSettingType returnIncorrectSettingType (CCSSetting *setting)
954+ {
955+ return incorrectSettingType;
956+ }
957+};
958+
959+class RequireSettingInterfaceRedirection
960+{
961+ public:
962+
963+ RequireSettingInterfaceRedirection (DefaultImplSetParamBase *base) :
964+ mBase (base),
965+ mSettingInterface (mBase->RedirectSettingInterface ())
966+ {
967+ }
968+
969+ ~RequireSettingInterfaceRedirection ()
970+ {
971+ mBase->RestoreSettingInterface (mSettingInterface);
972+ }
973+
974+ private:
975+
976+ DefaultImplSetParamBase *mBase;
977+ const CCSSettingInterface *mSettingInterface;
978+};
979+
980+template <typename SettingValueType>
981+class DefaultImplSetParamTemplatedBase
982+{
983+ protected:
984+
985+ typedef typename ValueContainer <SettingValueType>::Ptr ValueContainerPtr;
986+
987+ DefaultImplSetParamTemplatedBase (const ValueContainerPtr &defaultValueContainer,
988+ const ValueContainerPtr &nonDefaultValueContainer) :
989+ mDefaultValueContainer (defaultValueContainer),
990+ mNonDefaultValueContainer (nonDefaultValueContainer)
991+ {
992+ }
993+
994+ ValueContainerPtr mDefaultValueContainer;
995+ ValueContainerPtr mNonDefaultValueContainer;
996+};
997+
998+template <typename SettingValueType>
999+class DefaultImplSetParam :
1000+ /* Do not change the order of inheritance here, DefaultImplSetParamTemplatedBase
1001+ * must be destroyed after DefaultImplSetParamBase as DefaultImplSetParamBase
1002+ * has indirect weak references to variables in DefaultImplSetParamTemplatedBase
1003+ */
1004+ private DefaultImplSetParamTemplatedBase <SettingValueType>,
1005+ public DefaultImplSetParamBase
1006+{
1007+ public:
1008+
1009+ typedef typename SettingMutators <SettingValueType>::SetFunction SetFunction;
1010+ typedef typename SettingMutators <SettingValueType>::GetFunction GetFunction;
1011+ typedef typename ValueContainer <SettingValueType>::Ptr ValueContainerPtr;
1012+ typedef DefaultImplSetParamTemplatedBase <SettingValueType> TemplateParent;
1013+
1014+ DefaultImplSetParam (const ValueContainerPtr &defaultValueContainer,
1015+ CCSSettingType type,
1016+ SetFunction setFunction,
1017+ GetFunction getFunction,
1018+ const CCSSettingInfoPtr &info,
1019+ const ValueContainerPtr &nonDefaultValueContainer) :
1020+ DefaultImplSetParamTemplatedBase <SettingValueType> (defaultValueContainer,
1021+ nonDefaultValueContainer),
1022+ DefaultImplSetParamBase (info, type),
1023+ mSetFunction (setFunction),
1024+ mGetFunction (getFunction)
1025+ {
1026+ }
1027+
1028+ virtual void SetUpSetting (const SetUpSettingFunc &func)
1029+ {
1030+ /* Do delayed setup here */
1031+ mValue = TemplateParent::mDefaultValueContainer->getContainedValue (mType, mInfo);
1032+ mNonDefaultValue = TemplateParent::mNonDefaultValueContainer->getRawValue (mType, mInfo);
1033+
1034+ InitializeDefaultsForSetting (func);
1035+ }
1036+
1037+ virtual void SetUpParam (const CCSSettingPtr &setting)
1038+ {
1039+ ASSERT_TRUE ((*mGetFunction) (setting.get (), &mDefaultValue));
1040+
1041+ TakeReferenceToCreatedSetting (setting);
1042+ }
1043+
1044+ virtual Bool setWithInvalidType ()
1045+ {
1046+ RequireSettingInterfaceRedirection redirection (this);
1047+
1048+ return (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
1049+ }
1050+
1051+ virtual Bool setToNonDefaultValue ()
1052+ {
1053+ return (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
1054+ }
1055+
1056+ virtual Bool setToDefaultValue ()
1057+ {
1058+ return (*mSetFunction) (mSetting.get (), mDefaultValue, FALSE);
1059+ }
1060+
1061+ private:
1062+
1063+ SettingValueType mDefaultValue;
1064+ SettingValueType mNonDefaultValue;
1065+
1066+ protected:
1067+
1068+ SetFunction mSetFunction;
1069+ GetFunction mGetFunction;
1070+
1071+};
1072+
1073+class SetWithDisallowedValueBase
1074+{
1075+ protected:
1076+
1077+ SetWithDisallowedValueBase (const CCSSettingPtr &setting,
1078+ const CCSSettingInfoPtr &info) :
1079+ mSetting (setting),
1080+ mInfo (info)
1081+ {
1082+ }
1083+
1084+ CCSSettingPtr mSetting;
1085+ CCSSettingInfoPtr mInfo;
1086+};
1087+
1088+template <typename SettingValueType>
1089+class SetWithDisallowedValueTemplatedBase :
1090+ public SetWithDisallowedValueBase
1091+{
1092+ protected:
1093+
1094+ typedef typename SettingMutators <SettingValueType>::SetFunction SetFunction;
1095+
1096+ SetWithDisallowedValueTemplatedBase (SetFunction setFunction,
1097+ const CCSSettingPtr &setting,
1098+ const CCSSettingInfoPtr &info) :
1099+ SetWithDisallowedValueBase (setting, info),
1100+ mSetFunction (setFunction)
1101+ {
1102+ }
1103+
1104+ SetFunction mSetFunction;
1105+};
1106+
1107+template <typename SettingValueType>
1108+class SetWithDisallowedValue :
1109+ public SetWithDisallowedValueTemplatedBase <SettingValueType>
1110+{
1111+ public:
1112+
1113+ typedef typename SettingMutators <SettingValueType>::SetFunction SetFunction;
1114+
1115+ SetWithDisallowedValue (SetFunction setFunction,
1116+ const CCSSettingPtr &setting,
1117+ const CCSSettingInfoPtr &info) :
1118+ SetWithDisallowedValueTemplatedBase <SettingValueType> (setFunction, setting, info)
1119+ {
1120+ }
1121+
1122+ Bool operator () ()
1123+ {
1124+ return FALSE;
1125+ }
1126+};
1127+
1128+template <>
1129+class SetWithDisallowedValue <int> :
1130+ public SetWithDisallowedValueTemplatedBase <int>
1131+{
1132+ public:
1133+
1134+ typedef typename SettingMutators <int>::SetFunction SetFunction;
1135+ typedef SetWithDisallowedValueTemplatedBase <int> Parent;
1136+
1137+ SetWithDisallowedValue (SetFunction setFunction,
1138+ const CCSSettingPtr &setting,
1139+ const CCSSettingInfoPtr &info) :
1140+ SetWithDisallowedValueTemplatedBase <int> (setFunction, setting, info)
1141+ {
1142+ }
1143+
1144+ Bool operator () ()
1145+ {
1146+ return (*Parent::mSetFunction) (Parent::mSetting.get (),
1147+ Parent::mInfo->forInt.min - 1,
1148+ FALSE);
1149+ }
1150+};
1151+
1152+template <>
1153+class SetWithDisallowedValue <float> :
1154+ public SetWithDisallowedValueTemplatedBase <float>
1155+{
1156+ public:
1157+
1158+ typedef typename SettingMutators <float>::SetFunction SetFunction;
1159+ typedef SetWithDisallowedValueTemplatedBase <float> Parent;
1160+
1161+ SetWithDisallowedValue (SetFunction setFunction,
1162+ const CCSSettingPtr &setting,
1163+ const CCSSettingInfoPtr &info) :
1164+ SetWithDisallowedValueTemplatedBase <float> (setFunction, setting, info)
1165+ {
1166+ }
1167+
1168+ Bool operator () ()
1169+ {
1170+ return (*Parent::mSetFunction) (Parent::mSetting.get (),
1171+ Parent::mInfo->forFloat.min - 1,
1172+ FALSE);
1173+ }
1174+};
1175+
1176+template <>
1177+class SetWithDisallowedValue <const char *> :
1178+ public SetWithDisallowedValueTemplatedBase <const char *>
1179+{
1180+ public:
1181+
1182+ typedef typename SettingMutators <const char *>::SetFunction SetFunction;
1183+ typedef SetWithDisallowedValueTemplatedBase <const char *> Parent;
1184+
1185+ SetWithDisallowedValue (SetFunction setFunction,
1186+ const CCSSettingPtr &setting,
1187+ const CCSSettingInfoPtr &info) :
1188+ SetWithDisallowedValueTemplatedBase <const char *> (setFunction, setting, info)
1189+ {
1190+ }
1191+
1192+ Bool operator () ()
1193+ {
1194+ return (*Parent::mSetFunction) (Parent::mSetting.get (),
1195+ NULL,
1196+ FALSE);
1197+ }
1198+};
1199+
1200+template <typename SettingValueType>
1201+class DefaultImplSetFailureParam :
1202+ public DefaultImplSetParam <SettingValueType>
1203+{
1204+ public:
1205+
1206+ typedef DefaultImplSetParam <SettingValueType> Parent;
1207+ typedef typename DefaultImplSetParam <SettingValueType>::SetFunction SetFunction;
1208+ typedef typename DefaultImplSetParam <SettingValueType>::GetFunction GetFunction;
1209+ typedef typename DefaultImplSetParam <SettingValueType>::ValueContainerPtr ValueContainerPtr;
1210+
1211+ DefaultImplSetFailureParam (const ValueContainerPtr &defaultValueContainer,
1212+ CCSSettingType type,
1213+ SetFunction setFunction,
1214+ GetFunction getFunction,
1215+ const CCSSettingInfoPtr &info,
1216+ const ValueContainerPtr &nonDefaultValueContainer) :
1217+ DefaultImplSetParam <SettingValueType> (defaultValueContainer,
1218+ type,
1219+ setFunction,
1220+ getFunction,
1221+ info,
1222+ nonDefaultValueContainer)
1223+ {
1224+ }
1225+
1226+ virtual Bool setToFailValue ()
1227+ {
1228+ typedef DefaultImplSetParam <SettingValueType> Parent;
1229+ return SetWithDisallowedValue <SettingValueType> (Parent::mSetFunction,
1230+ Parent::mSetting,
1231+ Parent::mInfo) ();
1232+ }
1233+};
1234+
1235+template <typename SettingValueType>
1236+DefaultImplSetParamInterface::Ptr
1237+SemanticsParamFor (const typename ValueContainer <SettingValueType>::Ptr &defaultValue,
1238+ CCSSettingType type,
1239+ typename SettingMutators<SettingValueType>::SetFunction setFunc,
1240+ typename SettingMutators<SettingValueType>::GetFunction getFunc,
1241+ const CCSSettingInfoPtr &settingInfo,
1242+ const typename ValueContainer <SettingValueType>::Ptr &changeTo)
1243+{
1244+ typedef SettingValueType T;
1245+ return boost::make_shared <DefaultImplSetParam <T> > (defaultValue,
1246+ type,
1247+ setFunc,
1248+ getFunc,
1249+ settingInfo,
1250+ changeTo);
1251+}
1252+
1253+template <typename SettingValueType>
1254+DefaultImplSetParamInterface::Ptr
1255+FailureSemanticsParamFor (const typename ValueContainer <SettingValueType>::Ptr &defaultValue,
1256+ CCSSettingType type,
1257+ typename SettingMutators<SettingValueType>::SetFunction setFunc,
1258+ typename SettingMutators<SettingValueType>::GetFunction getFunc,
1259+ const CCSSettingInfoPtr &settingInfo,
1260+ const typename ValueContainer <SettingValueType>::Ptr &changeTo)
1261+{
1262+ typedef SettingValueType T;
1263+ return boost::make_shared <DefaultImplSetFailureParam <T> > (defaultValue,
1264+ type,
1265+ setFunc,
1266+ getFunc,
1267+ settingInfo,
1268+ changeTo);
1269+}
1270+
1271+class SettingDefaultImplSet :
1272+ public CCSSettingDefaultImplTest,
1273+ public WithParamInterface <DefaultImplSetParamInterface::Ptr>
1274+{
1275+ public:
1276+
1277+ virtual void SetUp ()
1278+ {
1279+ GetParam ()->SetUpSetting (boost::bind (&CCSSettingDefaultImplTest::SetUpSetting, this, _1));
1280+ GetParam ()->SetUpParam (setting);
1281+ }
1282+
1283+ virtual void TearDown ()
1284+ {
1285+ GetParam ()->TearDownSetting ();
1286+ }
1287+
1288+ CCSSettingType GetSettingType ()
1289+ {
1290+ return GetParam ()->GetSettingType ();
1291+ }
1292+};
1293+
1294+class SettingDefaulImplSetFailure :
1295+ public SettingDefaultImplSet
1296+{
1297+};
1298+
1299+}

Subscribers

People subscribed via source and target branches