charconvfw/charconvplugins/test/rtest/tsrc/main/tportuguesegsmsingle.cpp
changeset 51 a7c938434754
parent 44 601ab138ba0b
child 52 23d001107cf3
child 57 01e38b33e72a
equal deleted inserted replaced
44:601ab138ba0b 51:a7c938434754
     1 /*
       
     2 * Copyright (c) 2008-2009 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 <e32test.h>
       
    23 #include <f32file.h>
       
    24 #include <charconv.h>
       
    25 
       
    26 const TUint KCharacterSetIdentifier=KCharacterSetIdentifierPortugueseSingleSms7Bit;
       
    27 
       
    28 #ifdef __WINS__
       
    29 _LIT(KInputUnicodeFilename, "c:\\test\\data\\gsm7_portuguese_single_uni_input.dat");
       
    30 _LIT(KInputForeignFilename, "c:\\test\\data\\gsm7_portuguese_single_for_input.dat");
       
    31 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\gsm7_portuguese_single_uni_expect.dat");
       
    32 _LIT(KExpectForeignFilename, "c:\\test\\data\\gsm7_portuguese_single_for_expect.dat");
       
    33 #else
       
    34 _LIT(KInputUnicodeFilename, "z:\\test\\data\\gsm7_portuguese_single_uni_input.dat");
       
    35 _LIT(KInputForeignFilename, "z:\\test\\data\\gsm7_portuguese_single_for_input.dat");
       
    36 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\gsm7_portuguese_single_uni_expect.dat");
       
    37 _LIT(KExpectForeignFilename, "z:\\test\\data\\gsm7_portuguese_single_for_expect.dat");
       
    38 #endif
       
    39 
       
    40 ///////////////////////////////////////////////////////////////////////////////////////
       
    41 RTest TheTest(_L("TPortugueseGsmSingle"));
       
    42 CCnvCharacterSetConverter* characterSetConverter;
       
    43 RFs fileServerSession;
       
    44 TBuf8<974> temp;
       
    45 TBuf16<487> originalUnicode;
       
    46 TBuf8<487> generatedForeign;
       
    47 TBuf16<487> generatedUnicode;
       
    48 
       
    49 ///////////////////////////////////////////////////////////////////////////////////////
       
    50 //Tests macroses and functions.
       
    51 //If (!aValue) then the test will be panicked, the test data files will be deleted.
       
    52 static void Check(TInt aValue, TInt aLine)
       
    53 	{
       
    54 	if(!aValue)
       
    55 		{
       
    56 		TheTest(EFalse, aLine);
       
    57 		}
       
    58 	}
       
    59 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
       
    60 static void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    61 	{
       
    62 	if(aValue != aExpected)
       
    63 		{
       
    64 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    65 		TheTest(EFalse, aLine);
       
    66 		}
       
    67 	}
       
    68 //Use these to test conditions.
       
    69 #define TEST(arg) ::Check((arg), __LINE__)
       
    70 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    71 
       
    72 static void ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
       
    73 	{
       
    74 	RFile file;
       
    75 	TInt err = file.Open(aFs, aFilename, EFileRead);
       
    76 	TEST2(err, KErrNone);
       
    77 	CleanupClosePushL(file);	
       
    78 	err = file.Read(aDes);
       
    79 	TEST2(err, KErrNone);
       
    80 	CleanupStack::PopAndDestroy(&file);
       
    81 	}
       
    82 
       
    83 //translate from unicode big endian TDesC8 to TDes16
       
    84 static void Unicode_Big(TDesC8& aSource, TDes16& aTarget)
       
    85 	{
       
    86 	TInt length = aSource.Length();
       
    87 	TInt i = 0;
       
    88 	for(i=0;i<length-1;i++)
       
    89 		{
       
    90 		TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
       
    91 		aTarget.Append(temp);
       
    92 		i++;
       
    93 		}	
       
    94 	}
       
    95         
       
    96 /**
       
    97 @SYMTestCaseID				TI18N-CHARCONV-UT-4027
       
    98 @SYMTestCaseDesc			Testcase to test new converter name can be listed
       
    99 @SYMTestPriority			High
       
   100 @SYMTestActions				Test for CreateArrayOfCharacterSetsAvailableLC() 
       
   101 @SYMTestExpectedResults		The test passed, if Available character sets are listed in epocwind.out
       
   102 @SYMPREQ					PREQ 2592
       
   103 @SYMREQ						REQ 12583
       
   104 */
       
   105 void ListAlltheConvertersL()
       
   106 	{
       
   107 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
       
   108 		CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
       
   109 	TheTest.Start(_L(" @SYMTestCaseID:TI18N-CHARCONV-UT-4027 Available:\n "));
       
   110 	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
       
   111 		{
       
   112 		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
       
   113 		TPtrC charactersSetName(charactersSet.Name());
       
   114 		if (charactersSet.NameIsFileName())
       
   115 			{
       
   116 			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
       
   117 			}
       
   118 		TheTest.Printf(_L("    %S\n"), &charactersSetName);
       
   119 		}	
       
   120 	CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
       
   121 	}
       
   122 
       
   123 /**
       
   124 @SYMTestCaseID				TI18N-CHARCONV-UT-4028
       
   125 @SYMTestCaseDesc			Testcase to test new converter can be prepared
       
   126 @SYMTestPriority			High
       
   127 @SYMTestActions				Test for PrepareToConvertToOrFromL()
       
   128 @SYMTestExpectedResults		The test passed, If EAvailable is returned
       
   129 @SYMPREQ					PREQ 2592
       
   130 @SYMREQ						REQ 12583
       
   131 */
       
   132 void PrepareNewConverterL()
       
   133 	{
       
   134 	TheTest.Next(_L(" @SYMTestCaseID:TI18N-CHARCONV-UT-4028 Testing new converter can be prepared "));
       
   135 	CCnvCharacterSetConverter::TAvailability avaible = 	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, fileServerSession);
       
   136 	TEST( CCnvCharacterSetConverter::EAvailable == avaible );
       
   137 	}
       
   138 
       
   139 /**
       
   140 @SYMTestCaseID				TI18N-CHARCONV-UT-4029
       
   141 @SYMTestCaseDesc			Convert Unicode code to foreign character set
       
   142 @SYMTestPriority			High
       
   143 @SYMTestActions				Test for ConvertFromUnicode()
       
   144 @SYMTestExpectedResults		Test must not fail
       
   145 @SYMPREQ					PREQ 2592
       
   146 @SYMREQ						REQ 12583
       
   147 */
       
   148 LOCAL_C void ConvertFromUnicodeToForeignL()
       
   149 	{
       
   150 	TheTest.Next(_L(" @SYMTestCaseID:TI18N-CHARCONV-UT-4029 Testing encoding from Unicode to Foreign "));
       
   151 	ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
       
   152 	Unicode_Big(temp, originalUnicode); 
       
   153 	TEST(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
       
   154 	ReadDescL(temp, KExpectForeignFilename, fileServerSession);
       
   155 	TEST(generatedForeign == temp);
       
   156 	}
       
   157 
       
   158 /**
       
   159 @SYMTestCaseID				TI18N-CHARCONV-UT-4030
       
   160 @SYMTestCaseDesc			Convert foreign character set to Unicode code 
       
   161 @SYMTestPriority			High
       
   162 @SYMTestActions				Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
       
   163 @SYMTestExpectedResults		Test must not fail
       
   164 @SYMPREQ					PREQ 2592
       
   165 @SYMREQ						REQ 12583
       
   166 */
       
   167 LOCAL_C void ConvertFromForeignToUnicodeL()
       
   168 	{
       
   169 	TheTest.Next(_L(" @SYMTestCaseID:TI18N-CHARCONV-UT-4030 Testing encoding from Foreign to Unicode "));	
       
   170 	ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
       
   171 	TInt state=CCnvCharacterSetConverter::KStateDefault;
       
   172 	TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
       
   173 	ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
       
   174 	originalUnicode.Zero();
       
   175 	Unicode_Big(temp, originalUnicode); 
       
   176 	TEST(generatedUnicode == originalUnicode);
       
   177 	}	
       
   178 	
       
   179 /**
       
   180 @SYMTestCaseID				TI18N-CHARCONV-UT-4031
       
   181 @SYMTestCaseDesc			Convert illegal character from foreign character set to unicode 
       
   182 @SYMTestPriority			High
       
   183 @SYMTestActions				Test for ConvertToUnicode() with illegal foreign characters 0x1B
       
   184 @SYMTestExpectedResults		Test must not fail
       
   185 @SYMPREQ					PREQ 2592
       
   186 @SYMREQ						REQ 12583
       
   187 */
       
   188 LOCAL_C void ConvertIllegalForeignCharacter()
       
   189 	{
       
   190 	//test 0x1b
       
   191 	TheTest.Next(_L(" @SYMTestCaseID:TI18N-CHARCONV-UT-4031 Testing EErrorIllFormedInput "));	
       
   192 	generatedForeign.SetLength(1);
       
   193 	generatedForeign[0] = 0x1b; 		//the escape character
       
   194 	TInt state=CCnvCharacterSetConverter::KStateDefault;	
       
   195 	TEST( -20 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
       
   196 	}
       
   197 
       
   198 /**
       
   199 @SYMTestCaseID				TI18N-CHARCONV-UT-4032
       
   200 @SYMTestCaseDesc			Convert out of range characters from foreign character set to Unicode 
       
   201 @SYMTestPriority			High
       
   202 @SYMTestActions				Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
       
   203 @SYMTestExpectedResults		Test must not fail
       
   204 @SYMPREQ					PREQ 2592
       
   205 @SYMREQ						REQ 12583
       
   206 */
       
   207 LOCAL_C void ConvertOutOfRangeForeignCharacters()
       
   208 	{
       
   209 	//test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
       
   210 	TheTest.Next(_L(" @SYMTestCaseID:TI18N-CHARCONV-UT-4032 Testing Characters not in the Scope "));	
       
   211 	generatedForeign.SetLength(1);
       
   212 	generatedForeign[0] = 0x80;
       
   213 	TInt state=CCnvCharacterSetConverter::KStateDefault;
       
   214 	_LIT16(KExpected2, "\xfffd"); 	//the expected foreign
       
   215 	TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
       
   216 	TEST( generatedUnicode == KExpected2 );
       
   217 	}
       
   218 
       
   219 LOCAL_C void DoE32MainL()
       
   220 	{
       
   221 	CleanupClosePushL(fileServerSession);
       
   222 	User::LeaveIfError(fileServerSession.Connect());
       
   223 	characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
   224 	
       
   225 	ListAlltheConvertersL();
       
   226 	PrepareNewConverterL();
       
   227 	ConvertFromUnicodeToForeignL();
       
   228 	ConvertFromForeignToUnicodeL();
       
   229 	ConvertIllegalForeignCharacter();
       
   230 	ConvertOutOfRangeForeignCharacters();
       
   231 	
       
   232 	CleanupStack::PopAndDestroy(2);
       
   233 	}
       
   234 
       
   235 
       
   236 //  Global Functions
       
   237 
       
   238 GLDEF_C TInt E32Main()
       
   239 	{
       
   240 	__UHEAP_MARK;
       
   241 
       
   242 	TheTest.Title();
       
   243 
       
   244 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   245 	TEST(trapCleanup != NULL);
       
   246 
       
   247 	TRAPD(error, DoE32MainL());
       
   248 	TEST2(error, KErrNone);
       
   249 
       
   250 	delete trapCleanup;
       
   251 
       
   252 	TheTest.End();
       
   253 	TheTest.Close();
       
   254 
       
   255 	__UHEAP_MARKEND;
       
   256 	return KErrNone;
       
   257 	}