1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_multislot.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,166 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +#include <e32test.h>
1.21 +#include <f32file.h>
1.22 +#include <d32locd.h>
1.23 +
1.24 +static RTest test(_L("Testing t_multislot"));
1.25 +_LIT(KYes, "yes");
1.26 +_LIT(KNo, "no");
1.27 +static RFs fs;
1.28 +
1.29 +// this function was copied from t_sdpartition.cpp
1.30 +TInt FindMmcLocalDriveNumber(TChar aDriveChar, TInt& aLocalDriveNum, TInt aDriveNum)
1.31 + {
1.32 + TInt r = fs.CharToDrive(aDriveChar, aDriveNum);
1.33 + test(r==KErrNone);
1.34 +
1.35 + TDriveInfo driveInfo;
1.36 + r = fs.Drive(driveInfo, aDriveNum);
1.37 + test(r==KErrNone);
1.38 +
1.39 +
1.40 + TVolumeInfo vi;
1.41 + r = fs.Volume(vi, aDriveNum);
1.42 + test(r==KErrNone);
1.43 +
1.44 +
1.45 + TMediaSerialNumber serialNum;
1.46 + r = fs.GetMediaSerialNumber(serialNum, aDriveNum);
1.47 + test(r==KErrNone);
1.48 +
1.49 +
1.50 + test.Printf(_L("Drive %C size %ld\n"), (char) aDriveChar, vi.iSize);
1.51 + TInt len = serialNum.Length();
1.52 + test.Printf(_L("Serial number (len %d) :"), len);
1.53 + TInt n;
1.54 + for (n=0; n<len; n+=16)
1.55 + {
1.56 + TBuf16<16*3 +1> buf;
1.57 + for (TInt m=n; m<n+16; m++)
1.58 + {
1.59 + TBuf16<3> hexBuf;
1.60 + hexBuf.Format(_L("%02X "),serialNum[m]);
1.61 + buf.Append(hexBuf);
1.62 + }
1.63 + buf.Append(_L("\n"));
1.64 + test.Printf(buf);
1.65 + }
1.66 +
1.67 + TBusLocalDrive drv;
1.68 + TBool chg(EFalse);
1.69 + aLocalDriveNum = -1;
1.70 + TInt serialNumbersMatched = 0;
1.71 + for (n=0; n<KMaxLocalDrives; n++)
1.72 + {
1.73 + r = drv.Connect(n, chg); //for user area
1.74 +//RDebug::Print(_L("TBusLocalDrive::Connect(%d) %d"), n, r);
1.75 +
1.76 + if(r != KErrNone)
1.77 + {
1.78 + test.Printf(_L("drive %d: TBusLocalDrive::Connect() failed %d\n"), n, r);
1.79 + continue;
1.80 + }
1.81 +
1.82 + TLocalDriveCapsV5Buf capsBuf;
1.83 + TLocalDriveCapsV5& caps = capsBuf();
1.84 + r = drv.Caps(capsBuf);
1.85 + if(r != KErrNone)
1.86 + {
1.87 + test.Printf(_L("drive %d: TBusLocalDrive::Caps() failed %d\n"), n, r);
1.88 + continue;
1.89 + }
1.90 +
1.91 +//RDebug::Print(_L("areaSize %ld cardCapacity %ld"), caps.iSize, caps.iFormatInfo.iCapacity);
1.92 +
1.93 + TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength);
1.94 + if (serialNum.Compare(localSerialNum) == 0)
1.95 + {
1.96 + serialNumbersMatched++;
1.97 + TBool sizeMatch = (vi.iSize < caps.iSize);
1.98 + test.Printf(_L("drive %d: Serial number match, size match: %S\n"), n, sizeMatch?&KYes:&KNo);
1.99 + if (sizeMatch)
1.100 + {
1.101 + aLocalDriveNum = n;
1.102 + drv.Disconnect();
1.103 + break;
1.104 + }
1.105 + }
1.106 + drv.Disconnect();
1.107 + }
1.108 +
1.109 +
1.110 + return aLocalDriveNum == -1?KErrNotFound:KErrNone;
1.111 + }
1.112 +
1.113 +
1.114 +// Manual test - requires user to move a card between two physical slots
1.115 +extern TInt E32Main()
1.116 + {
1.117 + test.Start(_L("T_MULTISLOT Test"));
1.118 + test(fs.Connect()==KErrNone);
1.119 +
1.120 + // Get the list of removable drive driver-letters
1.121 + TDriveList driveList;
1.122 + test(fs.DriveList(driveList,KDriveAttRemovable)==KErrNone);
1.123 +
1.124 +
1.125 + TInt length=driveList.Length();
1.126 + TBool pass = EFalse;
1.127 +
1.128 + // i is drive letter (as int)
1.129 + // for every removable media logical drive
1.130 + for(TInt i=0; i<length; i++)
1.131 + {
1.132 + if(driveList[i] == 0)
1.133 + {
1.134 + continue;
1.135 + }
1.136 +
1.137 + TChar driveChar = i+'A';
1.138 + test.Next(_L("Testing Logical Drive"));
1.139 +
1.140 +
1.141 + TInt FirstlocDrvNum = KErrNotFound;
1.142 + TInt SecondlocDrvNum = KErrNotFound;
1.143 + TInt driveNum = -1;
1.144 + driveNum = i+'A';
1.145 + test.Printf(_L("Logical Drive : %d"), driveNum);
1.146 +
1.147 + // Get local drive number by gettin ghr Serial number fo the card (RFs call), then
1.148 + // enumerating the TBusLocalDrives and finding one that matches.
1.149 + test(FindMmcLocalDriveNumber(driveChar,FirstlocDrvNum,driveNum)==KErrNone);
1.150 + // Got first local drive number, now move card into second slot.
1.151 + test.Printf(_L("<Move MMC Card to second slot, then press any key>"));
1.152 + test.Getch();
1.153 + // Get second local drive number for same logical drive (should be different local drive number).
1.154 + test(FindMmcLocalDriveNumber(driveChar,SecondlocDrvNum,driveNum)==KErrNone);
1.155 + if(FirstlocDrvNum!=SecondlocDrvNum)
1.156 + {
1.157 + pass=ETrue;
1.158 + break;
1.159 + }
1.160 + // else perhaps this wasn't a multislot drive
1.161 + }
1.162 + test(pass);
1.163 + test.End();
1.164 + test.Close();
1.165 +
1.166 + fs.Close();
1.167 + return KErrNone;
1.168 + }
1.169 +