os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_extendedsms.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_extendedsms.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,239 @@
     1.4 +/*
     1.5 +* Copyright (c) 2008-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 "t_extendedsms.h"
    1.27 +
    1.28 +#ifdef __WINS__
    1.29 +_LIT(KInputUnicodeFilename, "c:\\test\\data\\extendedsms_uni_input.dat");
    1.30 +_LIT(KInputForeignFilename, "c:\\test\\data\\extendedsms_for_input.dat");
    1.31 +_LIT(KExpectUnicodeFilename, "c:\\test\\data\\extendedsms_uni_expect.dat");
    1.32 +_LIT(KExpectForeignFilename, "c:\\test\\data\\extendedsms_for_expect.dat");
    1.33 +#else
    1.34 +_LIT(KInputUnicodeFilename, "z:\\test\\data\\extendedsms_uni_input.dat");
    1.35 +_LIT(KInputForeignFilename, "z:\\test\\data\\extendedsms_for_input.dat");
    1.36 +_LIT(KExpectUnicodeFilename, "z:\\test\\data\\extendedsms_uni_expect.dat");
    1.37 +_LIT(KExpectForeignFilename, "z:\\test\\data\\extendedsms_for_expect.dat");
    1.38 +#endif
    1.39 +
    1.40 +static CCnvCharacterSetConverter* characterSetConverter;
    1.41 +static RFs fileServerSession;
    1.42 +static TBuf8<1254> temp;
    1.43 +static  TBuf16<627> originalUnicode;
    1.44 +static  TBuf8<627> generatedForeign;
    1.45 +static  TBuf16<627> generatedUnicode;
    1.46 +	
    1.47 +#define test(cond)                                  \
    1.48 +    {                                               \
    1.49 +    TBool __bb = (cond);                            \
    1.50 +    TEST(__bb);                                     \
    1.51 +    if (!__bb)                                      \
    1.52 +        {                                           \
    1.53 +        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    1.54 +        User::Leave(1);                             \
    1.55 +        }                                           \
    1.56 +    }
    1.57 +
    1.58 +
    1.59 +//read test data from file
    1.60 +void CT_EXTENDEDSMS::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
    1.61 +	{
    1.62 +	RFile file;
    1.63 +	TInt err = file.Open(aFs, aFilename, EFileRead);
    1.64 +	test(err == KErrNone);
    1.65 +	CleanupClosePushL(file);	
    1.66 +	err = file.Read(aDes);
    1.67 +	test(err == KErrNone);
    1.68 +	CleanupStack::PopAndDestroy(&file);
    1.69 +	}
    1.70 +
    1.71 +//translate from unicode big endian TDesC8 to TDes16
    1.72 +void CT_EXTENDEDSMS::Unicode_Big(TDesC8& aSource, TDes16& aTarget)
    1.73 +	{
    1.74 +	TInt length = aSource.Length();
    1.75 +	TInt i = 0;
    1.76 +	for(i=0;i<length-1;i++)
    1.77 +		{
    1.78 +		TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
    1.79 +		aTarget.Append(temp);
    1.80 +		i++;
    1.81 +		}	
    1.82 +	}
    1.83 +
    1.84 +/**
    1.85 +@SYMTestCaseID				SYSLIB-CHARCONV-UT-4003
    1.86 +@SYMTestCaseDesc			Testcase to test new converter name can be listed
    1.87 +@SYMTestPriority			High
    1.88 +@SYMTestActions				Test for CreateArrayOfCharacterSetsAvailableLC() 
    1.89 +@SYMTestExpectedResults		The test passed, if Available character sets are listed in epocwind.out
    1.90 +@SYMPREQ					PREQ2090
    1.91 +@SYMREQ						REQ10364
    1.92 +*/
    1.93 +void CT_EXTENDEDSMS::ListAlltheConvertersL()
    1.94 +	{
    1.95 +	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
    1.96 +		CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    1.97 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4003 Available Converters\n "));
    1.98 +	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
    1.99 +		{
   1.100 +		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
   1.101 +		TPtrC charactersSetName(charactersSet.Name());
   1.102 +		if (charactersSet.NameIsFileName())
   1.103 +			{
   1.104 +			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
   1.105 +			}
   1.106 +		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
   1.107 +		}	
   1.108 +	CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 +@SYMTestCaseID				SYSLIB-CHARCONV-UT-4004
   1.113 +@SYMTestCaseDesc			Testcase to test new converter name can be prepared for converting
   1.114 +@SYMTestPriority			High
   1.115 +@SYMTestActions				Test for PrepareToConvertToOrFromL()
   1.116 +@SYMTestExpectedResults		The test passed, If EAvailable is returned
   1.117 +@SYMPREQ					PREQ2090
   1.118 +@SYMREQ						REQ10364
   1.119 +*/
   1.120 +void CT_EXTENDEDSMS::PrepareNewConverterL()
   1.121 +	{
   1.122 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4004 Preparing the new converter "));
   1.123 +	CCnvCharacterSetConverter::TAvailability avaible = 	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierExtendedSms7Bit, fileServerSession);
   1.124 +	test( CCnvCharacterSetConverter::EAvailable == avaible );
   1.125 +	}
   1.126 +
   1.127 +/**
   1.128 +@SYMTestCaseID				SYSLIB-CHARCONV-UT-4005
   1.129 +@SYMTestCaseDesc			Convert Unicode code to foreign character set
   1.130 +@SYMTestPriority			High
   1.131 +@SYMTestActions				Test for ConvertFromUnicode()
   1.132 +@SYMTestExpectedResults		Test is passed if the generated cod and Expected code is same
   1.133 +@SYMPREQ					PREQ2090
   1.134 +@SYMREQ						REQ10364					
   1.135 +*/
   1.136 +void CT_EXTENDEDSMS::ConvertFromUnicodeToForeignL()
   1.137 +	{
   1.138 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4005 Encoding from Unicode to Foreign "));
   1.139 +	ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
   1.140 +	Unicode_Big(temp, originalUnicode); 
   1.141 +	test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
   1.142 +	ReadDescL(temp, KExpectForeignFilename, fileServerSession);
   1.143 +	test(generatedForeign == temp);
   1.144 +	}
   1.145 +
   1.146 +/**
   1.147 +@SYMTestCaseID				SYSLIB-CHARCONV-UT-4006
   1.148 +@SYMTestCaseDesc			Convert foreign character set to Unicode code 
   1.149 +@SYMTestPriority			High
   1.150 +@SYMTestActions				Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
   1.151 +@SYMTestExpectedResults		Test is passed if contents of generatedUnicode buffer with OriginalUnicode buffer are same.
   1.152 +@SYMPREQ					PREQ2090
   1.153 +@SYMREQ						REQ10364
   1.154 +*/
   1.155 +void CT_EXTENDEDSMS::ConvertFromForeignToUnicodeL()
   1.156 +	{
   1.157 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4006 Encoding from Foreign to Unicode "));	
   1.158 +	ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
   1.159 +	TInt state=CCnvCharacterSetConverter::KStateDefault;
   1.160 +	test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   1.161 +	ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
   1.162 +	originalUnicode.Zero();
   1.163 +	Unicode_Big(temp, originalUnicode); 
   1.164 +	test(generatedUnicode == originalUnicode);
   1.165 +	}	
   1.166 +
   1.167 +/**
   1.168 +@SYMTestCaseID				SYSLIB-CHARCONV-UT-4007
   1.169 +@SYMTestCaseDesc			Convert out of range characters from foreign character set to Unicode 
   1.170 +@SYMTestPriority			High
   1.171 +@SYMTestActions				Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
   1.172 +@SYMTestExpectedResults		The test is passed if generated code is same as expected code
   1.173 +@SYMPREQ					PREQ2090
   1.174 +@SYMREQ						REQ10364
   1.175 +*/
   1.176 +void CT_EXTENDEDSMS::ConvertOutOfRangeForeignCharacters()
   1.177 +	{
   1.178 +	//test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
   1.179 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4007 Testing Characters not in the Scope "));	
   1.180 +	generatedForeign.SetLength(1);
   1.181 +	generatedForeign[0] = 0x81;
   1.182 +	TInt state=CCnvCharacterSetConverter::KStateDefault;
   1.183 +	_LIT16(KExpected2, "\xfffd"); 	//the expected foreign
   1.184 +	test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   1.185 +	test( generatedUnicode == KExpected2 );
   1.186 +	}
   1.187 +
   1.188 +/**
   1.189 +@SYMTestCaseID				SYSLIB-CHARCONV-UT-4008
   1.190 +@SYMTestCaseDesc			Convert illegal character from foreign character set to unicode 
   1.191 +@SYMTestPriority			High
   1.192 +@SYMTestActions				Test for ConvertToUnicode() with illegal foreign characters 0x1B
   1.193 +@SYMTestExpectedResults		Test is passed if KErrCorrupt is returned
   1.194 +@SYMPREQ					PREQ2090
   1.195 +@SYMREQ						REQ10364
   1.196 +*/
   1.197 +void CT_EXTENDEDSMS::ConvertIllegalForeignCharacter()
   1.198 +	{
   1.199 +	//test 0x1b
   1.200 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4008 Testing EErrorIllFormedInput "));	
   1.201 +	generatedForeign.SetLength(1);
   1.202 +	generatedForeign[0] = 0x1b; 		//the escape character
   1.203 +	TInt state=CCnvCharacterSetConverter::KStateDefault;	
   1.204 +	test( KErrCorrupt == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   1.205 +	}
   1.206 +
   1.207 +void CT_EXTENDEDSMS::DoE32MainL()
   1.208 +	{
   1.209 +	CleanupClosePushL(fileServerSession);
   1.210 +	User::LeaveIfError(fileServerSession.Connect());
   1.211 +	characterSetConverter=CCnvCharacterSetConverter::NewLC();
   1.212 +	
   1.213 +	ListAlltheConvertersL();
   1.214 +	PrepareNewConverterL();
   1.215 +	ConvertFromUnicodeToForeignL();
   1.216 +	ConvertFromForeignToUnicodeL();
   1.217 +	ConvertOutOfRangeForeignCharacters();
   1.218 +	ConvertIllegalForeignCharacter();
   1.219 +
   1.220 +	CleanupStack::PopAndDestroy(2);
   1.221 +	}
   1.222 +
   1.223 +CT_EXTENDEDSMS::CT_EXTENDEDSMS()
   1.224 +    {
   1.225 +    SetTestStepName(KTestStep_T_EXTENDEDSMS);
   1.226 +    }
   1.227 +
   1.228 +TVerdict CT_EXTENDEDSMS::doTestStepL()
   1.229 +    {
   1.230 +    SetTestStepResult(EFail);
   1.231 +
   1.232 +    __UHEAP_MARK;
   1.233 +    TRAPD(error1, DoE32MainL());    
   1.234 +    __UHEAP_MARKEND;
   1.235 +
   1.236 +    if(error1 == KErrNone)
   1.237 +        {
   1.238 +        SetTestStepResult(EPass);
   1.239 +        }
   1.240 +
   1.241 +    return TestStepResult();
   1.242 +    }