os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/timap.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 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 "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 #include <e32std.h>
    20 #include <e32base.h>
    21 #include <f32file.h>
    22 #include <charconv.h>
    23 #include "t_imap.h"
    24 
    25 
    26 #define test(cond)                                          \
    27     {                                                       \
    28     TBool __bb = (cond);                                    \
    29     TEST(__bb);                                             \
    30     if (!__bb)                                              \
    31         {                                                   \
    32         ERR_PRINTF1(_L("ERROR: Test Failed"));              \
    33         User::Leave(1);                                     \
    34         }                                                   \
    35     }
    36 
    37 
    38 ///////////////////////////////////////////////////////////////////////////////////////
    39 ///////////////////////////////////////////////////////////////////////////////////////
    40 /**
    41 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0574
    42 @SYMTestCaseDesc        Tests for converting to Unicode from UTF- 7, from UTF-7 to Unicode
    43 @SYMTestPriority        Medium
    44 @SYMTestActions        	Tests for CCnvCharacterSetConverter::ConvertToUnicode(),
    45 						CCnvCharacterSetConverter::ConvertFromUnicode() function
    46 @SYMTestExpectedResults Test must not fail
    47 @SYMREQ                 REQ0000
    48 */
    49 void CT_IMAP::TestIMAP()
    50 	{
    51 	RFs fileServerSession;
    52 	CleanupClosePushL(fileServerSession);
    53 	User::LeaveIfError(fileServerSession.Connect());
    54 	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
    55 	TInt state=CCnvCharacterSetConverter::KStateDefault;
    56 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0574 Testing IMAP UTF-7 "));
    57 	test(characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierImapUtf7, fileServerSession)==CCnvCharacterSetConverter::EAvailable);
    58 	TBuf16<256> originalUnicode;
    59 	TBuf8<256> generatedUtf7;
    60 	TBuf16<256> generatedUnicode;
    61 	//
    62 	INFO_PRINTF1(_L("Empty descriptor"));
    63 	originalUnicode=_L16("");
    64 	test(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
    65 	test(generatedUtf7==_L8(""));
    66 	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
    67 	test(state==CCnvCharacterSetConverter::KStateDefault);
    68 	test(generatedUnicode==originalUnicode);
    69 	INFO_PRINTF1(_L("Characters \" +&-~\\\""));
    70 	originalUnicode=_L16(" +&-~\\");
    71 	test(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
    72 	test(generatedUtf7==_L8(" +&--~\\"));
    73 	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
    74 	test(state==CCnvCharacterSetConverter::KStateDefault);
    75 	test(generatedUnicode==originalUnicode);
    76 	INFO_PRINTF1(_L("Example quoted in RFC 2060 (Section 5.1.3)"));
    77 	originalUnicode.Format(_L16("~peter/mail/%c%c%c/%c%c"), 0x65e5, 0x672c, 0x8a9e, 0x53f0, 0x5317);
    78 	test(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
    79 	test(generatedUtf7==_L8("~peter/mail/&ZeVnLIqe-/&U,BTFw-"));
    80 	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
    81 	test(state==CCnvCharacterSetConverter::KStateDefault);
    82 	test(generatedUnicode==originalUnicode);
    83 	INFO_PRINTF1(_L("Testing fix for defect EDNDSEF-4KMEUH in \"Symbian Defect Tracking v3.0\""));
    84 	originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c%c"), 0x30ad, 0x30e3, 0x30d3, 0x30cd, 0x30c3, 0x30c8, 0x3068, 0x306f, 0xff1f);
    85 	test(characterSetConverter->ConvertFromUnicode(generatedUtf7, originalUnicode)==0);
    86 	test(generatedUtf7==_L8("&MK0w4zDTMM0wwzDIMGgwb,8f-"));
    87 	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7, state)==0);
    88 	test(state==CCnvCharacterSetConverter::KStateDefault);
    89 	test(generatedUnicode==originalUnicode);
    90 	TBuf8<0x14> generatedUtf7_0x14;
    91 	test(characterSetConverter->ConvertFromUnicode(generatedUtf7_0x14, originalUnicode)==3);
    92 	test(generatedUtf7_0x14==_L8("&MK0w4zDTMM0wwzDI-"));
    93 	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedUtf7_0x14, state)==0);
    94 	test(state==CCnvCharacterSetConverter::KStateDefault);
    95 	test(generatedUnicode==originalUnicode.Left(6));
    96 	CleanupStack::PopAndDestroy(2); // characterSetConverter and fileServerSession
    97 	}
    98 
    99 CT_IMAP::CT_IMAP()
   100     {
   101     SetTestStepName(KTestStep_T_IMAP);
   102     }
   103 
   104 TVerdict CT_IMAP::doTestStepL()
   105     {
   106     SetTestStepResult(EFail);
   107 
   108     __UHEAP_MARK;
   109 
   110     TRAPD(error1, TestIMAP());
   111 
   112     __UHEAP_MARKEND;
   113 
   114     if(error1 == KErrNone )
   115         {
   116         SetTestStepResult(EPass);
   117         }
   118 
   119     return TestStepResult();
   120     }