os/textandloc/charconvfw/fatfilenameconversionplugins/test/T_CP949.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_CP949.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,210 @@
     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_CP949.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, "\xFFFF\x0053\x0059\x004D\x0042\x0049\x0041\x004E\xAC21\xC6AA\xFFFF\x9673\x8A70");
    1.38 +_LIT8(CP949_1, "\x5F\x53\x59\x4D\x42\x49\x41\x4E\x81\x4D\x9F\x42\x5F\xF2\xE7\xFD\xFE");
    1.39 +_LIT16(Uni_2, "\xFFFD\x005F\x304A\xFFFD\xFFFD");
    1.40 +_LIT8(CP949_2, "\xAA\x40\x5F\xAA\xAA\xFF\xFE");
    1.41 +
    1.42 +_LIT(KName,"CP949");
    1.43 +const TUid KPluginUid={0x10206A90};
    1.44 +
    1.45 +
    1.46 +// Used for supressing warning in OOM tests
    1.47 +#define __UNUSED_VAR(var) var = var
    1.48 +
    1.49 +/**
    1.50 +@SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1777
    1.51 +@SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class
    1.52 +@SYMTestPriority 	    High
    1.53 +@SYMTestActions  	    Tests for conversions from/to Unicode, using a function pointer
    1.54 +@SYMTestExpectedResults Test must not fail
    1.55 +*/
    1.56 +void CT_CP949::TestL()
    1.57 +	{
    1.58 +    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1777 "));
    1.59 +	RLibrary lib;
    1.60 +
    1.61 +	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
    1.62 +	// load the dll
    1.63 +	TInt returnValue = lib.Load(KName,serverUid);
    1.64 +	test(returnValue==0);
    1.65 +
    1.66 +	// get a pointer to the specified ordinal function and call it
    1.67 +	TLibraryFunction function1 = lib.Lookup(1);
    1.68 +	TLibraryFunction function2 = lib.Lookup(2);
    1.69 +	TLibraryFunction function3 = lib.Lookup(3);
    1.70 +
    1.71 +	//cast the function pointer f to a function of type void with two arguments
    1.72 +	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
    1.73 +	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
    1.74 +
    1.75 +	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);
    1.76 +	TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
    1.77 +
    1.78 +	typedef TBool (*TIsLegalShortNameCharacter)(TUint);
    1.79 +	TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3);
    1.80 +
    1.81 +
    1.82 +	TBuf8<20> foreign1;
    1.83 +	TBuf16<15> unicode2;
    1.84 +
    1.85 +	const TDesC16& unicode1(Uni_1);
    1.86 +	TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); 	//testing conversion from Unicode
    1.87 +	test(err==0);
    1.88 +	TInt error = foreign1.Compare(CP949_1);
    1.89 +	test(error==0);
    1.90 +	foreign1.Zero();
    1.91 +
    1.92 +	const TDesC8& foreign2(CP949_2);
    1.93 +	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
    1.94 +	error = unicode2.Compare(Uni_2);
    1.95 +	test(error==0);
    1.96 +	unicode2.Zero();
    1.97 +
    1.98 +
    1.99 +	//testing for legal short name character
   1.100 +	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
   1.101 +	test(result==1);
   1.102 +	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
   1.103 +	test(result==0);
   1.104 +	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
   1.105 +	test(result==0);
   1.106 +	result = (*aIsLegalShortNameCharacter)(0xAC02); //testing for double byte character
   1.107 +	test(result==1);
   1.108 +
   1.109 +	lib.Close();
   1.110 +	}
   1.111 +
   1.112 +/**
   1.113 +@SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1847-0002
   1.114 +@SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class as part of INC090073
   1.115 +@SYMTestPriority 	    High
   1.116 +@SYMTestActions  	    Tests for correct character conversion on certain chinese characters for CP936
   1.117 +@SYMTestExpectedResults Test must not fail
   1.118 +*/
   1.119 +void CT_CP949::TestINC090073L()
   1.120 +	{
   1.121 +    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847-0002 "));
   1.122 + 	_LIT16(unicode, "\x715C\x7A37\x61A9\x80B1\x86A3\x6B46\x6615");
   1.123 +	_LIT8(CP932Code, "\xE9\xF2\xF2\xC3\xCC\xA8\xCE\xDD\xCD\xF7\xFD\xE4\xFD\xDA");
   1.124 +
   1.125 +	RLibrary lib;
   1.126 +
   1.127 +	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
   1.128 +	// load the dll
   1.129 +	TInt returnValue = lib.Load(KName,serverUid);
   1.130 +	test(returnValue==0);
   1.131 +
   1.132 +	// get a pointer to the specified ordinal function and call it
   1.133 +	TLibraryFunction function1 = lib.Lookup(1);
   1.134 +
   1.135 +
   1.136 +	//cast the function pointer f to a function of type void with two arguments
   1.137 +	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
   1.138 +	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
   1.139 +
   1.140 +	TBuf8<15> foreign1;
   1.141 +
   1.142 +	foreign1.Zero();
   1.143 +	const TDesC16& unicode1(unicode);
   1.144 +	TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); 	//testing conversion from Unicode
   1.145 +	test(err==0);
   1.146 +	TInt error = foreign1.Compare(CP932Code);
   1.147 +	test(error==0);
   1.148 +	foreign1.Zero();
   1.149 +
   1.150 +	lib.Close();
   1.151 +	}
   1.152 +
   1.153 +void CT_CP949::OOMTestL()
   1.154 +	{
   1.155 +    INFO_PRINTF1(_L("OOM testing"));
   1.156 +	TInt err, tryCount = 0;
   1.157 +	do
   1.158 +		{
   1.159 +			__UHEAP_MARK;
   1.160 +  		// find out the number of open handles
   1.161 +		TInt startProcessHandleCount;
   1.162 +		TInt startThreadHandleCount;
   1.163 +		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.164 +
   1.165 +			// Setting Heap failure for OOM test
   1.166 +		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
   1.167 +
   1.168 +		TRAP(err,TestL());
   1.169 +
   1.170 +		__UHEAP_SETFAIL(RHeap::ENone, 0);
   1.171 +
   1.172 +		// check that no handles have leaked
   1.173 +		TInt endProcessHandleCount;
   1.174 +		TInt endThreadHandleCount;
   1.175 +		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.176 +
   1.177 +		test(startProcessHandleCount == endProcessHandleCount);
   1.178 +		test(startThreadHandleCount  == endThreadHandleCount);
   1.179 +
   1.180 +		__UHEAP_MARKEND;
   1.181 +		}while (err == KErrNoMemory);
   1.182 +
   1.183 +	test(err == KErrNone);
   1.184 +	INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
   1.185 +	}
   1.186 +
   1.187 +
   1.188 +CT_CP949::CT_CP949()
   1.189 +    {
   1.190 +    SetTestStepName(KTestStep_T_CP949);
   1.191 +    }
   1.192 +
   1.193 +
   1.194 +
   1.195 +TVerdict CT_CP949::doTestStepL()
   1.196 +    {
   1.197 +    SetTestStepResult(EFail);
   1.198 +
   1.199 +    __UHEAP_MARK;
   1.200 +
   1.201 +    TRAPD(error1, TestL());
   1.202 +    TRAPD(error2, TestINC090073L());
   1.203 +    TRAPD(error3, OOMTestL());
   1.204 +
   1.205 +    __UHEAP_MARKEND;
   1.206 +
   1.207 +    if(error1 == KErrNone && error2 == KErrNone && error3 == KErrNone)
   1.208 +        {
   1.209 +        SetTestStepResult(EPass);
   1.210 +        }
   1.211 +
   1.212 +    return TestStepResult();
   1.213 +    }