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