charconvfw/Charconv/ongoing/test/source/main/tturkishlockingsingle.cpp
changeset 32 8b9155204a54
equal deleted inserted replaced
31:b9ad20498fb4 32:8b9155204a54
       
     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 the License "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=KCharacterSetIdentifierTurkishLockingAndSingleSms7Bit;
       
    32 
       
    33 #ifdef __WINS__
       
    34 _LIT(KInputUnicodeFilename, "c:\\test\\data\\turkish_locking_single_uni_input.dat");
       
    35 _LIT(KInputForeignFilename, "c:\\test\\data\\turkish_locking_single_for_input.dat");
       
    36 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\turkish_locking_single_uni_expect.dat");
       
    37 _LIT(KExpectForeignFilename, "c:\\test\\data\\turkish_locking_single_for_expect.dat");
       
    38 #else
       
    39 _LIT(KInputUnicodeFilename, "z:\\test\\data\\turkish_locking_single_uni_input.dat");
       
    40 _LIT(KInputForeignFilename, "z:\\test\\data\\turkish_locking_single_for_input.dat");
       
    41 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\turkish_locking_single_uni_expect.dat");
       
    42 _LIT(KExpectForeignFilename, "z:\\test\\data\\turkish_locking_single_for_expect.dat");
       
    43 #endif
       
    44 
       
    45 ///////////////////////////////////////////////////////////////////////////////////////
       
    46 RTest TheTest(_L("TTurkishLockingSingle"));
       
    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 /**
       
   105 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4021
       
   106 @SYMTestCaseDesc			Testcase to test new converter name can be listed
       
   107 @SYMTestPriority			High
       
   108 @SYMTestActions				Test for CreateArrayOfCharacterSetsAvailableLC() 
       
   109 @SYMTestExpectedResults		The test passed, if Available character sets are listed in epocwind.out
       
   110 @SYMPREQ					PREQ22265
       
   111 @SYMREQ						REQ10670
       
   112 */
       
   113 void ListAlltheConvertersL()
       
   114 	{
       
   115 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
       
   116 		CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
       
   117 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4021 Available:\n "));
       
   118 	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
       
   119 		{
       
   120 		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
       
   121 		TPtrC charactersSetName(charactersSet.Name());
       
   122 		if (charactersSet.NameIsFileName())
       
   123 			{
       
   124 			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
       
   125 			}
       
   126 		TheTest.Printf(_L("    %S\n"), &charactersSetName);
       
   127 		}	
       
   128 	CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
       
   129 	}
       
   130 
       
   131 /**
       
   132 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4022
       
   133 @SYMTestCaseDesc			Testcase to test new converter can be prepared
       
   134 @SYMTestPriority			High
       
   135 @SYMTestActions				Test for PrepareToConvertToOrFromL()
       
   136 @SYMTestExpectedResults		The test passed, If EAvailable is returned
       
   137 @SYMPREQ					PREQ22265
       
   138 @SYMREQ						REQ10670
       
   139 */
       
   140 void PrepareNewConverterL()
       
   141 	{
       
   142 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4022 Testing new converter can be prepared "));
       
   143 	CCnvCharacterSetConverter::TAvailability avaible = 	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, fileServerSession);
       
   144 	TEST( CCnvCharacterSetConverter::EAvailable == avaible );
       
   145 	}
       
   146 
       
   147 /**
       
   148 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4023
       
   149 @SYMTestCaseDesc			Convert Unicode code to foreign character set
       
   150 @SYMTestPriority			High
       
   151 @SYMTestActions				Test for ConvertFromUnicode()
       
   152 @SYMTestExpectedResults		Test must not fail
       
   153 @SYMPREQ					PREQ22265
       
   154 @SYMREQ						REQ10670
       
   155 */
       
   156 LOCAL_C void ConvertFromUnicodeToForeignL()
       
   157 	{
       
   158 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4023 Testing encoding from Unicode to Foreign "));
       
   159 	ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
       
   160 	Unicode_Big(temp, originalUnicode); 
       
   161 	TEST(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
       
   162 	ReadDescL(temp, KExpectForeignFilename, fileServerSession);
       
   163 	TEST(generatedForeign == temp);
       
   164 	}
       
   165 
       
   166 /**
       
   167 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4024
       
   168 @SYMTestCaseDesc			Convert foreign character set to Unicode code 
       
   169 @SYMTestPriority			High
       
   170 @SYMTestActions				Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
       
   171 @SYMTestExpectedResults		Test must not fail
       
   172 @SYMPREQ					PREQ22265
       
   173 @SYMREQ						REQ10670
       
   174 */
       
   175 LOCAL_C void ConvertFromForeignToUnicodeL()
       
   176 	{
       
   177 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4024 Testing encoding from Foreign to Unicode "));	
       
   178 	ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
       
   179 	TInt state=CCnvCharacterSetConverter::KStateDefault;
       
   180 	TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
       
   181 	ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
       
   182 	originalUnicode.Zero();
       
   183 	Unicode_Big(temp, originalUnicode); 
       
   184 	TEST(generatedUnicode == originalUnicode);
       
   185 	}	
       
   186 	
       
   187 /**
       
   188 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4025
       
   189 @SYMTestCaseDesc			Convert illegal character from foreign character set to unicode 
       
   190 @SYMTestPriority			High
       
   191 @SYMTestActions				Test for ConvertToUnicode() with illegal foreign characters 0x1B
       
   192 @SYMTestExpectedResults		Test must not fail
       
   193 @SYMPREQ					PREQ22265
       
   194 @SYMREQ						REQ10670
       
   195 */
       
   196 LOCAL_C void ConvertIllegalForeignCharacter()
       
   197 	{
       
   198 	//test 0x1b
       
   199 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4025 Testing EErrorIllFormedInput "));
       
   200 	generatedForeign.SetLength(1);
       
   201 	generatedForeign[0] = 0x1b; 		//the escape character
       
   202 	TInt state=CCnvCharacterSetConverter::KStateDefault;	
       
   203 	TEST( -20 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
       
   204 	}
       
   205 
       
   206 /**
       
   207 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4026
       
   208 @SYMTestCaseDesc			Convert out of range characters from foreign character set to Unicode 
       
   209 @SYMTestPriority			High
       
   210 @SYMTestActions				Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
       
   211 @SYMTestExpectedResults		Test must not fail
       
   212 @SYMPREQ					PREQ22265
       
   213 @SYMREQ						REQ10670
       
   214 */
       
   215 LOCAL_C void ConvertOutOfRangeForeignCharacters()
       
   216 	{
       
   217 	//test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
       
   218 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4026 Testing Characters not in the Scope "));	
       
   219 	generatedForeign.SetLength(1);
       
   220 	generatedForeign[0] = 0x80;
       
   221 	TInt state=CCnvCharacterSetConverter::KStateDefault;
       
   222 	_LIT16(KExpected2, "\xfffd"); 	//the expected foreign
       
   223 	TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
       
   224 	TEST( generatedUnicode == KExpected2 );
       
   225 	}
       
   226 
       
   227 LOCAL_C void DoE32MainL()
       
   228 	{
       
   229 	CleanupClosePushL(fileServerSession);
       
   230 	User::LeaveIfError(fileServerSession.Connect());
       
   231 	characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
   232 	
       
   233 	ListAlltheConvertersL();
       
   234 	PrepareNewConverterL();
       
   235 	ConvertFromUnicodeToForeignL();
       
   236 	ConvertFromForeignToUnicodeL();
       
   237 	ConvertIllegalForeignCharacter();
       
   238 	ConvertOutOfRangeForeignCharacters();
       
   239 	
       
   240 	CleanupStack::PopAndDestroy(2);
       
   241 	}
       
   242 
       
   243 
       
   244 //  Global Functions
       
   245 
       
   246 GLDEF_C TInt E32Main()
       
   247 	{
       
   248 	__UHEAP_MARK;
       
   249 
       
   250 	TheTest.Title();
       
   251 
       
   252 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   253 	TEST(trapCleanup != NULL);
       
   254 
       
   255 	TRAPD(error, DoE32MainL());
       
   256 	TEST2(error, KErrNone);
       
   257 
       
   258 	delete trapCleanup;
       
   259 
       
   260 	TheTest.End();
       
   261 	TheTest.Close();
       
   262 
       
   263 	__UHEAP_MARKEND;
       
   264 	return KErrNone;
       
   265 	}