os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_iscii.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_iscii.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009-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_iscii.h"
    1.27 +
    1.28 +const TUint KCharacterSetIdentifier=KCharacterSetIdentifierIscii;
    1.29 +
    1.30 +#define test(cond)                                  \
    1.31 +    {                                               \
    1.32 +    TBool __bb = (cond);                            \
    1.33 +    TEST(__bb);                                     \
    1.34 +    if (!__bb)                                      \
    1.35 +        {                                           \
    1.36 +        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    1.37 +        User::Leave(1);                             \
    1.38 +        }                                           \
    1.39 +    }
    1.40 +
    1.41 +
    1.42 +const TInt KBufferLength=100;
    1.43 +
    1.44 +void CT_ISCII::TestConversionToUnicodeFromISCII(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalISCII, TInt aExpectedResult)
    1.45 +    {
    1.46 +    TInt state=CCnvCharacterSetConverter::KStateDefault;
    1.47 +    TBuf16<KBufferLength> generatedUnicode;
    1.48 +    const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalISCII, state);
    1.49 +    test(returnValue == aExpectedResult );
    1.50 +    test(generatedUnicode==aExpectedUnicode);
    1.51 +    }
    1.52 +
    1.53 +void CT_ISCII::TestConversionToUnicodeFromTruncatedISCII(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16&, const TDesC8& aOriginalISCII, TInt aExpectedResult)
    1.54 +    {
    1.55 +    TInt state=CCnvCharacterSetConverter::KStateDefault;
    1.56 +    TBuf16<KBufferLength> generatedUnicode;
    1.57 +    const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalISCII, state);
    1.58 +    test(returnValue != aExpectedResult );
    1.59 +    }
    1.60 +
    1.61 +void CT_ISCII::TestConversionFromUnicodeToISCII(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode, const TDesC8& aExpectedISCII, TInt aExpectedResult)
    1.62 +    {
    1.63 +    TBuf8<KBufferLength> generatedISCII;
    1.64 +    const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedISCII, aOriginalUnicode);
    1.65 +    test(returnValue == aExpectedResult);
    1.66 +    test(generatedISCII==aExpectedISCII);
    1.67 +    }
    1.68 +
    1.69 +void CT_ISCII::TestConversion( CCnvCharacterSetConverter& aCharacterSetConverter )
    1.70 +{
    1.71 +    TestConversionFromUnicodeToISCII(aCharacterSetConverter, _L16("\x0079"), _L8("\xef\x42\x79"));
    1.72 +    TestConversionToUnicodeFromISCII(aCharacterSetConverter, _L16("\x0079"), _L8("\x79"));
    1.73 +
    1.74 +    TestConversionFromUnicodeToISCII(aCharacterSetConverter, _L16("\x0079\x007a\x0070\x0071\x0072\x0073\x0074\x0075"), _L8("\xef\x42\x79\x7a\x70\x71\x72\x73\x74\x75"));
    1.75 +    TestConversionToUnicodeFromISCII(aCharacterSetConverter, _L16("\x0079\x007a\x0070\x0071\x0072\x0073\x0074\x0075"), _L8("\x79\x7a\x70\x71\x72\x73\x74\x75"));
    1.76 +    TestConversionToUnicodeFromISCII(aCharacterSetConverter, _L16("\x0079\x007a\x0070\x0071\x0072\x0073\x0074\x0075\x0901"), _L8("\x79\x7a\x70\x71\x72\x73\x74\x75\xa1"));
    1.77 +    TestConversionToUnicodeFromISCII(aCharacterSetConverter, _L16("\x0079\x007a\x0070\x0071\x0072\x0073\x0074\x0075\x0901\x093d"), _L8("\x79\x7a\x70\x71\x72\x73\x74\x75\xa1\xea\xe9"));
    1.78 +    
    1.79 +    TestConversionFromUnicodeToISCII(aCharacterSetConverter, _L16("\x0901"), _L8("\xef\x42\xa1"));
    1.80 +    TestConversionToUnicodeFromISCII(aCharacterSetConverter, _L16("\x0901\x0079"), _L8("\xa1\x79"));
    1.81 +    TestConversionToUnicodeFromTruncatedISCII(aCharacterSetConverter, _L16("\x0901"), _L8("\xa1"));
    1.82 +    
    1.83 +    TestConversionFromUnicodeToISCII(aCharacterSetConverter, _L16("\x094d"), _L8("\xef\x42\xe8"));
    1.84 +    TestConversionFromUnicodeToISCII(aCharacterSetConverter, _L16("\x200c"), _L8("\xef\x42\xe8"));
    1.85 +    TestConversionToUnicodeFromISCII(aCharacterSetConverter, _L16("\x094d\x0079"), _L8("\xe8\x79"));
    1.86 +    
    1.87 +    TestConversionFromUnicodeToISCII(aCharacterSetConverter, _L16("\x0950"), _L8("\xef\x42\xa1\xe9"));
    1.88 +}
    1.89 +
    1.90 +void CT_ISCII::DoE32MainL()
    1.91 +	{
    1.92 +	RFs fileServerSession;
    1.93 +	CleanupClosePushL(fileServerSession);
    1.94 +	User::LeaveIfError(fileServerSession.Connect());
    1.95 +	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
    1.96 +	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
    1.97 +		CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    1.98 +	
    1.99 +	INFO_PRINTF1(_L("Available:\n"));
   1.100 +	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
   1.101 +		{
   1.102 +		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
   1.103 +		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
   1.104 +		TPtrC charactersSetName(charactersSet.Name());
   1.105 +		if (charactersSet.NameIsFileName())
   1.106 +			{
   1.107 +			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
   1.108 +			}
   1.109 +		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
   1.110 +		}
   1.111 +		
   1.112 +	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession);
   1.113 +
   1.114 +    TestConversion( *characterSetConverter );
   1.115 +    
   1.116 + 	CleanupStack::PopAndDestroy(3);
   1.117 +        }
   1.118 +
   1.119 +CT_ISCII::CT_ISCII()
   1.120 +    {
   1.121 +    SetTestStepName(KTestStep_T_ISCII);
   1.122 +    }
   1.123 +
   1.124 +TVerdict CT_ISCII::doTestStepL()
   1.125 +    {
   1.126 +    SetTestStepResult(EFail);
   1.127 +
   1.128 +    __UHEAP_MARK;
   1.129 +    TRAPD(error1, DoE32MainL());    
   1.130 +    __UHEAP_MARKEND;
   1.131 +
   1.132 +    if(error1 == KErrNone)
   1.133 +        {
   1.134 +        SetTestStepResult(EPass);
   1.135 +        }
   1.136 +
   1.137 +    return TestStepResult();
   1.138 +    }