tsrc/cpixmwtester/src/cpixmwtesterblocks.cpp
changeset 0 671dee74050a
child 1 6f2c1c46032b
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     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: This file contains testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include "CPixMWTester.h"
       
    20 
       
    21 #include <e32svr.h>
       
    22 #include <StifParser.h>
       
    23 #include <Stiftestinterface.h>
       
    24 
       
    25 #include "CBlacklistMgr.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 //extern  ?external_data;
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 //extern ?external_function( ?arg_type,?arg_type );
       
    32 
       
    33 // CONSTANTS
       
    34 //const ?type ?constant_var = ?constant;
       
    35 _LIT( KNoErrorString, "No Error" );
       
    36 //_LIT( KErrorString, " *** Error ***" );
       
    37 //Test Uid for testing Blacklist manager
       
    38 const TUid KTestUid = { 0x101D6348 };
       
    39 
       
    40 //For Watchdog
       
    41 _LIT(KTestHarvesterServer,"CPixHarvesterServer");
       
    42 _LIT(aEXeFileName , "WatchDog.exe");
       
    43 
       
    44 // MACROS
       
    45 //#define ?macro ?macro_def
       
    46 
       
    47 // LOCAL CONSTANTS AND MACROS
       
    48 //const ?type ?constant_var = ?constant;
       
    49 //#define ?macro_name ?macro_def
       
    50 
       
    51 // MODULE DATA STRUCTURES
       
    52 //enum ?declaration
       
    53 //typedef ?declaration
       
    54 
       
    55 // LOCAL FUNCTION PROTOTYPES
       
    56 //?type ?function_name( ?arg_type, ?arg_type );
       
    57 
       
    58 // FORWARD DECLARATIONS
       
    59 //class ?FORWARD_CLASSNAME;
       
    60 
       
    61 // ============================= LOCAL FUNCTIONS ===============================
       
    62 
       
    63 void doLog( CStifLogger* logger, TInt error, const TDesC& errorString )
       
    64     {
       
    65     if( KErrNone == error ) logger->Log( KNoErrorString );
       
    66     else logger->Log( errorString );
       
    67     }
       
    68 // -----------------------------------------------------------------------------
       
    69 // ?function_name ?description.
       
    70 // ?description
       
    71 // Returns: ?value_1: ?description
       
    72 //          ?value_n: ?description_line1
       
    73 //                    ?description_line2
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 /*
       
    77 ?type ?function_name(
       
    78     ?arg_type arg,  // ?description
       
    79     ?arg_type arg)  // ?description
       
    80     {
       
    81 
       
    82     ?code  // ?comment
       
    83 
       
    84     // ?comment
       
    85     ?code
       
    86     }
       
    87 */
       
    88 
       
    89 // ============================ MEMBER FUNCTIONS ===============================
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CCPixMWTester::Delete
       
    93 // Delete here all resources allocated and opened from test methods. 
       
    94 // Called from destructor. 
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CCPixMWTester::Delete() 
       
    98     {
       
    99 
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CCPixMWTester::RunMethodL
       
   104 // Run specified method. Contains also table of test mothods and their names.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CCPixMWTester::RunMethodL( 
       
   108     CStifItemParser& aItem ) 
       
   109     {
       
   110 
       
   111     static TStifFunctionInfo const KFunctions[] =
       
   112         {  
       
   113         // Copy this line for every implemented function.
       
   114         // First string is the function name used in TestScripter script file.
       
   115         // Second is the actual implementation member function.        
       
   116         ENTRY( "TestBlacklistPlugin", CCPixMWTester::TestBlacklistPluginL ),
       
   117         ENTRY( "TestBlacklistPluginVersion", CCPixMWTester::TestBlacklistPluginVersionL ),
       
   118         ENTRY( "TestWatchdog",CCPixMWTester::TestWatchdogL ),  
       
   119         //ADD NEW ENTRY HERE
       
   120         // [test cases entries] - Do not remove
       
   121 
       
   122         };
       
   123 
       
   124     const TInt count = sizeof( KFunctions ) / 
       
   125                         sizeof( TStifFunctionInfo );
       
   126 
       
   127     return RunInternalL( KFunctions, count, aItem );
       
   128 
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CCPixMWTester::TestBlacklistPluginL
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CCPixMWTester::TestBlacklistPluginL( CStifItemParser& aItem )
       
   136     {    
       
   137     TInt err = KErrNone;        
       
   138     CBlacklistMgr* blacklistmanager = CBlacklistMgr::NewL();
       
   139     CleanupStack::PushL( blacklistmanager );
       
   140     TInt version = 0;
       
   141     aItem.GetNextInt(version);
       
   142     //Add an Uid to Blacklist DB
       
   143     blacklistmanager->AddL( KTestUid , version );
       
   144     //Check if the Uid is added to database or not
       
   145     TBool found = blacklistmanager->FindL(KTestUid , version );
       
   146     
       
   147     if(!found) err = KErrNotFound;
       
   148     //clear the UID from the database
       
   149     blacklistmanager->Remove(KTestUid);
       
   150     CleanupStack::PopAndDestroy( blacklistmanager ); 
       
   151     doLog( iLog, err, KNoErrorString );        
       
   152     return err;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CCPixMWTester::TestBlacklistPluginVersionL
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CCPixMWTester::TestBlacklistPluginVersionL( CStifItemParser& aItem )
       
   160     {
       
   161     TInt err = KErrNone;   
       
   162     CBlacklistMgr* blacklistmanager = CBlacklistMgr::NewL();
       
   163     CleanupStack::PushL( blacklistmanager );
       
   164     TInt oldversion = 0;
       
   165     TInt newversion = 0;
       
   166     aItem.GetNextInt(oldversion);
       
   167     aItem.GetNextInt(newversion);
       
   168     //Add an Uid to Blacklist DB with old version
       
   169     blacklistmanager->AddL( KTestUid , oldversion );
       
   170     //Add an Uid to Blacklist DB with new version
       
   171     blacklistmanager->AddL( KTestUid , newversion );
       
   172     //Check if the Uid with old version exists
       
   173     TBool found = blacklistmanager->FindL(KTestUid , oldversion );
       
   174     if( found )
       
   175         {
       
   176         err = KErrNotFound;
       
   177         }
       
   178     else
       
   179         {
       
   180         //check with new version
       
   181         found = blacklistmanager->FindL(KTestUid , newversion );
       
   182         if(!found) err = KErrNotFound;
       
   183         }    
       
   184     //clear the UID from the database
       
   185     blacklistmanager->Remove(KTestUid);
       
   186     CleanupStack::PopAndDestroy( blacklistmanager );    
       
   187     doLog( iLog, err, KNoErrorString );
       
   188     return err;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CCPixMWTester::TestWatchdogL
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CCPixMWTester::TestWatchdogL( CStifItemParser&)
       
   196     {
       
   197     TInt err = KErrNone;
       
   198     //Start the watchdog exe 
       
   199     RProcess p;
       
   200     //CleanupStack::PushL(&p);
       
   201     TInt res=p.Create(aEXeFileName,KNullDesC);
       
   202     if(res==KErrNone)
       
   203         {
       
   204         p.Resume();
       
   205         }
       
   206     //wait for a minute.
       
   207     User::After((TTimeIntervalMicroSeconds32)120000000);
       
   208     //check for the CPixHarvesterServer
       
   209     //If server exists, Test case  is PASS else FAIL
       
   210     TFindServer harvesterServer(KTestHarvesterServer);
       
   211     TFullName name;
       
   212     err = harvesterServer.Next(name);
       
   213     p.Close();
       
   214     doLog( iLog, err, KNoErrorString );
       
   215     return err;
       
   216     }
       
   217 // -----------------------------------------------------------------------------
       
   218 // CCPixMWTester::?member_function
       
   219 // ?implementation_description
       
   220 // (other items were commented in a header).
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 /*
       
   224 TInt CCPixMWTester::?member_function(
       
   225    CItemParser& aItem )
       
   226    {
       
   227 
       
   228    ?code
       
   229 
       
   230    }
       
   231 */
       
   232 
       
   233 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   234 // None
       
   235 
       
   236 //  [End of File] - Do not remove