javamanager/debugapi/tsrc/src.s60/testjavadebugapi.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 Java Debug API
       
    15 *
       
    16 */
       
    17 #include <string>
       
    18 #include <list>
       
    19 #include <algorithm>
       
    20 #include <memory>
       
    21 #include <sys/types.h>
       
    22 #include <dirent.h>
       
    23 #include <unistd.h>
       
    24 
       
    25 
       
    26 #include "TestHarness.h"
       
    27 #include "logger.h"
       
    28 #include "javacommonutils.h"
       
    29 #include "exceptionbase.h"
       
    30 #include "javasymbianoslayer.h"
       
    31 #include "javadebugapi.h"
       
    32 
       
    33 const char INSTALL_DIR[] = "c:\\java\\debugapitest\\";
       
    34 const char JAD_EXTENSION[] = ".jad";
       
    35 const char JAR_EXTENSION[] = ".jar";
       
    36 
       
    37 const char* UEI_PARAMS = "-Xverbose:all,allocation,gc,gcverbose,class,classverbose,verifier,stackmaps,"
       
    38                          "bytecodes,frames,stackchunks,exceptions,events,threading,monitors,networking"
       
    39                          "-Xdebug -Xrunjdwp:server=y,address=localhost:8000";
       
    40 
       
    41 void logStrings(std::string aArg)
       
    42 {
       
    43     LOG1(EDebugApi, EInfo, " '%s'", aArg.c_str());
       
    44 }
       
    45 
       
    46 std::list<std::string> getFileList(const std::string& aPath, const std::string& aExtension)
       
    47 {
       
    48 
       
    49     std::list<std::string> files;
       
    50 
       
    51     DIR *pDIR = opendir(aPath.c_str());
       
    52     if (pDIR != NULL)
       
    53     {
       
    54         struct dirent* pDirEnt = readdir(pDIR);
       
    55         while (pDirEnt != NULL)
       
    56         {
       
    57             //check if file extension matches
       
    58             if (strcmp((pDirEnt->d_name + strlen(pDirEnt->d_name) - aExtension.length()), aExtension.c_str()) == 0)
       
    59             {
       
    60                 std::string file;
       
    61                 file = aPath + pDirEnt->d_name;
       
    62                 files.push_back(file);
       
    63             }
       
    64             pDirEnt = readdir(pDIR);
       
    65         }
       
    66         closedir(pDIR);
       
    67     }
       
    68 
       
    69     return files;
       
    70 }
       
    71 
       
    72 
       
    73 
       
    74 TEST_GROUP(TestJavaDebugApi)
       
    75 {
       
    76     TEST_SETUP()
       
    77     {
       
    78     }
       
    79 
       
    80     TEST_TEARDOWN()
       
    81     {
       
    82     }
       
    83 };
       
    84 
       
    85 
       
    86 /**
       
    87  * Tests install, start, stop and uninstall for JADs
       
    88  */
       
    89 TEST(TestJavaDebugApi, runAllJads)
       
    90 {
       
    91     std::list<std::string> files;
       
    92     files = getFileList(INSTALL_DIR, JAD_EXTENSION);
       
    93     LOG(EDebugApi, EInfo, "JAD files");
       
    94     std::for_each(files.begin(), files.end(), logStrings);
       
    95 
       
    96     CHECK(files.size() != 0); // fail if no files found
       
    97 
       
    98     for (std::list<std::string>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
       
    99     {
       
   100         // install app
       
   101         std::auto_ptr<HBufC> filename(stringToDes((*iter).c_str()));
       
   102         TUid suiteUid;
       
   103         RArray<TUid> applicationUids;
       
   104         int rc = java::debug::installApp(*filename, suiteUid, applicationUids);
       
   105         CHECK(rc == (int)ETrue);
       
   106 
       
   107         // start and stop each app
       
   108         for (int i = 0; i < applicationUids.Count(); i++)
       
   109         {
       
   110             std::auto_ptr<HBufC> ueiParams(stringToDes(UEI_PARAMS));
       
   111             TProcessId pid;
       
   112             rc = java::debug::startApp(applicationUids[i], *ueiParams, pid);
       
   113             CHECK(rc == (int)ETrue);
       
   114             RProcess process;
       
   115             rc = process.Open(pid);
       
   116             CHECK(rc == KErrNone);
       
   117             TRequestStatus status;
       
   118             process.Logon(status);
       
   119             // wait a while so that runtime has got ueiParams
       
   120             usleep(300000); //0.3s
       
   121             rc = java::debug::stopApp(applicationUids[i]);
       
   122             CHECK(rc == (int)ETrue);
       
   123             User::WaitForRequest(status);
       
   124             process.Close();
       
   125         }
       
   126 
       
   127         // uninstall app
       
   128         rc = java::debug::uninstallApp(suiteUid);
       
   129         CHECK(rc == (int)ETrue);
       
   130 
       
   131         applicationUids.Reset();
       
   132     }
       
   133 }
       
   134 
       
   135 /**
       
   136  * Tests install, start, stop and uninstall for JARs
       
   137  */
       
   138 TEST(TestJavaDebugApi, runAllJars)
       
   139 {
       
   140     EXPECT_N_LEAKS(1);
       
   141     std::list<std::string> files;
       
   142     files = getFileList(INSTALL_DIR, JAR_EXTENSION);
       
   143     LOG(EDebugApi, EInfo, "JAR files");
       
   144     std::for_each(files.begin(), files.end(), logStrings);
       
   145 
       
   146     CHECK(files.size() != 0); // fail if no files found
       
   147 
       
   148     for (std::list<std::string>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
       
   149     {
       
   150         // install app
       
   151         std::auto_ptr<HBufC> filename(stringToDes((*iter).c_str()));
       
   152         TUid suiteUid;
       
   153         RArray<TUid> applicationUids;
       
   154         int rc = java::debug::installApp(*filename, suiteUid, applicationUids);
       
   155         CHECK(rc == (int)ETrue);
       
   156 
       
   157         // start and stop each app
       
   158         for (int i = 0; i < applicationUids.Count(); i++)
       
   159         {
       
   160             std::auto_ptr<HBufC> ueiParams(stringToDes(UEI_PARAMS));
       
   161             TProcessId pid;
       
   162             rc = java::debug::startApp(applicationUids[i], *ueiParams, pid);
       
   163             CHECK(rc == (int)ETrue);
       
   164             RProcess process;
       
   165             rc = process.Open(pid);
       
   166             CHECK(rc == KErrNone);
       
   167             TRequestStatus status;
       
   168             process.Logon(status);
       
   169             // wait a while so that runtime has got ueiParams
       
   170             usleep(300000); //0.3s
       
   171             rc = java::debug::stopApp(applicationUids[i]);
       
   172             CHECK(rc == (int)ETrue);
       
   173             User::WaitForRequest(status);
       
   174             process.Close();
       
   175         }
       
   176 
       
   177         // uninstall app
       
   178         rc = java::debug::uninstallApp(suiteUid);
       
   179         CHECK(rc == (int)ETrue);
       
   180 
       
   181         applicationUids.Reset();
       
   182     }
       
   183 }
       
   184 
       
   185 TEST(TestJavaDebugApi, installError)
       
   186 {
       
   187     std::string file = "thisfiledoesnotexists.jar";
       
   188     std::auto_ptr<HBufC> filename(stringToDes(file.c_str()));
       
   189     TUid suiteUid;
       
   190     RArray<TUid> applicationUids;
       
   191     int rc = java::debug::installApp(*filename, suiteUid, applicationUids);
       
   192     CHECK(rc == (int)EFalse);
       
   193 }
       
   194 
       
   195 TEST(TestJavaDebugApi, uninstallError)
       
   196 {
       
   197     EXPECT_N_LEAKS(1);
       
   198     TUid suiteUid = TUid::Null();
       
   199     int rc = java::debug::uninstallApp(suiteUid);
       
   200     CHECK(rc == (int)EFalse);
       
   201 }
       
   202 
       
   203 TEST(TestJavaDebugApi, startError)
       
   204 {
       
   205     TUid appUid = TUid::Null();
       
   206     std::auto_ptr<HBufC> ueiParams(stringToDes(UEI_PARAMS));
       
   207     TProcessId pid = 0;
       
   208     int rc = java::debug::startApp(appUid, *ueiParams, pid);
       
   209     CHECK(rc == (int)EFalse);
       
   210 }
       
   211 
       
   212 TEST(TestJavaDebugApi, stopError)
       
   213 {
       
   214     EXPECT_N_LEAKS(1);
       
   215     TUid appUid = TUid::Null();
       
   216     int rc = java::debug::stopApp(appUid);
       
   217     CHECK(rc == (int)ETrue);
       
   218 }