First public contribution.
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include "t_win1253.h"
25 const TUint KCharacterSetIdentifier=KCharacterSetIdentifierWin1253;
28 _LIT(KInputUnicodeFilename, "c:\\test\\data\\win1253_uni_input.dat");
29 _LIT(KInputForeignFilename, "c:\\test\\data\\win1253_for_input.dat");
30 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\win1253_uni_expect.dat");
31 _LIT(KExpectForeignFilename, "c:\\test\\data\\win1253_for_expect.dat");
33 _LIT(KInputUnicodeFilename, "z:\\test\\data\\win1253_uni_input.dat");
34 _LIT(KInputForeignFilename, "z:\\test\\data\\win1253_for_input.dat");
35 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\win1253_uni_expect.dat");
36 _LIT(KExpectForeignFilename, "z:\\test\\data\\win1253_for_expect.dat");
41 TBool __bb = (cond); \
45 ERR_PRINTF1(_L("ERROR: Test Failed")); \
50 void CT_WIN1253::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
53 TInt err = file.Open(aFs, aFilename, EFileRead);
54 test(err == KErrNone);
55 CleanupClosePushL(file);
56 err = file.Read(aDes);
57 test(err == KErrNone);
58 CleanupStack::PopAndDestroy(&file);
61 void CT_WIN1253::Merge_Big(TDesC8& aSource, TDes16& aTarget)
63 TInt length = aSource.Length();
65 for(i=0;i<length-1;i++)
67 TInt64 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
73 void CT_WIN1253::DoE32MainL()
75 RFs fileServerSession;
76 CleanupClosePushL(fileServerSession);
77 User::LeaveIfError(fileServerSession.Connect());
78 CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
79 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
80 CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
82 INFO_PRINTF1(_L("Available:\n"));
83 for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
85 const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
86 characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
87 TPtrC charactersSetName(charactersSet.Name());
88 if (charactersSet.NameIsFileName())
90 charactersSetName.Set(TParsePtrC(charactersSetName).Name());
92 INFO_PRINTF2(_L(" %S\n"), &charactersSetName);
95 INFO_PRINTF1(_L("Encoding from Unicode to Foreign"));
96 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession);
98 TBuf16<256> originalUnicode;
99 TBuf8<256> generatedForeign;
100 TBuf16<256> generatedUnicode;
101 ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
102 Merge_Big(temp, originalUnicode);
103 test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
104 ReadDescL(temp, KExpectForeignFilename, fileServerSession);
105 test(generatedForeign == temp);
107 INFO_PRINTF1(_L("Encoding from Foreign to Unicode"));
108 ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
109 TInt state=CCnvCharacterSetConverter::KStateDefault;
110 test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
111 ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
112 originalUnicode.Zero();
113 Merge_Big(temp, originalUnicode);
114 test(generatedUnicode == originalUnicode);
116 CleanupStack::PopAndDestroy(3);
119 CT_WIN1253::CT_WIN1253()
121 SetTestStepName(KTestStep_T_WIN1253);
124 TVerdict CT_WIN1253::doTestStepL()
126 SetTestStepResult(EFail);
129 TRAPD(error1, DoE32MainL());
132 if(error1 == KErrNone)
134 SetTestStepResult(EPass);
137 return TestStepResult();