os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_iso8859x.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2000-2010 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 <f32file.h>
    22 #include <charconv.h>
    23 #include "tiso8859x.h"
    24 #include "t_iso8859x.h"
    25 
    26 #define test(cond)                                  \
    27     {                                               \
    28     TBool __bb = (cond);                            \
    29     TEST(__bb);                                     \
    30     if (!__bb)                                      \
    31         {                                           \
    32         ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    33         User::Leave(1);                             \
    34         }                                           \
    35     }
    36 
    37 
    38 /**
    39 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0541
    40 @SYMTestCaseDesc        Tests for conversion from ISO 8859 to Unicode
    41 @SYMTestPriority        Medium
    42 @SYMTestActions         Tests for a filename and then convert to Unicode from ISO8859X
    43 @SYMTestExpectedResults Test must not fail
    44 @SYMREQ                 REQ0000
    45 */
    46 void CT_ISO8859X::test1L()
    47 	{
    48 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0541 "));
    49 	RFs fileServerSession;
    50 	CleanupClosePushL(fileServerSession);
    51 	User::LeaveIfError(fileServerSession.Connect());
    52 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
    53 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    54 	INFO_PRINTF1(_L("Available:\n"));
    55 	TInt i;
    56 	for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
    57 		{
    58 		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
    59 		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
    60 		TPtrC charactersSetName(charactersSet.Name());
    61 		if (charactersSet.NameIsFileName())
    62 			{
    63 			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
    64 			}
    65 		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
    66 		}
    67 	TInt state=CCnvCharacterSetConverter::KStateDefault;
    68 	for (i=0; i<iso8859TestData.iNumberOfItems; ++i)
    69 		{
    70 		INFO_PRINTF2(_L("Testing ISO 8859-%d"), iso8859TestData.iItems[i].iX);
    71 		characterSetConverter->PrepareToConvertToOrFromL(iso8859TestData.iItems[i].iCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession);
    72 		TPtrC16 originalUnicode(iso8859TestData.iItems[i].iUnicode, iso8859TestData.iItems[i].iTextLength);
    73 		TPtrC8 expectedIso8859(iso8859TestData.iItems[i].iIso8859, iso8859TestData.iItems[i].iTextLength);
    74 		TBuf16<256> generatedUnicode;
    75 		test(characterSetConverter->ConvertToUnicode(generatedUnicode, expectedIso8859, state)==0);
    76 		test(generatedUnicode==originalUnicode);
    77 		TBuf8<256> generatedIso8859;
    78 		test(characterSetConverter->ConvertFromUnicode(generatedIso8859, originalUnicode)==0);
    79 		test(state==CCnvCharacterSetConverter::KStateDefault);
    80 		test(generatedIso8859==expectedIso8859);
    81 		}
    82 	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
    83 	}
    84 
    85 /**
    86 Test code for INC042690 - Bi-directional MIME types are not supported in Charconv
    87 The bi-directional MIME types only indicate how to treat the layout of the mail,
    88 the actual character conversion should be the same as for the exisiting ISO-8859-6/ISO-8859-8 plugins
    89 
    90 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0542
    91 @SYMTestCaseDesc        Tests the Bi-directional MIME
    92 @SYMTestPriority        Medium
    93 @SYMTestActions         Tests for conversions of ISO_8859-6 UID to MIB
    94 @SYMTestExpectedResults Test must not fail
    95 @SYMREQ                 REQ0000
    96 */
    97 void CT_ISO8859X::testInc042690L()
    98 	{
    99 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0542 Test for INC042690 "));
   100 
   101 	RFs fileServerSession;
   102 	CleanupClosePushL(fileServerSession);
   103 	User::LeaveIfError(fileServerSession.Connect());
   104 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
   105 
   106 	// check that the character set value of '81' is converted to the ISO_8859-6 UID (0x10008a29)
   107 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(81,fileServerSession)==KCharacterSetIdentifierIso88596);
   108 	INFO_PRINTF1(_L("\nMIB 81->Char Set ISO_8859-6 UID - OK"));
   109 
   110 	// check that the character set value of '82' is converted to the ISO_8859-6 UID (0x10008a29)
   111 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(82,fileServerSession)==KCharacterSetIdentifierIso88596);
   112 	INFO_PRINTF1(_L("\nMIB 82->Char Set ISO_8859-6 UID - OK"));
   113 
   114 	// check that the character set value of '84' is converted to the ISO_8859-8 UID (0x10008a2a)
   115 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(84,fileServerSession)==KCharacterSetIdentifierIso88598);
   116 	INFO_PRINTF1(_L("\nMIB 84->Char Set ISO_8859-8 UID - OK"));
   117 
   118 	// check that the character set value of '85' is converted to the ISO_8859-8 UID (0x10008a2a)
   119 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(85,fileServerSession)==KCharacterSetIdentifierIso88598);
   120 	INFO_PRINTF1(_L("\nMIB 85->Char Set ISO_8859-8 UID - OK"));
   121 
   122 	// check that the ISO_8859-6 UID (0x10008a29) is converted to the character set value of '9'
   123 	test(characterSetConverter->ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierIso88596,fileServerSession)==9);
   124 	INFO_PRINTF1(_L("\nChar Set ISO_8859-6 UID->MIB - OK"));
   125 
   126 	// check that the ISO_8859-8 UID (0x10008a2a) is converted to the character set value of '11'
   127 	test(characterSetConverter->ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierIso88598,fileServerSession)==11);
   128 	INFO_PRINTF1(_L("\nChar Set ISO_8859-8 UID->MIB - OK"));
   129 
   130 	INFO_PRINTF1(_L("\nTest for INC042690 complete:\n"));
   131 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
   132 	}
   133 /**
   134 Test code for INC043911 - IANAMib 1014 not supported
   135 
   136 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0543
   137 @SYMTestCaseDesc        Tests for CCnvCharacterSetConverter::ConvertMibEnumOfCharacterSetToIdentifierL() function
   138 @SYMTestPriority        Medium
   139 @SYMTestActions         Tests for a conversions of MIB to UTF-16BE UID
   140 @SYMTestExpectedResults Test must not fail
   141 @SYMREQ                 REQ0000
   142 */
   143 void CT_ISO8859X::testInc043911L()
   144 	{
   145 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0543 Test for INC043911 "));
   146 
   147 	RFs fileServerSession;
   148 	CleanupClosePushL(fileServerSession);
   149 	User::LeaveIfError(fileServerSession.Connect());
   150 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
   151 
   152 	// check that the character set value of '1013' is converted to the UTF-16BE UID (0x101f4052)
   153 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1013,fileServerSession)==KCharacterSetIdentifierUnicodeBig);
   154 	INFO_PRINTF1(_L("\nMIB 1013->Char Set UTF-16BE UID - OK"));
   155 
   156 	// check that the character set value of '1014' is converted to the UTF-16LE UID (0x101f3fae)
   157 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1014,fileServerSession)==KCharacterSetIdentifierUnicodeLittle);
   158 	INFO_PRINTF1(_L("\nMIB 1014->Char Set UTF-16LE UID - OK"));
   159 
   160 	// check that the character set value of '1015' is converted to the UTF-16 UID (0x101ff492)
   161 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1015,fileServerSession)==KCharacterSetIdentifierUcs2);
   162 	INFO_PRINTF1(_L("\nMIB 1015->Char Set UTF-16 UID - OK"));
   163 
   164 
   165 	INFO_PRINTF1(_L("\nTest for INC043911 complete:\n"));
   166 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
   167 	}
   168 /**
   169 Test code for DEF050040 - Propagated: Baltic (ISO8859-13) missing in Basic.txt
   170 
   171 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0544
   172 @SYMTestCaseDesc        Tests for defect number DEF050040
   173 @SYMTestPriority        Medium
   174 @SYMTestActions         Tests for CCnvCharacterSetConverter::ConvertMibEnumOfCharacterSetToIdentifierL()
   175                         Tests for a conversions of MIB to ISO-8859-13 UID
   176 @SYMTestExpectedResults Test must not fail
   177 @SYMREQ                 REQ0000
   178 */
   179 void CT_ISO8859X::testDef050040L()
   180 	{
   181 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0544 Test for DEF050040 "));
   182 
   183 	RFs fileServerSession;
   184 	CleanupClosePushL(fileServerSession);
   185 	User::LeaveIfError(fileServerSession.Connect());
   186 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
   187 
   188 	// check that the character set value of '109' is converted to the ISO-8859-13 UID (0x10008a2c)
   189 	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(109,fileServerSession)==KCharacterSetIdentifierIso885913);
   190 	INFO_PRINTF1(_L("\nMIB 109->Char Set ISO-8859-13 UID - OK"));
   191 
   192 	INFO_PRINTF1(_L("\nTest for DEF050040 complete:\n"));
   193 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
   194 	}
   195 /**
   196 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0545
   197 @SYMTestCaseDesc        Tests for conversion of  ISO8859 to Unicode
   198 @SYMTestPriority        Medium
   199 @SYMTestActions         Calls up conversion test functions of ISO8859 to Unicode
   200 @SYMTestExpectedResults Test must not fail
   201 @SYMREQ                 REQ0000
   202 */
   203 void CT_ISO8859X::DoE32MainL()
   204 	{
   205     INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-CHARCONV-CT-0545 Tests for conversion of  ISO8859 to Unicode"));
   206 	test1L();
   207 	testInc042690L();
   208 	testInc043911L();
   209 	testDef050040L();	
   210 	}
   211 
   212 CT_ISO8859X::CT_ISO8859X()
   213     {
   214     SetTestStepName(KTestStep_T_ISO8859X);
   215     }
   216 
   217 TVerdict CT_ISO8859X::doTestStepL()
   218     {
   219     SetTestStepResult(EFail);
   220 
   221     __UHEAP_MARK;
   222     TRAPD(error1, DoE32MainL());    
   223     __UHEAP_MARKEND;
   224 
   225     if(error1 == KErrNone)
   226         {
   227         SetTestStepResult(EPass);
   228         }
   229 
   230     return TestStepResult();
   231     }
   232