coreapplicationuis/rfsplugins/tsrc/rfspluginstest/AIRFSPluginTestModule/src/AIRFSPluginTestModule.cpp
changeset 69 dcd4152cfe55
equal deleted inserted replaced
65:8a530a83576a 69:dcd4152cfe55
       
     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
       
    19 #include <StifTestInterface.h>
       
    20 #include "AIRFSPluginTestModule.h"
       
    21 #include <SettingServerClient.h>
       
    22 #include <rfsplugin.h>
       
    23 
       
    24 // EXTERNAL DATA STRUCTURES
       
    25 //extern  ?external_data;
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES  
       
    28 //extern ?external_function( ?arg_type,?arg_type );
       
    29 
       
    30 // CONSTANTS
       
    31 //const ?type ?constant_var = ?constant;
       
    32 
       
    33 // MACROS
       
    34 //#define ?macro ?macro_def
       
    35 
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 //const ?type ?constant_var = ?constant;
       
    38 //#define ?macro_name ?macro_def
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 //enum ?declaration
       
    42 //typedef ?declaration
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 //?type ?function_name( ?arg_type, ?arg_type );
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 //class ?FORWARD_CLASSNAME;
       
    49 
       
    50 // ============================= LOCAL FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // ?function_name ?description.
       
    54 // ?description
       
    55 // Returns: ?value_1: ?description
       
    56 //          ?value_n: ?description_line1
       
    57 //                    ?description_line2
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 /*
       
    61 ?type ?function_name(
       
    62     ?arg_type arg,  // ?description
       
    63     ?arg_type arg)  // ?description
       
    64     {
       
    65 
       
    66     ?code  // ?comment
       
    67 
       
    68     // ?comment
       
    69     ?code
       
    70     }
       
    71 */
       
    72 
       
    73 // ============================ MEMBER FUNCTIONS ===============================
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAIRFSPluginTestModule::CAIRFSPluginTestModule
       
    77 // C++ default constructor can NOT contain any code, that
       
    78 // might leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CAIRFSPluginTestModule::CAIRFSPluginTestModule( 
       
    82     CTestModuleIf& aTestModuleIf ):
       
    83         CScriptBase( aTestModuleIf )
       
    84     {
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CAIRFSPluginTestModule::Delete
       
    89 // Delete here all resources allocated and opened from test methods. 
       
    90 // Called from destructor. 
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CAIRFSPluginTestModule::Delete() 
       
    94     {
       
    95 
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CAIRFSPluginTestModule::ConstructL
       
   100 // Symbian 2nd phase constructor can leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CAIRFSPluginTestModule::ConstructL()
       
   104     {
       
   105     //Read logger settings to check whether test case name is to be
       
   106     //appended to log file name.
       
   107     RSettingServer settingServer;
       
   108     TInt ret = settingServer.Connect();
       
   109     if(ret != KErrNone)
       
   110         {
       
   111         User::Leave(ret);
       
   112         }
       
   113     // Struct to StifLogger settigs.
       
   114     TLoggerSettings loggerSettings; 
       
   115     // Parse StifLogger defaults from STIF initialization file.
       
   116     ret = settingServer.GetLoggerSettings(loggerSettings);
       
   117     if(ret != KErrNone)
       
   118         {
       
   119         User::Leave(ret);
       
   120         } 
       
   121     // Close Setting server session
       
   122     settingServer.Close();
       
   123 
       
   124     TFileName logFileName;
       
   125     
       
   126     if(loggerSettings.iAddTestCaseTitle)
       
   127         {
       
   128         TName title;
       
   129         TestModuleIf().GetTestCaseTitleL(title);
       
   130         logFileName.Format(KAIRFSPluginTestModuleLogFileWithTitle, &title);
       
   131         }
       
   132     else
       
   133         {
       
   134         logFileName.Copy(KAIRFSPluginTestModuleLogFile);
       
   135         }
       
   136 
       
   137     iLog = CStifLogger::NewL( KAIRFSPluginTestModuleLogPath, 
       
   138                           logFileName,
       
   139                           CStifLogger::ETxt,
       
   140                           CStifLogger::EFile,
       
   141                           EFalse );
       
   142     
       
   143     SendTestClassVersion();
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CAIRFSPluginTestModule::NewL
       
   148 // Two-phased constructor.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CAIRFSPluginTestModule* CAIRFSPluginTestModule::NewL( 
       
   152     CTestModuleIf& aTestModuleIf )
       
   153     {
       
   154     CAIRFSPluginTestModule* self = new (ELeave) CAIRFSPluginTestModule( aTestModuleIf );
       
   155 
       
   156     CleanupStack::PushL( self );
       
   157     self->ConstructL();
       
   158     CleanupStack::Pop();
       
   159 
       
   160     return self;
       
   161 
       
   162     }
       
   163 
       
   164 // Destructor
       
   165 CAIRFSPluginTestModule::~CAIRFSPluginTestModule()
       
   166     { 
       
   167 
       
   168     // Delete resources allocated from test methods
       
   169     Delete();
       
   170 
       
   171     delete iPlugin;
       
   172     REComSession::FinalClose();
       
   173 
       
   174     // Delete logger
       
   175     delete iLog; 
       
   176 
       
   177     }
       
   178 
       
   179 //-----------------------------------------------------------------------------
       
   180 // CAIRFSPluginTestModule::SendTestClassVersion
       
   181 // Method used to send version of test class
       
   182 //-----------------------------------------------------------------------------
       
   183 //
       
   184 void CAIRFSPluginTestModule::SendTestClassVersion()
       
   185 	{
       
   186 	TVersion moduleVersion;
       
   187 	moduleVersion.iMajor = TEST_CLASS_VERSION_MAJOR;
       
   188 	moduleVersion.iMinor = TEST_CLASS_VERSION_MINOR;
       
   189 	moduleVersion.iBuild = TEST_CLASS_VERSION_BUILD;
       
   190 	
       
   191 	TFileName moduleName;
       
   192 	moduleName = _L("AIRFSPluginTestModule.dll");
       
   193 
       
   194 	TBool newVersionOfMethod = ETrue;
       
   195 	TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod);
       
   196 	}
       
   197 
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CAIRFSPluginTestModule::RunMethodL
       
   202 // Run specified method. Contains also table of test mothods and their names.
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TInt CAIRFSPluginTestModule::RunMethodL( 
       
   206     CStifItemParser& aItem ) 
       
   207     {
       
   208 
       
   209     static TStifFunctionInfo const KFunctions[] =
       
   210         {  
       
   211         // Copy this line for every implemented function.
       
   212         // First string is the function name used in TestScripter script file.
       
   213         // Second is the actual implementation member function. 
       
   214         //ENTRY( "Example", CAIRFSPluginTestModule::ExampleL ),
       
   215         //ADD NEW ENTRY HERE
       
   216         // [test cases entries] - Do not remove
       
   217         ENTRY( "CreatePlugin", CAIRFSPluginTestModule::CreatePlugin ),
       
   218         ENTRY( "DestroyPlugin", CAIRFSPluginTestModule::DestroyPlugin ),
       
   219         ENTRY( "RestoreFactorySettings", CAIRFSPluginTestModule::RestoreFactorySettings ),
       
   220         ENTRY( "GetScript", CAIRFSPluginTestModule::GetScript ),
       
   221         ENTRY( "ExecuteCustomCommand", CAIRFSPluginTestModule::ExecuteCustomCommand ),
       
   222         };
       
   223 
       
   224     const TInt count = sizeof( KFunctions ) / 
       
   225                         sizeof( TStifFunctionInfo );
       
   226 
       
   227     return RunInternalL( KFunctions, count, aItem );
       
   228 
       
   229     }
       
   230 
       
   231 TInt CAIRFSPluginTestModule::CreatePlugin(CStifItemParser& /*aItem */)
       
   232     {
       
   233     RDebug::Print(_L("CAIRFSPluginTestModule::CreatePlugin"));
       
   234     STIF_ASSERT_NOT_LEAVES(iPlugin = CRFSPlugin::NewL( TUid::Uid( 0x2000F8B2 ) ) );
       
   235     STIF_ASSERT_NOT_NULL( iPlugin );
       
   236     
       
   237     return KErrNone;
       
   238     
       
   239     }
       
   240 TInt CAIRFSPluginTestModule::DestroyPlugin(CStifItemParser& /*aItem*/ )
       
   241     {
       
   242     RDebug::Print(_L("CAIRFSPluginTestModule::DestroyPlugin"));
       
   243     delete iPlugin;
       
   244     iPlugin = NULL;
       
   245         
       
   246     return KErrNone;
       
   247     }
       
   248 TInt CAIRFSPluginTestModule::RestoreFactorySettings(CStifItemParser& /*aItem*/ )
       
   249     {
       
   250     RDebug::Print(_L("CAIRFSPluginTestModule::RestoreFactorySettings"));
       
   251     STIF_ASSERT_NOT_LEAVES( iPlugin->RestoreFactorySettingsL( ENormalRfs ) );
       
   252     STIF_ASSERT_NOT_LEAVES( iPlugin->RestoreFactorySettingsL( EDeepRfs ) );
       
   253     STIF_ASSERT_NOT_LEAVES( iPlugin->RestoreFactorySettingsL( EInitRfs ) );
       
   254     STIF_ASSERT_NOT_LEAVES( iPlugin->RestoreFactorySettingsL( static_cast<TRfsReason>( 100 ) ) );
       
   255     return KErrNone;
       
   256     }
       
   257 TInt CAIRFSPluginTestModule::GetScript(CStifItemParser& /*aItem*/ )
       
   258     {
       
   259     RDebug::Print(_L("CAIRFSPluginTestModule::GetScript"));
       
   260     TBuf<256> path;
       
   261      //TBuf<256> buf;
       
   262      //buf.Copy(KExpectedScript);
       
   263      STIF_ASSERT_NOT_LEAVES( iPlugin->GetScriptL( ENormalRfs, path ) );
       
   264      RDebug::Print(_L( "Script = '%S'"), &path );
       
   265      //STIF_ASSERT_EQUALS( buf, path );
       
   266 
       
   267      STIF_ASSERT_NOT_LEAVES( iPlugin->GetScriptL( EDeepRfs, path ) );
       
   268      RDebug::Print(_L( "Script = '%S'"), &path );
       
   269      //STIF_ASSERT_EQUALS( buf, path );
       
   270 
       
   271      STIF_ASSERT_NOT_LEAVES( iPlugin->GetScriptL( EInitRfs, path ) );
       
   272      RDebug::Print(_L( "Script = '%S'"), &path );
       
   273      //STIF_ASSERT_EQUALS( buf, path );
       
   274 
       
   275      STIF_ASSERT_NOT_LEAVES( iPlugin->GetScriptL( static_cast<TRfsReason>( 100 ), path ) );
       
   276      RDebug::Print(_L( "Script = '%S'"), &path );
       
   277      //STIF_ASSERT_EQUALS( buf, path );
       
   278 
       
   279     return KErrNone;
       
   280     }
       
   281 TInt CAIRFSPluginTestModule::ExecuteCustomCommand(CStifItemParser& /*aItem*/ )
       
   282     {
       
   283     RDebug::Print(_L("CAIRFSPluginTestModule::ExecuteCustomCommand"));
       
   284     TBuf<256> param1( KNullDesC );
       
   285      STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( ENormalRfs, param1 ) );
       
   286      TBuf<1> param2( KNullDesC );
       
   287      STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( EDeepRfs, param2 ) );
       
   288      STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( EInitRfs, param2 ) );
       
   289      STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( static_cast<TRfsReason>( 100 ), param2 ) );
       
   290     return KErrNone;
       
   291     }
       
   292 
       
   293 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // LibEntryL is a polymorphic Dll entry point.
       
   297 // Returns: CScriptBase: New CScriptBase derived object
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 EXPORT_C CScriptBase* LibEntryL( 
       
   301     CTestModuleIf& aTestModuleIf ) // Backpointer to STIF Test Framework
       
   302     {
       
   303 
       
   304     return ( CScriptBase* ) CAIRFSPluginTestModule::NewL( aTestModuleIf );
       
   305 
       
   306     }
       
   307 
       
   308 // End of File