javamanager/javaregistry/tsrc/src/testregistryapplicationentry.cpp
branchRCL_3
changeset 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <string>
       
    20 #include <memory>
       
    21 
       
    22 #include "TestHarness.h"
       
    23 
       
    24 #include "javaregistry.h"
       
    25 #include "javaregistryapplicationentry.h"
       
    26 #include "javaregistrypackageentry.h"
       
    27 #include "javastorage.h"
       
    28 #include "javastorageexception.h"
       
    29 #include "javastoragenames.h"
       
    30 #include "javasymbianoslayer.h"
       
    31 #include "javauid.h"
       
    32 #include "logger.h"
       
    33 #include "mjavaattribute.h"
       
    34 #include "storagetestutils.h"
       
    35 
       
    36 using namespace std;
       
    37 using namespace Java;
       
    38 using namespace java::storage;
       
    39 using namespace java::util;
       
    40 
       
    41 /**
       
    42  * Test JavaRegistryApplicationEntry.
       
    43  */
       
    44 TEST_GROUP(TestRegistryApplicationEntry)
       
    45 {
       
    46     JavaStorage* js;
       
    47     JavaStorageTestUtils* jtu;
       
    48     CActiveScheduler* newScheduler;
       
    49 
       
    50     TEST_SETUP()
       
    51     {
       
    52         newScheduler = new CActiveScheduler();
       
    53         CActiveScheduler::Install(newScheduler);
       
    54 
       
    55         js = JavaStorage::createInstance();
       
    56         jtu = new JavaStorageTestUtils();
       
    57     }
       
    58     TEST_TEARDOWN()
       
    59     {
       
    60         try
       
    61         {
       
    62             js->rollbackTransaction();
       
    63             js->close();
       
    64             delete js;
       
    65             js = NULL;
       
    66         }
       
    67         catch (...)
       
    68         {
       
    69             // No can do
       
    70         }
       
    71 
       
    72         delete js;
       
    73         js = 0;
       
    74         delete jtu;
       
    75         jtu = 0;
       
    76 
       
    77         delete newScheduler;
       
    78         newScheduler = NULL;
       
    79     }
       
    80 };
       
    81 
       
    82 /**
       
    83  * Test CJavaRegistryApplicationEntry::IsStartable() method.
       
    84  * 1. Test return default value ETrue.
       
    85  */
       
    86 TEST(TestRegistryApplicationEntry, TestIsStartable)
       
    87 {
       
    88     LOG(EJavaStorage, EInfo, "+TestIsStartable");
       
    89 
       
    90     JavaStorageApplicationEntry_t midlet1;
       
    91     JavaStorageEntry attr;
       
    92 
       
    93     Uid suite1Uid(L"[e22a1111]");
       
    94 
       
    95     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
    96     midlet1.insert(attr);
       
    97 
       
    98     Uid midlet1Uid(L"[e22a1111]");
       
    99 
       
   100     attr.setEntry(ID, midlet1Uid.toString());
       
   101     midlet1.insert(attr);
       
   102 
       
   103     js->open();
       
   104     js->startTransaction();
       
   105 
       
   106     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   107 
       
   108     JavaStorageApplicationEntry_t suite1;
       
   109     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   110     suite1.insert(attr);
       
   111     attr.setEntry(MEDIA_ID, L"-124614446");
       
   112     suite1.insert(attr);
       
   113 
       
   114     wstring vendor = L"SuiteVendor";
       
   115     attr.setEntry(VENDOR, vendor);
       
   116     suite1.insert(attr);
       
   117 
       
   118     attr.setEntry(VERSION, L"0.1");
       
   119     suite1.insert(attr);
       
   120 
       
   121     attr.setEntry(ID, suite1Uid.toString());
       
   122     suite1.insert(attr);
       
   123 
       
   124     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   125 
       
   126     // Session must be committed before next use of Registry otherwise
       
   127     // it is locked.
       
   128     js->commitTransaction();
       
   129 
       
   130     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   131 
       
   132     TUid midletUid;
       
   133     uidToTUid(midlet1Uid, midletUid);
       
   134 
       
   135     CJavaRegistryApplicationEntry* entry =
       
   136         (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid);
       
   137 
       
   138     CHECK(entry != NULL);
       
   139     CHECK(entry->IsStartable() == true);
       
   140 
       
   141     delete entry;
       
   142     entry = NULL;
       
   143 
       
   144     // Clean
       
   145     js->startTransaction();
       
   146     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   147     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   148     js->commitTransaction();
       
   149     js->close();
       
   150 
       
   151     LOG(EJavaStorage, EInfo, "-TestIsStartable");
       
   152 }
       
   153 
       
   154 /**
       
   155  * Test CJavaRegistryApplicationEntry::IsVisible() method.
       
   156  * 1. Test return default value ETrue.
       
   157  */
       
   158 TEST(TestRegistryApplicationEntry, TestIsVisible)
       
   159 {
       
   160     LOG(EJavaStorage, EInfo, "+TestIsVisible");
       
   161     JavaStorageApplicationEntry_t midlet1;
       
   162     JavaStorageEntry attr;
       
   163 
       
   164     Uid suite1Uid(L"[e22a1111]");
       
   165 
       
   166     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   167     midlet1.insert(attr);
       
   168 
       
   169     Uid midlet1Uid(L"[e22a1111]");
       
   170 
       
   171     attr.setEntry(ID, midlet1Uid.toString());
       
   172     midlet1.insert(attr);
       
   173 
       
   174     js->open();
       
   175     js->startTransaction();
       
   176 
       
   177     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   178 
       
   179     JavaStorageApplicationEntry_t suite1;
       
   180     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   181     suite1.insert(attr);
       
   182 
       
   183     wstring vendor = L"SuiteVendor";
       
   184     attr.setEntry(VENDOR, vendor);
       
   185     suite1.insert(attr);
       
   186     attr.setEntry(MEDIA_ID, L"-124614446");
       
   187     suite1.insert(attr);
       
   188 
       
   189     attr.setEntry(VERSION, L"0.1");
       
   190     suite1.insert(attr);
       
   191 
       
   192     attr.setEntry(ID, suite1Uid.toString());
       
   193     suite1.insert(attr);
       
   194 
       
   195     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   196 
       
   197     // Session must be committed before next use of Registry otherwise
       
   198     // it is locked.
       
   199     js->commitTransaction();
       
   200 
       
   201     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   202 
       
   203     TUid midletUid;
       
   204     uidToTUid(midlet1Uid, midletUid);
       
   205 
       
   206     CJavaRegistryApplicationEntry* entry =
       
   207         (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid);
       
   208 
       
   209     CHECK(entry != NULL);
       
   210     CHECK(entry->IsVisible() == true);
       
   211 
       
   212     delete entry;
       
   213     entry = NULL;
       
   214 
       
   215     // Clean
       
   216     js->startTransaction();
       
   217     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   218     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   219     js->commitTransaction();
       
   220     js->close();
       
   221     LOG(EJavaStorage, EInfo, "-TestIsVisible");
       
   222 }
       
   223 
       
   224 /**
       
   225  * Test CJavaRegistryApplicationEntry::IsResident() method.
       
   226  * 1. Test return default value ETrue.
       
   227  */
       
   228 TEST(TestRegistryApplicationEntry, TestIsResident)
       
   229 {
       
   230     LOG(EJavaStorage, EInfo, "+TestIsResident");
       
   231     JavaStorageApplicationEntry_t midlet1;
       
   232     JavaStorageEntry attr;
       
   233 
       
   234     Uid suite1Uid(L"[e22a1111]");
       
   235 
       
   236     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   237     midlet1.insert(attr);
       
   238 
       
   239     Uid midlet1Uid(L"[e22a1111]");
       
   240 
       
   241     attr.setEntry(ID, midlet1Uid.toString());
       
   242     midlet1.insert(attr);
       
   243 
       
   244     js->open();
       
   245     js->startTransaction();
       
   246 
       
   247     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   248 
       
   249     JavaStorageApplicationEntry_t suite1;
       
   250     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   251     suite1.insert(attr);
       
   252     attr.setEntry(MEDIA_ID, L"-124614446");
       
   253     suite1.insert(attr);
       
   254 
       
   255     wstring vendor = L"SuiteVendor";
       
   256     attr.setEntry(VENDOR, vendor);
       
   257     suite1.insert(attr);
       
   258 
       
   259     attr.setEntry(VERSION, L"0.1");
       
   260     suite1.insert(attr);
       
   261 
       
   262     attr.setEntry(ID, suite1Uid.toString());
       
   263     suite1.insert(attr);
       
   264 
       
   265     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   266 
       
   267     // Session must be committed before next use of Registry otherwise
       
   268     // it is locked.
       
   269     js->commitTransaction();
       
   270 
       
   271     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   272 
       
   273     TUid midletUid;
       
   274     uidToTUid(midlet1Uid, midletUid);
       
   275 
       
   276     CJavaRegistryApplicationEntry* entry =
       
   277         (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid);
       
   278 
       
   279     CHECK(entry != NULL);
       
   280     CHECK(entry->IsResident() == true);
       
   281 
       
   282     delete entry;
       
   283     entry = NULL;
       
   284 
       
   285     // Clean
       
   286     js->startTransaction();
       
   287     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   288     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   289     js->commitTransaction();
       
   290     js->close();
       
   291     LOG(EJavaStorage, EInfo, "-TestIsResident");
       
   292 }
       
   293 
       
   294 /**
       
   295  * Test CJavaRegistryApplicationEntry::GroupName() method.
       
   296  * 1. Test return default value KNullDesC.
       
   297  * 2. Test IsStartable return ETrue.
       
   298  * 3. Test IsVisible return ETrue.
       
   299  * 4. Test IsResident return ETrue.
       
   300  */
       
   301 TEST(TestRegistryApplicationEntry, TestGroupName)
       
   302 {
       
   303     LOG(EJavaStorage, EInfo, "+TestGroupName");
       
   304     JavaStorageApplicationEntry_t midlet1;
       
   305     JavaStorageEntry attr;
       
   306 
       
   307     Uid suite1Uid(L"[e22a1111]");
       
   308 
       
   309     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   310     midlet1.insert(attr);
       
   311 
       
   312     Uid midlet1Uid(L"[e22a1111]");
       
   313 
       
   314     attr.setEntry(ID, midlet1Uid.toString());
       
   315     midlet1.insert(attr);
       
   316 
       
   317     js->open();
       
   318     js->startTransaction();
       
   319 
       
   320     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   321 
       
   322     JavaStorageApplicationEntry_t suite1;
       
   323     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   324     suite1.insert(attr);
       
   325     attr.setEntry(MEDIA_ID, L"-124614446");
       
   326     suite1.insert(attr);
       
   327 
       
   328     wstring vendor = L"SuiteVendor";
       
   329     attr.setEntry(VENDOR, vendor);
       
   330     suite1.insert(attr);
       
   331 
       
   332     attr.setEntry(VERSION, L"0.1");
       
   333     suite1.insert(attr);
       
   334 
       
   335     attr.setEntry(ID, suite1Uid.toString());
       
   336     suite1.insert(attr);
       
   337 
       
   338     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   339 
       
   340     // Session must be committed before next use of Registry otherwise
       
   341     // it is locked.
       
   342     js->commitTransaction();
       
   343 
       
   344     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   345 
       
   346     TUid midletUid;
       
   347     uidToTUid(midlet1Uid, midletUid);
       
   348 
       
   349     CJavaRegistryApplicationEntry* entry =
       
   350         (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid);
       
   351 
       
   352     CHECK(entry->IsStartable() == true);
       
   353     CHECK(entry->IsVisible() == true);
       
   354     CHECK(entry->IsResident() == true);
       
   355 
       
   356     CHECK(entry != NULL);
       
   357     CHECK(entry->GroupName() == KNullDesC);
       
   358 
       
   359     delete entry;
       
   360     entry = NULL;
       
   361 
       
   362     // Clean
       
   363     js->startTransaction();
       
   364     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   365     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   366     js->commitTransaction();
       
   367     js->close();
       
   368     LOG(EJavaStorage, EInfo, "-TestGroupName");
       
   369 }
       
   370 
       
   371 /**
       
   372  * Test CJavaRegistryApplicationEntry::PackageEntryL() method.
       
   373  * 1. Test return package entry.
       
   374  */
       
   375 TEST(TestRegistryApplicationEntry, TestPackageEntryL)
       
   376 {
       
   377     LOG(EJavaStorage, EInfo, "+TestPackageEntryL");
       
   378     JavaStorageApplicationEntry_t midlet1;
       
   379     JavaStorageEntry attr;
       
   380 
       
   381     Uid suite1Uid(L"[e22a2111]");
       
   382 
       
   383     attr.setEntry(PACKAGE_ID, suite1Uid.toString());
       
   384     midlet1.insert(attr);
       
   385 
       
   386     Uid midlet1Uid(L"[e22a2211]");
       
   387 
       
   388     attr.setEntry(ID, midlet1Uid.toString());
       
   389     midlet1.insert(attr);
       
   390 
       
   391     js->open();
       
   392     js->startTransaction();
       
   393 
       
   394     CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1));
       
   395 
       
   396     JavaStorageApplicationEntry_t suite1;
       
   397     attr.setEntry(PACKAGE_NAME, L"MySuite");
       
   398     suite1.insert(attr);
       
   399     attr.setEntry(MEDIA_ID, L"-124614446");
       
   400     suite1.insert(attr);
       
   401 
       
   402     wstring vendor = L"SuiteVendor";
       
   403     attr.setEntry(VENDOR, vendor);
       
   404     suite1.insert(attr);
       
   405 
       
   406     attr.setEntry(VERSION, L"0.1");
       
   407     suite1.insert(attr);
       
   408 
       
   409     attr.setEntry(ID, suite1Uid.toString());
       
   410     suite1.insert(attr);
       
   411 
       
   412     CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   413 
       
   414     // Session must be committed before next use of Registry otherwise
       
   415     // it is locked.
       
   416     js->commitTransaction();
       
   417 
       
   418     auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL());
       
   419 
       
   420     TUid midletUid;
       
   421     uidToTUid(midlet1Uid, midletUid);
       
   422 
       
   423     CJavaRegistryApplicationEntry* entry =
       
   424         (CJavaRegistryApplicationEntry*) registry->RegistryEntryL(midletUid);
       
   425     CHECK(entry != NULL);
       
   426 
       
   427     CJavaRegistryPackageEntry* packageEntry = entry->PackageEntryL();
       
   428     CHECK(packageEntry != NULL);
       
   429 
       
   430     TUid suiteUid;
       
   431     uidToTUid(suite1Uid, suiteUid);
       
   432 
       
   433     CHECK(packageEntry->Uid() == suiteUid);
       
   434 
       
   435     delete packageEntry;
       
   436     packageEntry = NULL;
       
   437 
       
   438     delete entry;
       
   439     entry = NULL;
       
   440 
       
   441     // Clean
       
   442     js->startTransaction();
       
   443     CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1));
       
   444     CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1));
       
   445     js->commitTransaction();
       
   446     js->close();
       
   447     registry.reset(0);
       
   448     LOG(EJavaStorage, EInfo, "-TestPackageEntryL");
       
   449 }