kerneltest/f32test/server/t_proxydrive1.cpp
branchRCL_3
changeset 36 bbf8bed59bcb
child 41 0ffb4e86fcc9
equal deleted inserted replaced
28:5b5d147c7838 36:bbf8bed59bcb
       
     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 the License "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 // f32test\ext\t_ext1.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32test.h>
       
    20 #include <e32svr.h>
       
    21 #include "t_server.h"
       
    22 #include "f32_test_utils.h"
       
    23 
       
    24 using namespace F32_Test_Utils;
       
    25 
       
    26 
       
    27 GLDEF_D RTest test(_L("T_PROXYDRIVE1"));
       
    28 
       
    29 
       
    30 TInt GetRemovableDrive(TInt aDriveNumber)
       
    31 	{
       
    32 	RLocalDrive d;
       
    33 	TBool flag=EFalse;
       
    34 
       
    35 	//Find the local drive number corresponding to aDriveNumber
       
    36 	TMediaSerialNumber serialNum;
       
    37 	TInt r = TheFs.GetMediaSerialNumber(serialNum, aDriveNumber);
       
    38 	if(r!= KErrNone)
       
    39 		return r;
       
    40 
       
    41 	TInt len = serialNum.Length();
       
    42 	test.Printf(_L("Serial number (len %d) :\n"), len);
       
    43 
       
    44 	for (TInt n=0; n<KMaxLocalDrives; n++)
       
    45 		{
       
    46 		r = d.Connect(n, flag);
       
    47 		if(r != KErrNone)
       
    48 			{
       
    49 			test.Printf(_L("drive %d: TBusLocalDrive::Connect() failed %d\n"), n, r);
       
    50 			continue;
       
    51 			}
       
    52 
       
    53 	    TLocalDriveCapsV5Buf capsBuf;
       
    54 	    TLocalDriveCapsV5& caps = capsBuf();
       
    55 		r = d.Caps(capsBuf);
       
    56 		if(r != KErrNone)
       
    57 			{
       
    58 			test.Printf(_L("drive %d: TBusLocalDrive::Caps() failed %d\n"), n, r);
       
    59 			continue;
       
    60 			}
       
    61 
       
    62 		if ((caps.iDriveAtt & KDriveAttRemovable) == 0)
       
    63 			{
       
    64 			continue;
       
    65 			}
       
    66 
       
    67 		TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength);
       
    68 		if (serialNum.Compare(localSerialNum) == 0)
       
    69 			{
       
    70 			d.Close();
       
    71 			test.Printf(_L("found removable drive: local drive number %d\n"), n);
       
    72 			return n;
       
    73 			}
       
    74 
       
    75 		d.Close();
       
    76 		}
       
    77 
       
    78 	return KErrNotFound;
       
    79 	}
       
    80 
       
    81 
       
    82 
       
    83 
       
    84 GLDEF_C void CallTestsL()
       
    85 	{
       
    86     TInt drive;
       
    87 	TInt err=RFs::CharToDrive(gDriveToTest,drive);
       
    88 	test.Start(_L("Starting Test - T_PROXYDRIVE1"));
       
    89 	test(err==KErrNone);
       
    90 
       
    91     PrintDrvInfo(TheFs, drive);
       
    92 
       
    93 
       
    94 	_LIT(KBitProxyDriveName, "t_bitproxydrive.pxy");
       
    95 	_LIT(KBitProxyDrive, "bitproxydrive");
       
    96 
       
    97 	TInt r;
       
    98 
       
    99 	TInt localDriveNumber = GetRemovableDrive(drive);
       
   100 	if (localDriveNumber < 0)
       
   101 		{
       
   102 		test.Printf(_L("Not a removable drive, skipping test\n"));
       
   103 		return;
       
   104 		}
       
   105 
       
   106 
       
   107 	test.Next(_L("Adding and then removing a proxy drive with an open subsession"));
       
   108 	r = TheFs.AddProxyDrive(KBitProxyDriveName);
       
   109 	test.Printf(_L("AddProxyDrive(%S) r %d\n"), &KBitProxyDriveName, r);
       
   110 	test(r == KErrNone || r == KErrAlreadyExists);
       
   111 
       
   112 	TPckgBuf<TInt> p1; p1() = localDriveNumber;
       
   113 	TBuf<1> p2;
       
   114 	TInt driveNumber = EDriveM;
       
   115 
       
   116 	r = TheFs.MountProxyDrive(driveNumber, KBitProxyDrive, &p1, &p2);
       
   117 	test.Printf(_L("MountProxyDrive(%d, %S) r %d\n"), driveNumber, &KBitProxyDrive, r);
       
   118 	test (r >= 0);
       
   119 
       
   120 	_LIT(KFileSystem, "FAT");
       
   121 	r = TheFs.MountFileSystem(KFileSystem, driveNumber);
       
   122 	test.Printf(_L("MountFileSystem(%S) r %d\n"), &KFileSystem, r);
       
   123 	test(r == KErrNone);
       
   124 
       
   125 
       
   126 	RFs fs;
       
   127 	r = fs.Connect();
       
   128 	test(r == KErrNone);
       
   129 
       
   130 
       
   131 	TPath dirPath = _L("?:\\*");
       
   132 	dirPath[0] = (TUint8) ('A' + driveNumber);
       
   133 	RDir dir;
       
   134 	r = dir.Open(fs, dirPath, KEntryAttNormal);
       
   135 	test.Printf(_L("RDir::Open(%S) r %d\n"), &dirPath, r);
       
   136 
       
   137 
       
   138 	r = TheFs.DismountFileSystem(KFileSystem, driveNumber);
       
   139 	test.Printf(_L("DismountFileSystem(%S) r %d\n"), &KFileSystem, r);
       
   140 	test (r == KErrInUse);
       
   141 
       
   142 	// dismount failed - attempt a forced dismount
       
   143 	TRequestStatus stat;
       
   144 	TheFs.NotifyDismount(driveNumber, stat, EFsDismountForceDismount);
       
   145 	User::WaitForRequest(stat);
       
   146 	r = stat.Int();
       
   147 	test.Printf(_L("DismountFileSystem(%S, EFsDismountForceDismount) r %d\n"), &KFileSystem, r);
       
   148 	test (r == KErrNone);
       
   149 
       
   150 	r = TheFs.DismountProxyDrive(driveNumber);
       
   151 	test.Printf(_L("DismountProxyDrive(%d) r %d\n"), driveNumber, r);
       
   152 	test (r == KErrNone);
       
   153 	
       
   154 
       
   155 	test.Printf(_L("closing dir (%S)....\n"), &dirPath, r);
       
   156 	dir.Close();
       
   157 
       
   158 	test.Printf(_L("closing file session()....\n"));
       
   159 	fs.Close();
       
   160 
       
   161 	r = TheFs.RemoveProxyDrive(KBitProxyDrive);
       
   162 	test (r == KErrNone);
       
   163 
       
   164 	test.End();
       
   165 	test.Close();
       
   166 	}