sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#include "captestutility.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
// CDefaultCapabilityTest
|
sl@0
|
28 |
|
sl@0
|
29 |
EXPORT_C CDefaultCapabilityTest::~CDefaultCapabilityTest()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
delete iTestName;
|
sl@0
|
32 |
|
sl@0
|
33 |
if (iLogWriteStream)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
iLogWriteStream->WriteInt32L(EFileEnd); // End marker
|
sl@0
|
36 |
iLogWriteStream->Close();
|
sl@0
|
37 |
delete iLogWriteStream;
|
sl@0
|
38 |
iLogWriteStream=0;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
EXPORT_C void CDefaultCapabilityTest::SetNameL(const TDesC& aName)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
delete iTestName;
|
sl@0
|
45 |
iTestName=0;
|
sl@0
|
46 |
iTestName=HBufC::NewL(aName.Length());
|
sl@0
|
47 |
TPtr testNamePtr=iTestName->Des();
|
sl@0
|
48 |
testNamePtr.Copy(aName);
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
EXPORT_C TInt CDefaultCapabilityTest::CheckFailL(TInt aResult, const TDesC& aTestName)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
_LIT(KColourRed, "<font color=FF0000>");
|
sl@0
|
54 |
_LIT(KColourGreen, "<font color=00AF00>");
|
sl@0
|
55 |
_LIT(KFontEndColour, "</font>");
|
sl@0
|
56 |
TBuf<1024> buf;
|
sl@0
|
57 |
|
sl@0
|
58 |
if (iExpectPermissionDenied && aResult==KErrPermissionDenied)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
buf.Format(_L("%S%S: Permission Denied, Err=%d%S"), &KColourGreen, &aTestName, aResult, &KFontEndColour);
|
sl@0
|
61 |
iLogWriteStream->WriteInt32L(ETestPassed);
|
sl@0
|
62 |
*iLogWriteStream << buf;
|
sl@0
|
63 |
return aResult;
|
sl@0
|
64 |
}
|
sl@0
|
65 |
else if (!iExpectPermissionDenied && aResult!=KErrPermissionDenied)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
buf.Format(_L("%S%S: Succeeded, Err=%d%S"), &KColourGreen, &aTestName, aResult, &KFontEndColour);
|
sl@0
|
68 |
iLogWriteStream->WriteInt32L(ETestPassed);
|
sl@0
|
69 |
*iLogWriteStream << buf;
|
sl@0
|
70 |
return aResult;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
// Test failed, do something with error.
|
sl@0
|
74 |
if (aResult == KErrPermissionDenied)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
buf.Format(_L("%S%S: Permission denied! (Unexpected), Err=%d%S"), &KColourRed, &aTestName, aResult, &KFontEndColour);
|
sl@0
|
77 |
iLogWriteStream->WriteInt32L(ETestFailed);
|
sl@0
|
78 |
*iLogWriteStream << buf;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
else
|
sl@0
|
81 |
{
|
sl@0
|
82 |
buf.Format(_L("%S%S: Succeeded! (Unexpected), Err=%d%S"), &KColourRed, &aTestName, aResult, &KFontEndColour);
|
sl@0
|
83 |
iLogWriteStream->WriteInt32L(ETestFailed);
|
sl@0
|
84 |
*iLogWriteStream << buf;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
SetFail();
|
sl@0
|
88 |
return aResult;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
EXPORT_C void CDefaultCapabilityTest::RunTestL(RFile& aLogFile)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
// Setup logging
|
sl@0
|
94 |
iLogFile=&aLogFile;
|
sl@0
|
95 |
|
sl@0
|
96 |
if (iLogWriteStream)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
iLogWriteStream->Close();
|
sl@0
|
99 |
delete iLogWriteStream;
|
sl@0
|
100 |
iLogWriteStream=0;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
iLogWriteStream=new(ELeave) RFileWriteStream(aLogFile, 0);
|
sl@0
|
103 |
|
sl@0
|
104 |
// run tests
|
sl@0
|
105 |
RunTestL();
|
sl@0
|
106 |
|
sl@0
|
107 |
if (!iFail)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
iLogWriteStream->WriteInt32L(ETestsEnded); // Test ended ok
|
sl@0
|
110 |
}
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
EXPORT_C const TDesC& CDefaultCapabilityTest::Name() const
|
sl@0
|
114 |
{
|
sl@0
|
115 |
if (iTestName)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
return *iTestName;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
return KNullDesC;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
EXPORT_C const TDesC& CDefaultCapabilityTest::SubName() const
|
sl@0
|
123 |
{
|
sl@0
|
124 |
if (iTestSubName)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
return *iTestSubName;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
return KNullDesC;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
EXPORT_C TCapabilitySet CDefaultCapabilityTest::CapabilitiesRequired() const
|
sl@0
|
132 |
{
|
sl@0
|
133 |
return iCapabilitySet;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
EXPORT_C TUid CDefaultCapabilityTest::VidRequired() const
|
sl@0
|
137 |
{
|
sl@0
|
138 |
return iVidRequired;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
EXPORT_C TUid CDefaultCapabilityTest::SidRequired() const
|
sl@0
|
142 |
{
|
sl@0
|
143 |
return iSidRequired;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
EXPORT_C void CDefaultCapabilityTest::SetCapabilityRequired(const TCapability& aCapability)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
iCapabilitySet.AddCapability(aCapability);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
EXPORT_C void CDefaultCapabilityTest::SetSidRequired(const TUid& aSid)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
iSidRequired=aSid;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
EXPORT_C void CDefaultCapabilityTest::SetVidRequired(const TUid& aVid)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
iVidRequired=aVid;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
// CDefaultCapabilityTestFactory
|
sl@0
|
162 |
EXPORT_C MCapabilityTest* CDefaultCapabilityTestFactory::Test(TInt aTestNumber)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
return iTests[aTestNumber];
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
EXPORT_C TInt CDefaultCapabilityTestFactory::NumberOfTests()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
return iTests.Count();
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
EXPORT_C void CDefaultCapabilityTestFactory::AddTestL(CDefaultCapabilityTest* aTest)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
iTests.AppendL(aTest);
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
|
sl@0
|
178 |
EXPORT_C CDefaultCapabilityTestFactory::~CDefaultCapabilityTestFactory()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
for (TInt i=0; i< iTests.Count(); ++i)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
delete iTests[i];
|
sl@0
|
183 |
}
|
sl@0
|
184 |
iTests.Reset();
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|