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