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

Proposed by Sam Spilsbury
Status: Merged
Approved by: Martin Mrazik
Approved revision: 3498
Merged at revision: 3506
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1063617.7
Merge into: lp:compiz/0.9.9
Diff against target: 585 lines (+407/-41)
1 file modified
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp (+407/-41)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1063617.7
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Sam Spilsbury Approve
Daniel van Vugt Approve
Review via email: mp+136917@code.launchpad.net

This proposal supersedes 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 : Posted in a previous version of this proposal

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

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Ping, other work is blocked on this

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

1. As usual, I find it unreadable due to the long lines, from long identifiers and template use everywhere.

2. Can you find a better name for: class RequireSettingInterfaceRedirection ? There seems to be no (strong enough) noun really describing what an instance of such a thing is. How do I visualize a RequireSettingInterfaceRedirection in my model of the world? Is "redirection" the noun? Sounds more like an operation so would be a method of some other class.

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

On Dec 4, 2012 11:59 AM, "Daniel van Vugt" <email address hidden>
wrote:
>
> Review: Needs Information
>
> 1. As usual, I find it unreadable due to the long lines, from long
identifiers and template use everywhere.
>

Can you identify which lines you find problematic, and provide alternative
solutions please?

> 2. Can you find a better name for: class
RequireSettingInterfaceRedirection ? There seems to be no (strong enough)
noun really describing what an instance of such a thing is. How do I
visualize a RequireSettingInterfaceRedirection in my model of the world? Is
"redirection" the noun? Sounds more like an operation so would be a method
of some other class.

Its meant to be a state that automatically cleans up. Hence the reason why
its a class.

Its only really used once though, so I suppose it can be changed to:

->RedirectGetTypeFunc ()
->DoThing ()
->UnredirectGetTypeFunc ()

>
>
> --
>
https://code.launchpad.net/~compiz-team/compiz/compiz.fix_1063617.7/+merge/136917
> Your team Compiz Maintainers is subscribed to branch lp:compiz.

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

Identifiers too long:
  * "Initialize" should be "Init"
  * "Interface" and "Impl" are implied by the context and should be obvious from the rest of the class name, if not the namespace. So you should never need to say "Interface", "Impl" or "Base".
  * Many parameters are excessively descriptive and sometimes misleading. For example "copyToValue"/"copyFromValue" could be better represented as nouns: "dest"/"src".
  * ValueContainerPtr mDefaultValueContainer; ValueContainerPtr mNonDefaultValueContainer; ... I already know they are ValueContainers. You rarely need to put the type name in the variable name. The variable name is already half the description of a variable.
  * "WithParamInterface" as a template name. How does the "With" prefix make sense?
  * "MockInitializerFuncsWithDelegators" as a class name... The "With" suffix is unusual and hinders readability because the primary noun is no longer at the end (contrary to English grammar). Consider rewording "WithWhatever" suffixes into a prefix of some sort.
  * "SemanticsParamFor" and "FailureSemanticsParamFor" are unreadable because the types of the parameters dominate the function definition, mostly due to templates. I don't have an understanding of the code to suggest any alternatives right now, other than templates should only ever be used scarcely.

Finally, remember carefully chosen English is only half the problem in readable code. The other half is realizing code is mostly symbolic. You should see the structure and flow without having to read the words themselves. And remember we recognize words or identifiers as symbols. So if an identifier is made up of too many words it becomes unrecognisable as a symbol and easily mistaken for some other identifier with similar spelling.

But enough said. I've said it all before.

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

Thanks for the advice.

I'll have another look today to see where we can simplify some of the class
names (they are a bit lame).
On Dec 4, 2012 1:29 PM, "Daniel van Vugt" <email address hidden>
wrote:

> Review: Approve
>
> Identifiers too long:
> * "Initialize" should be "Init"
> * "Interface" and "Impl" are implied by the context and should be
> obvious from the rest of the class name, if not the namespace. So you
> should never need to say "Interface", "Impl" or "Base".
> * Many parameters are excessively descriptive and sometimes misleading.
> For example "copyToValue"/"copyFromValue" could be better represented as
> nouns: "dest"/"src".
> * ValueContainerPtr mDefaultValueContainer; ValueContainerPtr
> mNonDefaultValueContainer; ... I already know they are ValueContainers.
> You rarely need to put the type name in the variable name. The variable
> name is already half the description of a variable.
> * "WithParamInterface" as a template name. How does the "With" prefix
> make sense?
> * "MockInitializerFuncsWithDelegators" as a class name... The "With"
> suffix is unusual and hinders readability because the primary noun is no
> longer at the end (contrary to English grammar). Consider rewording
> "WithWhatever" suffixes into a prefix of some sort.
> * "SemanticsParamFor" and "FailureSemanticsParamFor" are unreadable
> because the types of the parameters dominate the function definition,
> mostly due to templates. I don't have an understanding of the code to
> suggest any alternatives right now, other than templates should only ever
> be used scarcely.
>
> Finally, remember carefully chosen English is only half the problem in
> readable code. The other half is realizing code is mostly symbolic. You
> should see the structure and flow without having to read the words
> themselves. And remember we recognize words or identifiers as symbols. So
> if an identifier is made up of too many words it becomes unrecognisable as
> a symbol and easily mistaken for some other identifier with similar
> spelling.
>
> But enough said. I've said it all before.
>
> --
>
> https://code.launchpad.net/~compiz-team/compiz/compiz.fix_1063617.7/+merge/136917
> Your team Compiz Maintainers is subscribed to branch lp:compiz.
>

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

On Dec 4, 2012 1:29 PM, "Daniel van Vugt" <email address hidden>
wrote:
>
> Review: Approve
>
> Identifiers too long:
> * "Initialize" should be "Init"

I'll change that.

> * "Interface" and "Impl" are implied by the context and should be
obvious from the rest of the class name, if not the namespace. So you
should never need to say "Interface", "Impl" or "Base".

I agree with this, although the structural separation is necessary.

Either I can use the namespace trick, I'll give this a little more thought
and see what works.

> * Many parameters are excessively descriptive and sometimes misleading.
For example "copyToValue"/"copyFromValue" could be better represented as
nouns: "dest"/"src".

+1

> * ValueContainerPtr mDefaultValueContainer; ValueContainerPtr
 mNonDefaultValueContainer; ... I already know they are ValueContainers.
You rarely need to put the type name in the variable name. The variable
name is already half the description of a variable.

+1 . They can become mDefaultValue and mNonDefaultValue

> * "WithParamInterface" as a template name. How does the "With" prefix
make sense?

This is lame, but it comes from Google Test.

> * "MockInitializerFuncsWithDelegators" as a class name... The "With"
suffix is unusual and hinders readability because the primary noun is no
longer at the end (contrary to English grammar). Consider rewording
"WithWhatever" suffixes into a prefix of some sort.

This can become StubVerifiedSettingInitializers

> * "SemanticsParamFor" and "FailureSemanticsParamFor" are unreadable
because the types of the parameters dominate the function definition,
mostly due to templates. I don't have an understanding of the code to
suggest any alternatives right now, other than templates should only ever
be used scarcely.

Yeah, the only reason why templates were used was that there would be far
too much code repetition any other way.

>
> Finally, remember carefully chosen English is only half the problem in
readable code. The other half is realizing code is mostly symbolic. You
should see the structure and flow without having to read the words
themselves. And remember we recognize words or identifiers as symbols. So
if an identifier is made up of too many words it becomes unrecognisable as
a symbol and easily mistaken for some other identifier with similar
spelling.

Yeah, I agree with this. Sadly english is not too good at dealing with this
problem.

Have another look at this tomorrow, I'll fix up some of the names tonight.

>
> But enough said. I've said it all before.
>
> --
>
https://code.launchpad.net/~compiz-team/compiz/compiz.fix_1063617.7/+merge/136917
> Your team Compiz Maintainers is subscribed to branch lp:compiz.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve
Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

(merged trunk)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp'
2--- compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp 2012-11-26 08:06:08 +0000
3+++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp 2012-12-05 06:00:30 +0000
4@@ -40,6 +40,9 @@
5 using ::testing::_;
6 using ::testing::Return;
7 using ::testing::InSequence;
8+using ::testing::WithArgs;
9+using ::testing::WithParamInterface;
10+using ::testing::Invoke;
11 using ::testing::ReturnNull;
12
13 TEST(CCSSettingTest, TestMock)
14@@ -146,28 +149,28 @@
15 typedef boost::shared_ptr <CCSSettingValue> CCSSettingValuePtr;
16 typedef boost::shared_ptr <CCSSetting> CCSSettingPtr;
17
18-class MockInitializerFuncs
19+class MockInitFuncs
20 {
21 public:
22
23- MOCK_METHOD3 (initializeInfo, void (CCSSettingType, CCSSettingInfo *, void *));
24- MOCK_METHOD4 (initializeDefaultValue, void (CCSSettingType, CCSSettingInfo *, CCSSettingValue *, void *));
25+ MOCK_METHOD3 (initInfo, void (CCSSettingType, CCSSettingInfo *, void *));
26+ MOCK_METHOD4 (initDefaultValue, void (CCSSettingType, CCSSettingInfo *, CCSSettingValue *, void *));
27
28- static void wrapInitializeInfo (CCSSettingType type,
29- CCSSettingInfo *info,
30- void *data)
31+ static void wrapInitInfo (CCSSettingType type,
32+ CCSSettingInfo *info,
33+ void *data)
34 {
35- MockInitializerFuncs &funcs (*(reinterpret_cast <MockInitializerFuncs *> (data)));
36- funcs.initializeInfo (type, info, data);
37+ MockInitFuncs &funcs (*(reinterpret_cast <MockInitFuncs *> (data)));
38+ funcs.initInfo (type, info, data);
39 }
40
41- static void wrapInitializeValue (CCSSettingType type,
42- CCSSettingInfo *info,
43- CCSSettingValue *value,
44- void *data)
45+ static void wrapInitValue (CCSSettingType type,
46+ CCSSettingInfo *info,
47+ CCSSettingValue *value,
48+ void *data)
49 {
50- MockInitializerFuncs &funcs (*(reinterpret_cast <MockInitializerFuncs *> (data)));
51- funcs.initializeDefaultValue (type, info, value, data);
52+ MockInitFuncs &funcs (*(reinterpret_cast <MockInitFuncs *> (data)));
53+ funcs.initDefaultValue (type, info, value, data);
54 }
55 };
56
57@@ -178,7 +181,6 @@
58 const std::string SETTING_SUBGROUP = "Sub Group";
59 const std::string SETTING_HINTS = "Hints";
60 const CCSSettingType SETTING_TYPE = TypeInt;
61-}
62
63 class CCSSettingDefaultImplTest :
64 public ::testing::Test
65@@ -192,15 +194,15 @@
66 {
67 }
68
69- virtual void SetUpSetting (MockInitializerFuncs &funcs)
70+ virtual void SetUpSetting (MockInitFuncs &funcs)
71 {
72 void *vFuncs = reinterpret_cast <void *> (&funcs);
73
74 /* Info must be initialized before the value */
75 InSequence s;
76
77- EXPECT_CALL (funcs, initializeInfo (GetSettingType (), _, vFuncs));
78- EXPECT_CALL (funcs, initializeDefaultValue (GetSettingType (), _, _, vFuncs));
79+ EXPECT_CALL (funcs, initInfo (GetSettingType (), _, vFuncs));
80+ EXPECT_CALL (funcs, initDefaultValue (GetSettingType (), _, _, vFuncs));
81
82 setting = AutoDestroy (ccsSettingDefaultImplNew (plugin.get (),
83 SETTING_NAME.c_str (),
84@@ -210,9 +212,9 @@
85 SETTING_HINTS.c_str (),
86 SETTING_GROUP.c_str (),
87 SETTING_SUBGROUP.c_str (),
88- MockInitializerFuncs::wrapInitializeValue,
89+ MockInitFuncs::wrapInitValue,
90 vFuncs,
91- MockInitializerFuncs::wrapInitializeInfo,
92+ MockInitFuncs::wrapInitInfo,
93 vFuncs,
94 &ccsDefaultObjectAllocator,
95 &ccsDefaultInterfaceTable),
96@@ -221,7 +223,7 @@
97
98 virtual void SetUp ()
99 {
100- MockInitializerFuncs funcs;
101+ MockInitFuncs funcs;
102
103 SetUpSetting (funcs);
104
105@@ -237,6 +239,8 @@
106 boost::shared_ptr <CCSSetting> setting;
107 };
108
109+}
110+
111 TEST_F (CCSSettingDefaultImplTest, Construction)
112 {
113 EXPECT_EQ (SETTING_TYPE, ccsSettingGetType (setting.get ()));
114@@ -384,30 +388,30 @@
115 private:
116
117 const CCSSettingValuePtr &
118- InitializedSpawnedValue (const CCSSettingValuePtr &value,
119- CCSSettingType type,
120- const CCSSettingInfoPtr &info)
121+ InitValue (const CCSSettingValuePtr &value,
122+ CCSSettingType type,
123+ const CCSSettingInfoPtr &info)
124 {
125 const CCSSettingPtr &setting (GetSetting (type, info));
126 value->parent = setting.get ();
127- mContainedValues.push_back (value);
128+ mValues.push_back (value);
129
130- return mContainedValues.back ();
131+ return mValues.back ();
132 }
133
134 public:
135
136 template <typename SettingValueType>
137 const CCSSettingValuePtr &
138- SpawnValueForInfoAndType (const SettingValueType &rawValue,
139- CCSSettingType type,
140- const CCSSettingInfoPtr &info)
141+ SpawnValue (const SettingValueType &rawValue,
142+ CCSSettingType type,
143+ const CCSSettingInfoPtr &info)
144 {
145
146 CCSSettingValuePtr value (AutoDestroy (RawValueToCCSValue <SettingValueType> (rawValue),
147 ccsSettingValueUnref));
148
149- return InitializedSpawnedValue (value, type, info);
150+ return InitValue (value, type, info);
151 }
152
153 const CCSSettingPtr &
154@@ -446,7 +450,7 @@
155 * as the values hold a weak reference to
156 * it */
157 CCSSettingPtr mSetting;
158- std::vector <CCSSettingValuePtr> mContainedValues;
159+ std::vector <CCSSettingValuePtr> mValues;
160
161 };
162
163@@ -470,8 +474,8 @@
164 {
165 protected:
166
167- ContainedValueGenerator mContainedValueGenerator;
168- CCSSettingValuePtr mContainedValue;
169+ ContainedValueGenerator mGenerator;
170+ CCSSettingValuePtr mValue;
171 };
172
173 template <typename SettingValueType>
174@@ -497,12 +501,12 @@
175 getContainedValue (CCSSettingType type,
176 const CCSSettingInfoPtr &info)
177 {
178- if (!mContainedValue)
179- mContainedValue = mContainedValueGenerator.SpawnValueForInfoAndType (mRawValue,
180- type,
181- info);
182+ if (!mValue)
183+ mValue = mGenerator.SpawnValue (mRawValue,
184+ type,
185+ info);
186
187- return mContainedValue;
188+ return mValue;
189 }
190
191 private:
192@@ -531,9 +535,9 @@
193 const cci::SettingValueListWrapper::Ptr &wrapper (SetupWrapper (type, info));
194
195 mContainedWrapper =
196- mContainedValueGenerator.SpawnValueForInfoAndType (wrapper,
197- type,
198- info);
199+ mContainedValueGenerator.SpawnValue (wrapper,
200+ type,
201+ info);
202 }
203
204 return mContainedWrapper;
205@@ -612,6 +616,92 @@
206 return boost::make_shared <ListValueContainer <SettingValueType> > (value);
207 }
208
209+class SetParam
210+{
211+ public:
212+
213+ typedef boost::shared_ptr <SetParam> Ptr;
214+ typedef boost::function <void (MockInitFuncs &funcs)> SetUpSettingFunc;
215+
216+ virtual ~SetParam () {};
217+
218+ virtual void SetUpSetting (const SetUpSettingFunc &func) = 0;
219+ virtual void TearDownSetting () = 0;
220+ virtual CCSSettingType GetSettingType () = 0;
221+ virtual void SetUpParam (const CCSSettingPtr &) = 0;
222+ virtual Bool setWithInvalidType () = 0;
223+ virtual Bool setToFailValue () = 0;
224+ virtual Bool setToNonDefaultValue () = 0;
225+ virtual Bool setToDefaultValue () = 0;
226+};
227+
228+void stubInitInfo (CCSSettingType type,
229+ CCSSettingInfo *dst,
230+ void *data)
231+{
232+ CCSSettingInfo *src = reinterpret_cast <CCSSettingInfo *> (data);
233+
234+ ccsCopyInfo (src, dst, type);
235+}
236+
237+void stubInitDefaultValue (CCSSettingType type,
238+ CCSSettingInfo *info,
239+ CCSSettingValue *dest,
240+ void *data)
241+{
242+ CCSSettingValue *src = reinterpret_cast <CCSSettingValue *> (data);
243+ CCSSetting *oldDestParent = src->parent;
244+
245+ /* Change the parent to this setting that's being initialized
246+ * as that needs to go into the setting's default value as
247+ * the parent entry */
248+ src->parent = dest->parent;
249+ ccsCopyValueInto (src, dest, type, info);
250+
251+ /* Restore the old parent */
252+ src->parent = oldDestParent;
253+}
254+
255+class StubInitFuncs :
256+ public MockInitFuncs
257+{
258+ public:
259+
260+ StubInitFuncs (CCSSettingInfo *info,
261+ CCSSettingValue *value) :
262+ MockInitFuncs (),
263+ mInfo (info),
264+ mValue (value)
265+ {
266+ ON_CALL (*this, initInfo (_, _, _))
267+ .WillByDefault (WithArgs <0, 1> (
268+ Invoke (this,
269+ &StubInitFuncs::initInfo)));
270+
271+ ON_CALL (*this, initDefaultValue (_, _, _, _))
272+ .WillByDefault (WithArgs <0, 1, 2> (
273+ Invoke (this,
274+ &StubInitFuncs::initializeValue)));
275+ }
276+
277+ void initInfo (CCSSettingType type,
278+ CCSSettingInfo *info)
279+ {
280+ stubInitInfo (type, info, reinterpret_cast <void *> (mInfo));
281+ }
282+
283+ void initializeValue (CCSSettingType type,
284+ CCSSettingInfo *info,
285+ CCSSettingValue *value)
286+ {
287+ stubInitDefaultValue (type, info, value,
288+ reinterpret_cast <void *> (mValue));
289+ }
290+
291+ CCSSettingInfo *mInfo;
292+ CCSSettingValue *mValue;
293+};
294+
295 template <typename SettingValueType>
296 struct SettingMutators
297 {
298@@ -622,6 +712,185 @@
299 SettingValueType *);
300 };
301
302+class InternalSetParam :
303+ public SetParam
304+{
305+ protected:
306+
307+ InternalSetParam (const CCSSettingInfoPtr &info,
308+ CCSSettingType type) :
309+ mInfo (info),
310+ mType (type)
311+ {
312+ }
313+
314+ virtual void TearDownSetting ()
315+ {
316+ if (mSetting)
317+ setToDefaultValue ();
318+ }
319+
320+ void InitDefaultsForSetting (const SetUpSettingFunc &func)
321+ {
322+ StubInitFuncs stubInitializers (mInfo.get (), mValue.get ());
323+
324+ func (stubInitializers);
325+ }
326+
327+ void TakeReferenceToCreatedSetting (const CCSSettingPtr &setting)
328+ {
329+ mSetting = setting;
330+ }
331+
332+ const CCSSettingInterface * RedirectSettingInterface ()
333+ {
334+ const CCSSettingInterface *settingInterface =
335+ GET_INTERFACE (CCSSettingInterface, mSetting.get ());
336+ CCSSettingInterface tmpSettingInterface = *settingInterface;
337+
338+ tmpSettingInterface.settingGetType =
339+ InternalSetParam::returnIncorrectSettingType;
340+
341+ ccsObjectRemoveInterface (mSetting.get (),
342+ GET_INTERFACE_TYPE (CCSSettingInterface));
343+ ccsObjectAddInterface (mSetting.get (),
344+ (const CCSInterface *) &tmpSettingInterface,
345+ GET_INTERFACE_TYPE (CCSSettingInterface));
346+
347+ return settingInterface;
348+ }
349+
350+ void RestoreSettingInterface (const CCSSettingInterface *settingInterface)
351+ {
352+ /* Restore the old interface */
353+ ccsObjectRemoveInterface (mSetting.get (),
354+ GET_INTERFACE_TYPE (CCSSettingInterface));
355+ ccsObjectAddInterface (mSetting.get (),
356+ (const CCSInterface *) settingInterface,
357+ GET_INTERFACE_TYPE (CCSSettingInterface));
358+ }
359+
360+ virtual Bool setToFailValue ()
361+ {
362+ return TRUE;
363+ }
364+
365+ virtual CCSSettingType GetSettingType ()
366+ {
367+ return mType;
368+ }
369+
370+ protected:
371+
372+ CCSSettingInfoPtr mInfo;
373+ CCSSettingValuePtr mValue;
374+ CCSSettingType mType;
375+ CCSSettingPtr mSetting;
376+
377+ private:
378+
379+ static const CCSSettingType incorrectSettingType = TypeNum;
380+ static CCSSettingType returnIncorrectSettingType (CCSSetting *setting)
381+ {
382+ return incorrectSettingType;
383+ }
384+};
385+
386+template <typename SettingValueType>
387+class SetParamContainerStorage
388+{
389+ protected:
390+
391+ typedef typename ValueContainer <SettingValueType>::Ptr ValueContainerPtr;
392+
393+ SetParamContainerStorage (const ValueContainerPtr &defaultValue,
394+ const ValueContainerPtr &nonDefaultValue) :
395+ mDefault (defaultValue),
396+ mNonDefault (nonDefaultValue)
397+ {
398+ }
399+
400+ ValueContainerPtr mDefault;
401+ ValueContainerPtr mNonDefault;
402+};
403+
404+template <typename SettingValueType>
405+class TypedSetParam :
406+ /* Do not change the order of inheritance here, DefaultImplSetParamTemplatedBase
407+ * must be destroyed after DefaultImplSetParamBase as DefaultImplSetParamBase
408+ * has indirect weak references to variables in DefaultImplSetParamTemplatedBase
409+ */
410+ private SetParamContainerStorage <SettingValueType>,
411+ public InternalSetParam
412+{
413+ public:
414+
415+ typedef typename SettingMutators <SettingValueType>::SetFunction SetFunction;
416+ typedef typename SettingMutators <SettingValueType>::GetFunction GetFunction;
417+ typedef typename ValueContainer <SettingValueType>::Ptr ValueContainerPtr;
418+ typedef SetParamContainerStorage <SettingValueType> TemplateParent;
419+
420+ TypedSetParam (const ValueContainerPtr &defaultValue,
421+ CCSSettingType type,
422+ SetFunction setFunction,
423+ GetFunction getFunction,
424+ const CCSSettingInfoPtr &info,
425+ const ValueContainerPtr &nonDefaultValue) :
426+ SetParamContainerStorage <SettingValueType> (defaultValue,
427+ nonDefaultValue),
428+ InternalSetParam (info, type),
429+ mSetFunction (setFunction),
430+ mGetFunction (getFunction)
431+ {
432+ }
433+
434+ virtual void SetUpSetting (const SetUpSettingFunc &func)
435+ {
436+ /* Do delayed setup here */
437+ mValue = TemplateParent::mDefault->getContainedValue (mType, mInfo);
438+ mNonDefaultValue = TemplateParent::mNonDefault->getRawValue (mType, mInfo);
439+
440+ InitDefaultsForSetting (func);
441+ }
442+
443+ virtual void SetUpParam (const CCSSettingPtr &setting)
444+ {
445+ ASSERT_TRUE ((*mGetFunction) (setting.get (), &mDefaultValue));
446+
447+ TakeReferenceToCreatedSetting (setting);
448+ }
449+
450+ virtual Bool setWithInvalidType ()
451+ {
452+ CCSSettingInterface *iface = RedirectSettingInterface ();
453+ Bool ret = (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
454+ RestoreSettingInterface (iface);
455+
456+ return ret;
457+ }
458+
459+ virtual Bool setToNonDefaultValue ()
460+ {
461+ return (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
462+ }
463+
464+ virtual Bool setToDefaultValue ()
465+ {
466+ return (*mSetFunction) (mSetting.get (), mDefaultValue, FALSE);
467+ }
468+
469+ private:
470+
471+ SettingValueType mDefaultValue;
472+ SettingValueType mNonDefaultValue;
473+
474+ protected:
475+
476+ SetFunction mSetFunction;
477+ GetFunction mGetFunction;
478+
479+};
480+
481 class SetWithDisallowedValueBase
482 {
483 protected:
484@@ -749,4 +1018,101 @@
485 }
486 };
487
488+template <typename SettingValueType>
489+class SetFailureParam :
490+ public TypedSetParam <SettingValueType>
491+{
492+ public:
493+
494+ typedef TypedSetParam <SettingValueType> Parent;
495+ typedef typename TypedSetParam <SettingValueType>::SetFunction SetFunction;
496+ typedef typename TypedSetParam <SettingValueType>::GetFunction GetFunction;
497+ typedef typename TypedSetParam <SettingValueType>::ValueContainerPtr ValueContainerPtr;
498+
499+ SetFailureParam (const ValueContainerPtr &defaultValue,
500+ CCSSettingType type,
501+ SetFunction setFunction,
502+ GetFunction getFunction,
503+ const CCSSettingInfoPtr &info,
504+ const ValueContainerPtr &nonDefault) :
505+ TypedSetParam <SettingValueType> (defaultValue,
506+ type,
507+ setFunction,
508+ getFunction,
509+ info,
510+ nonDefault)
511+ {
512+ }
513+
514+ virtual Bool setToFailValue ()
515+ {
516+ typedef TypedSetParam <SettingValueType> Parent;
517+ return SetWithDisallowedValue <SettingValueType> (Parent::mSetFunction,
518+ Parent::mSetting,
519+ Parent::mInfo) ();
520+ }
521+};
522+
523+template <typename T>
524+SetParam::Ptr
525+SemanticsParamFor (const typename ValueContainer <T>::Ptr &defaultValue,
526+ CCSSettingType type,
527+ typename SettingMutators<T>::SetFunction setFunc,
528+ typename SettingMutators<T>::GetFunction getFunc,
529+ const CCSSettingInfoPtr &settingInfo,
530+ const typename ValueContainer <T>::Ptr &changeTo)
531+{
532+ return boost::make_shared <TypedSetParam <T> > (defaultValue,
533+ type,
534+ setFunc,
535+ getFunc,
536+ settingInfo,
537+ changeTo);
538+}
539+
540+template <typename T>
541+SetParam::Ptr
542+FailureSemanticsParamFor (const typename ValueContainer <T>::Ptr &defaultValue,
543+ CCSSettingType type,
544+ typename SettingMutators<T>::SetFunction setFunc,
545+ typename SettingMutators<T>::GetFunction getFunc,
546+ const CCSSettingInfo &settingInfo,
547+ const typename ValueContainer <T>::Ptr &changeTo)
548+{
549+ return boost::make_shared <SetFailureParam <T> > (defaultValue,
550+ type,
551+ setFunc,
552+ getFunc,
553+ settingInfo,
554+ changeTo);
555+}
556+
557+class SettingDefaultImplSet :
558+ public CCSSettingDefaultImplTest,
559+ public WithParamInterface <SetParam::Ptr>
560+{
561+ public:
562+
563+ virtual void SetUp ()
564+ {
565+ GetParam ()->SetUpSetting (boost::bind (&CCSSettingDefaultImplTest::SetUpSetting, this, _1));
566+ GetParam ()->SetUpParam (setting);
567+ }
568+
569+ virtual void TearDown ()
570+ {
571+ GetParam ()->TearDownSetting ();
572+ }
573+
574+ CCSSettingType GetSettingType ()
575+ {
576+ return GetParam ()->GetSettingType ();
577+ }
578+};
579+
580+class SettingDefaulImplSetFailure :
581+ public SettingDefaultImplSet
582+{
583+};
584+
585 }

Subscribers

People subscribed via source and target branches