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