javamanager/javaregistry/tsrc/src/testregistry.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 #include <memory>
       
    21 
       
    22 #include "TestHarness.h"
       
    23 
       
    24 #include "javastorage.h"
       
    25 #include "javastorageexception.h"
       
    26 #include "javastoragenames.h"
       
    27 #include "javauid.h"
       
    28 #include "javasymbianoslayer.h"
       
    29 
       
    30 #include "storagetestutils.h"
       
    31 #include "javaregistry.h"
       
    32 #include "javaregistryentry.h"
       
    33 #include "logger.h"
       
    34 
       
    35 using namespace std;
       
    36 using namespace Java;
       
    37 using namespace java::storage;
       
    38 using namespace java::util;
       
    39 
       
    40 TEST_GROUP(TestRegistry)
       
    41 {
       
    42     JavaStorage* js;
       
    43     JavaStorageTestUtils* jtu;
       
    44     CActiveScheduler* newScheduler;
       
    45 
       
    46     TEST_SETUP()
       
    47     {
       
    48         newScheduler = new CActiveScheduler();
       
    49         CActiveScheduler::Install(newScheduler);
       
    50 
       
    51         js = JavaStorage::createInstance();
       
    52         jtu = new JavaStorageTestUtils();
       
    53     }
       
    54     TEST_TEARDOWN()
       
    55     {
       
    56         try
       
    57         {
       
    58             js->rollbackTransaction();
       
    59             js->close();
       
    60             delete js;
       
    61             js = NULL;
       
    62         }
       
    63         catch (...)
       
    64         {
       
    65             // No can do
       
    66         }
       
    67 
       
    68         delete js;
       
    69         js = 0;
       
    70         delete jtu;
       
    71         jtu = 0;
       
    72 
       
    73         delete newScheduler;
       
    74         newScheduler = NULL;
       
    75     }
       
    76 };
       
    77 
       
    78 /**
       
    79  * Test CJavaRegistry::RegistryEntryL(TUid) method.
       
    80  *   1. No UID in registry.
       
    81  *   2. No matching UID on registry.
       
    82  *   3. Suite UID found.
       
    83  *   4. MIDlet UID found.
       
    84  *   5. Query twice.
       
    85  *   6. Query with TUid::Null(). Null returned.
       
    86  */
       
    87 TEST(TestRegistry, TestRegistry)
       
    88 {
       
    89     LOG(EJavaStorage, EInfo, "+TestRegistry");
       
    90 
       
    91     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
    92     TUid uid = TUid::Uid(3777185127);    // e1234567
       
    93 
       
    94     // 1. No UID in registry
       
    95     CJavaRegistryEntry* entry = registry->RegistryEntryL(uid);
       
    96     CHECK(entry == NULL);
       
    97 
       
    98     // 2. No matching UID on registry.
       
    99     JavaStorageApplicationEntry_t populateEntry;
       
   100     JavaStorageEntry attr;
       
   101 
       
   102     attr.setEntry(PACKAGE_ID, L"[e1234577]");
       
   103     populateEntry.insert(attr);
       
   104 
       
   105     Uid entryUid(L"[e1234588]");
       
   106 
       
   107     attr.setEntry(ID, entryUid.toString());
       
   108     populateEntry.insert(attr);
       
   109 
       
   110     js->open(JAVA_DATABASE_NAME);
       
   111     js->startTransaction();
       
   112     CHECK(jtu->populate(*js, APPLICATION_TABLE, populateEntry));
       
   113 
       
   114     JavaStorageApplicationEntry_t packageEntry;
       
   115     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   116     packageEntry.insert(attr);
       
   117 
       
   118     Uid entryUid2(L"[e1234577]");
       
   119     attr.setEntry(ID, entryUid2.toString());
       
   120     packageEntry.insert(attr);
       
   121 
       
   122     attr.setEntry(MEDIA_ID, L"-124614446");
       
   123     packageEntry.insert(attr);
       
   124 
       
   125     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, packageEntry));
       
   126     js->commitTransaction();
       
   127 
       
   128     entry = registry->RegistryEntryL(uid);
       
   129     CHECK(entry == NULL);
       
   130 
       
   131     // 3. Suite UID found.
       
   132     TUid suiteUid;
       
   133     uidToTUid(entryUid2, suiteUid);
       
   134 
       
   135     entry = registry->RegistryEntryL(suiteUid);
       
   136     CHECK(entry != NULL);
       
   137 
       
   138     TUid regsuiteUid = entry->Uid();
       
   139 
       
   140     // Check suite UID;
       
   141     CHECK(regsuiteUid == suiteUid);
       
   142 
       
   143     delete entry;
       
   144     entry = NULL;
       
   145 
       
   146     TUid midletUid;
       
   147     uidToTUid(entryUid, midletUid);
       
   148 
       
   149     // 4. MIDlet UID found.
       
   150     entry = registry->RegistryEntryL(midletUid);
       
   151     CHECK(entry != NULL);
       
   152 
       
   153     TUid regMidletUid = entry->Uid();
       
   154 
       
   155     // Check UID;
       
   156     CHECK(regMidletUid == midletUid);
       
   157 
       
   158     delete entry;
       
   159     entry = NULL;
       
   160 
       
   161     // 5. Query twice. This is second query
       
   162     entry = registry->RegistryEntryL(midletUid);
       
   163     CHECK(entry != NULL);
       
   164 
       
   165     regMidletUid = entry->Uid();
       
   166 
       
   167     // Check UID;
       
   168     CHECK(regMidletUid == midletUid);
       
   169 
       
   170     delete entry;
       
   171     entry = NULL;
       
   172 
       
   173     // 6. Query with TUid::Null()
       
   174     uid = TUid::Null();
       
   175 
       
   176     entry = registry->RegistryEntryL(uid);
       
   177     CHECK(entry == NULL);
       
   178 
       
   179     // Clean
       
   180     js->startTransaction();
       
   181     CHECK(jtu->remove(*js, APPLICATION_TABLE, populateEntry));
       
   182     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, packageEntry));
       
   183 
       
   184     js->commitTransaction();
       
   185     js->close();
       
   186     registry.reset(0);
       
   187     LOG(EJavaStorage, EInfo, "-TestRegistry");
       
   188 }
       
   189 
       
   190 /**
       
   191  * Test RegistryEntryL when multiple entries stored to registry.
       
   192  * 1. Several suites.
       
   193  * 2. Several MIDlets.
       
   194  */
       
   195 TEST(TestRegistry, TestRegistryMultiEntry)
       
   196 {
       
   197     LOG(EJavaStorage, EInfo, "+TestMultiRegistry");
       
   198 
       
   199     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   200 
       
   201     // Populate first MIDlet
       
   202     JavaStorageApplicationEntry_t midlet1;
       
   203     JavaStorageEntry attr;
       
   204 
       
   205     attr.setEntry(PACKAGE_ID, L"[e1234577]");
       
   206     midlet1.insert(attr);
       
   207 
       
   208     string tableName = APPLICATION_TABLE;
       
   209     Uid appUid(L"[e1234588]");
       
   210 
       
   211     attr.setEntry(ID, appUid.toString());
       
   212     midlet1.insert(attr);
       
   213 
       
   214     js->open(JAVA_DATABASE_NAME);
       
   215     js->startTransaction();
       
   216 
       
   217     CHECK(jtu->populate(*js, tableName, midlet1));
       
   218 
       
   219     JavaStorageApplicationEntry_t suite1;
       
   220     attr.setEntry(PACKAGE_NAME, L"MySuite1");
       
   221     suite1.insert(attr);
       
   222 
       
   223     Uid suiteUid1(L"[e1234588]");
       
   224     attr.setEntry(ID, suiteUid1.toString());
       
   225     suite1.insert(attr);
       
   226 
       
   227     attr.setEntry(MEDIA_ID, L"-124614446");
       
   228     suite1.insert(attr);
       
   229 
       
   230     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   231 
       
   232     // Populate second MIDlet
       
   233     JavaStorageApplicationEntry_t midlet2;
       
   234 
       
   235     attr.setEntry(PACKAGE_ID, L"[e1234512]");
       
   236     midlet2.insert(attr);
       
   237 
       
   238     Uid midletUid2(L"[e1234a12]");
       
   239     attr.setEntry(ID, midletUid2.toString());
       
   240     midlet2.insert(attr);
       
   241 
       
   242     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2));
       
   243 
       
   244     JavaStorageApplicationEntry_t suite2;
       
   245     attr.setEntry(PACKAGE_NAME, L"MySuite2");
       
   246     suite2.insert(attr);
       
   247 
       
   248     Uid suiteUid2(L"[e1234512]");
       
   249     attr.setEntry(ID, suiteUid2.toString());
       
   250     suite2.insert(attr);
       
   251 
       
   252     attr.setEntry(MEDIA_ID, L"-124614446");
       
   253     suite2.insert(attr);
       
   254 
       
   255     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   256 
       
   257     // Populate third MIDlet
       
   258     JavaStorageApplicationEntry_t midlet3;
       
   259 
       
   260     attr.setEntry(PACKAGE_ID, L"[e1234513]");
       
   261     midlet3.insert(attr);
       
   262 
       
   263     Uid midletUid3(L"[e1234a13]");
       
   264     attr.setEntry(ID, midletUid3.toString());
       
   265     midlet3.insert(attr);
       
   266 
       
   267     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet3));
       
   268 
       
   269     JavaStorageApplicationEntry_t suite3;
       
   270     attr.setEntry(PACKAGE_NAME, L"MySuite3");
       
   271     suite3.insert(attr);
       
   272 
       
   273     Uid suiteUid3(L"[e1234513]");
       
   274     attr.setEntry(ID, suiteUid3.toString());
       
   275     suite3.insert(attr);
       
   276 
       
   277     attr.setEntry(MEDIA_ID, L"-124614446");
       
   278     suite3.insert(attr);
       
   279 
       
   280     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite3));
       
   281 
       
   282     // Session must be committed before next use of Registry otherwise
       
   283     // it is locked.
       
   284     js->commitTransaction();
       
   285 
       
   286     // Suite UID.
       
   287     TUid uid = TUid::Uid(3777185043);    // e1234513 Suite uid
       
   288     CJavaRegistryEntry* entry = registry->RegistryEntryL(uid);
       
   289     CHECK(entry != NULL);
       
   290 
       
   291     TUid suiteUid = entry->Uid();
       
   292 
       
   293     // Check suite UID;
       
   294     CHECK(suiteUid.iUid == uid.iUid);
       
   295 
       
   296     delete entry;
       
   297     entry = NULL;
       
   298 
       
   299     // MIDlet UID.
       
   300     uid = TUid::Uid(3777186322);    // e1234a12 MIDlet
       
   301 
       
   302     entry = registry->RegistryEntryL(uid);
       
   303     CHECK(entry != NULL);
       
   304 
       
   305     TUid midletUid = entry->Uid();
       
   306 
       
   307     // Check suite UID;
       
   308     CHECK(midletUid.iUid == uid.iUid);
       
   309 
       
   310     delete entry;
       
   311     entry = NULL;
       
   312 
       
   313     // Clean
       
   314     js->startTransaction();
       
   315     tableName = APPLICATION_TABLE;
       
   316     CHECK(jtu->remove(*js, tableName, midlet1));
       
   317     CHECK(jtu->remove(*js, tableName, midlet2));
       
   318     CHECK(jtu->remove(*js, tableName, midlet3));
       
   319 
       
   320     tableName = APPLICATION_PACKAGE_TABLE;
       
   321     CHECK(jtu->remove(*js, tableName, suite1));
       
   322     CHECK(jtu->remove(*js, tableName, suite2));
       
   323     CHECK(jtu->remove(*js, tableName, suite3));
       
   324 
       
   325     js->commitTransaction();
       
   326     js->close();
       
   327     registry.reset(0);
       
   328     LOG(EJavaStorage, EInfo, "-TestMultiRegistry");
       
   329 }
       
   330 
       
   331 /**
       
   332  * Test CJavaRegistry::RegistryEntryExistsL(TUid) method.
       
   333  *   1. No UID in registry.
       
   334  *   2. No matching UID on registry.
       
   335  *   3. Suite UID found.
       
   336  *   4. MIDlet UID found.
       
   337  *   5. Query twice.
       
   338  *   6. Query with TUid::Null(). Leaves KErrArgument.
       
   339  */
       
   340 TEST(TestRegistry, TestEntryExists)
       
   341 {
       
   342     LOG(EJavaStorage, EInfo, "+TestEntryExists");
       
   343 
       
   344     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   345     TUid uid = TUid::Uid(3777185127);    // e1234567
       
   346 
       
   347     // 1. No UID in registry
       
   348     TBool exists = registry->RegistryEntryExistsL(uid);
       
   349     CHECK(false == exists);
       
   350 
       
   351     // 2. No matching UID on registry.
       
   352     JavaStorageApplicationEntry_t populateEntry;
       
   353     JavaStorageEntry attr;
       
   354 
       
   355     attr.setEntry(PACKAGE_ID, L"[e1234577]");
       
   356     populateEntry.insert(attr);
       
   357 
       
   358     Uid entryUid(L"[e1234588]");
       
   359 
       
   360     attr.setEntry(ID, entryUid.toString());
       
   361     populateEntry.insert(attr);
       
   362 
       
   363     string tableName = APPLICATION_TABLE;
       
   364 
       
   365     js->open(JAVA_DATABASE_NAME);
       
   366     js->startTransaction();
       
   367 
       
   368     CHECK(jtu->populate(*js, tableName, populateEntry));
       
   369 
       
   370     JavaStorageApplicationEntry_t packageEntry;
       
   371     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   372     packageEntry.insert(attr);
       
   373 
       
   374     Uid entryUid2(L"[e1234577]");
       
   375     attr.setEntry(ID, entryUid2.toString());
       
   376     packageEntry.insert(attr);
       
   377 
       
   378     attr.setEntry(MEDIA_ID, L"-124614446");
       
   379     packageEntry.insert(attr);
       
   380 
       
   381     tableName = APPLICATION_PACKAGE_TABLE;
       
   382 
       
   383     CHECK(jtu->populate(*js, tableName, packageEntry));
       
   384 
       
   385     // Session must be committed before next use of Registry otherwise
       
   386     // it is locked.
       
   387     js->commitTransaction();
       
   388 
       
   389     exists = registry->RegistryEntryExistsL(uid);
       
   390     CHECK(false == exists);
       
   391 
       
   392     // 3. Suite UID found.
       
   393     uid = TUid::Uid(3777185143);    // E1234577 aka suiteUID
       
   394 
       
   395     exists = registry->RegistryEntryExistsL(uid);
       
   396     CHECK(true == exists);
       
   397 
       
   398     // 4. MIDlet UID found.
       
   399     uid = TUid::Uid(3777185160);    // E1234588 aka midletUID
       
   400 
       
   401     exists = registry->RegistryEntryExistsL(uid);
       
   402     CHECK(true == exists);
       
   403 
       
   404     // 5. Query twice. This is second query
       
   405     exists = registry->RegistryEntryExistsL(uid);
       
   406     CHECK(true == exists);
       
   407 
       
   408     // 6. Query with TUid::Null()
       
   409     uid = TUid::Null();
       
   410 
       
   411     TRAPD(err, exists = registry->RegistryEntryExistsL(uid));
       
   412     CHECK(KErrArgument == err);
       
   413 
       
   414     // Clean
       
   415     js->startTransaction();
       
   416     tableName = APPLICATION_TABLE;
       
   417     CHECK(jtu->remove(*js, tableName, populateEntry));
       
   418 
       
   419     tableName = APPLICATION_PACKAGE_TABLE;
       
   420     CHECK(jtu->remove(*js, tableName, packageEntry));
       
   421 
       
   422     js->commitTransaction();
       
   423     js->close();
       
   424     registry.reset(0);
       
   425     LOG(EJavaStorage, EInfo, "-TestEntryExists");
       
   426 }
       
   427 
       
   428 /**
       
   429  * Test CJavaRegistry::GetRegistryEntryUidsL(RArray) method.
       
   430  *   1. No UID in registry.
       
   431  *   2. Suite and MIDlet UID found.
       
   432  *   3. Two MIDlets within same Suite.
       
   433  *   4. Two suites and MIDlets.
       
   434  *   5. Query twice.
       
   435  *   6. Invalid uid is not added.
       
   436  */
       
   437 TEST(TestRegistry, TestGetRegistryEntryUidsL)
       
   438 {
       
   439     LOG(EJavaStorage, EInfo, "+TestGetRegistryEntryUidsL");
       
   440     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   441 
       
   442     // 1. No UID in registry
       
   443     RArray<TUid> uids;
       
   444     registry->GetRegistryEntryUidsL(uids);
       
   445     CHECK(uids.Count() == 0);
       
   446 
       
   447     uids.Reset();
       
   448 
       
   449     // 2. Suite and MIDlet UID found.
       
   450     JavaStorageApplicationEntry_t populateEntry;
       
   451     JavaStorageEntry attr;
       
   452 
       
   453     Uid suiteUid1(L"[e1234577]");
       
   454     attr.setEntry(PACKAGE_ID, suiteUid1.toString());
       
   455     populateEntry.insert(attr);
       
   456 
       
   457     Uid midletUid1(L"[e1234588]");
       
   458 
       
   459     attr.setEntry(ID, midletUid1.toString());
       
   460     populateEntry.insert(attr);
       
   461 
       
   462     string tableName = APPLICATION_TABLE;
       
   463 
       
   464     js->open(JAVA_DATABASE_NAME);
       
   465     js->startTransaction();
       
   466     CHECK(jtu->populate(*js, tableName, populateEntry));
       
   467 
       
   468     JavaStorageApplicationEntry_t suite1;
       
   469     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   470     suite1.insert(attr);
       
   471 
       
   472     attr.setEntry(ID, suiteUid1.toString());
       
   473     suite1.insert(attr);
       
   474 
       
   475     attr.setEntry(MEDIA_ID, L"-124614446");
       
   476     suite1.insert(attr);
       
   477 
       
   478     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   479 
       
   480     // Session must be committed before next use of Registry otherwise
       
   481     // it is locked.
       
   482     js->commitTransaction();
       
   483 
       
   484     registry->GetRegistryEntryUidsL(uids);
       
   485     CHECK(uids.Count() == 2);
       
   486 
       
   487     TUid suiteUid;
       
   488     uidToTUid(suiteUid1, suiteUid);
       
   489 
       
   490     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   491 
       
   492     TUid midletUid;
       
   493     uidToTUid(midletUid1, midletUid);
       
   494 
       
   495     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   496 
       
   497     uids.Reset();
       
   498 
       
   499     // 3. Two MIDlets within same Suite.
       
   500     JavaStorageApplicationEntry_t populateEntry2;
       
   501 
       
   502     attr.setEntry(PACKAGE_ID, suiteUid1.toString());
       
   503     populateEntry2.insert(attr);
       
   504 
       
   505     Uid midletUid2(L"[e123D58A]");
       
   506 
       
   507     attr.setEntry(ID, midletUid2.toString());
       
   508     populateEntry2.insert(attr);
       
   509 
       
   510     js->open(JAVA_DATABASE_NAME);
       
   511     js->startTransaction();
       
   512     CHECK(jtu->populate(*js, tableName, populateEntry2));
       
   513 
       
   514     // Session must be committed before next use of Registry otherwise
       
   515     // it is locked.
       
   516     js->commitTransaction();
       
   517 
       
   518     registry->GetRegistryEntryUidsL(uids);
       
   519     CHECK(uids.Count() == 3);
       
   520 
       
   521     uidToTUid(suiteUid1, suiteUid);
       
   522     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   523 
       
   524     uidToTUid(midletUid1, midletUid);
       
   525     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   526 
       
   527     uidToTUid(midletUid2, midletUid);
       
   528     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   529 
       
   530     uids.Reset();
       
   531 
       
   532     // 4. Two suites and MIDlets.
       
   533     JavaStorageApplicationEntry_t populateEntry3;
       
   534 
       
   535     Uid suiteUid2(L"[e12345AA]");
       
   536     attr.setEntry(PACKAGE_ID, suiteUid2.toString());
       
   537     populateEntry3.insert(attr);
       
   538 
       
   539     Uid midletUid3(L"[e12345DD]");
       
   540 
       
   541     attr.setEntry(ID, midletUid3.toString());
       
   542     populateEntry3.insert(attr);
       
   543 
       
   544     js->open(JAVA_DATABASE_NAME);
       
   545     js->startTransaction();
       
   546     CHECK(jtu->populate(*js, tableName, populateEntry3));
       
   547 
       
   548     JavaStorageApplicationEntry_t suite2;
       
   549     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   550     suite2.insert(attr);
       
   551 
       
   552     attr.setEntry(ID, suiteUid2.toString());
       
   553     suite2.insert(attr);
       
   554 
       
   555     attr.setEntry(MEDIA_ID, L"-124614446");
       
   556     suite2.insert(attr);
       
   557 
       
   558     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   559 
       
   560     // Session must be committed before next use of Registry otherwise
       
   561     // it is locked.
       
   562     js->commitTransaction();
       
   563 
       
   564     registry->GetRegistryEntryUidsL(uids);
       
   565     CHECK(uids.Count() == 5);
       
   566 
       
   567     uidToTUid(suiteUid1, suiteUid);
       
   568     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   569     uidToTUid(suiteUid2, suiteUid);
       
   570     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   571 
       
   572     uidToTUid(midletUid1, midletUid);
       
   573     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   574     uidToTUid(midletUid2, midletUid);
       
   575     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   576     uidToTUid(midletUid3, midletUid);
       
   577     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   578 
       
   579     uids.Reset();
       
   580 
       
   581     // 5. Query twice.
       
   582     registry->GetRegistryEntryUidsL(uids);
       
   583     CHECK(uids.Count() == 5);
       
   584     uids.Reset();
       
   585 
       
   586     // 6. Invalid uid is not added.
       
   587     JavaStorageApplicationEntry_t populateEntry4;
       
   588 
       
   589     attr.setEntry(PACKAGE_ID, L"[123G5678]");
       
   590     populateEntry4.insert(attr);
       
   591 
       
   592     attr.setEntry(ID, L"[e123G5DD]");
       
   593     populateEntry4.insert(attr);
       
   594 
       
   595     js->open();
       
   596     js->startTransaction();
       
   597     CHECK(jtu->populate(*js, tableName, populateEntry4));
       
   598 
       
   599     // Session must be committed before next use of Registry otherwise
       
   600     // it is locked.
       
   601     js->commitTransaction();
       
   602 
       
   603     registry->GetRegistryEntryUidsL(uids);
       
   604 
       
   605     // Invalid is not added
       
   606     CHECK(uids.Count() == 5);
       
   607 
       
   608     uids.Reset();
       
   609     uids.Close();
       
   610 
       
   611     CHECK(jtu->remove(*js, tableName, populateEntry));
       
   612     CHECK(jtu->remove(*js, tableName, populateEntry2));
       
   613     CHECK(jtu->remove(*js, tableName, populateEntry3));
       
   614     CHECK(jtu->remove(*js, tableName, populateEntry4));
       
   615     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   616     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   617     js->close();
       
   618 
       
   619     registry.reset(0);
       
   620     LOG(EJavaStorage, EInfo, "-TestGetRegistryEntryUidsL");
       
   621 }
       
   622 
       
   623 /**
       
   624  * Test CJavaRegistry::GetRegistryEntryUidsL(Type, RArray) method.
       
   625  *   1. No UID in registry for application type.
       
   626  *   2. No UID in registry for suite type.
       
   627  *   3. Unknown type.
       
   628  *   4. Suite UID when MIDlet and suite populated.
       
   629  *   5. General suite UID when MIDlet and suite populated.
       
   630  *   6. MIDlet UID when MIDlet and suite populated.
       
   631  *   7. General app UID when MIDlet and suite populated.
       
   632  *   8. Two MIDlets within same Suite.
       
   633  *   9. Two suites and MIDlets.
       
   634  *   10. Invalid uid is not added.
       
   635  *   11. Unknown type when app is populated.
       
   636  */
       
   637 TEST(TestRegistry, TestGetRegistryEntryUidsL2)
       
   638 {
       
   639     LOG(EJavaStorage, EInfo, "+TestGetRegistryEntryUidsL2");
       
   640     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   641 
       
   642     // 1. No UID in registry for application type.
       
   643     RArray<TUid> uids;
       
   644     registry->GetRegistryEntryUidsL(EGeneralApplication, uids);
       
   645     CHECK(uids.Count() == 0);
       
   646 
       
   647     registry->GetRegistryEntryUidsL(EMidp2Midlet, uids);
       
   648     CHECK(uids.Count() == 0);
       
   649 
       
   650     // 2. No UID in registry for suite type.
       
   651     registry->GetRegistryEntryUidsL(EGeneralPackage, uids);
       
   652     CHECK(uids.Count() == 0);
       
   653 
       
   654     registry->GetRegistryEntryUidsL(EMidp2MidletSuite, uids);
       
   655     CHECK(uids.Count() == 0);
       
   656 
       
   657     // 3. Unknown type.
       
   658     registry->GetRegistryEntryUidsL(EERCP, uids);
       
   659     CHECK(uids.Count() == 0);
       
   660     uids.Reset();
       
   661 
       
   662     JavaStorageApplicationEntry_t populateEntry;
       
   663     JavaStorageEntry attr;
       
   664 
       
   665     Uid suiteUid1(L"[e1234577]");
       
   666     attr.setEntry(PACKAGE_ID, suiteUid1.toString());
       
   667     populateEntry.insert(attr);
       
   668 
       
   669     Uid midletUid1(L"[e1234588]");
       
   670     attr.setEntry(ID, midletUid1.toString());
       
   671     populateEntry.insert(attr);
       
   672 
       
   673     string tableName = APPLICATION_TABLE;
       
   674 
       
   675     js->open();
       
   676     js->startTransaction();
       
   677     CHECK(jtu->populate(*js, tableName, populateEntry));
       
   678 
       
   679     JavaStorageApplicationEntry_t suite1;
       
   680     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   681     suite1.insert(attr);
       
   682 
       
   683     attr.setEntry(ID, suiteUid1.toString());
       
   684     suite1.insert(attr);
       
   685 
       
   686     attr.setEntry(MEDIA_ID, L"-124614446");
       
   687     suite1.insert(attr);
       
   688 
       
   689     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   690 
       
   691     // Session must be committed before next use of Registry otherwise
       
   692     // it is locked.
       
   693     js->commitTransaction();
       
   694 
       
   695     // 4. Suite UID when MIDlet and suite populated.
       
   696     registry->GetRegistryEntryUidsL(EMidp2MidletSuite, uids);
       
   697     CHECK(uids.Count() == 1);
       
   698     uids.Reset();
       
   699 
       
   700     // 5. General suite UID when MIDlet and suite populated.
       
   701     registry->GetRegistryEntryUidsL(EGeneralPackage, uids);
       
   702     CHECK(uids.Count() == 1);
       
   703     uids.Reset();
       
   704 
       
   705     // 6. MIDlet UID when MIDlet and suite populated.
       
   706     registry->GetRegistryEntryUidsL(EMidp2Midlet, uids);
       
   707     CHECK(uids.Count() == 1);
       
   708     uids.Reset();
       
   709 
       
   710     // 7. General app UID when MIDlet and suite populated.
       
   711     registry->GetRegistryEntryUidsL(EGeneralApplication, uids);
       
   712     CHECK(uids.Count() == 1);
       
   713     uids.Reset();
       
   714 
       
   715     // 8. Two MIDlets within same Suite.
       
   716     JavaStorageApplicationEntry_t populateEntry2;
       
   717 
       
   718     attr.setEntry(PACKAGE_ID, suiteUid1.toString());
       
   719     populateEntry2.insert(attr);
       
   720 
       
   721     Uid midletUid2(L"[e123D58A]");
       
   722 
       
   723     attr.setEntry(ID, midletUid2.toString());
       
   724     populateEntry2.insert(attr);
       
   725 
       
   726     js->startTransaction();
       
   727     CHECK(jtu->populate(*js, tableName, populateEntry2));
       
   728 
       
   729     // Session must be committed before next use of Registry otherwise
       
   730     // it is locked.
       
   731     js->commitTransaction();
       
   732 
       
   733     registry->GetRegistryEntryUidsL(EMidp2MidletSuite, uids);
       
   734     CHECK(uids.Count() == 1);
       
   735 
       
   736     TUid suiteUid;
       
   737     uidToTUid(suiteUid1, suiteUid);
       
   738     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   739     uids.Reset();
       
   740 
       
   741     registry->GetRegistryEntryUidsL(EMidp2Midlet, uids);
       
   742     CHECK(uids.Count() == 2);
       
   743     uids.Reset();
       
   744 
       
   745     registry->GetRegistryEntryUidsL(EGeneralApplication, uids);
       
   746     CHECK(uids.Count() == 2);
       
   747 
       
   748     TUid midletUid;
       
   749     uidToTUid(midletUid1, midletUid);
       
   750     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   751 
       
   752     uidToTUid(midletUid2, midletUid);
       
   753     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   754 
       
   755     uids.Reset();
       
   756 
       
   757     // 9. Two suites and MIDlets.
       
   758     JavaStorageApplicationEntry_t populateEntry3;
       
   759 
       
   760     Uid suiteUid2(L"[e12345AA]");
       
   761     attr.setEntry(PACKAGE_ID, suiteUid2.toString());
       
   762     populateEntry3.insert(attr);
       
   763 
       
   764     Uid midletUid3(L"[e12345DD]");
       
   765     attr.setEntry(ID, midletUid3.toString());
       
   766     populateEntry3.insert(attr);
       
   767 
       
   768     // js->open();
       
   769     js->startTransaction();
       
   770     CHECK(jtu->populate(*js, tableName, populateEntry3));
       
   771 
       
   772     JavaStorageApplicationEntry_t suite2;
       
   773     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   774     suite2.insert(attr);
       
   775 
       
   776     attr.setEntry(ID, suiteUid2.toString());
       
   777     suite2.insert(attr);
       
   778 
       
   779     attr.setEntry(MEDIA_ID, L"-124614446");
       
   780     suite2.insert(attr);
       
   781 
       
   782     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   783 
       
   784     // Session must be committed before next use of Registry otherwise
       
   785     // it is locked.
       
   786     js->commitTransaction();
       
   787 
       
   788     registry->GetRegistryEntryUidsL(EMidp2MidletSuite, uids);
       
   789     CHECK(uids.Count() == 2);
       
   790 
       
   791     uidToTUid(suiteUid1, suiteUid);
       
   792     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   793     uidToTUid(suiteUid2, suiteUid);
       
   794     CHECK(uids.Find(suiteUid) != KErrNotFound);
       
   795     uids.Reset();
       
   796 
       
   797     registry->GetRegistryEntryUidsL(EMidp2Midlet, uids);
       
   798     CHECK(uids.Count() == 3);
       
   799 
       
   800     uidToTUid(midletUid1, midletUid);
       
   801     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   802     uidToTUid(midletUid2, midletUid);
       
   803     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   804     uidToTUid(midletUid3, midletUid);
       
   805     CHECK(uids.Find(midletUid) != KErrNotFound);
       
   806 
       
   807     uids.Reset();
       
   808 
       
   809     // 10. Invalid uid is not added.
       
   810     JavaStorageApplicationEntry_t populateEntry4;
       
   811 
       
   812     attr.setEntry(PACKAGE_ID, L"[123G5678]");
       
   813     populateEntry4.insert(attr);
       
   814 
       
   815     attr.setEntry(ID, L"[e123G5DD]");
       
   816     populateEntry4.insert(attr);
       
   817 
       
   818     js->startTransaction();
       
   819     CHECK(jtu->populate(*js, tableName, populateEntry4));
       
   820 
       
   821     // Session must be committed before next use of Registry otherwise
       
   822     // it is locked.
       
   823     js->commitTransaction();
       
   824 
       
   825     registry->GetRegistryEntryUidsL(EMidp2MidletSuite, uids);
       
   826     CHECK(uids.Count() == 2);
       
   827     uids.Reset();
       
   828 
       
   829     registry->GetRegistryEntryUidsL(EMidp2Midlet, uids);
       
   830     CHECK(uids.Count() == 3);
       
   831     uids.Reset();
       
   832 
       
   833     // 11. Unknown type when app is populated.
       
   834     registry->GetRegistryEntryUidsL(EERCP, uids);
       
   835     CHECK(uids.Count() == 0);
       
   836     uids.Reset();
       
   837 
       
   838     CHECK(jtu->remove(*js, tableName, populateEntry));
       
   839     CHECK(jtu->remove(*js, tableName, populateEntry2));
       
   840     CHECK(jtu->remove(*js, tableName, populateEntry3));
       
   841     CHECK(jtu->remove(*js, tableName, populateEntry4));
       
   842     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   843     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2));
       
   844     js->close();
       
   845 
       
   846     registry.reset(0);
       
   847     LOG(EJavaStorage, EInfo, "-TestGetRegistryEntryUidsL2");
       
   848 }