|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "TJapaneseSoundProperty.h" |
|
17 |
|
18 // System includes |
|
19 #include <vcard.h> |
|
20 #include <f32file.h> |
|
21 #include <e32test.h> |
|
22 |
|
23 // Literal constants |
|
24 _LIT(KTestName, "TJapaneseSoundProperty"); |
|
25 _LIT(KTestPath, "Z:\\VersitJapaneseVCards\\"); |
|
26 _LIT8(KSoundExtensionPropertyParameterName, "X-IRMC-N"); |
|
27 |
|
28 // Globals |
|
29 static RFs TheFsSession; |
|
30 static RTest TheTest(KTestName); |
|
31 |
|
32 static void DoTestsL() |
|
33 { |
|
34 CVersitCardTest* test = CVersitCardTest::NewLC(); |
|
35 test->StartTestsL(); |
|
36 CleanupStack::PopAndDestroy(test); |
|
37 } |
|
38 |
|
39 static void DriveSpaceReport() |
|
40 { |
|
41 TheTest.Printf(_L("Drive space report:\n")); |
|
42 |
|
43 TVolumeInfo volInfo; |
|
44 TheFsSession.Volume(volInfo, EDriveC); |
|
45 TheTest.Printf(_L("Volume C: Free Space: %D\n"), volInfo.iFree); |
|
46 TheTest.Printf(_L("Volume C: Total Size: %D\n"), volInfo.iSize); |
|
47 |
|
48 TheFsSession.Volume(volInfo, EDriveZ); |
|
49 TheTest.Printf(_L("Volume Z: Free Space: %D\n"), volInfo.iFree); |
|
50 TheTest.Printf(_L("Volume Z: Total Size: %D\n"), volInfo.iSize); |
|
51 } |
|
52 |
|
53 //@SYMTestCaseID PIM-TJAPANESESOUNDPROPERTY-0001 |
|
54 |
|
55 GLDEF_C TInt E32Main() |
|
56 { |
|
57 |
|
58 TTime startTime; |
|
59 startTime.UniversalTime(); |
|
60 |
|
61 __UHEAP_MARK; |
|
62 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
63 if (!theCleanup) |
|
64 return KErrNoMemory; |
|
65 |
|
66 if (TheFsSession.Connect() < KErrNone) |
|
67 return KErrGeneral; |
|
68 |
|
69 // Test code to see how much space is left on c: when this is failing with |
|
70 // -43 (KErrDirFull) |
|
71 DriveSpaceReport(); |
|
72 // end of test code |
|
73 |
|
74 TheTest.Start(_L("@SYMTestCaseID PIM-TJAPANESESOUNDPROPERTY-0001 TJapaneseSoundProperty")); |
|
75 TRAPD(error, DoTestsL()); |
|
76 if (error != KErrNone) |
|
77 { |
|
78 TheTest.Printf(_L("Test failed with error code: %d"), error); |
|
79 |
|
80 // Test code to see how much space is left on c: when this is failing with |
|
81 // -43 (KErrDirFull) |
|
82 DriveSpaceReport(); |
|
83 // end of test code |
|
84 } |
|
85 TheTest(error == KErrNone); |
|
86 TheTest.End(); |
|
87 TheTest.Close(); |
|
88 TheFsSession.Close(); |
|
89 |
|
90 delete theCleanup; |
|
91 __UHEAP_MARKEND; |
|
92 |
|
93 TTime finishTime; |
|
94 finishTime.UniversalTime(); |
|
95 TReal elapsed = (TReal)finishTime.MicroSecondsFrom(startTime).Int64(); |
|
96 TheTest.Printf(_L("Elapsed time: %.4f\n"), elapsed/1000000); |
|
97 |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 CVersitCardTest::~CVersitCardTest() |
|
102 { |
|
103 } |
|
104 |
|
105 void CVersitCardTest::ConstructL() |
|
106 { |
|
107 } |
|
108 |
|
109 CVersitCardTest* CVersitCardTest::NewLC() |
|
110 { |
|
111 CVersitCardTest* self = new(ELeave) CVersitCardTest; |
|
112 CleanupStack::PushL(self); |
|
113 self->ConstructL(); |
|
114 return self; |
|
115 } |
|
116 |
|
117 //******************************************************************************************** |
|
118 void CVersitCardTest::StartTestsL() |
|
119 { |
|
120 CParserVCard* parser; |
|
121 |
|
122 |
|
123 // TEST 0 |
|
124 _LIT(KTestFileName0, "escaped.vcf"); //SOUND;X-IRMC-N:This \;Is The \;First\;\;;\;Second\; Bit \; |
|
125 parser = InternalizeCardLC(KTestPath, KTestFileName0); |
|
126 CheckNumberOfSoundPropertiesL(KTestFileName0, *parser, 2); |
|
127 CleanupStack::PopAndDestroy(parser); |
|
128 |
|
129 |
|
130 // TEST 1 |
|
131 _LIT(KTestFileName1, "amano.vcf"); //SOUND;X-IRMC-N:Amano;Yoshitaka |
|
132 parser = InternalizeCardLC(KTestPath, KTestFileName1); |
|
133 CheckNumberOfSoundPropertiesL(KTestFileName1, *parser, 2); |
|
134 CleanupStack::PopAndDestroy(parser); |
|
135 |
|
136 |
|
137 // TEST 2 |
|
138 _LIT(KTestFileName2, "aoki.vcf"); //SOUND;X-IRMC-N;CHARSET=SHIFT_JIS:?A?I?L;?C?T?I |
|
139 parser = InternalizeCardLC(KTestPath, KTestFileName2); |
|
140 CheckNumberOfSoundPropertiesL(KTestFileName2, *parser, 2); |
|
141 CleanupStack::PopAndDestroy(parser); |
|
142 |
|
143 |
|
144 // TEST 3 |
|
145 _LIT(KTestFileName3, "barbara.vcf"); //SOUND;X-IRMC-N;CHARSET=SHIFT_JIS:?o?[?o?‰;?J?^?I?J |
|
146 parser = InternalizeCardLC(KTestPath, KTestFileName3); |
|
147 CheckNumberOfSoundPropertiesL(KTestFileName3, *parser, 2); |
|
148 CleanupStack::PopAndDestroy(parser); |
|
149 |
|
150 |
|
151 // TEST 4 |
|
152 _LIT(KTestFileName4, "Digit1.vcf"); //SOUND;X-IRMC-N:999999;99999 |
|
153 parser = InternalizeCardLC(KTestPath, KTestFileName4); |
|
154 CheckNumberOfSoundPropertiesL(KTestFileName4, *parser, 2); |
|
155 CleanupStack::PopAndDestroy(parser); |
|
156 |
|
157 |
|
158 // TEST 5 |
|
159 _LIT(KTestFileName5, "Digit2.vcf"); //SOUND;X-IRMC-N:‚R‚R‚R‚R‚R‚R;‚T‚T‚T‚T‚T‚T |
|
160 parser = InternalizeCardLC(KTestPath, KTestFileName5); |
|
161 CheckNumberOfSoundPropertiesL(KTestFileName5, *parser, 2); |
|
162 CleanupStack::PopAndDestroy(parser); |
|
163 |
|
164 |
|
165 // TEST 6 |
|
166 _LIT(KTestFileName6, "haga.vcf"); //SOUND;X-IRMC-N;CHARSET=SHIFT_JIS:?n?K;?„?X?V |
|
167 parser = InternalizeCardLC(KTestPath, KTestFileName6); |
|
168 CheckNumberOfSoundPropertiesL(KTestFileName6, *parser, 2); |
|
169 CleanupStack::PopAndDestroy(parser); |
|
170 |
|
171 |
|
172 // TEST 7 |
|
173 _LIT(KTestFileName7, "kasai.vcf"); |
|
174 parser = InternalizeCardLC(KTestPath, KTestFileName7); |
|
175 CheckNumberOfSoundPropertiesL(KTestFileName7, *parser, 2); |
|
176 CleanupStack::PopAndDestroy(parser); |
|
177 |
|
178 |
|
179 // TEST 8 |
|
180 _LIT(KTestFileName8, "kitajima.vcf"); |
|
181 parser = InternalizeCardLC(KTestPath, KTestFileName8); |
|
182 CheckNumberOfSoundPropertiesL(KTestFileName8, *parser, 2); |
|
183 CleanupStack::PopAndDestroy(parser); |
|
184 |
|
185 |
|
186 // TEST 9 |
|
187 _LIT(KTestFileName9, "Longest.vcf"); |
|
188 parser = InternalizeCardLC(KTestPath, KTestFileName9); |
|
189 CheckNumberOfSoundPropertiesL(KTestFileName9, *parser, 2); |
|
190 CleanupStack::PopAndDestroy(parser); |
|
191 |
|
192 |
|
193 // TEST 10 |
|
194 _LIT(KTestFileName10, "matsui.vcf"); |
|
195 parser = InternalizeCardLC(KTestPath, KTestFileName10); |
|
196 CheckNumberOfSoundPropertiesL(KTestFileName10, *parser, 2); |
|
197 CleanupStack::PopAndDestroy(parser); |
|
198 |
|
199 |
|
200 // TEST 11 |
|
201 _LIT(KTestFileName11, "miyazaki.vcf"); |
|
202 parser = InternalizeCardLC(KTestPath, KTestFileName11); |
|
203 CheckNumberOfSoundPropertiesL(KTestFileName11, *parser, 2); |
|
204 CleanupStack::PopAndDestroy(parser); |
|
205 |
|
206 |
|
207 // TEST 12 |
|
208 _LIT(KTestFileName12, "nakai.vcf"); |
|
209 parser = InternalizeCardLC(KTestPath, KTestFileName12); |
|
210 CheckNumberOfSoundPropertiesL(KTestFileName12, *parser, 2); |
|
211 CleanupStack::PopAndDestroy(parser); |
|
212 |
|
213 |
|
214 // TEST 13 |
|
215 _LIT(KTestFileName13, "powell.vcf"); |
|
216 parser = InternalizeCardLC(KTestPath, KTestFileName13); |
|
217 CheckNumberOfSoundPropertiesL(KTestFileName13, *parser, 2); |
|
218 CleanupStack::PopAndDestroy(parser); |
|
219 |
|
220 |
|
221 // TEST 14 |
|
222 _LIT(KTestFileName14, "prolongedsound.vcf"); |
|
223 parser = InternalizeCardLC(KTestPath, KTestFileName14); |
|
224 CheckNumberOfSoundPropertiesL(KTestFileName14, *parser, 2); |
|
225 CleanupStack::PopAndDestroy(parser); |
|
226 |
|
227 |
|
228 // TEST 15 |
|
229 _LIT(KTestFileName15, "SpecialCharacter1.vcf"); |
|
230 parser = InternalizeCardLC(KTestPath, KTestFileName15); |
|
231 CheckNumberOfSoundPropertiesL(KTestFileName15, *parser, 2); |
|
232 CleanupStack::PopAndDestroy(parser); |
|
233 |
|
234 |
|
235 // TEST 16 |
|
236 _LIT(KTestFileName16, "SpecialCharacter1.vcf"); |
|
237 parser = InternalizeCardLC(KTestPath, KTestFileName16); |
|
238 CheckNumberOfSoundPropertiesL(KTestFileName16, *parser, 2); |
|
239 CleanupStack::PopAndDestroy(parser); |
|
240 |
|
241 |
|
242 // TEST 17 |
|
243 _LIT(KTestFileName17, "SpecialCharacter2.vcf"); |
|
244 parser = InternalizeCardLC(KTestPath, KTestFileName17); |
|
245 CheckNumberOfSoundPropertiesL(KTestFileName17, *parser, 2); |
|
246 CleanupStack::PopAndDestroy(parser); |
|
247 |
|
248 |
|
249 // TEST 18 |
|
250 _LIT(KTestFileName18, "takashiro.vcf"); |
|
251 parser = InternalizeCardLC(KTestPath, KTestFileName18); |
|
252 CheckNumberOfSoundPropertiesL(KTestFileName18, *parser, 2); |
|
253 CleanupStack::PopAndDestroy(parser); |
|
254 |
|
255 // TEST 19 |
|
256 _LIT(KTestFileName19, "MultipleSounds.vcf"); |
|
257 parser = InternalizeCardLC(KTestPath, KTestFileName19); |
|
258 CheckNumberOfSoundPropertiesL(KTestFileName19, *parser, 2, 2); |
|
259 CleanupStack::PopAndDestroy(parser); |
|
260 |
|
261 |
|
262 // Create vCard with sound property and export it. |
|
263 CreateVCardTestL(); |
|
264 } |
|
265 |
|
266 |
|
267 //******************************************************************************************** |
|
268 CParserVCard* CVersitCardTest::InternalizeCardLC(const TDesC& aFile) |
|
269 // |
|
270 // Internalize the specified file |
|
271 // |
|
272 { |
|
273 CParserVCard* parser = CParserVCard::NewL(); |
|
274 CleanupStack::PushL(parser); |
|
275 // |
|
276 TInt pos = 0; |
|
277 RFile file; |
|
278 User::LeaveIfError(file.Open(TheFsSession, aFile, EFileRead)); |
|
279 CleanupClosePushL(file); |
|
280 |
|
281 // Read from the file |
|
282 static_cast<CVersitParser*>(parser)->InternalizeL(file, pos); |
|
283 |
|
284 CleanupStack::PopAndDestroy(); // file |
|
285 // |
|
286 return parser; |
|
287 } |
|
288 |
|
289 |
|
290 //******************************************************************************************** |
|
291 CParserVCard* CVersitCardTest::InternalizeCardLC(const TDesC& aPath, const TDesC& aFileName) |
|
292 // |
|
293 // Internalize the specified file from the specified path |
|
294 // |
|
295 { |
|
296 TFileName name(aPath); |
|
297 name += aFileName; |
|
298 return InternalizeCardLC(name); |
|
299 } |
|
300 |
|
301 |
|
302 //******************************************************************************************** |
|
303 void CVersitCardTest::CheckNumberOfSoundPropertiesL(const TDesC& aFileName, const CParserVCard& aParser, TInt aExpectedArrayElementCount, TInt aExpectedPropertyCount) |
|
304 // |
|
305 // Check that the number of SOUND sub-elements are as expected |
|
306 // |
|
307 { |
|
308 TheTest.Printf(_L("%S\n"), &aFileName); |
|
309 (void) aFileName; |
|
310 // |
|
311 TBool passedTest = EFalse; |
|
312 CArrayPtr<CParserProperty>* properties = aParser.PropertyL(KVersitTokenSOUND, TUid::Uid(KVersitPropertyHBufCUid), EFalse); |
|
313 TheTest(properties != NULL); |
|
314 if (properties) |
|
315 { |
|
316 // |
|
317 CleanupStack::PushL(properties); |
|
318 const TInt count = properties->Count(); |
|
319 TheTest(count == aExpectedPropertyCount); |
|
320 // |
|
321 for(TInt i=0; i<count; i++) |
|
322 { |
|
323 const CParserProperty* property = properties->At(i); |
|
324 |
|
325 // Check that the X-IRMC-N property parameter exists |
|
326 const TBool foundParam = property->Param(KSoundExtensionPropertyParameterName) != NULL; |
|
327 TheTest(foundParam); |
|
328 |
|
329 // Check property value |
|
330 TheTest(property->Value() != NULL); |
|
331 |
|
332 CParserPropertyValueHBufC* propertyAsHBufC = static_cast<CParserPropertyValueHBufC*>(property->Value()); |
|
333 |
|
334 // Check property value as an array |
|
335 CParserPropertyValueCDesCArray* valueAsArray = propertyAsHBufC->TreatAsArrayPropertyLC(*property); |
|
336 TheTest(valueAsArray->Value() != NULL); |
|
337 CDesCArray& array = *valueAsArray->Value(); |
|
338 // |
|
339 const TInt arrayItemCount = array.Count(); |
|
340 TheTest(arrayItemCount == aExpectedArrayElementCount); |
|
341 for(TInt j=0; j<arrayItemCount; j++) |
|
342 { |
|
343 const TPtrC pValue(array[j]); |
|
344 TheTest.Printf(_L("%S\n"), &pValue); |
|
345 } |
|
346 TheTest.Printf(_L("\n")); |
|
347 CleanupStack::PopAndDestroy(valueAsArray); |
|
348 // |
|
349 passedTest = ETrue; |
|
350 } |
|
351 |
|
352 CleanupStack::PopAndDestroy(properties); |
|
353 } |
|
354 TheTest(passedTest); |
|
355 } |
|
356 |
|
357 |
|
358 //******************************************************************************************** |
|
359 void CVersitCardTest::CreateVCardTestL() |
|
360 // |
|
361 // |
|
362 // |
|
363 { |
|
364 CVersitParser* parser = CParserVCard::NewL(); |
|
365 CleanupStack::PushL(parser); |
|
366 |
|
367 // Add Name |
|
368 { |
|
369 CDesCArrayFlat* nameArray = new(ELeave) CDesCArrayFlat(2); |
|
370 CleanupStack::PushL(nameArray); |
|
371 nameArray->AppendL(_L("Wibble")); |
|
372 nameArray->AppendL(_L("Wobble")); |
|
373 // |
|
374 CParserPropertyValue* propNameValue = new(ELeave) CParserPropertyValueCDesCArray(nameArray); |
|
375 CleanupStack::Pop(nameArray); |
|
376 CleanupStack::PushL(propNameValue); |
|
377 CParserProperty* propName = CParserProperty::NewL(*propNameValue, KVersitTokenN, NULL); |
|
378 CleanupStack::Pop(propNameValue); |
|
379 parser->AddPropertyL(propName); |
|
380 } |
|
381 |
|
382 // Add Sound |
|
383 { |
|
384 CDesCArrayFlat* soundArray = new(ELeave) CDesCArrayFlat(2); |
|
385 CleanupStack::PushL(soundArray); |
|
386 soundArray->AppendL(_L("Sound1")); |
|
387 soundArray->AppendL(_L("Sound2")); |
|
388 // |
|
389 CParserPropertyValue* propSoundValue = new(ELeave) CParserPropertyValueCDesCArray(soundArray); |
|
390 CleanupStack::Pop(soundArray); |
|
391 CleanupStack::PushL(propSoundValue); |
|
392 CParserProperty* propSound = CParserProperty::NewL(*propSoundValue, KVersitTokenSOUND, NULL); |
|
393 CleanupStack::Pop(propSoundValue); |
|
394 // |
|
395 CParserParam* param = CParserParam::NewL(KSoundExtensionPropertyParameterName, KNullDesC8); |
|
396 CleanupStack::PushL(param); |
|
397 propSound->AddParamL(param); |
|
398 CleanupStack::Pop(param); |
|
399 // |
|
400 parser->AddPropertyL(propSound); |
|
401 } |
|
402 |
|
403 // Export vCard |
|
404 _LIT(KFileName, "C:\\JapaneseSound.vcf"); |
|
405 RFile file; |
|
406 User::LeaveIfError(file.Replace(TheFsSession, KFileName, EFileWrite)); |
|
407 CleanupClosePushL(file); |
|
408 parser->ExternalizeL(file); |
|
409 CleanupStack::PopAndDestroy(&file); |
|
410 |
|
411 // Test |
|
412 CParserVCard* importedCard = CVersitCardTest::InternalizeCardLC(KFileName); |
|
413 CheckNumberOfSoundPropertiesL(KFileName, *importedCard, 2); |
|
414 CleanupStack::PopAndDestroy(importedCard); |
|
415 |
|
416 // Tidy up |
|
417 CleanupStack::PopAndDestroy(parser); |
|
418 } |
|
419 |
|
420 |
|
421 |