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

Proposed by Sam Spilsbury
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 3517
Merged at revision: 3610
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1063617.9.1
Merge into: lp:compiz/0.9.9
Prerequisite: lp:~compiz-team/compiz/compiz.fix_1063617.8
Diff against target: 612 lines (+282/-79)
1 file modified
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp (+282/-79)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1063617.9.1
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+148003@code.launchpad.net

This proposal supersedes a proposal from 2013-02-12.

Commit message

Also allow the tests to run through ccsSetValue

Description of the change

Also allow the tests to run through ccsSetValue (increases coverage)

To post a comment you must log in.
Revision history for this message
MC Return (mc-return) wrote : Posted in a previous version of this proposal

Your commit message needs fixing here ^^

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

There is a typo here:

246 + throw std::runtime_error ("called PerfomSet with unknown SetMethod");

it should probably read:

246 + throw std::runtime_error ("called performSet with unknown SetMethod");

3517. By Sam Spilsbury

Small typo fix

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

Thanks, fixed.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

LGTM

review: Approve

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-12-12 08:54:11 +0000
3+++ compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp 2013-02-13 01:43:22 +0000
4@@ -18,6 +18,8 @@
5 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 */
7
8+#include <tr1/tuple>
9+
10 #include <gtest/gtest.h>
11 #include <gmock/gmock.h>
12
13@@ -45,6 +47,7 @@
14 using ::testing::Invoke;
15 using ::testing::ReturnNull;
16 using ::testing::Values;
17+using ::testing::Combine;
18
19 TEST(CCSSettingTest, TestMock)
20 {
21@@ -497,7 +500,11 @@
22
23 ReturnType operator () ()
24 {
25- return strdup (Parent::mValue);
26+ /* Passing an illegal value is okay */
27+ if (Parent::mValue)
28+ return strdup (Parent::mValue);
29+ else
30+ return NULL;
31 }
32
33 private:
34@@ -521,8 +528,11 @@
35
36 ReturnType operator () ()
37 {
38- return ccsCopyList (*Parent::mValue,
39- Parent::mValue->setting ().get ());
40+ if (Parent::mValue)
41+ return ccsCopyList (*Parent::mValue,
42+ Parent::mValue->setting ().get ());
43+ else
44+ return NULL;
45 }
46 };
47
48@@ -732,7 +742,17 @@
49
50 private:
51
52- const cci::SettingValueListWrapper::Ptr &
53+ virtual const cci::SettingValueListWrapper::Ptr &
54+ SetupWrapper (CCSSettingType type,
55+ const CCSSettingInfoPtr &info) = 0;
56+};
57+
58+class ListValueContainerFromChildValueBase :
59+ public ListValueContainerBase
60+{
61+ private:
62+
63+ virtual const cci::SettingValueListWrapper::Ptr &
64 SetupWrapper (CCSSettingType type,
65 const CCSSettingInfoPtr &info)
66 {
67@@ -757,13 +777,45 @@
68 virtual CCSSettingValue * GetValueForListWrapper () = 0;
69 };
70
71+class ListValueContainerFromList :
72+ public ListValueContainerBase
73+{
74+ public:
75+
76+ ListValueContainerFromList (CCSSettingValueList rawValueList) :
77+ mRawValueList (rawValueList)
78+ {
79+ }
80+
81+ private:
82+
83+ const cci::SettingValueListWrapper::Ptr &
84+ SetupWrapper (CCSSettingType type,
85+ const CCSSettingInfoPtr &info)
86+ {
87+ if (!mWrapper)
88+ {
89+ const CCSSettingPtr &setting (mContainedValueGenerator.GetSetting (type, info));
90+ mWrapper.reset (new cci::SettingValueListWrapper (ccsCopyList (mRawValueList, setting.get ()),
91+ cci::Deep,
92+ type,
93+ info,
94+ setting));
95+ }
96+
97+ return mWrapper;
98+ }
99+
100+ CCSSettingValueList mRawValueList;
101+};
102+
103 template <typename SettingValueType>
104-class ListValueContainer :
105- public ListValueContainerBase
106+class ChildValueListValueContainer :
107+ public ListValueContainerFromChildValueBase
108 {
109 public:
110
111- ListValueContainer (const SettingValueType &value) :
112+ ChildValueListValueContainer (const SettingValueType &value) :
113 mRawChildValue (value)
114 {
115 }
116@@ -782,8 +834,136 @@
117 typename ValueContainer <CCSSettingValueList>::Ptr
118 ContainList (const SettingValueType &value)
119 {
120- return boost::make_shared <ListValueContainer <SettingValueType> > (value);
121-}
122+ return boost::make_shared <ChildValueListValueContainer <SettingValueType> > (value);
123+}
124+
125+typename ValueContainer <CCSSettingValueList>::Ptr
126+ContainPrexistingList (const CCSSettingValueList &value)
127+{
128+ return boost::make_shared <ListValueContainerFromList> (value);
129+}
130+
131+template <typename SettingValueType>
132+struct SettingMutators
133+{
134+ typedef CCSSetStatus (*SetFunction) (CCSSetting *setting,
135+ SettingValueType data,
136+ Bool);
137+ typedef Bool (*GetFunction) (CCSSetting *setting,
138+ SettingValueType *);
139+};
140+
141+typedef enum _SetMethod
142+{
143+ ThroughRaw,
144+ ThroughValue
145+} SetMethod;
146+
147+template <typename SettingValueType>
148+CCSSetStatus performRawSet (const SettingValueType &rawValue,
149+ const CCSSettingPtr &setting,
150+ typename SettingMutators<SettingValueType>::SetFunction setFunction)
151+{
152+ return (*setFunction) (setting.get (), rawValue, FALSE);
153+}
154+
155+template <typename SettingValueType>
156+class RawValueContainmentPacker
157+{
158+ public:
159+
160+ RawValueContainmentPacker (const SettingValueType &value) :
161+ mValue (value)
162+ {
163+ }
164+
165+ typename ValueContainer <SettingValueType>::Ptr
166+ operator () ()
167+ {
168+ return ContainNormal (mValue);
169+ }
170+
171+ private:
172+
173+ const SettingValueType &mValue;
174+};
175+
176+template <>
177+class RawValueContainmentPacker <CCSSettingValueList>
178+{
179+ public:
180+
181+ RawValueContainmentPacker (const CCSSettingValueList &value) :
182+ mValue (value)
183+ {
184+ }
185+
186+ typename ValueContainer <CCSSettingValueList>::Ptr
187+ operator () ()
188+ {
189+ return ContainPrexistingList (mValue);
190+ }
191+
192+ private:
193+
194+ const CCSSettingValueList &mValue;
195+};
196+
197+template <typename SettingValueType>
198+typename ValueContainer <SettingValueType>::Ptr
199+ContainRawValue (const SettingValueType &value)
200+{
201+ return RawValueContainmentPacker <SettingValueType> (value) ();
202+}
203+
204+template <typename SettingValueType>
205+CCSSetStatus performValueSet (const SettingValueType &rawValue,
206+ const CCSSettingInfoPtr &info,
207+ CCSSettingType type,
208+ const CCSSettingPtr &setting)
209+{
210+ typename ValueContainer <SettingValueType>::Ptr container (ContainRawValue (rawValue));
211+ const CCSSettingValuePtr &value (container->getContainedValue (type,
212+ info));
213+
214+ return ccsSetValue (setting.get (), value.get (), FALSE);
215+}
216+
217+template <typename SettingValueType>
218+CCSSetStatus performSet (const SettingValueType &rawValue,
219+ const CCSSettingPtr &setting,
220+ const CCSSettingInfoPtr &info,
221+ CCSSettingType type,
222+ typename SettingMutators<SettingValueType>::SetFunction setFunction,
223+ SetMethod method)
224+{
225+ /* XXX:
226+ * This is really bad design because it effectively involves runtime
227+ * switching on types. Unfortunately, there doesn't seem to be a better
228+ * way to do this that's not hugely verbose - injecting the method
229+ * as a class or a function would mean that we'd have to expose
230+ * template parameters to areas where we can't do that because we
231+ * want the tests to run once for ccsSetValue and once for
232+ * ccsSet* . If we did that, we'd have to either write the tests
233+ * twice, or write the INSTANTIATE_TEST_CASE_P sections twice and
234+ * both are 200+ lines of copy-and-paste as opposed to this type-switch
235+ * here
236+ */
237+ switch (method)
238+ {
239+ case ThroughRaw:
240+ return performRawSet (rawValue, setting, setFunction);
241+ break;
242+ case ThroughValue:
243+ return performValueSet (rawValue, info, type, setting);
244+ break;
245+ default:
246+ throw std::runtime_error ("called perfomSet with unknown SetMethod");
247+ }
248+
249+ throw std::runtime_error ("Unreachable");
250+}
251+
252
253 class SetParam
254 {
255@@ -798,10 +978,10 @@
256 virtual void TearDownSetting () = 0;
257 virtual CCSSettingType GetSettingType () = 0;
258 virtual void SetUpParam (const CCSSettingPtr &) = 0;
259- virtual CCSSetStatus setWithInvalidType () = 0;
260- virtual CCSSetStatus setToFailValue () = 0;
261- virtual CCSSetStatus setToNonDefaultValue () = 0;
262- virtual CCSSetStatus setToDefaultValue () = 0;
263+ virtual CCSSetStatus setWithInvalidType (SetMethod) = 0;
264+ virtual CCSSetStatus setToFailValue (SetMethod) = 0;
265+ virtual CCSSetStatus setToNonDefaultValue (SetMethod) = 0;
266+ virtual CCSSetStatus setToDefaultValue (SetMethod) = 0;
267 };
268
269 void stubInitInfo (CCSSettingType type,
270@@ -871,16 +1051,6 @@
271 CCSSettingValue *mValue;
272 };
273
274-template <typename SettingValueType>
275-struct SettingMutators
276-{
277- typedef CCSSetStatus (*SetFunction) (CCSSetting *setting,
278- SettingValueType data,
279- Bool);
280- typedef Bool (*GetFunction) (CCSSetting *setting,
281- SettingValueType *);
282-};
283-
284 class InternalSetParam :
285 public SetParam
286 {
287@@ -895,8 +1065,6 @@
288
289 virtual void TearDownSetting ()
290 {
291- if (mSetting)
292- setToDefaultValue ();
293 }
294
295 void InitDefaultsForSetting (const SetUpSettingFunc &func)
296@@ -944,7 +1112,7 @@
297 GET_INTERFACE_TYPE (CCSSettingInterface));
298 }
299
300- virtual CCSSetStatus setToFailValue ()
301+ virtual CCSSetStatus setToFailValue (SetMethod method)
302 {
303 return SetFailed;
304 }
305@@ -961,6 +1129,8 @@
306 CCSSettingType mType;
307 CCSSettingPtr mSetting;
308
309+ CCSSettingInterface tmpSettingInterface;
310+
311 private:
312
313 static const CCSSettingType incorrectSettingType = TypeNum;
314@@ -1034,26 +1204,25 @@
315 TakeReferenceToCreatedSetting (setting);
316 }
317
318- virtual CCSSetStatus setWithInvalidType ()
319+ virtual CCSSetStatus setWithInvalidType (SetMethod method)
320 {
321 /* Temporarily redirect the setting interface to
322 * our own with an overloaded settingGetType function */
323-
324 const CCSSettingInterface *iface = RedirectSettingInterface ();
325- CCSSetStatus ret = (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
326+ CCSSetStatus ret = performSet (mNonDefaultValue, mSetting, mInfo, mType, mSetFunction, method);
327 RestoreSettingInterface (iface);
328
329 return ret;
330 }
331
332- virtual CCSSetStatus setToNonDefaultValue ()
333+ virtual CCSSetStatus setToNonDefaultValue (SetMethod method)
334 {
335- return (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
336+ return performSet (mNonDefaultValue, mSetting, mInfo, mType, mSetFunction, method);
337 }
338
339- virtual CCSSetStatus setToDefaultValue ()
340+ virtual CCSSetStatus setToDefaultValue (SetMethod method)
341 {
342- return (*mSetFunction) (mSetting.get (), mDefaultValue, FALSE);
343+ return performSet (mDefaultValue, mSetting, mInfo, mType, mSetFunction, method);
344 }
345
346 private:
347@@ -1073,14 +1242,17 @@
348 protected:
349
350 SetWithDisallowedValueBase (const CCSSettingPtr &setting,
351- const CCSSettingInfoPtr &info) :
352+ const CCSSettingInfoPtr &info,
353+ CCSSettingType type) :
354 mSetting (setting),
355- mInfo (info)
356+ mInfo (info),
357+ mType (type)
358 {
359 }
360
361 CCSSettingPtr mSetting;
362 CCSSettingInfoPtr mInfo;
363+ CCSSettingType mType;
364 };
365
366 template <typename SettingValueType>
367@@ -1093,8 +1265,9 @@
368
369 SetWithDisallowedValueTemplatedBase (SetFunction setFunction,
370 const CCSSettingPtr &setting,
371- const CCSSettingInfoPtr &info) :
372- SetWithDisallowedValueBase (setting, info),
373+ const CCSSettingInfoPtr &info,
374+ CCSSettingType type) :
375+ SetWithDisallowedValueBase (setting, info, type),
376 mSetFunction (setFunction)
377 {
378 }
379@@ -1112,12 +1285,13 @@
380
381 SetWithDisallowedValue (SetFunction setFunction,
382 const CCSSettingPtr &setting,
383- const CCSSettingInfoPtr &info) :
384- SetWithDisallowedValueTemplatedBase <SettingValueType> (setFunction, setting, info)
385+ const CCSSettingInfoPtr &info,
386+ CCSSettingType type) :
387+ SetWithDisallowedValueTemplatedBase <SettingValueType> (setFunction, setting, info, type)
388 {
389 }
390
391- CCSSetStatus operator () ()
392+ CCSSetStatus operator () (SetMethod method)
393 {
394 return SetFailed;
395 }
396@@ -1134,16 +1308,20 @@
397
398 SetWithDisallowedValue (SetFunction setFunction,
399 const CCSSettingPtr &setting,
400- const CCSSettingInfoPtr &info) :
401- SetWithDisallowedValueTemplatedBase <int> (setFunction, setting, info)
402+ const CCSSettingInfoPtr &info,
403+ CCSSettingType type) :
404+ SetWithDisallowedValueTemplatedBase <int> (setFunction, setting, info, type)
405 {
406 }
407
408- CCSSetStatus operator () ()
409+ CCSSetStatus operator () (SetMethod method)
410 {
411- return (*Parent::mSetFunction) (Parent::mSetting.get (),
412- Parent::mInfo->forInt.min - 1,
413- FALSE);
414+ return performSet <int> (Parent::mInfo->forInt.min - 1,
415+ Parent::mSetting,
416+ Parent::mInfo,
417+ Parent::mType,
418+ Parent::mSetFunction,
419+ method);
420 }
421 };
422
423@@ -1158,16 +1336,20 @@
424
425 SetWithDisallowedValue (SetFunction setFunction,
426 const CCSSettingPtr &setting,
427- const CCSSettingInfoPtr &info) :
428- SetWithDisallowedValueTemplatedBase <float> (setFunction, setting, info)
429+ const CCSSettingInfoPtr &info,
430+ CCSSettingType type) :
431+ SetWithDisallowedValueTemplatedBase <float> (setFunction, setting, info, type)
432 {
433 }
434
435- CCSSetStatus operator () ()
436+ CCSSetStatus operator () (SetMethod method)
437 {
438- return (*Parent::mSetFunction) (Parent::mSetting.get (),
439- Parent::mInfo->forFloat.min - 1,
440- FALSE);
441+ return performSet <float> (Parent::mInfo->forFloat.min - 1.0f,
442+ Parent::mSetting,
443+ Parent::mInfo,
444+ Parent::mType,
445+ Parent::mSetFunction,
446+ method);
447 }
448 };
449
450@@ -1182,16 +1364,20 @@
451
452 SetWithDisallowedValue (SetFunction setFunction,
453 const CCSSettingPtr &setting,
454- const CCSSettingInfoPtr &info) :
455- SetWithDisallowedValueTemplatedBase <const char *> (setFunction, setting, info)
456+ const CCSSettingInfoPtr &info,
457+ CCSSettingType type) :
458+ SetWithDisallowedValueTemplatedBase <const char *> (setFunction, setting, info, type)
459 {
460 }
461
462- CCSSetStatus operator () ()
463+ CCSSetStatus operator () (SetMethod method)
464 {
465- return (*Parent::mSetFunction) (Parent::mSetting.get (),
466- NULL,
467- FALSE);
468+ return performSet <const char *> (NULL,
469+ Parent::mSetting,
470+ Parent::mInfo,
471+ Parent::mType,
472+ Parent::mSetFunction,
473+ method);
474 }
475 };
476
477@@ -1221,12 +1407,13 @@
478 {
479 }
480
481- virtual CCSSetStatus setToFailValue ()
482+ virtual CCSSetStatus setToFailValue (SetMethod method)
483 {
484 typedef TypedSetParam <SettingValueType> Parent;
485 return SetWithDisallowedValue <SettingValueType> (Parent::mSetFunction,
486 Parent::mSetting,
487- Parent::mInfo) ();
488+ Parent::mInfo,
489+ Parent::mType) (method);
490 }
491 };
492
493@@ -1264,27 +1451,41 @@
494 changeTo);
495 }
496
497+typedef std::tr1::tuple <SetParam::Ptr,
498+ SetMethod> SettingDefaultImplSetParamType;
499+
500 class SettingDefaultImplSet :
501 public CCSSettingDefaultImplTest,
502- public WithParamInterface <SetParam::Ptr>
503+ public WithParamInterface <SettingDefaultImplSetParamType>
504 {
505 public:
506
507+ SettingDefaultImplSet () :
508+ setHarness (std::tr1::get <0> (GetParam ())),
509+ setMethod (std::tr1::get <1> (GetParam ()))
510+ {
511+ }
512+
513 virtual void SetUp ()
514 {
515- GetParam ()->SetUpSetting (boost::bind (&CCSSettingDefaultImplTest::SetUpSetting, this, _1));
516- GetParam ()->SetUpParam (setting);
517+ setHarness->SetUpSetting (boost::bind (&CCSSettingDefaultImplTest::SetUpSetting, this, _1));
518+ setHarness->SetUpParam (setting);
519 }
520
521 virtual void TearDown ()
522 {
523- GetParam ()->TearDownSetting ();
524+ setHarness->TearDownSetting ();
525 }
526
527 CCSSettingType GetSettingType ()
528 {
529- return GetParam ()->GetSettingType ();
530+ return setHarness->GetSettingType ();
531 }
532+
533+ protected:
534+
535+ SetParam::Ptr setHarness;
536+ SetMethod setMethod;
537 };
538
539 class SettingDefaulImplSetFailure :
540@@ -1302,41 +1503,41 @@
541
542 TEST_P (SettingDefaultImplSet, WithInvalidType)
543 {
544- EXPECT_EQ (SetFailed, GetParam ()->setWithInvalidType ());
545+ EXPECT_EQ (SetFailed, setHarness->setWithInvalidType (setMethod));
546 }
547
548 TEST_P (SettingDefaultImplSet, ToNewValue)
549 {
550- EXPECT_EQ (SetToNewValue, GetParam ()->setToNonDefaultValue ());
551+ EXPECT_EQ (SetToNewValue, setHarness->setToNonDefaultValue (setMethod));
552 }
553
554 TEST_P (SettingDefaultImplSet, ToSameValue)
555 {
556- EXPECT_EQ (SetToNewValue, GetParam ()->setToNonDefaultValue ());
557- EXPECT_EQ (SetToSameValue, GetParam ()->setToNonDefaultValue ());
558+ EXPECT_EQ (SetToNewValue, setHarness->setToNonDefaultValue (setMethod));
559+ EXPECT_EQ (SetToSameValue, setHarness->setToNonDefaultValue (setMethod));
560 }
561
562 TEST_P (SettingDefaultImplSet, ToDefaultValue)
563 {
564- EXPECT_EQ (SetToNewValue, GetParam ()->setToNonDefaultValue ());
565- EXPECT_EQ (SetToDefault, GetParam ()->setToDefaultValue ());
566+ EXPECT_EQ (SetToNewValue, setHarness->setToNonDefaultValue (setMethod));
567+ EXPECT_EQ (SetToDefault, setHarness->setToDefaultValue (setMethod));
568 }
569
570 TEST_P (SettingDefaultImplSet, IsDefaultValue)
571 {
572- EXPECT_EQ (SetToNewValue, GetParam ()->setToNonDefaultValue ());
573- EXPECT_EQ (SetToDefault, GetParam ()->setToDefaultValue ());
574- EXPECT_EQ (SetIsDefault, GetParam ()->setToDefaultValue ());
575+ EXPECT_EQ (SetToNewValue, setHarness->setToNonDefaultValue (setMethod));
576+ EXPECT_EQ (SetToDefault, setHarness->setToDefaultValue (setMethod));
577+ EXPECT_EQ (SetIsDefault, setHarness->setToDefaultValue (setMethod));
578 }
579
580 TEST_P (SettingDefaulImplSetFailure, ToFailValue)
581 {
582- EXPECT_EQ (SetFailed, GetParam ()->setToFailValue ());
583+ EXPECT_EQ (SetFailed, setHarness->setToFailValue (setMethod));
584 }
585
586 #define VALUE_TEST INSTANTIATE_TEST_CASE_P
587
588-VALUE_TEST (SetSemantics, SettingDefaulImplSetFailure,
589+VALUE_TEST (SetSemantics, SettingDefaulImplSetFailure, Combine (
590 Values (FailSParam <int> (ContainNormal (INTEGER_DEFAULT_VALUE),
591 TypeInt,
592 ccsSetInt,
593@@ -1364,9 +1565,10 @@
594 ccsGetMatch,
595 AutoDestroyInfo (getGenericInfo (TypeMatch),
596 TypeMatch),
597- ContainNormal (MATCH_VALUE))));
598+ ContainNormal (MATCH_VALUE))),
599+ Values (ThroughRaw, ThroughValue)));
600
601-VALUE_TEST (SetSemantics, SettingDefaultImplSet,
602+VALUE_TEST (SetSemantics, SettingDefaultImplSet, Combine (
603 Values (SParam <int> (ContainNormal (INTEGER_DEFAULT_VALUE),
604 TypeInt,
605 ccsSetInt,
606@@ -1506,4 +1708,5 @@
607 ccsGetList,
608 getListInfo (TypeBell,
609 getActionInfo (TypeBell)),
610- ContainList (BELL_VALUE))));
611+ ContainList (BELL_VALUE))),
612+ Values (ThroughRaw, ThroughValue)));

Subscribers

People subscribed via source and target branches