os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_turkishsingle.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2008-2010 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 #include <e32std.h>
    20 #include <e32base.h>
    21 #include <f32file.h>
    22 #include <charconv.h>
    23 #include "t_turkishsingle.h"
    24 
    25 const TUint KCharacterSetIdentifier=KCharacterSetIdentifierTurkishSingleSms7Bit;
    26 
    27 #ifdef __WINS__
    28 _LIT(KInputUnicodeFilename, "c:\\test\\data\\gsm7_turkish_single_uni_input.dat");
    29 _LIT(KInputForeignFilename, "c:\\test\\data\\gsm7_turkish_single_for_input.dat");
    30 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\gsm7_turkish_single_uni_expect.dat");
    31 _LIT(KExpectForeignFilename, "c:\\test\\data\\gsm7_turkish_single_for_expect.dat");
    32 #else
    33 _LIT(KInputUnicodeFilename, "z:\\test\\data\\gsm7_turkish_single_uni_input.dat");
    34 _LIT(KInputForeignFilename, "z:\\test\\data\\gsm7_turkish_single_for_input.dat");
    35 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\gsm7_turkish_single_uni_expect.dat");
    36 _LIT(KExpectForeignFilename, "z:\\test\\data\\gsm7_turkish_single_for_expect.dat");
    37 #endif
    38 
    39 static CCnvCharacterSetConverter* characterSetConverter;
    40 static RFs fileServerSession;
    41 static TBuf8<974> temp;
    42 static TBuf16<487> originalUnicode;
    43 static TBuf8<487> generatedForeign;
    44 static TBuf16<487> generatedUnicode;
    45 
    46 #define test(cond)                                  \
    47     {                                               \
    48     TBool __bb = (cond);                            \
    49     TEST(__bb);                                     \
    50     if (!__bb)                                      \
    51         {                                           \
    52         ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    53         User::Leave(1);                             \
    54         }                                           \
    55     }
    56 
    57 
    58 void CT_TURKISHSINGLE::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
    59 	{
    60 	RFile file;
    61 	TInt err = file.Open(aFs, aFilename, EFileRead);
    62 	test(err == KErrNone);
    63 	CleanupClosePushL(file);	
    64 	err = file.Read(aDes);
    65 	test(err == KErrNone);
    66 	CleanupStack::PopAndDestroy(&file);
    67 	}
    68 
    69 //translate from unicode big endian TDesC8 to TDes16
    70 void CT_TURKISHSINGLE::Unicode_Big(TDesC8& aSource, TDes16& aTarget)
    71 	{
    72 	TInt length = aSource.Length();
    73 	TInt i = 0;
    74 	for(i=0;i<length-1;i++)
    75 		{
    76 		TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
    77 		aTarget.Append(temp);
    78 		i++;
    79 		}	
    80 	}
    81         
    82 /**
    83 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4009
    84 @SYMTestCaseDesc			Testcase to test new converter name can be listed
    85 @SYMTestPriority			High
    86 @SYMTestActions				Test for CreateArrayOfCharacterSetsAvailableLC() 
    87 @SYMTestExpectedResults		The test passed, if Available character sets are listed in epocwind.out
    88 @SYMPREQ					PREQ22265
    89 @SYMREQ						REQ10670
    90 */
    91 void CT_TURKISHSINGLE::ListAlltheConvertersL()
    92 	{
    93 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
    94 		CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    95 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4009 Available:\n "));
    96 	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
    97 		{
    98 		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
    99 		TPtrC charactersSetName(charactersSet.Name());
   100 		if (charactersSet.NameIsFileName())
   101 			{
   102 			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
   103 			}
   104 		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
   105 		}	
   106 	CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
   107 	}
   108 
   109 /**
   110 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4010
   111 @SYMTestCaseDesc			Testcase to test new converter can be prepared
   112 @SYMTestPriority			High
   113 @SYMTestActions				Test for PrepareToConvertToOrFromL()
   114 @SYMTestExpectedResults		The test passed, If EAvailable is returned
   115 @SYMPREQ					PREQ22265
   116 @SYMREQ						REQ10670
   117 */
   118 void CT_TURKISHSINGLE::PrepareNewConverterL()
   119 	{
   120     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4010 Testing new converter can be prepared "));
   121 	CCnvCharacterSetConverter::TAvailability avaible = 	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, fileServerSession);
   122 	test( CCnvCharacterSetConverter::EAvailable == avaible );
   123 	}
   124 
   125 /**
   126 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4011
   127 @SYMTestCaseDesc			Convert Unicode code to foreign character set
   128 @SYMTestPriority			High
   129 @SYMTestActions				Test for ConvertFromUnicode()
   130 @SYMTestExpectedResults		Test must not fail
   131 @SYMPREQ					PREQ22265
   132 @SYMREQ						REQ10670
   133 */
   134 void CT_TURKISHSINGLE::ConvertFromUnicodeToForeignL()
   135 	{
   136     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4011 Testing encoding from Unicode to Foreign "));
   137 	ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
   138 	Unicode_Big(temp, originalUnicode); 
   139 	test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
   140 	ReadDescL(temp, KExpectForeignFilename, fileServerSession);
   141 	test(generatedForeign == temp);
   142 	}
   143 
   144 /**
   145 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4012
   146 @SYMTestCaseDesc			Convert foreign character set to Unicode code 
   147 @SYMTestPriority			High
   148 @SYMTestActions				Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
   149 @SYMTestExpectedResults		Test must not fail
   150 @SYMPREQ					PREQ22265
   151 @SYMREQ						REQ10670
   152 */
   153 void CT_TURKISHSINGLE::ConvertFromForeignToUnicodeL()
   154 	{
   155     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4012 Testing encoding from Foreign to Unicode "));	
   156 	ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
   157 	TInt state=CCnvCharacterSetConverter::KStateDefault;
   158 	test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   159 	ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
   160 	originalUnicode.Zero();
   161 	Unicode_Big(temp, originalUnicode); 
   162 	test(generatedUnicode == originalUnicode);
   163 	}	
   164 	
   165 /**
   166 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4013
   167 @SYMTestCaseDesc			Convert illegal character from foreign character set to unicode 
   168 @SYMTestPriority			High
   169 @SYMTestActions				Test for ConvertToUnicode() with illegal foreign characters 0x1B
   170 @SYMTestExpectedResults		Test must not fail
   171 @SYMPREQ					PREQ22265
   172 @SYMREQ						REQ10670
   173 */
   174 void CT_TURKISHSINGLE::ConvertIllegalForeignCharacter()
   175 	{
   176 	//test 0x1b
   177     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4013 Testing EErrorIllFormedInput "));	
   178 	generatedForeign.SetLength(1);
   179 	generatedForeign[0] = 0x1b; 		//the escape character
   180 	TInt state=CCnvCharacterSetConverter::KStateDefault;	
   181 	test( -20 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   182 	}
   183 
   184 /**
   185 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4014
   186 @SYMTestCaseDesc			Convert out of range characters from foreign character set to Unicode 
   187 @SYMTestPriority			High
   188 @SYMTestActions				Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
   189 @SYMTestExpectedResults		Test must not fail
   190 @SYMPREQ					PREQ22265
   191 @SYMREQ						REQ10670
   192 */
   193 void CT_TURKISHSINGLE::ConvertOutOfRangeForeignCharacters()
   194 	{
   195 	//test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
   196     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4014 Testing Characters not in the Scope "));	
   197 	generatedForeign.SetLength(1);
   198 	generatedForeign[0] = 0x80;
   199 	TInt state=CCnvCharacterSetConverter::KStateDefault;
   200 	_LIT16(KExpected2, "\xfffd"); 	//the expected foreign
   201 	test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   202 	test( generatedUnicode == KExpected2 );
   203 	}
   204 
   205 void CT_TURKISHSINGLE::DoE32MainL()
   206 	{
   207 	CleanupClosePushL(fileServerSession);
   208 	User::LeaveIfError(fileServerSession.Connect());
   209 	characterSetConverter=CCnvCharacterSetConverter::NewLC();
   210 	
   211 	ListAlltheConvertersL();
   212 	PrepareNewConverterL();
   213 	ConvertFromUnicodeToForeignL();
   214 	ConvertFromForeignToUnicodeL();
   215 	ConvertIllegalForeignCharacter();
   216 	ConvertOutOfRangeForeignCharacters();
   217 	
   218 	CleanupStack::PopAndDestroy(2);
   219 	}
   220 
   221 CT_TURKISHSINGLE::CT_TURKISHSINGLE()
   222     {
   223     SetTestStepName(KTestStep_T_TURKISHSINGLE);
   224     }
   225 
   226 TVerdict CT_TURKISHSINGLE::doTestStepL()
   227     {
   228     SetTestStepResult(EFail);
   229 
   230     __UHEAP_MARK;
   231     TRAPD(error1, DoE32MainL());
   232     __UHEAP_MARKEND;
   233 
   234     if(error1 == KErrNone)
   235         {
   236         SetTestStepResult(EPass);
   237         }
   238 
   239     return TestStepResult();
   240     }