146
149
typedef boost::shared_ptr <CCSSettingValue> CCSSettingValuePtr;
147
150
typedef boost::shared_ptr <CCSSetting> CCSSettingPtr;
149
class MockInitializerFuncs
153
MOCK_METHOD3 (initializeInfo, void (CCSSettingType, CCSSettingInfo *, void *));
154
MOCK_METHOD4 (initializeDefaultValue, void (CCSSettingType, CCSSettingInfo *, CCSSettingValue *, void *));
156
MOCK_METHOD3 (initInfo, void (CCSSettingType, CCSSettingInfo *, void *));
157
MOCK_METHOD4 (initDefaultValue, void (CCSSettingType, CCSSettingInfo *, CCSSettingValue *, void *));
156
static void wrapInitializeInfo (CCSSettingType type,
157
CCSSettingInfo *info,
159
static void wrapInitInfo (CCSSettingType type,
160
CCSSettingInfo *info,
160
MockInitializerFuncs &funcs (*(reinterpret_cast <MockInitializerFuncs *> (data)));
161
funcs.initializeInfo (type, info, data);
163
MockInitFuncs &funcs (*(reinterpret_cast <MockInitFuncs *> (data)));
164
funcs.initInfo (type, info, data);
164
static void wrapInitializeValue (CCSSettingType type,
165
CCSSettingInfo *info,
166
CCSSettingValue *value,
167
static void wrapInitValue (CCSSettingType type,
168
CCSSettingInfo *info,
169
CCSSettingValue *value,
169
MockInitializerFuncs &funcs (*(reinterpret_cast <MockInitializerFuncs *> (data)));
170
funcs.initializeDefaultValue (type, info, value, data);
172
MockInitFuncs &funcs (*(reinterpret_cast <MockInitFuncs *> (data)));
173
funcs.initDefaultValue (type, info, value, data);
195
virtual void SetUpSetting (MockInitializerFuncs &funcs)
197
virtual void SetUpSetting (MockInitFuncs &funcs)
197
199
void *vFuncs = reinterpret_cast <void *> (&funcs);
199
201
/* Info must be initialized before the value */
202
EXPECT_CALL (funcs, initializeInfo (GetSettingType (), _, vFuncs));
203
EXPECT_CALL (funcs, initializeDefaultValue (GetSettingType (), _, _, vFuncs));
204
EXPECT_CALL (funcs, initInfo (GetSettingType (), _, vFuncs));
205
EXPECT_CALL (funcs, initDefaultValue (GetSettingType (), _, _, vFuncs));
205
207
setting = AutoDestroy (ccsSettingDefaultImplNew (plugin.get (),
206
208
SETTING_NAME.c_str (),
386
390
const CCSSettingValuePtr &
387
InitializedSpawnedValue (const CCSSettingValuePtr &value,
389
const CCSSettingInfoPtr &info)
391
InitValue (const CCSSettingValuePtr &value,
393
const CCSSettingInfoPtr &info)
391
395
const CCSSettingPtr &setting (GetSetting (type, info));
392
396
value->parent = setting.get ();
393
mContainedValues.push_back (value);
397
mValues.push_back (value);
395
return mContainedValues.back ();
399
return mValues.back ();
400
404
template <typename SettingValueType>
401
405
const CCSSettingValuePtr &
402
SpawnValueForInfoAndType (const SettingValueType &rawValue,
404
const CCSSettingInfoPtr &info)
406
SpawnValue (const SettingValueType &rawValue,
408
const CCSSettingInfoPtr &info)
407
411
CCSSettingValuePtr value (AutoDestroy (RawValueToCCSValue <SettingValueType> (rawValue),
408
412
ccsSettingValueUnref));
410
return InitializedSpawnedValue (value, type, info);
414
return InitValue (value, type, info);
413
417
const CCSSettingPtr &
612
616
return boost::make_shared <ListValueContainer <SettingValueType> > (value);
623
typedef boost::shared_ptr <SetParam> Ptr;
624
typedef boost::function <void (MockInitFuncs &funcs)> SetUpSettingFunc;
626
virtual ~SetParam () {};
628
virtual void SetUpSetting (const SetUpSettingFunc &func) = 0;
629
virtual void TearDownSetting () = 0;
630
virtual CCSSettingType GetSettingType () = 0;
631
virtual void SetUpParam (const CCSSettingPtr &) = 0;
632
virtual Bool setWithInvalidType () = 0;
633
virtual Bool setToFailValue () = 0;
634
virtual Bool setToNonDefaultValue () = 0;
635
virtual Bool setToDefaultValue () = 0;
638
void stubInitInfo (CCSSettingType type,
642
CCSSettingInfo *src = reinterpret_cast <CCSSettingInfo *> (data);
644
ccsCopyInfo (src, dst, type);
647
void stubInitDefaultValue (CCSSettingType type,
648
CCSSettingInfo *info,
649
CCSSettingValue *dest,
652
CCSSettingValue *src = reinterpret_cast <CCSSettingValue *> (data);
653
CCSSetting *oldDestParent = src->parent;
655
/* Change the parent to this setting that's being initialized
656
* as that needs to go into the setting's default value as
657
* the parent entry */
658
src->parent = dest->parent;
659
ccsCopyValueInto (src, dest, type, info);
661
/* Restore the old parent */
662
src->parent = oldDestParent;
665
class StubInitFuncs :
670
StubInitFuncs (CCSSettingInfo *info,
671
CCSSettingValue *value) :
676
ON_CALL (*this, initInfo (_, _, _))
677
.WillByDefault (WithArgs <0, 1> (
679
&StubInitFuncs::initInfo)));
681
ON_CALL (*this, initDefaultValue (_, _, _, _))
682
.WillByDefault (WithArgs <0, 1, 2> (
684
&StubInitFuncs::initializeValue)));
687
void initInfo (CCSSettingType type,
688
CCSSettingInfo *info)
690
stubInitInfo (type, info, reinterpret_cast <void *> (mInfo));
693
void initializeValue (CCSSettingType type,
694
CCSSettingInfo *info,
695
CCSSettingValue *value)
697
stubInitDefaultValue (type, info, value,
698
reinterpret_cast <void *> (mValue));
701
CCSSettingInfo *mInfo;
702
CCSSettingValue *mValue;
615
705
template <typename SettingValueType>
616
706
struct SettingMutators
622
712
SettingValueType *);
715
class InternalSetParam :
720
InternalSetParam (const CCSSettingInfoPtr &info,
721
CCSSettingType type) :
727
virtual void TearDownSetting ()
730
setToDefaultValue ();
733
void InitDefaultsForSetting (const SetUpSettingFunc &func)
735
StubInitFuncs stubInitializers (mInfo.get (), mValue.get ());
737
func (stubInitializers);
740
void TakeReferenceToCreatedSetting (const CCSSettingPtr &setting)
745
const CCSSettingInterface * RedirectSettingInterface ()
747
const CCSSettingInterface *settingInterface =
748
GET_INTERFACE (CCSSettingInterface, mSetting.get ());
749
CCSSettingInterface tmpSettingInterface = *settingInterface;
751
tmpSettingInterface.settingGetType =
752
InternalSetParam::returnIncorrectSettingType;
754
ccsObjectRemoveInterface (mSetting.get (),
755
GET_INTERFACE_TYPE (CCSSettingInterface));
756
ccsObjectAddInterface (mSetting.get (),
757
(const CCSInterface *) &tmpSettingInterface,
758
GET_INTERFACE_TYPE (CCSSettingInterface));
760
return settingInterface;
763
void RestoreSettingInterface (const CCSSettingInterface *settingInterface)
765
/* Restore the old interface */
766
ccsObjectRemoveInterface (mSetting.get (),
767
GET_INTERFACE_TYPE (CCSSettingInterface));
768
ccsObjectAddInterface (mSetting.get (),
769
(const CCSInterface *) settingInterface,
770
GET_INTERFACE_TYPE (CCSSettingInterface));
773
virtual Bool setToFailValue ()
778
virtual CCSSettingType GetSettingType ()
785
CCSSettingInfoPtr mInfo;
786
CCSSettingValuePtr mValue;
787
CCSSettingType mType;
788
CCSSettingPtr mSetting;
792
static const CCSSettingType incorrectSettingType = TypeNum;
793
static CCSSettingType returnIncorrectSettingType (CCSSetting *setting)
795
return incorrectSettingType;
799
template <typename SettingValueType>
800
class SetParamContainerStorage
804
typedef typename ValueContainer <SettingValueType>::Ptr ValueContainerPtr;
806
SetParamContainerStorage (const ValueContainerPtr &defaultValue,
807
const ValueContainerPtr &nonDefaultValue) :
808
mDefault (defaultValue),
809
mNonDefault (nonDefaultValue)
813
ValueContainerPtr mDefault;
814
ValueContainerPtr mNonDefault;
817
template <typename SettingValueType>
818
class TypedSetParam :
819
/* Do not change the order of inheritance here, DefaultImplSetParamTemplatedBase
820
* must be destroyed after DefaultImplSetParamBase as DefaultImplSetParamBase
821
* has indirect weak references to variables in DefaultImplSetParamTemplatedBase
823
private SetParamContainerStorage <SettingValueType>,
824
public InternalSetParam
828
typedef typename SettingMutators <SettingValueType>::SetFunction SetFunction;
829
typedef typename SettingMutators <SettingValueType>::GetFunction GetFunction;
830
typedef typename ValueContainer <SettingValueType>::Ptr ValueContainerPtr;
831
typedef SetParamContainerStorage <SettingValueType> TemplateParent;
833
TypedSetParam (const ValueContainerPtr &defaultValue,
835
SetFunction setFunction,
836
GetFunction getFunction,
837
const CCSSettingInfoPtr &info,
838
const ValueContainerPtr &nonDefaultValue) :
839
SetParamContainerStorage <SettingValueType> (defaultValue,
841
InternalSetParam (info, type),
842
mSetFunction (setFunction),
843
mGetFunction (getFunction)
847
virtual void SetUpSetting (const SetUpSettingFunc &func)
849
/* Do delayed setup here */
850
mValue = TemplateParent::mDefault->getContainedValue (mType, mInfo);
851
mNonDefaultValue = TemplateParent::mNonDefault->getRawValue (mType, mInfo);
853
InitDefaultsForSetting (func);
856
virtual void SetUpParam (const CCSSettingPtr &setting)
858
ASSERT_TRUE ((*mGetFunction) (setting.get (), &mDefaultValue));
860
TakeReferenceToCreatedSetting (setting);
863
virtual Bool setWithInvalidType ()
865
CCSSettingInterface *iface = RedirectSettingInterface ();
866
Bool ret = (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
867
RestoreSettingInterface (iface);
872
virtual Bool setToNonDefaultValue ()
874
return (*mSetFunction) (mSetting.get (), mNonDefaultValue, FALSE);
877
virtual Bool setToDefaultValue ()
879
return (*mSetFunction) (mSetting.get (), mDefaultValue, FALSE);
884
SettingValueType mDefaultValue;
885
SettingValueType mNonDefaultValue;
889
SetFunction mSetFunction;
890
GetFunction mGetFunction;
625
894
class SetWithDisallowedValueBase
1021
template <typename SettingValueType>
1022
class SetFailureParam :
1023
public TypedSetParam <SettingValueType>
1027
typedef TypedSetParam <SettingValueType> Parent;
1028
typedef typename TypedSetParam <SettingValueType>::SetFunction SetFunction;
1029
typedef typename TypedSetParam <SettingValueType>::GetFunction GetFunction;
1030
typedef typename TypedSetParam <SettingValueType>::ValueContainerPtr ValueContainerPtr;
1032
SetFailureParam (const ValueContainerPtr &defaultValue,
1033
CCSSettingType type,
1034
SetFunction setFunction,
1035
GetFunction getFunction,
1036
const CCSSettingInfoPtr &info,
1037
const ValueContainerPtr &nonDefault) :
1038
TypedSetParam <SettingValueType> (defaultValue,
1047
virtual Bool setToFailValue ()
1049
typedef TypedSetParam <SettingValueType> Parent;
1050
return SetWithDisallowedValue <SettingValueType> (Parent::mSetFunction,
1056
template <typename T>
1058
SemanticsParamFor (const typename ValueContainer <T>::Ptr &defaultValue,
1059
CCSSettingType type,
1060
typename SettingMutators<T>::SetFunction setFunc,
1061
typename SettingMutators<T>::GetFunction getFunc,
1062
const CCSSettingInfoPtr &settingInfo,
1063
const typename ValueContainer <T>::Ptr &changeTo)
1065
return boost::make_shared <TypedSetParam <T> > (defaultValue,
1073
template <typename T>
1075
FailureSemanticsParamFor (const typename ValueContainer <T>::Ptr &defaultValue,
1076
CCSSettingType type,
1077
typename SettingMutators<T>::SetFunction setFunc,
1078
typename SettingMutators<T>::GetFunction getFunc,
1079
const CCSSettingInfo &settingInfo,
1080
const typename ValueContainer <T>::Ptr &changeTo)
1082
return boost::make_shared <SetFailureParam <T> > (defaultValue,
1090
class SettingDefaultImplSet :
1091
public CCSSettingDefaultImplTest,
1092
public WithParamInterface <SetParam::Ptr>
1096
virtual void SetUp ()
1098
GetParam ()->SetUpSetting (boost::bind (&CCSSettingDefaultImplTest::SetUpSetting, this, _1));
1099
GetParam ()->SetUpParam (setting);
1102
virtual void TearDown ()
1104
GetParam ()->TearDownSetting ();
1107
CCSSettingType GetSettingType ()
1109
return GetParam ()->GetSettingType ();
1113
class SettingDefaulImplSetFailure :
1114
public SettingDefaultImplSet