debugapps/appregexec/tsrc/src/AppRegExec_testBlocks.cpp
changeset 53 819e59dfc032
equal deleted inserted replaced
52:36d60d12b4af 53:819e59dfc032
       
     1 /*
       
     2 * Copyright (c) 2010 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 
       
    19 // [INCLUDE FILES] - do not remove
       
    20 #include <e32svr.h>
       
    21 #include <StifParser.h>
       
    22 #include <StifTestInterface.h>
       
    23 #include <swi/sisregistrysession.h>
       
    24 #include "AppRegExec_test.h"
       
    25 
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CAppRegExec_test::Delete
       
    32 // Delete here all resources allocated and opened from test methods. 
       
    33 // Called from destructor. 
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 void CAppRegExec_test::Delete() 
       
    37     {
       
    38 
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CAppRegExec_test::RunMethodL
       
    43 // Run specified method. Contains also table of test mothods and their names.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 TInt CAppRegExec_test::RunMethodL( 
       
    47     CStifItemParser& aItem ) 
       
    48     {
       
    49 
       
    50     static TStifFunctionInfo const KFunctions[] =
       
    51         {  
       
    52         // Copy this line for every implemented function.
       
    53         // First string is the function name used in TestScripter script file.
       
    54         // Second is the actual implementation member function. 
       
    55         ENTRY( "Positive_TestCase", CAppRegExec_test::Positive ),
       
    56         ENTRY( "Negative_TestCase", CAppRegExec_test::Negative ),
       
    57         ENTRY( "StartBackRoundApp",CAppRegExec_test::StartBackRoundApp),
       
    58         //ADD NEW ENTRY HERE
       
    59         // [test cases entries] - Do not remove
       
    60 
       
    61         };
       
    62 
       
    63     const TInt count = sizeof( KFunctions ) / 
       
    64                         sizeof( TStifFunctionInfo );
       
    65 
       
    66     return RunInternalL( KFunctions, count, aItem );
       
    67 
       
    68     }
       
    69 
       
    70 
       
    71 /*
       
    72  * In this Test Case we assume that the console App is running in backround and will try to copy GUI app resource 
       
    73  * registration file . So the GUI app corresponding to this resource should launch successfully.
       
    74  */
       
    75 TInt CAppRegExec_test::Positive(CStifItemParser& /*aItem*/)
       
    76     {
       
    77     TInt err = KErrNone;
       
    78     
       
    79     // delete Test data from C:\logs\stopmodetestdata.txt
       
    80     CheckAndDeleteL(KTestDataSessionPath,KTestDataFile);
       
    81     
       
    82     // Start unRegistration Process & wait till it get exit/terminated.
       
    83     StartProcess(KAppUnRegisterEXE,ETrue);
       
    84         
       
    85     // delete Resource Registration files
       
    86     CheckAndDeleteL(KResourceSessionPath,KResRegFile);
       
    87     
       
    88     //Transfer the Resource Registration files
       
    89     TInt ret = BaflUtils::CopyFile(iFsSession,KTestDataRSC_SRC,KTestDataRSC_DST);
       
    90     
       
    91     // wait some time till this resource get registered by background process
       
    92     User::After(5000000);
       
    93     
       
    94     // Start GUI app under test which will write some testdata in filesystem and exit.
       
    95     StartProcess(KTestDataEXE,ETrue);
       
    96   
       
    97     // check whether the test data written by GUI app exist .If exist then assuming that the GUI app launched 
       
    98     // Successfully else not launched.
       
    99     TBool isPresent = IsExist(KTestDataSessionPath,KTestDataFile);
       
   100     if(!isPresent)
       
   101         {
       
   102         _LIT( KLogStr02, "Has not launched Hello.exe" );
       
   103         iLog->Log( KLogStr02 );
       
   104         RDebug::Print(KLogStr02);
       
   105         return KErrGeneral;
       
   106         }
       
   107     return err;
       
   108     }
       
   109 
       
   110 /*
       
   111  * In this Test Case,the console App is not running in backround.Will try to copy resource 
       
   112  * registration file . So the GUI app corresponding to this resource should not launch successfully.
       
   113  */
       
   114 TInt CAppRegExec_test::Negative(CStifItemParser& /*aItem*/)
       
   115     {
       
   116     TInt err = KErrNone;
       
   117     
       
   118     // delete Test data from C:\logs\stopmodetestdata.txt
       
   119     CheckAndDeleteL(KTestDataSessionPath,KTestDataFile);
       
   120     
       
   121     // Start unRegistration Process & wait till it get exit/terminated.
       
   122     StartProcess(KAppUnRegisterEXE,ETrue);
       
   123     
       
   124     // delete Resource Registration files
       
   125     CheckAndDeleteL(KResourceSessionPath,KResRegFile);
       
   126     
       
   127         
       
   128     // Find the Backround Process & shut down if it is already running 
       
   129     TBool found = FindProcess(KMatchName);
       
   130     // If not found then there is no need to proceed with negative testing
       
   131     // Simply returning KErrNotFound
       
   132     if(!found)
       
   133         {
       
   134         return KErrNotFound;
       
   135         }
       
   136     
       
   137     //Transfer the Resource Registration files
       
   138     TInt ret = BaflUtils::CopyFile(iFsSession,KTestDataRSC_SRC,KTestDataRSC_DST);
       
   139     
       
   140     // Start GUI app under test which will write some testdata in filesystem and exit.
       
   141     StartProcess(KTestDataEXE,ETrue);
       
   142     
       
   143     // check whether the test data written by GUI app exist .If exist then assuming that the GUI app launched 
       
   144     // Successfully else not launched.
       
   145     TBool isPresent = IsExist(KTestDataSessionPath,KTestDataFile);
       
   146     
       
   147     if(isPresent)
       
   148         {
       
   149         _LIT( KLogStr03, "Has launched Hello.exe" );
       
   150         iLog->Log( KLogStr03 );
       
   151         RDebug::Print(KLogStr03);
       
   152         return KErrGeneral;
       
   153         }
       
   154     
       
   155     return err;
       
   156     }
       
   157 
       
   158 /*
       
   159  * StartBackRoundApp: This Test cases should be used to launch the Backround process
       
   160  * which actually registers the GUI app.& which was shut down by Negative Test Case.
       
   161  * 
       
   162  */
       
   163 TInt CAppRegExec_test::StartBackRoundApp(CStifItemParser& /*aItem*/)
       
   164     {
       
   165     return StartProcess(KAppRegisterEXE,EFalse);
       
   166     }
       
   167 
       
   168 /*
       
   169  * CheckAndDeleteL- will takes dirPath & Filename.
       
   170  * will check whether the provided file is Valid or not. If valid then delete it.
       
   171  */
       
   172 void CAppRegExec_test::CheckAndDeleteL(const TDesC16& aPath,const TDesC16& aFile)
       
   173     {
       
   174     TBuf<256> abuf;
       
   175     abuf.Copy(aPath);
       
   176     abuf.Append(aFile);
       
   177     
       
   178     TBool ret = BaflUtils::FileExists(iFsSession,abuf);
       
   179     if(ret)
       
   180         {
       
   181         _LIT( KLogStr01, "CAppRegExec_test:: File deleted" );
       
   182         iLog->Log( KLogStr01 );
       
   183         RDebug::Print(KLogStr01);
       
   184         iFsSession.Delete(abuf);
       
   185         }
       
   186     
       
   187     }
       
   188 
       
   189 /*
       
   190  * IsExist - will takes dirPath & Filename.
       
   191  * return True if valid file else False.
       
   192  */
       
   193 TBool CAppRegExec_test::IsExist(const TDesC16& aPath,const TDesC16& aFile)
       
   194     {
       
   195     TBuf<256> abuf;
       
   196     abuf.Copy(aPath);
       
   197     abuf.Append(aFile);
       
   198     
       
   199     TBool ret = BaflUtils::FileExists(iFsSession,abuf);
       
   200     _LIT( KLogStr04, "CAppRegExec_test:: IsExist -FileExists bool = %d" );
       
   201     RDebug::Print(KLogStr04,ret);
       
   202     iLog->Log(KLogStr04,ret); 
       
   203     return ret;
       
   204     }
       
   205 
       
   206 
       
   207 /*
       
   208  * StartProcess - wil be used to launch any application.
       
   209  */
       
   210 TInt CAppRegExec_test::StartProcess(const TDesC16& aFileName,TBool wait)  // Filename with drive and path
       
   211     {
       
   212     RProcess proc;
       
   213     TInt err = KErrNone;
       
   214     err = proc.Create(aFileName, KNullDesC);
       
   215     
       
   216     if(wait)
       
   217         {
       
   218         TRequestStatus stat;
       
   219         proc.Logon(stat);
       
   220         proc.Resume(); 
       
   221         // Thread is executing. Can add code here to run in parallel... 
       
   222         // blocks here while process is running
       
   223         User::WaitForRequest(stat);
       
   224         // Process is ended, you can use proc.ExitType()
       
   225         proc.Close();
       
   226         }
       
   227     else{
       
   228         proc.Resume();
       
   229         proc.Close();
       
   230         }
       
   231     return err;
       
   232     }
       
   233 
       
   234 /*
       
   235  * FindProcess - This function searches the given process . 
       
   236  * it will shutdown the process if running in backround.
       
   237  */
       
   238 TBool CAppRegExec_test::FindProcess(const TDesC16& aPath)
       
   239     {
       
   240     RProcess procHandle;
       
   241     TFindProcess procFinder;
       
   242     TFullName result;
       
   243     TBool found = EFalse;
       
   244     while(procFinder.Next(result)== KErrNone)
       
   245         {
       
   246         //Checking for AppRegExec.exe process with its length(14). 
       
   247         //Since the TFindProcess conatins the process Name + some orbitary values
       
   248         //associated with it.something like <ProcessName>[0X234567]
       
   249 
       
   250         if(result.Left(14) == aPath)
       
   251             {
       
   252             
       
   253             RDebug::Print(_L("**** Found the Process ****"));
       
   254             RDebug::Print(result);
       
   255             TInt err = procHandle.Open(procFinder,EOwnerThread);
       
   256             if(err == KErrNone)
       
   257                 {
       
   258                 procHandle.Kill(0);
       
   259                 found = ETrue;
       
   260                 break;
       
   261                 }
       
   262             }
       
   263         }
       
   264     procHandle.Close();
       
   265     return found;
       
   266     }
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 //  [End of File] - Do not remove
       
   272 
       
   273 // End of File