0
|
1 |
// Copyright (c) 2006-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 |
#include <f32file.h>
|
|
17 |
#include "tsu_mmf_mmruf_step.h"
|
|
18 |
|
|
19 |
static const TInt KTestStepNameSize = 22; // MM-MMF-MMRUF-U-xxxx-HP
|
|
20 |
|
|
21 |
/*
|
|
22 |
**
|
|
23 |
*/
|
|
24 |
RMMRUFTestStep::RMMRUFTestStep(const TTestSpec* aTestSpec)
|
|
25 |
: iTestSpec(aTestSpec)
|
|
26 |
{
|
|
27 |
ASSERT(iTestSpec != NULL);
|
|
28 |
|
|
29 |
_LIT(KTestStep, "MM-MMF-MMRUF-U-%04d-HP");
|
|
30 |
|
|
31 |
TBuf<KTestStepNameSize> temp;
|
|
32 |
temp.Zero();
|
|
33 |
temp.AppendFormat(KTestStep, iTestSpec->iTestNumber);
|
|
34 |
iTestStepName = temp;
|
|
35 |
}
|
|
36 |
|
|
37 |
/*
|
|
38 |
**
|
|
39 |
*/
|
|
40 |
RMMRUFTestStep::~RMMRUFTestStep()
|
|
41 |
{
|
|
42 |
Close();
|
|
43 |
}
|
|
44 |
|
|
45 |
/*
|
|
46 |
**
|
|
47 |
*/
|
|
48 |
RMMRUFTestStep* RMMRUFTestStep::NewL(const TTestSpec* aTestSpec)
|
|
49 |
{
|
|
50 |
return new(ELeave) RMMRUFTestStep(aTestSpec);
|
|
51 |
}
|
|
52 |
|
|
53 |
/*
|
|
54 |
**
|
|
55 |
*/
|
|
56 |
TVerdict RMMRUFTestStep::DoTestStepPreambleL()
|
|
57 |
{
|
|
58 |
User::LeaveIfError(iAppArc.Connect());
|
|
59 |
return EPass;
|
|
60 |
}
|
|
61 |
|
|
62 |
/*
|
|
63 |
**
|
|
64 |
*/
|
|
65 |
TVerdict RMMRUFTestStep::DoTestStepPostambleL()
|
|
66 |
{
|
|
67 |
iAppArc.Close();
|
|
68 |
return EPass;
|
|
69 |
}
|
|
70 |
|
|
71 |
/*
|
|
72 |
**
|
|
73 |
*/
|
|
74 |
TVerdict RMMRUFTestStep::DoTestStepL()
|
|
75 |
{
|
|
76 |
iTestStepResult = EFail;
|
|
77 |
TPtrC filename(iTestSpec->iFileName);
|
|
78 |
INFO_PRINTF2(_L("Testing file: %S"), &filename);
|
|
79 |
|
|
80 |
RFile file;
|
|
81 |
TInt err = file.Open(iAppArc.FileServer(), filename, EFileRead | EFileShareAny);
|
|
82 |
if (err != KErrNone)
|
|
83 |
{
|
|
84 |
INFO_PRINTF3(_L("RFile.Open(\"%S\") failed: %d"), &filename, err);
|
|
85 |
User::Leave(err);
|
|
86 |
}
|
|
87 |
|
|
88 |
CleanupClosePushL(file);
|
|
89 |
TDataRecognitionResult dataType;
|
|
90 |
err = iAppArc.Recognise(file, dataType);
|
|
91 |
if (err != KErrNone)
|
|
92 |
{
|
|
93 |
iTestStepResult = EInconclusive;
|
|
94 |
INFO_PRINTF2(_L("RApaLsSession.RecognizeData() failed: %d"), err);
|
|
95 |
User::Leave(err);
|
|
96 |
}
|
|
97 |
|
|
98 |
CleanupStack::Pop(); // file
|
|
99 |
|
|
100 |
// Check the results.
|
|
101 |
TPtrC8 resMime(dataType.iDataType.Des8());
|
|
102 |
TPtrC8 expectedMime(iTestSpec->iExpectedMimeType);
|
|
103 |
|
|
104 |
if (expectedMime.Compare(resMime) == 0)
|
|
105 |
{
|
|
106 |
if (iTestSpec->iTestNumber >= 600)
|
|
107 |
{
|
|
108 |
// Negative testing above 600
|
|
109 |
// These are negative tests. So Mime type must be empty
|
|
110 |
if (resMime.Compare(_L8("")) == 0)
|
|
111 |
{
|
|
112 |
iTestStepResult = EPass;
|
|
113 |
return iTestStepResult;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
// DEF129505 - MMRuf incorrectly recognises unicode text files as MP3 files
|
|
117 |
else if (iTestSpec->iTestNumber == 500)
|
|
118 |
{
|
|
119 |
iTestStepResult = EPass;
|
|
120 |
return iTestStepResult;
|
|
121 |
}
|
|
122 |
|
|
123 |
// Set the result to EFail initially and change it to EPass
|
|
124 |
// further down in the code after checking the expected confidence.
|
|
125 |
iTestStepResult = EFail;
|
|
126 |
TBuf<64> confidence;
|
|
127 |
switch (dataType.iConfidence)
|
|
128 |
{
|
|
129 |
case KConfCertain:
|
|
130 |
confidence.Copy(_L("KConfCertain"));
|
|
131 |
break;
|
|
132 |
case KConfProbable:
|
|
133 |
confidence.Copy(_L("KConfProbable"));
|
|
134 |
break;
|
|
135 |
case KConfPossible:
|
|
136 |
confidence.Copy(_L("KConfPossible"));
|
|
137 |
break;
|
|
138 |
case KConfNotRecognised:
|
|
139 |
confidence.Copy(_L("KConfNotRecognised"));
|
|
140 |
break;
|
|
141 |
default:
|
|
142 |
// Safe Guard: This will never happen
|
|
143 |
break;
|
|
144 |
}
|
|
145 |
|
|
146 |
// #############################################################
|
|
147 |
// SPECIAL CASES: There are some formats that are never recognised
|
|
148 |
// with confidence = ECertain. Deal with these here.
|
|
149 |
switch (iTestSpec->iTestNumber)
|
|
150 |
{
|
|
151 |
case 55: // RAM.
|
|
152 |
case 115: // SDP
|
|
153 |
case 116: // SDP
|
|
154 |
case 117: // SDP
|
|
155 |
case 118: // SDP
|
|
156 |
case 119: // SDP
|
|
157 |
case 120: // SDP
|
|
158 |
case 121: // SDP
|
|
159 |
case 122: // SDP
|
|
160 |
if (dataType.iConfidence != KConfProbable)
|
|
161 |
{
|
|
162 |
INFO_PRINTF2(_L("Bad confidence level: %S, expected KConfProbable"), &confidence);
|
|
163 |
}
|
|
164 |
else
|
|
165 |
{
|
|
166 |
iTestStepResult = EPass;
|
|
167 |
}
|
|
168 |
|
|
169 |
return iTestStepResult;
|
|
170 |
|
|
171 |
default:
|
|
172 |
// Deliberate fall-through.
|
|
173 |
break;
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
// Mod of 3 cos there are 3 test cases for each format
|
|
178 |
TInt res = iTestSpec->iTestNumber % 3;
|
|
179 |
switch (res)
|
|
180 |
{
|
|
181 |
case 1:
|
|
182 |
// 1st test
|
|
183 |
// Buffer Data and file extension are correct.
|
|
184 |
if (dataType.iConfidence == KConfCertain)
|
|
185 |
{
|
|
186 |
iTestStepResult = EPass;
|
|
187 |
}
|
|
188 |
else
|
|
189 |
{
|
|
190 |
INFO_PRINTF2(_L("Returned Wrong Confidence Value: %S, expected KConfCertain"), &confidence);
|
|
191 |
}
|
|
192 |
break;
|
|
193 |
|
|
194 |
case 2:
|
|
195 |
// 2nd test
|
|
196 |
// Buffer data is correct, but the file extension is incorrect.
|
|
197 |
if (dataType.iConfidence >= KConfProbable)
|
|
198 |
{
|
|
199 |
iTestStepResult = EPass;
|
|
200 |
}
|
|
201 |
else
|
|
202 |
{
|
|
203 |
INFO_PRINTF2(_L("Returned Wrong Confidence Value: %S, expected KConfProbable"), &confidence);
|
|
204 |
}
|
|
205 |
break;
|
|
206 |
|
|
207 |
case 0:
|
|
208 |
// 3rd test
|
|
209 |
// Buffer data is unknown and file extension exists.
|
|
210 |
if (dataType.iConfidence >= KConfPossible)
|
|
211 |
{
|
|
212 |
iTestStepResult = EPass;
|
|
213 |
}
|
|
214 |
else
|
|
215 |
{
|
|
216 |
INFO_PRINTF2(_L("Returned Wrong Confidence Value: %S, expected KConfPossible"), &confidence);
|
|
217 |
}
|
|
218 |
break;
|
|
219 |
|
|
220 |
default:
|
|
221 |
// Safe Guard: This must never happen
|
|
222 |
break;
|
|
223 |
}
|
|
224 |
}
|
|
225 |
else
|
|
226 |
{
|
|
227 |
TBuf<KMaxDataTypeLength> returned;
|
|
228 |
returned.Copy(dataType.iDataType.Des());
|
|
229 |
INFO_PRINTF2(_L("- wrong returned MIME-type: %S"), &returned);
|
|
230 |
iTestStepResult = EFail;
|
|
231 |
}
|
|
232 |
return iTestStepResult;
|
|
233 |
}
|
|
234 |
|
|
235 |
|
|
236 |
//
|
|
237 |
// OOM Tests
|
|
238 |
//
|
|
239 |
|
|
240 |
/*
|
|
241 |
**
|
|
242 |
*/
|
|
243 |
RTestStepMMRUFOOM* RTestStepMMRUFOOM::NewL(const TTestSpec* aTestSpec)
|
|
244 |
{
|
|
245 |
return new(ELeave) RTestStepMMRUFOOM(aTestSpec);
|
|
246 |
}
|
|
247 |
|
|
248 |
/*
|
|
249 |
**
|
|
250 |
*/
|
|
251 |
RTestStepMMRUFOOM::RTestStepMMRUFOOM(const TTestSpec* aTestSpec)
|
|
252 |
:iTestSpec(aTestSpec)
|
|
253 |
{
|
|
254 |
ASSERT(iTestSpec != NULL);
|
|
255 |
|
|
256 |
_LIT(KAllocTestStep, "MM-MMF-MMRUF-U-%04d-CP");
|
|
257 |
|
|
258 |
TBuf<KTestStepNameSize> temp;
|
|
259 |
temp.Zero();
|
|
260 |
temp.AppendFormat(KAllocTestStep, iTestSpec->iTestNumber);
|
|
261 |
iTestStepName = temp;
|
|
262 |
}
|
|
263 |
|
|
264 |
/*
|
|
265 |
**
|
|
266 |
*/
|
|
267 |
TVerdict RTestStepMMRUFOOM::DoTestStepPreambleL()
|
|
268 |
{
|
|
269 |
User::LeaveIfError(iAppArc.Connect());
|
|
270 |
return EPass;
|
|
271 |
}
|
|
272 |
|
|
273 |
/*
|
|
274 |
**
|
|
275 |
*/
|
|
276 |
TVerdict RTestStepMMRUFOOM::DoTestStepPostambleL()
|
|
277 |
{
|
|
278 |
iAppArc.Close();
|
|
279 |
return EPass;
|
|
280 |
}
|
|
281 |
|
|
282 |
/*
|
|
283 |
**
|
|
284 |
*/
|
|
285 |
TVerdict RTestStepMMRUFOOM::DoTestStepL()
|
|
286 |
{
|
|
287 |
TInt err;
|
|
288 |
TDataRecognitionResult dataType;
|
|
289 |
TPtrC filename(iTestSpec->iFileName);
|
|
290 |
RFile file;
|
|
291 |
TInt failCount = 1;
|
|
292 |
TBool completed;
|
|
293 |
TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
|
|
294 |
|
|
295 |
|
|
296 |
iTestStepResult = EFail;
|
|
297 |
err = file.Open(iAppArc.FileServer(), filename, EFileRead | EFileShareAny);
|
|
298 |
if (err != KErrNone)
|
|
299 |
{
|
|
300 |
INFO_PRINTF2(_L("RFile.Open() failed: %d"), err);
|
|
301 |
User::Leave(err);
|
|
302 |
}
|
|
303 |
CleanupClosePushL(file);
|
|
304 |
|
|
305 |
FOREVER
|
|
306 |
{
|
|
307 |
__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
|
|
308 |
|
|
309 |
iTestStepResult = EFail;
|
|
310 |
// We will check 1000 Allocations as this is a non leaving function.
|
|
311 |
err = iAppArc.Recognise(file, dataType);
|
|
312 |
if (err != KErrNone)
|
|
313 |
{
|
|
314 |
INFO_PRINTF2(_L("RApaLsSession.RecognizeData() failed: %d"), err);
|
|
315 |
iTestStepResult = EInconclusive;
|
|
316 |
}
|
|
317 |
|
|
318 |
completed = EFalse;
|
|
319 |
if (err == KErrNone)
|
|
320 |
{
|
|
321 |
if (iTestStepResult == EPass)
|
|
322 |
{
|
|
323 |
TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
|
|
324 |
if (testAlloc==NULL)
|
|
325 |
{
|
|
326 |
reachedEnd = ETrue;
|
|
327 |
failCount--; // -= 1;
|
|
328 |
}
|
|
329 |
else
|
|
330 |
{
|
|
331 |
User::Free(testAlloc);
|
|
332 |
}
|
|
333 |
completed = reachedEnd;
|
|
334 |
}
|
|
335 |
else
|
|
336 |
{
|
|
337 |
// the test failed but we have already proved above
|
|
338 |
// that the required plugins are present
|
|
339 |
// therefore we assume that the interface returned
|
|
340 |
// a NULL pointer and so we can continue to test
|
|
341 |
// until the timeout or the fail count exceeds
|
|
342 |
completed = EFalse;
|
|
343 |
}
|
|
344 |
}
|
|
345 |
else if (err == KErrNotSupported)
|
|
346 |
{
|
|
347 |
// the test has returned not supported but we already
|
|
348 |
// know that the interface *is* supported so we assume
|
|
349 |
// that the interface creation failed due to lack of
|
|
350 |
// memory and so we continue to test until the timeout
|
|
351 |
// or we exceed the fail count
|
|
352 |
completed = EFalse;
|
|
353 |
}
|
|
354 |
else if (err != KErrNoMemory) // bad error code
|
|
355 |
{
|
|
356 |
completed = ETrue;
|
|
357 |
}
|
|
358 |
|
|
359 |
__UHEAP_SETFAIL(RHeap::ENone ,0);
|
|
360 |
|
|
361 |
// if we have completed successfully or we have exceeded
|
|
362 |
// a 1000 failed ALLOC attempts then quit
|
|
363 |
if (completed || failCount > 1000)
|
|
364 |
{
|
|
365 |
break; // exit loop
|
|
366 |
}
|
|
367 |
|
|
368 |
failCount++;
|
|
369 |
}
|
|
370 |
|
|
371 |
// finished with test
|
|
372 |
CleanupStack::Pop(); //file
|
|
373 |
|
|
374 |
if (err != KErrNone)
|
|
375 |
{
|
|
376 |
INFO_PRINTF3(_L(" Error(%d) with %d memory allocations tested"), err, failCount);
|
|
377 |
User::LeaveIfError(err);
|
|
378 |
}
|
|
379 |
else
|
|
380 |
{
|
|
381 |
INFO_PRINTF2(_L(" Completed OK with %d memory allocations tested"), failCount);
|
|
382 |
iTestStepResult = EPass;
|
|
383 |
}
|
|
384 |
|
|
385 |
TPtrC8 resMime(dataType.iDataType.Des8());
|
|
386 |
TPtrC8 expectedMime(iTestSpec->iExpectedMimeType);
|
|
387 |
|
|
388 |
TBuf<KMaxDataTypeLength> returned;
|
|
389 |
returned.Copy(dataType.iDataType.Des());
|
|
390 |
|
|
391 |
if (expectedMime.Compare(resMime) == 0)
|
|
392 |
{
|
|
393 |
INFO_PRINTF2(_L("Matched Expected MIME-type: %S"), &returned);
|
|
394 |
iTestStepResult = EPass;
|
|
395 |
}
|
|
396 |
else
|
|
397 |
{
|
|
398 |
INFO_PRINTF2(_L("- wrong returned MIME-type: %S"), &returned);
|
|
399 |
iTestStepResult = EFail;
|
|
400 |
}
|
|
401 |
INFO_PRINTF1(_L("finished with this test step"));
|
|
402 |
// test steps return a result
|
|
403 |
return iTestStepResult;
|
|
404 |
}
|
|
405 |
|