usbengines/usbwatcher/tsrc/UsbWatcherTest/src/UsbWatcherTest.cpp
branchRCL_3
changeset 92 dde4619868dc
parent 86 703a2b94c06c
child 95 55a3258355ea
equal deleted inserted replaced
86:703a2b94c06c 92:dde4619868dc
     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 // INCLUDE FILES
       
    19 #include <Stiftestinterface.h>
       
    20 #include "UsbWatcherTest.h"
       
    21 #include <SettingServerClient.h>
       
    22 #include "testdebug.h"
       
    23 
       
    24 // EXTERNAL DATA STRUCTURES
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // MACROS
       
    31 
       
    32 // LOCAL CONSTANTS AND MACROS
       
    33 
       
    34 // MODULE DATA STRUCTURES
       
    35 
       
    36 // LOCAL FUNCTION PROTOTYPES
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // -----------------------------------------------------------------------------
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CUsbWatcherTest::CUsbWatcherTest
       
    49 // C++ default constructor can NOT contain any code, that
       
    50 // might leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CUsbWatcherTest::CUsbWatcherTest( 
       
    54     CTestModuleIf& aTestModuleIf ):
       
    55         CScriptBase( aTestModuleIf )
       
    56     {
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUsbWatcherTest::ConstructL
       
    61 // Symbian 2nd phase constructor can leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CUsbWatcherTest::ConstructL()
       
    65     {
       
    66     //Read logger settings to check whether test case name is to be
       
    67     //appended to log file name.
       
    68     RSettingServer settingServer;
       
    69     TInt ret = settingServer.Connect();
       
    70     if(ret != KErrNone)
       
    71         {
       
    72         User::Leave(ret);
       
    73         }
       
    74     // Struct to StifLogger settigs.
       
    75     TLoggerSettings loggerSettings; 
       
    76     // Parse StifLogger defaults from STIF initialization file.
       
    77     ret = settingServer.GetLoggerSettings( loggerSettings );
       
    78     if( ret != KErrNone )
       
    79         {
       
    80         User::Leave( ret );
       
    81         } 
       
    82     // Close Setting server session
       
    83     settingServer.Close();
       
    84 
       
    85     TFileName logFileName;
       
    86     
       
    87     if( loggerSettings.iAddTestCaseTitle )
       
    88         {
       
    89         TName title;
       
    90         TestModuleIf().GetTestCaseTitleL( title );
       
    91         logFileName.Format( KUsbWatcherTestLogFileWithTitle, &title );
       
    92         }
       
    93     else
       
    94         {
       
    95         logFileName.Copy( KUsbWatcherTestLogFile );
       
    96         }
       
    97 
       
    98     iLog = CStifLogger::NewL( KUsbWatcherTestLogPath, 
       
    99                           logFileName,
       
   100                           CStifLogger::ETxt,
       
   101                           CStifLogger::EFile,
       
   102                           EFalse );
       
   103     
       
   104     SendTestClassVersion();
       
   105     TestConstructL();
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CUsbWatcherTest::NewL
       
   110 // Two-phased constructor.
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CUsbWatcherTest* CUsbWatcherTest::NewL( 
       
   114     CTestModuleIf& aTestModuleIf )
       
   115     {
       
   116     CUsbWatcherTest* self = new (ELeave) CUsbWatcherTest( aTestModuleIf );
       
   117     CleanupStack::PushL( self );
       
   118     self->ConstructL();
       
   119     CleanupStack::Pop();
       
   120     return self;
       
   121     }
       
   122 
       
   123 // Destructor
       
   124 CUsbWatcherTest::~CUsbWatcherTest()
       
   125     { 
       
   126 
       
   127     // Delete resources allocated from test methods
       
   128     TestDelete();
       
   129 
       
   130     // Delete logger
       
   131     delete iLog; 
       
   132 
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CUsbWatcherTest::RunMethodL
       
   137 // Run specified method. Contains also table of test mothods and their names.
       
   138 // -----------------------------------------------------------------------------
       
   139 
       
   140 TInt CUsbWatcherTest::RunMethodL( 
       
   141     CStifItemParser& aItem ) 
       
   142     {
       
   143     return ExecuteTestBlock( aItem );
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CUsbWatcherTest::ExecuteTestBlock
       
   148 // -----------------------------------------------------------------------------
       
   149 
       
   150 TInt CUsbWatcherTest::ExecuteTestBlock( CStifItemParser& aItem )
       
   151     {
       
   152     TRACE_FUNC_ENTRY
       
   153     iItem = &aItem;    
       
   154     TInt res;
       
   155     TUsbWatcherTestResult testResult = ETestCaseFailed;
       
   156     
       
   157     res = iItem -> GetString( _L( "tester" ), iTestBlockParams.iTestBlockName );
       
   158     if ( res != KErrNone )
       
   159         {
       
   160         TRACE_INFO( "Getting test block name failed with: %d", res )
       
   161         TRACE_FUNC_EXIT
       
   162         return res;
       
   163         }
       
   164     TRACE_INFO( "Test block name: %S", &iTestBlockParams.iTestBlockName )
       
   165     
       
   166     TRACE( "Extracting test block parameters..." )
       
   167     TRAP( res, TestBlocksInfoL() );
       
   168     if ( res != KErrNone )
       
   169         {
       
   170         TRACE_INFO( "Extracting parameters failed: %d", res )
       
   171         TRACE_FUNC_EXIT
       
   172         return res;
       
   173         }
       
   174     if ( !iTestBlockFound )
       
   175         {
       
   176         TRACE( "Test block not found!" )
       
   177         TRACE_FUNC_EXIT
       
   178         return KErrNotFound;
       
   179         }    
       
   180     TRACE( "Extracting parameters successful" )
       
   181     
       
   182     TRAP( res, ( this ->*iTestBlockFunction )( iTestBlockParams, testResult ) );
       
   183     if ( res != KErrNone )
       
   184         {
       
   185         TRACE_INFO( "ExecuteTestBlockL error: %d", res )
       
   186         TRACE_FUNC_EXIT
       
   187         return res;
       
   188         }
       
   189     
       
   190     STIF_ASSERT_EQUALS( ETestCasePassed, testResult );
       
   191     TRACE( "Test block passed!" );
       
   192     TRACE_FUNC_EXIT 
       
   193     return KErrNone;
       
   194     } 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CUsbWatcherTest::GetTestBlockParamL
       
   198 // -----------------------------------------------------------------------------
       
   199 
       
   200 void CUsbWatcherTest::GetTestBlockParamL( TGetTestBlockParamOperation aOperation, TTestBlockParamName aParamName )
       
   201     {    
       
   202     switch( aOperation )
       
   203         {
       
   204         case eGetString:
       
   205             {
       
   206             switch ( aParamName )
       
   207                 {
       
   208                 case eTestOption1:
       
   209                     {
       
   210                     User::LeaveIfError( iItem -> GetNextString( iTestBlockParams.iTestOption1 ) );
       
   211                     break;
       
   212                     }
       
   213                 case eTestOption2:
       
   214                     {
       
   215                     User::LeaveIfError( iItem -> GetNextString( iTestBlockParams.iTestOption2 ) );
       
   216                     break;
       
   217                     }
       
   218                 case eTestOption3:
       
   219                     {
       
   220                     User::LeaveIfError( iItem -> GetNextString( iTestBlockParams.iTestOption3 ) );
       
   221                     break;
       
   222                     }
       
   223                 default:
       
   224                     {
       
   225                     User::Leave( KErrArgument );
       
   226                     break;
       
   227                     }
       
   228                 }
       
   229             break;
       
   230             }
       
   231         case eGetInt:
       
   232             {
       
   233             switch ( aParamName )
       
   234                 {
       
   235                 case eTestIntOption1:
       
   236                     {
       
   237                     User::LeaveIfError( iItem -> GetNextInt( iTestBlockParams.iTestIntOption1 ) );
       
   238                     break;
       
   239                     }
       
   240                 case eTestIntOption2:
       
   241                     {
       
   242                     User::LeaveIfError( iItem -> GetNextInt( iTestBlockParams.iTestIntOption2 ) );
       
   243                     break;
       
   244                     }
       
   245                 case eTestIntOption3:
       
   246                     {
       
   247                     User::LeaveIfError( iItem -> GetNextInt( iTestBlockParams.iTestIntOption3 ) );
       
   248                     break;
       
   249                     }
       
   250                 default:
       
   251                     {
       
   252                     User::Leave( KErrArgument );
       
   253                     break;
       
   254                     }
       
   255                 }
       
   256             break;
       
   257             }
       
   258         case eGetChar:            
       
   259             {
       
   260             switch ( aParamName )
       
   261                 {
       
   262                 case eTestCharOption1:
       
   263                     {
       
   264                     User::LeaveIfError( iItem -> GetNextChar( iTestBlockParams.iTestCharOption1 ) );
       
   265                     break;
       
   266                     }
       
   267                 case eTestCharOption2:
       
   268                     {
       
   269                     User::LeaveIfError( iItem -> GetNextChar( iTestBlockParams.iTestCharOption2 ) );
       
   270                     break;
       
   271                     }
       
   272                 case eTestCharOption3:
       
   273                     {
       
   274                     User::LeaveIfError( iItem -> GetNextChar( iTestBlockParams.iTestCharOption3 ) );
       
   275                     break;
       
   276                     }
       
   277                 default:
       
   278                     {
       
   279                     User::Leave( KErrArgument );
       
   280                     }
       
   281                 }
       
   282             break;
       
   283             }
       
   284         default:
       
   285             {
       
   286             User::Leave( KErrArgument );
       
   287             }
       
   288         }
       
   289     }
       
   290 
       
   291 //-----------------------------------------------------------------------------
       
   292 // CUsbWatcherTest::SendTestClassVersion
       
   293 // Method used to send version of test class
       
   294 //-----------------------------------------------------------------------------
       
   295 //
       
   296 void CUsbWatcherTest::SendTestClassVersion()
       
   297 	{
       
   298 	TVersion moduleVersion;
       
   299 	moduleVersion.iMajor = TEST_CLASS_VERSION_MAJOR;
       
   300 	moduleVersion.iMinor = TEST_CLASS_VERSION_MINOR;
       
   301 	moduleVersion.iBuild = TEST_CLASS_VERSION_BUILD;
       
   302 	
       
   303 	TFileName moduleName;
       
   304 	moduleName = _L("UsbWatcherTest.dll");
       
   305 
       
   306 	TBool newVersionOfMethod = ETrue;
       
   307 	TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod);
       
   308 	}
       
   309 
       
   310 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // LibEntryL is a polymorphic Dll entry point.
       
   314 // Returns: CScriptBase: New CScriptBase derived object
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 EXPORT_C CScriptBase* LibEntryL( 
       
   318     CTestModuleIf& aTestModuleIf ) // Backpointer to STIF Test Framework
       
   319     {
       
   320 
       
   321     return ( CScriptBase* ) CUsbWatcherTest::NewL( aTestModuleIf );
       
   322 
       
   323     }
       
   324 
       
   325 
       
   326 //  End of File