javamanager/debugapi/tsrc/src.s60/testapplauncher.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19: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 AppLauncher class
       
    15 *
       
    16 */
       
    17 
       
    18 #include "applauncher.h"
       
    19 
       
    20 #include "TestHarness.h"
       
    21 #include "logger.h"
       
    22 #include "commsmessage.h"
       
    23 #include "rtcmessages.h"
       
    24 
       
    25 using namespace std;
       
    26 using namespace java::debug;
       
    27 using namespace java::comms;
       
    28 using namespace java::captain;
       
    29 using java::util::Uid;
       
    30 
       
    31 class TestAppLauncher : public AppLauncher
       
    32 {
       
    33 public:
       
    34     TestAppLauncher(const Uid& aAppUid) : AppLauncher(aAppUid),
       
    35             fail(false), createStartCalled(false), createStopCalled(false), sendToCalled(false) {};
       
    36     virtual ~TestAppLauncher() {};
       
    37 
       
    38     virtual CommsMessage createStartAppMessage(const std::wstring& aJvmArgs)
       
    39     {
       
    40         createStartCalled = true;
       
    41         return AppLauncher::createStartAppMessage(aJvmArgs);
       
    42     };
       
    43     virtual CommsMessage createStopAppMessage()
       
    44     {
       
    45         createStopCalled = true;
       
    46         return AppLauncher::createStopAppMessage();
       
    47     };
       
    48     virtual int sendToJavaCaptain(CommsMessage& aMessage)
       
    49     {
       
    50         sendToCalled = true;
       
    51         if (fail) return -666;
       
    52         return AppLauncher::sendToJavaCaptain(aMessage);
       
    53     };
       
    54 
       
    55     bool fail;
       
    56     bool createStartCalled;
       
    57     bool createStopCalled;
       
    58     bool sendToCalled;
       
    59 };
       
    60 
       
    61 
       
    62 TEST_GROUP(TestAppLauncher)
       
    63 {
       
    64     TEST_SETUP()
       
    65     {
       
    66     }
       
    67 
       
    68     TEST_TEARDOWN()
       
    69     {
       
    70     }
       
    71 };
       
    72 
       
    73 
       
    74 TEST(TestAppLauncher, startApp)
       
    75 {
       
    76     Uid appUid(L"[12345678]");
       
    77     wstring args = L"hello world";
       
    78 
       
    79     TestAppLauncher launcher(appUid);
       
    80     int rc = launcher.startApp(args);
       
    81 
       
    82     CHECK(launcher.createStartCalled);
       
    83     CHECK(launcher.sendToCalled);
       
    84 }
       
    85 
       
    86 TEST(TestAppLauncher, startAppFail)
       
    87 {
       
    88     Uid appUid(L"[12345678]");
       
    89     wstring args = L"hello world";
       
    90 
       
    91     TestAppLauncher launcher(appUid);
       
    92     launcher.fail = true;
       
    93     int rc = launcher.startApp(args);
       
    94 
       
    95     CHECK(rc != 0);
       
    96     CHECK(launcher.createStartCalled);
       
    97     CHECK(launcher.sendToCalled);
       
    98 }
       
    99 
       
   100 TEST(TestAppLauncher, stopApp)
       
   101 {
       
   102     Uid appUid(L"[12345678]");
       
   103 
       
   104     TestAppLauncher launcher(appUid);
       
   105     int rc = launcher.stopApp();
       
   106 
       
   107     CHECK(rc == 0);
       
   108     CHECK(launcher.createStopCalled);
       
   109     CHECK(launcher.sendToCalled);
       
   110 }
       
   111 
       
   112 TEST(TestAppLauncher, stopAppFail)
       
   113 {
       
   114     Uid appUid(L"[12345678]");
       
   115 
       
   116     TestAppLauncher launcher(appUid);
       
   117     launcher.fail = true;
       
   118     int rc = launcher.stopApp();
       
   119 
       
   120     CHECK(rc != 0);
       
   121     CHECK(launcher.createStopCalled);
       
   122     CHECK(launcher.sendToCalled);
       
   123 }
       
   124 
       
   125 
       
   126 TEST(TestAppLauncher, createStartAppMessage)
       
   127 {
       
   128     Uid appUid(L"[12345678]");
       
   129     wstring args = L"hello world";
       
   130 
       
   131     TestAppLauncher launcher(appUid);
       
   132     CommsMessage msg = launcher.createStartAppMessage(args);
       
   133 
       
   134     CHECK(msg.getMessageId() == RTC_MSG_ID_LAUNCH_APPLICATION_REQ);
       
   135     CHECK(msg.getModuleId() == PLUGIN_ID_RTC_C);
       
   136 
       
   137     Uid uid;
       
   138     int launchType = 0;
       
   139     int options = 0;
       
   140     std::string rtc;
       
   141     std::wstring appArgs;
       
   142     std::wstring jvmArgs;
       
   143 
       
   144     getLaunchApplicationReqParams(msg, uid, launchType, options, rtc, appArgs, jvmArgs);
       
   145 
       
   146     CHECK(uid == appUid);
       
   147     CHECK(launchType == RTC_LAUNCH_TYPE_DEBUG_C);
       
   148     CHECK(options == RTC_LAUNCH_OPTIONS_RUNNING_IND_REQ_C);
       
   149     CHECK(rtc.compare(RTC_LAUNCH_RUNTIME_MIDP_C) == 0);
       
   150     CHECK(appArgs.compare(L"") == 0);
       
   151     CHECK(jvmArgs.compare(args) == 0);
       
   152 }
       
   153 
       
   154 TEST(TestAppLauncher, createStopAppMessage)
       
   155 {
       
   156     Uid appUid(L"[12345678]");
       
   157 
       
   158     TestAppLauncher launcher(appUid);
       
   159     CommsMessage msg = launcher.createStopAppMessage();
       
   160 
       
   161     CHECK(msg.getMessageId() == RTC_MSG_ID_TERMINATE_APPLICATION_REQ);
       
   162     CHECK(msg.getModuleId() == PLUGIN_ID_RTC_C);
       
   163 
       
   164     Uid uid;
       
   165     int options = 0;
       
   166 
       
   167     getTerminateApplicationReqParams(msg, uid, options);
       
   168     CHECK(uid == appUid);
       
   169     CHECK(options == RTC_LAUNCH_OPTIONS_TERMINATE_IND_REQ_C);
       
   170 }
       
   171 
       
   172 TEST(TestAppLauncher, sendToJavaCaptain)
       
   173 {
       
   174     Uid appUid(L"[12345678]");
       
   175 
       
   176     TestAppLauncher launcher(appUid);
       
   177     CommsMessage msg = launcher.createStopAppMessage();
       
   178 
       
   179     int rc = launcher.sendToJavaCaptain(msg);
       
   180     CHECK(rc == 0);
       
   181 
       
   182     launcher.fail = true;
       
   183     rc = launcher.sendToJavaCaptain(msg);
       
   184     CHECK(rc != 0);
       
   185 }