1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 /* |
2 // All rights reserved. |
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 // This component and the accompanying materials are made available |
3 * All rights reserved. |
4 // under the terms of "Eclipse Public License v1.0" |
4 * This component and the accompanying materials are made available |
5 // which accompanies this distribution, and is available |
5 * under the terms of "Eclipse Public License v1.0" |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 * which accompanies this distribution, and is available |
7 // |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 // Initial Contributors: |
8 * |
9 // Nokia Corporation - initial contribution. |
9 * Initial Contributors: |
10 // |
10 * Nokia Corporation - initial contribution. |
11 // Contributors: |
11 * |
12 // |
12 * Contributors: |
13 // Description: |
13 * |
14 // |
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
15 |
18 |
16 #include "t_currentdb.h" |
19 #include "t_currentdb.h" |
17 |
20 |
18 // System includes |
21 // System includes |
19 #include <e32std.h> |
22 #include <e32std.h> |
47 const TInt KSpeedDialPositionOne = 1; |
50 const TInt KSpeedDialPositionOne = 1; |
48 const TInt KSpeedDialPositionTwo = 2; |
51 const TInt KSpeedDialPositionTwo = 2; |
49 |
52 |
50 const TInt KTestSteps = 100; |
53 const TInt KTestSteps = 100; |
51 |
54 |
52 // |
55 //////////////////////////////////////////////////////////////////////////////////// |
53 // -------> CTestActiveScheduler (header) |
56 // -------> CTestActiveScheduler (header) |
54 // |
57 //////////////////////////////////////////////////////////////////////////////////// |
55 class CTestActiveScheduler : public CActiveScheduler |
58 class CTestActiveScheduler : public CActiveScheduler |
56 { |
59 { |
57 // |
60 //////////////////////////////////////////////////////////////////////////////////// |
58 public: |
61 public: |
59 // |
62 //////////////////////////////////////////////////////////////////////////////////// |
60 void Error (TInt aError) const; |
63 void Error (TInt aError) const; |
61 }; |
64 }; |
62 |
65 |
63 |
66 |
64 // |
67 //////////////////////////////////////////////////////////////////////////////////// |
65 // -------> CTestActiveScheduler (source) |
68 // -------> CTestActiveScheduler (source) |
66 // |
69 //////////////////////////////////////////////////////////////////////////////////// |
67 void CTestActiveScheduler::Error(TInt aError) const |
70 void CTestActiveScheduler::Error(TInt aError) const |
68 { |
71 { |
69 User::Panic(_L("AScheduler"),aError); |
72 User::Panic(_L("AScheduler"),aError); |
70 } |
73 } |
71 |
74 |
72 |
75 |
73 // |
76 //////////////////////////////////////////////////////////////////////////////////// |
74 // -------> CTestBase (source) |
77 // -------> CTestBase (source) |
75 // |
78 //////////////////////////////////////////////////////////////////////////////////// |
76 CTestBase::CTestBase(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
79 CTestBase::CTestBase(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
77 : CActive(aPriority), iTestCoordinator(aTester), iClientNumber(aClientNumber), iThreadPriority(aThreadPriority) |
80 : CActive(aPriority), iTestCoordinator(aTester), iClientNumber(aClientNumber), iThreadPriority(aThreadPriority) |
78 { |
81 { |
79 } |
82 } |
80 |
83 |
89 User::LeaveIfError(iThread.Create(aName, ThreadFunction, KDefaultStackSize, 0x2000, 0x20000, this, EOwnerThread)); |
92 User::LeaveIfError(iThread.Create(aName, ThreadFunction, KDefaultStackSize, 0x2000, 0x20000, this, EOwnerThread)); |
90 iThread.Resume(); |
93 iThread.Resume(); |
91 iThread.SetPriority(iThreadPriority); |
94 iThread.SetPriority(iThreadPriority); |
92 } |
95 } |
93 |
96 |
94 // |
97 //////////////////////////////////////////////////////////////////////////////////// |
95 // |
98 //////////////////////////////////////////////////////////////////////////////////// |
96 // |
99 //////////////////////////////////////////////////////////////////////////////////// |
97 |
100 |
98 void CTestBase::Complete(TInt aReason) |
101 void CTestBase::Complete(TInt aReason) |
99 { |
102 { |
100 // Complete the request with the specified reason. |
103 // Complete the request with the specified reason. |
101 __ASSERT_ALWAYS(IsActive() && iStatus.Int() == KRequestPending, User::Invariant()); |
104 __ASSERT_ALWAYS(IsActive() && iStatus.Int() == KRequestPending, User::Invariant()); |
102 TRequestStatus* status = &iStatus; |
105 TRequestStatus* status = &iStatus; |
103 iThread.RequestComplete(status, aReason); |
106 iThread.RequestComplete(status, aReason); |
104 } |
107 } |
105 |
108 |
106 // |
109 //////////////////////////////////////////////////////////////////////////////////// |
107 // |
110 //////////////////////////////////////////////////////////////////////////////////// |
108 // |
111 //////////////////////////////////////////////////////////////////////////////////// |
109 |
112 |
110 void CTestBase::RunL() |
113 void CTestBase::RunL() |
111 { |
114 { |
112 _LIT(KThreadTestCompleteFormat, "Thread %d finished tests"); |
115 _LIT(KThreadTestCompleteFormat, "Thread %d finished tests"); |
113 |
116 |
161 { |
164 { |
162 Complete(KErrCancel); |
165 Complete(KErrCancel); |
163 } |
166 } |
164 } |
167 } |
165 |
168 |
166 // |
169 //////////////////////////////////////////////////////////////////////////////////// |
167 // |
170 //////////////////////////////////////////////////////////////////////////////////// |
168 // |
171 //////////////////////////////////////////////////////////////////////////////////// |
169 |
172 |
170 TInt CTestBase::ThreadFunction(TAny* aParam) |
173 TInt CTestBase::ThreadFunction(TAny* aParam) |
171 { |
174 { |
172 CTestBase* self = STATIC_CAST(CTestBase*, aParam); |
175 CTestBase* self = STATIC_CAST(CTestBase*, aParam); |
173 |
176 |
239 void CTestBase::HandleThreadDeletionL() |
242 void CTestBase::HandleThreadDeletionL() |
240 { |
243 { |
241 iContactsTest->EndTestLib(KErrNone); |
244 iContactsTest->EndTestLib(KErrNone); |
242 } |
245 } |
243 |
246 |
244 // |
247 //////////////////////////////////////////////////////////////////////////////////// |
245 // |
248 //////////////////////////////////////////////////////////////////////////////////// |
246 // |
249 //////////////////////////////////////////////////////////////////////////////////// |
247 |
250 |
248 void CTestBase::ReadyForNextTest() |
251 void CTestBase::ReadyForNextTest() |
249 // |
252 // |
250 // Requests another test be executed |
253 // Requests another test be executed |
251 // |
254 // |
399 iSemaphoreOne.Close(); |
402 iSemaphoreOne.Close(); |
400 iSemaphoreTwo.Close(); |
403 iSemaphoreTwo.Close(); |
401 } |
404 } |
402 |
405 |
403 |
406 |
404 // |
407 //////////////////////////////////////////////////////////////////////////////////// |
405 // -------> CTestThreadOne (source) |
408 // -------> CTestThreadOne (source) |
406 // |
409 //////////////////////////////////////////////////////////////////////////////////// |
407 CTestThreadOne::CTestThreadOne(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
410 CTestThreadOne::CTestThreadOne(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
408 : CTestBase(aTester, aClientNumber, aThreadPriority, aPriority) |
411 : CTestBase(aTester, aClientNumber, aThreadPriority, aPriority) |
409 { |
412 { |
410 } |
413 } |
411 |
414 |
424 buf.Format(_L("Constructing test utilities with database set as %S"), &KTestDatabaseFile); |
427 buf.Format(_L("Constructing test utilities with database set as %S"), &KTestDatabaseFile); |
425 iTest->Next(buf); |
428 iTest->Next(buf); |
426 iContactsTest->ConstructL(*iTest, KTestDatabaseFile); |
429 iContactsTest->ConstructL(*iTest, KTestDatabaseFile); |
427 } |
430 } |
428 |
431 |
429 // |
432 //////////////////////////////////////////////////////////////////////////////////// |
430 // |
433 //////////////////////////////////////////////////////////////////////////////////// |
431 // |
434 //////////////////////////////////////////////////////////////////////////////////// |
432 |
435 |
433 void CTestThreadOne::DoTestL(TInt aTestNumber) |
436 void CTestThreadOne::DoTestL(TInt aTestNumber) |
434 { |
437 { |
435 TBuf<50> buf; |
438 TBuf<50> buf; |
436 buf.Format(KThreadTestFormat, iClientNumber, aTestNumber); |
439 buf.Format(KThreadTestFormat, iClientNumber, aTestNumber); |
468 default: |
471 default: |
469 User::Invariant(); |
472 User::Invariant(); |
470 } |
473 } |
471 } |
474 } |
472 |
475 |
473 // |
476 //////////////////////////////////////////////////////////////////////////////////// |
474 // |
477 //////////////////////////////////////////////////////////////////////////////////// |
475 // |
478 //////////////////////////////////////////////////////////////////////////////////// |
476 |
479 |
477 void CTestThreadOne::DoTest1L() |
480 void CTestThreadOne::DoTest1L() |
478 { |
481 { |
479 // This thread has a higher priority than thread 2 so it should run first, |
482 // This thread has a higher priority than thread 2 so it should run first, |
480 // hence this test should work. |
483 // hence this test should work. |
941 iSemaphoreTwo.Signal(); |
944 iSemaphoreTwo.Signal(); |
942 |
945 |
943 iContactsTest->CloseDatabase(); |
946 iContactsTest->CloseDatabase(); |
944 } |
947 } |
945 |
948 |
946 // |
949 //////////////////////////////////////////////////////////////////////////////////// |
947 // -------> CTestThreadTwo (source) |
950 // -------> CTestThreadTwo (source) |
948 // |
951 //////////////////////////////////////////////////////////////////////////////////// |
949 CTestThreadTwo::CTestThreadTwo(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
952 CTestThreadTwo::CTestThreadTwo(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
950 : CTestBase(aTester, aClientNumber, aThreadPriority, aPriority) |
953 : CTestBase(aTester, aClientNumber, aThreadPriority, aPriority) |
951 { |
954 { |
952 } |
955 } |
953 |
956 |
966 buf.Format(_L("Constructing test utilities with database set as %S"), &KTestDatabaseFile); |
969 buf.Format(_L("Constructing test utilities with database set as %S"), &KTestDatabaseFile); |
967 iTest->Next(buf); |
970 iTest->Next(buf); |
968 iContactsTest->ConstructL(*iTest, KTestDatabaseFile2); |
971 iContactsTest->ConstructL(*iTest, KTestDatabaseFile2); |
969 } |
972 } |
970 |
973 |
971 // |
974 //////////////////////////////////////////////////////////////////////////////////// |
972 // |
975 //////////////////////////////////////////////////////////////////////////////////// |
973 // |
976 //////////////////////////////////////////////////////////////////////////////////// |
974 |
977 |
975 void CTestThreadTwo::DoTestL(TInt aTestNumber) |
978 void CTestThreadTwo::DoTestL(TInt aTestNumber) |
976 { |
979 { |
977 TBuf<50> buf; |
980 TBuf<50> buf; |
978 buf.Format(KThreadTestFormat, iClientNumber, aTestNumber); |
981 buf.Format(KThreadTestFormat, iClientNumber, aTestNumber); |
1010 default: |
1013 default: |
1011 User::Invariant(); |
1014 User::Invariant(); |
1012 } |
1015 } |
1013 } |
1016 } |
1014 |
1017 |
1015 // |
1018 //////////////////////////////////////////////////////////////////////////////////// |
1016 // |
1019 //////////////////////////////////////////////////////////////////////////////////// |
1017 // |
1020 //////////////////////////////////////////////////////////////////////////////////// |
1018 |
1021 |
1019 void CTestThreadTwo::DoTest1L() |
1022 void CTestThreadTwo::DoTest1L() |
1020 { |
1023 { |
1021 iSemaphoreOne.Signal(); |
1024 iSemaphoreOne.Signal(); |
1022 // This thread has a lower priority than thread 1 so it should run second, |
1025 // This thread has a lower priority than thread 1 so it should run second, |
1420 iSemaphoreOne.Signal(); |
1423 iSemaphoreOne.Signal(); |
1421 |
1424 |
1422 CleanupStack::PopAndDestroy(2); // threadOneDb, changeNotifier |
1425 CleanupStack::PopAndDestroy(2); // threadOneDb, changeNotifier |
1423 } |
1426 } |
1424 |
1427 |
1425 // |
1428 //////////////////////////////////////////////////////////////////////////////////// |
1426 // -------> CTestManager (source) |
1429 // -------> CTestManager (source) |
1427 // |
1430 //////////////////////////////////////////////////////////////////////////////////// |
1428 CTestManager::CTestManager(TInt aPriority) |
1431 CTestManager::CTestManager(TInt aPriority) |
1429 : CTimer(aPriority) |
1432 : CTimer(aPriority) |
1430 { |
1433 { |
1431 CActiveScheduler::Add(this); |
1434 CActiveScheduler::Add(this); |
1432 } |
1435 } |
1462 CleanupStack::PushL(self); |
1465 CleanupStack::PushL(self); |
1463 self->ConstructL(); |
1466 self->ConstructL(); |
1464 return self; |
1467 return self; |
1465 } |
1468 } |
1466 |
1469 |
1467 // |
1470 //////////////////////////////////////////////////////////////////////////////////// |
1468 // |
1471 //////////////////////////////////////////////////////////////////////////////////// |
1469 // |
1472 //////////////////////////////////////////////////////////////////////////////////// |
1470 |
1473 |
1471 void CTestManager::RunL() |
1474 void CTestManager::RunL() |
1472 { |
1475 { |
1473 if ( iClient1->IsActive() && iClient2->IsActive() |
1476 if ( iClient1->IsActive() && iClient2->IsActive() |
1474 && iClient1->CurrentTest() == iClient2->CurrentTest() |
1477 && iClient1->CurrentTest() == iClient2->CurrentTest() |
1514 |
1517 |
1515 // Re-issue the asynchronous request to the CTimer |
1518 // Re-issue the asynchronous request to the CTimer |
1516 IssueTimerRequest(); |
1519 IssueTimerRequest(); |
1517 } |
1520 } |
1518 |
1521 |
1519 // |
1522 //////////////////////////////////////////////////////////////////////////////////// |
1520 // |
1523 //////////////////////////////////////////////////////////////////////////////////// |
1521 // |
1524 //////////////////////////////////////////////////////////////////////////////////// |
1522 |
1525 |
1523 void CTestManager::IssueTimerRequest() |
1526 void CTestManager::IssueTimerRequest() |
1524 { |
1527 { |
1525 const TInt KOneSecond = 1000000; |
1528 const TInt KOneSecond = 1000000; |
1526 After(KOneSecond); |
1529 After(KOneSecond); |
1527 } |
1530 } |
1528 |
1531 |
1529 |
1532 |
1530 // |
1533 //////////////////////////////////////////////////////////////////////////////////// |
1531 // -------> Static global functions (source) |
1534 // -------> Static global functions (source) |
1532 // |
1535 //////////////////////////////////////////////////////////////////////////////////// |
1533 static void doMainL() |
1536 static void doMainL() |
1534 { |
1537 { |
1535 CTestActiveScheduler* scheduler = new (ELeave) CTestActiveScheduler; |
1538 CTestActiveScheduler* scheduler = new (ELeave) CTestActiveScheduler; |
1536 CleanupStack::PushL(scheduler); |
1539 CleanupStack::PushL(scheduler); |
1537 CActiveScheduler::Install(scheduler); |
1540 CActiveScheduler::Install(scheduler); |