charconvfw/Charconv/ongoing/test/source/utf/TIMAP.CPP
changeset 32 8b9155204a54
equal deleted inserted replaced
31:b9ad20498fb4 32:8b9155204a54
       
     1 /*
       
     2 * Copyright (c) 1997-2005 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 the License "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 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include <e32std.h>
       
    26 #include <e32base.h>
       
    27 #include <e32test.h>
       
    28 #include <f32file.h>
       
    29 #include <charconv.h>
       
    30 
       
    31 ///////////////////////////////////////////////////////////////////////////////////////
       
    32 
       
    33 RTest TheTest(_L("TImap"));
       
    34 	
       
    35 ///////////////////////////////////////////////////////////////////////////////////////
       
    36 ///////////////////////////////////////////////////////////////////////////////////////
       
    37 //Tests macroses and functions.
       
    38 //If (!aValue) then the test will be panicked, the test data files will be deleted.
       
    39 static void Check(TInt aValue, TInt aLine)
       
    40 	{
       
    41 	if(!aValue)
       
    42 		{
       
    43 		TheTest(EFalse, aLine);
       
    44 		}
       
    45 	}
       
    46 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
       
    47 static void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    48 	{
       
    49 	if(aValue != aExpected)
       
    50 		{
       
    51 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    52 		TheTest(EFalse, aLine);
       
    53 		}
       
    54 	}
       
    55 //Use these to test conditions.
       
    56 #define TEST(arg) ::Check((arg), __LINE__)
       
    57 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    58 
       
    59 ///////////////////////////////////////////////////////////////////////////////////////
       
    60 ///////////////////////////////////////////////////////////////////////////////////////
       
    61 /**
       
    62 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0574
       
    63 @SYMTestCaseDesc        Tests for converting to Unicode from UTF- 7, from UTF-7 to Unicode
       
    64 @SYMTestPriority        Medium
       
    65 @SYMTestActions        	Tests for CCnvCharacterSetConverter::ConvertToUnicode(),
       
    66 						CCnvCharacterSetConverter::ConvertFromUnicode() function
       
    67 @SYMTestExpectedResults Test must not fail
       
    68 @SYMREQ                 REQ0000
       
    69 */
       
    70 LOCAL_C void DoE32MainL()
       
    71 	{
       
    72 	RFs fileServerSession;
       
    73 	CleanupClosePushL(fileServerSession);
       
    74 	User::LeaveIfError(fileServerSession.Connect());
       
    75 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
       
    76 	TInt state=CCnvCharacterSetConverter::KStateDefault;
       
    77 	TheTest.Start(_L("Testing IMAP UTF-7"));
       
    78 	TEST(characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierImapUtf7, fileServerSession)==CCnvCharacterSetConverter::EAvailable);
       
    79 	TBuf16<256> originalUnicode;
       
    80 	TBuf8<256> generatedUtf7;
       
    81 	TBuf16<256> generatedUnicode;
       
    82 	//
       
    83 	TheTest.Next(_L("Empty descriptor"));
       
    84 	originalUnicode=_L16("");
       
    85 	TEST(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
       
    86 	TEST(generatedUtf7==_L8(""));
       
    87 	TEST(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
       
    88 	TEST(state==CCnvCharacterSetConverter::KStateDefault);
       
    89 	TEST(generatedUnicode==originalUnicode);
       
    90 	TheTest.Next(_L("Characters \" +&-~\\\""));
       
    91 	originalUnicode=_L16(" +&-~\\");
       
    92 	TEST(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
       
    93 	TEST(generatedUtf7==_L8(" +&--~\\"));
       
    94 	TEST(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
       
    95 	TEST(state==CCnvCharacterSetConverter::KStateDefault);
       
    96 	TEST(generatedUnicode==originalUnicode);
       
    97 	TheTest.Next(_L("Example quoted in RFC 2060 (Section 5.1.3)"));
       
    98 	originalUnicode.Format(_L16("~peter/mail/%c%c%c/%c%c"), 0x65e5, 0x672c, 0x8a9e, 0x53f0, 0x5317);
       
    99 	TEST(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
       
   100 	TEST(generatedUtf7==_L8("~peter/mail/&ZeVnLIqe-/&U,BTFw-"));
       
   101 	TEST(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
       
   102 	TEST(state==CCnvCharacterSetConverter::KStateDefault);
       
   103 	TEST(generatedUnicode==originalUnicode);
       
   104 	TheTest.Next(_L("Testing fix for defect EDNDSEF-4KMEUH in \"Symbian Defect Tracking v3.0\""));
       
   105 	originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c%c"), 0x30ad, 0x30e3, 0x30d3, 0x30cd, 0x30c3, 0x30c8, 0x3068, 0x306f, 0xff1f);
       
   106 	TEST(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
       
   107 	TEST(generatedUtf7==_L8("&MK0w4zDTMM0wwzDIMGgwb,8f-"));
       
   108 	TEST(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
       
   109 	TEST(state==CCnvCharacterSetConverter::KStateDefault);
       
   110 	TEST(generatedUnicode==originalUnicode);
       
   111 	TBuf8<0x14> generatedUtf7_0x14;
       
   112 	TEST(characterSetConverter->ConvertFromUnicode(generatedUtf7_0x14, originalUnicode)==3);
       
   113 	TEST(generatedUtf7_0x14==_L8("&MK0w4zDTMM0wwzDI-"));
       
   114 	TEST(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7_0x14, state)==0);
       
   115 	TEST(state==CCnvCharacterSetConverter::KStateDefault);
       
   116 	TEST(generatedUnicode==originalUnicode.Left(6));
       
   117 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
       
   118 	}
       
   119 
       
   120 GLDEF_C TInt E32Main()
       
   121 	{
       
   122 	__UHEAP_MARK;
       
   123 
       
   124 	TheTest.Title();
       
   125 
       
   126 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   127 	TEST(trapCleanup != NULL);
       
   128 
       
   129 	TRAPD(error, DoE32MainL());
       
   130 	TEST2(error, KErrNone);
       
   131 
       
   132 	delete trapCleanup;
       
   133 
       
   134 	TheTest.End();
       
   135 	TheTest.Close();
       
   136 
       
   137 	__UHEAP_MARKEND;
       
   138 	return KErrNone;
       
   139 	}
       
   140