os/textandloc/charconvfw/fatfilenameconversionplugins/test/T_CP932.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/fatfilenameconversionplugins/test/T_CP932.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,215 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-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 "T_CP932.h"
    1.23 +#include <e32des8.h>
    1.24 +
    1.25 +#define test(cond)                                          \
    1.26 +    {                                                       \
    1.27 +    TBool __bb = (cond);                                    \
    1.28 +    TEST(__bb);                                             \
    1.29 +    if (!__bb)                                              \
    1.30 +        {                                                   \
    1.31 +        ERR_PRINTF1(_L("ERROR: Test Failed"));              \
    1.32 +        User::Leave(1);                                     \
    1.33 +        }                                                   \
    1.34 +    }
    1.35 +
    1.36 +
    1.37 +_LIT16(Uni_1, "\x0053\x0059\x004D\x3125\x6349\xAAAA\x9673\x9ED1\x3000\xFF9F");
    1.38 +_LIT8(CP932_1, "\x53\x59\x4D\x5F\x91\xA8\x5F\x92\xC2\xEE\xEC\x81\x40\xDF");
    1.39 +_LIT16(Uni_2, "\x0032\x0070\xFFFD\xFF61\x8D77\xFFFD\xFFFD");
    1.40 +_LIT8(CP932_2, "\x32\x70\x80\xA1\x8B\x4E\xA0\x96\x7F");
    1.41 +_LIT16(Uni_3, "\x4E00\x5141\x674F\x95C7\x58F1");
    1.42 +_LIT8(CP932_3, "\x88\xEA\x88\xF2\x88\xC7\x88\xC5\x88\xEB");
    1.43 +
    1.44 +_LIT(KName,"CP932");
    1.45 +const TUid KPluginUid={0x10206A92};
    1.46 +
    1.47 +
    1.48 +// Used for supressing warning in OOM tests
    1.49 +#define __UNUSED_VAR(var) var = var
    1.50 +
    1.51 +/**
    1.52 +@SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1779
    1.53 +@SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class
    1.54 +@SYMTestPriority 	    High
    1.55 +@SYMTestActions  	    Tests for conversions from/to Unicode, using a function pointer
    1.56 +@SYMTestExpectedResults Test must not fail 
    1.57 +*/
    1.58 +void CT_CP932::TestL()
    1.59 +	{ 
    1.60 +    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1779 "));
    1.61 +	RLibrary lib;
    1.62 +
    1.63 +	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);	
    1.64 +	// load the dll	
    1.65 +	TInt returnValue = lib.Load(KName,serverUid);
    1.66 +	test(returnValue==0);
    1.67 +
    1.68 +	// get a pointer to the specified ordinal function and call it	
    1.69 +	TLibraryFunction function1 = lib.Lookup(1);
    1.70 +	TLibraryFunction function2 = lib.Lookup(2);
    1.71 +	TLibraryFunction function3 = lib.Lookup(3);
    1.72 +
    1.73 +	//cast the function pointer f to a function of type void with two arguments
    1.74 +	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);	
    1.75 +	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
    1.76 +	
    1.77 +	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);	
    1.78 +	TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
    1.79 +	
    1.80 +	typedef TBool (*TIsLegalShortNameCharacter)(TUint);	
    1.81 +	TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3);
    1.82 +	
    1.83 +	
    1.84 +	TBuf8<15> foreign1;
    1.85 +	TBuf8<15> foreign3;
    1.86 +	TBuf16<15> unicode2;
    1.87 +	
    1.88 +	const TDesC16& unicode1(Uni_1);
    1.89 +	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
    1.90 +	TInt error = foreign1.Compare(CP932_1);
    1.91 +	test(error==0);
    1.92 +	foreign1.Zero();
    1.93 +	
    1.94 +	const TDesC16& unicode3(Uni_3);
    1.95 +	(*aConvertFromUnicodeL)(foreign3, unicode3); 	//testing conversion from Unicode for INC112715
    1.96 +	error = foreign3.Compare(CP932_3);
    1.97 +	test(error==0);
    1.98 +	foreign3.Zero();
    1.99 +	
   1.100 +	const TDesC8& foreign2(CP932_2);
   1.101 +	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
   1.102 +	error = unicode2.Compare(Uni_2);
   1.103 +	test(error==0);
   1.104 +	unicode2.Zero();
   1.105 +	
   1.106 +	
   1.107 +	//testing for legal short name character
   1.108 +	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
   1.109 +	test(result==1);
   1.110 +	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
   1.111 +	test(result==0);
   1.112 +	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
   1.113 +	test(result==0);
   1.114 +	result = (*aIsLegalShortNameCharacter)(0xFF61); //testing for a double byte character
   1.115 +	test(result==1);
   1.116 +
   1.117 +	lib.Close();
   1.118 +	}
   1.119 +
   1.120 +/**
   1.121 +@SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1847
   1.122 +@SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class as part of INC090073
   1.123 +@SYMTestPriority 	    High
   1.124 +@SYMTestActions  	    Tests for correct character conversion on certain chinese characters 
   1.125 +@SYMTestExpectedResults Test must not fail 
   1.126 +*/	
   1.127 +void CT_CP932::TestINC090073L()
   1.128 +	{
   1.129 +    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847 "));
   1.130 + 	_LIT16(unicode, "\x6DFC\x715C\x9785\x7A37\x61A9\x80B1\x86A3\x7B71\x6615\x6600");
   1.131 +	_LIT8(CP932Code, "\xED\xE6\xED\xF6\xE8\xD7\xE2\x6C\x8C\x65\x8D\x6E\xE5\x6E\xE2\xAA\xED\xB3\xED\xB2");
   1.132 +
   1.133 +	RLibrary lib;
   1.134 +
   1.135 +	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);	
   1.136 +	// load the dll	
   1.137 +	TInt returnValue = lib.Load(KName,serverUid);
   1.138 +	test(returnValue==0);
   1.139 +
   1.140 +	// get a pointer to the specified ordinal function and call it	
   1.141 +	TLibraryFunction function1 = lib.Lookup(1);
   1.142 +
   1.143 +
   1.144 +	//cast the function pointer f to a function of type void with two arguments
   1.145 +	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);	
   1.146 +	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
   1.147 +	
   1.148 +	TBuf8<20> foreign1;
   1.149 +	
   1.150 +	const TDesC16& unicode1(unicode);
   1.151 +	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
   1.152 +	TInt error = foreign1.Compare(CP932Code);
   1.153 +	test(error==0);
   1.154 +	foreign1.Zero();
   1.155 +
   1.156 +	lib.Close();
   1.157 +	}	
   1.158 +
   1.159 +void CT_CP932::OOMTestL()
   1.160 +	{
   1.161 +    INFO_PRINTF1(_L("OOM testing"));
   1.162 +	TInt err, tryCount = 0;
   1.163 +	do	
   1.164 +		{
   1.165 +			__UHEAP_MARK;
   1.166 +  		// find out the number of open handles
   1.167 +		TInt startProcessHandleCount;
   1.168 +		TInt startThreadHandleCount;
   1.169 +		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.170 +		
   1.171 +			// Setting Heap failure for OOM test
   1.172 +		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
   1.173 +
   1.174 +		TRAP(err,TestL());
   1.175 +			
   1.176 +		__UHEAP_SETFAIL(RHeap::ENone, 0);
   1.177 +		
   1.178 +		// check that no handles have leaked
   1.179 +		TInt endProcessHandleCount;
   1.180 +		TInt endThreadHandleCount;
   1.181 +		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.182 +
   1.183 +		test(startProcessHandleCount == endProcessHandleCount);
   1.184 +		test(startThreadHandleCount  == endThreadHandleCount);
   1.185 +
   1.186 +		__UHEAP_MARKEND;
   1.187 +		}while (err == KErrNoMemory);
   1.188 +		
   1.189 +	test(err == KErrNone);
   1.190 +	INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
   1.191 +	}
   1.192 +
   1.193 +
   1.194 +CT_CP932::CT_CP932()
   1.195 +    {
   1.196 +    SetTestStepName(KTestStep_T_CP932);
   1.197 +    }
   1.198 +
   1.199 +
   1.200 +TVerdict CT_CP932::doTestStepL()
   1.201 +    {
   1.202 +    SetTestStepResult(EFail);
   1.203 +
   1.204 +    __UHEAP_MARK;
   1.205 +
   1.206 +    TRAPD(error1, TestL());
   1.207 +    TRAPD(error2, TestINC090073L());
   1.208 +    TRAPD(error3, OOMTestL());
   1.209 +
   1.210 +    __UHEAP_MARKEND;
   1.211 +
   1.212 +    if(error1 == KErrNone && error2 == KErrNone && error3 == KErrNone)
   1.213 +        {
   1.214 +        SetTestStepResult(EPass);
   1.215 +        }
   1.216 +
   1.217 +    return TestStepResult();
   1.218 +    }