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