1 // Copyright (c) 2008-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 // |
|
15 // |
|
16 |
|
17 #ifndef __D_SYMBIANUNITTESTLDD_H |
|
18 #define __D_SYMBIANUNITTESTLDD_H |
|
19 |
|
20 |
|
21 #include <kernel/kernel.h> |
|
22 #include "symbianunittestlddif.h" |
|
23 |
|
24 |
|
25 // CLASS DECLARATION |
|
26 |
|
27 |
|
28 class DSymbianUnitTestFactory : public DLogicalDevice |
|
29 { |
|
30 public: |
|
31 IMPORT_C DSymbianUnitTestFactory(const TDesC& aName); |
|
32 IMPORT_C virtual ~DSymbianUnitTestFactory(); |
|
33 IMPORT_C virtual TInt Install(); |
|
34 IMPORT_C virtual void GetCaps(TDes8& aDes) const; |
|
35 virtual TInt Create(DLogicalChannelBase*& aChannel) = 0; |
|
36 |
|
37 private: |
|
38 TName iDriverName; |
|
39 |
|
40 }; |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 /** |
|
47 * The base class for kernel unit test classes. |
|
48 * It implements logical driver to run test code in kernel mode |
|
49 * The classes inheriting from this class should implements Construct |
|
50 * for adding test case |
|
51 * @lib symbianunittestldd.lib |
|
52 */ |
|
53 class DSymbianUnitTest : public DLogicalChannelBase |
|
54 { |
|
55 |
|
56 public: // Typedefs |
|
57 |
|
58 typedef TInt ( DSymbianUnitTest::*FunctionPtr )(); |
|
59 |
|
60 |
|
61 public: |
|
62 |
|
63 //Constructor |
|
64 IMPORT_C DSymbianUnitTest(); |
|
65 |
|
66 // Destructor |
|
67 IMPORT_C virtual ~DSymbianUnitTest(); |
|
68 |
|
69 /** |
|
70 * This function should be overidden in the actual unit test classes. |
|
71 * It is the default setup function that gets executed |
|
72 * by the framework before each unit test case. |
|
73 */ |
|
74 IMPORT_C virtual TInt Setup(); |
|
75 |
|
76 /** |
|
77 * This function should be overidden in the actual unit test classes. |
|
78 * It is the default teardown function that gets executed |
|
79 * by the framework after each unit test case. |
|
80 */ |
|
81 IMPORT_C virtual TInt Teardown(); |
|
82 |
|
83 |
|
84 protected: |
|
85 |
|
86 /** |
|
87 * Adds a new unit test case to this unit test. |
|
88 * Use macro ADD_SYMBIAN_UT in symbianunittestmacros.h |
|
89 * instead to avoid the need to pass |
|
90 * the name of the unit test case as a parameter. |
|
91 * |
|
92 * @param aName the name of the unit test case |
|
93 * @param aSetupFunction a function pointer to the setup function |
|
94 * that will be executed before the actual unit test case |
|
95 * @param aTestFunction a function pointer to the unit test case |
|
96 * @param aTeardownFunction a function pointer to the teardown function |
|
97 * that will be executed after the actual unit test case |
|
98 */ |
|
99 IMPORT_C void AddTestCase( |
|
100 const TDesC& aName, |
|
101 DSymbianUnitTest::FunctionPtr aSetupFunction, |
|
102 DSymbianUnitTest::FunctionPtr aTestFunction, |
|
103 DSymbianUnitTest::FunctionPtr aTeardownFunction ); |
|
104 |
|
105 /** |
|
106 * Asserts that two TInt values are equal. |
|
107 * Leaves with a Symbian unit test framework specific error code |
|
108 * if the values are not equal. |
|
109 * In case of a failed assertion, the framework records |
|
110 * the failure reason, line number and file name to the test results. |
|
111 * Use macro SYMBIAN_UT_ASSERT_EQUALS in symbianunittestmacros.h |
|
112 * instead to avoid the need to pass the other parameters |
|
113 * than the actual asserted values. |
|
114 * |
|
115 * @param aExpectedValue the expected value |
|
116 * @param aActualValue the actual value |
|
117 * @param aLineNumber the line number of the assertion |
|
118 * @param aFileName the name of the file where the assertion is located |
|
119 */ |
|
120 IMPORT_C TInt AssertEquals( |
|
121 TInt aExpectedValue, |
|
122 TInt aActualValue, |
|
123 TInt aLineNumber, |
|
124 const TDesC8& aFileName ); |
|
125 |
|
126 /** |
|
127 * Asserts that two TDesC8 values are equal. |
|
128 * Leaves with a Symbian unit test framework specific error code |
|
129 * if the values are not equal. |
|
130 * In case of a failed assertion, the framework records |
|
131 * the failure reason, line number and file name to the test results. |
|
132 * Use macro SYMBIAN_UT_ASSERT_EQUALS in symbianunittestmacros.h |
|
133 * instead to avoid the need to pass the other parameters |
|
134 * than the actual asserted values. |
|
135 * |
|
136 * @param aExpectedValue the expected value |
|
137 * @param aActualValue the actual value |
|
138 * @param aLineNumber the line number of the assertion |
|
139 * @param aFileName the name of the file where the assertion is located |
|
140 */ |
|
141 IMPORT_C TInt AssertEquals( |
|
142 const TDesC8& aExpectedValue, |
|
143 const TDesC8& aActualValue, |
|
144 TInt aLineNumber, |
|
145 const TDesC8& aFileName ); |
|
146 |
|
147 |
|
148 |
|
149 /** |
|
150 * Records a failed assertion to the test results and |
|
151 * leaves with a Symbian unit test framework specific error code |
|
152 * to quit the execution of the test function. |
|
153 * Use macro SYMBIAN_UT_ASSERT in symbianunittestmacros.h |
|
154 * to perform the actual assertion. |
|
155 * |
|
156 * @param aFailureMessage the failed assertion as text |
|
157 * @param aLineNumber the line number of the assertion |
|
158 * @param aFileName the name of the file where the assertion is located |
|
159 */ |
|
160 IMPORT_C TInt AssertionFailed( |
|
161 const TDesC8& aFailureMessage, |
|
162 TInt aLineNumber, |
|
163 const TDesC8& aFileName ); |
|
164 |
|
165 /** |
|
166 * Add test cases |
|
167 * Although the functions implemented in this class |
|
168 * for unit test assertions and adding test cases |
|
169 * can be called directly from the subclasses, |
|
170 * the macros defined in symbianunittestmacros.h should be used instead. |
|
171 */ |
|
172 virtual void Construct() = 0; |
|
173 |
|
174 |
|
175 private: // Internal class for a unit test function's data |
|
176 |
|
177 class DSymbianUnitTestCase : public DBase |
|
178 { |
|
179 public: // Constructors and destructor |
|
180 |
|
181 DSymbianUnitTestCase( |
|
182 const TDesC& aName, |
|
183 DSymbianUnitTest::FunctionPtr aSetupFunction, |
|
184 DSymbianUnitTest::FunctionPtr aTestFunction, |
|
185 DSymbianUnitTest::FunctionPtr aTeardownFunction ); |
|
186 |
|
187 ~DSymbianUnitTestCase(); |
|
188 |
|
189 public: // New functions |
|
190 |
|
191 const TDesC& Name() const; |
|
192 |
|
193 public: // Data |
|
194 |
|
195 DSymbianUnitTest::FunctionPtr iSetupFunction; |
|
196 DSymbianUnitTest::FunctionPtr iTestFunction; |
|
197 DSymbianUnitTest::FunctionPtr iTeardownFunction; |
|
198 |
|
199 private: // Data |
|
200 |
|
201 HBuf* iName; |
|
202 }; |
|
203 |
|
204 private: |
|
205 |
|
206 |
|
207 TInt TestCount(TInt* aDest); |
|
208 |
|
209 TInt ExecuteTestCase(TAny* aIndex, TDes8* aResult); |
|
210 |
|
211 TInt GetTestCaseName(TAny* aIndex, TDes* aCaseName); |
|
212 |
|
213 TInt ExecuteTestCaseInThread(); |
|
214 |
|
215 static TInt TestThreadEntryFunction( TAny* aPtr ); |
|
216 |
|
217 void Printf(TDes8& aDes, const char* aFmt, ...); |
|
218 |
|
219 IMPORT_C virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); |
|
220 |
|
221 private: // Data |
|
222 |
|
223 HBuf* iName; |
|
224 RPointerArray< DSymbianUnitTestCase > iTestCases; |
|
225 DSymbianUnitTestCase* iCurrentTestCase; // Not owned |
|
226 |
|
227 DThread* iClient; //pointer to client thread for read/write data |
|
228 TSUTTestCaseResult* iCurrentResult; // Not owned |
|
229 NFastSemaphore iExecSem;//semaphore for synchronization between main thread and execworkder thread |
|
230 |
|
231 //TUint iExecThreadId; //id of the current exec workder thread. |
|
232 //DCrashHandler* iCrashHandler; |
|
233 |
|
234 }; |
|
235 |
|
236 |
|
237 |
|
238 #endif //__D_SYMBIANUNITTESTLDD_H |
|
239 |
|