sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// @file testcasecontroller.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "basetestcase.h"
|
sl@0
|
20 |
#include "testcasecontroller.h"
|
sl@0
|
21 |
#include "testcasefactory.h"
|
sl@0
|
22 |
#include "testengine.h"
|
sl@0
|
23 |
#include "testpolicy.h"
|
sl@0
|
24 |
#include "testdebug.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
_LIT(KClientDeviceDriverName,"EUSBC");
|
sl@0
|
27 |
_LIT(KHostDeviceDriverName,"usbhubdriver");
|
sl@0
|
28 |
_LIT(KHostDeviceInterfaceDriverName,"usbdi");
|
sl@0
|
29 |
_LIT(KOtgdiLddFileName, "otgdi");
|
sl@0
|
30 |
|
sl@0
|
31 |
namespace NUnitTesting_USBDI
|
sl@0
|
32 |
{
|
sl@0
|
33 |
|
sl@0
|
34 |
CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole);
|
sl@0
|
37 |
CleanupStack::PushL(self);
|
sl@0
|
38 |
self->ConstructL();
|
sl@0
|
39 |
CleanupStack::Pop(self);
|
sl@0
|
40 |
return self;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole)
|
sl@0
|
45 |
: CActive(EPriorityStandard),
|
sl@0
|
46 |
iTestEngine(aTestEngine),
|
sl@0
|
47 |
iHostRole(aHostRole)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
// Add to current threads active scheduler
|
sl@0
|
50 |
CActiveScheduler::Add(this);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
CTestCaseController::~CTestCaseController()
|
sl@0
|
55 |
{
|
sl@0
|
56 |
LOG_FUNC
|
sl@0
|
57 |
|
sl@0
|
58 |
Cancel(); // Cancels any oustanding test cases
|
sl@0
|
59 |
|
sl@0
|
60 |
delete iTestPolicy;
|
sl@0
|
61 |
|
sl@0
|
62 |
if(iHostRole)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
TInt err = User::FreeLogicalDevice(KHostDeviceInterfaceDriverName);
|
sl@0
|
65 |
if(err != KErrNone)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceInterfaceDriverName);
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
err = User::FreeLogicalDevice(KHostDeviceDriverName);
|
sl@0
|
71 |
if(err != KErrNone)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceDriverName);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
err = User::FreeLogicalDevice(KOtgdiLddFileName);
|
sl@0
|
77 |
if(err != KErrNone)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceDriverName);
|
sl@0
|
80 |
}
|
sl@0
|
81 |
}
|
sl@0
|
82 |
else
|
sl@0
|
83 |
{
|
sl@0
|
84 |
TInt err(User::FreeLogicalDevice(KClientDeviceDriverName));
|
sl@0
|
85 |
if(err != KErrNone)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KClientDeviceDriverName);
|
sl@0
|
88 |
}
|
sl@0
|
89 |
}
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
void CTestCaseController::ConstructL()
|
sl@0
|
93 |
{
|
sl@0
|
94 |
LOG_FUNC
|
sl@0
|
95 |
TInt err = KErrNone;
|
sl@0
|
96 |
|
sl@0
|
97 |
_LIT(KLoadingNamedDriverString,"loading driver: %S\n");
|
sl@0
|
98 |
_LIT(KLoadedNamedDriverString,"loaded driver: %S\n");
|
sl@0
|
99 |
|
sl@0
|
100 |
// loading drivers
|
sl@0
|
101 |
if(iHostRole)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
gtest.Printf(KLoadingNamedDriverString,&KHostDeviceDriverName);
|
sl@0
|
104 |
// Load both Host USB device drivers
|
sl@0
|
105 |
err = User::LoadLogicalDevice(KHostDeviceDriverName);
|
sl@0
|
106 |
gtest((err == KErrNone) || (err == KErrAlreadyExists));
|
sl@0
|
107 |
gtest.Printf(KLoadedNamedDriverString,&KHostDeviceDriverName);
|
sl@0
|
108 |
|
sl@0
|
109 |
RDebug::Print(KLoadingNamedDriverString,&KHostDeviceInterfaceDriverName);
|
sl@0
|
110 |
err = User::LoadLogicalDevice(KHostDeviceInterfaceDriverName);
|
sl@0
|
111 |
gtest((err == KErrNone) || (err == KErrAlreadyExists));
|
sl@0
|
112 |
gtest.Printf(KLoadedNamedDriverString,&KHostDeviceInterfaceDriverName);
|
sl@0
|
113 |
|
sl@0
|
114 |
// If test cases are running USB host side actions
|
sl@0
|
115 |
// then run each test case in its own thread
|
sl@0
|
116 |
iTestPolicy = CThreadTestPolicy::NewL();
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
{
|
sl@0
|
120 |
|
sl@0
|
121 |
// Load the USB client driver
|
sl@0
|
122 |
gtest.Printf(KLoadingNamedDriverString,&KClientDeviceDriverName);
|
sl@0
|
123 |
err = User::LoadLogicalDevice(KClientDeviceDriverName);
|
sl@0
|
124 |
gtest((err == KErrNone) || (err == KErrAlreadyExists));
|
sl@0
|
125 |
gtest.Printf(KLoadedNamedDriverString,&KClientDeviceDriverName);
|
sl@0
|
126 |
|
sl@0
|
127 |
// Run each test case in the main thread as its not new API
|
sl@0
|
128 |
// and not expected to panic
|
sl@0
|
129 |
iTestPolicy = CBasicTestPolicy::NewL();
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
// Get the identity of the next test case to run
|
sl@0
|
133 |
err = iTestEngine.NextTestCaseId(iTestCaseId);
|
sl@0
|
134 |
gtest.Next(iTestCaseId);
|
sl@0
|
135 |
|
sl@0
|
136 |
// Run the test case
|
sl@0
|
137 |
iTestPolicy->RunTestCaseL(iTestCaseId,iStatus);
|
sl@0
|
138 |
SetActive();
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
|
sl@0
|
142 |
void CTestCaseController::DoCancel()
|
sl@0
|
143 |
{
|
sl@0
|
144 |
// Cancel the outstanding test case running
|
sl@0
|
145 |
|
sl@0
|
146 |
iTestPolicy->Cancel();
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
void CTestCaseController::RunL()
|
sl@0
|
151 |
{
|
sl@0
|
152 |
LOG_FUNC
|
sl@0
|
153 |
|
sl@0
|
154 |
// Retrieve the completion code of the last test case run
|
sl@0
|
155 |
TInt err(iStatus.Int());
|
sl@0
|
156 |
|
sl@0
|
157 |
TBuf<64> log;
|
sl@0
|
158 |
if(err != KErrNone)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
iTestCasesResults.Append(EFalse);
|
sl@0
|
161 |
gtest.Printf(_L("FAILED err=%d\n"),err);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
else
|
sl@0
|
164 |
{
|
sl@0
|
165 |
iTestCasesResults.Append(ETrue);
|
sl@0
|
166 |
gtest.Printf(_L("PASSED\n"));
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
// Get the identity of the next test case to run
|
sl@0
|
170 |
|
sl@0
|
171 |
err = iTestEngine.NextTestCaseId(iTestCaseId);
|
sl@0
|
172 |
if(err == KErrNone)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
RDebug::Printf("\n");
|
sl@0
|
175 |
RDebug::Printf("\n");
|
sl@0
|
176 |
RDebug::Printf("\n");
|
sl@0
|
177 |
gtest.Next(iTestCaseId);
|
sl@0
|
178 |
RDebug::Printf(" --------------------");
|
sl@0
|
179 |
RDebug::Printf("\n");
|
sl@0
|
180 |
RDebug::Printf("\n");
|
sl@0
|
181 |
RDebug::Printf("\n");
|
sl@0
|
182 |
|
sl@0
|
183 |
// Run the next test case
|
sl@0
|
184 |
|
sl@0
|
185 |
iTestPolicy->RunTestCaseL(iTestCaseId,iStatus);
|
sl@0
|
186 |
SetActive();
|
sl@0
|
187 |
}
|
sl@0
|
188 |
else if(err == KErrNotFound)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
RDebug::Printf("All specified test cases performed");
|
sl@0
|
191 |
RDebug::Printf("----------------------------------");
|
sl@0
|
192 |
|
sl@0
|
193 |
|
sl@0
|
194 |
// count nb failures
|
sl@0
|
195 |
TUint nbFailures = 0;
|
sl@0
|
196 |
for(TInt test = 0; test < iTestCasesResults.Count() ; test++)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
if(!iTestCasesResults[test])
|
sl@0
|
199 |
//NB iTestCasesResults is a boolean array added to each time a test is run...
|
sl@0
|
200 |
// ...even if it is a repeat.
|
sl@0
|
201 |
{
|
sl@0
|
202 |
nbFailures++;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
}
|
sl@0
|
205 |
RDebug::Printf("There are %d test case results, %d failures", iTestCasesResults.Count(), nbFailures);
|
sl@0
|
206 |
|
sl@0
|
207 |
// Number of tests that should have been run (including repeats)
|
sl@0
|
208 |
TUint nbTests = iTestEngine.TestCasesIdentities().Count() * iTestEngine.NumRepeats();
|
sl@0
|
209 |
if(nbTests!=iTestCasesResults.Count())
|
sl@0
|
210 |
{
|
sl@0
|
211 |
RDebug::Printf("The number of tests that should have been run (%d) DOES NOT EQUAL the actual number of tests run (%d).",
|
sl@0
|
212 |
nbTests, iTestCasesResults.Count());
|
sl@0
|
213 |
RDebug::Printf("This test suite will now PANIC!");
|
sl@0
|
214 |
}
|
sl@0
|
215 |
ASSERT((nbTests==iTestCasesResults.Count()));
|
sl@0
|
216 |
|
sl@0
|
217 |
|
sl@0
|
218 |
for(TInt repeat = 0; repeat < iTestEngine.NumRepeats() ; repeat++)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
if(iTestEngine.NumRepeats() > 1)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
RDebug::Printf("Test Case Loop %d..........", repeat+1);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
for(TInt testIndex = 0; testIndex < iTestEngine.TestCasesIdentities().Count() ; testIndex++)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
if(iTestCasesResults[testIndex])
|
sl@0
|
227 |
{
|
sl@0
|
228 |
RDebug::Print(_L("Test Case: %S : PASSED"), (iTestEngine.TestCasesIdentities())[testIndex]);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
else
|
sl@0
|
231 |
{
|
sl@0
|
232 |
RDebug::Print(_L("Test Case: %S : FAILED"), (iTestEngine.TestCasesIdentities())[testIndex]);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
}
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
RDebug::Printf("CActiveScheduler::Stop CTestCaseController::RunL");
|
sl@0
|
238 |
CActiveScheduler::Stop();
|
sl@0
|
239 |
}
|
sl@0
|
240 |
else
|
sl@0
|
241 |
{
|
sl@0
|
242 |
RDebug::Printf("<Error %d> Unknown error from CTestEngine::NextTestCaseId",err);
|
sl@0
|
243 |
User::Leave(err);
|
sl@0
|
244 |
}
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
|
sl@0
|
248 |
TInt CTestCaseController::RunError(TInt aError)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
LOG_FUNC
|
sl@0
|
251 |
|
sl@0
|
252 |
switch(aError)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
case KErrNoMemory: //follow through
|
sl@0
|
255 |
default:
|
sl@0
|
256 |
// Panic the test module
|
sl@0
|
257 |
gtest(EFalse);
|
sl@0
|
258 |
break;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
return KErrNone;
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
|
sl@0
|
267 |
|
sl@0
|
268 |
|