loggingservices/eventlogger/test/src/t_logbackup.cpp
changeset 0 08ec8eefde2f
child 11 667e88a979d7
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <s32file.h>
       
    17 #include <babackup.h>
       
    18 
       
    19 #include "TEST.H"
       
    20 #include <logview.h>
       
    21 
       
    22 #undef test  //there is a "test" macro which hides "RTest test" declaration.
       
    23 
       
    24 RTest test(_L("Log Backup Test Harness"));
       
    25 CBaBackupSessionWrapper* theBackup = NULL;
       
    26 
       
    27 /////////////////////////////////////////////////////////////////////////////////////
       
    28 /////////////////////////////////////////////////////////////////////////////////////
       
    29 /////////////////////////////////////////////////////////////////////////////////////
       
    30 #ifdef __WINS__
       
    31 
       
    32 _LIT(KTestEventDesc, "Event Type Description");
       
    33 _LIT(KTestRemoteParty, "Remote Party");
       
    34 _LIT(KTestDirection, "Direction");
       
    35 const TLogDurationType KTestDurationType = 1;
       
    36 const TLogDuration KTestDuration = 0x1234;
       
    37 _LIT(KTestStatus, "Status");
       
    38 _LIT(KTestSubject, "Subject");
       
    39 _LIT(KTestNumber, "Number");
       
    40 const TLogContactItemId KTestContact = 0x1234;
       
    41 const TLogLink KTestLink = 0x1234;
       
    42 _LIT8(KTestData, "ABCDEFGH");
       
    43 _LIT(KTestNumber1, "TheNumber");
       
    44 _LIT(KTestNumber2, "Changed Number");
       
    45 
       
    46 class TClientObserverTestReceiver : public MLogClientChangeObserver
       
    47 	{
       
    48 public:
       
    49 	TClientObserverTestReceiver(TBool& aFlag) : iCallCount(0), iFlag(aFlag) { }
       
    50 
       
    51 public:
       
    52 	void HandleLogClientChangeEventL(TUid aChangeType, TInt /*aChangeParam1*/, TInt /*aChangeParam2*/, TInt /*aChangeParam3*/)
       
    53 		{
       
    54 		++iCallCount;
       
    55 		iFlag = (aChangeType == KLogClientChangeEventRefreshView);
       
    56 		}
       
    57 	inline TInt CallCount() const { return iCallCount; }
       
    58 	inline void Reset() { iCallCount = 0; iFlag = EFalse; }
       
    59 
       
    60 private:
       
    61 	TInt iCallCount;
       
    62 	TBool& iFlag;
       
    63 	};
       
    64 	
       
    65 LOCAL_C TBool IsLogOpenL()
       
    66 	{
       
    67 	return TestUtils::IsDatabaseOpenL();
       
    68 	}
       
    69 
       
    70 /**
       
    71 @SYMTestCaseID          SYSLIB-LOGENG-CT-0993
       
    72 @SYMTestCaseDesc	    Tests for a file open
       
    73 @SYMTestPriority 	    High
       
    74 @SYMTestActions  	    Check for errors while testing for file open 
       
    75 @SYMTestExpectedResults Test must not fail
       
    76 @SYMREQ                 REQ0000
       
    77 */
       
    78 LOCAL_C void TestLogOpenL()
       
    79 	{
       
    80 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0993 "));
       
    81 	TEST(IsLogOpenL());
       
    82 	}
       
    83 
       
    84 /**
       
    85 @SYMTestCaseID          SYSLIB-LOGENG-CT-0994
       
    86 @SYMTestCaseDesc	    Tests for file close
       
    87 @SYMTestPriority 	    High
       
    88 @SYMTestActions  	    Check for errors while testing for file close
       
    89 @SYMTestExpectedResults Test must not fail
       
    90 @SYMREQ                 REQ0000
       
    91 */
       
    92 LOCAL_C void TestLogClosedL()
       
    93 	{
       
    94 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0994 "));
       
    95 	TEST(!IsLogOpenL());
       
    96 	}
       
    97 
       
    98 LOCAL_C void StartBackupL()
       
    99 	{
       
   100 	User::InfoPrint(_L("Backup"));
       
   101 
       
   102 	TDriveUnit driveUnit(EDriveC);
       
   103 	TDriveName name = driveUnit.Name();
       
   104 
       
   105 	TParse parse;
       
   106 	LEAVE_IF_ERROR(parse.Set(KLogDatabaseName, &name, NULL));
       
   107 
       
   108 	delete theBackup;
       
   109 	theBackup = NULL;
       
   110 	theBackup = CBaBackupSessionWrapper::NewL();
       
   111 
       
   112 	theBackup->CloseFileL(parse.FullName(), MBackupObserver::EReleaseLockNoAccess);
       
   113 	User::After(1000000);
       
   114 	}
       
   115 
       
   116 LOCAL_C void DeleteLogDatabaseL()
       
   117 	{
       
   118 	User::InfoPrint(_L("delete"));
       
   119 	TestUtils::DeleteDatabaseL(EFalse);
       
   120 	}
       
   121 
       
   122 LOCAL_C void EndBackupL()
       
   123 	{
       
   124 	delete theBackup;
       
   125 	theBackup = NULL;
       
   126 	User::After(1000000);
       
   127 	}
       
   128 
       
   129 LOCAL_C void DelayL(TInt aDelay)
       
   130 	{
       
   131 	CTestTimer* timer = CTestTimer::NewL();
       
   132 	timer->After(aDelay);
       
   133 	CActiveScheduler::Start();
       
   134 	delete timer;
       
   135 	}
       
   136 
       
   137 
       
   138 const TUid KTestEventUid = {0x10005393};
       
   139 _LIT(KTestEventDesc1, "Event Type Description");
       
   140 _LIT(KTestEventDesc2, "Changed Event Description");
       
   141 
       
   142 LOCAL_C void ForceClientImplInstL(CLogClient& aClient)
       
   143 	{
       
   144 	CLogEventType* type = CLogEventType::NewL();
       
   145 	CleanupStack::PushL(type);
       
   146 	type->SetUid(KTestEventUid);
       
   147 	type->SetDescription(KTestEventDesc1);
       
   148 	type->SetLoggingEnabled(ETrue);
       
   149 	
       
   150 	CTestActive* active = new(ELeave)CTestActive;
       
   151 	CleanupStack::PushL(active);
       
   152 	aClient.AddEventType(*type, active->iStatus);
       
   153 	active->StartL();
       
   154 	CActiveScheduler::Start();
       
   155 	CleanupStack::PopAndDestroy(2);//type, active
       
   156 	
       
   157 	}
       
   158 
       
   159 /**
       
   160 @SYMTestCaseID          SYSLIB-LOGENG-CT-0995
       
   161 @SYMTestCaseDesc	    Tests for starting and ending the backup session 
       
   162 @SYMTestPriority 	    High
       
   163 @SYMTestActions  	    Test for file open and close,start and end of the backup session
       
   164 @SYMTestExpectedResults Test must not fail
       
   165 @SYMREQ                 REQ0000
       
   166 */
       
   167 LOCAL_C void TestLockingL()
       
   168 	{
       
   169 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0995 "));
       
   170 	CLogClient* client = CLogClient::NewL(theFs);
       
   171 	CleanupStack::PushL(client);
       
   172 
       
   173 	ForceClientImplInstL(*client);
       
   174 
       
   175 
       
   176 	DelayL(1000000);
       
   177 	TestLogOpenL();
       
   178 	StartBackupL();
       
   179 	DelayL(1000000);
       
   180 
       
   181 	TestLogClosedL();
       
   182 
       
   183 	EndBackupL();
       
   184 	TestLogOpenL();
       
   185 
       
   186 	CleanupStack::PopAndDestroy(); // client
       
   187 	}
       
   188 
       
   189 /**
       
   190 @SYMTestCaseID          SYSLIB-LOGENG-CT-0996
       
   191 @SYMTestCaseDesc	    Tests for deleting the file when its locked
       
   192 @SYMTestPriority 	    High
       
   193 @SYMTestActions  	    Attempt for deleting the file when its locked
       
   194 @SYMTestExpectedResults Test must not fail
       
   195 @SYMREQ                 REQ0000
       
   196 */
       
   197 LOCAL_C void TestDeleteWhileLockedL()
       
   198 	{
       
   199 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0996 "));
       
   200 	CLogClient* client = CLogClient::NewL(theFs);
       
   201 	CleanupStack::PushL(client);
       
   202 	ForceClientImplInstL(*client);
       
   203 
       
   204 	TestLogOpenL();
       
   205 	StartBackupL();
       
   206 	DelayL(1000000);
       
   207 	TestLogClosedL();
       
   208 
       
   209 	CleanupStack::PopAndDestroy(); // client
       
   210 	TestLogClosedL();
       
   211 
       
   212 	client = CLogClient::NewL(theFs);
       
   213 	CleanupStack::PushL(client);
       
   214 	ForceClientImplInstL(*client);
       
   215 	EndBackupL();
       
   216 
       
   217 	TestLogOpenL();
       
   218 	StartBackupL();
       
   219 	DelayL(1000000);
       
   220 	TestLogClosedL();
       
   221 	EndBackupL();
       
   222 	TestLogOpenL();
       
   223 
       
   224 	CleanupStack::PopAndDestroy(); // client
       
   225 	}
       
   226 
       
   227 /**
       
   228 @SYMTestCaseID          SYSLIB-LOGENG-CT-0997
       
   229 @SYMTestCaseDesc	    Tests for deleting the view while its locked
       
   230 @SYMTestPriority 	    High
       
   231 @SYMTestActions  	    Delete the view when its locked
       
   232 @SYMTestExpectedResults Test must not fail
       
   233 @SYMREQ                 REQ0000
       
   234 */
       
   235 LOCAL_C void TestDeleteViewWhileLockedL()
       
   236 	{
       
   237 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0997 "));
       
   238 	CLogClient* client = CLogClient::NewL(theFs);
       
   239 	CleanupStack::PushL(client);
       
   240 	ForceClientImplInstL(*client);
       
   241 
       
   242 	CLogFilter* filter = CLogFilter::NewL();
       
   243 	CleanupStack::PushL(filter);
       
   244 
       
   245 	CLogViewEvent* view = CLogViewEvent::NewL(*client);
       
   246 	CleanupStack::PushL(view);
       
   247 
       
   248 	TestLogOpenL();
       
   249 	StartBackupL();
       
   250 	DelayL(1000000);
       
   251 	TestLogClosedL();
       
   252 
       
   253 	CleanupStack::PopAndDestroy(3); // view, filter, client
       
   254 	TestLogClosedL();
       
   255 
       
   256 	client = CLogClient::NewL(theFs);
       
   257 	CleanupStack::PushL(client);
       
   258 	ForceClientImplInstL(*client);
       
   259 
       
   260 	filter = CLogFilter::NewL();
       
   261 	CleanupStack::PushL(filter);
       
   262 
       
   263 	view = CLogViewEvent::NewL(*client);
       
   264 	CleanupStack::PushL(view);
       
   265 	EndBackupL();
       
   266 
       
   267 	TestLogOpenL();
       
   268 	StartBackupL();
       
   269 	DelayL(1000000);
       
   270 	TestLogClosedL();
       
   271 	EndBackupL();
       
   272 	TestLogOpenL();
       
   273 
       
   274 	CleanupStack::PopAndDestroy(3); // view, filter, client
       
   275 	}
       
   276 
       
   277 /**
       
   278 @SYMTestCaseID          SYSLIB-LOGENG-CT-0998
       
   279 @SYMTestCaseDesc	    Multiple client logging test
       
   280 @SYMTestPriority 	    High
       
   281 @SYMTestActions  	    Open multiple clients and test for starting and ending the backup 
       
   282 @SYMTestExpectedResults Test must not fail
       
   283 @SYMREQ                 REQ0000
       
   284 */
       
   285 LOCAL_C void TestMultipleClientLockingL()
       
   286 	{
       
   287 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0998 "));
       
   288 	CLogClient* client1 = CLogClient::NewL(theFs);
       
   289 	CleanupStack::PushL(client1);
       
   290 	ForceClientImplInstL(*client1);
       
   291 
       
   292 	TestLogOpenL();
       
   293 
       
   294 	CLogClient* client2 = CLogClient::NewL(theFs);
       
   295 	CleanupStack::PushL(client2);
       
   296 	ForceClientImplInstL(*client2);
       
   297 
       
   298 	TestLogOpenL();
       
   299 
       
   300 	StartBackupL();
       
   301 	EndBackupL();
       
   302 	TestLogOpenL();
       
   303 
       
   304 	StartBackupL();
       
   305 	TestLogClosedL();
       
   306 
       
   307 	EndBackupL();
       
   308 	TestLogOpenL();
       
   309 
       
   310 	CleanupStack::PopAndDestroy(2); // client1, client2
       
   311 	}
       
   312 
       
   313 /**
       
   314 @SYMTestCaseID          SYSLIB-LOGENG-CT-0999
       
   315 @SYMTestCaseDesc	    Multiple view locking test
       
   316 @SYMTestPriority 	    High
       
   317 @SYMTestActions  	    Open multiple views and test for starting and ending of backup
       
   318 @SYMTestExpectedResults Test must not fail
       
   319 @SYMREQ                 REQ0000
       
   320 */
       
   321 LOCAL_C void TestMultipleViewLockingL()
       
   322 	{
       
   323 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0999 "));
       
   324 	CLogClient* client = CLogClient::NewL(theFs);
       
   325 	CleanupStack::PushL(client);
       
   326 	ForceClientImplInstL(*client);
       
   327 
       
   328 	CLogFilter* filter = CLogFilter::NewL();
       
   329 	CleanupStack::PushL(filter);
       
   330 
       
   331 	CLogViewEvent* view1 = CLogViewEvent::NewL(*client);
       
   332 	CleanupStack::PushL(view1);
       
   333 
       
   334 	CLogViewEvent* view2 = CLogViewEvent::NewL(*client);
       
   335 	CleanupStack::PushL(view2);
       
   336 
       
   337 	TestLogOpenL();
       
   338 	StartBackupL();
       
   339 	TestLogClosedL();
       
   340 	EndBackupL();
       
   341 	TestLogOpenL();
       
   342 
       
   343 	CleanupStack::PopAndDestroy(4); // view2, view1, filter, client
       
   344 	}
       
   345 
       
   346 LOCAL_C void DoTestLogL(CLogBase& aClient, TInt aError)
       
   347 	{
       
   348 	CTestActive* active = new(ELeave)CTestActive();
       
   349 	CleanupStack::PushL(active);
       
   350 
       
   351 	CLogEvent* event = CLogEvent::NewL();
       
   352 	CleanupStack::PushL(event);
       
   353 
       
   354 	TTime now;
       
   355 	now.UniversalTime();
       
   356 
       
   357 	event->SetEventType(KLogCallEventTypeUid);
       
   358 
       
   359 	active->StartL();
       
   360 	aClient.AddEvent(*event, active->iStatus);
       
   361 	CActiveScheduler::Start();
       
   362 	TEST2(active->iStatus.Int(), aError);
       
   363 
       
   364 	if (aError == KErrNone)
       
   365 		{
       
   366 		TEST(event->EventType() == KLogCallEventTypeUid);
       
   367 		TEST(event->Description().Length() > 0);
       
   368 		TEST(event->Time() >= now);
       
   369 		now = event->Time();
       
   370 		}
       
   371 	else
       
   372 		{
       
   373 		// User a dummy id to prevent assertion
       
   374 		event->SetId(123);
       
   375 		}
       
   376 
       
   377 	TLogId id = event->Id();
       
   378 
       
   379 	event->SetRemoteParty(KTestRemoteParty);
       
   380 	event->SetDirection(KTestDirection);
       
   381 	event->SetDurationType(KTestDurationType);
       
   382 	event->SetDuration(KTestDuration);
       
   383 	event->SetStatus(KTestStatus);
       
   384 	event->SetSubject(KTestSubject);
       
   385 	event->SetNumber(KTestNumber);
       
   386 	event->SetContact(KTestContact);
       
   387 	event->SetLink(KTestLink);
       
   388 	event->SetDataL(KTestData);
       
   389 
       
   390 	active->StartL();
       
   391 	aClient.ChangeEvent(*event, active->iStatus);
       
   392 	CActiveScheduler::Start();
       
   393 	TEST2(active->iStatus.Int(), aError);
       
   394 
       
   395 	if (aError == KErrNone)
       
   396 		{
       
   397 		TEST(event->Id() == id);
       
   398 		TEST(event->EventType() == KLogCallEventTypeUid);
       
   399 		TEST(event->Description().Length() > 0);
       
   400 		TEST(event->Time() == now);
       
   401 		TEST(event->RemoteParty() == KTestRemoteParty);
       
   402 		TEST(event->Direction() == KTestDirection);
       
   403 		TEST(event->DurationType() == KTestDurationType);
       
   404 		TEST(event->Duration() == KTestDuration);
       
   405 		TEST(event->Status() == KTestStatus);
       
   406 		TEST(event->Subject() == KTestSubject);
       
   407 		TEST(event->Number() == KTestNumber);
       
   408 		TEST(event->Contact() == KTestContact);
       
   409 		TEST(event->Link() == KTestLink);
       
   410 		TEST(event->Data() == KTestData);
       
   411 		}
       
   412 
       
   413 	CleanupStack::PopAndDestroy(); // event;
       
   414 
       
   415 	event = CLogEvent::NewL();
       
   416 	CleanupStack::PushL(event);
       
   417 
       
   418 	event->SetId(id);
       
   419 
       
   420 	active->StartL();
       
   421 	aClient.GetEvent(*event, active->iStatus);
       
   422 	CActiveScheduler::Start();
       
   423 	TEST2(active->iStatus.Int(), aError);
       
   424 
       
   425 	if (aError == KErrNone)
       
   426 		{
       
   427 		TEST(event->Id() == id);
       
   428 		TEST(event->EventType() == KLogCallEventTypeUid);
       
   429 		TEST(event->Description().Length() > 0);
       
   430 		TEST(event->Time() == now);
       
   431 		TEST(event->RemoteParty() == KTestRemoteParty);
       
   432 		TEST(event->Direction() == KTestDirection);
       
   433 		TEST(event->DurationType() == KTestDurationType);
       
   434 		TEST(event->Duration() == KTestDuration);
       
   435 		TEST(event->Status() == KTestStatus);
       
   436 		TEST(event->Subject() == KTestSubject);
       
   437 		TEST(event->Number() == KTestNumber);
       
   438 		TEST(event->Contact() == KTestContact);
       
   439 		TEST(event->Link() == KTestLink);
       
   440 		TEST(event->Data() == KTestData);
       
   441 		}
       
   442 
       
   443 	active->StartL();
       
   444 	aClient.DeleteEvent(id, active->iStatus);
       
   445 	CActiveScheduler::Start();
       
   446 	TEST2(active->iStatus.Int(), aError);
       
   447 
       
   448 	active->StartL();
       
   449 	aClient.GetEvent(*event, active->iStatus);
       
   450 	CActiveScheduler::Start();
       
   451 	RDebug::Print(_L("*** active->iStatus.Int()=%d\n"), active->iStatus.Int());
       
   452 	TEST(active->iStatus.Int() == aError || active->iStatus.Int() == KErrNotFound);
       
   453 
       
   454 	CleanupStack::PopAndDestroy(2); // event, active
       
   455 	}
       
   456 
       
   457 /**
       
   458 @SYMTestCaseID          SYSLIB-LOGENG-CT-1000
       
   459 @SYMTestCaseDesc	    Client requests test
       
   460 @SYMTestPriority 	    High
       
   461 @SYMTestActions  	    Tests for client requests when the file is opened and check for no errors
       
   462 						Tests for client requests when the file is closed and check for access denied errors
       
   463 						Re-test for client requests when file is opened and check for no errors
       
   464 @SYMTestExpectedResults Test must not fail
       
   465 @SYMREQ                 REQ0000
       
   466 */
       
   467 LOCAL_C void TestClientRequestsL()
       
   468 	{
       
   469 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1000 "));
       
   470 	CLogClient* client1 = CLogClient::NewL(theFs);
       
   471 	CleanupStack::PushL(client1);
       
   472 	ForceClientImplInstL(*client1);
       
   473 
       
   474 	TestLogOpenL();
       
   475 
       
   476 	CLogClient* client2 = CLogClient::NewL(theFs);
       
   477 	CleanupStack::PushL(client2);
       
   478 	ForceClientImplInstL(*client2);
       
   479 
       
   480 	TestLogOpenL();
       
   481 
       
   482 	DoTestLogL(*client1, KErrNone);
       
   483 	DoTestLogL(*client2, KErrNone);
       
   484 
       
   485 	StartBackupL();
       
   486 	DelayL(1000000);
       
   487 	TestLogClosedL();
       
   488 
       
   489 	DoTestLogL(*client1, KErrAccessDenied);
       
   490 	DoTestLogL(*client2, KErrAccessDenied);
       
   491 
       
   492 	EndBackupL();
       
   493 	TestLogOpenL();
       
   494 
       
   495 	DoTestLogL(*client1, KErrNone);
       
   496 	DoTestLogL(*client2, KErrNone);
       
   497 
       
   498 	CleanupStack::PopAndDestroy(2); // client1, client2
       
   499 	}
       
   500 
       
   501 /**
       
   502 @SYMTestCaseID          SYSLIB-LOGENG-CT-1001
       
   503 @SYMTestCaseDesc	    Tests for notification changes
       
   504 @SYMTestPriority 	    High
       
   505 @SYMTestActions  	    Set up for client log notification changes.
       
   506                         Change the log and unlock the log.Try and change the log again and check for access denied error.
       
   507 @SYMTestExpectedResults Test must not fail
       
   508 @SYMREQ                 REQ0000
       
   509 */
       
   510 LOCAL_C void TestNotificationsL()
       
   511 	{
       
   512 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1001 "));
       
   513 	CTestActive* notify = new(ELeave)CTestActive;
       
   514 	CleanupStack::PushL(notify);
       
   515 
       
   516 	CTestTimer* timer = CTestTimer::NewL();
       
   517 	CleanupStack::PushL(timer);
       
   518 
       
   519 	CLogClient* client = CLogClient::NewL(theFs);
       
   520 	CleanupStack::PushL(client);
       
   521 	ForceClientImplInstL(*client);
       
   522 	EndBackupL();
       
   523 
       
   524 	// Setup change notification
       
   525 	notify->StartL();
       
   526 	client->NotifyChange(10000000, notify->iStatus);
       
   527 
       
   528 	// Wait a second
       
   529 	timer->After(1000000);
       
   530 	CActiveScheduler::Start();
       
   531 
       
   532 	// Change the log
       
   533 	DoTestLogL(*client, KErrNone);
       
   534 
       
   535 	// Unlock the log
       
   536 	TestLogOpenL();
       
   537 	StartBackupL();
       
   538 	DelayL(1000000);
       
   539 	TestLogClosedL();
       
   540 
       
   541 	// Try and change the log again
       
   542 	DoTestLogL(*client, KErrAccessDenied);
       
   543 
       
   544 	// Make sure the notifier doesn't complete
       
   545 	timer->After(15000000);
       
   546 	CActiveScheduler::Start();
       
   547 	TEST(notify->IsActive());
       
   548 
       
   549 	// Lock the log
       
   550 	EndBackupL();
       
   551 	TestLogOpenL();
       
   552 
       
   553 	// Wait for notification
       
   554 	CActiveScheduler::Start();
       
   555 	TEST(!notify->IsActive());
       
   556 
       
   557 	// Setup change notification
       
   558 	notify->StartL();
       
   559 	client->NotifyChange(10000000, notify->iStatus);
       
   560 
       
   561 	// Wait a second
       
   562 	timer->After(1000000);
       
   563 	CActiveScheduler::Start();
       
   564 
       
   565 	// Unlock the log
       
   566 	TestLogOpenL();
       
   567 	StartBackupL();
       
   568 	DelayL(1000000);
       
   569 	TestLogClosedL();
       
   570 
       
   571 	// Check notification is completed when client destroyed
       
   572 	TEST(notify->IsActive());
       
   573 	CleanupStack::PopAndDestroy(client);
       
   574 
       
   575 	// Wait for notification
       
   576 	CActiveScheduler::Start();	
       
   577 	TEST(!notify->IsActive());
       
   578 	TEST2(notify->iStatus.Int(), KErrCancel);
       
   579 
       
   580 	// Recreate client
       
   581 	client = CLogClient::NewL(theFs);
       
   582 	CleanupStack::PushL(client);
       
   583 
       
   584 	// Setup change notification
       
   585 	notify->StartL();
       
   586 	client->NotifyChange(10000000, notify->iStatus);
       
   587 
       
   588 	// Wait a second
       
   589 	timer->After(1000000);
       
   590 	CActiveScheduler::Start();
       
   591 
       
   592 	// Check notification is completed when cancelled
       
   593 	TEST(notify->IsActive());
       
   594 	client->NotifyChangeCancel();
       
   595 
       
   596 	// Wait for notification
       
   597 	CActiveScheduler::Start();	
       
   598 	TEST(!notify->IsActive());
       
   599 	TEST2(notify->iStatus.Int(), KErrCancel);
       
   600 
       
   601 	// Setup change notification
       
   602 	notify->StartL();
       
   603 	client->NotifyChange(10000000, notify->iStatus);
       
   604 
       
   605 	// Wait a second
       
   606 	timer->After(1000000);
       
   607 	CActiveScheduler::Start();
       
   608 
       
   609 	// Lock the log
       
   610 	EndBackupL();
       
   611 	TestLogOpenL();
       
   612 
       
   613 	// Wait for notification
       
   614 	TEST(notify->IsActive());
       
   615 	CActiveScheduler::Start();	
       
   616 	TEST(!notify->IsActive());
       
   617 	TEST(notify->iStatus >= 0);
       
   618 
       
   619 	notify->StartL();
       
   620 	client->NotifyChange(10000000, notify->iStatus);
       
   621 
       
   622 	// Wait a second
       
   623 	timer->After(1000000);
       
   624 	CActiveScheduler::Start();
       
   625 
       
   626 	// Change the log
       
   627 	DoTestLogL(*client, KErrNone);
       
   628 
       
   629 	// Wait for notification
       
   630 	TEST(notify->IsActive());
       
   631 	CActiveScheduler::Start();	
       
   632 	TEST(!notify->IsActive());
       
   633 	TEST(notify->iStatus >= 0);
       
   634 
       
   635 	CleanupStack::PopAndDestroy(3); // client, timer, notify
       
   636 	}
       
   637 
       
   638 /**
       
   639 @SYMTestCaseID          SYSLIB-LOGENG-CT-1002
       
   640 @SYMTestCaseDesc	    Tests for request in progress
       
   641 @SYMTestPriority 	    High
       
   642 @SYMTestActions  	    Add an event when backup is started and check for access denied error
       
   643 @SYMTestExpectedResults Test must not fail
       
   644 @SYMREQ                 REQ0000
       
   645 */
       
   646 LOCAL_C void TestRequestInProgressL()
       
   647 	{
       
   648 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1002 "));
       
   649 	CLogClient* client = CLogClient::NewL(theFs);
       
   650 	CleanupStack::PushL(client);
       
   651 	ForceClientImplInstL(*client);
       
   652 	EndBackupL();
       
   653 
       
   654 	CTestActive* active = new(ELeave)CTestActive();
       
   655 	CleanupStack::PushL(active);
       
   656 
       
   657 	CLogEvent* event = CLogEvent::NewL();
       
   658 	CleanupStack::PushL(event);
       
   659 
       
   660 	event->SetEventType(KLogCallEventTypeUid);
       
   661 
       
   662 	active->StartL();
       
   663 	client->AddEvent(*event, active->iStatus);
       
   664 	StartBackupL();
       
   665 	CActiveScheduler::Start();
       
   666 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   667 	DelayL(1000000);
       
   668 
       
   669 	// User a dummy id to prevent assertion
       
   670 	event->SetId(123);
       
   671 
       
   672 	EndBackupL();
       
   673 	active->StartL();
       
   674 	client->ChangeEvent(*event, active->iStatus);
       
   675 	StartBackupL();
       
   676 
       
   677 	CActiveScheduler::Start();
       
   678 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   679 	DelayL(1000000);
       
   680 
       
   681 	EndBackupL();
       
   682 	active->StartL();
       
   683 	client->GetEvent(*event, active->iStatus);
       
   684 	StartBackupL();
       
   685 
       
   686 	CActiveScheduler::Start();
       
   687 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   688 	DelayL(1000000);
       
   689 
       
   690 	EndBackupL();
       
   691 	active->StartL();
       
   692 	client->DeleteEvent(event->Id(), active->iStatus);
       
   693 	StartBackupL();
       
   694 
       
   695 	CActiveScheduler::Start();
       
   696 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   697 	DelayL(1000000);
       
   698 
       
   699 	EndBackupL();
       
   700 	active->StartL();
       
   701 	client->GetEvent(*event, active->iStatus);
       
   702 	StartBackupL();
       
   703 
       
   704 	CActiveScheduler::Start();
       
   705 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   706 	DelayL(1000000);
       
   707 
       
   708 	// Check the log is useable
       
   709 	EndBackupL();
       
   710 	DoTestLogL(*client, KErrNone);
       
   711 
       
   712 	CleanupStack::PopAndDestroy(3); // client, event, active
       
   713 	}
       
   714 
       
   715 /**
       
   716 @SYMTestCaseID          SYSLIB-LOGENG-CT-1003
       
   717 @SYMTestCaseDesc	    Tests for log view when request is in progress
       
   718 @SYMTestPriority 	    High
       
   719 @SYMTestActions  	    Add events to the log,set a filter on log view and start the backup session 
       
   720                         and check for the request status for access denied.
       
   721 @SYMTestExpectedResults Test must not fail
       
   722 @SYMREQ                 REQ0000
       
   723 */
       
   724 LOCAL_C void TestViewRequestInProgressL()
       
   725 	{
       
   726 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1003 "));
       
   727 	CLogClient* client = CLogClient::NewL(theFs);
       
   728 	CleanupStack::PushL(client);
       
   729 	ForceClientImplInstL(*client);
       
   730 	EndBackupL();
       
   731 
       
   732 	CTestActive* active = new(ELeave)CTestActive();
       
   733 	CleanupStack::PushL(active);
       
   734 
       
   735 	CLogFilter* filter = CLogFilter::NewL();
       
   736 	CleanupStack::PushL(filter);
       
   737 
       
   738 	CLogViewEvent* view = CLogViewEvent::NewL(*client);
       
   739 	CleanupStack::PushL(view);
       
   740 
       
   741 	CLogEvent* event = CLogEvent::NewL();
       
   742 	CleanupStack::PushL(event);
       
   743 	event->SetEventType(KLogCallEventTypeUid);
       
   744 
       
   745 	active->StartL();
       
   746 	client->AddEvent(*event, active->iStatus);
       
   747 	CActiveScheduler::Start();
       
   748 	TEST2(active->iStatus.Int(), KErrNone);
       
   749 
       
   750 	active->StartL();
       
   751 	client->AddEvent(*event, active->iStatus);
       
   752 	CActiveScheduler::Start();
       
   753 	TEST2(active->iStatus.Int(), KErrNone);
       
   754 
       
   755 	TestLogOpenL();
       
   756 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   757 	active->StartL();
       
   758 	StartBackupL();
       
   759 
       
   760 	CActiveScheduler::Start();
       
   761 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   762 	DelayL(1000000);
       
   763 	TestLogClosedL();
       
   764 
       
   765 	EndBackupL();
       
   766 	TestLogOpenL();
       
   767 
       
   768 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   769 	active->StartL();
       
   770 	CActiveScheduler::Start();
       
   771 	TEST2(active->iStatus.Int(), KErrNone);
       
   772 	
       
   773 	TEST(view->NextL(active->iStatus));
       
   774 	active->StartL();
       
   775 	StartBackupL();
       
   776 
       
   777 	CActiveScheduler::Start();
       
   778 	TEST2(active->iStatus.Int(), KErrAccessDenied);
       
   779 	DelayL(1000000);
       
   780 	TestLogClosedL();
       
   781 
       
   782 	EndBackupL();
       
   783 	TestLogOpenL();
       
   784 
       
   785 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   786 	active->StartL();
       
   787 	CActiveScheduler::Start();
       
   788 	TEST2(active->iStatus.Int(), KErrNone);
       
   789 	
       
   790 	TEST(view->NextL(active->iStatus));
       
   791 	active->StartL();
       
   792 	CActiveScheduler::Start();
       
   793 	TEST2(active->iStatus.Int(), KErrNone);
       
   794 
       
   795 	// Now check a view is no longer valid after a backup
       
   796 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   797 	active->StartL();
       
   798 	CActiveScheduler::Start();
       
   799 	TEST2(active->iStatus.Int(), KErrNone);
       
   800 	TEST(view->CountL() > 1);
       
   801 
       
   802 	StartBackupL();
       
   803 	EndBackupL();
       
   804 
       
   805 	DelayL(1000000);
       
   806 
       
   807 	// Check the view can be setup again
       
   808 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   809 	active->StartL();
       
   810 	CActiveScheduler::Start();
       
   811 	TEST2(active->iStatus.Int(), KErrNone);
       
   812 	TEST(view->CountL() > 1);
       
   813 
       
   814 	TEST(view->NextL(active->iStatus));
       
   815 	active->StartL();
       
   816 	CActiveScheduler::Start();
       
   817 	TEST2(active->iStatus.Int(), KErrNone);
       
   818 
       
   819 	CleanupStack::PopAndDestroy(5); // event, view, filter, active, client
       
   820 	}
       
   821 
       
   822 /**
       
   823 @SYMTestCaseID          SYSLIB-LOGENG-CT-1004
       
   824 @SYMTestCaseDesc	    Tests for view event log
       
   825 @SYMTestPriority 	    High
       
   826 @SYMTestActions  	    Create an event type and add the event to the log.
       
   827                         Close the log and try setting the filter on view.Check for access denied error.
       
   828 						Repeat the operation after opening the log and check for no error
       
   829 @SYMTestExpectedResults Test must not fail
       
   830 @SYMREQ                 REQ0000
       
   831 */
       
   832 LOCAL_C void TestViewSetup1L()
       
   833 	{
       
   834 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1004 "));
       
   835 	CLogClient* client = CLogClient::NewL(theFs);
       
   836 	CleanupStack::PushL(client);
       
   837 	ForceClientImplInstL(*client);
       
   838 	EndBackupL();
       
   839 
       
   840 	CTestActive* active = new(ELeave)CTestActive();
       
   841 	CleanupStack::PushL(active);
       
   842 
       
   843 	CLogFilter* filter = CLogFilter::NewL();
       
   844 	CleanupStack::PushL(filter);
       
   845 
       
   846 	CLogViewEvent* view = CLogViewEvent::NewL(*client);
       
   847 	CleanupStack::PushL(view);
       
   848 
       
   849 	CLogEvent* event = CLogEvent::NewL();
       
   850 	CleanupStack::PushL(event);
       
   851 	event->SetEventType(KLogCallEventTypeUid);
       
   852 
       
   853 	active->StartL();
       
   854 	client->AddEvent(*event, active->iStatus);
       
   855 	CActiveScheduler::Start();
       
   856 	TEST2(active->iStatus.Int(), KErrNone);
       
   857 
       
   858 	TestLogOpenL();
       
   859 	StartBackupL();
       
   860 	DelayL(1000000);
       
   861 	TestLogClosedL();
       
   862 
       
   863 	TRAPD(error, view->SetFilterL(*filter, active->iStatus));
       
   864 	TEST2(error, KErrAccessDenied);
       
   865 
       
   866 	EndBackupL();
       
   867 	TestLogOpenL();
       
   868 
       
   869 	DelayL(1000000);
       
   870 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   871 	active->StartL();
       
   872 	CActiveScheduler::Start();
       
   873 	TEST2(active->iStatus.Int(), KErrNone);
       
   874 
       
   875 	StartBackupL();
       
   876 	DelayL(1000000);
       
   877 	TestLogClosedL();
       
   878 	//
       
   879 	CleanupStack::PopAndDestroy(5); // event, view, filter, active, client
       
   880 	}
       
   881 
       
   882 /**
       
   883 @SYMTestCaseID          SYSLIB-LOGENG-CT-1005
       
   884 @SYMTestCaseDesc	    Tests for view event log
       
   885 @SYMTestPriority 	    High
       
   886 @SYMTestActions  	    Create an event type and add the event to the log.
       
   887                         Close the log and try setting the filter on view twice with an interval of one second.Check for access denied errors.
       
   888 						Repeat the operation after opening the log and check for no error
       
   889 @SYMTestExpectedResults Test must not fail
       
   890 @SYMREQ                 REQ0000
       
   891 */
       
   892 LOCAL_C void TestViewSetup2L()
       
   893  	{
       
   894 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1005 "));
       
   895  	CLogClient* client = CLogClient::NewL(theFs);
       
   896  	CleanupStack::PushL(client);
       
   897  	ForceClientImplInstL(*client);
       
   898  	EndBackupL();
       
   899  
       
   900  	CTestActive* active = new(ELeave)CTestActive();
       
   901  	CleanupStack::PushL(active);
       
   902  
       
   903  	CLogFilter* filter = CLogFilter::NewL();
       
   904  	CleanupStack::PushL(filter);
       
   905  
       
   906  	CLogViewEvent* view = CLogViewEvent::NewL(*client);
       
   907  	CleanupStack::PushL(view);
       
   908  
       
   909  	CLogEvent* event = CLogEvent::NewL();
       
   910  	CleanupStack::PushL(event);
       
   911  	event->SetEventType(KLogCallEventTypeUid);
       
   912  
       
   913  	active->StartL();
       
   914  	client->AddEvent(*event, active->iStatus);
       
   915  	CActiveScheduler::Start();
       
   916  	TEST2(active->iStatus.Int(), KErrNone);
       
   917  
       
   918  	DelayL(1000000);
       
   919  	TEST(view->SetFilterL(*filter, active->iStatus));
       
   920  	active->StartL();
       
   921  	CActiveScheduler::Start();
       
   922  	TEST2(active->iStatus.Int(), KErrNone);
       
   923  
       
   924  	TestLogOpenL();
       
   925  	StartBackupL();
       
   926  	TestLogClosedL();
       
   927  
       
   928  	TRAPD(error, view->SetFilterL(*filter, active->iStatus));
       
   929  	TEST2(error, KErrAccessDenied);
       
   930  
       
   931  	DelayL(1000000);
       
   932  
       
   933  	TRAP(error, view->SetFilterL(*filter, active->iStatus));
       
   934  	TEST2(error, KErrAccessDenied);
       
   935  
       
   936  	EndBackupL();
       
   937  	TestLogOpenL();
       
   938  
       
   939  //	DelayL(1000000);
       
   940  	TEST(view->SetFilterL(*filter, active->iStatus));
       
   941  	active->StartL();
       
   942  	CActiveScheduler::Start();
       
   943  	TEST2(active->iStatus.Int(), KErrNone);
       
   944  
       
   945  	StartBackupL();
       
   946  	DelayL(1000000);
       
   947  	TestLogClosedL();
       
   948  	//
       
   949  	CleanupStack::PopAndDestroy(5); // event, view, filter, active, client
       
   950  	}
       
   951 
       
   952 /**
       
   953 Check that a KLogClientChangeEventRefreshView message is sent if the database is changed
       
   954 during a backup.  This could occur if the database is restored.
       
   955  
       
   956 This was added to test the fix for DEF051602 - Problems with MLogViewChangeObserver when a backup occurs
       
   957 
       
   958 @SYMTestCaseID          SYSLIB-LOGENG-CT-1006
       
   959 @SYMTestCaseDesc	    Check for any problems with MLogViewChangeObserver when a backup occurs
       
   960 @SYMTestPriority 	    High
       
   961 @SYMTestActions  	    Check that a KLogClientChangeEventRefreshView message is sent if the database is changed
       
   962 						during a backup.  This could occur if the database is restored.
       
   963 @SYMTestExpectedResults Test must not fail
       
   964 @SYMREQ                 REQ0000
       
   965 */
       
   966 LOCAL_C void TestRefreshViewL()
       
   967 {
       
   968     test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1006 "));
       
   969 	CLogClient* client = CLogClient::NewL(theFs);
       
   970 	CleanupStack::PushL(client);
       
   971 
       
   972 	// Create a test observer MLogClientChangeObserver
       
   973 	TBool logRefreshViewFlag = EFalse;
       
   974 	TClientObserverTestReceiver testReceiver(logRefreshViewFlag);
       
   975 	client->SetGlobalChangeObserverL(&testReceiver);
       
   976 
       
   977 	// start a backup
       
   978 	TestLogOpenL();
       
   979 	StartBackupL();
       
   980 	DelayL(1000000);
       
   981 	TestLogClosedL();
       
   982 	
       
   983 	// delete the database so a new empty db will be created
       
   984 	// This will cause a KLogClientChangeEventRefreshViewRefresh 
       
   985 	// message to be sent
       
   986 	DeleteLogDatabaseL();
       
   987 
       
   988 	// end the backup
       
   989 	EndBackupL();
       
   990 	DelayL(1000000);
       
   991 	
       
   992 
       
   993 	// check the obsever hs recieved a message
       
   994 	TEST(logRefreshViewFlag);
       
   995 	// 
       
   996 	
       
   997 	CleanupStack::PopAndDestroy(client);
       
   998 }
       
   999 
       
  1000 
       
  1001 #endif//__WINS__
       
  1002 /////////////////////////////////////////////////////////////////////////////////////
       
  1003 /////////////////////////////////////////////////////////////////////////////////////
       
  1004 /////////////////////////////////////////////////////////////////////////////////////
       
  1005 
       
  1006 void doTestsL()
       
  1007 //
       
  1008 //
       
  1009 //
       
  1010 	{
       
  1011 	test.Start(_L("T_LogBackup"));
       
  1012 	TestUtils::Initialize(_L("T_BACKUP"));
       
  1013 	TestUtils::DeleteDatabaseL();
       
  1014 #ifndef __WINS__
       
  1015 	test.Printf(_L("This test harness will only work on WINS\n"));
       
  1016 	User::After(5000000);
       
  1017 #else//__WINS__
       
  1018 	CLogChangeNotifier* notifier = CLogChangeNotifier::NewL();
       
  1019 	CleanupStack::PushL(notifier);
       
  1020 
       
  1021 	test.Next(_L("Locking"));
       
  1022 	TestLockingL();
       
  1023 	theLog.Write(_L8("Test 1 OK\n"));
       
  1024 
       
  1025 	test.Next(_L("Delete client while locked"));
       
  1026 	TestDeleteWhileLockedL();
       
  1027 	theLog.Write(_L8("Test 2 OK\n"));
       
  1028 
       
  1029 	test.Next(_L("Delete view while locked"));
       
  1030 	TestDeleteViewWhileLockedL();
       
  1031 	theLog.Write(_L8("Test 3 OK\n"));
       
  1032 
       
  1033 	test.Next(_L("Multiple clients"));
       
  1034 	TestMultipleClientLockingL();
       
  1035 	theLog.Write(_L8("Test 4 OK\n"));
       
  1036 
       
  1037 	test.Next(_L("Multiple views"));
       
  1038 	TestMultipleViewLockingL();
       
  1039 	theLog.Write(_L8("Test 5 OK\n"));
       
  1040 
       
  1041 	test.Next(_L("Client Requests"));
       
  1042 	TestClientRequestsL();
       
  1043 	theLog.Write(_L8("Test 6 OK\n"));
       
  1044 
       
  1045 	test.Next(_L("View setup"));
       
  1046 	TestViewSetup1L();
       
  1047 	TestViewSetup2L();
       
  1048 	theLog.Write(_L8("Test 7 OK\n"));
       
  1049 
       
  1050 	test.Next(_L("Notifications"));
       
  1051 	TestNotificationsL();
       
  1052 	theLog.Write(_L8("Test 8 OK\n"));
       
  1053 
       
  1054 	test.Next(_L("Request in progress"));
       
  1055 	TestRequestInProgressL();
       
  1056 	theLog.Write(_L8("Test 9 OK\n"));
       
  1057 
       
  1058 	test.Next(_L("View request in progress"));
       
  1059 	TestViewRequestInProgressL();
       
  1060 	theLog.Write(_L8("Test 10 OK\n"));
       
  1061 
       
  1062 	test.Next(_L("Refresh view"));
       
  1063 	TestRefreshViewL();
       
  1064 	theLog.Write(_L8("Test 11 OK\n"));
       
  1065 
       
  1066 	CleanupStack::PopAndDestroy(notifier);
       
  1067 #endif//__WINS__
       
  1068 	}