os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_cacheddriveinfo/t_cacheddriveinfo.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_cacheddriveinfo/t_cacheddriveinfo.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,263 @@
     1.4 +// Copyright (c) 2006-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 +//
    1.18 +
    1.19 +#include <bsul/bsul.h>
    1.20 +#include <e32test.h>
    1.21 +#include <bautils.h>
    1.22 +
    1.23 +LOCAL_D RTest theTest(_L("t_cacheddriveinfo"));
    1.24 +
    1.25 +// Valid Paths / Folder Name
    1.26 +const TPtrC KValidPathNameCSystem1Data1=_L("C:\\System1\\Data1\\");
    1.27 +const TPtrC KValidDriveZ=_L("Z:\\");
    1.28 +const TPtrC KValidDriveC=_L("C:\\");
    1.29 +const TPtrC KValidDriveT=_L("T:\\");
    1.30 +const TPtrC KValidDriveE=_L("E:\\");
    1.31 +
    1.32 +// InValid Paths / Folder Names
    1.33 +const TPtrC KNoParameters=_L("");
    1.34 +const TPtrC KInValidParameters=_L("3: \\52324424");
    1.35 +const TPtrC KInValidDriveP=_L("P:\\");
    1.36 +
    1.37 +//
    1.38 +//Test macroses and functions
    1.39 +LOCAL_C void Check(TInt aValue, TInt aLine)
    1.40 +	{
    1.41 +	if(!aValue)
    1.42 +		{
    1.43 +		theTest(EFalse, aLine);
    1.44 +		}
    1.45 +	}
    1.46 +#define TEST(arg) ::Check((arg), __LINE__)
    1.47 +
    1.48 +/**
    1.49 +@SYMTestCaseID SYSLIB-BAFL-CT-1393
    1.50 +@SYMTestCaseDesc Tests BSUL::CCachedDriveInfo
    1.51 +@SYMTestPriority Medium
    1.52 +@SYMTestActions Pass in various drives and parameters and checks 'Read Only Internal' status.
    1.53 +				The same parameters are checked as in the tests for BaflUtils::DriveIsReadOnlyInternal
    1.54 +@SYMTestExpectedResults The test must not fail.
    1.55 +*/
    1.56 +void TestCachedDriveInfoL(RFs& aFs)
    1.57 +	{
    1.58 +	theTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1393 "));
    1.59 +	BSUL::CCachedDriveInfo *cachedDriveInfo = BSUL::CCachedDriveInfo::NewLC(aFs);
    1.60 +
    1.61 +	// the C drive should not be read-only internal
    1.62 +	TEST(!cachedDriveInfo->IsReadOnlyInternalL(KValidPathNameCSystem1Data1));
    1.63 +	// the Z drive should be read-only internal
    1.64 +	TEST(cachedDriveInfo->IsReadOnlyInternalL(KValidDriveZ));
    1.65 +	// a non-mounted drive should not be read-only internal
    1.66 +	TEST(!cachedDriveInfo->IsReadOnlyInternalL(KInValidDriveP));
    1.67 +	// an invalide path should leave with an error
    1.68 +	TRAPD(err, cachedDriveInfo->IsReadOnlyInternalL(KNoParameters));
    1.69 +	TEST(err != KErrNone);
    1.70 +	// an invalide path should leave with an error
    1.71 +	TRAP(err, cachedDriveInfo->IsReadOnlyInternalL(KInValidParameters));
    1.72 +	TEST(err != KErrNone);
    1.73 +
    1.74 +	CleanupStack::PopAndDestroy(cachedDriveInfo);
    1.75 +	}
    1.76 +
    1.77 +/**
    1.78 +@SYMTestCaseID SYSLIB-BAFL-CT-1680
    1.79 +@SYMTestCaseDesc Tests BSUL::CCachedDriveInfo
    1.80 +@SYMTestPriority Medium
    1.81 +@SYMTestActions Pass in various drives and parameters and checks all kinds attributes:
    1.82 +				KDriveAttSubsted,KDriveAttRemote, KDriveAttLocal, KDriveAttInternal, KDriveAttRemovable
    1.83 +				KDriveAttRedirected,KDriveAttRom.
    1.84 +@SYMTestExpectedResults The test must not fail.
    1.85 +*/
    1.86 +void TestCachedDriveInfoFlagSetL(RFs& aFs)
    1.87 +	{
    1.88 +
    1.89 +	theTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1680 "));
    1.90 +	TFileName fileName;
    1.91 +	TInt err;
    1.92 +	if(!BaflUtils::PathExists(aFs, _L("C:\\Logs\\")))
    1.93 +		{
    1.94 +		err = aFs.MkDir(_L("C:\\Logs\\"));
    1.95 +		}
    1.96 +
    1.97 +	err=aFs.SetSubst(_L("C:\\Logs\\"),EDriveO);
    1.98 +    TEST(err==KErrNone);
    1.99 +    err=aFs.Subst(fileName,EDriveO);
   1.100 +	TEST(err==KErrNone);
   1.101 +    TEST(fileName==_L("C:\\Logs\\"));
   1.102 +
   1.103 +	BSUL::CCachedDriveInfo *cachedDriveInfo = BSUL::CCachedDriveInfo::NewLC(aFs);
   1.104 +
   1.105 +	// The O drive should be subst drive
   1.106 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(EDriveO, KDriveAttSubsted));
   1.107 +
   1.108 +	// The O drive should not be local drive
   1.109 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(EDriveO, KDriveAttLocal));
   1.110 +
   1.111 +	// The O drive should not be remote drive
   1.112 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(EDriveO, KDriveAttRemote));
   1.113 +
   1.114 +	// The C drive should be local drive
   1.115 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveC, KDriveAttLocal));
   1.116 +
   1.117 +	// The C drive should be internal drive
   1.118 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveC, KDriveAttInternal));
   1.119 +
   1.120 +	// The C drive should not be remote drive
   1.121 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveC, KDriveAttRemote));
   1.122 +
   1.123 +	// The C drive should not be removable drive
   1.124 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveC, KDriveAttRemovable));
   1.125 +
   1.126 +	// The C drive should be local and internal drive
   1.127 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveC, KDriveAttInternal|KDriveAttInternal));
   1.128 +
   1.129 +	// The C drive should be local and internal drive, but not remote
   1.130 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveC, KDriveAttInternal|KDriveAttInternal|KDriveAttRemote));
   1.131 +
   1.132 +	// The Z drive should  rom drive.
   1.133 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveZ, KDriveAttRom));
   1.134 +
   1.135 +	//The Z drive should  rom, and internal drive.
   1.136 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveZ, KDriveAttRom|KDriveAttInternal));
   1.137 +
   1.138 +	//The Z drive should  rom and internal drive, but not removable
   1.139 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveZ, KDriveAttRom|KDriveAttInternal|KDriveAttRemovable));
   1.140 +
   1.141 +	// The Z drive should not be Redirected drive
   1.142 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveZ, KDriveAttRedirected));
   1.143 +
   1.144 +	// The Z drive should  rom drive, but not Redirected
   1.145 +	TEST(!cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveZ, KDriveAttRom|KDriveAttRedirected));
   1.146 +
   1.147 +	// The T drive should  be a removable, local drive on winscw, E drive on hardware
   1.148 +#if defined __WINSCW__	
   1.149 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveT, KDriveAttRemovable|KDriveAttLocal));
   1.150 +#elif defined __X86GCC__
   1.151 +	// No removable drives on X86 platform
   1.152 +#else
   1.153 +	TEST(cachedDriveInfo->IsFlagSetOnDriveL(KValidDriveE, KDriveAttRemovable|KDriveAttLocal));
   1.154 +#endif
   1.155 +
   1.156 +	//clean up subst drive
   1.157 +	err=aFs.SetSubst(_L(""),EDriveO);
   1.158 +	TEST(err==KErrNone);
   1.159 +	CleanupStack::PopAndDestroy(cachedDriveInfo);
   1.160 +	}
   1.161 +
   1.162 +/**
   1.163 +@SYMTestCaseID SYSLIB-BAFL-CT-4014
   1.164 +@SYMTestCaseDesc Tests BSUL::CCachedDriveInfo
   1.165 +@SYMTestPriority Medium
   1.166 +@SYMTestActions Pass in various drives and media types to verify media type of drives.
   1.167 +@SYMTestExpectedResults The media type must be as expected for each drive.
   1.168 +@SYMDEF DEF109839
   1.169 +*/
   1.170 +void TestCachedDriveMediaTypeL(RFs& aFs)
   1.171 +	{
   1.172 +	theTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-4014 "));
   1.173 +	BSUL::CCachedDriveInfo *cachedDriveInfo = BSUL::CCachedDriveInfo::NewLC(aFs);
   1.174 +
   1.175 +	// the T drive should be a hard disk media type on WINSCW, E drive on hardware
   1.176 +#ifdef __WINSCW__
   1.177 +	TEST(cachedDriveInfo->MediaTypeL(KValidDriveT,EMediaHardDisk));
   1.178 +#elif defined __X86GCC__
   1.179 +	// No removeable drive in X86 platform
   1.180 +#else
   1.181 +	TEST(cachedDriveInfo->MediaTypeL(KValidDriveE,EMediaHardDisk));
   1.182 +#endif
   1.183 +
   1.184 +	// the Z drive should be a Rom drive
   1.185 +	TEST(cachedDriveInfo->MediaTypeL(KValidDriveZ,EMediaRom));
   1.186 +
   1.187 +#ifdef __WINSCW__
   1.188 +	// the C drive should report as EMediaHardDisk for the PC Drive
   1.189 +	TEST(cachedDriveInfo->MediaTypeL(KValidDriveC,EMediaHardDisk));
   1.190 +#elif defined __EPOC32__
   1.191 +	// the C drive could be a RAM or NAND flash drive depending on how the ROM is built.
   1.192 +	// the C drive should report as EMediaHardDisk for WDP enabled configuraion
   1.193 +	TEST(cachedDriveInfo->MediaTypeL(KValidDriveC,EMediaRam) || cachedDriveInfo->MediaTypeL(KValidDriveC,EMediaNANDFlash) || cachedDriveInfo->MediaTypeL(KValidDriveC,EMediaHardDisk));
   1.194 +#endif
   1.195 +
   1.196 +	// a non-mounted drive should not be EMediaHardDisk
   1.197 +	TMediaType actual;
   1.198 +	TEST(!cachedDriveInfo->MediaTypeL(KInValidDriveP,EMediaHardDisk,&actual));
   1.199 +	TEST(actual == EMediaNotPresent);
   1.200 +
   1.201 +	CleanupStack::PopAndDestroy(cachedDriveInfo);
   1.202 +	}
   1.203 +
   1.204 +/**
   1.205 +@SYMTestCaseID SYSLIB-BAFL-CT-4015
   1.206 +@SYMTestCaseDesc Tests BSUL::CCachedDriveInfo
   1.207 +@SYMTestPriority Medium
   1.208 +@SYMTestActions Call the GetDefaultRemovableMemoryCardDriveL API on WINSCW and hardware.
   1.209 +@SYMTestExpectedResults The MMC drive must be found.
   1.210 +@SYMDEF DEF109839
   1.211 +*/
   1.212 +void TestCachedDriveRemovableMemoryCardDriveL(RFs& aFs)
   1.213 +	{
   1.214 +	theTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-4015 "));
   1.215 +	BSUL::CCachedDriveInfo *cachedDriveInfo = BSUL::CCachedDriveInfo::NewLC(aFs);
   1.216 +
   1.217 +	// the T drive should be a hard disk media type on WINSCW, E drive on hardware
   1.218 +#ifdef __WINSCW__
   1.219 +	TEST(cachedDriveInfo->GetDefaultRemovableMemoryCardDriveL() == TDriveUnit(KValidDriveT));
   1.220 +#elif defined __X86GCC__
   1.221 +	// No removable drives in X86 platform
   1.222 +	TRAPD(err,cachedDriveInfo->GetDefaultRemovableMemoryCardDriveL());
   1.223 +	TEST(err == KErrNotFound);
   1.224 +#else
   1.225 +	TEST(cachedDriveInfo->GetDefaultRemovableMemoryCardDriveL() == TDriveUnit(KValidDriveE));
   1.226 +#endif
   1.227 +
   1.228 +	CleanupStack::PopAndDestroy(cachedDriveInfo);
   1.229 +	}
   1.230 +
   1.231 +/**
   1.232 +@SYMTestCaseID SYSLIB-BAFL-CT-1394
   1.233 +@SYMTestCaseDesc Tests BSUL::CCachedDriveInfo
   1.234 +@SYMTestPriority Medium
   1.235 +@SYMTestActions Executes tests for BSUL::CCachedDriveInfo.
   1.236 +@SYMTestExpectedResults The test must not fail.
   1.237 +*/
   1.238 +void DoTests()
   1.239 +	{
   1.240 +	theTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1394 "));
   1.241 +	RFs fs;
   1.242 +	fs.Connect();
   1.243 +	CleanupClosePushL(fs);
   1.244 +
   1.245 +	TestCachedDriveInfoL(fs);
   1.246 +	TestCachedDriveInfoFlagSetL(fs);
   1.247 +	TestCachedDriveMediaTypeL(fs);
   1.248 +	TestCachedDriveRemovableMemoryCardDriveL(fs);
   1.249 +
   1.250 +	CleanupStack::PopAndDestroy(&fs);
   1.251 +	}
   1.252 +
   1.253 +GLDEF_C TInt E32Main()
   1.254 +	{
   1.255 +	__UHEAP_MARK;
   1.256 +	CTrapCleanup *cleanup=CTrapCleanup::New();
   1.257 +	theTest.Title();
   1.258 +	theTest.Start(_L("Testing t_cacheddriveinfo"));
   1.259 +	TRAPD(err,DoTests());
   1.260 +	TEST(!err);
   1.261 +	theTest.End();
   1.262 +	theTest.Close();
   1.263 +	delete cleanup;
   1.264 +	__UHEAP_MARKEND;
   1.265 +	return(0);
   1.266 +	}