kerneltest/e32test/pccd/t_multislot.cpp
changeset 0 a41df078684a
child 33 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <e32test.h>
       
    18 #include <f32file.h>
       
    19 
       
    20 static RTest test(_L("Testing t_multislot"));
       
    21 _LIT(KYes, "yes");
       
    22 _LIT(KNo, "no");
       
    23 static RFs fs;
       
    24 
       
    25 // this function was copied from t_sdpartition.cpp
       
    26 TInt FindMmcLocalDriveNumber(TChar aDriveChar, TInt& aLocalDriveNum, TInt aDriveNum)
       
    27 	{
       
    28 	TInt r = fs.CharToDrive(aDriveChar, aDriveNum);
       
    29 	test(r==KErrNone);
       
    30 
       
    31 	TDriveInfo driveInfo;
       
    32     r = fs.Drive(driveInfo, aDriveNum);
       
    33     test(r==KErrNone);
       
    34 
       
    35 
       
    36 	TVolumeInfo vi;
       
    37 	r = fs.Volume(vi, aDriveNum);
       
    38     test(r==KErrNone);
       
    39 
       
    40 
       
    41 	TMediaSerialNumber serialNum;
       
    42 	r = fs.GetMediaSerialNumber(serialNum, aDriveNum);
       
    43     test(r==KErrNone);
       
    44 
       
    45 
       
    46     test.Printf(_L("Drive %C size %ld\n"), (char) aDriveChar, vi.iSize);
       
    47 	TInt len = serialNum.Length();
       
    48 	test.Printf(_L("Serial number (len %d) :"), len);
       
    49 	TInt n;
       
    50 	for (n=0; n<len; n+=16)
       
    51 		{
       
    52 		TBuf16<16*3 +1> buf;
       
    53 		for (TInt m=n; m<n+16; m++)
       
    54 			{
       
    55 			TBuf16<3> hexBuf;
       
    56 			hexBuf.Format(_L("%02X "),serialNum[m]);
       
    57 			buf.Append(hexBuf);
       
    58 			}
       
    59 		buf.Append(_L("\n"));
       
    60 		test.Printf(buf);
       
    61 		}
       
    62 
       
    63 	TBusLocalDrive drv;
       
    64 	TBool chg(EFalse);
       
    65 	aLocalDriveNum = -1;
       
    66 	TInt serialNumbersMatched = 0;
       
    67 	for (n=0; n<KMaxLocalDrives; n++)
       
    68 		{
       
    69 		r = drv.Connect(n, chg); //for user area
       
    70 //RDebug::Print(_L("TBusLocalDrive::Connect(%d) %d"), n, r);
       
    71 
       
    72 		if(r != KErrNone)
       
    73 			{
       
    74 			test.Printf(_L("drive %d: TBusLocalDrive::Connect() failed %d\n"), n, r);
       
    75 			continue;
       
    76 			}	
       
    77 
       
    78 	    TLocalDriveCapsV5Buf capsBuf;
       
    79 	    TLocalDriveCapsV5& caps = capsBuf();
       
    80 		r = drv.Caps(capsBuf);
       
    81 		if(r != KErrNone)
       
    82 			{
       
    83 			test.Printf(_L("drive %d: TBusLocalDrive::Caps() failed %d\n"), n, r);
       
    84 			continue;
       
    85 			}	
       
    86 
       
    87 //RDebug::Print(_L("areaSize %ld cardCapacity %ld"), caps.iSize, caps.iFormatInfo.iCapacity);
       
    88 
       
    89 		TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength);
       
    90 		if (serialNum.Compare(localSerialNum) == 0)
       
    91 			{
       
    92 			serialNumbersMatched++;
       
    93 			TBool sizeMatch = (vi.iSize < caps.iSize);
       
    94 			test.Printf(_L("drive %d: Serial number match, size match: %S\n"), n, sizeMatch?&KYes:&KNo);
       
    95 			if (sizeMatch)
       
    96 				{
       
    97 				aLocalDriveNum = n;
       
    98 				drv.Disconnect();
       
    99 				break;
       
   100 				}
       
   101 			}
       
   102 		drv.Disconnect();
       
   103 		}
       
   104 
       
   105 
       
   106 	return aLocalDriveNum == -1?KErrNotFound:KErrNone;
       
   107 	}
       
   108 
       
   109 
       
   110 // Manual test - requires user to move a card between two physical slots
       
   111 extern TInt E32Main()
       
   112 	{
       
   113 	test.Start(_L("T_MULTISLOT Test"));
       
   114 	test(fs.Connect()==KErrNone);
       
   115 	
       
   116 	// Get the list of removable drive driver-letters
       
   117 	TDriveList driveList;
       
   118 	test(fs.DriveList(driveList,KDriveAttRemovable)==KErrNone);
       
   119 	
       
   120 	
       
   121 	TInt length=driveList.Length();
       
   122 	TBool pass = EFalse;
       
   123 	
       
   124 	// i is drive letter (as int)
       
   125 	// for every removable media logical drive
       
   126 	for(TInt i=0; i<length; i++)
       
   127 		{
       
   128 		if(driveList[i] == 0)
       
   129 			{
       
   130 			continue;
       
   131 			}
       
   132 
       
   133 		TChar driveChar = i+'A';
       
   134 		test.Next(_L("Testing Logical Drive"));
       
   135 		
       
   136 
       
   137 		TInt FirstlocDrvNum = KErrNotFound;
       
   138 		TInt SecondlocDrvNum = KErrNotFound;
       
   139 		TInt driveNum = -1;
       
   140 		driveNum = i+'A';
       
   141 		test.Printf(_L("Logical Drive : %d"), driveNum);
       
   142 		
       
   143 		// Get local drive number by gettin ghr Serial number fo the card (RFs call), then 
       
   144 		// enumerating the TBusLocalDrives and finding one that matches.
       
   145 		test(FindMmcLocalDriveNumber(driveChar,FirstlocDrvNum,driveNum)==KErrNone);
       
   146 		// Got first local drive number, now move card into second slot.
       
   147 		test.Printf(_L("<Move MMC Card to second slot, then press any key>"));
       
   148 		test.Getch();
       
   149 		// Get second local drive number for same logical drive (should be different local drive number).
       
   150 		test(FindMmcLocalDriveNumber(driveChar,SecondlocDrvNum,driveNum)==KErrNone);
       
   151 		if(FirstlocDrvNum!=SecondlocDrvNum)
       
   152 			{
       
   153 			pass=ETrue;
       
   154 			break;
       
   155 			}
       
   156 		// else perhaps this wasn't a multislot drive
       
   157 		}
       
   158 	test(pass);
       
   159 	test.End();
       
   160 	test.Close();
       
   161 	
       
   162 	fs.Close();
       
   163 	return KErrNone;
       
   164 	}
       
   165