Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file testcasecontroller.cpp
19 #include "basetestcase.h"
20 #include "testcasecontroller.h"
21 #include "testcasefactory.h"
22 #include "testengine.h"
23 #include "testpolicy.h"
24 #include "testdebug.h"
26 _LIT(KClientDeviceDriverName,"EUSBC");
27 _LIT(KHostDeviceDriverName,"usbhubdriver");
28 _LIT(KHostDeviceInterfaceDriverName,"usbdi");
29 _LIT(KOtgdiLddFileName, "otgdi");
31 namespace NUnitTesting_USBDI
34 CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole)
36 CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole);
37 CleanupStack::PushL(self);
39 CleanupStack::Pop(self);
44 CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole)
45 : CActive(EPriorityStandard),
46 iTestEngine(aTestEngine),
49 // Add to current threads active scheduler
50 CActiveScheduler::Add(this);
54 CTestCaseController::~CTestCaseController()
58 Cancel(); // Cancels any oustanding test cases
64 TInt err = User::FreeLogicalDevice(KHostDeviceInterfaceDriverName);
67 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceInterfaceDriverName);
70 err = User::FreeLogicalDevice(KHostDeviceDriverName);
73 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceDriverName);
76 err = User::FreeLogicalDevice(KOtgdiLddFileName);
79 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceDriverName);
84 TInt err(User::FreeLogicalDevice(KClientDeviceDriverName));
87 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KClientDeviceDriverName);
92 void CTestCaseController::ConstructL()
97 _LIT(KLoadingNamedDriverString,"loading driver: %S\n");
98 _LIT(KLoadedNamedDriverString,"loaded driver: %S\n");
103 gtest.Printf(KLoadingNamedDriverString,&KHostDeviceDriverName);
104 // Load both Host USB device drivers
105 err = User::LoadLogicalDevice(KHostDeviceDriverName);
106 gtest((err == KErrNone) || (err == KErrAlreadyExists));
107 gtest.Printf(KLoadedNamedDriverString,&KHostDeviceDriverName);
109 RDebug::Print(KLoadingNamedDriverString,&KHostDeviceInterfaceDriverName);
110 err = User::LoadLogicalDevice(KHostDeviceInterfaceDriverName);
111 gtest((err == KErrNone) || (err == KErrAlreadyExists));
112 gtest.Printf(KLoadedNamedDriverString,&KHostDeviceInterfaceDriverName);
114 // If test cases are running USB host side actions
115 // then run each test case in its own thread
116 iTestPolicy = CThreadTestPolicy::NewL();
121 // Load the USB client driver
122 gtest.Printf(KLoadingNamedDriverString,&KClientDeviceDriverName);
123 err = User::LoadLogicalDevice(KClientDeviceDriverName);
124 gtest((err == KErrNone) || (err == KErrAlreadyExists));
125 gtest.Printf(KLoadedNamedDriverString,&KClientDeviceDriverName);
127 // Run each test case in the main thread as its not new API
128 // and not expected to panic
129 iTestPolicy = CBasicTestPolicy::NewL();
132 // Get the identity of the next test case to run
133 err = iTestEngine.NextTestCaseId(iTestCaseId);
134 gtest.Next(iTestCaseId);
137 iTestPolicy->RunTestCaseL(iTestCaseId,iStatus);
142 void CTestCaseController::DoCancel()
144 // Cancel the outstanding test case running
146 iTestPolicy->Cancel();
150 void CTestCaseController::RunL()
154 // Retrieve the completion code of the last test case run
155 TInt err(iStatus.Int());
160 iTestCasesResults.Append(EFalse);
161 gtest.Printf(_L("FAILED err=%d\n"),err);
165 iTestCasesResults.Append(ETrue);
166 gtest.Printf(_L("PASSED\n"));
169 // Get the identity of the next test case to run
171 err = iTestEngine.NextTestCaseId(iTestCaseId);
174 RDebug::Printf("\n");
175 RDebug::Printf("\n");
176 RDebug::Printf("\n");
177 gtest.Next(iTestCaseId);
178 RDebug::Printf(" --------------------");
179 RDebug::Printf("\n");
180 RDebug::Printf("\n");
181 RDebug::Printf("\n");
183 // Run the next test case
185 iTestPolicy->RunTestCaseL(iTestCaseId,iStatus);
188 else if(err == KErrNotFound)
190 RDebug::Printf("All specified test cases performed");
191 RDebug::Printf("----------------------------------");
195 TUint nbFailures = 0;
196 for(TInt test = 0; test < iTestCasesResults.Count() ; test++)
198 if(!iTestCasesResults[test])
199 //NB iTestCasesResults is a boolean array added to each time a test is run...
200 // ...even if it is a repeat.
205 RDebug::Printf("There are %d test case results, %d failures", iTestCasesResults.Count(), nbFailures);
207 // Number of tests that should have been run (including repeats)
208 TUint nbTests = iTestEngine.TestCasesIdentities().Count() * iTestEngine.NumRepeats();
209 if(nbTests!=iTestCasesResults.Count())
211 RDebug::Printf("The number of tests that should have been run (%d) DOES NOT EQUAL the actual number of tests run (%d).",
212 nbTests, iTestCasesResults.Count());
213 RDebug::Printf("This test suite will now PANIC!");
215 ASSERT((nbTests==iTestCasesResults.Count()));
218 for(TInt repeat = 0; repeat < iTestEngine.NumRepeats() ; repeat++)
220 if(iTestEngine.NumRepeats() > 1)
222 RDebug::Printf("Test Case Loop %d..........", repeat+1);
224 for(TInt testIndex = 0; testIndex < iTestEngine.TestCasesIdentities().Count() ; testIndex++)
226 if(iTestCasesResults[testIndex])
228 RDebug::Print(_L("Test Case: %S : PASSED"), (iTestEngine.TestCasesIdentities())[testIndex]);
232 RDebug::Print(_L("Test Case: %S : FAILED"), (iTestEngine.TestCasesIdentities())[testIndex]);
237 RDebug::Printf("CActiveScheduler::Stop CTestCaseController::RunL");
238 CActiveScheduler::Stop();
242 RDebug::Printf("<Error %d> Unknown error from CTestEngine::NextTestCaseId",err);
248 TInt CTestCaseController::RunError(TInt aError)
254 case KErrNoMemory: //follow through
256 // Panic the test module