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