|
1 /* |
|
2 * Copyright (c) 2004 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 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "ut_cmcedictionary.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 |
|
27 // INTERNAL INCLUDES |
|
28 #include "mcedictionary.h" |
|
29 #include "MCETestHelper.h" |
|
30 |
|
31 const TInt KKey1 = -22; |
|
32 const TInt KKey2 = 0; |
|
33 const TUint KUintValue = 456; |
|
34 const TUint KUintValue2 = 675; |
|
35 _LIT8( KStringValue, "some value" ); |
|
36 _LIT8( KStringValue2, "another value" ); |
|
37 |
|
38 // CONSTRUCTION |
|
39 UT_CMceDictionary* UT_CMceDictionary::NewL() |
|
40 { |
|
41 UT_CMceDictionary* self = UT_CMceDictionary::NewLC(); |
|
42 CleanupStack::Pop(); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 UT_CMceDictionary* UT_CMceDictionary::NewLC() |
|
48 { |
|
49 UT_CMceDictionary* self = new( ELeave ) UT_CMceDictionary(); |
|
50 CleanupStack::PushL( self ); |
|
51 |
|
52 self->ConstructL(); |
|
53 |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 // Destructor (virtual by CBase) |
|
59 UT_CMceDictionary::~UT_CMceDictionary() |
|
60 { |
|
61 } |
|
62 |
|
63 // Default constructor |
|
64 UT_CMceDictionary::UT_CMceDictionary() |
|
65 { |
|
66 } |
|
67 |
|
68 // Second phase construct |
|
69 void UT_CMceDictionary::ConstructL() |
|
70 { |
|
71 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
72 // It generates the test case table. |
|
73 CEUnitTestSuiteClass::ConstructL(); |
|
74 } |
|
75 |
|
76 // METHODS |
|
77 |
|
78 |
|
79 |
|
80 void UT_CMceDictionary::SetupL( ) |
|
81 { |
|
82 iDictionary = new ( ELeave ) CMceDictionary(); |
|
83 } |
|
84 |
|
85 void UT_CMceDictionary::Teardown( ) |
|
86 { |
|
87 delete iDictionary; |
|
88 } |
|
89 |
|
90 void UT_CMceDictionary::UT_CMceDictionaryItem_KeyL() |
|
91 { |
|
92 CMceDictionaryItem* item = new( ELeave ) CMceKeyTValuePair<TInt>( KKey1, KUintValue ); |
|
93 EUNIT_ASSERT( item->Key() == KKey1 ); |
|
94 delete item; |
|
95 |
|
96 HBufC8* valueBuf = KStringValue().AllocLC(); |
|
97 item = new( ELeave ) CMceKeyCValuePair<HBufC8>( KKey2, valueBuf ); |
|
98 CleanupStack::Pop( valueBuf ); |
|
99 EUNIT_ASSERT( item->Key() == KKey2 ); |
|
100 delete item; |
|
101 } |
|
102 |
|
103 void UT_CMceDictionary::UT_CMceKeyTValuePair_ValueL() |
|
104 { |
|
105 CMceKeyTValuePair<TInt>* item = new( ELeave ) CMceKeyTValuePair<TInt>( KKey1, KUintValue ); |
|
106 EUNIT_ASSERT( item->Value() == KUintValue ); |
|
107 delete item; |
|
108 } |
|
109 |
|
110 void UT_CMceDictionary::UT_CMceKeyTValuePair_SetValueL() |
|
111 { |
|
112 CMceKeyTValuePair<TInt>* item = new( ELeave ) CMceKeyTValuePair<TInt>( KKey2, KUintValue ); |
|
113 item->SetValue( KUintValue2 ); |
|
114 EUNIT_ASSERT( item->iValue == KUintValue2 ); |
|
115 delete item; |
|
116 } |
|
117 |
|
118 void UT_CMceDictionary::UT_CMceKeyCValuePair_ValueL() |
|
119 { |
|
120 HBufC8* valueBuf = KStringValue().AllocLC(); |
|
121 CMceKeyCValuePair<HBufC8>* item = new( ELeave ) CMceKeyCValuePair<HBufC8>( KKey1, valueBuf ); |
|
122 CleanupStack::Pop( valueBuf ); |
|
123 |
|
124 EUNIT_ASSERT( item->Value() ); |
|
125 EUNIT_ASSERT( item->Value()->Compare( KStringValue ) == 0 ); |
|
126 delete item; |
|
127 } |
|
128 |
|
129 void UT_CMceDictionary::UT_CMceKeyCValuePair_SetValueL() |
|
130 { |
|
131 HBufC8* valueBuf = KStringValue().AllocLC(); |
|
132 CMceKeyCValuePair<HBufC8>* item = new( ELeave ) CMceKeyCValuePair<HBufC8>( KKey2, valueBuf ); |
|
133 CleanupStack::Pop( valueBuf ); |
|
134 CleanupStack::PushL( item ); |
|
135 |
|
136 HBufC8* valueBuf2 = KStringValue2().AllocL(); |
|
137 item->SetValue( valueBuf2 ); |
|
138 EUNIT_ASSERT( item->iValue->Compare( KStringValue2 ) == 0 ); |
|
139 CleanupStack::PopAndDestroy( item ); |
|
140 } |
|
141 |
|
142 void UT_CMceDictionary::UT_CMceDictionary_PairL() |
|
143 { |
|
144 CMceDictionaryItem* item = new( ELeave ) CMceKeyTValuePair<TInt>( KKey1, KUintValue ); |
|
145 CleanupStack::PushL( item ); |
|
146 iDictionary->iPairs.AppendL( item ); |
|
147 CleanupStack::Pop( item ); |
|
148 CMceKeyTValuePair<TInt>* pair = static_cast< CMceKeyTValuePair<TInt>* >( |
|
149 iDictionary->Pair( KKey1 ) ); |
|
150 EUNIT_ASSERT( pair == item ); |
|
151 |
|
152 HBufC8* valueBuf = KStringValue().AllocLC(); |
|
153 CMceDictionaryItem* item2 = new( ELeave ) CMceKeyCValuePair<HBufC8>( KKey2, valueBuf ); |
|
154 CleanupStack::Pop( valueBuf ); |
|
155 CleanupStack::PushL( item2 ); |
|
156 iDictionary->iPairs.AppendL( item2 ); |
|
157 CleanupStack::Pop( item2 ); |
|
158 CMceKeyCValuePair<TInt>* pair2 = static_cast< CMceKeyCValuePair<TInt>* >( |
|
159 iDictionary->Pair( KKey2 ) ); |
|
160 EUNIT_ASSERT( pair2 == item2 ); |
|
161 } |
|
162 |
|
163 void UT_CMceDictionary::UT_CMceDictionary_AddLL() |
|
164 { |
|
165 CMceDictionaryItem* item = new( ELeave ) CMceKeyTValuePair<TInt>( KKey1, KUintValue ); |
|
166 CleanupStack::PushL( item ); |
|
167 iDictionary->AddL( item ); |
|
168 CleanupStack::Pop( item ); |
|
169 |
|
170 HBufC8* valueBuf = KStringValue().AllocLC(); |
|
171 CMceDictionaryItem* item2 = new( ELeave ) CMceKeyCValuePair<HBufC8>( KKey2, valueBuf ); |
|
172 CleanupStack::Pop( valueBuf ); |
|
173 CleanupStack::PushL( item2 ); |
|
174 iDictionary->AddL( item2 ); |
|
175 CleanupStack::Pop( item2 ); |
|
176 |
|
177 EUNIT_ASSERT( iDictionary->iPairs.Count() == 2 ); |
|
178 EUNIT_ASSERT( iDictionary->iPairs[0] == item ); |
|
179 |
|
180 EUNIT_ASSERT( iDictionary->iPairs[1] == item2 ); |
|
181 } |
|
182 |
|
183 void UT_CMceDictionary::UT_CMceDictionary_DeleteL() |
|
184 { |
|
185 CMceDictionaryItem* item = new( ELeave ) CMceKeyTValuePair<TInt>( KKey1, KUintValue ); |
|
186 CleanupStack::PushL( item ); |
|
187 iDictionary->iPairs.AppendL( item ); |
|
188 CleanupStack::Pop( item ); |
|
189 |
|
190 HBufC8* valueBuf = KStringValue().AllocLC(); |
|
191 CMceDictionaryItem* item2 = new( ELeave ) CMceKeyCValuePair<HBufC8>( KKey2, valueBuf ); |
|
192 CleanupStack::Pop( valueBuf ); |
|
193 CleanupStack::PushL( item2 ); |
|
194 iDictionary->iPairs.AppendL( item2 ); |
|
195 CleanupStack::Pop( item2 ); |
|
196 |
|
197 EUNIT_ASSERT( iDictionary->iPairs.Count() == 2 ); |
|
198 |
|
199 iDictionary->Delete( KKey1 ); |
|
200 EUNIT_ASSERT( !iDictionary->Pair( KKey1 ) ); |
|
201 |
|
202 EUNIT_ASSERT( iDictionary->iPairs.Count() == 1 ); |
|
203 |
|
204 iDictionary->Delete( KKey1 ); |
|
205 EUNIT_ASSERT( iDictionary->iPairs.Count() == 1 ); |
|
206 |
|
207 iDictionary->Delete( KKey2 ); |
|
208 EUNIT_ASSERT( !iDictionary->Pair( KKey2 ) ); |
|
209 |
|
210 EUNIT_ASSERT( iDictionary->iPairs.Count() == 0 ); |
|
211 } |
|
212 |
|
213 |
|
214 // TEST TABLE |
|
215 |
|
216 EUNIT_BEGIN_TEST_TABLE( |
|
217 UT_CMceDictionary, |
|
218 "UT_CMceDictionary", |
|
219 "UNIT" ) |
|
220 |
|
221 EUNIT_TEST( |
|
222 "Key - method ", |
|
223 "CMceDictionaryItem", |
|
224 "Key", |
|
225 "FUNCTIONALITY", |
|
226 SetupL, UT_CMceDictionaryItem_KeyL, Teardown) |
|
227 |
|
228 EUNIT_TEST( |
|
229 "Value - method ", |
|
230 "CMceKeyTValuePair", |
|
231 "Value", |
|
232 "FUNCTIONALITY", |
|
233 SetupL, UT_CMceKeyTValuePair_ValueL, Teardown) |
|
234 |
|
235 EUNIT_TEST( |
|
236 "SetValue - method ", |
|
237 "CMceKeyTValuePair", |
|
238 "SetValue", |
|
239 "FUNCTIONALITY", |
|
240 SetupL, UT_CMceKeyTValuePair_SetValueL, Teardown) |
|
241 |
|
242 EUNIT_TEST( |
|
243 "Value - method ", |
|
244 "CMceKeyCValuePair", |
|
245 "Value", |
|
246 "FUNCTIONALITY", |
|
247 SetupL, UT_CMceKeyCValuePair_ValueL, Teardown) |
|
248 |
|
249 EUNIT_TEST( |
|
250 "SetValue - method ", |
|
251 "CMceKeyCValuePair", |
|
252 "SetValue", |
|
253 "FUNCTIONALITY", |
|
254 SetupL, UT_CMceKeyCValuePair_SetValueL, Teardown) |
|
255 |
|
256 EUNIT_TEST( |
|
257 "PairL - method ", |
|
258 "CMceDictionary", |
|
259 "PairL", |
|
260 "FUNCTIONALITY", |
|
261 SetupL, UT_CMceDictionary_PairL, Teardown) |
|
262 |
|
263 EUNIT_TEST( |
|
264 "AddL - method ", |
|
265 "CMceDictionary", |
|
266 "AddL", |
|
267 "FUNCTIONALITY", |
|
268 SetupL, UT_CMceDictionary_AddLL, Teardown) |
|
269 |
|
270 EUNIT_TEST( |
|
271 "DeleteL - method ", |
|
272 "CMceDictionary", |
|
273 "DeleteL", |
|
274 "FUNCTIONALITY", |
|
275 SetupL, UT_CMceDictionary_DeleteL, Teardown) |
|
276 |
|
277 EUNIT_END_TEST_TABLE |
|
278 |
|
279 // END OF FILE |