271
|
1 |
// Copyright (c) 2010 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 |
// e32test\buffer\d_version.cpp
|
|
15 |
// LDD for testing kernel side of TVersion
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include <kernel/kern_priv.h>
|
|
20 |
#include "d_version.h"
|
|
21 |
|
|
22 |
class DVersionTestFactory : public DLogicalDevice
|
|
23 |
//
|
|
24 |
// VersionTest LDD factory
|
|
25 |
//
|
|
26 |
{
|
|
27 |
public:
|
|
28 |
DVersionTestFactory();
|
|
29 |
~DVersionTestFactory();
|
|
30 |
virtual TInt Install(); //overriding pure virtual
|
|
31 |
virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
|
|
32 |
virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
|
|
33 |
};
|
|
34 |
|
|
35 |
class DVersionTest : public DLogicalChannelBase
|
|
36 |
//
|
|
37 |
// VersionTest LDD channel
|
|
38 |
//
|
|
39 |
{
|
|
40 |
public:
|
|
41 |
DVersionTest();
|
|
42 |
~DVersionTest();
|
|
43 |
protected:
|
|
44 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
|
45 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
|
|
46 |
private:
|
|
47 |
TBool QVS(TInt aCurrent,TInt aRequested);
|
|
48 |
TVersion* iTV[KNumTVersions];
|
|
49 |
TVersion iDefTV; // tests default constructor
|
|
50 |
};
|
|
51 |
|
|
52 |
LOCAL_D const TText* Names[]=
|
|
53 |
{
|
|
54 |
_S("0.00(0)"),
|
|
55 |
_S("0.00(0)"),
|
|
56 |
_S("0.00(1)"),
|
|
57 |
_S("0.00(999)"),
|
|
58 |
_S("0.01(0)"),
|
|
59 |
_S("0.01(1)"),
|
|
60 |
_S("0.01(999)"),
|
|
61 |
_S("0.99(0)"),
|
|
62 |
_S("0.99(1)"),
|
|
63 |
_S("0.99(999)"),
|
|
64 |
_S("1.00(0)"),
|
|
65 |
_S("1.00(1)"),
|
|
66 |
_S("1.00(999)"),
|
|
67 |
_S("1.01(0)"),
|
|
68 |
_S("1.01(1)"),
|
|
69 |
_S("1.01(999)"),
|
|
70 |
_S("1.99(0)"),
|
|
71 |
_S("1.99(1)"),
|
|
72 |
_S("1.99(999)"),
|
|
73 |
_S("99.00(0)"),
|
|
74 |
_S("99.00(1)"),
|
|
75 |
_S("99.00(999)"),
|
|
76 |
_S("99.01(0)"),
|
|
77 |
_S("99.01(1)"),
|
|
78 |
_S("99.01(999)"),
|
|
79 |
_S("99.99(0)"),
|
|
80 |
_S("99.99(1)"),
|
|
81 |
_S("99.99(999)")
|
|
82 |
};
|
|
83 |
|
|
84 |
DVersionTestFactory::DVersionTestFactory()
|
|
85 |
//
|
|
86 |
// Constructor
|
|
87 |
//
|
|
88 |
{
|
|
89 |
}
|
|
90 |
|
|
91 |
//
|
|
92 |
// Destructor
|
|
93 |
//
|
|
94 |
DVersionTestFactory::~DVersionTestFactory()
|
|
95 |
{
|
|
96 |
}
|
|
97 |
|
|
98 |
TInt DVersionTestFactory::Create(DLogicalChannelBase*& aChannel)
|
|
99 |
//
|
|
100 |
// Create
|
|
101 |
//
|
|
102 |
{
|
|
103 |
aChannel=new DVersionTest;
|
|
104 |
return aChannel?KErrNone:KErrNoMemory;
|
|
105 |
}
|
|
106 |
|
|
107 |
TInt DVersionTestFactory::Install()
|
|
108 |
//
|
|
109 |
// Install the LDD - overriding pure virtual
|
|
110 |
//
|
|
111 |
{
|
|
112 |
return SetName(&KVersionTestLddName);
|
|
113 |
}
|
|
114 |
|
|
115 |
void DVersionTestFactory::GetCaps(TDes8& /*aDes*/) const
|
|
116 |
//
|
|
117 |
// Get capabilities - overriding pure virtual
|
|
118 |
//
|
|
119 |
{
|
|
120 |
// Not used but required as DLogicalDevice::GetCaps is pure virtual
|
|
121 |
}
|
|
122 |
|
|
123 |
DECLARE_STANDARD_LDD()
|
|
124 |
{
|
|
125 |
return new DVersionTestFactory;
|
|
126 |
}
|
|
127 |
|
|
128 |
DVersionTest::DVersionTest()
|
|
129 |
//
|
|
130 |
// Constructor
|
|
131 |
//
|
|
132 |
{
|
|
133 |
iTV[0]=&iDefTV;
|
|
134 |
TInt i=1;
|
|
135 |
TInt major=0;
|
|
136 |
FOREVER
|
|
137 |
{
|
|
138 |
TInt minor=0;
|
|
139 |
FOREVER
|
|
140 |
{
|
|
141 |
TInt build=0;
|
|
142 |
FOREVER
|
|
143 |
{
|
|
144 |
iTV[i++]=new TVersion(major,minor,build);
|
|
145 |
if (build==999)
|
|
146 |
{
|
|
147 |
break;
|
|
148 |
}
|
|
149 |
build=(build==1? 999: 1);
|
|
150 |
}
|
|
151 |
if (minor==99)
|
|
152 |
{
|
|
153 |
break;
|
|
154 |
}
|
|
155 |
minor=(minor==1? 99: 1);
|
|
156 |
}
|
|
157 |
if (major==99)
|
|
158 |
{
|
|
159 |
break;
|
|
160 |
}
|
|
161 |
major=(major==1? 99: 1);
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
TInt DVersionTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
|
|
166 |
//
|
|
167 |
// Create channel
|
|
168 |
//
|
|
169 |
{
|
|
170 |
return KErrNone;
|
|
171 |
}
|
|
172 |
|
|
173 |
DVersionTest::~DVersionTest()
|
|
174 |
//
|
|
175 |
// Destructor
|
|
176 |
//
|
|
177 |
{
|
|
178 |
}
|
|
179 |
|
|
180 |
TInt DVersionTest::Request(TInt aFunction, TAny* /*a1*/, TAny* /*a2*/)
|
|
181 |
{
|
|
182 |
TInt r=KErrNone;
|
|
183 |
switch (aFunction)
|
|
184 |
{
|
|
185 |
case RVersionTest::EVersionTestName:
|
|
186 |
{
|
|
187 |
//
|
|
188 |
// Test the version name
|
|
189 |
//
|
|
190 |
{
|
|
191 |
for (TInt i=0; i<KNumTVersions; i++)
|
|
192 |
{
|
|
193 |
TPtrC Name=(TPtrC)Names[i];
|
|
194 |
if (iTV[i]->Name().Compare(Name))
|
|
195 |
{
|
|
196 |
r=KErrNotSupported;
|
|
197 |
return r;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
}
|
|
201 |
break;
|
|
202 |
}
|
|
203 |
case RVersionTest::EVersionTestQVS:
|
|
204 |
{
|
|
205 |
//
|
|
206 |
// Check QueryVersionSupported()
|
|
207 |
//
|
|
208 |
for (TInt i=0; i<KNumTVersions; i++)
|
|
209 |
{
|
|
210 |
for (TInt j=0; j<KNumTVersions; j++)
|
|
211 |
{
|
|
212 |
if (Kern::QueryVersionSupported(*iTV[i],*iTV[j])!=QVS(i,j))
|
|
213 |
{
|
|
214 |
r=KErrNotSupported;
|
|
215 |
return r;
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
break;
|
|
221 |
}
|
|
222 |
default:
|
|
223 |
break;
|
|
224 |
}
|
|
225 |
return r;
|
|
226 |
}
|
|
227 |
|
|
228 |
TBool DVersionTest::QVS(TInt aCurrent,TInt aRequested)
|
|
229 |
//
|
|
230 |
// An independent calculation of what QueryVersionSupported should return
|
|
231 |
//
|
|
232 |
{
|
|
233 |
if (aCurrent)
|
|
234 |
aCurrent--;
|
|
235 |
if (aRequested)
|
|
236 |
aRequested--;
|
|
237 |
aCurrent/=3;
|
|
238 |
aRequested/=3;
|
|
239 |
return(aCurrent>=aRequested);
|
|
240 |
}
|