javamanager/javaregistry/legacy/tsrc/src/testlegacyregistry.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 "javacommonutils.h"
       
    24 #include "javaoslayer.h"
       
    25 #include "javastorage.h"
       
    26 #include "javastorageexception.h"
       
    27 #include "javastoragenames.h"
       
    28 #include "javasymbianoslayer.h"
       
    29 #include "javauid.h"
       
    30 #include "logger.h"
       
    31 #include "mjavaregistry.h"
       
    32 #include "storagetestutils.h"
       
    33 
       
    34 using namespace std;
       
    35 using namespace java::storage;
       
    36 using namespace java::util;
       
    37 
       
    38 TEST_GROUP(TestLegacyRegistry)
       
    39 {
       
    40     JavaStorage* js;
       
    41     JavaStorageTestUtils* jtu;
       
    42     CActiveScheduler* newScheduler;
       
    43 
       
    44     TEST_SETUP()
       
    45     {
       
    46         newScheduler = new CActiveScheduler();
       
    47         CActiveScheduler::Install(newScheduler);
       
    48 
       
    49         js = JavaStorage::createInstance();
       
    50         jtu = new JavaStorageTestUtils();
       
    51     }
       
    52     TEST_TEARDOWN()
       
    53     {
       
    54         try
       
    55         {
       
    56             js->rollbackTransaction();
       
    57             js->close();
       
    58             delete js;
       
    59             js = NULL;
       
    60         }
       
    61         catch (...)
       
    62         {
       
    63             // No can do
       
    64         }
       
    65 
       
    66         delete js;
       
    67         js = 0;
       
    68         delete jtu;
       
    69         jtu = 0;
       
    70 
       
    71         delete newScheduler;
       
    72         newScheduler = NULL;
       
    73     }
       
    74 };
       
    75 
       
    76 /**
       
    77  * Test CJavaRegistry::InstalledSuiteUidsL() method.
       
    78  *   1. No UID in registry.
       
    79  *   2. One UID in registry.
       
    80  *   3. Several UIDs in registtry.
       
    81  */
       
    82 TEST(TestLegacyRegistry, TestInstalledSuiteUidsL)
       
    83 {
       
    84     LOG(EJavaStorage, EInfo, "+TestInstalledSuiteUidsL");
       
    85 
       
    86     // 1. No UID in registry
       
    87     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
    88     CHECK(registry != NULL);
       
    89 
       
    90     RArray<TUid> suiteUids;
       
    91     registry->InstalledSuiteUidsL(suiteUids);
       
    92 
       
    93     CHECK(0 == suiteUids.Count());
       
    94 
       
    95     // 2. One UID in registry.
       
    96     suiteUids.Reset();
       
    97     suiteUids.Close();
       
    98 
       
    99     // Populate first suite
       
   100     js->open();
       
   101     js->startTransaction();
       
   102 
       
   103     JavaStorageApplicationEntry_t suite1;
       
   104     JavaStorageEntry attr;
       
   105     attr.setEntry(PACKAGE_NAME, L"TestSuite1");
       
   106     suite1.insert(attr);
       
   107 
       
   108     string tableName = APPLICATION_PACKAGE_TABLE;
       
   109     Uid suite1Uid(L"[e22a4577]");
       
   110     attr.setEntry(ID, suite1Uid.toString());
       
   111     suite1.insert(attr);
       
   112 
       
   113     attr.setEntry(MEDIA_ID, L"-124614446");
       
   114     suite1.insert(attr);
       
   115 
       
   116     CHECK(jtu->populate(*js, tableName, suite1));
       
   117 
       
   118     JavaStorageApplicationEntry_t midlet1;
       
   119     attr.setEntry(NAME, L"MyMIDlet1");
       
   120     midlet1.insert(attr);
       
   121 
       
   122     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   123     midlet1.insert(attr);
       
   124 
       
   125     string appTableName = APPLICATION_TABLE;
       
   126     Uid midlet1Uid(L"[e12abc77]");
       
   127     attr.setEntry(ID, midlet1Uid.toString());
       
   128     midlet1.insert(attr);
       
   129 
       
   130     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   131 
       
   132     // Session must be committed before next use of Registry otherwise
       
   133     // it is locked.
       
   134     js->commitTransaction();
       
   135 
       
   136     registry->InstalledSuiteUidsL(suiteUids);
       
   137 
       
   138     CHECK(1 == suiteUids.Count());
       
   139 
       
   140     // Check uid is same than populated one
       
   141     TUid suiteUid;
       
   142     uidToTUid(suite1Uid, suiteUid);
       
   143 
       
   144     CHECK(suiteUids[0] == suiteUid);
       
   145 
       
   146     // 3. Several UIDs in registtry.
       
   147     suiteUids.Reset();
       
   148     suiteUids.Close();
       
   149 
       
   150     // Populate the second suite
       
   151     js->startTransaction();
       
   152 
       
   153     JavaStorageApplicationEntry_t suite2;
       
   154     attr.setEntry(PACKAGE_NAME, L"TestSuite2");
       
   155     suite2.insert(attr);
       
   156 
       
   157     Uid suite2Uid(L"[e1234a88]");
       
   158     attr.setEntry(ID, suite2Uid.toString());
       
   159     suite2.insert(attr);
       
   160 
       
   161     attr.setEntry(MEDIA_ID, L"-124614446");
       
   162     suite2.insert(attr);
       
   163 
       
   164     CHECK(jtu->populate(*js, tableName, suite2));
       
   165 
       
   166     JavaStorageApplicationEntry_t midlet2;
       
   167     attr.setEntry(NAME, L"MyMIDlet2");
       
   168     midlet2.insert(attr);
       
   169 
       
   170     attr.setEntry(PACKAGE_ID, suite2Uid.toString());
       
   171     midlet2.insert(attr);
       
   172 
       
   173     Uid midlet2Uid(L"[e12cba77]");
       
   174     attr.setEntry(ID, midlet2Uid.toString());
       
   175     midlet2.insert(attr);
       
   176 
       
   177     CHECK(jtu->populate(*js, appTableName, midlet2));
       
   178 
       
   179     // Session must be committed before next use of Registry otherwise
       
   180     // it is locked.
       
   181     js->commitTransaction();
       
   182 
       
   183     registry->InstalledSuiteUidsL(suiteUids);
       
   184     CHECK(2 == suiteUids.Count());
       
   185 
       
   186     // Check uids are the same. Entries are returned at same
       
   187     // order they're written.
       
   188     uidToTUid(suite1Uid, suiteUid);
       
   189     CHECK(suiteUids[0] == suiteUid);
       
   190 
       
   191     uidToTUid(suite2Uid, suiteUid);
       
   192     CHECK(suiteUids[1] == suiteUid);
       
   193 
       
   194     // Clean
       
   195     js->startTransaction();
       
   196     CHECK(jtu->remove(*js, tableName, suite1));
       
   197     CHECK(jtu->remove(*js, tableName, suite2));
       
   198     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   199     CHECK(jtu->remove(*js, appTableName, midlet2));
       
   200 
       
   201     js->commitTransaction();
       
   202     js->close();
       
   203 
       
   204     registry->Release();
       
   205     suiteUids.Reset();
       
   206     suiteUids.Close();
       
   207     LOG(EJavaStorage, EInfo, "-TestInstalledSuiteUidsL");
       
   208 }
       
   209 
       
   210 /**
       
   211  * Test SuiteEntryL() method.
       
   212  * 1. No suite entry in registry.
       
   213  * 2. NullUid.
       
   214  * 3. No matching entry in registry.
       
   215  * 4. Matching entry in registry.
       
   216  */
       
   217 TEST(TestLegacyRegistry, TestSuiteEntryL)
       
   218 {
       
   219     LOG(EJavaStorage, EInfo, "+TestSuiteEntryL");
       
   220 
       
   221     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   222     CHECK(registry != NULL);
       
   223 
       
   224     TUid uid = TUid::Uid(3777185127);    // e1234567
       
   225 
       
   226     // 1. No suite entry in registry.
       
   227     MJavaRegistrySuiteEntry* suiteEntry = NULL;
       
   228 
       
   229     TRAPD(err, suiteEntry = registry->SuiteEntryL(uid));
       
   230     CHECK(KErrNotFound == err);
       
   231 
       
   232     // 2. NullUid.
       
   233     TRAP(err, suiteEntry = registry->SuiteEntryL(TUid::Null()));
       
   234     CHECK(KErrArgument == err);
       
   235 
       
   236     // 3. No matching entry in registry.
       
   237 
       
   238     // Populate not matching entry
       
   239     js->open(JAVA_DATABASE_NAME);
       
   240     js->startTransaction();
       
   241 
       
   242     JavaStorageApplicationEntry_t suite1;
       
   243     JavaStorageEntry attr;
       
   244     attr.setEntry(PACKAGE_NAME, L"TestSuite1");
       
   245     suite1.insert(attr);
       
   246 
       
   247     string tableName = APPLICATION_PACKAGE_TABLE;
       
   248     Uid suite1Uid(L"[e1234577]");
       
   249 
       
   250     attr.setEntry(ID, suite1Uid.toString());
       
   251     suite1.insert(attr);
       
   252 
       
   253     attr.setEntry(MEDIA_ID, L"-124614446");
       
   254     suite1.insert(attr);
       
   255 
       
   256     CHECK(jtu->populate(*js, tableName, suite1));
       
   257 
       
   258     JavaStorageApplicationEntry_t midlet1;
       
   259     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   260     midlet1.insert(attr);
       
   261 
       
   262     Uid midlet1Uid(L"[e3335577]");
       
   263     attr.setEntry(ID, midlet1Uid.toString());
       
   264     midlet1.insert(attr);
       
   265 
       
   266     string appTableName = APPLICATION_TABLE;
       
   267 
       
   268     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   269     js->commitTransaction();
       
   270 
       
   271     TRAP(err, suiteEntry = registry->SuiteEntryL(uid));
       
   272     CHECK(KErrNotFound == err);
       
   273 
       
   274     // 4. Matching entry in registry.
       
   275 
       
   276     // Populate matching entry.
       
   277     js->startTransaction();
       
   278 
       
   279     JavaStorageApplicationEntry_t suite2;
       
   280     attr.setEntry(PACKAGE_NAME, L"TestSuite2");
       
   281     suite2.insert(attr);
       
   282 
       
   283     Uid suite2Uid(L"[e1234567]");
       
   284     attr.setEntry(ID, suite2Uid.toString());
       
   285     suite2.insert(attr);
       
   286 
       
   287     attr.setEntry(MEDIA_ID, L"-124614446");
       
   288     suite2.insert(attr);
       
   289 
       
   290     CHECK(jtu->populate(*js, tableName, suite2));
       
   291 
       
   292     JavaStorageApplicationEntry_t midlet2;
       
   293     attr.setEntry(PACKAGE_ID, suite2Uid.toString());
       
   294     midlet2.insert(attr);
       
   295 
       
   296     Uid midlet2Uid(L"[e3365577]");
       
   297     attr.setEntry(ID, midlet2Uid.toString());
       
   298     midlet2.insert(attr);
       
   299 
       
   300     CHECK(jtu->populate(*js, appTableName, midlet2));
       
   301     js->commitTransaction();
       
   302 
       
   303     TRAP(err, suiteEntry = registry->SuiteEntryL(uid));
       
   304     CHECK(KErrNone == err);
       
   305     CHECK(NULL != suiteEntry);  // Actual suite entry is tested elsewhere.
       
   306 
       
   307     // Clean
       
   308     js->startTransaction();
       
   309     CHECK(jtu->remove(*js, tableName, suite1));
       
   310     CHECK(jtu->remove(*js, tableName, suite2));
       
   311     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   312     CHECK(jtu->remove(*js, appTableName, midlet2));
       
   313     js->commitTransaction();
       
   314     js->close();
       
   315 
       
   316     suiteEntry->Release();
       
   317     registry->Release();
       
   318 
       
   319     LOG(EJavaStorage, EInfo, "-TestSuiteEntryL");
       
   320 }
       
   321 
       
   322 /**
       
   323  * Test MIDletEntryL() method.
       
   324  *
       
   325  * 1. No midlet entry in registry.
       
   326  * 2. No matching entry in registry.
       
   327  * 3. Matching entry in registry.
       
   328  */
       
   329 TEST(TestLegacyRegistry, TestMIDletEntryL)
       
   330 {
       
   331     LOG(EJavaStorage, EInfo, "+TestMIDletEntryL");
       
   332     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   333     CHECK(registry != NULL);
       
   334 
       
   335     TUid uid = TUid::Uid(3777185127);    // e1234567
       
   336 
       
   337     // 1. No suite entry in registry.
       
   338     MJavaRegistryMIDletEntry* midletEntry = NULL;
       
   339 
       
   340     TRAPD(err, midletEntry = registry->MIDletEntryL(uid));
       
   341     CHECK(KErrNotFound == err);
       
   342 
       
   343     // 2. NullUid.
       
   344     TRAP(err, midletEntry = registry->MIDletEntryL(TUid::Null()));
       
   345     CHECK(KErrNotFound == err);
       
   346 
       
   347     // 3. No matching entry in registry.
       
   348 
       
   349     // Populate not matching entry
       
   350     js->open(JAVA_DATABASE_NAME);
       
   351     js->startTransaction();
       
   352 
       
   353     JavaStorageApplicationEntry_t midlet1;
       
   354     JavaStorageEntry attr;
       
   355     attr.setEntry(NAME, L"MyMIDlet1");
       
   356     midlet1.insert(attr);
       
   357 
       
   358     Uid suite1Uid(L"[e123456a]");
       
   359     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   360     midlet1.insert(attr);
       
   361 
       
   362     string tableName = APPLICATION_TABLE;
       
   363     Uid midlet1Uid(L"[e1234577]");
       
   364     attr.setEntry(ID, midlet1Uid.toString());
       
   365     midlet1.insert(attr);
       
   366 
       
   367     CHECK(jtu->populate(*js, tableName, midlet1));
       
   368 
       
   369     // Suite is alse required
       
   370     JavaStorageApplicationEntry_t suite1;
       
   371     attr.setEntry(PACKAGE_NAME, L"TestSuite1");
       
   372     suite1.insert(attr);
       
   373 
       
   374     string suiteTable = APPLICATION_PACKAGE_TABLE;
       
   375     attr.setEntry(ID, suite1Uid.toString());
       
   376     suite1.insert(attr);
       
   377 
       
   378     attr.setEntry(MEDIA_ID, L"-124614446");
       
   379     suite1.insert(attr);
       
   380 
       
   381     CHECK(jtu->populate(*js, suiteTable, suite1));
       
   382 
       
   383     // Session must be committed before next use of Registry otherwise
       
   384     // it is locked.
       
   385     js->commitTransaction();
       
   386 
       
   387     TRAP(err, midletEntry = registry->MIDletEntryL(uid));
       
   388     CHECK(KErrNotFound == err);
       
   389 
       
   390     // 4. Matching entry in registry.
       
   391 
       
   392     // Populate matching entry.
       
   393     js->startTransaction();
       
   394 
       
   395     JavaStorageApplicationEntry_t midlet2;
       
   396     attr.setEntry(NAME, L"MyMIDlet2");
       
   397     midlet2.insert(attr);
       
   398 
       
   399     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   400     midlet2.insert(attr);
       
   401 
       
   402     Uid midlet2Uid(L"[e1234567]");
       
   403     attr.setEntry(ID, midlet2Uid.toString());
       
   404     midlet2.insert(attr);
       
   405 
       
   406     CHECK(jtu->populate(*js, tableName, midlet2));
       
   407 
       
   408     // Session must be committed before next use of Registry otherwise
       
   409     // it is locked.
       
   410     js->commitTransaction();
       
   411 
       
   412     TRAP(err, midletEntry = registry->MIDletEntryL(uid));
       
   413     CHECK(KErrNone == err);
       
   414     CHECK(NULL != midletEntry);  // Actual midlet entry is tested elsewhere.
       
   415 
       
   416     midletEntry->Release();
       
   417 
       
   418     // Clean
       
   419     js->startTransaction();
       
   420     CHECK(jtu->remove(*js, tableName, midlet1));
       
   421     CHECK(jtu->remove(*js, tableName, midlet2));
       
   422     CHECK(jtu->remove(*js, suiteTable,suite1));
       
   423 
       
   424     js->commitTransaction();
       
   425     js->close();
       
   426 
       
   427     registry->Release();
       
   428 
       
   429     LOG(EJavaStorage, EInfo, "-TestMIDletEntryL");
       
   430 }
       
   431 
       
   432 /**
       
   433  * Test MJavaRegistrySuiteEntry attributes are returned correctly.
       
   434  */
       
   435 TEST(TestLegacyRegistry, TestSuiteEntryAttributes)
       
   436 {
       
   437     LOG(EJavaStorage, EInfo, "+TestSuiteEntryAttributes");
       
   438 
       
   439     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   440     CHECK(registry != NULL);
       
   441 
       
   442     TUid uid = TUid::Uid(3777185127);    // e1234567
       
   443 
       
   444     // Populate entry
       
   445     js->open(JAVA_DATABASE_NAME);
       
   446     js->startTransaction();
       
   447 
       
   448     JavaStorageApplicationEntry_t suite1;
       
   449     JavaStorageEntry attr;
       
   450     wstring srcSuiteName = L"TestSuite1";
       
   451     attr.setEntry(PACKAGE_NAME, srcSuiteName);
       
   452     suite1.insert(attr);
       
   453 
       
   454     wstring srcJarPath = L"Path/To/Jar";
       
   455     attr.setEntry(JAR_PATH, srcJarPath);
       
   456     suite1.insert(attr);
       
   457 
       
   458     wstring srcJadPath = L"JAD/To/Path";
       
   459     attr.setEntry(JAD_PATH, srcJadPath);
       
   460     suite1.insert(attr);
       
   461 
       
   462     wstring srcVendorName = L"TestSuite1";
       
   463     attr.setEntry(VENDOR, srcVendorName);
       
   464     suite1.insert(attr);
       
   465 
       
   466     attr.setEntry(VERSION, L"1.2.3");
       
   467     suite1.insert(attr);
       
   468 
       
   469     string tableName = APPLICATION_PACKAGE_TABLE;
       
   470     Uid suite1Uid(L"[e1234567]");
       
   471     attr.setEntry(ID, suite1Uid.toString());
       
   472     suite1.insert(attr);
       
   473 
       
   474     attr.setEntry(MEDIA_ID, L"-124614446");
       
   475     suite1.insert(attr);
       
   476 
       
   477     CHECK(jtu->populate(*js, tableName, suite1));
       
   478 
       
   479     JavaStorageApplicationEntry_t midlet1;
       
   480     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   481     midlet1.insert(attr);
       
   482 
       
   483     Uid midlet1Uid(L"[e3334577]");
       
   484     attr.setEntry(ID, midlet1Uid.toString());
       
   485     midlet1.insert(attr);
       
   486 
       
   487     string appTableName = APPLICATION_TABLE;
       
   488 
       
   489     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   490     js->commitTransaction();
       
   491 
       
   492     MJavaRegistrySuiteEntry* suiteEntry = NULL;
       
   493     TRAPD(err, suiteEntry = registry->SuiteEntryL(uid));
       
   494 
       
   495     CHECK(KErrNone == err);
       
   496     CHECK(NULL != suiteEntry);
       
   497 
       
   498     // Test UID
       
   499     TUid suiteUid;
       
   500     uidToTUid(suite1Uid, suiteUid);
       
   501     CHECK(suiteEntry->UidL() == suiteUid);
       
   502 
       
   503     const TDesC16& suiteName = suiteEntry->SuiteNameL();
       
   504     auto_ptr<HBufC16> nameBuf(HBufC16::NewL(suiteName.Length() + 1));
       
   505     TPtr16 nameBufPtr(nameBuf->Des());
       
   506     nameBufPtr.Append(suiteName);
       
   507     wstring refStr(desToWstring(nameBufPtr));
       
   508 
       
   509     CHECK(refStr == srcSuiteName);
       
   510 
       
   511     const TDesC16& vendor = suiteEntry->VendorL();
       
   512     auto_ptr<HBufC16> vendorBuf(HBufC16::NewL(vendor.Length() + 1));
       
   513     TPtr16 vendorBufPtr(vendorBuf->Des());
       
   514     vendorBufPtr.Append(vendor);
       
   515     refStr = desToWstring(vendorBufPtr);
       
   516 
       
   517     CHECK(refStr == srcVendorName);
       
   518 
       
   519     TAppVersion version = suiteEntry->VersionL();
       
   520     TAppVersion srcVersion(1, 2, 3);
       
   521     CHECK(version.iMajor == srcVersion.iMajor);
       
   522     CHECK(version.iMinor == srcVersion.iMinor);
       
   523     CHECK(version.iBuild == srcVersion.iBuild);
       
   524 
       
   525     const TDesC16& jadPath = suiteEntry->JadPathL();
       
   526     auto_ptr<HBufC16> jadBuf(HBufC16::NewL(jadPath.Length() + 1));
       
   527     TPtr16 jadBufPtr(jadBuf->Des());
       
   528     jadBufPtr.Append(jadPath);
       
   529     refStr = desToWstring(jadBufPtr);
       
   530 
       
   531     CHECK(refStr == srcJadPath);
       
   532 
       
   533     const TDesC16& jarPath = suiteEntry->JarPathL();
       
   534     auto_ptr<HBufC16> jarBuf(HBufC16::NewL(jarPath.Length() + 1));
       
   535     TPtr16 jarBufPtr(jarBuf->Des());
       
   536     jarBufPtr.Append(jarPath);
       
   537     refStr = desToWstring(jarBufPtr);
       
   538 
       
   539     CHECK(refStr == srcJarPath);
       
   540 
       
   541     // Clean
       
   542     js->startTransaction();
       
   543     CHECK(jtu->remove(*js, tableName, suite1));
       
   544     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   545     js->commitTransaction();
       
   546     js->close();
       
   547 
       
   548     suiteEntry->Release();
       
   549     registry->Release();
       
   550 
       
   551     LOG(EJavaStorage, EInfo, "-TestSuiteEntryAttributes");
       
   552 }
       
   553 
       
   554 /**
       
   555  * Test MJavaRegistryMIDletEntry attributes are returned correctly.
       
   556  */
       
   557 TEST(TestLegacyRegistry, TestMIDletEntryAttributes)
       
   558 {
       
   559     LOG(EJavaStorage, EInfo, "+TestMIDletEntryAttributes");
       
   560 
       
   561     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   562     CHECK(registry != NULL);
       
   563 
       
   564     // Populate entry
       
   565     js->open(JAVA_DATABASE_NAME);
       
   566     js->startTransaction();
       
   567 
       
   568     JavaStorageApplicationEntry_t suite1;
       
   569     JavaStorageEntry attr;
       
   570     attr.setEntry(PACKAGE_NAME, L"TestSuite1");
       
   571     suite1.insert(attr);
       
   572 
       
   573     attr.setEntry(JAR_PATH, L"Path/To/Jar");
       
   574     suite1.insert(attr);
       
   575 
       
   576     attr.setEntry(JAD_PATH, L"JAD/To/Path");
       
   577     suite1.insert(attr);
       
   578 
       
   579     attr.setEntry(VENDOR, L"TestSuite1Vendor");
       
   580     suite1.insert(attr);
       
   581 
       
   582     attr.setEntry(VERSION, L"1.2.3");
       
   583     suite1.insert(attr);
       
   584 
       
   585     attr.setEntry(MEDIA_ID, L"-124614446");
       
   586     suite1.insert(attr);
       
   587 
       
   588     string tableName = APPLICATION_PACKAGE_TABLE;
       
   589     Uid suite1Uid(L"[e1234567]");
       
   590     attr.setEntry(ID, suite1Uid.toString());
       
   591     suite1.insert(attr);
       
   592     CHECK(jtu->populate(*js, tableName, suite1));
       
   593 
       
   594     JavaStorageApplicationEntry_t midlet1;
       
   595     wstring srcMidletName = L"MyMIDlet1";
       
   596     attr.setEntry(NAME, srcMidletName);
       
   597     midlet1.insert(attr);
       
   598 
       
   599     attr.setEntry(PACKAGE_ID, L"[e1234567]");
       
   600     midlet1.insert(attr);
       
   601 
       
   602     string appTableName = APPLICATION_TABLE;
       
   603     TUid uid = TUid::Uid(3777185143);    // e1234577
       
   604     Uid midlet1Uid(L"[e1234577]");
       
   605     attr.setEntry(ID, midlet1Uid.toString());
       
   606     midlet1.insert(attr);
       
   607 
       
   608     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   609 
       
   610     // Session must be committed before next use of Registry otherwise
       
   611     // it is locked.
       
   612     js->commitTransaction();
       
   613 
       
   614     MJavaRegistryMIDletEntry* midletEntry = NULL;
       
   615     TRAPD(err, midletEntry = registry->MIDletEntryL(uid));
       
   616 
       
   617     CHECK(KErrNone == err);
       
   618     CHECK(NULL != midletEntry);
       
   619 
       
   620     // Test UID
       
   621     TUid midletUid;
       
   622     uidToTUid(midlet1Uid, midletUid);
       
   623     CHECK(midletEntry->UidL() == midletUid);
       
   624 
       
   625     const TDesC16& midletName = midletEntry->MIDletNameL();
       
   626     auto_ptr<HBufC16> nameBuf(HBufC16::NewL(midletName.Length() + 1));
       
   627     TPtr16 nameBufPtr(nameBuf->Des());
       
   628     nameBufPtr.Append(midletName);
       
   629     wstring refStr(desToWstring(nameBufPtr));
       
   630 
       
   631     CHECK(refStr == srcMidletName);
       
   632 
       
   633     const MJavaRegistrySuiteEntry& suiteEntry = midletEntry->SuiteEntryL();
       
   634 
       
   635     // Verify suite UID to be sure we're dealing with correct entry.
       
   636     TUid suiteUid;
       
   637     uidToTUid(suite1Uid, suiteUid);
       
   638     CHECK(suiteEntry.UidL() == suiteUid);
       
   639 
       
   640     // Clean
       
   641     js->startTransaction();
       
   642     CHECK(jtu->remove(*js, tableName, suite1));
       
   643     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   644 
       
   645     js->commitTransaction();
       
   646     js->close();
       
   647 
       
   648     midletEntry->Release();
       
   649     registry->Release();
       
   650 
       
   651     LOG(EJavaStorage, EInfo, "-TestMIDletEntryAttributes");
       
   652 }
       
   653 
       
   654 /**
       
   655  * Test CJavaRegistry::InstalledMIDletUidsL() method.
       
   656  *   1. No UID in registry.
       
   657  *   2. One UID in registry.
       
   658  *   3. Several UIDs in registtry.
       
   659  */
       
   660 TEST(TestLegacyRegistry, TestInstalledMIDletUidsL)
       
   661 {
       
   662     LOG(EJavaStorage, EInfo, "+TestInstalledMIDletUidsL");
       
   663 
       
   664     // 1. No UID in registry
       
   665     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   666     CHECK(registry != NULL);
       
   667 
       
   668     RArray<TUid> midletUids;
       
   669     registry->InstalledMIDletUidsL(midletUids);
       
   670 
       
   671     CHECK(0 == midletUids.Count());
       
   672 
       
   673     // 2. One UID in registry.
       
   674     midletUids.Reset();
       
   675     midletUids.Close();
       
   676 
       
   677     // Populate first suite
       
   678     js->open();
       
   679     js->startTransaction();
       
   680 
       
   681     Uid suite1Uid(L"[e22a45d7]");
       
   682     JavaStorageEntry attr;
       
   683     JavaStorageApplicationEntry_t midlet1;
       
   684     attr.setEntry(NAME, L"MyMIDlet1");
       
   685     midlet1.insert(attr);
       
   686 
       
   687     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   688     midlet1.insert(attr);
       
   689 
       
   690     string appTableName = APPLICATION_TABLE;
       
   691     Uid midlet1Uid(L"[e12abcd7]");
       
   692     attr.setEntry(ID, midlet1Uid.toString());
       
   693     midlet1.insert(attr);
       
   694 
       
   695     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   696 
       
   697     JavaStorageApplicationEntry_t suite1;
       
   698 
       
   699     attr.setEntry(MEDIA_ID, L"-124614446");
       
   700     suite1.insert(attr);
       
   701 
       
   702     attr.setEntry(ID, suite1Uid.toString());
       
   703     suite1.insert(attr);
       
   704 
       
   705     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   706 
       
   707     // Session must be committed before next use of Registry otherwise
       
   708     // it is locked.
       
   709     js->commitTransaction();
       
   710 
       
   711     registry->InstalledMIDletUidsL(midletUids);
       
   712 
       
   713     CHECK(1 == midletUids.Count());
       
   714 
       
   715     // Check uid is same than populated one
       
   716     TUid midletUid;
       
   717     uidToTUid(midlet1Uid, midletUid);
       
   718 
       
   719     CHECK(midletUids[0] == midletUid);
       
   720 
       
   721     // 3. Several UIDs in registtry.
       
   722     midletUids.Reset();
       
   723     midletUids.Close();
       
   724 
       
   725     // Populate the second suite
       
   726     js->startTransaction();
       
   727 
       
   728     Uid suite2Uid(L"[e0234a88]");
       
   729     JavaStorageApplicationEntry_t midlet2;
       
   730     attr.setEntry(NAME, L"MyMIDlet2");
       
   731     midlet2.insert(attr);
       
   732 
       
   733     attr.setEntry(PACKAGE_ID, suite2Uid.toString());
       
   734     midlet2.insert(attr);
       
   735 
       
   736     Uid midlet2Uid(L"[e02cba77]");
       
   737     attr.setEntry(ID, midlet2Uid.toString());
       
   738     midlet2.insert(attr);
       
   739 
       
   740     CHECK(jtu->populate(*js, appTableName, midlet2));
       
   741 
       
   742     JavaStorageApplicationEntry_t suite2;
       
   743 
       
   744     attr.setEntry(MEDIA_ID, L"-124614446");
       
   745     suite2.insert(attr);
       
   746 
       
   747     attr.setEntry(ID, suite2Uid.toString());
       
   748     suite2.insert(attr);
       
   749 
       
   750     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   751     js->commitTransaction();
       
   752 
       
   753     registry->InstalledMIDletUidsL(midletUids);
       
   754     CHECK(2 == midletUids.Count());
       
   755 
       
   756     // Check uids are the same. Entries are returned at same
       
   757     // order they're written.
       
   758     uidToTUid(midlet1Uid, midletUid);
       
   759     CHECK(midletUids[0] == midletUid);
       
   760 
       
   761     uidToTUid(midlet2Uid, midletUid);
       
   762     CHECK(midletUids[1] == midletUid);
       
   763 
       
   764     // Clean
       
   765     js->startTransaction();
       
   766     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   767     CHECK(jtu->remove(*js, appTableName, midlet2));
       
   768     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   769     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   770 
       
   771     js->commitTransaction();
       
   772     js->close();
       
   773 
       
   774     registry->Release();
       
   775 
       
   776     midletUids.Reset();
       
   777     midletUids.Close();
       
   778 
       
   779     LOG(EJavaStorage, EInfo, "-TestInstalledMIDletUidsL");
       
   780 }
       
   781 
       
   782 /**
       
   783  * Test CJavaRegistry::TestSuiteEntryExistsL() method.
       
   784  * 1. No UID in registry.
       
   785  * 2. One UID in registry.
       
   786  * 3. Application UID in registry. Entry must not exists.
       
   787  * 4. TUid::Null leaves KErrArgument.
       
   788  */
       
   789 TEST(TestLegacyRegistry, TestSuiteEntryExistsL)
       
   790 {
       
   791     LOG(EJavaStorage, EInfo, "+TestSuiteEntryExistsL");
       
   792 
       
   793     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   794     CHECK(registry != NULL);
       
   795 
       
   796     TUid uid = TUid::Uid(3777185127);    // e1234567
       
   797 
       
   798     // 1. No UID in registry.
       
   799     CHECK(registry->SuiteEntryExistsL(uid) == EFalse);
       
   800 
       
   801     // 4. TUid::Null leaves KErrArgument.
       
   802     TRAPD(err, registry->SuiteEntryExistsL(TUid::Null()));
       
   803     CHECK(KErrArgument == err);
       
   804 
       
   805     // Populate entry
       
   806     JavaStorageApplicationEntry_t suite1;
       
   807     JavaStorageEntry attr;
       
   808     attr.setEntry(PACKAGE_NAME, L"TestSuite1");
       
   809     suite1.insert(attr);
       
   810 
       
   811     attr.setEntry(JAR_PATH, L"Path/To/Jar");
       
   812     suite1.insert(attr);
       
   813 
       
   814     attr.setEntry(JAD_PATH, L"JAD/To/Path");
       
   815     suite1.insert(attr);
       
   816 
       
   817     attr.setEntry(VENDOR, L"TestSuite1Vendor");
       
   818     suite1.insert(attr);
       
   819 
       
   820     attr.setEntry(VERSION, L"1.2.3");
       
   821     suite1.insert(attr);
       
   822 
       
   823     attr.setEntry(MEDIA_ID, L"-124614446");
       
   824     suite1.insert(attr);
       
   825 
       
   826     string tableName = APPLICATION_PACKAGE_TABLE;
       
   827     Uid suite1Uid(L"[e0001111]");
       
   828     attr.setEntry(ID, suite1Uid.toString());
       
   829     suite1.insert(attr);
       
   830 
       
   831     js->open();
       
   832     js->startTransaction();
       
   833     CHECK(jtu->populate(*js, tableName, suite1));
       
   834 
       
   835     JavaStorageApplicationEntry_t midlet1;
       
   836     attr.setEntry(NAME, L"MyMIDlet1");
       
   837     midlet1.insert(attr);
       
   838 
       
   839     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   840     midlet1.insert(attr);
       
   841 
       
   842     string appTableName = APPLICATION_TABLE;
       
   843     Uid midlet1Uid(L"[e000bcd7]");
       
   844     attr.setEntry(ID, midlet1Uid.toString());
       
   845     midlet1.insert(attr);
       
   846 
       
   847     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   848     js->commitTransaction();
       
   849 
       
   850     // 2. One suite UID in registry.
       
   851     TUid suiteUid;
       
   852     uidToTUid(suite1Uid, suiteUid);
       
   853 
       
   854     CHECK(registry->SuiteEntryExistsL(suiteUid) == true);
       
   855 
       
   856     // 3. Application UID in registry. Entry must not exists.
       
   857 
       
   858     TUid midletUid;
       
   859     uidToTUid(midlet1Uid, midletUid);
       
   860     CHECK(registry->SuiteEntryExistsL(midletUid) == EFalse);
       
   861 
       
   862     js->startTransaction();
       
   863     CHECK(jtu->remove(*js, tableName, suite1));
       
   864     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   865     js->commitTransaction();
       
   866     js->close();
       
   867     registry->Release();
       
   868 
       
   869     LOG(EJavaStorage, EInfo, "-TestSuiteEntryExistsL");
       
   870 }
       
   871 
       
   872 /**
       
   873  * Test CJavaRegistry::TestSuiteEntryExistsL() method.
       
   874  * 1. Test no entries leaves KErrNotFound.
       
   875  * 2. Test empty name leaves KErrNotFound.
       
   876  * 3. Test empty vendor leaves KErrNotFound.
       
   877  * 4. Test not matching name leaves KErrNotFound.
       
   878  * 5. Test matching name and vendor found entry.
       
   879  */
       
   880 TEST(TestLegacyRegistry, TestSuiteEntryL2)
       
   881 {
       
   882     LOG(EJavaStorage, EInfo, "+TestSuiteEntryL2");
       
   883 
       
   884     MJavaRegistry* registry = MJavaRegistry::CreateL();
       
   885     CHECK(registry != NULL);
       
   886 
       
   887     MJavaRegistrySuiteEntry* suiteEntry = NULL;
       
   888     _LIT(KSuiteName, "TestMySuiteName");
       
   889     _LIT(KSuiteVendor, "TestMySuiteVendor");
       
   890 
       
   891     // 1. Test no entries leaves KErrNotFound.
       
   892     TRAPD(err, suiteEntry = registry->SuiteEntryL(KSuiteName, KSuiteVendor));
       
   893     CHECK(KErrNotFound == err);
       
   894 
       
   895     JavaStorageApplicationEntry_t suite1;
       
   896     JavaStorageEntry attr;
       
   897     attr.setEntry(PACKAGE_NAME, L"TestMySuiteName");
       
   898     suite1.insert(attr);
       
   899 
       
   900     attr.setEntry(VENDOR, L"TestMySuiteVendor");
       
   901     suite1.insert(attr);
       
   902 
       
   903     string tableName = APPLICATION_PACKAGE_TABLE;
       
   904     Uid suite1Uid(L"[e1111577]");
       
   905 
       
   906     attr.setEntry(ID, suite1Uid.toString());
       
   907     suite1.insert(attr);
       
   908 
       
   909     attr.setEntry(MEDIA_ID, L"-124614446");
       
   910     suite1.insert(attr);
       
   911 
       
   912     js->open();
       
   913     js->startTransaction();
       
   914     CHECK(jtu->populate(*js, tableName, suite1));
       
   915 
       
   916     JavaStorageApplicationEntry_t midlet1;
       
   917     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   918     midlet1.insert(attr);
       
   919 
       
   920     Uid midlet1Uid(L"[e3333577]");
       
   921     attr.setEntry(ID, midlet1Uid.toString());
       
   922     midlet1.insert(attr);
       
   923 
       
   924     string appTableName = APPLICATION_TABLE;
       
   925 
       
   926     CHECK(jtu->populate(*js, appTableName, midlet1));
       
   927     js->commitTransaction();
       
   928 
       
   929     // 2. Test empty name leaves KErrNotFound.
       
   930     TRAP(err, suiteEntry = registry->SuiteEntryL(KNullDesC, KSuiteVendor));
       
   931     CHECK(KErrArgument == err);
       
   932 
       
   933     // 3. Test empty vendor leaves KErrNotFound.
       
   934     TRAP(err, suiteEntry = registry->SuiteEntryL(KSuiteName, KNullDesC));
       
   935     CHECK(KErrArgument == err);
       
   936 
       
   937     // 4. Test not matching name leaves KErrNotFound.
       
   938     _LIT(KSuiteNameNoMatch, "NoMatchName");
       
   939     _LIT(KSuiteVendorNoMatch, "NoMatchVendor");
       
   940     TRAP(err, suiteEntry =
       
   941              registry->SuiteEntryL(KSuiteNameNoMatch, KSuiteVendorNoMatch));
       
   942     CHECK(KErrNotFound == err);
       
   943 
       
   944     // 5. Test matching name and vendor found entry.
       
   945     suiteEntry = registry->SuiteEntryL(KSuiteName, KSuiteVendor);
       
   946     CHECK(suiteEntry != NULL);
       
   947 
       
   948     TUid suiteUid;
       
   949     uidToTUid(suite1Uid, suiteUid);
       
   950     CHECK(suiteEntry->UidL() == suiteUid);
       
   951 
       
   952     js->startTransaction();
       
   953     CHECK(jtu->remove(*js, tableName, suite1));
       
   954     CHECK(jtu->remove(*js, appTableName, midlet1));
       
   955     js->commitTransaction();
       
   956     js->close();
       
   957 
       
   958     suiteEntry->Release();
       
   959     registry->Release();
       
   960 
       
   961     LOG(EJavaStorage, EInfo, "-TestSuiteEntryL2");
       
   962 }
       
   963