0
|
1 |
// Copyright (c) 2002-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 |
// This file contains the test steps for Unit Test Suite 03 : Filename.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
// EPOC includes
|
|
19 |
#include <e32base.h>
|
|
20 |
|
|
21 |
// Test system includes
|
|
22 |
#include <testframework.h>
|
|
23 |
|
|
24 |
// Specific includes for this test suite
|
|
25 |
#include "TSU_MmTsthStep03.h"
|
|
26 |
#include "TSU_MmTsthSuite03.h"
|
|
27 |
|
|
28 |
// Specific includes for these test steps
|
|
29 |
#include "TSU_MmTsth03.h"
|
|
30 |
#include "TestFramework/Filename.h"
|
|
31 |
|
|
32 |
// --------------------------------------------
|
|
33 |
|
|
34 |
// Unit Test Suite 03 : Filename.cpp
|
|
35 |
// Depends on : none
|
|
36 |
|
|
37 |
// Tests :-
|
|
38 |
// 1. Allocate and deallocate an object
|
|
39 |
// 2. Test assignment overloads
|
|
40 |
// 3. Test copy overloads
|
|
41 |
// 4. Test locate
|
|
42 |
// 5. Test slicing (Left)
|
|
43 |
// 11. Test data scope
|
|
44 |
|
|
45 |
// ---------------------
|
|
46 |
// RTestMmTsthU0301
|
|
47 |
|
|
48 |
RTestMmTsthU0301* RTestMmTsthU0301::NewL()
|
|
49 |
{
|
|
50 |
RTestMmTsthU0301* self = new(ELeave) RTestMmTsthU0301;
|
|
51 |
return self;
|
|
52 |
}
|
|
53 |
|
|
54 |
// Each test step initialises its own name.
|
|
55 |
RTestMmTsthU0301::RTestMmTsthU0301()
|
|
56 |
{
|
|
57 |
iTestStepName = _L("MM-TSTH-U-0301");
|
|
58 |
}
|
|
59 |
|
|
60 |
// preamble
|
|
61 |
TVerdict RTestMmTsthU0301::OpenL()
|
|
62 |
{
|
|
63 |
// stub - to avoid calling RTestStep_MM_TSTH_U_03::OpenL() which
|
|
64 |
// initialises iFileName
|
|
65 |
return iTestStepResult = EPass;
|
|
66 |
}
|
|
67 |
|
|
68 |
// postamble
|
|
69 |
void RTestMmTsthU0301::Close()
|
|
70 |
{
|
|
71 |
}
|
|
72 |
|
|
73 |
// do the test step.
|
|
74 |
TVerdict RTestMmTsthU0301::DoTestStepL()
|
|
75 |
{
|
|
76 |
// NB this test is the test for NewL() therefore it uses
|
|
77 |
// a stubbed preamble / postamble
|
|
78 |
|
|
79 |
INFO_PRINTF1(_L("Create a CFileName"));
|
|
80 |
|
|
81 |
TVerdict currentVerdict = EPass;
|
|
82 |
|
|
83 |
// create a CFileName with NewL
|
|
84 |
CFileName* theFileName = NULL;
|
|
85 |
TRAPD(err, theFileName = CFileName::NewL());
|
|
86 |
if(err != KErrNone)
|
|
87 |
{
|
|
88 |
ERR_PRINTF2(_L("CFileName::NewL left with code %d"), err);
|
|
89 |
return iTestStepResult = EFail;
|
|
90 |
}
|
|
91 |
INFO_PRINTF1(_L("CFileName::NewL succeeded"));
|
|
92 |
delete theFileName;
|
|
93 |
|
|
94 |
// create a CFileName with NewLC
|
|
95 |
CFileName* theLCFileName = NULL;
|
|
96 |
TRAPD(err2, theLCFileName = CFileName::NewLC();
|
|
97 |
CleanupStack::Pop(theLCFileName) );
|
|
98 |
if(err2 != KErrNone)
|
|
99 |
{
|
|
100 |
ERR_PRINTF2(_L("CFileName::NewLC left with code %d"), err2);
|
|
101 |
return iTestStepResult = EFail;
|
|
102 |
}
|
|
103 |
|
|
104 |
INFO_PRINTF1(_L("CFileName::NewLC succeeded"));
|
|
105 |
delete theLCFileName;
|
|
106 |
return iTestStepResult = currentVerdict; // should be EPass if we've got here
|
|
107 |
}
|
|
108 |
|
|
109 |
// ------------------------
|
|
110 |
// RTestMmTsthU0302
|
|
111 |
RTestMmTsthU0302* RTestMmTsthU0302::NewL()
|
|
112 |
{
|
|
113 |
RTestMmTsthU0302* self = new(ELeave) RTestMmTsthU0302;
|
|
114 |
return self;
|
|
115 |
}
|
|
116 |
|
|
117 |
// Each test step initialises its own name.
|
|
118 |
RTestMmTsthU0302::RTestMmTsthU0302()
|
|
119 |
{
|
|
120 |
iTestStepName = _L("MM-TSTH-U-0302");
|
|
121 |
}
|
|
122 |
|
|
123 |
// do the test step.
|
|
124 |
TVerdict RTestMmTsthU0302::DoTestStepL()
|
|
125 |
{
|
|
126 |
const TInt KTestBufSize = 48; // allocate enough space for test strings
|
|
127 |
|
|
128 |
INFO_PRINTF1(_L("Test CFileName assign overloads"));
|
|
129 |
|
|
130 |
TVerdict currentVerdict = EPass;
|
|
131 |
|
|
132 |
// test against TPtrC
|
|
133 |
TPtrC testTPtrCStr = _L("Test TPtrC String");
|
|
134 |
*iFileName = testTPtrCStr;
|
|
135 |
if(testTPtrCStr != iFileName->FileName())
|
|
136 |
{
|
|
137 |
ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed"));
|
|
138 |
return iTestStepResult = EFail;
|
|
139 |
}
|
|
140 |
|
|
141 |
// test against TDesC
|
|
142 |
TBufC<KTestBufSize> testTDesCStr = _L("Test TDesC String");
|
|
143 |
*iFileName = testTDesCStr;
|
|
144 |
if(testTDesCStr != iFileName->FileName())
|
|
145 |
{
|
|
146 |
ERR_PRINTF1(_L("CFileName::operator=(const TDesC&) failed"));
|
|
147 |
return iTestStepResult = EFail;
|
|
148 |
}
|
|
149 |
|
|
150 |
// test against TFileName
|
|
151 |
TFileName testTFileNameStr = _L("Test TFileName String");
|
|
152 |
*iFileName = testTFileNameStr;
|
|
153 |
if(testTFileNameStr != iFileName->FileName())
|
|
154 |
{
|
|
155 |
ERR_PRINTF1(_L("CFileName::operator=(const TFileName&) failed"));
|
|
156 |
return iTestStepResult = EFail;
|
|
157 |
}
|
|
158 |
|
|
159 |
// test against TText*
|
|
160 |
const TText* testTTextStr = _S("Test TText String\0");
|
|
161 |
*iFileName = testTTextStr;
|
|
162 |
// convert testTTextStr for comparison purposes
|
|
163 |
TBuf<KTestBufSize> testCompTTextStr(testTTextStr);
|
|
164 |
if(testCompTTextStr != iFileName->FileName())
|
|
165 |
{
|
|
166 |
ERR_PRINTF1(_L("CFileName::operator=(const TText*) failed"));
|
|
167 |
return iTestStepResult = EFail;
|
|
168 |
}
|
|
169 |
|
|
170 |
// test against self
|
|
171 |
CFileName* testCFileName = CFileName::NewL();
|
|
172 |
*testCFileName = _L("Test CFileName String");
|
|
173 |
*iFileName = *testCFileName;
|
|
174 |
if(testCFileName->FileName() != iFileName->FileName())
|
|
175 |
{
|
|
176 |
ERR_PRINTF1(_L("CFileName::operator=(const CFileName&) failed"));
|
|
177 |
delete testCFileName;
|
|
178 |
return iTestStepResult = EFail;
|
|
179 |
}
|
|
180 |
delete testCFileName;
|
|
181 |
|
|
182 |
return iTestStepResult = currentVerdict; // should be EPass if we've got here
|
|
183 |
|
|
184 |
}
|
|
185 |
|
|
186 |
// ------------------------
|
|
187 |
// RTestMmTsthU0303
|
|
188 |
|
|
189 |
RTestMmTsthU0303* RTestMmTsthU0303::NewL()
|
|
190 |
{
|
|
191 |
RTestMmTsthU0303* self = new(ELeave) RTestMmTsthU0303;
|
|
192 |
return self;
|
|
193 |
}
|
|
194 |
|
|
195 |
// Each test step initialises its own name.
|
|
196 |
RTestMmTsthU0303::RTestMmTsthU0303()
|
|
197 |
{
|
|
198 |
iTestStepName = _L("MM-TSTH-U-0303");
|
|
199 |
}
|
|
200 |
|
|
201 |
// do the test step.
|
|
202 |
TVerdict RTestMmTsthU0303::DoTestStepL()
|
|
203 |
{
|
|
204 |
const TInt KTestBufSize = 48; // allocate enough space for test strings
|
|
205 |
|
|
206 |
INFO_PRINTF1(_L("Test CFileName::Copy"));
|
|
207 |
|
|
208 |
TVerdict currentVerdict = EPass;
|
|
209 |
|
|
210 |
// test against TDesC8
|
|
211 |
TBufC8<KTestBufSize> testTDesC8Str = _L8("Test TDesC8 String");
|
|
212 |
iFileName->Copy(testTDesC8Str);
|
|
213 |
// convert testTDesC8Str for comparison purposes
|
|
214 |
TBuf16<KTestBufSize> testCompTDesC8Str = _L16("Test TDesC8 String");
|
|
215 |
if(testCompTDesC8Str != iFileName->FileName())
|
|
216 |
{
|
|
217 |
ERR_PRINTF1(_L("CFileName::Copy(const TDesC8&) failed"));
|
|
218 |
return iTestStepResult = EFail;
|
|
219 |
}
|
|
220 |
|
|
221 |
// test against TDesC16
|
|
222 |
TBufC16<KTestBufSize> testTDesC16Str = _L16("Test TDesC16 String");
|
|
223 |
iFileName->Copy(testTDesC16Str);
|
|
224 |
if(testTDesC16Str != iFileName->FileName())
|
|
225 |
{
|
|
226 |
ERR_PRINTF1(_L("CFileName::Copy(const TDesC16&) failed"));
|
|
227 |
return iTestStepResult = EFail;
|
|
228 |
}
|
|
229 |
|
|
230 |
// test against TUint16* with length
|
|
231 |
const TUint16* testTUint16Str = _S16("Test TUint16 String");
|
|
232 |
// convert testTUint16Str for comparison purposes
|
|
233 |
TBuf16<KTestBufSize> testCompTUint16Str(testTUint16Str);
|
|
234 |
iFileName->Copy(testTUint16Str, testCompTUint16Str.Length());
|
|
235 |
const TDesC& iFileNameLeft = iFileName->FileName().Left(testCompTUint16Str.Length());
|
|
236 |
if(testCompTUint16Str != iFileNameLeft)
|
|
237 |
{
|
|
238 |
ERR_PRINTF1(_L("CFileName::Copy(const TUint16*, int) failed"));
|
|
239 |
return iTestStepResult = EFail;
|
|
240 |
}
|
|
241 |
|
|
242 |
// test against TUint16* zero terminated
|
|
243 |
const TUint16* testTUint16ZStr = _S16("Test TUint16Z String\0");
|
|
244 |
iFileName->Copy(testTUint16ZStr);
|
|
245 |
// convert testTUint16Str for comparison purposes
|
|
246 |
TBuf16<KTestBufSize> testCompTUint16ZStr(testTUint16ZStr);
|
|
247 |
if(testCompTUint16ZStr != iFileName->FileName())
|
|
248 |
{
|
|
249 |
ERR_PRINTF1(_L("CFileName::Copy(const TUint16*) failed"));
|
|
250 |
return iTestStepResult = EFail;
|
|
251 |
}
|
|
252 |
|
|
253 |
return iTestStepResult = currentVerdict; // should be EPass if we've got here
|
|
254 |
|
|
255 |
}
|
|
256 |
|
|
257 |
// ------------------------
|
|
258 |
// RTestMmTsthU0304
|
|
259 |
RTestMmTsthU0304* RTestMmTsthU0304::NewL()
|
|
260 |
{
|
|
261 |
RTestMmTsthU0304* self = new(ELeave) RTestMmTsthU0304;
|
|
262 |
return self;
|
|
263 |
}
|
|
264 |
|
|
265 |
// Each test step initialises its own name.
|
|
266 |
RTestMmTsthU0304::RTestMmTsthU0304()
|
|
267 |
{
|
|
268 |
iTestStepName = _L("MM-TSTH-U-0304");
|
|
269 |
}
|
|
270 |
|
|
271 |
// Do the test step.
|
|
272 |
TVerdict RTestMmTsthU0304::DoTestStepL()
|
|
273 |
{
|
|
274 |
INFO_PRINTF1(_L("Test CFileName::Locate"));
|
|
275 |
|
|
276 |
TVerdict currentVerdict = EPass;
|
|
277 |
|
|
278 |
// test is inconclusive if the assignment fails
|
|
279 |
TPtrC testLocateStr = _L("ABCDEFG");
|
|
280 |
*iFileName = testLocateStr;
|
|
281 |
if(testLocateStr != iFileName->FileName())
|
|
282 |
{
|
|
283 |
ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test"));
|
|
284 |
return iTestStepResult = EInconclusive;
|
|
285 |
}
|
|
286 |
TInt rc = iFileName->Locate('C');
|
|
287 |
if(rc != 2)
|
|
288 |
{
|
|
289 |
ERR_PRINTF1(_L("CFileName::Locate() failed"));
|
|
290 |
return iTestStepResult = EFail;
|
|
291 |
}
|
|
292 |
rc = iFileName->Locate('Z');
|
|
293 |
if(rc != KErrNotFound)
|
|
294 |
{
|
|
295 |
ERR_PRINTF1(_L("CFileName::Locate() failed"));
|
|
296 |
return iTestStepResult = EFail;
|
|
297 |
}
|
|
298 |
|
|
299 |
return iTestStepResult = currentVerdict; // should be EPass if we've got here
|
|
300 |
}
|
|
301 |
|
|
302 |
// ------------------------
|
|
303 |
// RTestMmTsthU0305
|
|
304 |
|
|
305 |
RTestMmTsthU0305* RTestMmTsthU0305::NewL()
|
|
306 |
{
|
|
307 |
RTestMmTsthU0305* self = new(ELeave) RTestMmTsthU0305;
|
|
308 |
return self;
|
|
309 |
}
|
|
310 |
|
|
311 |
// Each test step initialises its own name.
|
|
312 |
RTestMmTsthU0305::RTestMmTsthU0305()
|
|
313 |
{
|
|
314 |
iTestStepName = _L("MM-TSTH-U-0305");
|
|
315 |
}
|
|
316 |
|
|
317 |
// Do the test step.
|
|
318 |
TVerdict RTestMmTsthU0305::DoTestStepL()
|
|
319 |
{
|
|
320 |
INFO_PRINTF1(_L("Test CFileName::Left"));
|
|
321 |
|
|
322 |
TVerdict currentVerdict = EPass;
|
|
323 |
|
|
324 |
// test is inconclusive if the assignment fails
|
|
325 |
TPtrC testLocateStr = _L("ABCDEFG");
|
|
326 |
*iFileName = testLocateStr;
|
|
327 |
if(testLocateStr != iFileName->FileName())
|
|
328 |
{
|
|
329 |
ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test"));
|
|
330 |
return iTestStepResult = EInconclusive;
|
|
331 |
}
|
|
332 |
const TFileName& iFileNameLeft = iFileName->Left(3);
|
|
333 |
TPtrC testLeftStr = _L("ABC");
|
|
334 |
|
|
335 |
if(testLeftStr != iFileNameLeft)
|
|
336 |
{
|
|
337 |
ERR_PRINTF1(_L("CFileName::Left() failed"));
|
|
338 |
return iTestStepResult = EFail;
|
|
339 |
}
|
|
340 |
|
|
341 |
return iTestStepResult = currentVerdict; // should be EPass if we've got here
|
|
342 |
|
|
343 |
}
|
|
344 |
|
|
345 |
// ------------------------
|
|
346 |
// RTestMmTsthU0311
|
|
347 |
RTestMmTsthU0311* RTestMmTsthU0311::NewL()
|
|
348 |
{
|
|
349 |
RTestMmTsthU0311* self = new(ELeave) RTestMmTsthU0311;
|
|
350 |
return self;
|
|
351 |
}
|
|
352 |
|
|
353 |
// Each test step initialises its own name.
|
|
354 |
RTestMmTsthU0311::RTestMmTsthU0311()
|
|
355 |
{
|
|
356 |
iTestStepName = _L("MM-TSTH-U-0311");
|
|
357 |
}
|
|
358 |
|
|
359 |
// Do the test step.
|
|
360 |
TVerdict RTestMmTsthU0311::DoTestStepL()
|
|
361 |
{
|
|
362 |
const TInt KTestBufSize = 48; // allocate enough space for test strings
|
|
363 |
|
|
364 |
INFO_PRINTF1(_L("Test CFileName memory scope"));
|
|
365 |
|
|
366 |
TVerdict currentVerdict = EPass;
|
|
367 |
|
|
368 |
// send original copied string out of scope, to prove that CFileName
|
|
369 |
// is using its own data space
|
|
370 |
TPtr16 testDynTDesCStr(REINTERPRET_CAST(TUint16*,User::AllocLC(KTestBufSize*2)), 0, KTestBufSize);
|
|
371 |
testDynTDesCStr = _L("Test TDesC String");
|
|
372 |
*iFileName = testDynTDesCStr;
|
|
373 |
|
|
374 |
CleanupStack::PopAndDestroy(); // testDynTDesCStr
|
|
375 |
|
|
376 |
// if iFileName->FileName() is out of scope, this will panic with USER 7. If it doesn't, we've passed
|
|
377 |
TPtrC resStr = iFileName->FileName();
|
|
378 |
INFO_PRINTF2(_L("CFileName::FileName() is '%S'"), &resStr);
|
|
379 |
|
|
380 |
return iTestStepResult = currentVerdict; // should be EPass if we've got here
|
|
381 |
|
|
382 |
}
|