Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This file contains the test steps for Unit Test Suite 03 : Filename.cpp
21 // Test system includes
22 #include <testframework.h>
24 // Specific includes for this test suite
25 #include "TSU_MmTsthStep03.h"
26 #include "TSU_MmTsthSuite03.h"
28 // Specific includes for these test steps
29 #include "TSU_MmTsth03.h"
30 #include "TestFramework/Filename.h"
32 // --------------------------------------------
34 // Unit Test Suite 03 : Filename.cpp
38 // 1. Allocate and deallocate an object
39 // 2. Test assignment overloads
40 // 3. Test copy overloads
42 // 5. Test slicing (Left)
43 // 11. Test data scope
45 // ---------------------
48 RTestMmTsthU0301* RTestMmTsthU0301::NewL()
50 RTestMmTsthU0301* self = new(ELeave) RTestMmTsthU0301;
54 // Each test step initialises its own name.
55 RTestMmTsthU0301::RTestMmTsthU0301()
57 iTestStepName = _L("MM-TSTH-U-0301");
61 TVerdict RTestMmTsthU0301::OpenL()
63 // stub - to avoid calling RTestStep_MM_TSTH_U_03::OpenL() which
64 // initialises iFileName
65 return iTestStepResult = EPass;
69 void RTestMmTsthU0301::Close()
74 TVerdict RTestMmTsthU0301::DoTestStepL()
76 // NB this test is the test for NewL() therefore it uses
77 // a stubbed preamble / postamble
79 INFO_PRINTF1(_L("Create a CFileName"));
81 TVerdict currentVerdict = EPass;
83 // create a CFileName with NewL
84 CFileName* theFileName = NULL;
85 TRAPD(err, theFileName = CFileName::NewL());
88 ERR_PRINTF2(_L("CFileName::NewL left with code %d"), err);
89 return iTestStepResult = EFail;
91 INFO_PRINTF1(_L("CFileName::NewL succeeded"));
94 // create a CFileName with NewLC
95 CFileName* theLCFileName = NULL;
96 TRAPD(err2, theLCFileName = CFileName::NewLC();
97 CleanupStack::Pop(theLCFileName) );
100 ERR_PRINTF2(_L("CFileName::NewLC left with code %d"), err2);
101 return iTestStepResult = EFail;
104 INFO_PRINTF1(_L("CFileName::NewLC succeeded"));
105 delete theLCFileName;
106 return iTestStepResult = currentVerdict; // should be EPass if we've got here
109 // ------------------------
111 RTestMmTsthU0302* RTestMmTsthU0302::NewL()
113 RTestMmTsthU0302* self = new(ELeave) RTestMmTsthU0302;
117 // Each test step initialises its own name.
118 RTestMmTsthU0302::RTestMmTsthU0302()
120 iTestStepName = _L("MM-TSTH-U-0302");
124 TVerdict RTestMmTsthU0302::DoTestStepL()
126 const TInt KTestBufSize = 48; // allocate enough space for test strings
128 INFO_PRINTF1(_L("Test CFileName assign overloads"));
130 TVerdict currentVerdict = EPass;
132 // test against TPtrC
133 TPtrC testTPtrCStr = _L("Test TPtrC String");
134 *iFileName = testTPtrCStr;
135 if(testTPtrCStr != iFileName->FileName())
137 ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed"));
138 return iTestStepResult = EFail;
141 // test against TDesC
142 TBufC<KTestBufSize> testTDesCStr = _L("Test TDesC String");
143 *iFileName = testTDesCStr;
144 if(testTDesCStr != iFileName->FileName())
146 ERR_PRINTF1(_L("CFileName::operator=(const TDesC&) failed"));
147 return iTestStepResult = EFail;
150 // test against TFileName
151 TFileName testTFileNameStr = _L("Test TFileName String");
152 *iFileName = testTFileNameStr;
153 if(testTFileNameStr != iFileName->FileName())
155 ERR_PRINTF1(_L("CFileName::operator=(const TFileName&) failed"));
156 return iTestStepResult = EFail;
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())
166 ERR_PRINTF1(_L("CFileName::operator=(const TText*) failed"));
167 return iTestStepResult = EFail;
171 CFileName* testCFileName = CFileName::NewL();
172 *testCFileName = _L("Test CFileName String");
173 *iFileName = *testCFileName;
174 if(testCFileName->FileName() != iFileName->FileName())
176 ERR_PRINTF1(_L("CFileName::operator=(const CFileName&) failed"));
177 delete testCFileName;
178 return iTestStepResult = EFail;
180 delete testCFileName;
182 return iTestStepResult = currentVerdict; // should be EPass if we've got here
186 // ------------------------
189 RTestMmTsthU0303* RTestMmTsthU0303::NewL()
191 RTestMmTsthU0303* self = new(ELeave) RTestMmTsthU0303;
195 // Each test step initialises its own name.
196 RTestMmTsthU0303::RTestMmTsthU0303()
198 iTestStepName = _L("MM-TSTH-U-0303");
202 TVerdict RTestMmTsthU0303::DoTestStepL()
204 const TInt KTestBufSize = 48; // allocate enough space for test strings
206 INFO_PRINTF1(_L("Test CFileName::Copy"));
208 TVerdict currentVerdict = EPass;
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())
217 ERR_PRINTF1(_L("CFileName::Copy(const TDesC8&) failed"));
218 return iTestStepResult = EFail;
221 // test against TDesC16
222 TBufC16<KTestBufSize> testTDesC16Str = _L16("Test TDesC16 String");
223 iFileName->Copy(testTDesC16Str);
224 if(testTDesC16Str != iFileName->FileName())
226 ERR_PRINTF1(_L("CFileName::Copy(const TDesC16&) failed"));
227 return iTestStepResult = EFail;
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)
238 ERR_PRINTF1(_L("CFileName::Copy(const TUint16*, int) failed"));
239 return iTestStepResult = EFail;
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())
249 ERR_PRINTF1(_L("CFileName::Copy(const TUint16*) failed"));
250 return iTestStepResult = EFail;
253 return iTestStepResult = currentVerdict; // should be EPass if we've got here
257 // ------------------------
259 RTestMmTsthU0304* RTestMmTsthU0304::NewL()
261 RTestMmTsthU0304* self = new(ELeave) RTestMmTsthU0304;
265 // Each test step initialises its own name.
266 RTestMmTsthU0304::RTestMmTsthU0304()
268 iTestStepName = _L("MM-TSTH-U-0304");
272 TVerdict RTestMmTsthU0304::DoTestStepL()
274 INFO_PRINTF1(_L("Test CFileName::Locate"));
276 TVerdict currentVerdict = EPass;
278 // test is inconclusive if the assignment fails
279 TPtrC testLocateStr = _L("ABCDEFG");
280 *iFileName = testLocateStr;
281 if(testLocateStr != iFileName->FileName())
283 ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test"));
284 return iTestStepResult = EInconclusive;
286 TInt rc = iFileName->Locate('C');
289 ERR_PRINTF1(_L("CFileName::Locate() failed"));
290 return iTestStepResult = EFail;
292 rc = iFileName->Locate('Z');
293 if(rc != KErrNotFound)
295 ERR_PRINTF1(_L("CFileName::Locate() failed"));
296 return iTestStepResult = EFail;
299 return iTestStepResult = currentVerdict; // should be EPass if we've got here
302 // ------------------------
305 RTestMmTsthU0305* RTestMmTsthU0305::NewL()
307 RTestMmTsthU0305* self = new(ELeave) RTestMmTsthU0305;
311 // Each test step initialises its own name.
312 RTestMmTsthU0305::RTestMmTsthU0305()
314 iTestStepName = _L("MM-TSTH-U-0305");
318 TVerdict RTestMmTsthU0305::DoTestStepL()
320 INFO_PRINTF1(_L("Test CFileName::Left"));
322 TVerdict currentVerdict = EPass;
324 // test is inconclusive if the assignment fails
325 TPtrC testLocateStr = _L("ABCDEFG");
326 *iFileName = testLocateStr;
327 if(testLocateStr != iFileName->FileName())
329 ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test"));
330 return iTestStepResult = EInconclusive;
332 const TFileName& iFileNameLeft = iFileName->Left(3);
333 TPtrC testLeftStr = _L("ABC");
335 if(testLeftStr != iFileNameLeft)
337 ERR_PRINTF1(_L("CFileName::Left() failed"));
338 return iTestStepResult = EFail;
341 return iTestStepResult = currentVerdict; // should be EPass if we've got here
345 // ------------------------
347 RTestMmTsthU0311* RTestMmTsthU0311::NewL()
349 RTestMmTsthU0311* self = new(ELeave) RTestMmTsthU0311;
353 // Each test step initialises its own name.
354 RTestMmTsthU0311::RTestMmTsthU0311()
356 iTestStepName = _L("MM-TSTH-U-0311");
360 TVerdict RTestMmTsthU0311::DoTestStepL()
362 const TInt KTestBufSize = 48; // allocate enough space for test strings
364 INFO_PRINTF1(_L("Test CFileName memory scope"));
366 TVerdict currentVerdict = EPass;
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;
374 CleanupStack::PopAndDestroy(); // testDynTDesCStr
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);
380 return iTestStepResult = currentVerdict; // should be EPass if we've got here