sl@0: /* sl@0: * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "T_CP950.h" sl@0: #include sl@0: sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: sl@0: sl@0: _LIT16(Uni_1, "\x0053\x3125\x3122\xAAAA\x9673\x2593\xFA0C\x3000"); sl@0: _LIT8(CP950_1, "\x53\xA3\xB6\xA3\xB3\x5F\xB3\xAF\xF9\xFE\xC9\x4A\xA1\x40"); sl@0: _LIT16(Uni_2, "\x0032\xFFFD\xFE3E\xFFFD\xFFFD"); sl@0: _LIT8(CP950_2, "\x32\x80\xA1\x70\xC1\x7F\xA7"); sl@0: sl@0: _LIT(KName,"CP950"); sl@0: const TUid KPluginUid={0x10206A8C}; sl@0: sl@0: sl@0: // Used for supressing warning in OOM tests sl@0: #define __UNUSED_VAR(var) var = var sl@0: sl@0: // sl@0: /** sl@0: @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1776 sl@0: @SYMTestCaseDesc Tests API behaviours of UnicodeConv class sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for conversions from/to Unicode, using a function pointer sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void CT_CP950::TestL() sl@0: { sl@0: INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1776")); sl@0: RLibrary lib; sl@0: sl@0: const TUidType serverUid(KNullUid,KNullUid,KPluginUid); sl@0: // load the dll sl@0: TInt returnValue = lib.Load(KName,serverUid); sl@0: test(returnValue==0); sl@0: sl@0: // get a pointer to the specified ordinal function and call it sl@0: TLibraryFunction function1 = lib.Lookup(1); sl@0: TLibraryFunction function2 = lib.Lookup(2); sl@0: TLibraryFunction function3 = lib.Lookup(3); sl@0: sl@0: //cast the function pointer f to a function of type void with two arguments sl@0: typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); sl@0: TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast (function1); sl@0: sl@0: typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); sl@0: TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast (function2); sl@0: sl@0: typedef TBool (*TIsLegalShortNameCharacter)(TUint); sl@0: TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast (function3); sl@0: sl@0: TBuf8<20> foreign1; sl@0: TBuf16<20> unicode2; sl@0: sl@0: const TDesC16& unicode1(Uni_1); sl@0: (*aConvertFromUnicodeL)(foreign1, unicode1); //testing conversion from Unicode sl@0: TInt error = foreign1.Compare(CP950_1); sl@0: sl@0: test(error==0); sl@0: foreign1.Zero(); sl@0: sl@0: const TDesC8& foreign2(CP950_2); sl@0: (*aConvertToUnicodeL)(unicode2,foreign2); //testing conversion to Unicode sl@0: error = unicode2.Compare(Uni_2); sl@0: test(error==0); sl@0: unicode2.Zero(); sl@0: sl@0: sl@0: //testing for legal short name character sl@0: TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character sl@0: test(result==1); sl@0: result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character sl@0: test(result==0); sl@0: result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character sl@0: test(result==0); sl@0: result = (*aIsLegalShortNameCharacter)(0x3000); //testing for a double byte character sl@0: test(result==1); sl@0: sl@0: lib.Close(); sl@0: } sl@0: sl@0: // test code for INC080460: FATCharsetConv panics - stops china build booting sl@0: void CT_CP950::TestINC080460L() sl@0: { sl@0: RLibrary lib; sl@0: const TUidType serverUid(KNullUid,KNullUid,KPluginUid); sl@0: sl@0: // load the dll sl@0: TInt returnValue = lib.Load(KName,serverUid); sl@0: test(returnValue==0); sl@0: sl@0: // get a pointer to the specified ordinal function and call it sl@0: TLibraryFunction function1 = lib.Lookup(1); sl@0: TLibraryFunction function2 = lib.Lookup(2); sl@0: sl@0: //cast the function pointer f to a function of type void with two arguments sl@0: typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); sl@0: TConvertFromUnicodeL ConvertFromUnicodeL = reinterpret_cast (function1); sl@0: sl@0: typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); sl@0: TConvertToUnicodeL ConvertToUnicodeL = reinterpret_cast (function2); sl@0: sl@0: // the problem in this defect is when the foreign buffer is not big enough the code panics sl@0: // the solution is for the code to leave sl@0: sl@0: // the foreign buffer is 11 (8+3) and there are 17 unicode characters sl@0: TBuf8<11> foreign; sl@0: _LIT16(longUnicode, "\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA"); sl@0: const TDesC16& testUnicode1(longUnicode); sl@0: TInt error = KErrNone; sl@0: sl@0: // ConvertFromUnicodeL - check that this call leaves sl@0: foreign.Zero(); sl@0: TRAP( error, ConvertFromUnicodeL(foreign, testUnicode1)); //testing conversion from Unicode sl@0: test(error == KErrOverflow ); sl@0: sl@0: // ConvertFromUnicodeL - test 1 character to long leaves sl@0: _LIT16(longUnicode2, "FilenameEx\x3122"); sl@0: const TDesC16& testUnicode2(longUnicode2); sl@0: foreign.Zero(); sl@0: error = KErrNone; sl@0: TRAP( error, ConvertFromUnicodeL(foreign, testUnicode2)); //testing conversion from Unicode sl@0: test(error == KErrOverflow ); sl@0: sl@0: // ConvertFromUnicodeL - test 11 character does not leave sl@0: _LIT16(longUnicode3, "FilenameExt"); sl@0: const TDesC16& testUnicode3(longUnicode3); sl@0: foreign.Zero(); sl@0: error = KErrNone; sl@0: TRAP( error, ConvertFromUnicodeL(foreign, testUnicode3)); //testing conversion from Unicode sl@0: test(error == KErrNone ); sl@0: sl@0: // check ConvertToUnicodeL leaves when the buffer is too small sl@0: TBuf16<6> unicodeBuffer; sl@0: _LIT8(sampletext, "this is far to big to fit"); sl@0: const TDesC8& sample(sampletext); sl@0: sl@0: unicodeBuffer.Zero(); sl@0: error = KErrNone; sl@0: TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample)); //testing conversion to Unicode sl@0: test(error==KErrOverflow); sl@0: sl@0: // test 6 characters does NOT leave sl@0: _LIT8( chars6, "abcdef"); sl@0: const TDesC8& sample6(chars6); sl@0: unicodeBuffer.Zero(); sl@0: error = KErrNone; sl@0: TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample6)); //testing conversion to Unicode sl@0: test(error==KErrNone); sl@0: sl@0: // test 7 characters does leave sl@0: _LIT8( chars7, "abcdefg"); sl@0: const TDesC8& sample7(chars7); sl@0: unicodeBuffer.Zero(); sl@0: error = KErrNone; sl@0: TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample7)); //testing conversion to Unicode sl@0: test(error==KErrOverflow); sl@0: sl@0: // test when 7 foreign characters fits in 5 unicode it does NOT leave sl@0: _LIT8( CP950_sample, "\x32\x80\xA1\x70\xC1\x7F\xA7"); sl@0: const TDesC8& sample7to5(CP950_sample); sl@0: unicodeBuffer.Zero(); sl@0: error = KErrNone; sl@0: TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample7to5)); //testing conversion to Unicode sl@0: test(error==KErrNone); sl@0: sl@0: lib.Close(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1847-0003 sl@0: @SYMTestCaseDesc Tests API behaviours of UnicodeConv class as part of INC090073 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for correct character conversion on certain chinese characters for CP936 sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void CT_CP950::TestINC090073L() sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847-0003 ")); sl@0: _LIT16(unicode, "\x7C91\x8026\x8160\x7633\x6DFC\x715C\x6600\x9785\x86D8\x7A37\x61A9\x80B1\x86A3\x89E5\x80F2\x9B48\x6C19\x7B71\x946B\x6B46\x6615"); sl@0: _LIT8(CP950Code, "\xD3\x4A\xBD\xA2\xDF\x73\xEA\x6F\xD9\xE7\xB7\xD4\xA9\xFB\xBB\xDF\xDB\xB1\xBD\x5E\xBE\xCD\xAA\xD0\xB0\x47\xDF\xFD\xD3\x6A\xEF\x69\xCB\x49\xDF\x4E\xF8\xCA\xDD\xF5\xA9\xFD"); sl@0: sl@0: RLibrary lib; sl@0: sl@0: const TUidType serverUid(KNullUid,KNullUid,KPluginUid); sl@0: // load the dll sl@0: TInt returnValue = lib.Load(KName,serverUid); sl@0: test(returnValue==0); sl@0: sl@0: // get a pointer to the specified ordinal function and call it sl@0: TLibraryFunction function1 = lib.Lookup(1); sl@0: sl@0: //cast the function pointer f to a function of type void with two arguments sl@0: typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); sl@0: TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast (function1); sl@0: sl@0: TBuf8<50> foreign1; sl@0: sl@0: foreign1.Zero(); sl@0: const TDesC16& unicode1(unicode); sl@0: TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); //testing conversion from Unicode sl@0: test(err==0); sl@0: TInt error = foreign1.Compare(CP950Code); sl@0: test(error==0); sl@0: foreign1.Zero(); sl@0: sl@0: lib.Close(); sl@0: } sl@0: sl@0: void CT_CP950::OOMTestL() sl@0: { sl@0: INFO_PRINTF1(_L("OOM testing")); sl@0: TInt err, tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: // find out the number of open handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: // Setting Heap failure for OOM test sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: sl@0: TRAP(err,TestL()); sl@0: sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: test(startProcessHandleCount == endProcessHandleCount); sl@0: test(startThreadHandleCount == endThreadHandleCount); sl@0: sl@0: __UHEAP_MARKEND; sl@0: }while (err == KErrNoMemory); sl@0: sl@0: test(err == KErrNone); sl@0: INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: sl@0: CT_CP950::CT_CP950() sl@0: { sl@0: SetTestStepName(KTestStep_T_CP950); sl@0: } sl@0: sl@0: sl@0: TVerdict CT_CP950::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(error1, TestL()); sl@0: TRAPD(error2, TestINC090073L()); sl@0: TRAPD(error3, TestINC080460L()); sl@0: TRAPD(error4, OOMTestL()); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone && error2 == KErrNone && error3 == KErrNone && error4 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }