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

Proposed by Sam Spilsbury
Status: Superseded
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: 585 lines (+272/-76)
1 file modified
compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp (+272/-76)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1063617.9.1
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Compiz Maintainers Pending
Review via email: mp+136857@code.launchpad.net

This proposal has been superseded by 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 :

Your commit message needs fixing here ^^

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

Merge lp:compiz

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

The failure tests pass NULL through CopyRawValue - allow that and just return
NULL as the copy

3517. By Sam Spilsbury

Small typo fix

Unmerged revisions

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

Subscribers

People subscribed via source and target branches