|
1 // Copyright (c) 2003-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 "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 // |
|
15 |
|
16 // Epoc includes |
|
17 #include <f32file.h> |
|
18 #include <e32base.h> |
|
19 #include <e32cons.h> |
|
20 #include <e32test.h> |
|
21 //TestBed includes |
|
22 #include "TestController.h" |
|
23 #include "ComponentInfo.h" |
|
24 //ECom includes |
|
25 #include <ecom/ecom.h> |
|
26 // |
|
27 #include "TestHarnessTemplate.h" |
|
28 |
|
29 /** |
|
30 @internalComponent |
|
31 @fn void DoTestingL(RTest& aRTest, TNewComponentTestLC aNewComponentTestLC) |
|
32 Intended Usage : Run the tests discovered by the TestController. |
|
33 @param aRTest A RTest instance. |
|
34 @param aNewComponentTestLC A pointer to defined into ECOM test app global |
|
35 function. It should create derived CComponentTester object which |
|
36 knows about the tests required. |
|
37 @return void. |
|
38 @leave KErrNoMemory, Any other codes possible from a test. |
|
39 @pre aNewComponentTestLC != NULL. |
|
40 Error Condition : None |
|
41 @since 7.0s |
|
42 */ |
|
43 LOCAL_C void DoTestingL(RTest& aRTest, TNewComponentTestLC aNewComponentTestLC) |
|
44 { |
|
45 _LIT(KLogFileDirectory, "C:\\Logs\\TestBed\\"); |
|
46 _LIT(KUnitTestMessage, "Unit Test %d: %S\n"); |
|
47 _LIT(KNoTestsMessage, "No Tests found\n"); |
|
48 |
|
49 // Avoid cleanup stack heap allocation expansion problems |
|
50 // when testing for heap allocation leaks within the test |
|
51 // harnesses, by expanding the stack now. |
|
52 const TInt KMaxCleanupFrames = 20; |
|
53 for (TInt i = 0; i < KMaxCleanupFrames; ++i) |
|
54 CleanupStack::PushL((TAny*)0); |
|
55 CleanupStack::Pop(KMaxCleanupFrames); |
|
56 |
|
57 // Check that the logging directory exists, and if it doesn't then create it |
|
58 RFs fs; |
|
59 User::LeaveIfError(fs.Connect()); |
|
60 TInt err = fs.MkDirAll(KLogFileDirectory); |
|
61 if(err != KErrAlreadyExists) // Don't leave if it already exists |
|
62 User::LeaveIfError(err); |
|
63 fs.Close(); |
|
64 |
|
65 // Set up the logging configuration information |
|
66 _LIT(KLogTitle, "Test Bed Test"); |
|
67 TLoggingInfo* loggingInfo = new(ELeave) TLoggingInfo; |
|
68 CleanupStack::PushL(loggingInfo); |
|
69 loggingInfo->iTitle = &(KLogTitle); |
|
70 loggingInfo->iUseRDebug = ETrue; |
|
71 loggingInfo->iLogOutput = 0; |
|
72 loggingInfo->iReportOutput = 0; |
|
73 loggingInfo->iStyle = EHtml; |
|
74 |
|
75 // Create the test controller object and start the test |
|
76 #ifdef LOG_PANIC_UNIT_TEST_FAILURE |
|
77 CTestController* theController = CTestController::NewLC(NULL, aNewComponentTestLC, &aRTest, loggingInfo); |
|
78 #else |
|
79 CTestController* theController = CTestController::NewLC(NULL, aNewComponentTestLC, NULL, loggingInfo); |
|
80 #endif //LOG_PANIC_UNIT_TEST_FAILURE |
|
81 |
|
82 _LIT(KControllerBuilt,"Test Controller built with the following tests...\n"); |
|
83 aRTest.Printf(KControllerBuilt); |
|
84 |
|
85 // Get a list of the available tests and display them |
|
86 const RPointerArray<CComponentInfo>& testList = theController->FindComponents(); |
|
87 TInt numTests = testList.Count(); |
|
88 if(numTests) |
|
89 { |
|
90 for(TInt index = 0; index < numTests; ++index) |
|
91 { |
|
92 //Print all the unit tests |
|
93 const RPointerArray<CUnitTestInfo>& transList = testList[index]->UnitTestsInfo(); |
|
94 TInt numTrans = transList.Count(); |
|
95 if(numTrans) |
|
96 { |
|
97 for(TInt transIndex = 0; transIndex < numTrans; ++transIndex) |
|
98 { |
|
99 //Print the test component name |
|
100 aRTest.Printf(KUnitTestMessage, |
|
101 transIndex+1, &(transList[transIndex]->UnitTestId())); |
|
102 } |
|
103 } |
|
104 else |
|
105 aRTest.Printf(KNoTestsMessage); // No tests found |
|
106 } |
|
107 |
|
108 // Run the tests |
|
109 theController->Start(); |
|
110 } |
|
111 else |
|
112 aRTest.Printf(KNoTestsMessage); // No tests found |
|
113 |
|
114 CleanupStack::PopAndDestroy(2, loggingInfo); |
|
115 } |
|
116 |
|
117 |
|
118 /** |
|
119 @fn TInt E32Main_TestHarness(TNewComponentTestLC aNewComponentTestLC) |
|
120 Intended Usage : Main entry point to the console app called by E32 |
|
121 @param aNewComponentTestLC A pointer to defined into ECOM test app global |
|
122 function. It should create derived CComponentTester object which |
|
123 knows about the tests required. |
|
124 @return TInt KErrNone. |
|
125 @leave KErrNoMemory, Any other codes possible from a test. |
|
126 @pre aNewComponentTestLC != NULL. |
|
127 @since 7.0s |
|
128 */ |
|
129 EXPORT_C TInt E32Main_TestHarness(TNewComponentTestLC aNewComponentTestLC) |
|
130 { |
|
131 // Set up for heap leak checking |
|
132 __UHEAP_MARK; |
|
133 |
|
134 // Obtain for the system the exeutable filename of this process |
|
135 RProcess current; |
|
136 TParse exeFilename; |
|
137 exeFilename.SetNoWild(current.FileName(), NULL, NULL); |
|
138 |
|
139 // Startup the RTest framework |
|
140 RTest rTest(exeFilename.Name()); |
|
141 rTest.Title(); |
|
142 rTest.Start(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TESTHARNESSTEMPLATE-0001 Test Bed Tester EXE ")); |
|
143 |
|
144 // Leaking thread handles |
|
145 TInt startProcessHandleCount; |
|
146 TInt startThreadHandleCount; |
|
147 TInt endProcessHandleCount; |
|
148 TInt endThreadHandleCount; |
|
149 |
|
150 RThread thisThread; |
|
151 thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
152 |
|
153 // Create the clean up stack. |
|
154 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
155 |
|
156 // Call the main function and trap the result |
|
157 TRAPD(retCode, DoTestingL(rTest, aNewComponentTestLC)); // perform test |
|
158 rTest(retCode==KErrNone); |
|
159 |
|
160 // This line added to close handles associated to last plugin loaded. |
|
161 // The last plugin DLL is only unloaded when the client makes another call into ECom |
|
162 // (assuming the client has destroyed the implementation). |
|
163 // TLS area cleaned up only when DLL unloaded or thread ends. |
|
164 // FinalClose() ensures that the last DLL is unloaded and TLS cleaned up. |
|
165 // Memory leaks/open handles will occur if this is not called. |
|
166 // |
|
167 // If ECom is not used should have no effect. |
|
168 REComSession::FinalClose(); |
|
169 |
|
170 // Destroy the curernt cleanup stack |
|
171 delete cleanup; |
|
172 |
|
173 // Check for open handles |
|
174 thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
175 if(startThreadHandleCount != endThreadHandleCount) |
|
176 {__DEBUGGER()} // Oops leaked some handles |
|
177 |
|
178 // End the testing |
|
179 rTest.Next(_L("/n")); |
|
180 rTest.End(); |
|
181 //rTest.Getch(); |
|
182 rTest.Close(); |
|
183 |
|
184 // End heap leak checking and exit |
|
185 __UHEAP_MARKEND; |
|
186 return KErrNone; |
|
187 } |