os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_extendedsms.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.
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <e32std.h>
    20 #include <e32base.h>
    21 #include <f32file.h>
    22 #include <charconv.h>
    23 #include "t_extendedsms.h"
    24 
    25 #ifdef __WINS__
    26 _LIT(KInputUnicodeFilename, "c:\\test\\data\\extendedsms_uni_input.dat");
    27 _LIT(KInputForeignFilename, "c:\\test\\data\\extendedsms_for_input.dat");
    28 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\extendedsms_uni_expect.dat");
    29 _LIT(KExpectForeignFilename, "c:\\test\\data\\extendedsms_for_expect.dat");
    30 #else
    31 _LIT(KInputUnicodeFilename, "z:\\test\\data\\extendedsms_uni_input.dat");
    32 _LIT(KInputForeignFilename, "z:\\test\\data\\extendedsms_for_input.dat");
    33 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\extendedsms_uni_expect.dat");
    34 _LIT(KExpectForeignFilename, "z:\\test\\data\\extendedsms_for_expect.dat");
    35 #endif
    36 
    37 static CCnvCharacterSetConverter* characterSetConverter;
    38 static RFs fileServerSession;
    39 static TBuf8<1254> temp;
    40 static  TBuf16<627> originalUnicode;
    41 static  TBuf8<627> generatedForeign;
    42 static  TBuf16<627> generatedUnicode;
    43 	
    44 #define test(cond)                                  \
    45     {                                               \
    46     TBool __bb = (cond);                            \
    47     TEST(__bb);                                     \
    48     if (!__bb)                                      \
    49         {                                           \
    50         ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    51         User::Leave(1);                             \
    52         }                                           \
    53     }
    54 
    55 
    56 //read test data from file
    57 void CT_EXTENDEDSMS::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
    58 	{
    59 	RFile file;
    60 	TInt err = file.Open(aFs, aFilename, EFileRead);
    61 	test(err == KErrNone);
    62 	CleanupClosePushL(file);	
    63 	err = file.Read(aDes);
    64 	test(err == KErrNone);
    65 	CleanupStack::PopAndDestroy(&file);
    66 	}
    67 
    68 //translate from unicode big endian TDesC8 to TDes16
    69 void CT_EXTENDEDSMS::Unicode_Big(TDesC8& aSource, TDes16& aTarget)
    70 	{
    71 	TInt length = aSource.Length();
    72 	TInt i = 0;
    73 	for(i=0;i<length-1;i++)
    74 		{
    75 		TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
    76 		aTarget.Append(temp);
    77 		i++;
    78 		}	
    79 	}
    80 
    81 /**
    82 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4003
    83 @SYMTestCaseDesc			Testcase to test new converter name can be listed
    84 @SYMTestPriority			High
    85 @SYMTestActions				Test for CreateArrayOfCharacterSetsAvailableLC() 
    86 @SYMTestExpectedResults		The test passed, if Available character sets are listed in epocwind.out
    87 @SYMPREQ					PREQ2090
    88 @SYMREQ						REQ10364
    89 */
    90 void CT_EXTENDEDSMS::ListAlltheConvertersL()
    91 	{
    92 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
    93 		CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    94 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4003 Available Converters\n "));
    95 	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
    96 		{
    97 		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
    98 		TPtrC charactersSetName(charactersSet.Name());
    99 		if (charactersSet.NameIsFileName())
   100 			{
   101 			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
   102 			}
   103 		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
   104 		}	
   105 	CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
   106 	}
   107 
   108 /**
   109 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4004
   110 @SYMTestCaseDesc			Testcase to test new converter name can be prepared for converting
   111 @SYMTestPriority			High
   112 @SYMTestActions				Test for PrepareToConvertToOrFromL()
   113 @SYMTestExpectedResults		The test passed, If EAvailable is returned
   114 @SYMPREQ					PREQ2090
   115 @SYMREQ						REQ10364
   116 */
   117 void CT_EXTENDEDSMS::PrepareNewConverterL()
   118 	{
   119 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4004 Preparing the new converter "));
   120 	CCnvCharacterSetConverter::TAvailability avaible = 	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierExtendedSms7Bit, fileServerSession);
   121 	test( CCnvCharacterSetConverter::EAvailable == avaible );
   122 	}
   123 
   124 /**
   125 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4005
   126 @SYMTestCaseDesc			Convert Unicode code to foreign character set
   127 @SYMTestPriority			High
   128 @SYMTestActions				Test for ConvertFromUnicode()
   129 @SYMTestExpectedResults		Test is passed if the generated cod and Expected code is same
   130 @SYMPREQ					PREQ2090
   131 @SYMREQ						REQ10364					
   132 */
   133 void CT_EXTENDEDSMS::ConvertFromUnicodeToForeignL()
   134 	{
   135 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4005 Encoding from Unicode to Foreign "));
   136 	ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
   137 	Unicode_Big(temp, originalUnicode); 
   138 	test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
   139 	ReadDescL(temp, KExpectForeignFilename, fileServerSession);
   140 	test(generatedForeign == temp);
   141 	}
   142 
   143 /**
   144 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4006
   145 @SYMTestCaseDesc			Convert foreign character set to Unicode code 
   146 @SYMTestPriority			High
   147 @SYMTestActions				Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
   148 @SYMTestExpectedResults		Test is passed if contents of generatedUnicode buffer with OriginalUnicode buffer are same.
   149 @SYMPREQ					PREQ2090
   150 @SYMREQ						REQ10364
   151 */
   152 void CT_EXTENDEDSMS::ConvertFromForeignToUnicodeL()
   153 	{
   154 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4006 Encoding from Foreign to Unicode "));	
   155 	ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
   156 	TInt state=CCnvCharacterSetConverter::KStateDefault;
   157 	test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   158 	ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
   159 	originalUnicode.Zero();
   160 	Unicode_Big(temp, originalUnicode); 
   161 	test(generatedUnicode == originalUnicode);
   162 	}	
   163 
   164 /**
   165 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4007
   166 @SYMTestCaseDesc			Convert out of range characters from foreign character set to Unicode 
   167 @SYMTestPriority			High
   168 @SYMTestActions				Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
   169 @SYMTestExpectedResults		The test is passed if generated code is same as expected code
   170 @SYMPREQ					PREQ2090
   171 @SYMREQ						REQ10364
   172 */
   173 void CT_EXTENDEDSMS::ConvertOutOfRangeForeignCharacters()
   174 	{
   175 	//test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
   176 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4007 Testing Characters not in the Scope "));	
   177 	generatedForeign.SetLength(1);
   178 	generatedForeign[0] = 0x81;
   179 	TInt state=CCnvCharacterSetConverter::KStateDefault;
   180 	_LIT16(KExpected2, "\xfffd"); 	//the expected foreign
   181 	test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   182 	test( generatedUnicode == KExpected2 );
   183 	}
   184 
   185 /**
   186 @SYMTestCaseID				SYSLIB-CHARCONV-UT-4008
   187 @SYMTestCaseDesc			Convert illegal character from foreign character set to unicode 
   188 @SYMTestPriority			High
   189 @SYMTestActions				Test for ConvertToUnicode() with illegal foreign characters 0x1B
   190 @SYMTestExpectedResults		Test is passed if KErrCorrupt is returned
   191 @SYMPREQ					PREQ2090
   192 @SYMREQ						REQ10364
   193 */
   194 void CT_EXTENDEDSMS::ConvertIllegalForeignCharacter()
   195 	{
   196 	//test 0x1b
   197 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4008 Testing EErrorIllFormedInput "));	
   198 	generatedForeign.SetLength(1);
   199 	generatedForeign[0] = 0x1b; 		//the escape character
   200 	TInt state=CCnvCharacterSetConverter::KStateDefault;	
   201 	test( KErrCorrupt == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
   202 	}
   203 
   204 void CT_EXTENDEDSMS::DoE32MainL()
   205 	{
   206 	CleanupClosePushL(fileServerSession);
   207 	User::LeaveIfError(fileServerSession.Connect());
   208 	characterSetConverter=CCnvCharacterSetConverter::NewLC();
   209 	
   210 	ListAlltheConvertersL();
   211 	PrepareNewConverterL();
   212 	ConvertFromUnicodeToForeignL();
   213 	ConvertFromForeignToUnicodeL();
   214 	ConvertOutOfRangeForeignCharacters();
   215 	ConvertIllegalForeignCharacter();
   216 
   217 	CleanupStack::PopAndDestroy(2);
   218 	}
   219 
   220 CT_EXTENDEDSMS::CT_EXTENDEDSMS()
   221     {
   222     SetTestStepName(KTestStep_T_EXTENDEDSMS);
   223     }
   224 
   225 TVerdict CT_EXTENDEDSMS::doTestStepL()
   226     {
   227     SetTestStepResult(EFail);
   228 
   229     __UHEAP_MARK;
   230     TRAPD(error1, DoE32MainL());    
   231     __UHEAP_MARKEND;
   232 
   233     if(error1 == KErrNone)
   234         {
   235         SetTestStepResult(EPass);
   236         }
   237 
   238     return TestStepResult();
   239     }