|
1 // Copyright (c) 2005-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 /** |
|
17 @file |
|
18 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 |
|
22 #include <s32file.h> |
|
23 #include <s32mem.h> |
|
24 |
|
25 #include <conarc.h> |
|
26 #include <concnf.h> |
|
27 #include <conlist.h> |
|
28 #include <bautils.h> |
|
29 #include "TB64CnvStep.h" |
|
30 #include <ecom/ecom.h> |
|
31 #include <u32hal.h> |
|
32 |
|
33 _LIT(KLitOriginalTxtFile, "z:\\resource\\test\\conarc\\release.txt"); |
|
34 _LIT(KLitExpectedEtextFromTxtFile, "z:\\resource\\test\\Conarc\\release.txt.etext"); |
|
35 _LIT(KLitOriginalDocFile, "z:\\resource\\test\\Conarc\\w7allchr.doc"); |
|
36 _LIT(KLitExpectedBase64FromDocFile, "z:\\resource\\test\\Conarc\\w7allchr.doc.b64"); |
|
37 _LIT(KLitExpectedQuotedPrintableFromDocFile, "z:\\resource\\test\\Conarc\\w7allchr.doc.qp"); |
|
38 _LIT(KLitExpectedQuotedPrintableFromDocFileWithoutSplChar, "z:\\resource\\test\\Conarc\\w7allchrwosplchr.doc.qp"); |
|
39 |
|
40 _LIT(KLitDirectoryForGeneratedFiles, "c:\\conarc\\"); |
|
41 _LIT(KLitGeneratedEtextFromTxtFile, "c:\\conarc\\release.txt.etext"); |
|
42 _LIT(KLitGeneratedTxtFileFromEtext, "c:\\conarc\\release.txt.etext.txt"); |
|
43 _LIT(KLitGeneratedBase64FromDocFile, "c:\\conarc\\w7allchr.doc.b64"); |
|
44 _LIT(KLitGeneratedDocFileFromBase64, "c:\\conarc\\w7allchr.doc.b64.doc"); |
|
45 _LIT(KLitGeneratedQuotedPrintableFromDocFile, "c:\\conarc\\w7allchr.doc.qp"); |
|
46 _LIT(KLitGeneratedDocFileFromQuotedPrintable, "c:\\conarc\\w7allchr.doc.qp.doc"); |
|
47 |
|
48 TBool CTB64CnvStep::FilesAreIdenticalL(RFs& aFs, const TDesC& aFile1, const TDesC& aFile2) |
|
49 { // static |
|
50 RFile file1; |
|
51 CleanupClosePushL(file1); |
|
52 User::LeaveIfError(file1.Open(aFs, aFile1, EFileShareReadersOnly|EFileStream|EFileRead)); |
|
53 RFile file2; |
|
54 CleanupClosePushL(file2); |
|
55 User::LeaveIfError(file2.Open(aFs, aFile2, EFileShareReadersOnly|EFileStream|EFileRead)); |
|
56 TBuf8<200> buffer1; |
|
57 TBuf8<200> buffer2; |
|
58 TBool result=EFalse; |
|
59 FOREVER |
|
60 { |
|
61 User::LeaveIfError(file1.Read(buffer1)); |
|
62 User::LeaveIfError(file2.Read(buffer2)); |
|
63 if (buffer1!=buffer2) // catches the case where the buffers' contents are different, and/or where they have different lengths, e.g. where one is empty |
|
64 { |
|
65 result=EFalse; |
|
66 break; |
|
67 } |
|
68 if (buffer1.Length()==0) |
|
69 { |
|
70 __ASSERT_ALWAYS(buffer2.Length()==0, User::Invariant()); |
|
71 result=ETrue; |
|
72 break; |
|
73 } |
|
74 } |
|
75 CleanupStack::PopAndDestroy(2, &file1); |
|
76 return result; |
|
77 } |
|
78 |
|
79 void CTB64CnvStep::ConvertFileL(CCnaConverterList& aList, TUint aConverterUid, const TDesC& aInputFile, const TDesC& aOutputFile) |
|
80 { |
|
81 CConverterBase* const converter=aList.NewConverterL(TUid::Uid(aConverterUid)); |
|
82 TEST(converter!=NULL); |
|
83 CleanupStack::PushL(converter); |
|
84 TEST(converter->Uid().iUid==aConverterUid); |
|
85 TEST(converter->Capabilities()&CConverterBase::EConvertsObjects); |
|
86 RFileReadStream inputStream; |
|
87 CleanupClosePushL(inputStream); |
|
88 RFileWriteStream outputStream; |
|
89 CleanupClosePushL(outputStream); |
|
90 User::LeaveIfError(inputStream.Open(iFs, aInputFile, EFileShareReadersOnly|EFileStream|EFileRead)); |
|
91 User::LeaveIfError(outputStream.Replace(iFs, aOutputFile, EFileShareExclusive|EFileStream|EFileWrite)); |
|
92 converter->ConvertObjectL(inputStream, outputStream); |
|
93 outputStream.CommitL(); |
|
94 CleanupStack::PopAndDestroy(3, converter); |
|
95 } |
|
96 |
|
97 void CTB64CnvStep::DoTextEtextL(CCnaConverterList* aList) |
|
98 { |
|
99 INFO_PRINTF1(_L("Testing Etext\n")); |
|
100 |
|
101 ConvertFileL(*aList, KUidPlainTextToETextConverter, KLitOriginalTxtFile, KLitGeneratedEtextFromTxtFile); |
|
102 INFO_PRINTF1(_L("... testing conversion to Etext\n")); |
|
103 TEST(FilesAreIdenticalL(iFs, KLitGeneratedEtextFromTxtFile, KLitExpectedEtextFromTxtFile)); |
|
104 ConvertFileL(*aList, KUidETextToPlainTextConverter, KLitGeneratedEtextFromTxtFile, KLitGeneratedTxtFileFromEtext); |
|
105 INFO_PRINTF1(_L("... and testing conversion back from Etext (round trip)\n")); |
|
106 TEST(FilesAreIdenticalL(iFs, KLitGeneratedTxtFileFromEtext, KLitOriginalTxtFile)); |
|
107 |
|
108 TEST(BaflUtils::DeleteFile(iFs, KLitGeneratedEtextFromTxtFile)==KErrNone); |
|
109 TEST(BaflUtils::DeleteFile(iFs, KLitGeneratedTxtFileFromEtext)==KErrNone); |
|
110 } |
|
111 |
|
112 void CTB64CnvStep::DoTextEtextWithControlCharsL(CCnaConverterList* aList) |
|
113 { |
|
114 TUid uid={KUidPlainTextToETextConverter}; |
|
115 INFO_PRINTF1(_L("Testing Etext with Control Characters\n")); |
|
116 TBuf8<50> buf=_L8("Testing control characters "); |
|
117 buf.Append('\x000'); |
|
118 TBufC8<20> buf2(_L8("\x006\x007 ah!!!")); |
|
119 buf.Append(buf2); |
|
120 TBuf8<50> out; |
|
121 RDesReadStream read(buf); |
|
122 RDesWriteStream write(out); |
|
123 CConverterBase* conv=aList->NewConverterL(uid); |
|
124 TEST(conv!=NULL); |
|
125 CleanupStack::PushL(conv); |
|
126 TEST(conv->Uid()==uid); |
|
127 TEST(conv->Capabilities()&CConverterBase::EConvertsObjects); |
|
128 conv->ConvertObjectL(read,write); |
|
129 CleanupStack::PopAndDestroy(conv); |
|
130 write.CommitL(); |
|
131 write.Close(); |
|
132 read.Close(); |
|
133 TBuf8<50> resultBuf; |
|
134 read.Open(out); |
|
135 write.Open(resultBuf); |
|
136 uid.iUid=KUidETextToPlainTextConverter; |
|
137 conv=aList->NewConverterL(uid); |
|
138 TEST(conv!=NULL); |
|
139 CleanupStack::PushL(conv); |
|
140 TEST(conv->Uid()==uid); |
|
141 TEST(conv->Capabilities()&CConverterBase::EConvertsObjects); |
|
142 conv->ConvertObjectL(read,write); |
|
143 CleanupStack::PopAndDestroy(conv); |
|
144 write.CommitL(); |
|
145 write.Close(); |
|
146 read.Close(); |
|
147 TEST(buf==resultBuf); |
|
148 } |
|
149 |
|
150 /** |
|
151 @SYMTestCaseID TB64CNVStep-DoTestBase64L |
|
152 |
|
153 @SYMPREQ REQxxx |
|
154 |
|
155 @SYMTestCaseDesc Base 64 Test Converter |
|
156 |
|
157 @SYMTestPriority High |
|
158 |
|
159 @SYMTestStatus Implemented |
|
160 |
|
161 @SYMTestActions Converts a .b64 file to a .doc file, Converts a .doc file to a .b64 file and compares them. |
|
162 Test the following APIs |
|
163 CConverterBase2::ConvertObjectL(RReadStream& aReadStream, RWriteStream& aWriteStream, |
|
164 MConverterUiObserver* aObserver=NULL); |
|
165 CConverterBase2::Capabilities(); |
|
166 CConverterBase2::Uid(); |
|
167 CCnaConverterList::NewConverterL(TUid aUid) |
|
168 |
|
169 @SYMTestExpectedResults Compare is succesful |
|
170 */ |
|
171 |
|
172 void CTB64CnvStep::DoTestBase64L(CCnaConverterList* aList) |
|
173 { |
|
174 INFO_PRINTF1(_L("Testing Base64\n")); |
|
175 ConvertFileL(*aList, KUidConverterToBase64, KLitOriginalDocFile, KLitGeneratedBase64FromDocFile); |
|
176 INFO_PRINTF1(_L("... testing conversion to Base64\n")); |
|
177 TEST(FilesAreIdenticalL(iFs, KLitGeneratedBase64FromDocFile, KLitExpectedBase64FromDocFile)); |
|
178 |
|
179 ConvertFileL(*aList, KUidConverterFromBase64, KLitGeneratedBase64FromDocFile, KLitGeneratedDocFileFromBase64); |
|
180 INFO_PRINTF1(_L("... and testing conversion back from Base64 (round trip)\n")); |
|
181 TEST(FilesAreIdenticalL(iFs, KLitGeneratedDocFileFromBase64, KLitOriginalDocFile)); |
|
182 |
|
183 TEST(BaflUtils::DeleteFile(iFs, KLitGeneratedBase64FromDocFile)==KErrNone); |
|
184 TEST(BaflUtils::DeleteFile(iFs, KLitGeneratedDocFileFromBase64)==KErrNone); |
|
185 |
|
186 } |
|
187 |
|
188 /** |
|
189 @SYMTestCaseID TB64CNVStep-DoTestQPL |
|
190 |
|
191 @SYMPREQ REQxxx |
|
192 |
|
193 @SYMTestCaseDesc Quoted Printable Test Converter |
|
194 |
|
195 @SYMTestPriority High |
|
196 |
|
197 @SYMTestStatus Implemented |
|
198 |
|
199 @SYMTestActions Converts a .qp file to a .doc file, Converts a .qp.doc file to a .qp file and compares them |
|
200 Test the following APIs |
|
201 CConverterBase2::ConvertObjectL(RReadStream& aReadStream, RWriteStream& aWriteStream, |
|
202 MConverterUiObserver* aObserver=NULL); |
|
203 CConverterBase2::Capabilities(); |
|
204 CConverterBase2::Uid(); |
|
205 CCnaConverterList::NewConverterL(TUid aUid) |
|
206 |
|
207 @SYMTestExpectedResults Compare is succesful |
|
208 |
|
209 */ |
|
210 void CTB64CnvStep::DoTestQPL(CCnaConverterList* aList) |
|
211 { |
|
212 INFO_PRINTF1(_L("Testing Quoted-printable\n")); |
|
213 |
|
214 // On ARMV5 platform, this test is automated only with the value 1 (the default value) |
|
215 // of ROM patchable constant 'KEnableAllSplCharForQpCnv'. This does the convertion of all the special |
|
216 // characters into Quoted Printable format. The special characters are not converted if the patch data |
|
217 // value is set to 0 (zero) and it has been tested manually. |
|
218 TInt enableAllSplCharForQpCnv = 1; |
|
219 |
|
220 #ifdef __WINS__ |
|
221 // KEnableAllSplCharForQpCnv is a Rom patchable constant, so patch for emulator builds can be done by |
|
222 // adding "patchdata_conarc_dll_KEnableAllSplCharForQpCnv X" to epoc.ini file. |
|
223 // When X is set to non zero, the conversion is performed for all the special characters. |
|
224 // When X is set to zero, no conversion is performed in case of the special characters. |
|
225 // If this patch data value is not given in epoc.ini file, then this test will be executed with |
|
226 // the value 1 (the default value). |
|
227 |
|
228 TInt valueOfKEnableAllSplCharForQpCnv = 0; |
|
229 if (UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"patchdata_conarc_dll_KEnableAllSplCharForQpCnv",&valueOfKEnableAllSplCharForQpCnv) == KErrNone) |
|
230 { |
|
231 enableAllSplCharForQpCnv = valueOfKEnableAllSplCharForQpCnv; |
|
232 } |
|
233 #endif |
|
234 |
|
235 ConvertFileL(*aList, KUidPlainTextToQuotedPrintableConverter, KLitOriginalDocFile, KLitGeneratedQuotedPrintableFromDocFile); |
|
236 INFO_PRINTF1(_L("... testing conversion to Quoted-printable\n")); |
|
237 |
|
238 if (enableAllSplCharForQpCnv) |
|
239 { |
|
240 TEST(FilesAreIdenticalL(iFs, KLitGeneratedQuotedPrintableFromDocFile, KLitExpectedQuotedPrintableFromDocFile)); |
|
241 } |
|
242 else |
|
243 { |
|
244 TEST(FilesAreIdenticalL(iFs, KLitGeneratedQuotedPrintableFromDocFile, KLitExpectedQuotedPrintableFromDocFileWithoutSplChar)); |
|
245 } |
|
246 |
|
247 ConvertFileL(*aList, KUidQuotedPrintableToPlainTextConverter, KLitGeneratedQuotedPrintableFromDocFile, KLitGeneratedDocFileFromQuotedPrintable); |
|
248 INFO_PRINTF1(_L("... and testing back from Quoted-printable (round trip)\n")); |
|
249 TEST(FilesAreIdenticalL(iFs, KLitGeneratedDocFileFromQuotedPrintable, KLitOriginalDocFile)); |
|
250 |
|
251 TEST(BaflUtils::DeleteFile(iFs, KLitGeneratedQuotedPrintableFromDocFile)==KErrNone); |
|
252 TEST(BaflUtils::DeleteFile(iFs, KLitGeneratedDocFileFromQuotedPrintable)==KErrNone); |
|
253 } |
|
254 |
|
255 void CTB64CnvStep::DoSpecificL(CCnaConverterList* aList) |
|
256 { |
|
257 INFO_PRINTF1(_L("Specific tests")); |
|
258 INFO_PRINTF1(_L("QP conv 123 test")); |
|
259 TBuf8<25> buf = _L8("123"); |
|
260 TBuf8<25> out; |
|
261 RDesReadStream read(buf); |
|
262 RDesWriteStream write(out); |
|
263 TUid uid={KUidPlainTextToQuotedPrintableConverter}; |
|
264 CConverterBase* conv=aList->NewConverterL(uid); |
|
265 TEST(conv!=NULL); |
|
266 conv->ConvertObjectL(read,write); |
|
267 read.Close(); |
|
268 write.CommitL(); |
|
269 write.Close(); |
|
270 TEST(buf==out); |
|
271 delete conv; |
|
272 INFO_PRINTF1(_L("String splitting")); |
|
273 TBuf8<256> buf2 = _L8("00 Xxxxxx Xxxxx\x00d\x00aXxxxx\x00d\x00aXxxxxxxxxxxxxxxxxx XX00 0XX\x00d\x00aUnited Kingdom"); |
|
274 TBuf8<256> out2; |
|
275 read.Open(buf2); |
|
276 write.Open(out2); |
|
277 CConverterBase* conv1=aList->NewConverterL(uid); |
|
278 TEST(conv1!=NULL); |
|
279 conv1->ConvertObjectL(read,write); |
|
280 read.Close(); |
|
281 write.CommitL(); |
|
282 write.Close(); |
|
283 delete conv1; |
|
284 TBuf8<256> return2; |
|
285 read.Open(out2); |
|
286 write.Open(return2); |
|
287 TUid uid2={KUidQuotedPrintableToPlainTextConverter}; |
|
288 CConverterBase* conv2=aList->NewConverterL(uid2); |
|
289 TEST(conv2!=NULL); |
|
290 conv2->ConvertObjectL(read,write); |
|
291 read.Close(); |
|
292 write.CommitL(); |
|
293 write.Close(); |
|
294 delete conv2; |
|
295 TEST(return2.Compare(buf2)==0); |
|
296 } |
|
297 |
|
298 void CTB64CnvStep::DoTestL() |
|
299 { |
|
300 BaflUtils::EnsurePathExistsL(iFs, KLitDirectoryForGeneratedFiles); |
|
301 |
|
302 CCnaConverterList* const list=CCnaConverterList::NewLC(); |
|
303 list->UpdateL(); |
|
304 INFO_PRINTF2(_L("Created converter list (found %d converters)\n"), list->Count()); |
|
305 |
|
306 DoTestBase64L(list); |
|
307 DoTestQPL(list); |
|
308 DoTextEtextL(list); |
|
309 // specific cases test code |
|
310 DoSpecificL(list); |
|
311 DoTextEtextWithControlCharsL(list); |
|
312 |
|
313 CleanupStack::PopAndDestroy(list); |
|
314 INFO_PRINTF1(_L("Destroyed converter list\n")); |
|
315 } |
|
316 |
|
317 |
|
318 CTB64CnvStep::~CTB64CnvStep() |
|
319 /** |
|
320 Destructor |
|
321 */ |
|
322 { |
|
323 } |
|
324 |
|
325 CTB64CnvStep::CTB64CnvStep() |
|
326 /** |
|
327 Constructor |
|
328 */ |
|
329 { |
|
330 // Call base class method to set up the human readable name for logging |
|
331 SetTestStepName(KTB64CnvStep); |
|
332 } |
|
333 |
|
334 TVerdict CTB64CnvStep::doTestStepL() |
|
335 { |
|
336 INFO_PRINTF1(_L("Test Started")); |
|
337 // |
|
338 iFs.Connect(); |
|
339 // |
|
340 __UHEAP_MARK; |
|
341 INFO_PRINTF1(_L("Testing Base64")); |
|
342 TRAPD(r,DoTestL()); |
|
343 TEST(r==KErrNone); |
|
344 |
|
345 REComSession::FinalClose(); |
|
346 |
|
347 __UHEAP_MARKEND; |
|
348 INFO_PRINTF1(_L("Test Finished")); |
|
349 |
|
350 return TestStepResult(); |
|
351 } |
|
352 |
|
353 |
|
354 |
|
355 |