os/mm/mmtestenv/mmtestfwunittest/src/tsu_mmtsth03/TSU_MmTsth03.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmtestenv/mmtestfwunittest/src/tsu_mmtsth03/TSU_MmTsth03.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,382 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// This file contains the test steps for Unit Test Suite 03 : Filename.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +// EPOC includes
    1.22 +#include <e32base.h>
    1.23 +
    1.24 +// Test system includes
    1.25 +#include <testframework.h>
    1.26 +
    1.27 +// Specific includes for this test suite
    1.28 +#include "TSU_MmTsthStep03.h"
    1.29 +#include "TSU_MmTsthSuite03.h"
    1.30 +
    1.31 +// Specific includes for these test steps
    1.32 +#include "TSU_MmTsth03.h"
    1.33 +#include "TestFramework/Filename.h"
    1.34 +
    1.35 +// --------------------------------------------
    1.36 +
    1.37 +// Unit Test Suite 03 : Filename.cpp
    1.38 +// Depends on : none
    1.39 +
    1.40 +// Tests :-
    1.41 +// 1. Allocate and deallocate an object
    1.42 +// 2. Test assignment overloads
    1.43 +// 3. Test copy overloads
    1.44 +// 4. Test locate
    1.45 +// 5. Test slicing (Left)
    1.46 +// 11. Test data scope
    1.47 +
    1.48 +// ---------------------
    1.49 +// RTestMmTsthU0301
    1.50 +
    1.51 +RTestMmTsthU0301* RTestMmTsthU0301::NewL()
    1.52 +	{
    1.53 +	RTestMmTsthU0301* self = new(ELeave) RTestMmTsthU0301;
    1.54 +	return self;
    1.55 +	}
    1.56 +
    1.57 +// Each test step initialises its own name.
    1.58 +RTestMmTsthU0301::RTestMmTsthU0301()
    1.59 +	{
    1.60 +	iTestStepName = _L("MM-TSTH-U-0301");
    1.61 +	}
    1.62 +
    1.63 +// preamble
    1.64 +TVerdict RTestMmTsthU0301::OpenL()
    1.65 +	{
    1.66 +	// stub - to avoid calling RTestStep_MM_TSTH_U_03::OpenL() which
    1.67 +	// initialises iFileName
    1.68 +	return iTestStepResult = EPass;
    1.69 +	}
    1.70 +
    1.71 +// postamble
    1.72 +void RTestMmTsthU0301::Close()
    1.73 +	{
    1.74 +	}
    1.75 +
    1.76 +// do the test step.
    1.77 +TVerdict RTestMmTsthU0301::DoTestStepL()
    1.78 +	{
    1.79 +	// NB this test is the test for NewL() therefore it uses
    1.80 +	// a stubbed preamble / postamble
    1.81 +	
    1.82 +	INFO_PRINTF1(_L("Create a CFileName"));
    1.83 +
    1.84 +	TVerdict currentVerdict = EPass;
    1.85 +
    1.86 +	// create a CFileName with NewL
    1.87 +	CFileName* theFileName = NULL;
    1.88 +	TRAPD(err, theFileName = CFileName::NewL());
    1.89 +	if(err != KErrNone)
    1.90 +		{
    1.91 +		ERR_PRINTF2(_L("CFileName::NewL left with code %d"), err);
    1.92 +		return iTestStepResult = EFail;
    1.93 +		}
    1.94 +	INFO_PRINTF1(_L("CFileName::NewL succeeded"));
    1.95 +	delete theFileName;
    1.96 +
    1.97 +	// create a CFileName with NewLC
    1.98 +	CFileName* theLCFileName = NULL;
    1.99 +	TRAPD(err2, theLCFileName = CFileName::NewLC();
   1.100 +				CleanupStack::Pop(theLCFileName) );
   1.101 +	if(err2 != KErrNone)
   1.102 +		{
   1.103 +		ERR_PRINTF2(_L("CFileName::NewLC left with code %d"), err2);
   1.104 +		return iTestStepResult = EFail;
   1.105 +		}
   1.106 +
   1.107 +	INFO_PRINTF1(_L("CFileName::NewLC succeeded"));
   1.108 +	delete theLCFileName;
   1.109 +	return iTestStepResult = currentVerdict; // should be EPass if we've got here
   1.110 +	}
   1.111 +
   1.112 +// ------------------------
   1.113 +// RTestMmTsthU0302
   1.114 +RTestMmTsthU0302* RTestMmTsthU0302::NewL()
   1.115 +	{
   1.116 +	RTestMmTsthU0302* self = new(ELeave) RTestMmTsthU0302;
   1.117 +	return self;
   1.118 +	}
   1.119 +
   1.120 +// Each test step initialises its own name.
   1.121 +RTestMmTsthU0302::RTestMmTsthU0302()
   1.122 +	{
   1.123 +	iTestStepName = _L("MM-TSTH-U-0302");
   1.124 +	}
   1.125 +
   1.126 +// do the test step.
   1.127 +TVerdict RTestMmTsthU0302::DoTestStepL()
   1.128 +	{
   1.129 +	const TInt KTestBufSize = 48;	// allocate enough space for test strings
   1.130 +
   1.131 +	INFO_PRINTF1(_L("Test CFileName assign overloads"));
   1.132 +
   1.133 +	TVerdict currentVerdict = EPass;
   1.134 +
   1.135 +	// test against TPtrC
   1.136 +	TPtrC testTPtrCStr = _L("Test TPtrC String");
   1.137 +	*iFileName = testTPtrCStr;
   1.138 +	if(testTPtrCStr != iFileName->FileName())
   1.139 +		{
   1.140 +		ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed"));
   1.141 +		return iTestStepResult = EFail;
   1.142 +		}
   1.143 +
   1.144 +	// test against TDesC
   1.145 +	TBufC<KTestBufSize> testTDesCStr = _L("Test TDesC String");
   1.146 +	*iFileName = testTDesCStr;
   1.147 +	if(testTDesCStr != iFileName->FileName())
   1.148 +		{
   1.149 +		ERR_PRINTF1(_L("CFileName::operator=(const TDesC&) failed"));
   1.150 +		return iTestStepResult = EFail;
   1.151 +		}
   1.152 +
   1.153 +	// test against TFileName
   1.154 +	TFileName testTFileNameStr = _L("Test TFileName String");
   1.155 +	*iFileName = testTFileNameStr;
   1.156 +	if(testTFileNameStr != iFileName->FileName())
   1.157 +		{
   1.158 +		ERR_PRINTF1(_L("CFileName::operator=(const TFileName&) failed"));
   1.159 +		return iTestStepResult = EFail;
   1.160 +		}
   1.161 +
   1.162 +	// test against TText*
   1.163 +	const TText* testTTextStr = _S("Test TText String\0");
   1.164 +	*iFileName = testTTextStr;
   1.165 +	// convert testTTextStr for comparison purposes
   1.166 +	TBuf<KTestBufSize> testCompTTextStr(testTTextStr);
   1.167 +	if(testCompTTextStr != iFileName->FileName())
   1.168 +		{
   1.169 +		ERR_PRINTF1(_L("CFileName::operator=(const TText*) failed"));
   1.170 +		return iTestStepResult = EFail;
   1.171 +		}
   1.172 +
   1.173 +	// test against self
   1.174 +	CFileName* testCFileName = CFileName::NewL();
   1.175 +	*testCFileName = _L("Test CFileName String");
   1.176 +	*iFileName = *testCFileName;
   1.177 +	if(testCFileName->FileName() != iFileName->FileName())
   1.178 +		{
   1.179 +		ERR_PRINTF1(_L("CFileName::operator=(const CFileName&) failed"));
   1.180 +		delete testCFileName;
   1.181 +		return iTestStepResult = EFail;
   1.182 +		}
   1.183 +	delete testCFileName;
   1.184 +
   1.185 +	return iTestStepResult = currentVerdict; // should be EPass if we've got here
   1.186 +
   1.187 +	}
   1.188 +
   1.189 +// ------------------------
   1.190 +// RTestMmTsthU0303
   1.191 +
   1.192 +RTestMmTsthU0303* RTestMmTsthU0303::NewL()
   1.193 +	{
   1.194 +	RTestMmTsthU0303* self = new(ELeave) RTestMmTsthU0303;
   1.195 +	return self;
   1.196 +	}
   1.197 +
   1.198 +// Each test step initialises its own name.
   1.199 +RTestMmTsthU0303::RTestMmTsthU0303()
   1.200 +	{
   1.201 +	iTestStepName = _L("MM-TSTH-U-0303");
   1.202 +	}
   1.203 +
   1.204 +// do the test step.
   1.205 +TVerdict RTestMmTsthU0303::DoTestStepL()
   1.206 +	{
   1.207 +	const TInt KTestBufSize = 48;	// allocate enough space for test strings
   1.208 +
   1.209 +	INFO_PRINTF1(_L("Test CFileName::Copy"));
   1.210 +
   1.211 +	TVerdict currentVerdict = EPass;
   1.212 +
   1.213 +	// test against TDesC8
   1.214 +	TBufC8<KTestBufSize> testTDesC8Str = _L8("Test TDesC8 String");
   1.215 +	iFileName->Copy(testTDesC8Str);
   1.216 +	// convert testTDesC8Str for comparison purposes
   1.217 +	TBuf16<KTestBufSize> testCompTDesC8Str = _L16("Test TDesC8 String");
   1.218 +	if(testCompTDesC8Str != iFileName->FileName())
   1.219 +		{
   1.220 +		ERR_PRINTF1(_L("CFileName::Copy(const TDesC8&) failed"));
   1.221 +		return iTestStepResult = EFail;
   1.222 +		}
   1.223 +
   1.224 +	// test against TDesC16
   1.225 +	TBufC16<KTestBufSize> testTDesC16Str = _L16("Test TDesC16 String");
   1.226 +	iFileName->Copy(testTDesC16Str);
   1.227 +	if(testTDesC16Str != iFileName->FileName())
   1.228 +		{
   1.229 +		ERR_PRINTF1(_L("CFileName::Copy(const TDesC16&) failed"));
   1.230 +		return iTestStepResult = EFail;
   1.231 +		}
   1.232 +
   1.233 +	// test against TUint16* with length
   1.234 +	const TUint16* testTUint16Str = _S16("Test TUint16 String");
   1.235 +	// convert testTUint16Str for comparison purposes
   1.236 +	TBuf16<KTestBufSize> testCompTUint16Str(testTUint16Str);
   1.237 +	iFileName->Copy(testTUint16Str, testCompTUint16Str.Length());
   1.238 +	const TDesC& iFileNameLeft = iFileName->FileName().Left(testCompTUint16Str.Length());
   1.239 +	if(testCompTUint16Str != iFileNameLeft)
   1.240 +		{
   1.241 +		ERR_PRINTF1(_L("CFileName::Copy(const TUint16*, int) failed"));
   1.242 +		return iTestStepResult = EFail;
   1.243 +		}
   1.244 +
   1.245 +	// test against TUint16* zero terminated
   1.246 +	const TUint16* testTUint16ZStr = _S16("Test TUint16Z String\0");
   1.247 +	iFileName->Copy(testTUint16ZStr);
   1.248 +	// convert testTUint16Str for comparison purposes
   1.249 +	TBuf16<KTestBufSize> testCompTUint16ZStr(testTUint16ZStr);
   1.250 +	if(testCompTUint16ZStr != iFileName->FileName())
   1.251 +		{
   1.252 +		ERR_PRINTF1(_L("CFileName::Copy(const TUint16*) failed"));
   1.253 +		return iTestStepResult = EFail;
   1.254 +		}
   1.255 +
   1.256 +	return iTestStepResult = currentVerdict; // should be EPass if we've got here
   1.257 +
   1.258 +	}
   1.259 +
   1.260 +// ------------------------
   1.261 +// RTestMmTsthU0304
   1.262 +RTestMmTsthU0304* RTestMmTsthU0304::NewL()
   1.263 +	{
   1.264 +	RTestMmTsthU0304* self = new(ELeave) RTestMmTsthU0304;
   1.265 +	return self;
   1.266 +	}
   1.267 +
   1.268 +// Each test step initialises its own name.
   1.269 +RTestMmTsthU0304::RTestMmTsthU0304()
   1.270 +	{
   1.271 +	iTestStepName = _L("MM-TSTH-U-0304");
   1.272 +	}
   1.273 +
   1.274 +// Do the test step.
   1.275 +TVerdict RTestMmTsthU0304::DoTestStepL()
   1.276 +	{
   1.277 +	INFO_PRINTF1(_L("Test CFileName::Locate"));
   1.278 +
   1.279 +	TVerdict currentVerdict = EPass;
   1.280 +
   1.281 +	// test is inconclusive if the assignment fails
   1.282 +	TPtrC testLocateStr = _L("ABCDEFG");
   1.283 +	*iFileName = testLocateStr;
   1.284 +	if(testLocateStr != iFileName->FileName())
   1.285 +		{
   1.286 +		ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test"));
   1.287 +		return iTestStepResult = EInconclusive;
   1.288 +		}
   1.289 +	TInt rc = iFileName->Locate('C');
   1.290 +	if(rc != 2)
   1.291 +		{
   1.292 +		ERR_PRINTF1(_L("CFileName::Locate() failed"));
   1.293 +		return iTestStepResult = EFail;
   1.294 +		}
   1.295 +	rc = iFileName->Locate('Z');
   1.296 +	if(rc != KErrNotFound)
   1.297 +		{
   1.298 +		ERR_PRINTF1(_L("CFileName::Locate() failed"));
   1.299 +		return iTestStepResult = EFail;
   1.300 +		}
   1.301 +
   1.302 +	return iTestStepResult = currentVerdict; // should be EPass if we've got here
   1.303 +	}
   1.304 +
   1.305 +// ------------------------
   1.306 +// RTestMmTsthU0305
   1.307 +
   1.308 +RTestMmTsthU0305* RTestMmTsthU0305::NewL()
   1.309 +	{
   1.310 +	RTestMmTsthU0305* self = new(ELeave) RTestMmTsthU0305;
   1.311 +	return self;
   1.312 +	}
   1.313 +
   1.314 +// Each test step initialises its own name.
   1.315 +RTestMmTsthU0305::RTestMmTsthU0305()
   1.316 +	{
   1.317 +	iTestStepName = _L("MM-TSTH-U-0305");
   1.318 +	}
   1.319 +
   1.320 +// Do the test step.
   1.321 +TVerdict RTestMmTsthU0305::DoTestStepL()
   1.322 +	{
   1.323 +	INFO_PRINTF1(_L("Test CFileName::Left"));
   1.324 +
   1.325 +	TVerdict currentVerdict = EPass;
   1.326 +
   1.327 +	// test is inconclusive if the assignment fails
   1.328 +	TPtrC testLocateStr = _L("ABCDEFG");
   1.329 +	*iFileName = testLocateStr;
   1.330 +	if(testLocateStr != iFileName->FileName())
   1.331 +		{
   1.332 +		ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test"));
   1.333 +		return iTestStepResult = EInconclusive;
   1.334 +		}
   1.335 +	const TFileName& iFileNameLeft = iFileName->Left(3);
   1.336 +	TPtrC testLeftStr = _L("ABC");
   1.337 +
   1.338 +	if(testLeftStr != iFileNameLeft)
   1.339 +		{
   1.340 +		ERR_PRINTF1(_L("CFileName::Left() failed"));
   1.341 +		return iTestStepResult = EFail;
   1.342 +		}
   1.343 +
   1.344 +	return iTestStepResult = currentVerdict; // should be EPass if we've got here
   1.345 +
   1.346 +	}
   1.347 +
   1.348 +// ------------------------
   1.349 +// RTestMmTsthU0311
   1.350 +RTestMmTsthU0311* RTestMmTsthU0311::NewL()
   1.351 +	{
   1.352 +	RTestMmTsthU0311* self = new(ELeave) RTestMmTsthU0311;
   1.353 +	return self;
   1.354 +	}
   1.355 +
   1.356 +// Each test step initialises its own name.
   1.357 +RTestMmTsthU0311::RTestMmTsthU0311()
   1.358 +	{
   1.359 +	iTestStepName = _L("MM-TSTH-U-0311");
   1.360 +	}
   1.361 +
   1.362 +// Do the test step.
   1.363 +TVerdict RTestMmTsthU0311::DoTestStepL()
   1.364 +	{
   1.365 +	const TInt KTestBufSize = 48;	// allocate enough space for test strings
   1.366 +
   1.367 +	INFO_PRINTF1(_L("Test CFileName memory scope"));
   1.368 +
   1.369 +	TVerdict currentVerdict = EPass;
   1.370 +
   1.371 +	// send original copied string out of scope, to prove that CFileName
   1.372 +	// is using its own data space
   1.373 +	TPtr16 testDynTDesCStr(REINTERPRET_CAST(TUint16*,User::AllocLC(KTestBufSize*2)), 0, KTestBufSize);
   1.374 +	testDynTDesCStr = _L("Test TDesC String");
   1.375 +	*iFileName = testDynTDesCStr;
   1.376 +
   1.377 +	CleanupStack::PopAndDestroy(); // testDynTDesCStr
   1.378 +
   1.379 +	// if iFileName->FileName() is out of scope, this will panic with USER 7. If it doesn't, we've passed
   1.380 +	TPtrC resStr = iFileName->FileName();
   1.381 +	INFO_PRINTF2(_L("CFileName::FileName() is '%S'"), &resStr);
   1.382 +
   1.383 +	return iTestStepResult = currentVerdict; // should be EPass if we've got here
   1.384 +
   1.385 +	}