os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_shiftjisdirectmap.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.
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
#include <e32std.h>
sl@0
    19
#include <e32base.h>
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <charconv.h>
sl@0
    22
#include "t_shiftjisdirectmap.h"
sl@0
    23
sl@0
    24
#define test(cond)                                  \
sl@0
    25
    {                                               \
sl@0
    26
    TBool __bb = (cond);                            \
sl@0
    27
    TEST(__bb);                                     \
sl@0
    28
    if (!__bb)                                      \
sl@0
    29
        {                                           \
sl@0
    30
        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
sl@0
    31
        User::Leave(1);                             \
sl@0
    32
        }                                           \
sl@0
    33
    }
sl@0
    34
sl@0
    35
sl@0
    36
const TInt KBufferLength=100;
sl@0
    37
sl@0
    38
void CT_SHIFTJISDIRECTMAP::TestTruncatedConversionFromUnicodeToShiftJisDirectmap(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode)
sl@0
    39
	{
sl@0
    40
	for (TInt i=aOriginalUnicode.Length(); i>=0; --i)
sl@0
    41
		{
sl@0
    42
		TBuf8<KBufferLength> generatedShiftJisDirectmap;
sl@0
    43
		const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedShiftJisDirectmap, aOriginalUnicode.Left(i));
sl@0
    44
		test(returnValue>=0);
sl@0
    45
		TBuf8<KBufferLength> generatedsecondPartOfShiftJisDirectmap;
sl@0
    46
		test(aCharacterSetConverter.ConvertFromUnicode(generatedsecondPartOfShiftJisDirectmap, aOriginalUnicode.Mid(i-returnValue))==0);
sl@0
    47
		generatedShiftJisDirectmap.Append(generatedsecondPartOfShiftJisDirectmap);
sl@0
    48
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
    49
		TBuf16<KBufferLength> generatedUnicode;
sl@0
    50
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedShiftJisDirectmap, state)==0);
sl@0
    51
		test(generatedUnicode==aOriginalUnicode);
sl@0
    52
		}
sl@0
    53
	}
sl@0
    54
sl@0
    55
void CT_SHIFTJISDIRECTMAP::TestSplittingConvertingFromUnicodeToShiftJisDirectmap(CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfShiftJisDirectmap, const TDesC8& aExpectedShiftJisDirectmap, const TDesC16& aOriginalUnicode)
sl@0
    56
	{
sl@0
    57
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
sl@0
    58
	test(aMaximumLengthUpperLimit<=KBufferLength);
sl@0
    59
	TUint8 shiftJisDirectmapBuffer[KBufferLength];
sl@0
    60
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
sl@0
    61
		{
sl@0
    62
		TPtr8 generatedFirstPartOfShiftJisDirectmap(shiftJisDirectmapBuffer, i);
sl@0
    63
		test(aCharacterSetConverter.ConvertFromUnicode(generatedFirstPartOfShiftJisDirectmap, aOriginalUnicode)==aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit);
sl@0
    64
		test(generatedFirstPartOfShiftJisDirectmap==aExpectedShiftJisDirectmap.Left(aExpectedLengthOfFirstPartOfShiftJisDirectmap));
sl@0
    65
		TBuf8<KBufferLength> generatedSecondPartOfShiftJisDirectmap;
sl@0
    66
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfShiftJisDirectmap, aOriginalUnicode.Right(aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit))==0);
sl@0
    67
		test(generatedSecondPartOfShiftJisDirectmap==aExpectedShiftJisDirectmap.Mid(aExpectedLengthOfFirstPartOfShiftJisDirectmap));
sl@0
    68
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
    69
		TBuf16<KBufferLength> generatedUnicode;
sl@0
    70
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedFirstPartOfShiftJisDirectmap, state)==0);
sl@0
    71
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
    72
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
sl@0
    73
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, generatedSecondPartOfShiftJisDirectmap, state)==0);
sl@0
    74
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
    75
		generatedUnicode.Append(generatedSecondPartOfUnicode);
sl@0
    76
		test(generatedUnicode==aOriginalUnicode);
sl@0
    77
		}
sl@0
    78
	}
sl@0
    79
sl@0
    80
void CT_SHIFTJISDIRECTMAP::TestTruncatedConversionToUnicodeFromShiftJisDirectmap(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalShiftJisDirectmap)
sl@0
    81
	{
sl@0
    82
	for (TInt i=aOriginalShiftJisDirectmap.Length(); i>=3; --i)
sl@0
    83
		{
sl@0
    84
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
    85
		TBuf16<KBufferLength> generatedUnicode;
sl@0
    86
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalShiftJisDirectmap.Left(i), state);
sl@0
    87
		test(returnValue>=0);
sl@0
    88
		TBuf16<KBufferLength> generatedsecondPartOfUnicode;
sl@0
    89
		test(aCharacterSetConverter.ConvertToUnicode(generatedsecondPartOfUnicode, aOriginalShiftJisDirectmap.Mid(i-returnValue), state)==0);
sl@0
    90
		generatedUnicode.Append(generatedsecondPartOfUnicode);
sl@0
    91
		test(generatedUnicode==aExpectedUnicode);
sl@0
    92
		}
sl@0
    93
	}
sl@0
    94
sl@0
    95
void CT_SHIFTJISDIRECTMAP::TestSplittingConvertingToUnicodeFromShiftJisDirectmap(CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfShiftJisDirectmapBytesNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfUnicode, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalShiftJisDirectmap)
sl@0
    96
	{
sl@0
    97
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
sl@0
    98
	test(aMaximumLengthUpperLimit<=KBufferLength);
sl@0
    99
	TUint16 unicodeBuffer[KBufferLength];
sl@0
   100
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
sl@0
   101
		{
sl@0
   102
		TPtr16 generatedFirstPartOfUnicode(unicodeBuffer, i);
sl@0
   103
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
   104
		test(aCharacterSetConverter.ConvertToUnicode(generatedFirstPartOfUnicode, aOriginalShiftJisDirectmap, state)==aExpectedNumberOfShiftJisDirectmapBytesNotConvertedAtSplit);
sl@0
   105
		test(generatedFirstPartOfUnicode==aExpectedUnicode.Left(aExpectedLengthOfFirstPartOfUnicode));
sl@0
   106
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
   107
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
sl@0
   108
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, aOriginalShiftJisDirectmap.Right(aExpectedNumberOfShiftJisDirectmapBytesNotConvertedAtSplit), state)==0);
sl@0
   109
		test(generatedSecondPartOfUnicode==aExpectedUnicode.Mid(aExpectedLengthOfFirstPartOfUnicode));
sl@0
   110
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
   111
		TBuf8<KBufferLength> generatedShiftJisDirectmap;
sl@0
   112
		test(aCharacterSetConverter.ConvertFromUnicode(generatedShiftJisDirectmap, generatedFirstPartOfUnicode)==0);
sl@0
   113
		TBuf8<KBufferLength> generatedSecondPartOfShiftJisDirectmap;
sl@0
   114
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfShiftJisDirectmap, generatedSecondPartOfUnicode)==0);
sl@0
   115
		generatedShiftJisDirectmap.Append(generatedSecondPartOfShiftJisDirectmap);
sl@0
   116
		test(generatedShiftJisDirectmap==aOriginalShiftJisDirectmap);
sl@0
   117
		}
sl@0
   118
	}
sl@0
   119
sl@0
   120
void CT_SHIFTJISDIRECTMAP::DoE32MainL()
sl@0
   121
	{
sl@0
   122
	RFs fileServerSession;
sl@0
   123
	CleanupClosePushL(fileServerSession);
sl@0
   124
	User::LeaveIfError(fileServerSession.Connect());
sl@0
   125
	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
sl@0
   126
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
sl@0
   127
	INFO_PRINTF1(_L("Available:\n"));
sl@0
   128
	TInt i;
sl@0
   129
	for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
sl@0
   130
		{
sl@0
   131
		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
sl@0
   132
		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
sl@0
   133
		TPtrC charactersSetName(charactersSet.Name());
sl@0
   134
		if (charactersSet.NameIsFileName())
sl@0
   135
			{
sl@0
   136
			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
sl@0
   137
			}
sl@0
   138
		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
sl@0
   139
		}
sl@0
   140
	INFO_PRINTF1(_L("Testing ShiftJis (DirectMap) conversions "));
sl@0
   141
	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierShiftJisDirectmap, *arrayOfCharacterSetsAvailable, fileServerSession);
sl@0
   142
	//
sl@0
   143
	INFO_PRINTF1(_L("Empty descriptor"));
sl@0
   144
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 0, 10, 0, 0, KNullDesC8, KNullDesC16);
sl@0
   145
	TestSplittingConvertingToUnicodeFromShiftJisDirectmap(*characterSetConverter, 0, 10, 0, 0, KNullDesC16, KNullDesC8);
sl@0
   146
	
sl@0
   147
	INFO_PRINTF1(_L("Testing converting to ShiftJis (DirectMap)"));
sl@0
   148
	TBuf16<50> originalUnicode;
sl@0
   149
	originalUnicode.Format(_L16("Some %c%c%c%c"), 0xff9a, 0xff70, 0x6f22, 0x5b57);
sl@0
   150
	const TPtrC8 expectedShiftJisDirectmap(_S8("Some \xda\xb0\x8a\xbf\x8e\x9a"));
sl@0
   151
	TestTruncatedConversionFromUnicodeToShiftJisDirectmap(*characterSetConverter, originalUnicode);
sl@0
   152
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 0, 0, 9, 0, expectedShiftJisDirectmap, originalUnicode);
sl@0
   153
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 1, 1, 8, 1, expectedShiftJisDirectmap, originalUnicode);
sl@0
   154
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 2, 2, 7, 2, expectedShiftJisDirectmap, originalUnicode);
sl@0
   155
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 3, 3, 6, 3, expectedShiftJisDirectmap, originalUnicode);
sl@0
   156
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 4, 4, 5, 4, expectedShiftJisDirectmap, originalUnicode);
sl@0
   157
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 5, 5, 4, 5, expectedShiftJisDirectmap, originalUnicode);
sl@0
   158
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 6, 6, 3, 6, expectedShiftJisDirectmap, originalUnicode);
sl@0
   159
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 7, 7, 2, 7, expectedShiftJisDirectmap, originalUnicode);
sl@0
   160
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 9, 9, 1, 9, expectedShiftJisDirectmap, originalUnicode);
sl@0
   161
	TestSplittingConvertingFromUnicodeToShiftJisDirectmap(*characterSetConverter, 11, 11, 0, 11, expectedShiftJisDirectmap, originalUnicode);
sl@0
   162
	
sl@0
   163
	INFO_PRINTF1(_L("Testing converting to Unicode"));
sl@0
   164
	const TPtrC8 originalShiftJisDirectmap(_S8("pool\xbe\xae\xc3\xd3\x8e\xcc\x8e\xdf\x8e\xd9\x8f\xc0\xcd\x8f\xc8\xc5pool\x8e\xcc\x8e\xdf\x8e\xd9\xbe\xae\xc3\xd3\x8f\xc0\xcd\x8f\xc8\xc5\xbe\xae\xc3\xd3pool\x8f\xc0\xcd\x8f\xc8\xc5\x8e\xcc\x8e\xdf\x8e\xd9pool"));
sl@0
   165
	TBuf16<50> expectedUnicode;
sl@0
   166
	expectedUnicode.Format(_L16("pool%c%c%c%c%c%c%c%c%c%c%cpool%c%c%c%c%c%c%c%c%c%c%c%c%c%c%cpool%c%c%c%c%c%c%cpool"), 0xFF7E, 0xFF6E, 0xFF83, 0xFF93, 0x6368, 0x91C8, 0x52FA, 0x6CBC, 0xFF8D, 0x7701, 0xFF85, 0x6368, 0x91C8, 0x52FA, 0xFF7E, 0xFF6E, 0xFF83, 0xFF93, 0x6CBC, 0xFF8D, 0x7701, 0xFF85, 0xFF7E, 0xFF6E, 0xFF83, 0xFF93, 0x6CBC, 0xFF8D, 0x7701, 0xFF85, 0x6368, 0x91C8, 0x52FA);
sl@0
   167
	TestTruncatedConversionToUnicodeFromShiftJisDirectmap(*characterSetConverter, expectedUnicode, originalShiftJisDirectmap);
sl@0
   168
	TestTruncatedConversionToUnicodeFromShiftJisDirectmap(*characterSetConverter, expectedUnicode.Mid(4, 4), originalShiftJisDirectmap.Mid(4, 4));
sl@0
   169
	TestTruncatedConversionToUnicodeFromShiftJisDirectmap(*characterSetConverter, expectedUnicode.Mid(6, 3), originalShiftJisDirectmap.Mid(6, 4));
sl@0
   170
	TestTruncatedConversionToUnicodeFromShiftJisDirectmap(*characterSetConverter, expectedUnicode.Mid(11, 4), originalShiftJisDirectmap.Mid(14, 6));
sl@0
   171
	TestSplittingConvertingToUnicodeFromShiftJisDirectmap(*characterSetConverter, 4, 4, 60, 4, expectedUnicode, originalShiftJisDirectmap);
sl@0
   172
	TestSplittingConvertingToUnicodeFromShiftJisDirectmap(*characterSetConverter, 5, 5, 59, 5, expectedUnicode, originalShiftJisDirectmap);
sl@0
   173
	TestSplittingConvertingToUnicodeFromShiftJisDirectmap(*characterSetConverter, 6, 6, 58, 6, expectedUnicode, originalShiftJisDirectmap);
sl@0
   174
	
sl@0
   175
    const TPtrC8 originalShiftJisDirectmapYen(_S8("pool\x5c"));
sl@0
   176
    TBuf16<10> expectedUnicodeBackSlash;
sl@0
   177
    expectedUnicodeBackSlash.Format(_L16("pool%c"), 0x005c);
sl@0
   178
    TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
   179
    TBuf16<KBufferLength> generatedUnicodeBackSlash;
sl@0
   180
    test(characterSetConverter->ConvertToUnicode(generatedUnicodeBackSlash, originalShiftJisDirectmapYen, state) == 0);
sl@0
   181
    test(generatedUnicodeBackSlash==expectedUnicodeBackSlash);
sl@0
   182
sl@0
   183
	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
sl@0
   184
	}
sl@0
   185
sl@0
   186
CT_SHIFTJISDIRECTMAP::CT_SHIFTJISDIRECTMAP()
sl@0
   187
    {
sl@0
   188
    SetTestStepName(KTestStep_T_SHIFTJISDIRECTMAP);
sl@0
   189
    }
sl@0
   190
sl@0
   191
TVerdict CT_SHIFTJISDIRECTMAP::doTestStepL()
sl@0
   192
    {
sl@0
   193
    SetTestStepResult(EFail);
sl@0
   194
sl@0
   195
    __UHEAP_MARK;
sl@0
   196
    TRAPD(error1, DoE32MainL());    
sl@0
   197
    __UHEAP_MARKEND;
sl@0
   198
sl@0
   199
    if(error1 == KErrNone)
sl@0
   200
        {
sl@0
   201
        SetTestStepResult(EPass);
sl@0
   202
        }
sl@0
   203
sl@0
   204
    return TestStepResult();
sl@0
   205
    }
sl@0
   206
sl@0
   207