appfw/apparchitecture/tef/t_nonnativetest.cpp
branchRCL_3
changeset 20 c2c61fdca848
parent 19 924385140d98
child 21 9af619316cbf
equal deleted inserted replaced
19:924385140d98 20:c2c61fdca848
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent - Internal Symbian test code 
       
    19 */
       
    20 
       
    21 #include "t_nonnativetest.h"
       
    22 #include <e32base.h>
       
    23 #include <e32cmn.h> 
       
    24 #include "T_SisFileInstaller.h"
       
    25 #include <apgtask.h>
       
    26 #include <apgnotif.h>
       
    27 #include <e32property.h>
       
    28 #include<usif/scr/appregentries.h>
       
    29 #include "testableapalssession.h"
       
    30 #include "appfwk_test_utils.h"
       
    31 #include "apacmdln.h"
       
    32 #include "apgicnflpartner.h"
       
    33 
       
    34 _LIT(KTNonNativeRuntimeSisFile, "z:\\apparctest\\apparctestsisfiles\\tnonnativeruntime.sis");
       
    35 _LIT(KTNonNativeRuntimeComponent, "TNonNativeRunTime"); 
       
    36 
       
    37 _LIT(KTestScrDBSource, "z:\\apparctest\\scr_test.db");
       
    38 _LIT(KScrDBSource, "z:\\apparctest\\scr.db");
       
    39 _LIT(KScrDBTarget, "c:\\sys\\install\\scr\\scr.db");
       
    40 _LIT(KScrDBTempTarget, "c:\\sys\\install\\scr\\scr_temp.db");
       
    41 
       
    42 
       
    43 _LIT(KNonNotiveAppName, "\\268454131.fakeapp"); 
       
    44 
       
    45 const TUid KMidletUid={0x10210E26};
       
    46 const TUid KWidgetUid={0x10282821};
       
    47 const TUid KTestNonNativeUid={0xFF51233};
       
    48 
       
    49 const TUid KUidNonNativeRuntime={0xA0001002};
       
    50 
       
    51 const TUid KPropertyCategory = {0x101F289C};
       
    52 const TUint KNonNativeTestPropertyKey = 2;
       
    53 
       
    54 CT_NonNativeTestStep::~CT_NonNativeTestStep()
       
    55 /**
       
    56    Destructor
       
    57  */
       
    58     {
       
    59     }
       
    60 
       
    61 CT_NonNativeTestStep::CT_NonNativeTestStep()
       
    62 /**
       
    63    Constructor
       
    64  */
       
    65     {
       
    66     // Call base class method to set up the human readable name for logging
       
    67     SetTestStepName(KT_NonNativeTestStep);
       
    68     }
       
    69 
       
    70 TVerdict CT_NonNativeTestStep::doTestStepPreambleL()
       
    71 /**
       
    72    @return - TVerdict code
       
    73    Override of base class virtual
       
    74  */
       
    75     {
       
    76    
       
    77     //Create property which is used for communication between test and non-native runtime.
       
    78     TInt error;
       
    79     error=RProperty::Define(KPropertyCategory, KNonNativeTestPropertyKey, RProperty::EInt);
       
    80     if((error != KErrNone) && (error != KErrAlreadyExists))
       
    81         User::Leave(error);
       
    82     
       
    83     SetTestStepResult(EPass);
       
    84     return TestStepResult();
       
    85     }
       
    86 
       
    87 TVerdict CT_NonNativeTestStep::doTestStepPostambleL()
       
    88 /**
       
    89    @return - TVerdict code
       
    90    Override of base class virtual
       
    91  */
       
    92     {
       
    93     RProperty::Delete(KPropertyCategory, KNonNativeTestPropertyKey);
       
    94     
       
    95     return TestStepResult();
       
    96     }
       
    97     
       
    98     
       
    99 TVerdict CT_NonNativeTestStep::doTestStepL()
       
   100 {
       
   101     RunTestCases();
       
   102     return TestStepResult();
       
   103 }
       
   104 
       
   105 
       
   106 void CT_NonNativeTestStep::RunTestCases()
       
   107     {
       
   108     RTestableApaLsSession ls;
       
   109     User::LeaveIfError(ls.Connect());
       
   110     
       
   111     //Wait if apparc updating the applist
       
   112     TRequestStatus applistChangeStatus;
       
   113     ls.SetNotify(ETrue, applistChangeStatus);
       
   114     User::WaitForRequest(applistChangeStatus);
       
   115     
       
   116     //DONT_CHECK is used because when an application is installed the updated application
       
   117     //information is added in the session objects. This causes increase of memory at server side.
       
   118     //As there can be multiple applications registered with apparc for applist change notifications,
       
   119     //its not possible to clear the information in all the session objects.
       
   120     HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestNonNativeAppLaunchWithUnavailableMappingL(ls), NO_CLEANUP);
       
   121     HEAP_TEST_LS_SESSION(ls, 0, 0, TestNonNativeUnsupportedAPIs(ls), NO_CLEANUP); 
       
   122     HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestGetAppTypeL(ls), NO_CLEANUP);
       
   123     ls.Close();
       
   124     }
       
   125 
       
   126 
       
   127 /**
       
   128    @SYMTestCaseID           APPFWK-APPARC-0106
       
   129   
       
   130 
       
   131     @SYMTestCaseDesc        Tests whether apparc able to launch a non-native application for which the mapping is 
       
   132                             not avaialable in apparc mapping table but its available in SCR. 
       
   133                             
       
   134    @SYMTestPriority         High
       
   135   
       
   136    @SYMTestStatus           Implemented
       
   137    
       
   138                              
       
   139    @SYMTestExpectedResults Apparc will launch the non-native applciation.
       
   140  */
       
   141 
       
   142 void CT_NonNativeTestStep::TestNonNativeAppLaunchWithUnavailableMappingL(RTestableApaLsSession &aLs)
       
   143     {
       
   144     INFO_PRINTF1(_L("TestNonNativeAppLaunchWithUnavailableMapping test started..........."));
       
   145     
       
   146     RProperty property;
       
   147     User::LeaveIfError(property.Attach(KPropertyCategory, KNonNativeTestPropertyKey, EOwnerThread));
       
   148     CleanupClosePushL(property);
       
   149     User::After(2000000); //Wait for 2 secconds till SCR server closed.
       
   150     
       
   151     RSmlTestUtils fs;
       
   152     User::LeaveIfError(fs.Connect());
       
   153     CleanupClosePushL(fs);  
       
   154     
       
   155     INFO_PRINTF1(_L("Delete existing scr.db"));    
       
   156     //Copy the existing SCR db to temp file and delete it
       
   157     fs.CopyFileL(KScrDBTarget, KScrDBTempTarget);
       
   158     fs.DeleteFileL(KScrDBTarget);
       
   159     
       
   160     INFO_PRINTF1(_L("Copying scr_test.db"));    
       
   161     //Copy the scr_test.db which has non-native application information and 
       
   162     //non-native type to its runtime.
       
   163     fs.CopyFileL(KTestScrDBSource, KScrDBTarget);
       
   164     fs.ChangeFilePermissionL(KScrDBTarget);
       
   165     
       
   166     INFO_PRINTF1(_L("Updating applist with a non-native application exists in scr_test.db"));     
       
   167     TApaAppUpdateInfo appUpdateInfo;
       
   168     RArray<TApaAppUpdateInfo> updateAppArray;
       
   169     CleanupClosePushL(updateAppArray);    
       
   170     
       
   171     appUpdateInfo.iAppUid=TUid::Uid(0x100048F3); //Test non-native app
       
   172     appUpdateInfo.iAction= TApaAppUpdateInfo::EAppPresent;
       
   173     updateAppArray.AppendL(appUpdateInfo);
       
   174     
       
   175     TRequestStatus status;
       
   176     aLs.SetNotify(EFalse, status);    
       
   177     aLs.UpdateAppListL(updateAppArray);
       
   178     CleanupStack::PopAndDestroy(&updateAppArray);
       
   179     User::WaitForRequest(status);
       
   180     
       
   181     INFO_PRINTF1(_L("Starting non-native application"));    
       
   182     CApaCommandLine* cmd=CApaCommandLine::NewLC();
       
   183     cmd->SetExecutableNameL(KNonNotiveAppName);
       
   184     aLs.StartApp(*cmd);
       
   185     CleanupStack::PopAndDestroy(cmd);
       
   186     User::After(2000000);
       
   187    
       
   188     //Once the non-native runtime executes, the property value is set to 1.
       
   189     TInt value;
       
   190     property.Get(value);
       
   191     INFO_PRINTF2(_L("Property value: %d"), value);   
       
   192     TEST(value == 1);
       
   193  
       
   194     INFO_PRINTF1(_L("Restoring the scr.db"));    
       
   195     User::After(2000000);   
       
   196     fs.DeleteFileL(KScrDBTarget);
       
   197     fs.CopyFileL(KScrDBTempTarget, KScrDBTarget);
       
   198     fs.DeleteFileL(KScrDBTempTarget);
       
   199     
       
   200     CleanupStack::PopAndDestroy(2, &property);
       
   201     INFO_PRINTF1(_L("TestNonNativeAppLaunchWithUnavailableMapping test ended..........."));
       
   202     }
       
   203 
       
   204 
       
   205 
       
   206 void CT_NonNativeTestStep::TestNonNativeUnsupportedAPIs(RTestableApaLsSession &aLs)
       
   207 {
       
   208     INFO_PRINTF1(_L("TestNonNativeUnsupportedAPIs test started..........."));  
       
   209     TUid uid=KNullUid;
       
   210     TDriveUnit drive;
       
   211     CApaRegistrationResourceFileWriter* regFileWriter=NULL;
       
   212     CApaLocalisableResourceFileWriter* locFileWriter=NULL;
       
   213     RFile *file=NULL;
       
   214     TPtrC fileName;
       
   215     
       
   216     TRAPD(err, aLs.RegisterNonNativeApplicationTypeL(uid, fileName));
       
   217     TEST(err == KErrNotSupported);
       
   218 
       
   219     TRAP(err, aLs.DeregisterNonNativeApplicationTypeL(uid));
       
   220     TEST(err == KErrNotSupported);
       
   221     
       
   222     TRAP(err, aLs.PrepareNonNativeApplicationsUpdatesL());
       
   223     TEST(err == KErrNotSupported);
       
   224 
       
   225     TRAP(err, aLs.RegisterNonNativeApplicationL(uid, drive, *regFileWriter, locFileWriter, file));
       
   226     TEST(err == KErrNotSupported);
       
   227     
       
   228     TRAP(err, aLs.DeregisterNonNativeApplicationL(uid));
       
   229     TEST(err == KErrNotSupported);
       
   230     
       
   231     TRAP(err, aLs.CommitNonNativeApplicationsUpdatesL());
       
   232     TEST(err == KErrNotSupported);
       
   233     
       
   234     TRAP(err, aLs.ForceCommitNonNativeApplicationsUpdatesL());
       
   235     TEST(err == KErrNotSupported);
       
   236     
       
   237     TEST(aLs.RollbackNonNativeApplicationsUpdates() == KErrNotSupported);
       
   238     
       
   239     INFO_PRINTF1(_L("TestNonNativeUnsupportedAPIs test ended..........."));    
       
   240 }
       
   241 
       
   242 
       
   243 void CT_NonNativeTestStep::TestGetAppTypeL(RTestableApaLsSession &aLs)
       
   244     {
       
   245     INFO_PRINTF1(_L("TestGetAppTypeL test started..........."));
       
   246     
       
   247     RSmlTestUtils fs;
       
   248     User::LeaveIfError(fs.Connect());
       
   249     CleanupClosePushL(fs);  
       
   250     User::After(2000000); //Wait for 2 secconds till SCR server closed.    
       
   251     
       
   252     INFO_PRINTF1(_L("Delete existing scr.db"));    
       
   253     //Copy the existing SCR db to temp file and delete it
       
   254     fs.CopyFileL(KScrDBTarget, KScrDBTempTarget);
       
   255     fs.DeleteFileL(KScrDBTarget);
       
   256     
       
   257     INFO_PRINTF1(_L("Copying scr_test.db"));    
       
   258     //Copy the scr_test.db which has non-native application information and 
       
   259     //non-native type to its runtime.
       
   260     fs.CopyFileL(KTestScrDBSource, KScrDBTarget);
       
   261     fs.ChangeFilePermissionL(KScrDBTarget);    
       
   262     
       
   263      INFO_PRINTF1(_L("Updating applist with a non-native application exists in scr_test.db"));     
       
   264     TApaAppUpdateInfo appUpdateInfo;
       
   265     RArray<TApaAppUpdateInfo> updateAppArray;
       
   266     CleanupClosePushL(updateAppArray);    
       
   267     
       
   268     appUpdateInfo.iAppUid=TUid::Uid(0x100048F3); //Test non-native app
       
   269     appUpdateInfo.iAction= TApaAppUpdateInfo::EAppPresent;
       
   270     updateAppArray.AppendL(appUpdateInfo);
       
   271     
       
   272     appUpdateInfo.iAppUid=TUid::Uid(0x10201D0E); //Test java app
       
   273     appUpdateInfo.iAction= TApaAppUpdateInfo::EAppPresent;
       
   274     updateAppArray.AppendL(appUpdateInfo);
       
   275     
       
   276     appUpdateInfo.iAppUid=TUid::Uid(0x10286B0D); //Test widget app
       
   277     appUpdateInfo.iAction= TApaAppUpdateInfo::EAppPresent;
       
   278     updateAppArray.AppendL(appUpdateInfo);
       
   279     
       
   280     TRequestStatus status;
       
   281     aLs.SetNotify(EFalse, status);    
       
   282     aLs.UpdateAppListL(updateAppArray);
       
   283     CleanupStack::PopAndDestroy(&updateAppArray);
       
   284     User::WaitForRequest(status);
       
   285     
       
   286     INFO_PRINTF1(_L("Test GetAppType returns valid uids"));
       
   287     TUid appTypeID;
       
   288     User::LeaveIfError(aLs.GetAppType(appTypeID, TUid::Uid(0x10201D0E))); //Java app
       
   289     TEST(appTypeID == KMidletUid);
       
   290 
       
   291     User::LeaveIfError(aLs.GetAppType(appTypeID, TUid::Uid(0x100048F3))); //Test non-native app
       
   292     TEST(appTypeID == KTestNonNativeUid);
       
   293     
       
   294     User::LeaveIfError(aLs.GetAppType(appTypeID, TUid::Uid(0x10286B0D))); //widget app
       
   295     TEST(appTypeID == KWidgetUid);
       
   296     
       
   297    
       
   298     INFO_PRINTF1(_L("Restoring the scr.db"));    
       
   299     User::After(2000000);    
       
   300     fs.DeleteFileL(KScrDBTarget);
       
   301     fs.CopyFileL(KScrDBTempTarget, KScrDBTarget);
       
   302     fs.DeleteFileL(KScrDBTempTarget);
       
   303     
       
   304     CleanupStack::PopAndDestroy(&fs);
       
   305     INFO_PRINTF1(_L("TestGetAppTypeL test ended..........."));
       
   306     }
       
   307