|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /** |
|
18 * @note This class is provided only if module test hooks are set on. |
|
19 */ |
|
20 |
|
21 #include "alfmoduletestconf.h" |
|
22 #ifdef USE_MODULE_TEST_HOOKS_FOR_ALF |
|
23 |
|
24 #ifndef ALFMODULETESTITEM_H |
|
25 #define ALFMODULETESTITEM_H |
|
26 |
|
27 #include <e32def.h> |
|
28 #include "alfmoduletesttype.h" |
|
29 |
|
30 |
|
31 /** |
|
32 * CAlfModuleTestItem |
|
33 * |
|
34 * Provides key-value pair that is used in TAlfModuleTestMap. |
|
35 */ |
|
36 template< class T > |
|
37 NONSHARABLE_CLASS( TAlfModuleTestItem ) |
|
38 { |
|
39 |
|
40 public: |
|
41 |
|
42 /** |
|
43 * Default constructor |
|
44 * |
|
45 * This is provided for copy operations that may required default constructor. |
|
46 * For normal cases, use another constructor instead to initialize the item |
|
47 * with correct values. |
|
48 */ |
|
49 TAlfModuleTestItem(): |
|
50 iTestType( EAlfModuleTestTypeNone ), |
|
51 iKey( 0 ), |
|
52 iValueSetCount( 0 ), |
|
53 iLinkTargetKey( KErrNotFound ) |
|
54 { |
|
55 } |
|
56 |
|
57 |
|
58 /** |
|
59 * Constructor to initialize variables. |
|
60 * |
|
61 * @param aTestType Defines for what this test item is meant for. |
|
62 * @param aKey Key that identifies the item. |
|
63 * In test cases this could be for example handle. |
|
64 * @param aDefaultValue Default value for the map item. |
|
65 */ |
|
66 TAlfModuleTestItem( const TAlfModuleTestType& aTestType, TInt aKey, const T& aDefaultValue ): |
|
67 iTestType( aTestType ), |
|
68 iKey( aKey ), |
|
69 iValue( aDefaultValue ), |
|
70 iValueSetCount( 0 ), |
|
71 iLinkTargetKey( KErrNotFound ) |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 /** |
|
77 * @note Be carefull when comparing items because some items may |
|
78 * be link items instead of original items. |
|
79 * |
|
80 * @param aTestType Test type of accepted item. |
|
81 * @param aValue Item value to be compared. |
|
82 * @return ETrue if given object equals the value of this item. |
|
83 * Else EFalse. |
|
84 */ |
|
85 TBool Equals( const TAlfModuleTestType& aTestType, const T& aValue ) const |
|
86 { |
|
87 // Also, check that value has been set. If it has not been set, |
|
88 // then think objects as unequals. |
|
89 return ( iValueSetCount > 0 |
|
90 && iValue == aValue |
|
91 && TestTypeMatch( aTestType ) ); |
|
92 } |
|
93 |
|
94 |
|
95 /** |
|
96 * @return TInt Key that should be set during creation of this object. |
|
97 */ |
|
98 TInt Key() const |
|
99 { |
|
100 return iKey; |
|
101 } |
|
102 |
|
103 |
|
104 /** |
|
105 * @see TAlfModuleTestItem::ValueSetCount to check if the value has already been set. |
|
106 * |
|
107 * @return const T& Value that corresonds the key. |
|
108 */ |
|
109 const T& Value() const |
|
110 { |
|
111 return iValue; |
|
112 } |
|
113 |
|
114 |
|
115 /** |
|
116 * @param aValue Value to be set for the key |
|
117 */ |
|
118 void SetValue( const T& aValue ) |
|
119 { |
|
120 iValue = aValue; |
|
121 ++iValueSetCount; |
|
122 } |
|
123 |
|
124 |
|
125 /** |
|
126 * @return TInt Informs how many times the value has been set. |
|
127 */ |
|
128 TInt ValueSetCount() const |
|
129 { |
|
130 return iValueSetCount; |
|
131 } |
|
132 |
|
133 |
|
134 /** |
|
135 * @return const TAlfModuleTestType& Defines what the test is for. |
|
136 */ |
|
137 const TAlfModuleTestType& TestType() const |
|
138 { |
|
139 return iTestType; |
|
140 } |
|
141 |
|
142 |
|
143 /** |
|
144 * @param aTestType Type of the test this item is for. |
|
145 * @return TBool ETrue if flag matches this item. Else EFalse. |
|
146 */ |
|
147 TBool TestTypeMatch( const TAlfModuleTestType& aTestType ) const |
|
148 { |
|
149 return ( EAlfModuleTestTypeAll == aTestType |
|
150 || EAlfModuleTestTypeAll == iTestType |
|
151 || iTestType == aTestType ); |
|
152 } |
|
153 |
|
154 |
|
155 /** |
|
156 * @param aLinkTargetKey Key of the item that this item links to. |
|
157 * KErrNotFound if this is not a link item. |
|
158 */ |
|
159 void SetLinkTargetKey( TInt aLinkTargetKey ) |
|
160 { |
|
161 iLinkTargetKey = aLinkTargetKey; |
|
162 } |
|
163 |
|
164 |
|
165 /** |
|
166 * @return TInt Key of the item that this item links to. |
|
167 * KErrNotFound if this is not a link item. |
|
168 */ |
|
169 TInt LinkTargetKey() const |
|
170 { |
|
171 return iLinkTargetKey; |
|
172 } |
|
173 |
|
174 |
|
175 /** |
|
176 * Resets this item to the given default value and |
|
177 * sets value set count to zero. |
|
178 * |
|
179 * @note Type, key and link target remain unchanged. |
|
180 * |
|
181 * @param aDefaultValue Default value for the item. |
|
182 */ |
|
183 void Reset( const T& aDefaultValue ) |
|
184 { |
|
185 iValue = aDefaultValue; |
|
186 iValueSetCount = 0; |
|
187 } |
|
188 |
|
189 |
|
190 private: // data |
|
191 |
|
192 TAlfModuleTestType iTestType; |
|
193 TInt iKey; |
|
194 T iValue; |
|
195 TInt iValueSetCount; |
|
196 TInt iLinkTargetKey; |
|
197 |
|
198 }; |
|
199 |
|
200 #endif // ALFMODULETESTITEM_H |
|
201 |
|
202 #endif // USE_MODULE_TEST_HOOKS_FOR_ALF |
|
203 |
|
204 // End of File |