videofeeds/server/tsrc/VCXSettingsDatabaseTest/src/VCXSettingsDatabaseTestBlocks.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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:   ?Description*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32svr.h>
       
    22 #include <StifParser.h>
       
    23 #include <Stiftestinterface.h>
       
    24 #include "VCXSettingsDatabaseTest.h"
       
    25 
       
    26 #include "VCXTestLog.h"
       
    27 #include "CIptvSettingsDatabase.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 //extern  ?external_data;
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES
       
    33 //extern ?external_function( ?arg_type,?arg_type );
       
    34 
       
    35 // CONSTANTS
       
    36 //const ?type ?constant_var = ?constant;
       
    37 
       
    38 // MACROS
       
    39 //#define ?macro ?macro_def
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 //const ?type ?constant_var = ?constant;
       
    43 //#define ?macro_name ?macro_def
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 //enum ?declaration
       
    47 //typedef ?declaration
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 //?type ?function_name( ?arg_type, ?arg_type );
       
    51 
       
    52 // FORWARD DECLARATIONS
       
    53 //class ?FORWARD_CLASSNAME;
       
    54 
       
    55 // ============================= LOCAL FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // ?function_name ?description.
       
    59 // ?description
       
    60 // Returns: ?value_1: ?description
       
    61 //          ?value_n: ?description_line1
       
    62 //                    ?description_line2
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 /*
       
    66 ?type ?function_name(
       
    67     ?arg_type arg,  // ?description
       
    68     ?arg_type arg)  // ?description
       
    69     {
       
    70 
       
    71     ?code  // ?comment
       
    72 
       
    73     // ?comment
       
    74     ?code
       
    75     }
       
    76 */
       
    77 
       
    78 // ============================ MEMBER FUNCTIONS ===============================
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CIptvSettingsDatabaseTest::Delete
       
    82 // Delete here all resources allocated and opened from test methods.
       
    83 // Called from destructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CIptvSettingsDatabaseTest::Delete()
       
    87     {
       
    88 	if( iDatabase )
       
    89 		{
       
    90 		delete iDatabase;
       
    91 		}
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CIptvSettingsDatabaseTest::RunMethodL
       
    96 // Run specified method. Contains also table of test mothods and their names.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TInt CIptvSettingsDatabaseTest::RunMethodL(
       
   100     CStifItemParser& aItem )
       
   101     {
       
   102 
       
   103     static TStifFunctionInfo const KFunctions[] =
       
   104         {
       
   105         // Copy this line for every implemented function.
       
   106         // First string is the function name used in TestScripter script file.
       
   107         // Second is the actual implementation member function.
       
   108         ENTRY( "Create", CIptvSettingsDatabaseTest::CreateL ),
       
   109         ENTRY( "Destroy", CIptvSettingsDatabaseTest::DestroyL ),
       
   110         ENTRY( "TestSettings", CIptvSettingsDatabaseTest::TestSettingsL ),
       
   111         ENTRY( "TestLastUsage", CIptvSettingsDatabaseTest::TestLastUsageL )
       
   112         };
       
   113 
       
   114     const TInt count = sizeof( KFunctions ) /
       
   115                         sizeof( TStifFunctionInfo );
       
   116 
       
   117     return RunInternalL( KFunctions, count, aItem );
       
   118 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CIptvSettingsDatabaseTest::CreateL
       
   123 //
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 TInt CIptvSettingsDatabaseTest::CreateL( CStifItemParser& aItem )
       
   127     {
       
   128 
       
   129     // Print to UI
       
   130     _LIT( KIptvSettingsDatabaseTest, "IptvSettingsDatabaseTest" );
       
   131     _LIT( KWhere, "In Create" );
       
   132     TestModuleIf().Printf( 0, KIptvSettingsDatabaseTest, KWhere );
       
   133     // Print to log file
       
   134     iLog->Log( KWhere );
       
   135 
       
   136     VCXLOGLO1(">>>CIptvSettingsDatabaseTest::CreateL");
       
   137 
       
   138     aItem.SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
   139 
       
   140 	if( aItem.GetNextString(iDriveLetter) != KErrNone )
       
   141 	    {
       
   142 	    VCXLOGLO1("<<<CIptvSettingsDatabaseTest::CreateL: invalid argument!");
       
   143 	    return KErrArgument;
       
   144 	    }
       
   145 	VCXLOGLO2("CIptvSettingsDatabaseTest::CreateL iDriveLetter: %S", &iDriveLetter);
       
   146 
       
   147 	if( aItem.GetNextString(iDatabaseFilename) != KErrNone )
       
   148 	    {
       
   149 	    VCXLOGLO1("<<<CIptvSettingsDatabaseTest::CreateL: invalid argument!");
       
   150 	    return KErrArgument;
       
   151 	    }
       
   152 	VCXLOGLO2("CIptvSettingsDatabaseTest::CreateL iDatabaseFilename: %S", &iDatabaseFilename);
       
   153 
       
   154 	TInt err( 0 );
       
   155 
       
   156 	TBuf<256> tempPath;
       
   157 	tempPath.Format( KSettingsDatabaseTestPath, &iDriveLetter );
       
   158 	VCXLOGLO2("CIptvSettingsDatabaseTest::Checking path: %S", &tempPath);
       
   159 	CheckPath( tempPath );
       
   160 
       
   161 	if( iDatabaseFilename.Compare(_L("Badname") ) == 0)
       
   162 		{
       
   163 		VCXLOGLO1("CIptvSettingsDatabaseTest::CreateL: Using bad filename");
       
   164 		TBuf<256> tempFileName;
       
   165 		tempFileName.Append( iDriveLetter );
       
   166 		tempFileName.Append( KSettingsDatabaseTestBadFilename );
       
   167 		VCXLOGLO2("CIptvSettingsDatabaseTest::CreateL filename: %S", &tempFileName);
       
   168 	    TRAP( err, iDatabase = CIptvSettingsDatabase::NewL( tempFileName ));
       
   169 		}
       
   170 	else
       
   171 		{
       
   172 		TBuf<256> tempFileName;
       
   173 		tempFileName.Format( KSettingsDatabaseTestFileName, &iDriveLetter, &iDatabaseFilename );
       
   174 		VCXLOGLO2("CIptvSettingsDatabaseTest::CreateL filename: %S", &tempFileName);
       
   175 		PrepareFile( tempFileName );
       
   176 	  TRAP( err, iDatabase = CIptvSettingsDatabase::NewL( tempFileName ) )
       
   177 		}
       
   178 
       
   179 	if( err != KErrNone )
       
   180 		{
       
   181 		VCXLOGLO2("CIptvSettingsDatabaseTest::CreateL: creating instance failed! error %d", err);
       
   182 		}
       
   183 
       
   184     VCXLOGLO1("<<<CIptvSettingsDatabaseTest::CreateL");
       
   185     return err;
       
   186 
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CIptvServiceTest::DestroyServiceL
       
   191 // DestroyServiceL test method function.
       
   192 // (other items were commented in a header).
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CIptvSettingsDatabaseTest::DestroyL( CStifItemParser& /* aItem */ )
       
   196     {
       
   197     VCXLOGLO1(">>>CIptvSettingsDatabaseTest::DestroyL");
       
   198     // Print to UI
       
   199     _LIT( KIptvSettingsDatabaseTest, "IptvSettingsDatabaseTest" );
       
   200     _LIT( KWhere, "In DestroyL" );
       
   201     TestModuleIf().Printf( 0, KIptvSettingsDatabaseTest, KWhere );
       
   202     // Print to log file
       
   203     iLog->Log( KWhere );
       
   204 
       
   205     TInt err = KErrNone;
       
   206 
       
   207 	if(iDatabase)
       
   208 		{
       
   209 		delete iDatabase;
       
   210 		iDatabase = NULL;
       
   211 		}
       
   212 
       
   213 	VCXLOGLO1("<<<CIptvSettingsDatabaseTest::DestroyL");
       
   214     return err;
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CIptvSettingsDatabaseTest::SetSettingsL
       
   219 //
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TInt CIptvSettingsDatabaseTest::TestSettingsL( CStifItemParser& aItem )
       
   223     {
       
   224 
       
   225     // Print to UI
       
   226     _LIT( KIptvSettingsDatabaseTest, "IptvSettingsDatabaseTest" );
       
   227     _LIT( KWhere, "In TestSettings" );
       
   228     TestModuleIf().Printf( 0, KIptvSettingsDatabaseTest, KWhere );
       
   229     // Print to log file
       
   230     iLog->Log( KWhere );
       
   231 
       
   232     VCXLOGLO1(">>>CIptvSettingsDatabaseTest::TestSettings");
       
   233 
       
   234     TInt iParentalControl;
       
   235     if ( aItem.GetNextInt( iParentalControl ) != KErrNone )
       
   236     	{
       
   237     	iParentalControl = KMaxTInt;
       
   238     	}
       
   239 
       
   240     TInt iRecordingTimeReserve;
       
   241     if ( !aItem.GetNextInt( iRecordingTimeReserve ) != KErrNone )
       
   242     	{
       
   243     	iRecordingTimeReserve = KMaxTInt;
       
   244     	}
       
   245 
       
   246     TInt iReminderTime;
       
   247     if( !aItem.GetNextInt( iReminderTime ) != KErrNone )
       
   248     	{
       
   249     	iReminderTime = KMaxTInt;
       
   250     	}
       
   251 
       
   252     iSettings.iParentalControl = iParentalControl;
       
   253     iSettings.iRecordingTimeReserve = iRecordingTimeReserve;
       
   254     iSettings.iReminderTime = iReminderTime;
       
   255     iSettings.iLastUsedServiceId = 0;
       
   256     iSettings.iLastUsedChannelId = 0;
       
   257 
       
   258     iDatabase->SaveSettingsL( iSettings );
       
   259 
       
   260     TIptvLiveUISettings iReceivedSettings;
       
   261     iDatabase->ReadSettingsL( iReceivedSettings );
       
   262 
       
   263     if( (iReceivedSettings.iParentalControl != iSettings.iParentalControl) &&
       
   264     	(iReceivedSettings.iRecordingTimeReserve != iSettings.iRecordingTimeReserve) &&
       
   265     	(iReceivedSettings.iReminderTime != iSettings.iReminderTime) &&
       
   266     	(iReceivedSettings.iLastUsedServiceId != iSettings.iLastUsedServiceId) &&
       
   267     	(iReceivedSettings.iLastUsedChannelId != iSettings.iLastUsedChannelId)
       
   268     	)
       
   269     {
       
   270 		VCXLOGLO1("CIptvSettingsDatabaseTest::TestSettingsL: settings do not match!");
       
   271 		VCXLOGLO1("<<<CIptvSettingsDatabaseTest::TestSettingsL");
       
   272 		return KErrArgument;
       
   273     }
       
   274 
       
   275     VCXLOGLO1("<<<CIptvSettingsDatabaseTest::TestSettingsL");
       
   276     return KErrNone;
       
   277 
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CIptvSettingsDatabaseTest::TestLastUsageL
       
   282 //
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 TInt CIptvSettingsDatabaseTest::TestLastUsageL( CStifItemParser& /* aItem */ )
       
   286     {
       
   287     // Print to UI
       
   288     _LIT( KIptvSettingsDatabaseTest, "IptvSettingsDatabaseTest" );
       
   289     _LIT( KWhere, "In SetSettings" );
       
   290     TestModuleIf().Printf( 0, KIptvSettingsDatabaseTest, KWhere );
       
   291     // Print to log file
       
   292     iLog->Log( KWhere );
       
   293 
       
   294     VCXLOGLO1(">>>CIptvSettingsDatabaseTest::TestLastUsageL");
       
   295 
       
   296     iDatabase->SaveLastUsageL( iSettings );
       
   297 
       
   298     TIptvLiveUISettings iReceivedSettings;
       
   299     iDatabase->ReadLastUsageL( iReceivedSettings );
       
   300 
       
   301     if( (iReceivedSettings.iParentalControl != iSettings.iParentalControl) &&
       
   302     	(iReceivedSettings.iRecordingTimeReserve != iSettings.iRecordingTimeReserve) &&
       
   303     	(iReceivedSettings.iReminderTime != iSettings.iReminderTime) &&
       
   304     	(iReceivedSettings.iLastUsedServiceId != iSettings.iLastUsedServiceId) &&
       
   305     	(iReceivedSettings.iLastUsedChannelId != iSettings.iLastUsedChannelId)
       
   306     	)
       
   307     {
       
   308 		VCXLOGLO1("CIptvSettingsDatabaseTest::TestLastUsageL: settings do not match!");
       
   309 		VCXLOGLO1("<<<CIptvSettingsDatabaseTest::TestLastUsageL");
       
   310 		return KErrArgument;
       
   311     }
       
   312 
       
   313     VCXLOGLO1("<<<CIptvSettingsDatabaseTest::TestLastUsageL");
       
   314     return KErrNone;
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CIptvSettingsDatabaseTest::PrepareFile
       
   319 //
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 TInt CIptvSettingsDatabaseTest::PrepareFile( const TDesC &aFileName )
       
   323 	{
       
   324 	RFs iFs;
       
   325 	iFs.Connect();
       
   326 
       
   327 	VCXLOGLO2("CIptvSettingsDatabaseTest::PrepareFile: File exists: %S", &aFileName);
       
   328 	TRAPD( error, iFs.Delete( aFileName ) );
       
   329 
       
   330 	iFs.Close();
       
   331 
       
   332 	return error;
       
   333 	}
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CIptvSettingsDatabaseTest::CheckPath
       
   337 //
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 TInt CIptvSettingsDatabaseTest::CheckPath( const TDesC &aPath )
       
   341 	{
       
   342 	RFs iFs;
       
   343 	iFs.Connect();
       
   344 
       
   345 	TRAPD( error, BaflUtils::EnsurePathExistsL( iFs, aPath ) );
       
   346 
       
   347 	iFs.Close();
       
   348 
       
   349 	return error;
       
   350 	}
       
   351 
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CIptvSettingsDatabaseTest::?member_function
       
   355 // ?implementation_description
       
   356 // (other items were commented in a header).
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 /*
       
   360 TInt CIptvSettingsDatabaseTest::?member_function(
       
   361    CItemParser& aItem )
       
   362    {
       
   363 
       
   364    ?code
       
   365 
       
   366    }
       
   367 */
       
   368 
       
   369 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   370 // None
       
   371 
       
   372 //  End of File