charconvfw/Charconv/ongoing/test/source/main/TISO8859X.CPP
changeset 0 1fb32624e06b
child 16 56cd22a7a1cb
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 8859 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 #include "TISO8859X.H"
       
    31 
       
    32 ///////////////////////////////////////////////////////////////////////////////////////
       
    33 
       
    34 RTest TheTest(_L("TISO8859X"));
       
    35 	
       
    36 ///////////////////////////////////////////////////////////////////////////////////////
       
    37 ///////////////////////////////////////////////////////////////////////////////////////
       
    38 //Tests macroses and functions.
       
    39 //If (!aValue) then the test will be panicked, the test data files will be deleted.
       
    40 static void Check(TInt aValue, TInt aLine)
       
    41 	{
       
    42 	if(!aValue)
       
    43 		{
       
    44 		TheTest(EFalse, aLine);
       
    45 		}
       
    46 	}
       
    47 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
       
    48 static void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    49 	{
       
    50 	if(aValue != aExpected)
       
    51 		{
       
    52 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    53 		TheTest(EFalse, aLine);
       
    54 		}
       
    55 	}
       
    56 //Use these to test conditions.
       
    57 #define TEST(arg) ::Check((arg), __LINE__)
       
    58 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    59 
       
    60 ///////////////////////////////////////////////////////////////////////////////////////
       
    61 ///////////////////////////////////////////////////////////////////////////////////////
       
    62 /**
       
    63 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0541
       
    64 @SYMTestCaseDesc        Tests for conversion from ISO 8859 to Unicode
       
    65 @SYMTestPriority        Medium
       
    66 @SYMTestActions         Tests for a filename and then convert to Unicode from ISO8859X
       
    67 @SYMTestExpectedResults Test must not fail
       
    68 @SYMREQ                 REQ0000
       
    69 */
       
    70 LOCAL_C void test1L()
       
    71 	{
       
    72 	RFs fileServerSession;
       
    73 	CleanupClosePushL(fileServerSession);
       
    74 	User::LeaveIfError(fileServerSession.Connect());
       
    75 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
    76 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
       
    77 	TheTest.Printf(_L("Available:\n"));
       
    78 	TInt i;
       
    79 	for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
       
    80 		{
       
    81 		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
       
    82 		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
       
    83 		TPtrC charactersSetName(charactersSet.Name());
       
    84 		if (charactersSet.NameIsFileName())
       
    85 			{
       
    86 			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
       
    87 			}
       
    88 		TheTest.Printf(_L("    %S\n"), &charactersSetName);
       
    89 		}
       
    90 	TInt state=CCnvCharacterSetConverter::KStateDefault;
       
    91 	for (i=0; i<iso8859TestData.iNumberOfItems; ++i)
       
    92 		{
       
    93 		TBuf<50> message;
       
    94 		message.Format(_L("Testing ISO 8859-%d"), iso8859TestData.iItems[i].iX);
       
    95 		if (i==0)
       
    96 			{
       
    97 			TheTest.Start(message);
       
    98 			}
       
    99 		else
       
   100 			{
       
   101 			TheTest.Next(message);
       
   102 			}
       
   103 		characterSetConverter->PrepareToConvertToOrFromL(iso8859TestData.iItems[i].iCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession);
       
   104 		TPtrC16 originalUnicode(iso8859TestData.iItems[i].iUnicode, iso8859TestData.iItems[i].iTextLength);
       
   105 		TPtrC8 expectedIso8859(iso8859TestData.iItems[i].iIso8859, iso8859TestData.iItems[i].iTextLength);
       
   106 		TBuf16<256> generatedUnicode;
       
   107 		TEST(characterSetConverter->ConvertToUnicode(generatedUnicode, expectedIso8859, state)==0);
       
   108 		TEST(generatedUnicode==originalUnicode);
       
   109 		TBuf8<256> generatedIso8859;
       
   110 		TEST(characterSetConverter->ConvertFromUnicode(generatedIso8859, originalUnicode)==0);
       
   111 		TEST(state==CCnvCharacterSetConverter::KStateDefault);
       
   112 		if (i==0)
       
   113 			{
       
   114 			// i=0 means that testing fot ISO88591. This condition is needed as minor change made
       
   115 			// to ISO88591. Now 0x80 convertes to 0x20ac (Euro symbol). When that Euro symbol is 
       
   116 			// tried to be converted back to ISO88591, the result is 0x1A as there is no conversion
       
   117 			// the other way. Hence change it to be 0x80 for the test to pass. 
       
   118 			generatedIso8859[0x80] = 0x80;
       
   119 			}
       
   120 		TEST(generatedIso8859==expectedIso8859);
       
   121 		}
       
   122 	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
       
   123 	}
       
   124 
       
   125 /**
       
   126 Test code for INC042690 - Bi-directional MIME types are not supported in Charconv
       
   127 The bi-directional MIME types only indicate how to treat the layout of the mail, 
       
   128 the actual character conversion should be the same as for the exisiting ISO-8859-6/ISO-8859-8 plugins
       
   129 
       
   130 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0542
       
   131 @SYMTestCaseDesc        Tests the Bi-directional MIME  
       
   132 @SYMTestPriority        Medium
       
   133 @SYMTestActions         Tests for conversions of ISO_8859-6 UID to MIB
       
   134 @SYMTestExpectedResults Test must not fail
       
   135 @SYMREQ                 REQ0000
       
   136 */
       
   137 LOCAL_C void testInc042690L()
       
   138 	{
       
   139 	TheTest.Next(_L("Test for INC042690"));
       
   140 	
       
   141 	RFs fileServerSession;
       
   142 	CleanupClosePushL(fileServerSession);
       
   143 	User::LeaveIfError(fileServerSession.Connect());
       
   144 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
   145 
       
   146 	// check that the character set value of '81' is converted to the ISO_8859-6 UID (0x10008a29)
       
   147 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(81,fileServerSession)==KCharacterSetIdentifierIso88596);
       
   148 	TheTest.Printf(_L("\nMIB 81->Char Set ISO_8859-6 UID - OK"));
       
   149 
       
   150 	// check that the character set value of '82' is converted to the ISO_8859-6 UID (0x10008a29)
       
   151 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(82,fileServerSession)==KCharacterSetIdentifierIso88596);
       
   152 	TheTest.Printf(_L("\nMIB 82->Char Set ISO_8859-6 UID - OK"));
       
   153 
       
   154 	// check that the character set value of '84' is converted to the ISO_8859-8 UID (0x10008a2a)
       
   155 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(84,fileServerSession)==KCharacterSetIdentifierIso88598);
       
   156 	TheTest.Printf(_L("\nMIB 84->Char Set ISO_8859-8 UID - OK"));
       
   157 
       
   158 	// check that the character set value of '85' is converted to the ISO_8859-8 UID (0x10008a2a)
       
   159 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(85,fileServerSession)==KCharacterSetIdentifierIso88598);
       
   160 	TheTest.Printf(_L("\nMIB 85->Char Set ISO_8859-8 UID - OK"));
       
   161 
       
   162 	// check that the ISO_8859-6 UID (0x10008a29) is converted to the character set value of '9'
       
   163 	TEST(characterSetConverter->ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierIso88596,fileServerSession)==9);
       
   164 	TheTest.Printf(_L("\nChar Set ISO_8859-6 UID->MIB - OK"));
       
   165 	
       
   166 	// check that the ISO_8859-8 UID (0x10008a2a) is converted to the character set value of '11'
       
   167 	TEST(characterSetConverter->ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierIso88598,fileServerSession)==11);
       
   168 	TheTest.Printf(_L("\nChar Set ISO_8859-8 UID->MIB - OK"));
       
   169 
       
   170 	TheTest.Printf(_L("\nTest for INC042690 complete:\n"));
       
   171 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
       
   172 	}
       
   173 /**
       
   174 Test code for INC043911 - IANAMib 1014 not supported
       
   175 
       
   176 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0543
       
   177 @SYMTestCaseDesc        Tests for CCnvCharacterSetConverter::ConvertMibEnumOfCharacterSetToIdentifierL() function  
       
   178 @SYMTestPriority        Medium
       
   179 @SYMTestActions         Tests for a conversions of MIB to UTF-16BE UID 
       
   180 @SYMTestExpectedResults Test must not fail
       
   181 @SYMREQ                 REQ0000
       
   182 */
       
   183 LOCAL_C void testInc043911L()
       
   184 	{
       
   185 	TheTest.Next(_L("Test for INC043911"));
       
   186 	
       
   187 	RFs fileServerSession;
       
   188 	CleanupClosePushL(fileServerSession);
       
   189 	User::LeaveIfError(fileServerSession.Connect());
       
   190 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
   191 
       
   192 	// check that the character set value of '1013' is converted to the UTF-16BE UID (0x101f4052)
       
   193 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1013,fileServerSession)==KCharacterSetIdentifierUnicodeBig);
       
   194 	TheTest.Printf(_L("\nMIB 1013->Char Set UTF-16BE UID - OK"));
       
   195 
       
   196 	// check that the character set value of '1014' is converted to the UTF-16LE UID (0x101f3fae)
       
   197 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1014,fileServerSession)==KCharacterSetIdentifierUnicodeLittle);
       
   198 	TheTest.Printf(_L("\nMIB 1014->Char Set UTF-16LE UID - OK"));
       
   199 
       
   200 	// check that the character set value of '1015' is converted to the UTF-16 UID (0x101ff492)
       
   201 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1015,fileServerSession)==KCharacterSetIdentifierUcs2);
       
   202 	TheTest.Printf(_L("\nMIB 1015->Char Set UTF-16 UID - OK"));
       
   203 
       
   204 
       
   205 	TheTest.Printf(_L("\nTest for INC043911 complete:\n"));
       
   206 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
       
   207 	}
       
   208 /**
       
   209 Test code for DEF050040 - Propagated: Baltic (ISO8859-13) missing in Basic.txt 
       
   210 
       
   211 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0544
       
   212 @SYMTestCaseDesc        Tests for defect number DEF050040
       
   213 @SYMTestPriority        Medium
       
   214 @SYMTestActions         Tests for CCnvCharacterSetConverter::ConvertMibEnumOfCharacterSetToIdentifierL()  
       
   215                         Tests for a conversions of MIB to ISO-8859-13 UID 
       
   216 @SYMTestExpectedResults Test must not fail
       
   217 @SYMREQ                 REQ0000
       
   218 */
       
   219 LOCAL_C void testDef050040L()
       
   220 	{
       
   221 	TheTest.Next(_L("Test for DEF050040"));
       
   222 	
       
   223 	RFs fileServerSession;
       
   224 	CleanupClosePushL(fileServerSession);
       
   225 	User::LeaveIfError(fileServerSession.Connect());
       
   226 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
   227 
       
   228 	// check that the character set value of '109' is converted to the ISO-8859-13 UID (0x10008a2c)
       
   229 	TEST(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(109,fileServerSession)==KCharacterSetIdentifierIso885913);
       
   230 	TheTest.Printf(_L("\nMIB 109->Char Set ISO-8859-13 UID - OK"));
       
   231 
       
   232 	TheTest.Printf(_L("\nTest for DEF050040 complete:\n"));
       
   233 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
       
   234 	}
       
   235 /**
       
   236 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0545
       
   237 @SYMTestCaseDesc        Tests for conversion of  ISO8859 to Unicode 
       
   238 @SYMTestPriority        Medium
       
   239 @SYMTestActions         Calls up conversion test functions of ISO8859 to Unicode
       
   240 @SYMTestExpectedResults Test must not fail
       
   241 @SYMREQ                 REQ0000
       
   242 */
       
   243 LOCAL_C void DoE32MainL()
       
   244 	{
       
   245 	test1L();
       
   246 	testInc042690L();
       
   247 	testInc043911L();
       
   248 	testDef050040L();
       
   249 	}
       
   250 	
       
   251 GLDEF_C TInt E32Main()
       
   252 	{
       
   253 	__UHEAP_MARK;
       
   254 
       
   255 	TheTest.Title();
       
   256 
       
   257 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   258 	TEST(trapCleanup != NULL);
       
   259 
       
   260 	TRAPD(error, DoE32MainL());
       
   261 	TEST2(error, KErrNone);
       
   262 
       
   263 	delete trapCleanup;
       
   264 
       
   265 	TheTest.End();
       
   266 	TheTest.Close();
       
   267 
       
   268 	__UHEAP_MARKEND;
       
   269 	return KErrNone;
       
   270 	}
       
   271