253
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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 |
// @internalComponent
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <e32std_private.h>
|
|
20 |
#include <u32std.h> // unicode builds
|
|
21 |
#include <e32base.h>
|
|
22 |
#include <e32base_private.h>
|
|
23 |
#include <e32cons.h>
|
|
24 |
#include <e32Test.h> // RTest headder
|
|
25 |
#include <e32def.h>
|
|
26 |
#include <e32def_private.h>
|
|
27 |
#include "TestCaseFactory.h"
|
|
28 |
#include "debugmacros.h"
|
253
|
29 |
#include "OstTraceDefinitions.h"
|
|
30 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
31 |
#include "testcasefactoryTraces.h"
|
|
32 |
#endif
|
0
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
RTestFactory& RTestFactory::Instance()
|
|
37 |
{
|
|
38 |
static RTestFactory singleton;
|
|
39 |
return singleton;
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
RTestFactory::~RTestFactory()
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
RTestFactory::RTestFactory()
|
|
49 |
: iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
|
|
54 |
void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TCreationMethod aCreationMethod)
|
|
55 |
{
|
|
56 |
TStringIdentity key(aTestCaseId);
|
|
57 |
TInt err(Instance().iTestCases.Insert(key,aCreationMethod));
|
|
58 |
if (err != KErrNone)
|
|
59 |
{
|
|
60 |
// Log that a test case could not be registered due to err
|
253
|
61 |
OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE_DUP01, "Test case '%S' could not be registered with test case factory",aTestCaseId);
|
0
|
62 |
}
|
|
63 |
else
|
|
64 |
{
|
|
65 |
RTestFactory::TCreationMethod* creatorFunction = Instance().iTestCases.Find(key);
|
|
66 |
if (creatorFunction == NULL)
|
|
67 |
{
|
253
|
68 |
OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE_DUP02, "<Error> Test case '%S' did not register",aTestCaseId);
|
0
|
69 |
ListRegisteredTestCases();
|
|
70 |
}
|
|
71 |
else
|
|
72 |
{
|
253
|
73 |
OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE_DUP03, "Test case '%S' registered in factory",aTestCaseId);
|
0
|
74 |
}
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
TBool RTestFactory::TestCaseExists(const TDesC& aTestCaseId)
|
|
80 |
{
|
|
81 |
RTestFactory::TCreationMethod creatorFunction;
|
|
82 |
TStringIdentity key(aTestCaseId);
|
|
83 |
|
|
84 |
creatorFunction = REINTERPRET_CAST(RTestFactory::TCreationMethod, Instance().iTestCases.Find(key));
|
|
85 |
return (NULL != creatorFunction);
|
|
86 |
}
|
|
87 |
|
|
88 |
|
|
89 |
/* Returns the test ID (name) of test at offset aIndex in the MAP
|
|
90 |
*/
|
|
91 |
void RTestFactory::GetTestID(TInt aIndex, TBuf<KTestCaseIdLength> &aTestID)
|
|
92 |
{
|
253
|
93 |
if(gVerboseOutput)
|
|
94 |
{
|
|
95 |
OstTraceFunctionEntry0(RTESTFACTORY_GETTESTID);
|
|
96 |
}
|
0
|
97 |
|
|
98 |
RFactoryMap::TIter it(Instance().iTestCases);
|
|
99 |
|
|
100 |
TInt count(0);
|
|
101 |
for (count=0; count<Instance().iTestCases.Count(); count++)
|
|
102 |
{
|
|
103 |
it.NextKey();
|
|
104 |
if (count == aIndex)
|
|
105 |
{
|
|
106 |
TStringIdentity k(*it.CurrentKey());
|
|
107 |
TBuf<64> *p = REINTERPRET_CAST(TBuf<64>*, &k);
|
|
108 |
|
|
109 |
aTestID.Copy( *p);
|
|
110 |
return;
|
|
111 |
}
|
|
112 |
}
|
|
113 |
// Error: Case not found!
|
|
114 |
User::Leave(-2);
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
/* Return the ordinal value of the Test ID (numeric portion)
|
|
119 |
*/
|
|
120 |
TInt TestIDValue(const TDesC & aTestID)
|
|
121 |
{
|
|
122 |
TUint16 value;
|
|
123 |
TBuf<KTestCaseIdLength> id;
|
|
124 |
id = aTestID.Right(4);
|
|
125 |
TLex lex(id);
|
|
126 |
if (KErrNone == lex.Val(value, EDecimal))
|
|
127 |
return(value);
|
|
128 |
return(-1);
|
|
129 |
}
|
|
130 |
|
|
131 |
/* Print the test IDs in numerical order
|
|
132 |
* Returns a sorted array of strings containing all of the test IDs
|
|
133 |
*/
|
|
134 |
void RTestFactory::ListRegisteredTestCases(RPointerArray<HBufC> & aTestCaseNameArr)
|
|
135 |
{
|
253
|
136 |
if(gVerboseOutput)
|
|
137 |
{
|
|
138 |
OstTraceFunctionEntry0(RTESTFACTORY_LISTREGISTEREDTESTCASES);
|
|
139 |
}
|
0
|
140 |
RFactoryMap::TIter it(Instance().iTestCases);
|
|
141 |
TInt count(0);
|
|
142 |
TInt cases(Instance().iTestCases.Count());
|
|
143 |
|
|
144 |
test.Printf(_L("------ F A C T O R Y -------\n"));
|
253
|
145 |
OstTrace0(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP01, "------ F A C T O R Y -------\n");
|
0
|
146 |
|
|
147 |
it.Reset();
|
|
148 |
for (count=0; count<Instance().iTestCases.Count(); count++)
|
|
149 |
{
|
|
150 |
TStringIdentity k(*it.NextKey());
|
|
151 |
TBuf<KTestCaseIdLength> *p = REINTERPRET_CAST(TBuf<KTestCaseIdLength>*, &k); // pointer to the test ID
|
|
152 |
TBool placed(EFalse);
|
|
153 |
TInt pos(0);
|
|
154 |
TInt val(0);
|
|
155 |
|
|
156 |
// build the sorted list
|
|
157 |
while (!placed)
|
|
158 |
{
|
|
159 |
val = TestIDValue(*p);
|
|
160 |
if (aTestCaseNameArr.Count()==pos)
|
|
161 |
{ //array empty or reached end
|
|
162 |
HBufC* testIdentity = HBufC::NewLC(KTestCaseIdLength);
|
|
163 |
*testIdentity = *p;
|
|
164 |
aTestCaseNameArr.Append(testIdentity);
|
|
165 |
CleanupStack::Pop(testIdentity);
|
|
166 |
placed = ETrue;
|
|
167 |
}
|
|
168 |
else
|
|
169 |
{
|
|
170 |
if ( val < TestIDValue(*aTestCaseNameArr[pos]) )
|
|
171 |
{
|
|
172 |
HBufC* testIdentity = HBufC::NewLC(KTestCaseIdLength);
|
|
173 |
*testIdentity = *p;
|
|
174 |
aTestCaseNameArr.Insert(testIdentity, pos);
|
|
175 |
placed = ETrue;
|
|
176 |
CleanupStack::Pop(testIdentity);
|
|
177 |
}
|
|
178 |
else
|
|
179 |
{
|
|
180 |
pos++;
|
|
181 |
}
|
|
182 |
}
|
|
183 |
}
|
|
184 |
}
|
|
185 |
// print it
|
|
186 |
for (count=0; count<aTestCaseNameArr.Count(); count++)
|
|
187 |
{
|
|
188 |
test.Printf(_L("% 2d: %S\n"), count, aTestCaseNameArr[count]);
|
253
|
189 |
OstTraceExt2(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP02, "% 2d: %S\n", count, *aTestCaseNameArr[count]);
|
0
|
190 |
}
|
|
191 |
|
|
192 |
test.Printf(_L("----------------------------\n"));
|
253
|
193 |
OstTrace0(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP03, "----------------------------\n");
|
0
|
194 |
}
|
|
195 |
|
|
196 |
|
|
197 |
CTestCaseRoot* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId)
|
|
198 |
{
|
253
|
199 |
if(gVerboseOutput)
|
|
200 |
{
|
|
201 |
OstTraceFunctionEntry0(RTESTFACTORY_CREATETESTCASEL);
|
|
202 |
}
|
0
|
203 |
RTestFactory::TCreationMethod creatorFunction = NULL;
|
|
204 |
TInt err(KErrNone);
|
|
205 |
TStringIdentity key(aTestCaseId);
|
|
206 |
|
|
207 |
TRAP(err,creatorFunction = Instance().iTestCases.FindL(key));
|
|
208 |
if (err != KErrNone)
|
|
209 |
{
|
|
210 |
// Test case is not present in the factory therefore test cannot support specified test case
|
253
|
211 |
OstTraceExt2(TRACE_NORMAL, RTESTFACTORY_CREATETESTCASEL_DUP01, "<Error %d> Test case '%S' not supported",err,aTestCaseId);
|
0
|
212 |
ListRegisteredTestCases();
|
|
213 |
User::Leave(err);
|
|
214 |
}
|
|
215 |
|
253
|
216 |
OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_CREATETESTCASEL_DUP02, "Creating test case '%S'",aTestCaseId);
|
0
|
217 |
|
|
218 |
// Call the creator function to create the test case object
|
|
219 |
return creatorFunction(gSemiAutomated);
|
|
220 |
}
|
|
221 |
|
|
222 |
|