297
|
1 |
// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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 |
//
|
|
15 |
|
|
16 |
|
|
17 |
#include <e32def.h>
|
|
18 |
#include <e32cmn.h>
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <f32file.h>
|
|
21 |
#include <e32cons.h>
|
|
22 |
#include <e32debug.h>
|
|
23 |
#define __E32TEST_EXTENSION__
|
|
24 |
#include <e32test.h>
|
|
25 |
|
|
26 |
#include "cmsdrive.h"
|
|
27 |
#include "tmsprintdrive.h"
|
|
28 |
#include "ttestutils.h"
|
|
29 |
#include "cblockdevicetester.h"
|
|
30 |
|
|
31 |
extern CMsDrive* msDrive;
|
|
32 |
|
|
33 |
RTest test(_L("T_MSWRPR"));
|
|
34 |
RFs fsSession;
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
class TTests
|
|
39 |
{
|
|
40 |
public:
|
|
41 |
TTests(TInt aDriveNumber);
|
|
42 |
|
|
43 |
void FullFormat();
|
|
44 |
void tReadOnly();
|
|
45 |
void tReadWrite();
|
|
46 |
void RemountDrive();
|
|
47 |
|
|
48 |
private:
|
|
49 |
TInt iDriveNumber;
|
|
50 |
};
|
|
51 |
|
|
52 |
TTests::TTests(TInt aDriveNumber)
|
|
53 |
: iDriveNumber(aDriveNumber)
|
|
54 |
{
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
void TTests::RemountDrive()
|
|
59 |
{
|
|
60 |
TDriveInfo info;
|
|
61 |
const TUint KMediaRemountForceMediaChange = 0x00000001;
|
|
62 |
|
|
63 |
TRequestStatus changeStatus;
|
|
64 |
fsSession.NotifyChange(ENotifyAll, changeStatus);
|
|
65 |
|
|
66 |
test.Printf(_L("Remounting the drive\n"));
|
|
67 |
TInt err = fsSession.RemountDrive(iDriveNumber, NULL, KMediaRemountForceMediaChange);
|
|
68 |
test(err == KErrNotReady || err == KErrNone);
|
|
69 |
|
|
70 |
do
|
|
71 |
{
|
|
72 |
test.Printf(_L("Waiting for media change...\n"));
|
|
73 |
User::WaitForRequest(changeStatus);
|
|
74 |
|
|
75 |
err = fsSession.Drive(info, iDriveNumber);
|
|
76 |
test.Printf(_L("Completed.\n"));
|
|
77 |
|
|
78 |
fsSession.NotifyChange(ENotifyAll, changeStatus);
|
|
79 |
}
|
|
80 |
while (err == KErrNotReady);
|
|
81 |
fsSession.NotifyChangeCancel(changeStatus);
|
|
82 |
}
|
|
83 |
|
|
84 |
void TTests::tReadOnly()
|
|
85 |
{
|
|
86 |
test.Start(_L("tReadOnly\n"));
|
|
87 |
|
|
88 |
TDriveInfo driveInfo;
|
|
89 |
TInt err = fsSession.Drive(driveInfo);
|
|
90 |
test(err == KErrNone);
|
|
91 |
|
|
92 |
test.Printf(_L("DriveInfo MediaAtt= 0x%x\n"), driveInfo.iMediaAtt);
|
|
93 |
|
|
94 |
test((driveInfo.iMediaAtt&KMediaAttWriteProtected) != 0);
|
|
95 |
test.End();
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
void TTests::tReadWrite()
|
|
100 |
{
|
|
101 |
test.Start(_L("tReadWrite\n"));
|
|
102 |
|
|
103 |
TDriveInfo driveInfo;
|
|
104 |
TInt err = fsSession.Drive(driveInfo);
|
|
105 |
test(err == KErrNone);
|
|
106 |
|
|
107 |
test.Printf(_L("DriveInfo MediaAtt = %x %x\n"), driveInfo.iMediaAtt, driveInfo.iMediaAtt&KMediaAttWriteProtected);
|
|
108 |
test((driveInfo.iMediaAtt&KMediaAttWriteProtected) == 0);
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
test.End();
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
void TTests::FullFormat()
|
|
117 |
{
|
|
118 |
TInt counter;
|
|
119 |
RFormat format;
|
|
120 |
test.Next(_L("Test EFullFormat\n"));
|
|
121 |
|
|
122 |
TInt err = format.Open(fsSession, msDrive->GetSessionPath(), EFullFormat, counter);
|
|
123 |
test(err == KErrNone);
|
|
124 |
while (counter)
|
|
125 |
{
|
|
126 |
err = format.Next(counter);
|
|
127 |
test(err == KErrNone);
|
|
128 |
}
|
|
129 |
format.Close();
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
void CallTestsL()
|
|
134 |
{
|
|
135 |
TInt driveNumber = msDrive->DriveNumber();
|
|
136 |
// Print drive info
|
|
137 |
TRAPD(err, TMsPrintDrive::VolInfoL(driveNumber));
|
|
138 |
err = err;
|
|
139 |
|
|
140 |
TTests t(driveNumber);
|
|
141 |
|
|
142 |
test.Printf(_L("Preparing target drive..."));
|
|
143 |
//t.FullFormat();
|
|
144 |
|
|
145 |
CWrPrTester* wpTester = CWrPrTester::NewL(driveNumber);
|
|
146 |
CleanupStack::PushL(wpTester);
|
|
147 |
test.Printf(_L("Target drive ready.\n"));
|
|
148 |
|
|
149 |
test.Start(_L("**** WRITE PROTECT ****"));
|
|
150 |
|
|
151 |
t.RemountDrive();
|
|
152 |
t.tReadWrite();
|
|
153 |
err = wpTester->WriteReadTestL();
|
|
154 |
test(err == KErrNone);
|
|
155 |
|
|
156 |
test.Next(_L("**** Test WP=Set ****"));
|
|
157 |
TRAP(err, wpTester->SetWriteProtectL());
|
|
158 |
test(err == KErrNone);
|
|
159 |
t.RemountDrive();
|
|
160 |
t.tReadOnly();
|
|
161 |
err = wpTester->WriteReadTestL();
|
|
162 |
test(err == KErrAccessDenied);
|
|
163 |
|
|
164 |
test.Next(_L("**** Test WP=Clr ****"));
|
|
165 |
TRAP(err, wpTester->ClrWriteProtectL());
|
|
166 |
test(err == KErrNone);
|
|
167 |
t.RemountDrive();
|
|
168 |
t.tReadWrite();
|
|
169 |
err = wpTester->WriteReadTestL();
|
|
170 |
test(err == KErrNone);
|
|
171 |
|
|
172 |
test.End();
|
|
173 |
|
|
174 |
CleanupStack::PopAndDestroy(wpTester);
|
|
175 |
}
|