|
1 // Copyright (c) 2007-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 the License "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 // testengine.cpp |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32std_private.h> |
|
22 #include <u32std.h> // unicode builds |
|
23 #include <e32base.h> |
|
24 #include <e32base_private.h> |
|
25 #include <e32cons.h> |
|
26 #include <e32Test.h> // RTest headder |
|
27 #include <e32def.h> |
|
28 #include <e32def_private.h> |
|
29 #include "testcaseroot.h" |
|
30 #include "testcasecontroller.h" |
|
31 #include "testengine.h" |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole) |
|
37 { |
|
38 CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole) |
|
47 : CActive(EPriorityStandard), |
|
48 iTestEngine(aTestEngine), |
|
49 iHostRole(aHostRole) |
|
50 { |
|
51 // Add to current threads active scheduler |
|
52 CActiveScheduler::Add(this); |
|
53 } |
|
54 |
|
55 |
|
56 CTestCaseController::~CTestCaseController() |
|
57 { |
|
58 // Cancel any outstanding test cases |
|
59 Cancel(); |
|
60 delete iTestPolicy; |
|
61 } |
|
62 |
|
63 |
|
64 void CTestCaseController::ConstructL() |
|
65 { |
|
66 TInt err(KErrNone); |
|
67 |
|
68 iTestPolicy = CBasicTestPolicy::NewL(); |
|
69 |
|
70 err = iTestEngine.NextTestCaseId(iTestCaseId); |
|
71 if (err != KErrNone) |
|
72 User::Leave(-2); |
|
73 |
|
74 test.Next(iTestCaseId); |
|
75 // pass control to the test-policy (which merely instantiates and runs the test) |
|
76 iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus); |
|
77 SetActive(); // when the 1st test finnishes, we drop into our own RunL active processing loop |
|
78 } |
|
79 |
|
80 |
|
81 void CTestCaseController::DoCancel() |
|
82 { |
|
83 // Cancel the outstanding test case running |
|
84 iTestPolicy->Cancel(); |
|
85 } |
|
86 |
|
87 |
|
88 void CTestCaseController::RunL() |
|
89 { |
|
90 // Retrieve the completion code of the last test case run |
|
91 TInt err(iStatus.Int()); |
|
92 |
|
93 if (err != KErrNone) |
|
94 { |
|
95 test.Printf(_L("<Error> Test case %lS failed\n"),&iTestCaseId); |
|
96 } |
|
97 else |
|
98 { |
|
99 test.Printf(_L("Test case %lS passed\n"),&iTestCaseId); |
|
100 } |
|
101 |
|
102 // Find next test to run |
|
103 err = iTestEngine.NextTestCaseId(iTestCaseId); |
|
104 if (err == KErrNone) |
|
105 { |
|
106 test.Printf(_L("\n")); // ensures blank line between tests |
|
107 test.Printf(_L("\n")); |
|
108 test.Next(iTestCaseId); |
|
109 |
|
110 // run the next test here |
|
111 iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus); |
|
112 SetActive(); |
|
113 } |
|
114 else if (err == KErrNotFound) |
|
115 { |
|
116 RDebug::Printf("All specified test cases performed"); |
|
117 CActiveScheduler::Stop(); |
|
118 } |
|
119 else |
|
120 { |
|
121 RDebug::Printf("<Error %d> Unknown error from CTestEngine::NextTestCaseId",err); |
|
122 User::Leave(err); |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 TInt CTestCaseController::RunError(TInt aError) |
|
128 { |
|
129 LOG_FUNC |
|
130 switch (aError) |
|
131 { |
|
132 case KErrNoMemory: |
|
133 default: |
|
134 // Panic the test module |
|
135 test(EFalse); |
|
136 break; |
|
137 } |
|
138 return KErrNone; |
|
139 } |
|
140 |
|
141 |
|
142 |