javaruntimes/starterutils/tsrc/src/testueiargsparser.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:  Tests for UeiArgsParser class
       
    15 *
       
    16 */
       
    17 
       
    18 #include <string>
       
    19 #include <vector>
       
    20 
       
    21 #include "ueiargsparser.h"
       
    22 
       
    23 #include "TestHarness.h"
       
    24 #include "logger.h"
       
    25 
       
    26 using java::runtime::UeiArgsParser;
       
    27 using namespace std;
       
    28 
       
    29 class ArgsParserTester : public UeiArgsParser
       
    30 {
       
    31 public:
       
    32     // give access to base class's protected functions
       
    33     using UeiArgsParser::getArgs;
       
    34     using UeiArgsParser::isVerbose;
       
    35     using UeiArgsParser::isRundjwp;
       
    36     using UeiArgsParser::convertVerbose;
       
    37     using UeiArgsParser::convertRundjwp;
       
    38     using UeiArgsParser::hasOption;
       
    39     using UeiArgsParser::trimTrailingSpaces;
       
    40 };
       
    41 
       
    42 TEST_GROUP(TestUeiArgsParser)
       
    43 {
       
    44     ArgsParserTester parser;
       
    45     TEST_SETUP()
       
    46     {
       
    47     }
       
    48 
       
    49     TEST_TEARDOWN()
       
    50     {
       
    51     }
       
    52 };
       
    53 
       
    54 
       
    55 
       
    56 TEST(TestUeiArgsParser, convertUeiArgsToJvmArgs)
       
    57 {
       
    58     EXPECT_N_LEAKS(12);
       
    59     wstring uei = L"-classpath midlet.jar"
       
    60                   L" -Xverbose:allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
    61                   L"bytecodes,frames,stackchunks,exceptions,events,threading,monitors,networking"
       
    62                   L" -Xdebug -Xrunjdwp:server=y,address=localhost:8000"
       
    63                   L" -Dproperty=value -Xdescriptor:jad-file -Xdevice:device-name -Xheapsize:2M";
       
    64     wstring expectedResult = L"-verbose:gc,class -Xrunjdwp:server=y,address=localhost:8000";
       
    65 
       
    66     wstring result = parser.convertUeiArgsToJvmArgs(uei);
       
    67     CHECK(result.compare(expectedResult) == 0);
       
    68 }
       
    69 
       
    70 TEST(TestUeiArgsParser, getArgs)
       
    71 {
       
    72     EXPECT_N_LEAKS(4);
       
    73 
       
    74     std::vector<std::wstring> result = parser.getArgs(L"");
       
    75     CHECK(result.size() == 0);
       
    76 
       
    77     result = parser.getArgs(L"-Xverbose");
       
    78     CHECK(result.size() == 1);
       
    79 
       
    80     result = parser.getArgs(L"-Xverbose -Xrunjdwp:server=y,address=localhost:8000");
       
    81     CHECK(result.size() == 2);
       
    82 
       
    83     result = parser.getArgs(L"-Xdebug -Xverbose -Xrunjdwp:server=y,address=localhost:8000");
       
    84     CHECK(result.size() == 3);
       
    85 }
       
    86 
       
    87 TEST(TestUeiArgsParser, isVerbose)
       
    88 {
       
    89     wstring str = L"-Xverbose";
       
    90     CHECK(parser.isVerbose(str) == true);
       
    91 
       
    92     str = L"-Xverbose:all,allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
    93           L"bytecodes,frames,stackchunks,exceptions,events,threading,monitors,networking"
       
    94           L"-Xdebug -Xrunjdwp:server=y,address=localhost:8000";
       
    95     CHECK(parser.isVerbose(str) == true);
       
    96 
       
    97     str = L"-verbose:all,allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
    98           L"bytecodes,frames,stackchunks,exceptions,events,threading,monitors,networking"
       
    99           L"-Xdebug -Xrunjdwp:server=y,address=localhost:8000";
       
   100     CHECK(parser.isVerbose(str) == false);
       
   101 
       
   102     str = L" -Xverbose";
       
   103     CHECK(parser.isVerbose(str) == false);
       
   104     str = L"-xverbose";
       
   105     CHECK(parser.isVerbose(str) == false);
       
   106     str = L"";
       
   107     CHECK(parser.isVerbose(str) == false);
       
   108 }
       
   109 
       
   110 TEST(TestUeiArgsParser, isRundjwp)
       
   111 {
       
   112     wstring str = L"-Xrunjdwp";
       
   113     CHECK(parser.isRundjwp(str) == true);
       
   114 
       
   115     str = L"-Xrunjdwp:server=y,address=localhost:8000";
       
   116     CHECK(parser.isRundjwp(str) == true);
       
   117 
       
   118     str = L"-drunjdwp:server=y,address=localhost:8000";
       
   119     CHECK(parser.isRundjwp(str) == false);
       
   120 
       
   121     str = L" -Xrunjdwp";
       
   122     CHECK(parser.isRundjwp(str) == false);
       
   123     str = L"-drunjdwp";
       
   124     CHECK(parser.isRundjwp(str) == false);
       
   125     str = L"";
       
   126     CHECK(parser.isRundjwp(str) == false);
       
   127 }
       
   128 
       
   129 TEST(TestUeiArgsParser, convertVerbose)
       
   130 {
       
   131     EXPECT_N_LEAKS(7);
       
   132 
       
   133     wstring str = L"-Xverbose:all,allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
   134                   L"bytecodes,frames.stackchunks,exceptions,events,threading,monitors,networking";
       
   135     wstring result = parser.convertVerbose(str);
       
   136     CHECK(result.compare(L"-verbose:gc,class,stack,sizes") == 0);
       
   137 
       
   138     // no all
       
   139     str = L"-Xverbose:allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
   140           L"bytecodes,frames.stackchunks,exceptions,events,threading,monitors,networking";
       
   141     result = parser.convertVerbose(str);
       
   142     CHECK(result.compare(L"-verbose:gc,class") == 0);
       
   143 
       
   144     // only all
       
   145     str = L"-Xverbose:all,allocation,gcverbose,classverbose,verifier,stackmaps,"
       
   146           L"bytecodes,frames.stackchunks,exceptions,events,threading,monitors,networking";
       
   147     result = parser.convertVerbose(str);
       
   148     CHECK(result.compare(L"-verbose:gc,class,stack,sizes") == 0);
       
   149 
       
   150     // only gc
       
   151     str = L"-Xverbose:allocation,gc,gcverbose,classverbose,verifier,stackmaps,"
       
   152           L"bytecodes,frames.stackchunks,exceptions,events,threading,monitors,networking";
       
   153     result = parser.convertVerbose(str);
       
   154     CHECK(result.compare(L"-verbose:gc") == 0);
       
   155 
       
   156     // only class
       
   157     str = L"-Xverbose:allocation,gcverbose,class,classverbose,verifier,stackmaps,"
       
   158           L"bytecodes,frames.stackchunks,exceptions,events,threading,monitors,networking";
       
   159     result = parser.convertVerbose(str);
       
   160     CHECK(result.compare(L"-verbose:class") == 0);
       
   161 
       
   162     // no supported options
       
   163     str = L"-Xverbose:allocation,gcverbose,classverbose,verifier,stackmaps,"
       
   164           L"bytecodes,frames.stackchunks,exceptions,events,threading,monitors,networking";
       
   165     result = parser.convertVerbose(str);
       
   166     CHECK(result.compare(L"-verbose") == 0);
       
   167 
       
   168     // only Xverbose
       
   169     str = L"-Xverbose";
       
   170     result = parser.convertVerbose(str);
       
   171     CHECK(result.compare(L"-verbose") == 0);
       
   172 
       
   173 }
       
   174 
       
   175 TEST(TestUeiArgsParser, convertRundjwp)
       
   176 {
       
   177     wstring str = L"-Xrunjdwp:server=y,address=localhost:8000";
       
   178     wstring result = parser.convertRundjwp(str);
       
   179     CHECK(result.compare(str) == 0);
       
   180 }
       
   181 
       
   182 TEST(TestUeiArgsParser, hasOption)
       
   183 {
       
   184     wstring str = L"-classpath midlet.jar"
       
   185                   L"-Xverbose:all,allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
   186                   L"bytecodes,frames,stackchunks,exceptions,events,threading,monitors,networking"
       
   187                   L"-Xdebug -Xrunjdwp:server=y,address=localhost:8000";
       
   188 
       
   189     CHECK(parser.hasOption(str, L"all") == true);
       
   190     CHECK(parser.hasOption(str, L"class") == true);
       
   191     CHECK(parser.hasOption(str, L"gc") == true);
       
   192     CHECK(parser.hasOption(str, L"8000") == true);
       
   193 
       
   194     CHECK(parser.hasOption(str, L"alloca") == false);
       
   195     CHECK(parser.hasOption(str, L"classv") == false);
       
   196     CHECK(parser.hasOption(str, L"stack") == false);
       
   197 
       
   198     CHECK(parser.hasOption(str, L"ALL") == false);
       
   199     CHECK(parser.hasOption(str, L"CLASS") == false);
       
   200     CHECK(parser.hasOption(str, L"GC") == false);
       
   201 }
       
   202 
       
   203 TEST(TestUeiArgsParser, trimTrailingSpaces)
       
   204 {
       
   205     // string has whitespaces
       
   206     wstring str = L"erase trailing white-spaces   \n";
       
   207     wstring whitespaces = L" \t\f\v\n\r";
       
   208     wstring result = parser.trimTrailingSpaces(str, whitespaces);
       
   209     CHECK(result.compare(L"erase trailing white-spaces") == 0);
       
   210 
       
   211     str = L"erase trailing white-spaces ";
       
   212     result = parser.trimTrailingSpaces(str, L" ");
       
   213     CHECK(result.compare(L"erase trailing white-spaces") == 0);
       
   214 
       
   215     str = L"-verbose: ";
       
   216     result = parser.trimTrailingSpaces(str, L": ");
       
   217     CHECK(result.compare(L"-verbose") == 0);
       
   218 
       
   219     str = L"-verbose:gc,class,";
       
   220     result = parser.trimTrailingSpaces(str, L",");
       
   221     CHECK(result.compare(L"-verbose:gc,class") == 0);
       
   222 
       
   223     // string does not have whitespaces
       
   224     str = L"erase trailing white-spaces";
       
   225     result = parser.trimTrailingSpaces(str, whitespaces);
       
   226     CHECK(result.compare(L"erase trailing white-spaces") == 0);
       
   227 
       
   228     str = L"erase trailing white-spaces";
       
   229     result = parser.trimTrailingSpaces(str, L"kjh");
       
   230     CHECK(result.compare(L"erase trailing white-spaces") == 0);
       
   231 
       
   232     str = L"erase trailing white-spaces";
       
   233     result = parser.trimTrailingSpaces(str, L"e");
       
   234     CHECK(result.compare(L"erase trailing white-spaces") == 0);
       
   235 
       
   236     // empty string
       
   237     wstring empty;
       
   238     result = parser.trimTrailingSpaces(empty, whitespaces);
       
   239     CHECK(result.compare(L"") == 0);
       
   240     empty = L"";
       
   241     result = parser.trimTrailingSpaces(empty, L" ");
       
   242     CHECK(result.compare(L"") == 0);
       
   243 }