javacommons/utils/tsrc/src/testbase64.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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 #include <stdio.h>
       
    19 #include <string>
       
    20 
       
    21 #include "TestHarness.h"
       
    22 
       
    23 #include "javacommonutils.h"
       
    24 
       
    25 using namespace std;
       
    26 using namespace java::util;
       
    27 
       
    28 TEST_GROUP(TestBase64)
       
    29 {
       
    30     TEST_SETUP()
       
    31     {
       
    32     }
       
    33 
       
    34     TEST_TEARDOWN()
       
    35     {
       
    36     }
       
    37 };
       
    38 
       
    39 /**
       
    40  * Test JavaCommonUtils::base64encode().
       
    41  *
       
    42  * 1. Test encode string.
       
    43  * 2. Test encode empty string.
       
    44  * 3. Test encode hard string.
       
    45  * 4. Test encode not supported chars. It is tested that encoding does
       
    46  *    not panic.
       
    47  * 5. Test encode one char string.
       
    48  */
       
    49 TEST(TestBase64, testBase64Encoding)
       
    50 {
       
    51     // 1. Test encode string.
       
    52     string str = "PleaseEncodeMe";
       
    53     string encodedStr = JavaCommonUtils::base64encode(str);
       
    54     string refStr = "UGxlYXNlRW5jb2RlTWU=";
       
    55     CHECK(refStr == encodedStr);
       
    56 
       
    57     // 2. Test encode empty string.
       
    58     str = "";
       
    59     encodedStr = JavaCommonUtils::base64encode(str);
       
    60     refStr = "";
       
    61     CHECK(refStr == encodedStr);
       
    62 
       
    63     // 3. Test encode hard string "a. b"c#d&G"
       
    64     str = "aAzZ+/";
       
    65     encodedStr = JavaCommonUtils::base64encode(str);
       
    66     refStr = "YUF6Wisv";
       
    67     CHECK(refStr == encodedStr);
       
    68 
       
    69     // 4. Test encode not supported chars.
       
    70     str = "!\"#¤%&/()=?´´'*äö-.,;:_\\<>|@£$€";
       
    71     encodedStr = JavaCommonUtils::base64encode(str);
       
    72 
       
    73     // 5. Test encode one char string.
       
    74     str = "x";
       
    75     encodedStr = JavaCommonUtils::base64encode(str);
       
    76     refStr = "eA==";
       
    77     CHECK(refStr == encodedStr);
       
    78 }
       
    79 
       
    80 /**
       
    81  * Test JavaCommonUtils::base64encode().
       
    82  *
       
    83  * 1. Test decode valid string.
       
    84  * 2. Test decode empty string.
       
    85  * 3. Test decode hard string.
       
    86  * 3. Test decode not supported chars. It is tested that encoding does
       
    87  *    not panic.
       
    88  * 4. Test decode one char.
       
    89  */
       
    90 TEST(TestBase64, base64decode)
       
    91 {
       
    92     // 1. Test encode string.
       
    93     string str = "UGxlYXNlRW5jb2RlTWU=";
       
    94     string encodedStr = JavaCommonUtils::base64decode(str);
       
    95     string refStr = "PleaseEncodeMe";
       
    96     CHECK(refStr == encodedStr);
       
    97 
       
    98     // 2. Test encode empty string.
       
    99     str = "";
       
   100     encodedStr = JavaCommonUtils::base64decode(str);
       
   101     refStr = "";
       
   102     CHECK(refStr == encodedStr);
       
   103 
       
   104     // 3. Test encode hard string.
       
   105     str = "YUF6Wisv";
       
   106     encodedStr = JavaCommonUtils::base64decode(str);
       
   107     refStr = "aAzZ+/";
       
   108     CHECK(refStr == encodedStr);
       
   109 
       
   110     // 4. Test encode not supported chars.
       
   111     str = "!\"#¤%&/()=?´´'*äö-.,;:_\\<>|@£$€";
       
   112     encodedStr = JavaCommonUtils::base64decode(str);
       
   113 
       
   114     // 5. Test encode one char string.
       
   115     str = "eA==";
       
   116     encodedStr = JavaCommonUtils::base64decode(str);
       
   117     refStr = "x";
       
   118     CHECK(refStr == encodedStr);
       
   119 
       
   120 }