javamanager/javaregistry/legacy/tsrc/src/testmidletentry.cpp
branchRCL_3
changeset 14 04becd199f91
child 24 6c158198356e
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 #include "javaoslayer.h"
       
    25 #include "javaprocessconstants.h"
       
    26 #include "javastorage.h"
       
    27 #include "javastorageexception.h"
       
    28 #include "javastoragenames.h"
       
    29 #include "javasymbianoslayer.h"
       
    30 #include "javauid.h"
       
    31 #include "logger.h"
       
    32 #include "mjavaregistry.h"
       
    33 #include "storagetestutils.h"
       
    34 
       
    35 using namespace std;
       
    36 using namespace java::storage;
       
    37 using namespace java::util;
       
    38 
       
    39 /**
       
    40  * NOTE: Some of MJavaRegistryMIDletEntry interface methods are already tested
       
    41  * at testlegacyregistry.cpp test case.
       
    42  */
       
    43 TEST_GROUP(TestMIDletEntry)
       
    44 {
       
    45     JavaStorage* js;
       
    46     JavaStorageTestUtils* jtu;
       
    47 
       
    48     TEST_SETUP()
       
    49     {
       
    50         js = JavaStorage::createInstance();
       
    51         jtu = new JavaStorageTestUtils();
       
    52     }
       
    53     TEST_TEARDOWN()
       
    54     {
       
    55         try
       
    56         {
       
    57             js->rollbackTransaction();
       
    58             js->close();
       
    59             delete js;
       
    60             js = NULL;
       
    61         }
       
    62         catch (...)
       
    63         {
       
    64             // No can do
       
    65         }
       
    66 
       
    67         delete js;
       
    68         js = 0;
       
    69         delete jtu;
       
    70         jtu = 0;
       
    71     }
       
    72 };
       
    73 
       
    74 /**
       
    75  * Test CJavaRegistryMIDletEntry::SizeL() method.
       
    76  * 1. Test install MIDlet and check it size.
       
    77  */
       
    78 TEST(TestMIDletEntry, TestSizeL)
       
    79 {
       
    80     LOG(EJavaStorage, EInfo, "+TestSizeL");
       
    81 
       
    82     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
    83     CHECK(registry != NULL);
       
    84 
       
    85     RProcess rJavaInstaller;
       
    86     TFileName fileName;
       
    87     TBuf<400> commandLine;
       
    88 
       
    89     // Build command line used to pass all necessary info to Java Installer
       
    90     std::auto_ptr<HBufC> installerStarterDll(
       
    91         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
       
    92     commandLine = installerStarterDll->Des();
       
    93     commandLine.Append(_L(" install -jar=c:\\HelloWorld1.jar"));
       
    94     commandLine.Append(_L(" -silent -upgrade=yes -ocsp=no"));
       
    95     commandLine.Append(_L(" -download=no -upgrade_data=yes"));
       
    96 
       
    97     // start JavaInstaller
       
    98     std::auto_ptr<HBufC> installerProcess(
       
    99         stringToDes(java::runtime::JAVA_PROCESS));
       
   100     TInt err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   101 
       
   102     TRequestStatus status;
       
   103 
       
   104     if (KErrNone == err)
       
   105     {
       
   106         LOG(EJavaStorage, EInfo, "Calling Logon");
       
   107         // This call will wait until Java Installer exits (or panics)
       
   108         rJavaInstaller.Logon(status);
       
   109 
       
   110         LOG(EJavaStorage, EInfo, "Calling Resume");
       
   111         rJavaInstaller.Resume();
       
   112     }
       
   113     else
       
   114     {
       
   115         ELOG1(EJavaStorage, "Cannot start Installer, error %d", err);
       
   116         User::Leave(err);
       
   117     }
       
   118 
       
   119     LOG(EJavaStorage, EInfo, "Calling RProcess::Close");
       
   120 
       
   121     // now wait until Java Installer exits
       
   122     User::WaitForRequest(status);
       
   123 
       
   124     // free resources before returning
       
   125     rJavaInstaller.Close();
       
   126 
       
   127     RArray<TUid> uids;
       
   128     registry->InstalledMIDletUidsL(uids);
       
   129     CHECK(uids.Count() == 1);
       
   130 
       
   131     MJavaRegistryMIDletEntry* midletEntry
       
   132     = registry->MIDletEntryL(uids[0]);
       
   133     CHECK(midletEntry != NULL);
       
   134 
       
   135     CHECK(midletEntry->SizeL() > 4000);
       
   136 
       
   137     midletEntry->Release();
       
   138 
       
   139     // UNINSTALL
       
   140     // Build command line used to pass all necessary info to Java Installer
       
   141     commandLine = installerStarterDll->Des();
       
   142     commandLine.Append(_L(" uninstall -uid="));
       
   143     TUidName uidName = (uids[0]).Name();
       
   144     commandLine.Append(uidName);
       
   145     uids.Reset();
       
   146     uids.Close();
       
   147     commandLine.Append(_L(" -silent"));
       
   148 
       
   149     // start JavaInstaller
       
   150     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   151 
       
   152     status = KRequestPending;
       
   153 
       
   154     if (KErrNone == err)
       
   155     {
       
   156         LOG(EJavaStorage, EInfo, "Calling Logon");
       
   157         // This call will wait until Java Installer exits (or panics)
       
   158         rJavaInstaller.Logon(status);
       
   159 
       
   160         LOG(EJavaStorage, EInfo, "Calling Resume");
       
   161         rJavaInstaller.Resume();
       
   162     }
       
   163     else
       
   164     {
       
   165         ELOG1(EJavaStorage, "Cannot start Installer, error %d", err);
       
   166         User::Leave(err);
       
   167     }
       
   168 
       
   169     // now wait until Java Installer exits
       
   170     User::WaitForRequest(status);
       
   171 
       
   172     LOG(EJavaStorage, EInfo, "Calling RProcess::Close");
       
   173     // free resources before returning
       
   174     rJavaInstaller.Close();
       
   175 
       
   176     registry->Release();
       
   177 
       
   178     LOG(EJavaStorage, EInfo, "-TestSizeL");
       
   179 }