Update contrib.
1 // Copyright (c) 2002-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "t_logutil2.h"
21 RTest TheTest(_L("t_logbench"));
25 _LIT(KTestString, "%dabcdefghijklmnopqrstuvwxyz");
26 _LIT(KResultFile, "C:\\LOGENG_TEST.TXT");
28 const TInt KLogSize = 50;
29 const TInt KTestFactor = 2;
31 // Class used to record test details
45 LOCAL_C TInt GetHeapSizeL()
48 heap = User::Heap().Size();
53 LOCAL_C TInt GetServerHeapSizeL()
55 return 1024 * 1024;//By default - the process heap is 1M.
58 LOCAL_C TInt DatabaseSizeL()
60 return TestUtils::DatabaseSizeL();
64 @SYMTestCaseID SYSLIB-LOGENG-CT-0988
65 @SYMTestCaseDesc Sets the configuration setup for the tests
67 @SYMTestActions Setup for the environment for the tests
68 @SYMTestExpectedResults Test must not fail
71 LOCAL_C void TestSetupL(CLogClient& aClient)
73 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0988 "));
74 CTestActive* active = new(ELeave)CTestActive;
75 CleanupStack::PushL(active);
78 aClient.GetConfig(theConfig, active->iStatus);
80 CActiveScheduler::Start();
81 TEST2(active->iStatus.Int(), KErrNone);
83 TheTest.Printf(_L(" Log size: %d\n"), theConfig.iMaxLogSize);
84 TheTest.Printf(_L(" Recent list size: %d\n"), theConfig.iMaxRecentLogSize);
85 TheTest.Printf(_L(" Max Event Age: %d\n"), theConfig.iMaxEventAge);
87 TestUtils::DeleteDatabaseL();
90 aClient.GetConfig(theConfig, active->iStatus);
92 CActiveScheduler::Start();
93 TEST2(active->iStatus.Int(), KErrNone);
95 // Wait for user interation
96 //TheTest.Printf(_L(" Quick tests performed if no key pressed in next 10 seconds\n"));
98 //if (!TestUtils::WaitForKeyL(10000000, key))
100 theConfig.iMaxLogSize = KLogSize;
102 // Set configuration in database
103 aClient.ChangeConfig(theConfig, active->iStatus);
105 CActiveScheduler::Start();
106 TEST2(active->iStatus.Int(), KErrNone);
109 CleanupStack::PopAndDestroy(); // active
113 @SYMTestCaseID SYSLIB-LOGENG-CT-0989
114 @SYMTestCaseDesc Benchmark test
115 Tests for writing the log details to a file
116 @SYMTestPriority High
117 @SYMTestActions Add events to the log and write the configuration details to a file
118 @SYMTestExpectedResults Test must not fail
121 LOCAL_C void BenchmarkTestL(CLogClient& aClient, RFile& aFile)
123 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0989 "));
124 CTestActive* active = new(ELeave)CTestActive;
125 CleanupStack::PushL(active);
127 CLogViewEvent* view = CLogViewEvent::NewL(aClient);
128 CleanupStack::PushL(view);
130 CLogFilter* filter = CLogFilter::NewL();
131 CleanupStack::PushL(filter);
133 CLogEvent* event = CLogEvent::NewL();
134 CleanupStack::PushL(event);
135 event->SetEventType(KLogCallEventTypeUid);
137 aFile.Write(_L8("Adding Events\n"));
143 string.Format(KTestString, count);
145 while(count++ < theConfig.iMaxLogSize * KTestFactor)
147 event->SetRemoteParty(string);
148 event->SetSubject(string);
149 event->SetNumber(string);
150 event->SetStatus(string);
153 string.Format(KTestString, count);
156 before.UniversalTime();
159 aClient.AddEvent(*event, active->iStatus);
161 CActiveScheduler::Start();
162 TEST2(active->iStatus.Int(), KErrNone);
165 after.UniversalTime();
166 TTimeIntervalMicroSeconds interval = after.MicroSecondsFrom(before);
168 TInt dbSize = DatabaseSizeL();
169 TInt heapSize = GetHeapSizeL();
170 TInt serverHeapSize = GetServerHeapSizeL();
172 // Store details in file
173 TheTest.Printf(_L(" Num: %d, Time: %d, Db Size: %d, Hs: %d, Server Hs: %d\n"), count, I64INT(interval.Int64()), dbSize, heapSize, serverHeapSize);
174 buf.Format(_L8("%d,%d,%d,%d,%d\n"), count, I64INT(interval.Int64()), dbSize, heapSize, serverHeapSize);
178 aFile.Write(_L8("Navigating View\n"));
182 TEST(view->SetFilterL(*filter, active->iStatus));
184 CActiveScheduler::Start();
185 TEST2(active->iStatus.Int(), KErrNone);
187 while(view->NextL(active->iStatus))
190 before.UniversalTime();
193 CActiveScheduler::Start();
194 TEST2(active->iStatus.Int(), KErrNone);
197 after.UniversalTime();
198 TTimeIntervalMicroSeconds interval = after.MicroSecondsFrom(before);
200 TInt heapSize = GetHeapSizeL();
201 TInt serverHeapSize = GetServerHeapSizeL();
203 // Store details in file
204 TheTest.Printf(_L(" Count: %d, Time: %d, Hs: %d, Server Hs: %d\n"), count, I64INT(interval.Int64()), heapSize, serverHeapSize);
205 buf.Format(_L8("%d,%d,%d,%d\n"), count++, I64INT(interval.Int64()), heapSize, serverHeapSize);
209 CleanupStack::PopAndDestroy(4); // event, filter, view, active
213 @SYMTestCaseID SYSLIB-LOGENG-CT-0990
214 @SYMTestCaseDesc Tests for CLogViewRecent::SetRecentListL(),CLogViewRecent::DuplicatesL() functions
215 @SYMTestPriority High
216 @SYMTestActions Set the recent log view list and refresh for the duplicates view.
217 Check for ErrNone flag
218 @SYMTestExpectedResults Test must not fail
221 LOCAL_C void DoTestRecentViewsL(CLogClient& aClient, TLogRecentList aList, TInt aRecentCount, TInt aDuplicateCount)
223 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0990 "));
224 CTestActive* active = new(ELeave)CTestActive();
225 CleanupStack::PushL(active);
227 CLogViewRecent* recent = CLogViewRecent::NewL(aClient);
228 CleanupStack::PushL(recent);
230 CLogViewDuplicate* duplicate = CLogViewDuplicate::NewL(aClient);
231 CleanupStack::PushL(duplicate);
233 TEST(recent->SetRecentListL(aList, active->iStatus) || aRecentCount == 0);
236 if (aRecentCount == 0)
240 CActiveScheduler::Start();
241 TEST2(active->iStatus.Int(), KErrNone);
243 TEST(recent->DuplicatesL(*duplicate, active->iStatus) || aDuplicateCount == 0);
246 if (aDuplicateCount == 0)
250 CActiveScheduler::Start();
251 TEST2(active->iStatus.Int(), KErrNone);
253 while(duplicate->NextL(active->iStatus));
254 TEST(duplicate->CountL() == aDuplicateCount);
256 while(recent->NextL(active->iStatus));
257 TEST(recent->CountL() == aRecentCount);
259 CleanupStack::PopAndDestroy(3); // active, recent, duplicate
263 @SYMTestCaseID SYSLIB-LOGENG-CT-0991
264 @SYMTestCaseDesc Tests to clear the duplicates in a view
265 Tests CLogViewRecent::ClearDuplicatesL() function
266 @SYMTestPriority High
267 @SYMTestActions Set the recent log view list.Check for ErrNone flag.
268 Write the details to a file.
269 @SYMTestExpectedResults Test must not fail
272 LOCAL_C void DoTestClearDuplicateL(CLogClient& aClient, TLogRecentList aList, RFile& aFile)
274 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0991 "));
275 CTestActive* active = new(ELeave)CTestActive();
276 CleanupStack::PushL(active);
278 CLogViewRecent* recent = CLogViewRecent::NewL(aClient);
279 CleanupStack::PushL(recent);
282 before.UniversalTime();
284 recent->SetRecentListL(aList, active->iStatus);
286 CActiveScheduler::Start();
287 TEST2(active->iStatus.Int(), KErrNone);
288 recent->ClearDuplicatesL();
291 after.UniversalTime();
292 TTimeIntervalMicroSeconds interval = after.MicroSecondsFrom(before);
295 TheTest.Printf(_L("Clearing Duplicates for List %d, %d\n"), recent->RecentList(), I64INT(interval.Int64()));
296 buf.Format(_L8("Clearing Duplicates for List %d, %d\n"), recent->RecentList(), I64INT(interval.Int64()));
299 CleanupStack::PopAndDestroy(2); // recent, active
303 @SYMTestCaseID SYSLIB-LOGENG-CT-0992
304 @SYMTestCaseDesc Recent lists view test
305 @SYMTestPriority High
306 @SYMTestActions Add the events to the log and execute the test functions.
307 @SYMTestExpectedResults Test must not fail
310 LOCAL_C void TestRecentListsL(CLogClient& aClient, RFile& aFile)
312 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0992 "));
313 aFile.Write(_L8("Recent Lists\n"));
315 CTestActive* active = new(ELeave)CTestActive();
316 CleanupStack::PushL(active);
320 aClient.GetConfig(config, active->iStatus);
321 CActiveScheduler::Start();
322 TEST2(active->iStatus.Int(), KErrNone);
324 CLogEvent* event = CLogEvent::NewL();
325 CleanupStack::PushL(event);
326 event->SetEventType(KLogCallEventTypeUid);
328 for(TInt duplicates = 0; duplicates < 10; duplicates++)
331 before.UniversalTime();
335 aClient.GetString(incoming, R_LOG_DIR_IN);
336 event->SetDirection(incoming);
339 for(count = 0; count < config.iMaxRecentLogSize; count++)
343 event->SetNumber(number);
346 aClient.AddEvent(*event, active->iStatus);
347 CActiveScheduler::Start();
348 TEST2(active->iStatus.Int(), KErrNone);
353 aClient.GetString(outgoing, R_LOG_DIR_OUT);
354 event->SetDirection(outgoing);
356 for(count = 0; count < config.iMaxRecentLogSize; count++)
360 event->SetNumber(number);
363 aClient.AddEvent(*event, active->iStatus);
364 CActiveScheduler::Start();
365 TEST2(active->iStatus.Int(), KErrNone);
370 aClient.GetString(missed, R_LOG_DIR_MISSED);
371 event->SetDirection(missed);
373 for(count = 0; count < config.iMaxRecentLogSize; count++)
377 event->SetNumber(number);
380 aClient.AddEvent(*event, active->iStatus);
381 CActiveScheduler::Start();
382 TEST2(active->iStatus.Int(), KErrNone);
386 afterAdd.UniversalTime();
388 DoTestRecentViewsL(aClient, KLogRecentIncomingCalls, config.iMaxRecentLogSize, duplicates);
389 DoTestRecentViewsL(aClient, KLogRecentOutgoingCalls, config.iMaxRecentLogSize, duplicates);
390 DoTestRecentViewsL(aClient, KLogRecentMissedCalls, config.iMaxRecentLogSize, duplicates);
393 afterNav.UniversalTime();
395 TTimeIntervalMicroSeconds interval1 = afterAdd.MicroSecondsFrom(before);
396 TTimeIntervalMicroSeconds interval2 = afterNav.MicroSecondsFrom(afterAdd);
398 // Store details in file
400 TheTest.Printf(_L(" Count: %d, Add: %d, Nav: %d\n"), duplicates, I64INT(interval1.Int64()), I64INT(interval2.Int64()));
401 buf.Format(_L8("%d,%d,%d\n"), duplicates, I64INT(interval1.Int64()), I64INT(interval2.Int64()));
405 DoTestClearDuplicateL(aClient, KLogRecentIncomingCalls, aFile);
406 DoTestClearDuplicateL(aClient, KLogRecentOutgoingCalls, aFile);
407 DoTestClearDuplicateL(aClient, KLogRecentMissedCalls, aFile);
409 CleanupStack::PopAndDestroy(2); // active, event
415 TestUtils::Initialize(_L("t_logbench"));
417 CLogChangeNotifier* notifier = CLogChangeNotifier::NewL();
418 CleanupStack::PushL(notifier);
420 CLogClient* client = CLogClient::NewL(theFs);
421 CleanupStack::PushL(client);
423 CTestActive* active = new(ELeave)CTestActive();
424 CleanupStack::PushL(active);
427 client->GetConfig(config, active->iStatus);
429 CActiveScheduler::Start();
430 TEST2(active->iStatus.Int(), KErrNone);
432 TheTest.Start(_L("Setup"));
434 theLog.Write(_L8("Test 1 OK\n"));
437 LEAVE_IF_ERROR(results.Replace(theFs, KResultFile, EFileWrite|EFileShareExclusive));
439 TheTest.Next(_L("Benchmark tests"));
440 BenchmarkTestL(*client, results);
441 theLog.Write(_L8("Test 2 OK\n"));
443 TestUtils::DeleteDatabaseL();
445 TheTest.Next(_L("Recent List tests"));
446 TestRecentListsL(*client, results);
447 theLog.Write(_L8("Test 3 OK\n"));
450 client->ChangeConfig(config, active->iStatus);
452 CActiveScheduler::Start();
453 TEST2(active->iStatus.Int(), KErrNone);
456 CleanupStack::PopAndDestroy(3); // active, notifier, client;