os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_iso8859x.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_iso8859x.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,232 @@
     1.4 +/*
     1.5 +* Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include <e32base.h>
    1.24 +#include <f32file.h>
    1.25 +#include <charconv.h>
    1.26 +#include "tiso8859x.h"
    1.27 +#include "t_iso8859x.h"
    1.28 +
    1.29 +#define test(cond)                                  \
    1.30 +    {                                               \
    1.31 +    TBool __bb = (cond);                            \
    1.32 +    TEST(__bb);                                     \
    1.33 +    if (!__bb)                                      \
    1.34 +        {                                           \
    1.35 +        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    1.36 +        User::Leave(1);                             \
    1.37 +        }                                           \
    1.38 +    }
    1.39 +
    1.40 +
    1.41 +/**
    1.42 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0541
    1.43 +@SYMTestCaseDesc        Tests for conversion from ISO 8859 to Unicode
    1.44 +@SYMTestPriority        Medium
    1.45 +@SYMTestActions         Tests for a filename and then convert to Unicode from ISO8859X
    1.46 +@SYMTestExpectedResults Test must not fail
    1.47 +@SYMREQ                 REQ0000
    1.48 +*/
    1.49 +void CT_ISO8859X::test1L()
    1.50 +	{
    1.51 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0541 "));
    1.52 +	RFs fileServerSession;
    1.53 +	CleanupClosePushL(fileServerSession);
    1.54 +	User::LeaveIfError(fileServerSession.Connect());
    1.55 +	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
    1.56 +	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    1.57 +	INFO_PRINTF1(_L("Available:\n"));
    1.58 +	TInt i;
    1.59 +	for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
    1.60 +		{
    1.61 +		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
    1.62 +		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
    1.63 +		TPtrC charactersSetName(charactersSet.Name());
    1.64 +		if (charactersSet.NameIsFileName())
    1.65 +			{
    1.66 +			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
    1.67 +			}
    1.68 +		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
    1.69 +		}
    1.70 +	TInt state=CCnvCharacterSetConverter::KStateDefault;
    1.71 +	for (i=0; i<iso8859TestData.iNumberOfItems; ++i)
    1.72 +		{
    1.73 +		INFO_PRINTF2(_L("Testing ISO 8859-%d"), iso8859TestData.iItems[i].iX);
    1.74 +		characterSetConverter->PrepareToConvertToOrFromL(iso8859TestData.iItems[i].iCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession);
    1.75 +		TPtrC16 originalUnicode(iso8859TestData.iItems[i].iUnicode, iso8859TestData.iItems[i].iTextLength);
    1.76 +		TPtrC8 expectedIso8859(iso8859TestData.iItems[i].iIso8859, iso8859TestData.iItems[i].iTextLength);
    1.77 +		TBuf16<256> generatedUnicode;
    1.78 +		test(characterSetConverter->ConvertToUnicode(generatedUnicode, expectedIso8859, state)==0);
    1.79 +		test(generatedUnicode==originalUnicode);
    1.80 +		TBuf8<256> generatedIso8859;
    1.81 +		test(characterSetConverter->ConvertFromUnicode(generatedIso8859, originalUnicode)==0);
    1.82 +		test(state==CCnvCharacterSetConverter::KStateDefault);
    1.83 +		test(generatedIso8859==expectedIso8859);
    1.84 +		}
    1.85 +	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
    1.86 +	}
    1.87 +
    1.88 +/**
    1.89 +Test code for INC042690 - Bi-directional MIME types are not supported in Charconv
    1.90 +The bi-directional MIME types only indicate how to treat the layout of the mail,
    1.91 +the actual character conversion should be the same as for the exisiting ISO-8859-6/ISO-8859-8 plugins
    1.92 +
    1.93 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0542
    1.94 +@SYMTestCaseDesc        Tests the Bi-directional MIME
    1.95 +@SYMTestPriority        Medium
    1.96 +@SYMTestActions         Tests for conversions of ISO_8859-6 UID to MIB
    1.97 +@SYMTestExpectedResults Test must not fail
    1.98 +@SYMREQ                 REQ0000
    1.99 +*/
   1.100 +void CT_ISO8859X::testInc042690L()
   1.101 +	{
   1.102 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0542 Test for INC042690 "));
   1.103 +
   1.104 +	RFs fileServerSession;
   1.105 +	CleanupClosePushL(fileServerSession);
   1.106 +	User::LeaveIfError(fileServerSession.Connect());
   1.107 +	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
   1.108 +
   1.109 +	// check that the character set value of '81' is converted to the ISO_8859-6 UID (0x10008a29)
   1.110 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(81,fileServerSession)==KCharacterSetIdentifierIso88596);
   1.111 +	INFO_PRINTF1(_L("\nMIB 81->Char Set ISO_8859-6 UID - OK"));
   1.112 +
   1.113 +	// check that the character set value of '82' is converted to the ISO_8859-6 UID (0x10008a29)
   1.114 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(82,fileServerSession)==KCharacterSetIdentifierIso88596);
   1.115 +	INFO_PRINTF1(_L("\nMIB 82->Char Set ISO_8859-6 UID - OK"));
   1.116 +
   1.117 +	// check that the character set value of '84' is converted to the ISO_8859-8 UID (0x10008a2a)
   1.118 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(84,fileServerSession)==KCharacterSetIdentifierIso88598);
   1.119 +	INFO_PRINTF1(_L("\nMIB 84->Char Set ISO_8859-8 UID - OK"));
   1.120 +
   1.121 +	// check that the character set value of '85' is converted to the ISO_8859-8 UID (0x10008a2a)
   1.122 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(85,fileServerSession)==KCharacterSetIdentifierIso88598);
   1.123 +	INFO_PRINTF1(_L("\nMIB 85->Char Set ISO_8859-8 UID - OK"));
   1.124 +
   1.125 +	// check that the ISO_8859-6 UID (0x10008a29) is converted to the character set value of '9'
   1.126 +	test(characterSetConverter->ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierIso88596,fileServerSession)==9);
   1.127 +	INFO_PRINTF1(_L("\nChar Set ISO_8859-6 UID->MIB - OK"));
   1.128 +
   1.129 +	// check that the ISO_8859-8 UID (0x10008a2a) is converted to the character set value of '11'
   1.130 +	test(characterSetConverter->ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierIso88598,fileServerSession)==11);
   1.131 +	INFO_PRINTF1(_L("\nChar Set ISO_8859-8 UID->MIB - OK"));
   1.132 +
   1.133 +	INFO_PRINTF1(_L("\nTest for INC042690 complete:\n"));
   1.134 +	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
   1.135 +	}
   1.136 +/**
   1.137 +Test code for INC043911 - IANAMib 1014 not supported
   1.138 +
   1.139 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0543
   1.140 +@SYMTestCaseDesc        Tests for CCnvCharacterSetConverter::ConvertMibEnumOfCharacterSetToIdentifierL() function
   1.141 +@SYMTestPriority        Medium
   1.142 +@SYMTestActions         Tests for a conversions of MIB to UTF-16BE UID
   1.143 +@SYMTestExpectedResults Test must not fail
   1.144 +@SYMREQ                 REQ0000
   1.145 +*/
   1.146 +void CT_ISO8859X::testInc043911L()
   1.147 +	{
   1.148 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0543 Test for INC043911 "));
   1.149 +
   1.150 +	RFs fileServerSession;
   1.151 +	CleanupClosePushL(fileServerSession);
   1.152 +	User::LeaveIfError(fileServerSession.Connect());
   1.153 +	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
   1.154 +
   1.155 +	// check that the character set value of '1013' is converted to the UTF-16BE UID (0x101f4052)
   1.156 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1013,fileServerSession)==KCharacterSetIdentifierUnicodeBig);
   1.157 +	INFO_PRINTF1(_L("\nMIB 1013->Char Set UTF-16BE UID - OK"));
   1.158 +
   1.159 +	// check that the character set value of '1014' is converted to the UTF-16LE UID (0x101f3fae)
   1.160 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1014,fileServerSession)==KCharacterSetIdentifierUnicodeLittle);
   1.161 +	INFO_PRINTF1(_L("\nMIB 1014->Char Set UTF-16LE UID - OK"));
   1.162 +
   1.163 +	// check that the character set value of '1015' is converted to the UTF-16 UID (0x101ff492)
   1.164 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(1015,fileServerSession)==KCharacterSetIdentifierUcs2);
   1.165 +	INFO_PRINTF1(_L("\nMIB 1015->Char Set UTF-16 UID - OK"));
   1.166 +
   1.167 +
   1.168 +	INFO_PRINTF1(_L("\nTest for INC043911 complete:\n"));
   1.169 +	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
   1.170 +	}
   1.171 +/**
   1.172 +Test code for DEF050040 - Propagated: Baltic (ISO8859-13) missing in Basic.txt
   1.173 +
   1.174 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0544
   1.175 +@SYMTestCaseDesc        Tests for defect number DEF050040
   1.176 +@SYMTestPriority        Medium
   1.177 +@SYMTestActions         Tests for CCnvCharacterSetConverter::ConvertMibEnumOfCharacterSetToIdentifierL()
   1.178 +                        Tests for a conversions of MIB to ISO-8859-13 UID
   1.179 +@SYMTestExpectedResults Test must not fail
   1.180 +@SYMREQ                 REQ0000
   1.181 +*/
   1.182 +void CT_ISO8859X::testDef050040L()
   1.183 +	{
   1.184 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0544 Test for DEF050040 "));
   1.185 +
   1.186 +	RFs fileServerSession;
   1.187 +	CleanupClosePushL(fileServerSession);
   1.188 +	User::LeaveIfError(fileServerSession.Connect());
   1.189 +	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
   1.190 +
   1.191 +	// check that the character set value of '109' is converted to the ISO-8859-13 UID (0x10008a2c)
   1.192 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(109,fileServerSession)==KCharacterSetIdentifierIso885913);
   1.193 +	INFO_PRINTF1(_L("\nMIB 109->Char Set ISO-8859-13 UID - OK"));
   1.194 +
   1.195 +	INFO_PRINTF1(_L("\nTest for DEF050040 complete:\n"));
   1.196 +	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
   1.197 +	}
   1.198 +/**
   1.199 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0545
   1.200 +@SYMTestCaseDesc        Tests for conversion of  ISO8859 to Unicode
   1.201 +@SYMTestPriority        Medium
   1.202 +@SYMTestActions         Calls up conversion test functions of ISO8859 to Unicode
   1.203 +@SYMTestExpectedResults Test must not fail
   1.204 +@SYMREQ                 REQ0000
   1.205 +*/
   1.206 +void CT_ISO8859X::DoE32MainL()
   1.207 +	{
   1.208 +    INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-CHARCONV-CT-0545 Tests for conversion of  ISO8859 to Unicode"));
   1.209 +	test1L();
   1.210 +	testInc042690L();
   1.211 +	testInc043911L();
   1.212 +	testDef050040L();	
   1.213 +	}
   1.214 +
   1.215 +CT_ISO8859X::CT_ISO8859X()
   1.216 +    {
   1.217 +    SetTestStepName(KTestStep_T_ISO8859X);
   1.218 +    }
   1.219 +
   1.220 +TVerdict CT_ISO8859X::doTestStepL()
   1.221 +    {
   1.222 +    SetTestStepResult(EFail);
   1.223 +
   1.224 +    __UHEAP_MARK;
   1.225 +    TRAPD(error1, DoE32MainL());    
   1.226 +    __UHEAP_MARKEND;
   1.227 +
   1.228 +    if(error1 == KErrNone)
   1.229 +        {
   1.230 +        SetTestStepResult(EPass);
   1.231 +        }
   1.232 +
   1.233 +    return TestStepResult();
   1.234 +    }
   1.235 +