os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/tsimple8.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) 1997-2009 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
sl@0
    21
#include <utf.h>
sl@0
    22
#include "t_simple8.h"
sl@0
    23
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    24
sl@0
    25
#define test(cond)                                  \
sl@0
    26
    TEST((cond));                                   \
sl@0
    27
    if (!(cond))                                    \
sl@0
    28
        {                                           \
sl@0
    29
        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
sl@0
    30
        User::Leave(1);                             \
sl@0
    31
        }
sl@0
    32
sl@0
    33
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    34
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    35
sl@0
    36
/**
sl@0
    37
@SYMTestCaseID          SYSLIB-CHARCONV-CT-4002
sl@0
    38
@SYMTestCaseDesc        Test conversion of a UTF-8 BOM between Unicode and 8-bit 
sl@0
    39
                        encoding.
sl@0
    40
@SYMTestPriority        Medium
sl@0
    41
@SYMTestActions        	Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(),
sl@0
    42
                        CnvUtfConverter::ConvertToUnicodeFromUtf8L() function  
sl@0
    43
@SYMTestExpectedResults Tests must not fail
sl@0
    44
@SYMREQ                 REQ0000
sl@0
    45
*/
sl@0
    46
//INC118714L
sl@0
    47
void CT_SIMPLE8::TestForUtf8BomL()
sl@0
    48
	{
sl@0
    49
    INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-CHARCONV-CT-4002 Testing converting to and from UTF-8 BOM.")); 	
sl@0
    50
sl@0
    51
	TBuf8<100> generatedUtf8NoGKBWithBom(_L8("\xef\xbb\xbf\x7F\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64"));
sl@0
    52
	
sl@0
    53
	//convert to unicode and verify BOM converted properly.
sl@0
    54
	INFO_PRINTF1(_L("BOM, valid UTF-8 to Unicode conversion test."));
sl@0
    55
	TBuf16<256> generatedUnicode;
sl@0
    56
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8NoGKBWithBom)==0);
sl@0
    57
	test(generatedUnicode==_L16("\xFEFF\x007fHello World"));
sl@0
    58
   
sl@0
    59
	INFO_PRINTF1(_L("BOM, valid Unicode to UTF-8 conversion test."));
sl@0
    60
	TBuf8<256> generatedUtf8;
sl@0
    61
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, generatedUnicode)==0);
sl@0
    62
	test(generatedUtf8==generatedUtf8NoGKBWithBom);
sl@0
    63
	
sl@0
    64
	}
sl@0
    65
sl@0
    66
sl@0
    67
/**
sl@0
    68
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0563
sl@0
    69
@SYMTestCaseDesc        Conversion tests from Unicode to UTF-8 character set
sl@0
    70
@SYMTestPriority        Medium
sl@0
    71
@SYMTestActions        	Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(),
sl@0
    72
                        CnvUtfConverter::ConvertToUnicodeFromUtf8L() function
sl@0
    73
@SYMTestExpectedResults Test must not fail
sl@0
    74
@SYMREQ                 REQ0000
sl@0
    75
*/
sl@0
    76
void CT_SIMPLE8::TestSimple8()
sl@0
    77
	{
sl@0
    78
    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0563 Testing simple UTF-8 round trips "));
sl@0
    79
	TBuf16<256> originalUnicode;
sl@0
    80
	TBuf8<256> generatedUtf8;
sl@0
    81
	TBuf16<256> generatedUnicode;
sl@0
    82
	//
sl@0
    83
	INFO_PRINTF1(_L("Empty descriptor"));
sl@0
    84
	originalUnicode=_L16("");
sl@0
    85
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
sl@0
    86
	test(generatedUtf8==_L8(""));
sl@0
    87
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
sl@0
    88
	test(generatedUnicode==originalUnicode);
sl@0
    89
	// Testing the new API
sl@0
    90
	HBufC8* testbuffer8;
sl@0
    91
	HBufC* testbuffer;
sl@0
    92
	testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
sl@0
    93
	TPtr8 comparebuffer8 = testbuffer8->Des();
sl@0
    94
	test(comparebuffer8==generatedUtf8);
sl@0
    95
	testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
sl@0
    96
	TPtr compareBuffer = testbuffer->Des();
sl@0
    97
	test(compareBuffer == originalUnicode);
sl@0
    98
	delete testbuffer8;
sl@0
    99
	delete testbuffer;
sl@0
   100
sl@0
   101
	INFO_PRINTF1(_L("English \"Hello!\""));
sl@0
   102
	originalUnicode=_L16("Hello!");
sl@0
   103
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
sl@0
   104
	test(generatedUtf8==_L8("Hello!"));
sl@0
   105
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
sl@0
   106
	test(generatedUnicode==originalUnicode);
sl@0
   107
	// Testing the new API
sl@0
   108
	testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
sl@0
   109
	comparebuffer8.Set(testbuffer8->Des());
sl@0
   110
	test(comparebuffer8==generatedUtf8);
sl@0
   111
	testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
sl@0
   112
	compareBuffer.Set(testbuffer->Des());
sl@0
   113
	test(compareBuffer == originalUnicode);
sl@0
   114
	delete testbuffer8;
sl@0
   115
	delete testbuffer;
sl@0
   116
sl@0
   117
	INFO_PRINTF1(_L("Russian \"Hello!\""));
sl@0
   118
	originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c%c%c%c%c%c"), 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, 0x0439, 0x0442, 0x0435, 0x0021);
sl@0
   119
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
sl@0
   120
	test(generatedUtf8==_L8("\xd0\x97\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb2\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd0\xb9\xd1\x82\xd0\xb5\x21"));
sl@0
   121
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
sl@0
   122
	test(generatedUnicode==originalUnicode);
sl@0
   123
	// Testing the new API
sl@0
   124
	testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
sl@0
   125
	comparebuffer8.Set(testbuffer8->Des());
sl@0
   126
	test(comparebuffer8==generatedUtf8);
sl@0
   127
	testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
sl@0
   128
	compareBuffer.Set(testbuffer->Des());
sl@0
   129
	test(compareBuffer == originalUnicode);
sl@0
   130
	delete testbuffer8;
sl@0
   131
	delete testbuffer;
sl@0
   132
sl@0
   133
	INFO_PRINTF1(_L("Greek \"Hello!\""));
sl@0
   134
	originalUnicode.Format(_L16("%c%c%c%c%c%c"), 0x0393, 0x03b1, 0x03c3, 0x03bf, 0x03c5, 0x0021);
sl@0
   135
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
sl@0
   136
	test(generatedUtf8==_L8("\xce\x93\xce\xb1\xcf\x83\xce\xbf\xcf\x85\x21"));
sl@0
   137
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
sl@0
   138
	test(generatedUnicode==originalUnicode);
sl@0
   139
	// Testing the new API
sl@0
   140
	testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
sl@0
   141
	comparebuffer8.Set(testbuffer8->Des());
sl@0
   142
	test(comparebuffer8==generatedUtf8);
sl@0
   143
	testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
sl@0
   144
	compareBuffer.Set(testbuffer->Des());
sl@0
   145
	test(compareBuffer == originalUnicode);
sl@0
   146
	delete testbuffer8;
sl@0
   147
	delete testbuffer;
sl@0
   148
sl@0
   149
	INFO_PRINTF1(_L("Chinese \"Hello!\""));
sl@0
   150
	originalUnicode.Format(_L16("%c%c%c"), 0x4f60, 0x597d, 0x0021);
sl@0
   151
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
sl@0
   152
	test(generatedUtf8==_L8("\xe4\xbd\xa0\xe5\xa5\xbd\x21"));
sl@0
   153
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
sl@0
   154
	test(generatedUnicode==originalUnicode);
sl@0
   155
	// Testing the new API
sl@0
   156
	testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
sl@0
   157
	comparebuffer8.Set(testbuffer8->Des());
sl@0
   158
	test(comparebuffer8==generatedUtf8);
sl@0
   159
	testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
sl@0
   160
	compareBuffer.Set(testbuffer->Des());
sl@0
   161
	test(compareBuffer == originalUnicode);
sl@0
   162
	delete testbuffer8;
sl@0
   163
	delete testbuffer;
sl@0
   164
sl@0
   165
	INFO_PRINTF1(_L("Japanese \"Hello!\""));
sl@0
   166
	originalUnicode.Format(_L16("%c%c%c%c"), 0x4eca, 0x65e5, 0x306f, 0x0021);
sl@0
   167
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
sl@0
   168
	test(generatedUtf8==_L8("\xe4\xbb\x8a\xe6\x97\xa5\xe3\x81\xaf\x21"));
sl@0
   169
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
sl@0
   170
	test(generatedUnicode==originalUnicode);
sl@0
   171
	// Testing the new API
sl@0
   172
	testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
sl@0
   173
	comparebuffer8.Set(testbuffer8->Des());
sl@0
   174
	test(comparebuffer8==generatedUtf8);
sl@0
   175
	testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
sl@0
   176
	compareBuffer.Set(testbuffer->Des());
sl@0
   177
	test(compareBuffer == originalUnicode);
sl@0
   178
	delete testbuffer8;
sl@0
   179
	delete testbuffer;
sl@0
   180
	
sl@0
   181
	
sl@0
   182
	}
sl@0
   183
sl@0
   184
CT_SIMPLE8::CT_SIMPLE8()
sl@0
   185
    {
sl@0
   186
    SetTestStepName(KTestStep_T_SIMPLE8);
sl@0
   187
    }
sl@0
   188
sl@0
   189
TVerdict CT_SIMPLE8::doTestStepL()
sl@0
   190
    {
sl@0
   191
    SetTestStepResult(EFail);
sl@0
   192
sl@0
   193
    __UHEAP_MARK;
sl@0
   194
sl@0
   195
    TRAPD(error1, TestSimple8());
sl@0
   196
    TRAPD(error2, TestForUtf8BomL());
sl@0
   197
sl@0
   198
sl@0
   199
    __UHEAP_MARKEND;
sl@0
   200
sl@0
   201
    if(error1 == KErrNone && error2 == KErrNone)
sl@0
   202
        {
sl@0
   203
        SetTestStepResult(EPass);
sl@0
   204
        }
sl@0
   205
sl@0
   206
    return TestStepResult();
sl@0
   207
    }
sl@0
   208