javamanager/javaregistry/legacy/tsrc/src/testinstalledappsregistryentry.cpp
branchRCL_3
changeset 19 04becd199f91
child 48 e0d6e9bd3ca7
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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <string>
       
    20 
       
    21 #include "TestHarness.h"
       
    22 
       
    23 #include "javastorage.h"
       
    24 #include "javastorageexception.h"
       
    25 #include "javastoragenames.h"
       
    26 #include "javauid.h"
       
    27 #include "javaprocessconstants.h"
       
    28 #include "javasymbianoslayer.h"
       
    29 
       
    30 #include "storagetestutils.h"
       
    31 #include "javaregistry.h"
       
    32 #include "javaregistryentry.h"
       
    33 #include "logger.h"
       
    34 #include "minstalledappsregistry.h"
       
    35 
       
    36 using namespace std;
       
    37 using namespace Java;
       
    38 using namespace java::storage;
       
    39 using namespace java::util;
       
    40 
       
    41 const JavaStorageApplicationEntry_t createEntry(const wstring& aUid,
       
    42         const wstring& aName,
       
    43         const wstring& aValue);
       
    44 
       
    45 const JavaStorageApplicationEntry_t createValidCertsEntry(
       
    46     const wstring& aUid,
       
    47     const wstring& aCerts);
       
    48 
       
    49 TEST_GROUP(TestInstalledAppsRegistryEntry)
       
    50 {
       
    51     JavaStorage* js;
       
    52     JavaStorageTestUtils* jtu;
       
    53 
       
    54     TEST_SETUP()
       
    55     {
       
    56         js = JavaStorage::createInstance();
       
    57         jtu = new JavaStorageTestUtils();
       
    58     }
       
    59     TEST_TEARDOWN()
       
    60     {
       
    61         try
       
    62         {
       
    63             js->rollbackTransaction();
       
    64             js->close();
       
    65             delete js;
       
    66             js = NULL;
       
    67         }
       
    68         catch (...)
       
    69         {
       
    70             // No can do
       
    71         }
       
    72 
       
    73         delete js;
       
    74         js = 0;
       
    75         delete jtu;
       
    76         jtu = 0;
       
    77     }
       
    78 };
       
    79 
       
    80 /**
       
    81  * Test CInstalledAppsRegistryEntry::SizeL() method.
       
    82  * 1. Test install MIDlet suite and check suite and midlet size.
       
    83  */
       
    84 TEST(TestInstalledAppsRegistryEntry, TestSizeL)
       
    85 {
       
    86     LOG(EJavaStorage, EInfo, "+TestSizeL");
       
    87 
       
    88     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
    89     CleanupReleasePushL(*appsRegistry);
       
    90 
       
    91     RProcess rJavaInstaller;
       
    92     TFileName fileName;
       
    93     TBuf<400> commandLine;
       
    94 
       
    95     // Build command line used to pass all necessary info to Java Installer
       
    96     std::auto_ptr<HBufC> installerStarterDll(
       
    97         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
       
    98     commandLine = installerStarterDll->Des();
       
    99     commandLine.Append(_L(" install -jar=c:\\HelloWorld1.jar"));
       
   100     commandLine.Append(_L(" -silent -upgrade=yes -ocsp=no"));
       
   101     commandLine.Append(_L(" -download=no -upgrade_data=yes"));
       
   102 
       
   103     // start JavaInstaller
       
   104     std::auto_ptr<HBufC> installerProcess(
       
   105         stringToDes(java::runtime::JAVA_PROCESS));
       
   106     TInt err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   107 
       
   108     TRequestStatus status;
       
   109 
       
   110     if (KErrNone == err)
       
   111     {
       
   112         LOG(EJavaStorage, EInfo, "Calling Logon");
       
   113         // This call will wait until Java Installer exits (or panics)
       
   114         rJavaInstaller.Logon(status);
       
   115 
       
   116         LOG(EJavaStorage, EInfo, "Calling Resume");
       
   117         rJavaInstaller.Resume();
       
   118     }
       
   119     else
       
   120     {
       
   121         ELOG1(EJavaStorage, "Cannot start Installer, error %d", err);
       
   122         User::Leave(err);
       
   123     }
       
   124 
       
   125     LOG(EJavaStorage, EInfo, "Calling RProcess::Close");
       
   126 
       
   127     // now wait until Java Installer exits
       
   128     User::WaitForRequest(status);
       
   129 
       
   130     // free resources before returning
       
   131     rJavaInstaller.Close();
       
   132 
       
   133     RArray<TUid> uids;
       
   134     appsRegistry->InstalledUidsL(uids);
       
   135     CHECK(uids.Count() == 2); // One app and suite installed
       
   136 
       
   137     // Size is fetched through Suite and application.
       
   138     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(uids[0]);
       
   139     CleanupReleasePushL(*entry);
       
   140 
       
   141     CHECK(entry->SizeL() > 4000);
       
   142 
       
   143     CleanupStack::PopAndDestroy(entry);
       
   144 
       
   145     entry = appsRegistry->EntryL(uids[1]);
       
   146     CleanupReleasePushL(*entry);
       
   147 
       
   148     CHECK(entry->SizeL() > 4000);
       
   149     CleanupStack::PopAndDestroy(entry);
       
   150 
       
   151     // UNINSTALL
       
   152     // Build command line used to pass all necessary info to Java Installer
       
   153     commandLine = installerStarterDll->Des();
       
   154     commandLine.Append(_L(" uninstall -uid="));
       
   155     TUidName uidName = (uids[0]).Name();
       
   156     commandLine.Append(uidName);
       
   157     uids.Reset();
       
   158     uids.Close();
       
   159     commandLine.Append(_L(" -silent"));
       
   160 
       
   161     // start JavaInstaller
       
   162     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   163 
       
   164     status = KRequestPending;
       
   165 
       
   166     if (KErrNone == err)
       
   167     {
       
   168         LOG(EJavaStorage, EInfo, "Calling Logon");
       
   169         // This call will wait until Java Installer exits (or panics)
       
   170         rJavaInstaller.Logon(status);
       
   171 
       
   172         LOG(EJavaStorage, EInfo, "Calling Resume");
       
   173         rJavaInstaller.Resume();
       
   174     }
       
   175     else
       
   176     {
       
   177         ELOG1(EJavaStorage, "Cannot start Installer, error %d", err);
       
   178         User::Leave(err);
       
   179     }
       
   180 
       
   181     // now wait until Java Installer exits
       
   182     User::WaitForRequest(status);
       
   183 
       
   184     LOG(EJavaStorage, EInfo, "Calling RProcess::Close");
       
   185     // free resources before returning
       
   186     rJavaInstaller.Close();
       
   187 
       
   188     CleanupStack::PopAndDestroy(appsRegistry);
       
   189     LOG(EJavaStorage, EInfo, "-TestSizeL");
       
   190 }
       
   191 
       
   192 /**
       
   193  * Test CInstalledAppsRegistryEntry::UidL() method.
       
   194  * 1. Application uid.
       
   195  * 2. Application suite uid.
       
   196  * NOTE: Invalid Uid cannot be tested as it cannot be queried.
       
   197  */
       
   198 TEST(TestInstalledAppsRegistryEntry, TestUidL)
       
   199 {
       
   200     LOG(EJavaStorage, EInfo, "+TestUidL");
       
   201 
       
   202     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
   203     CleanupReleasePushL(*appsRegistry);
       
   204 
       
   205     JavaStorageApplicationEntry_t midlet1;
       
   206     JavaStorageEntry attr;
       
   207 
       
   208     Uid suite1Uid(L"[e22a4577]");
       
   209 
       
   210     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   211     midlet1.insert(attr);
       
   212 
       
   213     Uid midlet1Uid(L"[e22a4588]");
       
   214 
       
   215     attr.setEntry(ID, midlet1Uid.toString());
       
   216     midlet1.insert(attr);
       
   217 
       
   218     js->open();
       
   219     js->startTransaction();
       
   220     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   221 
       
   222     JavaStorageApplicationEntry_t suite1;
       
   223     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   224     suite1.insert(attr);
       
   225 
       
   226     attr.setEntry(ID, suite1Uid.toString());
       
   227     suite1.insert(attr);
       
   228 
       
   229     attr.setEntry(MEDIA_ID, L"-124614446");
       
   230     suite1.insert(attr);
       
   231 
       
   232     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   233     js->commitTransaction();
       
   234 
       
   235     // 1. Application uid.
       
   236     TUid midletUid;
       
   237     uidToTUid(midlet1Uid, midletUid);
       
   238 
       
   239     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(midletUid);
       
   240     CHECK(entry != NULL);
       
   241     CleanupReleasePushL(*entry);
       
   242 
       
   243     CHECK(entry->UidL() == midletUid);
       
   244     CleanupStack::PopAndDestroy(entry);
       
   245 
       
   246     // 2. Application suite uid.
       
   247     TUid suiteUid;
       
   248     uidToTUid(suite1Uid, suiteUid);
       
   249 
       
   250     entry = appsRegistry->EntryL(suiteUid);
       
   251     CHECK(entry != NULL);
       
   252     CleanupReleasePushL(*entry);
       
   253 
       
   254     CHECK(entry->UidL() == suiteUid);
       
   255     CleanupStack::PopAndDestroy(entry);
       
   256 
       
   257     // Clean
       
   258     js->startTransaction();
       
   259     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   260     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   261     js->commitTransaction();
       
   262     js->close();
       
   263 
       
   264     CleanupStack::PopAndDestroy(appsRegistry);
       
   265     LOG(EJavaStorage, EInfo, "-TestUidL");
       
   266 }
       
   267 
       
   268 /**
       
   269  * Test CInstalledAppsRegistryEntry::VersionL() method.
       
   270  * 1. Test version set via suite.
       
   271  * 2. Test version via application.
       
   272  * 3. Test version not set via suite. Version is 0.0.0.
       
   273  * 4. Test version not set via application. Version is 0.0.0.
       
   274  */
       
   275 TEST(TestInstalledAppsRegistryEntry, TestVersionL)
       
   276 {
       
   277     LOG(EJavaStorage, EInfo, "+TestVersionL");
       
   278 
       
   279     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
   280     CleanupReleasePushL(*appsRegistry);
       
   281 
       
   282     JavaStorageApplicationEntry_t midlet1;
       
   283     JavaStorageEntry attr;
       
   284 
       
   285     Uid suite1Uid(L"[e22a4577]");
       
   286 
       
   287     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   288     midlet1.insert(attr);
       
   289 
       
   290     Uid midlet1Uid(L"[e22a4588]");
       
   291 
       
   292     attr.setEntry(ID, midlet1Uid.toString());
       
   293     midlet1.insert(attr);
       
   294 
       
   295     js->open();
       
   296     js->startTransaction();
       
   297     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   298 
       
   299     JavaStorageApplicationEntry_t suite1;
       
   300     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   301     suite1.insert(attr);
       
   302 
       
   303     wstring vendor = L"SuiteVendor";
       
   304     attr.setEntry(VENDOR, vendor);
       
   305     suite1.insert(attr);
       
   306 
       
   307     attr.setEntry(VERSION, L"0.1");
       
   308     suite1.insert(attr);
       
   309 
       
   310     attr.setEntry(ID, suite1Uid.toString());
       
   311     suite1.insert(attr);
       
   312 
       
   313     attr.setEntry(MEDIA_ID, L"-124614446");
       
   314     suite1.insert(attr);
       
   315 
       
   316     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   317     js->commitTransaction();
       
   318 
       
   319     TUid suiteUid;
       
   320     uidToTUid(suite1Uid, suiteUid);
       
   321 
       
   322     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(suiteUid);
       
   323     CHECK(entry != NULL);
       
   324     CleanupReleasePushL(*entry);
       
   325 
       
   326     TAppVersion appVersion = entry->VersionL();
       
   327     TAppVersion refVersion(0, 1, 0);
       
   328 
       
   329     CHECK(appVersion.iMajor == refVersion.iMajor);
       
   330     CHECK(appVersion.iMinor == refVersion.iMinor);
       
   331     CHECK(appVersion.iBuild == refVersion.iBuild);
       
   332 
       
   333     CleanupStack::PopAndDestroy(entry);
       
   334 
       
   335     TUid midletUid;
       
   336     uidToTUid(midlet1Uid, midletUid);
       
   337 
       
   338     entry = appsRegistry->EntryL(midletUid);
       
   339     CHECK(entry != NULL);
       
   340     CleanupReleasePushL(*entry);
       
   341 
       
   342     appVersion = entry->VersionL();
       
   343     CHECK(appVersion.iMajor == refVersion.iMajor);
       
   344     CHECK(appVersion.iMinor == refVersion.iMinor);
       
   345     CHECK(appVersion.iBuild == refVersion.iBuild);
       
   346 
       
   347     CleanupStack::PopAndDestroy(entry);
       
   348 
       
   349     Uid suite2Uid(L"[e22b4577]");
       
   350 
       
   351     JavaStorageApplicationEntry_t suite2;
       
   352     attr.setEntry(PACKAGE_NAME, L"MySuite2");
       
   353     suite2.insert(attr);
       
   354 
       
   355     attr.setEntry(VENDOR, L"Inc. inc.");
       
   356     suite2.insert(attr);
       
   357 
       
   358     attr.setEntry(ID, suite2Uid.toString());
       
   359     suite2.insert(attr);
       
   360 
       
   361     attr.setEntry(MEDIA_ID, L"-124614446");
       
   362     suite2.insert(attr);
       
   363 
       
   364     JavaStorageApplicationEntry_t midlet2;
       
   365 
       
   366     attr.setEntry(PACKAGE_ID, suite2Uid.toString());
       
   367     midlet2.insert(attr);
       
   368 
       
   369     Uid midlet2Uid(L"[e22b4588]");
       
   370 
       
   371     attr.setEntry(ID, midlet2Uid.toString());
       
   372     midlet2.insert(attr);
       
   373 
       
   374     js->startTransaction();
       
   375     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2));
       
   376     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   377     js->commitTransaction();
       
   378 
       
   379     uidToTUid(suite2Uid, suiteUid);
       
   380 
       
   381     TAppVersion refVersion2(0, 0, 0);
       
   382 
       
   383     entry = appsRegistry->EntryL(suiteUid);
       
   384     CHECK(entry != NULL);
       
   385     CleanupReleasePushL(*entry);
       
   386 
       
   387     appVersion = entry->VersionL();
       
   388     CHECK(appVersion.iMajor == refVersion2.iMajor);
       
   389     CHECK(appVersion.iMinor == refVersion2.iMinor);
       
   390     CHECK(appVersion.iBuild == refVersion2.iBuild);
       
   391 
       
   392     CleanupStack::PopAndDestroy(entry);
       
   393 
       
   394     uidToTUid(midlet2Uid, midletUid);
       
   395     entry = appsRegistry->EntryL(midletUid);
       
   396     CHECK(entry != NULL);
       
   397     CleanupReleasePushL(*entry);
       
   398 
       
   399     appVersion = entry->VersionL();
       
   400     CHECK(appVersion.iMajor == refVersion2.iMajor);
       
   401     CHECK(appVersion.iMinor == refVersion2.iMinor);
       
   402     CHECK(appVersion.iBuild == refVersion2.iBuild);
       
   403 
       
   404     CleanupStack::PopAndDestroy(entry);
       
   405 
       
   406     // Clean
       
   407     js->startTransaction();
       
   408     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   409     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2));
       
   410     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   411     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   412     js->commitTransaction();
       
   413     js->close();
       
   414 
       
   415     CleanupStack::PopAndDestroy(appsRegistry);
       
   416     LOG(EJavaStorage, EInfo, "-TestVersionL");
       
   417 }
       
   418 
       
   419 /**
       
   420  * Test CInstalledAppsRegistryEntry::DriveL() method.
       
   421  * 1. Test application suite drive.
       
   422  * 2. Test application drive.
       
   423  */
       
   424 TEST(TestInstalledAppsRegistryEntry, TestDriveL)
       
   425 {
       
   426     LOG(EJavaStorage, EInfo, "+TestDriveL");
       
   427 
       
   428     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
   429     CleanupReleasePushL(*appsRegistry);
       
   430     JavaStorageApplicationEntry_t midlet1;
       
   431     JavaStorageEntry attr;
       
   432 
       
   433     Uid suite1Uid(L"[eaaa4577]");
       
   434 
       
   435     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   436     midlet1.insert(attr);
       
   437 
       
   438     Uid midlet1Uid(L"[eaaa4588]");
       
   439 
       
   440     attr.setEntry(ID, midlet1Uid.toString());
       
   441     midlet1.insert(attr);
       
   442 
       
   443     js->open();
       
   444     js->startTransaction();
       
   445     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   446 
       
   447     JavaStorageApplicationEntry_t suite1;
       
   448     attr.setEntry(ID, suite1Uid.toString());
       
   449     suite1.insert(attr);
       
   450 
       
   451     attr.setEntry(ROOT_PATH, L"e:\\private\\MIDlets\\[eaaa4577]");
       
   452     suite1.insert(attr);
       
   453 
       
   454     attr.setEntry(MEDIA_ID, L"-124614446");
       
   455     suite1.insert(attr);
       
   456 
       
   457     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   458     js->commitTransaction();
       
   459 
       
   460     // 1. Application uid.
       
   461     TUid midletUid;
       
   462     uidToTUid(midlet1Uid, midletUid);
       
   463 
       
   464     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(midletUid);
       
   465     CHECK(entry != NULL);
       
   466 
       
   467     CleanupReleasePushL(*entry);
       
   468 
       
   469     CHECK(entry->DriveL() == 'E');
       
   470 
       
   471     CleanupStack::PopAndDestroy(entry);
       
   472 
       
   473     TUid suiteUid;
       
   474     uidToTUid(suite1Uid, suiteUid);
       
   475 
       
   476     entry = appsRegistry->EntryL(suiteUid);
       
   477     CHECK(entry != NULL);
       
   478 
       
   479     CleanupReleasePushL(*entry);
       
   480 
       
   481     CHECK(entry->DriveL() == 'E');
       
   482 
       
   483     CleanupStack::PopAndDestroy(entry);
       
   484 
       
   485     js->startTransaction();
       
   486     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   487     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   488     js->commitTransaction();
       
   489     js->close();
       
   490 
       
   491     CleanupStack::PopAndDestroy(appsRegistry);
       
   492 
       
   493     LOG(EJavaStorage, EInfo, "-TestDriveL");
       
   494 }
       
   495 
       
   496 /**
       
   497  * Test CInstalledAppsRegistryEntry::IsInRomL() method.
       
   498  * 1. Test application suite not in ROM.
       
   499  * 2. Test application not in ROM.
       
   500  * 3. Test application suite in ROM.
       
   501  * 4. Test application in ROM.
       
   502  */
       
   503 TEST(TestInstalledAppsRegistryEntry, TestIsInRomL)
       
   504 {
       
   505     LOG(EJavaStorage, EInfo, "+TestIsInRomL");
       
   506 
       
   507     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
   508     CleanupReleasePushL(*appsRegistry);
       
   509 
       
   510     JavaStorageApplicationEntry_t midlet1;
       
   511     JavaStorageEntry attr;
       
   512 
       
   513     Uid suite1Uid(L"[e0004577]");
       
   514 
       
   515     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   516     midlet1.insert(attr);
       
   517 
       
   518     Uid midlet1Uid(L"[e0004588]");
       
   519 
       
   520     attr.setEntry(ID, midlet1Uid.toString());
       
   521     midlet1.insert(attr);
       
   522 
       
   523     js->open();
       
   524     js->startTransaction();
       
   525     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   526 
       
   527     JavaStorageApplicationEntry_t suite1;
       
   528     attr.setEntry(ID, suite1Uid.toString());
       
   529     suite1.insert(attr);
       
   530 
       
   531     attr.setEntry(JAR_PATH, L"e:\\private\\MIDlets\\[e0004577]");
       
   532     suite1.insert(attr);
       
   533 
       
   534     attr.setEntry(MEDIA_ID, L"-124614446");
       
   535     suite1.insert(attr);
       
   536 
       
   537     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   538     js->commitTransaction();
       
   539 
       
   540     TUid midletUid;
       
   541     uidToTUid(midlet1Uid, midletUid);
       
   542 
       
   543     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(midletUid);
       
   544     CHECK(entry != NULL);
       
   545     CleanupReleasePushL(*entry);
       
   546 
       
   547     // 2. Test application not in ROM.
       
   548     CHECK(entry->IsInRomL() == EFalse);
       
   549 
       
   550     CleanupStack::PopAndDestroy(entry);
       
   551 
       
   552     TUid suiteUid;
       
   553     uidToTUid(suite1Uid, suiteUid);
       
   554 
       
   555     // 1. Test application suite not in ROM.
       
   556     entry = appsRegistry->EntryL(suiteUid);
       
   557     CHECK(entry != NULL);
       
   558     CleanupReleasePushL(*entry);
       
   559 
       
   560     CHECK(entry->IsInRomL() == EFalse);
       
   561 
       
   562     CleanupStack::PopAndDestroy(entry);
       
   563 
       
   564     // Move suite to ROM.
       
   565     JavaStorageApplicationEntry_t updateEntry;
       
   566     attr.setEntry(JAR_PATH, L"z:\\private\\MIDlets\\[e0004577]");
       
   567     updateEntry.insert(attr);
       
   568 
       
   569     js->startTransaction();
       
   570     CHECK(jtu->update(*js, APPLICATION_PACKAGE_TABLE, updateEntry, suite1));
       
   571     js->commitTransaction();
       
   572 
       
   573     entry = appsRegistry->EntryL(midletUid);
       
   574     CHECK(entry != NULL);
       
   575     CleanupReleasePushL(*entry);
       
   576 
       
   577     // 4. Test application in ROM.
       
   578     CHECK(entry->IsInRomL() == true);
       
   579 
       
   580     CleanupStack::PopAndDestroy(entry);
       
   581 
       
   582     entry = appsRegistry->EntryL(suiteUid);
       
   583     CHECK(entry != NULL);
       
   584     CleanupReleasePushL(*entry);
       
   585 
       
   586     // 3. Test application suite in ROM.
       
   587     CHECK(entry->IsInRomL() == true);
       
   588 
       
   589     CleanupStack::PopAndDestroy(entry);
       
   590 
       
   591     js->startTransaction();
       
   592     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   593     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, updateEntry));
       
   594     js->commitTransaction();
       
   595     js->close();
       
   596 
       
   597     CleanupStack::PopAndDestroy(appsRegistry);
       
   598     LOG(EJavaStorage, EInfo, "-TestIsInRomL");
       
   599 }
       
   600 
       
   601 /**
       
   602  * Test CInstalledAppsRegistryEntry::NumberOfCertificateChainsL() method.
       
   603  * 1. Test when suite no cert chains. Size is 0.
       
   604  * 2. Test when suite one cert chains. Size is 1.
       
   605  * 3. Test when suite three cert chains. size is 3.
       
   606  */
       
   607 TEST(TestInstalledAppsRegistryEntry, TestNumberOfCertificateChainsL)
       
   608 {
       
   609     LOG(EJavaStorage, EInfo, "+TestNumberOfCertificateChainsL");
       
   610 
       
   611     JavaStorageApplicationEntry_t midlet1;
       
   612     JavaStorageEntry attr;
       
   613 
       
   614     Uid suite1Uid(L"[e22bf577]");
       
   615 
       
   616     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   617     midlet1.insert(attr);
       
   618 
       
   619     Uid midlet1Uid(L"[e22bf588]");
       
   620 
       
   621     attr.setEntry(ID, midlet1Uid.toString());
       
   622     midlet1.insert(attr);
       
   623 
       
   624     js->open();
       
   625     js->startTransaction();
       
   626     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   627 
       
   628     JavaStorageApplicationEntry_t suite1;
       
   629     attr.setEntry(PACKAGE_NAME, L"TestCertChains");
       
   630     suite1.insert(attr);
       
   631 
       
   632     attr.setEntry(ID, suite1Uid.toString());
       
   633     suite1.insert(attr);
       
   634 
       
   635     attr.setEntry(MEDIA_ID, L"-124614446");
       
   636     suite1.insert(attr);
       
   637 
       
   638     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   639     js->commitTransaction();
       
   640     js->close();
       
   641 
       
   642     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
   643     CleanupReleasePushL(*appsRegistry);
       
   644 
       
   645     TUid suiteUid;
       
   646     uidToTUid(suite1Uid, suiteUid);
       
   647 
       
   648     // 1. Test when no cert chains. Size is 0.
       
   649     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(suiteUid);
       
   650     CHECK(entry != NULL);
       
   651     CleanupReleasePushL(*entry);
       
   652 
       
   653     CHECK(entry->NumberOfCertificateChainsL() == 0);
       
   654 
       
   655     CleanupStack::PopAndDestroy(entry);
       
   656 
       
   657     TUid midletUid;
       
   658     uidToTUid(midlet1Uid, midletUid);
       
   659 
       
   660     // 1.2 Test no certs via app.
       
   661     entry = appsRegistry->EntryL(midletUid);
       
   662     CHECK(entry != NULL);
       
   663     CleanupReleasePushL(*entry);
       
   664     CHECK(entry->NumberOfCertificateChainsL() == 0);
       
   665 
       
   666     CleanupStack::PopAndDestroy(entry);
       
   667 
       
   668     // 2. Test when one cert chains. Size is 1.
       
   669 
       
   670     JavaStorageApplicationEntry_t certEntry;
       
   671     JavaStorageApplicationEntry_t validcertsEntry;
       
   672 
       
   673     js->open();
       
   674     validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1");
       
   675     js->write(MIDP_PACKAGE_TABLE, validcertsEntry);
       
   676 
       
   677     certEntry = createEntry(suite1Uid.toString(),
       
   678                             L"MIDlet-Certificate-1-1",
       
   679                             L"abc123");
       
   680 
       
   681     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry);
       
   682     js->close();
       
   683 
       
   684     entry = appsRegistry->EntryL(suiteUid);
       
   685     CHECK(entry != NULL);
       
   686     CleanupReleasePushL(*entry);
       
   687     CHECK(entry->NumberOfCertificateChainsL() == 1);
       
   688     CleanupStack::PopAndDestroy(entry);
       
   689 
       
   690     // 2.2 Test no certs via app.
       
   691     entry = appsRegistry->EntryL(midletUid);
       
   692     CHECK(entry != NULL);
       
   693     CleanupReleasePushL(*entry);
       
   694     CHECK(entry->NumberOfCertificateChainsL() == 1);
       
   695     CleanupStack::PopAndDestroy(entry);
       
   696 
       
   697     js->open();
       
   698     js->startTransaction();
       
   699     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry));
       
   700     CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry));
       
   701     js->commitTransaction();
       
   702     js->close();
       
   703 
       
   704     // 3. Test when three cert chains. size is 3.
       
   705     certEntry.clear();
       
   706     validcertsEntry.clear();
       
   707 
       
   708     validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1,2,3");
       
   709 
       
   710     js->open();
       
   711     js->write(MIDP_PACKAGE_TABLE, validcertsEntry);
       
   712 
       
   713     certEntry = createEntry(suite1Uid.toString(),
       
   714                             L"MIDlet-Certificate-1-1",
       
   715                             L"abc123");
       
   716 
       
   717     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry);
       
   718 
       
   719     JavaStorageApplicationEntry_t certEntry2;
       
   720     certEntry2 = createEntry(suite1Uid.toString(),
       
   721                              L"MIDlet-Certificate-2-1",
       
   722                              L"def456");
       
   723 
       
   724     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2);
       
   725 
       
   726     JavaStorageApplicationEntry_t certEntry3;
       
   727     certEntry3 = createEntry(suite1Uid.toString(),
       
   728                              L"MIDlet-Certificate-3-1",
       
   729                              L"fooBar");
       
   730 
       
   731     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3);
       
   732     js->close();
       
   733 
       
   734     entry = appsRegistry->EntryL(suiteUid);
       
   735     CHECK(entry != NULL);
       
   736     CleanupReleasePushL(*entry);
       
   737     CHECK(entry->NumberOfCertificateChainsL() == 3);
       
   738     CleanupStack::PopAndDestroy(entry);
       
   739 
       
   740     // 2.2 Test no certs via app.
       
   741     entry = appsRegistry->EntryL(midletUid);
       
   742     CHECK(entry != NULL);
       
   743     CleanupReleasePushL(*entry);
       
   744     CHECK(entry->NumberOfCertificateChainsL() == 3);
       
   745     CleanupStack::PopAndDestroy(entry);
       
   746 
       
   747     js->open();
       
   748     js->startTransaction();
       
   749     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry));
       
   750     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2));
       
   751     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3));
       
   752     CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry));
       
   753     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   754     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   755     js->commitTransaction();
       
   756     js->close();
       
   757 
       
   758     CleanupStack::PopAndDestroy(appsRegistry);
       
   759 
       
   760     LOG(EJavaStorage, EInfo, "-TestNumberOfCertificateChains");
       
   761 }
       
   762 
       
   763 /**
       
   764  * Test CInstalledAppsRegistryEntry::CertificateChainL() method.
       
   765  * 1. Test when suite no cert chains.
       
   766  * 2. Test when suite one cert chains.
       
   767  * 3. Test when suite three cert chains.
       
   768  * 4. Test index greater than.
       
   769  * 5. Test index less than i.e. -1.
       
   770  */
       
   771 TEST(TestInstalledAppsRegistryEntry, TestCertificateChainL)
       
   772 {
       
   773     LOG(EJavaStorage, EInfo, "+TestCertificateChainL");
       
   774     MInstalledAppsRegistry* appsRegistry = MInstalledAppsRegistry::CreateL();
       
   775     CleanupReleasePushL(*appsRegistry);
       
   776 
       
   777     JavaStorageApplicationEntry_t midlet1;
       
   778     JavaStorageEntry attr;
       
   779 
       
   780     Uid suite1Uid(L"[e22bf577]");
       
   781 
       
   782     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   783     midlet1.insert(attr);
       
   784 
       
   785     Uid midlet1Uid(L"[e22bf588]");
       
   786 
       
   787     attr.setEntry(ID, midlet1Uid.toString());
       
   788     midlet1.insert(attr);
       
   789 
       
   790     js->open();
       
   791     js->startTransaction();
       
   792     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   793 
       
   794     JavaStorageApplicationEntry_t suite1;
       
   795     attr.setEntry(PACKAGE_NAME, L"TestCertChains");
       
   796     suite1.insert(attr);
       
   797 
       
   798     attr.setEntry(ID, suite1Uid.toString());
       
   799     suite1.insert(attr);
       
   800     attr.setEntry(MEDIA_ID, L"-124614446");
       
   801     suite1.insert(attr);
       
   802 
       
   803     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   804     js->commitTransaction();
       
   805     js->close();
       
   806 
       
   807     TUid suiteUid;
       
   808     uidToTUid(suite1Uid, suiteUid);
       
   809 
       
   810     // 1. Test when no cert chains. Size is 0.
       
   811     MInstalledAppsRegistryEntry* entry = appsRegistry->EntryL(suiteUid);
       
   812     CHECK(entry != NULL);
       
   813     CleanupReleasePushL(*entry);
       
   814     CHECK(entry->NumberOfCertificateChainsL() == 0);
       
   815     CHECK(entry->CertificateChainL(0) == KNullDesC8);
       
   816     CleanupStack::PopAndDestroy(entry);
       
   817 
       
   818     TUid midletUid;
       
   819     uidToTUid(midlet1Uid, midletUid);
       
   820 
       
   821     // 1.2 Test no certs via app.
       
   822     entry = appsRegistry->EntryL(midletUid);
       
   823     CHECK(entry != NULL);
       
   824     CleanupReleasePushL(*entry);
       
   825     CHECK(entry->NumberOfCertificateChainsL() == 0);
       
   826     CHECK(entry->CertificateChainL(0) == KNullDesC8);
       
   827     CleanupStack::PopAndDestroy(entry);
       
   828 
       
   829     // 2. Test when one cert chains. Size is 1.
       
   830 
       
   831     JavaStorageApplicationEntry_t certEntry;
       
   832     JavaStorageApplicationEntry_t validcertsEntry;
       
   833 
       
   834     js->open();
       
   835     validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1");
       
   836     js->write(MIDP_PACKAGE_TABLE, validcertsEntry);
       
   837 
       
   838     certEntry = createEntry(suite1Uid.toString(),
       
   839                             L"MIDlet-Certificate-1-1",
       
   840                             L"YWJjMTIz"); // abc123 as base64 encoded.
       
   841 
       
   842     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry);
       
   843     js->close();
       
   844 
       
   845     _LIT8(KCertChain1, "abc123");
       
   846 
       
   847     entry = appsRegistry->EntryL(suiteUid);
       
   848     CHECK(entry != NULL);
       
   849     CleanupReleasePushL(*entry);
       
   850     CHECK(entry->NumberOfCertificateChainsL() == 1);
       
   851     CHECK(entry->CertificateChainL(0).Compare(KCertChain1) == 0);
       
   852     CleanupStack::PopAndDestroy(entry);
       
   853 
       
   854     // 2.2 Test no certs via app.
       
   855     entry = appsRegistry->EntryL(midletUid);
       
   856     CHECK(entry != NULL);
       
   857     CleanupReleasePushL(*entry);
       
   858     CHECK(entry->NumberOfCertificateChainsL() == 1);
       
   859     CHECK(entry->CertificateChainL(0).Compare(KCertChain1) == 0);
       
   860     CleanupStack::PopAndDestroy(entry);
       
   861 
       
   862     js->open();
       
   863     js->startTransaction();
       
   864     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry));
       
   865     CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry));
       
   866     js->commitTransaction();
       
   867     js->close();
       
   868 
       
   869 
       
   870     // 3. Test when three cert chains. size is 3.
       
   871     certEntry.clear();
       
   872     validcertsEntry.clear();
       
   873 
       
   874     validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1,2,3");
       
   875 
       
   876     js->open();
       
   877     js->write(MIDP_PACKAGE_TABLE, validcertsEntry);
       
   878 
       
   879     certEntry = createEntry(suite1Uid.toString(),
       
   880                             L"MIDlet-Certificate-1-1",
       
   881                             L"YWJjMTIz");  // abc123
       
   882 
       
   883     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry);
       
   884 
       
   885     JavaStorageApplicationEntry_t certEntry2;
       
   886     certEntry2 = createEntry(suite1Uid.toString(),
       
   887                              L"MIDlet-Certificate-2-1",
       
   888                              L"ZGVmNDU2");  // def456 as base 64 encoded.
       
   889 
       
   890     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2);
       
   891 
       
   892     JavaStorageApplicationEntry_t certEntry3;
       
   893     certEntry3 = createEntry(suite1Uid.toString(),
       
   894                              L"MIDlet-Certificate-3-1",
       
   895                              L"Zm9vQmFy");  // fooBar
       
   896 
       
   897     js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3);
       
   898     js->close();
       
   899 
       
   900     entry = appsRegistry->EntryL(suiteUid);
       
   901     CHECK(entry != NULL);
       
   902     CleanupReleasePushL(*entry);
       
   903     CHECK(entry->NumberOfCertificateChainsL() == 3);
       
   904     CHECK(entry->CertificateChainL(0).Compare(KCertChain1) == 0);
       
   905     _LIT8(KCertChain2, "def456");
       
   906     CHECK(entry->CertificateChainL(1).Compare(KCertChain2) == 0);
       
   907     _LIT8(KCertChain3, "fooBar");
       
   908     CHECK(entry->CertificateChainL(2).Compare(KCertChain3) == 0);
       
   909     CleanupStack::PopAndDestroy(entry);
       
   910 
       
   911     // 2.2 Test no certs via app.
       
   912     entry = appsRegistry->EntryL(midletUid);
       
   913     CHECK(entry != NULL);
       
   914     CleanupReleasePushL(*entry);
       
   915     CHECK(entry->NumberOfCertificateChainsL() == 3);
       
   916     CHECK(entry->CertificateChainL(0).Compare(KCertChain1) == 0);
       
   917     CHECK(entry->CertificateChainL(1).Compare(KCertChain2) == 0);
       
   918     CHECK(entry->CertificateChainL(2).Compare(KCertChain3) == 0);
       
   919 
       
   920     // 4. Test index greater than.
       
   921     CHECK(entry->CertificateChainL(3) == KNullDesC8);
       
   922 
       
   923     // 5. Test index less than i.e. -1.
       
   924     CHECK(entry->CertificateChainL(-1) == KNullDesC8);
       
   925 
       
   926     CleanupStack::PopAndDestroy(entry);
       
   927 
       
   928     js->open();
       
   929     js->startTransaction();
       
   930     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry));
       
   931     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2));
       
   932     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3));
       
   933     CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry));
       
   934     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   935     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   936     js->commitTransaction();
       
   937     js->close();
       
   938 
       
   939     CleanupStack::PopAndDestroy(appsRegistry);
       
   940 
       
   941     LOG(EJavaStorage, EInfo, "-TestCertificateChainL");
       
   942 }
       
   943 
       
   944 const JavaStorageApplicationEntry_t createEntry(const wstring& aUid,
       
   945         const wstring& aName,
       
   946         const wstring& aValue)
       
   947 {
       
   948     JavaStorageApplicationEntry_t entry;
       
   949     JavaStorageEntry attr;
       
   950 
       
   951     attr.setEntry(ID, aUid);
       
   952     entry.insert(attr);
       
   953 
       
   954     attr.setEntry(NAME, aName);
       
   955     entry.insert(attr);
       
   956 
       
   957     attr.setEntry(VALUE, aValue);
       
   958     entry.insert(attr);
       
   959 
       
   960     return entry;
       
   961 }
       
   962 
       
   963 const JavaStorageApplicationEntry_t createValidCertsEntry(const wstring& aUid,
       
   964         const wstring& aCerts)
       
   965 {
       
   966     JavaStorageApplicationEntry_t entry;
       
   967     JavaStorageEntry attr;
       
   968 
       
   969     attr.setEntry(ID, aUid);
       
   970     entry.insert(attr);
       
   971 
       
   972     attr.setEntry(VALID_CERTS, aCerts);
       
   973     entry.insert(attr);
       
   974 
       
   975     return entry;
       
   976 }