1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_win874.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,138 @@
1.4 +/*
1.5 +* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <e32base.h>
1.24 +#include <f32file.h>
1.25 +#include <charconv.h>
1.26 +#include "t_win874.h"
1.27 +
1.28 +const TUint KCharacterSetIdentifier=KCharacterSetIdentifierWin874;
1.29 +
1.30 +#ifdef __WINS__
1.31 +_LIT(KInputUnicodeFilename, "c:\\test\\data\\win874_uni_input.dat");
1.32 +_LIT(KInputForeignFilename, "c:\\test\\data\\win874_for_input.dat");
1.33 +_LIT(KExpectUnicodeFilename, "c:\\test\\data\\win874_uni_expect.dat");
1.34 +_LIT(KExpectForeignFilename, "c:\\test\\data\\win874_for_expect.dat");
1.35 +#else
1.36 +_LIT(KInputUnicodeFilename, "z:\\test\\data\\win874_uni_input.dat");
1.37 +_LIT(KInputForeignFilename, "z:\\test\\data\\win874_for_input.dat");
1.38 +_LIT(KExpectUnicodeFilename, "z:\\test\\data\\win874_uni_expect.dat");
1.39 +_LIT(KExpectForeignFilename, "z:\\test\\data\\win874_for_expect.dat");
1.40 +#endif
1.41 +
1.42 +#define test(cond) \
1.43 + { \
1.44 + TBool __bb = (cond); \
1.45 + TEST(__bb); \
1.46 + if (!__bb) \
1.47 + { \
1.48 + ERR_PRINTF1(_L("ERROR: Test Failed")); \
1.49 + User::Leave(1); \
1.50 + } \
1.51 + }
1.52 +
1.53 +void CT_WIN874::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
1.54 + {
1.55 + RFile file;
1.56 + TInt err = file.Open(aFs, aFilename, EFileRead);
1.57 + test(err == KErrNone);
1.58 + CleanupClosePushL(file);
1.59 + err = file.Read(aDes);
1.60 + test(err == KErrNone);
1.61 + CleanupStack::PopAndDestroy(&file);
1.62 + }
1.63 +
1.64 +void CT_WIN874::Merge_Big(TDesC8& aSource, TDes16& aTarget)
1.65 + {
1.66 + TInt length = aSource.Length();
1.67 + TInt i = 0;
1.68 + for(i=0;i<length-1;i++)
1.69 + {
1.70 + TInt64 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
1.71 + aTarget.Append(temp);
1.72 + i++;
1.73 + }
1.74 + }
1.75 +
1.76 +void CT_WIN874::DoE32MainL()
1.77 + {
1.78 + RFs fileServerSession;
1.79 + CleanupClosePushL(fileServerSession);
1.80 + User::LeaveIfError(fileServerSession.Connect());
1.81 + CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
1.82 + CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
1.83 + CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
1.84 +
1.85 + INFO_PRINTF1(_L("Available:\n"));
1.86 + for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
1.87 + {
1.88 + const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
1.89 + characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
1.90 + TPtrC charactersSetName(charactersSet.Name());
1.91 + if (charactersSet.NameIsFileName())
1.92 + {
1.93 + charactersSetName.Set(TParsePtrC(charactersSetName).Name());
1.94 + }
1.95 + INFO_PRINTF2(_L(" %S\n"), &charactersSetName);
1.96 + }
1.97 +
1.98 + INFO_PRINTF1(_L("Encoding from Unicode to Foreign"));
1.99 + characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession);
1.100 + TBuf8<450> temp;
1.101 + TBuf16<225> originalUnicode;
1.102 + TBuf8<225> generatedForeign;
1.103 + TBuf16<225> generatedUnicode;
1.104 + ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
1.105 + Merge_Big(temp, originalUnicode);
1.106 + test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
1.107 + ReadDescL(temp, KExpectForeignFilename, fileServerSession);
1.108 + test(generatedForeign == temp);
1.109 +
1.110 + INFO_PRINTF1(_L("Encoding from Foreign to Unicode"));
1.111 + ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
1.112 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.113 + test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
1.114 + ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
1.115 + originalUnicode.Zero();
1.116 + Merge_Big(temp, originalUnicode);
1.117 + test(generatedUnicode == originalUnicode);
1.118 +
1.119 + CleanupStack::PopAndDestroy(3);
1.120 + }
1.121 +
1.122 +CT_WIN874::CT_WIN874()
1.123 + {
1.124 + SetTestStepName(KTestStep_T_WIN874);
1.125 + }
1.126 +
1.127 +TVerdict CT_WIN874::doTestStepL()
1.128 + {
1.129 + SetTestStepResult(EFail);
1.130 +
1.131 + __UHEAP_MARK;
1.132 + TRAPD(error1, DoE32MainL());
1.133 + __UHEAP_MARKEND;
1.134 +
1.135 + if(error1 == KErrNone)
1.136 + {
1.137 + SetTestStepResult(EPass);
1.138 + }
1.139 +
1.140 + return TestStepResult();
1.141 + }