author | mikek |
Wed, 16 Jun 2010 12:59:18 +0100 | |
branch | GCC_SURGE |
changeset 160 | 30e086416910 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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\server\t_handshare.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <e32test.h> |
|
21 |
#include "t_server.h" |
|
22 |
#include "handshare.h" |
|
23 |
||
24 |
GLDEF_D RTest test(_L("T_HANDSHARE")); |
|
25 |
||
26 |
LOCAL_D TInt drivenum; |
|
27 |
||
28 |
||
29 |
||
30 |
// test of (deprecated) RFile::Adopt() |
|
31 |
// |
|
32 |
// Request an open file (read only) |
|
33 |
// |
|
34 |
GLDEF_C void RequestFileDeprecatedAdopt() |
|
35 |
{ |
|
36 |
test.Next(_L("RFile::Adopt()")); |
|
37 |
||
38 |
TInt r; |
|
39 |
RFileHandleSharer handsvr; |
|
40 |
do |
|
41 |
{ |
|
42 |
r=handsvr.Connect(); |
|
43 |
} |
|
44 |
while(r==KErrNotFound); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
45 |
test_KErrNone(r); |
0 | 46 |
r=handsvr.SetTestDrive(drivenum); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
test_KErrNone(r); |
0 | 48 |
TInt ssh; |
49 |
RFs fs1; |
|
50 |
TInt fsh = handsvr.GetFileHandle(ssh, EFileRead); |
|
51 |
||
52 |
r = fs1.SetReturnedHandle(fsh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
test_KErrNone(r); |
0 | 54 |
|
55 |
RFile file; |
|
56 |
r=file.Adopt(fs1,ssh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
test_KErrNone(r); |
0 | 58 |
|
59 |
TBuf8<100> rbuf; |
|
60 |
r=file.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
test_KErrNone(r); |
0 | 62 |
|
63 |
r=rbuf.CompareF(KTestData1()); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
test_KErrNone(r); |
0 | 65 |
|
66 |
r=file.Write(KTestData()); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
test_Value(r, r==KErrAccessDenied); |
0 | 68 |
|
69 |
r=file.ChangeMode(EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
test_Value(r, r==KErrArgument); |
0 | 71 |
|
72 |
r=file.Rename(_L("\\newname.txt")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied); |
0 | 74 |
|
75 |
file.Close(); |
|
76 |
||
77 |
fsh = handsvr.GetFileHandle(ssh, EFileRead); |
|
78 |
r = fs1.SetReturnedHandle(fsh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
test_KErrNone(r); |
0 | 80 |
|
81 |
// Adopt a bad sub-session handle |
|
82 |
||
83 |
r=file.Adopt(fs1, KNullHandle); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
test_Value(r, r==KErrBadHandle); |
0 | 85 |
|
86 |
r=file.Adopt(fs1, -1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
test_Value(r, r==KErrBadHandle); |
0 | 88 |
|
89 |
||
90 |
handsvr.Close(); |
|
91 |
file.Close(); |
|
92 |
RDebug::Print(_L("End Of Tests")); |
|
93 |
fs1.Close(); |
|
94 |
} |
|
95 |
||
96 |
||
97 |
||
98 |
// Cloning tests |
|
99 |
GLDEF_C void Duplicate() |
|
100 |
{ |
|
101 |
test.Next(_L("RFile::Duplicate()")); |
|
102 |
||
103 |
RFs fs; |
|
104 |
TInt r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
test_KErrNone(r); |
0 | 106 |
|
107 |
// Check the number of open file handles |
|
108 |
TInt resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
test_Value(resCount, resCount == 0); |
0 | 110 |
|
111 |
// create a file & fill it with data |
|
112 |
RFile file1; |
|
113 |
r=file1.Replace(fs,KCliFileName,EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
test_KErrNone(r); |
0 | 115 |
r=file1.Write(KTestData()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
test_KErrNone(r); |
0 | 117 |
file1.Close(); |
118 |
||
119 |
// open the file for read |
|
120 |
r = file1.Open(fs,KCliFileName,EFileRead); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
test_KErrNone(r); |
0 | 122 |
TBuf8<100> rbuf; |
123 |
r = file1.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
test_KErrNone(r); |
0 | 125 |
r=rbuf.CompareF(KTestData); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
test_KErrNone(r); |
0 | 127 |
|
128 |
||
129 |
// clone the file |
|
130 |
RFile file2; |
|
131 |
r = file2.Duplicate(file1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
test_Value(r, r==0); |
0 | 133 |
|
134 |
// make sure file positions are the same |
|
135 |
TInt pos1 = 0; |
|
136 |
r = file1.Seek(ESeekCurrent, pos1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
test_KErrNone(r); |
0 | 138 |
TInt pos2 = 0; |
139 |
r = file2.Seek(ESeekCurrent, pos2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
test_Value(pos1, pos1 == pos2); |
0 | 142 |
|
143 |
// change the position on the duplcated file handle & |
|
144 |
// verify that the original file handle's position is unchanged |
|
145 |
TInt oldPos1 = pos1; |
|
146 |
||
147 |
const TInt newPos2 = 5; |
|
148 |
pos2 = newPos2; |
|
149 |
r = file2.Seek(ESeekStart, pos2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
test_KErrNone(r); |
0 | 151 |
|
152 |
pos1 = 0; |
|
153 |
r = file1.Seek(ESeekCurrent, pos1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
test_Value(pos1, pos1 == oldPos1); |
0 | 156 |
|
157 |
pos2 = 0; |
|
158 |
r = file2.Seek(ESeekCurrent, pos2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
test_Value(pos2, pos2 == newPos2); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
test_Value(pos1, pos1 != pos2); |
0 | 162 |
|
163 |
// close the parent file and check we can still use the duplicated one. |
|
164 |
file1.Close(); |
|
165 |
||
166 |
// Check the number of open file handles - should be 1 (the duplicated one) |
|
167 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
test_Value(resCount, resCount == 1); |
0 | 169 |
|
170 |
fs.Close(); |
|
171 |
||
172 |
rbuf.FillZ(); |
|
173 |
||
174 |
// reset to pos 0 |
|
175 |
pos2 = 0; |
|
176 |
r = file2.Seek(ESeekStart, pos2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
test_KErrNone(r); |
0 | 178 |
|
179 |
r=file2.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
test_KErrNone(r); |
0 | 181 |
r=rbuf.CompareF(KTestData); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
test_KErrNone(r); |
0 | 183 |
file2.Close(); |
184 |
||
185 |
// start again - this time we're going to close the duplicated file first |
|
186 |
// and check we can still use the parent file |
|
187 |
||
188 |
r = fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
test_KErrNone(r); |
0 | 190 |
|
191 |
// Make a note of the number of open resources |
|
192 |
fs.ResourceCountMarkStart(); |
|
193 |
||
194 |
// open the file for read |
|
195 |
r = file1.Open(fs,KCliFileName,EFileRead); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
test_KErrNone(r); |
0 | 197 |
|
198 |
||
199 |
// clone the file & check we can read it |
|
200 |
r = file2.Duplicate(file1, EOwnerThread); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
test_Value(r, r==0); |
0 | 202 |
rbuf.FillZ(); |
203 |
r = file2.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
test_KErrNone(r); |
0 | 205 |
r=rbuf.CompareF(KTestData); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
test_KErrNone(r); |
0 | 207 |
|
208 |
||
209 |
// close the duplicated file and check we can still use the parent one. |
|
210 |
file2.Close(); |
|
211 |
||
212 |
rbuf.FillZ(); |
|
213 |
||
214 |
// check we can read the parent file |
|
215 |
r=file1.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
test_KErrNone(r); |
0 | 217 |
r=rbuf.CompareF(KTestData); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
test_KErrNone(r); |
0 | 219 |
|
220 |
// close the parent |
|
221 |
file1.Close(); |
|
222 |
||
223 |
// Check the number of open file handles |
|
224 |
fs.ResourceCountMarkEnd(); |
|
225 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
test_Value(resCount, resCount == 0); |
0 | 227 |
|
228 |
fs.Close(); |
|
229 |
} |
|
230 |
||
231 |
||
232 |
// Request an open file (write mode) from the server |
|
233 |
// using RFile::AdoptFromServer() |
|
234 |
GLDEF_C void RequestFileWrite() |
|
235 |
{ |
|
236 |
TInt r; |
|
237 |
RFileHandleSharer handsvr; |
|
238 |
do |
|
239 |
{ |
|
240 |
r=handsvr.Connect(); |
|
241 |
} |
|
242 |
while(r==KErrNotFound); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
test_KErrNone(r); |
0 | 244 |
|
245 |
r=handsvr.SetTestDrive(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
test_KErrNone(r); |
0 | 247 |
|
248 |
TInt ssh; |
|
249 |
TInt fsh = handsvr.GetFileHandle2(ssh, EFileWrite); |
|
250 |
test (fsh >= 0); |
|
251 |
||
252 |
// Closing the handle to the server ensures the server has closed it's |
|
253 |
// RFs and RFile handles - this provides a means of testing whether we |
|
254 |
// can still adopt the RFile even if the server has closed it's one. |
|
255 |
||
256 |
handsvr.Sync(); // make sure server has finished doing what it's doing |
|
257 |
handsvr.Close(); |
|
258 |
||
259 |
// adopt the file handle from FHServer |
|
260 |
test.Next(_L("RFile::AdoptFromServer()")); |
|
261 |
||
262 |
RFile file; |
|
263 |
r=file.AdoptFromServer(fsh, ssh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
test_KErrNone(r); |
0 | 265 |
|
266 |
TBuf8<100> rbuf; |
|
267 |
r=file.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
test_KErrNone(r); |
0 | 269 |
|
270 |
// server should write KTestData1 ("Server Write Server Write") to file |
|
271 |
r=rbuf.CompareF(KTestData1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
test_KErrNone(r); |
0 | 273 |
|
274 |
// reset to pos 0 |
|
275 |
TInt pos = 0; |
|
276 |
r = file.Seek(ESeekStart, pos); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
test_KErrNone(r); |
0 | 278 |
|
279 |
// overwrite with KTestData ("Client Write Client Write") to file |
|
280 |
r=file.Write(KTestData()); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
test_KErrNone(r); |
0 | 282 |
rbuf.FillZ(); |
283 |
r=file.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
test_KErrNone(r); |
0 | 285 |
r=rbuf.CompareF(KTestData); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
test_KErrNone(r); |
0 | 287 |
|
288 |
// !!! Disable platform security tests until we get the new APIs |
|
289 |
// r=file.Rename(_L("\\newname.txt")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
// test_Value(r, r==KErrPermissionDenied); |
0 | 291 |
|
292 |
test.Next(_L("RFile::Name()")); |
|
293 |
||
294 |
// retrieve the file name from the server |
|
295 |
TFileName name; |
|
296 |
r = file.Name(name); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
test_KErrNone(r); |
0 | 298 |
r = name.Compare(KSvrFileName()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
test_Value(r, r==0); |
0 | 300 |
|
301 |
||
302 |
test.Next(_L("RFile::Duplicate()")); |
|
303 |
RFile file2; |
|
304 |
r = file2.Duplicate(file); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
test_Value(r, r==0); |
0 | 306 |
|
307 |
||
308 |
TInt pos1 = 0; |
|
309 |
r = file.Seek(ESeekCurrent, pos1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
test_KErrNone(r); |
0 | 311 |
TInt pos2 = 0; |
312 |
r = file2.Seek(ESeekCurrent, pos2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
test_Value(pos1, pos1 == pos2); |
0 | 315 |
|
316 |
// close the parent file and check we can still use the duplicated one. |
|
317 |
file.Close(); |
|
318 |
||
319 |
rbuf.FillZ(); |
|
320 |
||
321 |
// reset to pos 0 |
|
322 |
pos2 = 0; |
|
323 |
r = file2.Seek(ESeekStart, pos2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
test_KErrNone(r); |
0 | 325 |
|
326 |
r=file2.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
test_KErrNone(r); |
0 | 328 |
r=rbuf.CompareF(KTestData); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
test_KErrNone(r); |
0 | 330 |
file2.Close(); |
331 |
} |
|
332 |
||
333 |
||
334 |
// Request a test file & test what we can do with it |
|
335 |
// i.e CFileMan::Copy, RFile::Rename() and RFs:Delete() |
|
336 |
// |
|
337 |
void RequestFileTest() |
|
338 |
{ |
|
339 |
TInt r; |
|
340 |
||
341 |
RFs fs; |
|
342 |
r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
test_KErrNone(r); |
0 | 344 |
r=fs.ShareProtected(); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
test_KErrNone(r); |
0 | 346 |
|
347 |
||
348 |
// define a filename in our private path |
|
349 |
TPath newPath; |
|
350 |
fs.PrivatePath(newPath); |
|
351 |
TFileName newFileName; |
|
352 |
newFileName = newPath; |
|
353 |
newFileName.Append(_L("newname.txt")); |
|
354 |
||
355 |
r=fs.CreatePrivatePath(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
test_KErrNone(r); |
0 | 357 |
r=fs.SetSessionToPrivate(drivenum); |
358 |
||
359 |
RFileHandleSharer handsvr; |
|
360 |
do |
|
361 |
{ |
|
362 |
r=handsvr.Connect(); |
|
363 |
} |
|
364 |
while(r==KErrNotFound); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
test_KErrNone(r); |
0 | 366 |
|
367 |
r=handsvr.SetTestDrive(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
test_KErrNone(r); |
0 | 369 |
|
370 |
// Next verify that we can copy a file retrieved from the server |
|
371 |
// using CFileMan::Copy() |
|
372 |
||
373 |
test.Next(_L("CFileMan::Copy()")); |
|
374 |
||
375 |
TInt ssh; |
|
376 |
TInt fsh = handsvr.GetFileHandle2(ssh, EFileRead); |
|
377 |
test (fsh >= 0); |
|
378 |
||
379 |
RFile file; |
|
380 |
r=file.AdoptFromServer(fsh, ssh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
test_KErrNone(r); |
0 | 382 |
|
383 |
||
384 |
CFileMan* fileMan = NULL; |
|
385 |
TRAP(r, fileMan = CFileMan::NewL(fs)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
test_Value(r, r == KErrNone && fileMan != NULL); |
0 | 387 |
|
388 |
// copy to file, overwrite |
|
389 |
r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
test_KErrNone(r); |
0 | 391 |
|
392 |
// copy to file, don't overwrite |
|
393 |
r = fileMan->Copy(file, newFileName, 0); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
test_Value(r, r == KErrAlreadyExists); |
0 | 395 |
|
396 |
// copy to file, overwrite |
|
397 |
r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
test_KErrNone(r); |
0 | 399 |
|
400 |
// copy to path |
|
401 |
r = fileMan->Copy(file, newPath, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
test_KErrNone(r); |
0 | 403 |
|
404 |
// copy to file, overwrite, asynchnonous |
|
405 |
TRequestStatus status(KRequestPending); |
|
406 |
r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite, status); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
test_KErrNone(r); |
0 | 408 |
User::WaitForRequest(status); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
test_KErrNone(status.Int()); |
0 | 410 |
|
411 |
||
412 |
// Negative tests... |
|
413 |
TPath newLongPath; |
|
414 |
TInt len; |
|
415 |
||
416 |
// copy to very long but valid path (no filename) which will overflow |
|
417 |
// when the filename is appended to it |
|
418 |
newLongPath = newPath; |
|
419 |
for (len=newLongPath.Length(); len< KMaxPath -4; len = newLongPath.Length()) |
|
420 |
newLongPath.Append(_L("x\\")); |
|
421 |
r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
test_Value(r, r == KErrBadName); |
0 | 423 |
|
424 |
// copy to very long but valid path (no filename) which will overflow |
|
425 |
// when drive letter is pre-pended to it |
|
426 |
newLongPath = newPath; |
|
427 |
for (len=newLongPath.Length(); len< KMaxPath -2; len = newLongPath.Length()) |
|
428 |
newLongPath.Append(_L("x\\")); |
|
429 |
r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
test_Value(r, r == KErrBadName); |
0 | 431 |
|
432 |
// copy to very long but valid path and filename which will overflow |
|
433 |
// when drive letter is pre-pended to it |
|
434 |
newLongPath.Append(_L("y")); |
|
435 |
r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
test_Value(r, r == KErrBadName); |
0 | 437 |
|
438 |
// copy to badly formed path |
|
439 |
newLongPath = newPath; |
|
440 |
newLongPath.Append(_L("\\y")); |
|
441 |
r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
test_Value(r, r == KErrBadName); |
0 | 443 |
|
444 |
// copy to correctly formed path which doesn't exist |
|
445 |
newLongPath = newPath; |
|
446 |
newLongPath.Append(_L("x\\y\\z")); |
|
447 |
r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
test_Value(r, r == KErrPathNotFound); |
0 | 449 |
|
450 |
delete fileMan; fileMan = NULL; |
|
451 |
||
452 |
file.Close(); |
|
453 |
||
454 |
||
455 |
// First verify that we CANNOT rename a file retrieved from the server |
|
456 |
// that has not been opened in EFileShareExclusive mode |
|
457 |
||
458 |
test.Next(_L("negative test of RFile::Rename()")); |
|
459 |
||
460 |
fsh = handsvr.GetFileHandle2(ssh, TFileMode(EFileShareAny | EFileWrite)); |
|
461 |
test (fsh >= 0); |
|
462 |
||
463 |
// adopt the file handle from FHServer |
|
464 |
r=file.AdoptFromServer(fsh, ssh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
test_KErrNone(r); |
0 | 466 |
|
467 |
r=file.Rename(_L("newname.txt")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied); |
0 | 469 |
|
470 |
// delete the file before we try to rename anything to it |
|
471 |
r = fs.Delete(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 473 |
|
474 |
r=file.Rename(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied); |
0 | 476 |
|
477 |
file.Close(); |
|
478 |
||
479 |
||
480 |
// Next verify that we CAN rename a file retrieved from the server |
|
481 |
// that HAS been opened in EFileShareExclusive mode |
|
482 |
||
483 |
test.Next(_L("RFile::Rename()")); |
|
484 |
||
485 |
fsh = handsvr.GetFileHandle2(ssh, EFileWrite); |
|
486 |
test (fsh >= 0); |
|
487 |
||
488 |
r=file.AdoptFromServer(fsh, ssh); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
test_KErrNone(r); |
0 | 490 |
|
491 |
// delete the file before we try to rename anything to it |
|
492 |
r = fs.Delete(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 494 |
|
495 |
r=file.Rename(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
test_KErrNone(r); |
0 | 497 |
|
498 |
file.Close(); |
|
499 |
||
500 |
// Next verify that we can delete the file (which should now |
|
501 |
// have been moved to our private directory) |
|
502 |
test.Next(_L("RFs::Delete()")); |
|
503 |
r = fs.Delete(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
504 |
test_KErrNone(r); |
0 | 505 |
|
506 |
handsvr.Close(); |
|
507 |
||
508 |
fs.Close(); |
|
509 |
} |
|
510 |
||
511 |
// |
|
512 |
// Pass an open file to the server |
|
513 |
// The server will use RFile::AdoptFromClient() |
|
514 |
// |
|
515 |
GLDEF_C void PassFile() |
|
516 |
{ |
|
517 |
RFs fs; |
|
518 |
TInt r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
test_KErrNone(r); |
0 | 520 |
|
521 |
// Check the number of open file handles |
|
522 |
TInt resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
523 |
test_Value(resCount, resCount == 0); |
0 | 524 |
|
525 |
r=fs.ShareProtected(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
526 |
test_KErrNone(r); |
0 | 527 |
|
528 |
r=fs.CreatePrivatePath(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
529 |
test_KErrNone(r); |
0 | 530 |
r=fs.SetSessionToPrivate(drivenum); |
531 |
||
532 |
||
533 |
RFile file1; |
|
534 |
r=file1.Replace(fs,KCliFileName,EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
test_KErrNone(r); |
0 | 536 |
r=file1.Write(KTestData()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
test_KErrNone(r); |
0 | 538 |
file1.Close(); |
539 |
||
540 |
RFileHandleSharer handsvr; |
|
541 |
do |
|
542 |
{ |
|
543 |
r=handsvr.Connect(); |
|
544 |
} |
|
545 |
while(r==KErrNotFound); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
test_KErrNone(r); |
0 | 547 |
|
548 |
r=handsvr.SetTestDrive(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
test_KErrNone(r); |
0 | 550 |
|
551 |
r=fs.SetSessionToPrivate(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
test_KErrNone(r); |
0 | 553 |
|
554 |
r=file1.Open(fs,KCliFileName,EFileRead); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
test_KErrNone(r); |
0 | 556 |
|
557 |
// pass the file handle to FHServer |
|
558 |
test.Next(_L("RFile::TransferToServer()")); |
|
559 |
||
560 |
TIpcArgs ipcArgs; |
|
561 |
file1.TransferToServer(ipcArgs, 0, 1); |
|
562 |
||
563 |
r = handsvr.PassFileHandle(ipcArgs); |
|
564 |
||
565 |
||
566 |
// verify that the original file handle's position is unchanged |
|
567 |
TInt pos = 0; |
|
568 |
r = file1.Seek(ESeekCurrent, pos); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
test_Value(pos, pos == 0); |
0 | 571 |
|
572 |
// make sure we can still use it |
|
573 |
TBuf8<100> rbuf; |
|
574 |
r=file1.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
test_KErrNone(r); |
0 | 576 |
|
577 |
// Close the file |
|
578 |
file1.Close(); |
|
579 |
||
580 |
handsvr.Close(); |
|
581 |
||
582 |
r=fs.MkDir(_L("C:\\mdir")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
583 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
0 | 584 |
|
585 |
// Check the number of open file handles |
|
586 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
test_Value(resCount, resCount == 0); |
0 | 588 |
|
589 |
fs.Close(); |
|
590 |
} |
|
591 |
||
592 |
||
593 |
// |
|
594 |
// Pass an invalid file handle to the server |
|
595 |
// The server will use RFile::AdoptFromClient() |
|
596 |
// |
|
597 |
GLDEF_C void PassInvalidFile() |
|
598 |
{ |
|
599 |
||
600 |
RFs fs; |
|
601 |
TInt r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
test_KErrNone(r); |
0 | 603 |
|
604 |
// Check the number of open file handles |
|
605 |
TInt resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
606 |
test_Value(resCount, resCount == 0); |
0 | 607 |
|
608 |
r=fs.ShareProtected(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
test_KErrNone(r); |
0 | 610 |
|
611 |
r=fs.CreatePrivatePath(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
test_KErrNone(r); |
0 | 613 |
r=fs.SetSessionToPrivate(drivenum); |
614 |
||
615 |
||
616 |
RFile file1; |
|
617 |
r=file1.Replace(fs,KCliFileName,EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
618 |
test_KErrNone(r); |
0 | 619 |
r=file1.Write(KTestData()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
test_KErrNone(r); |
0 | 621 |
file1.Close(); |
622 |
||
623 |
RFileHandleSharer handsvr; |
|
624 |
do |
|
625 |
{ |
|
626 |
r=handsvr.Connect(); |
|
627 |
} |
|
628 |
while(r==KErrNotFound); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
test_KErrNone(r); |
0 | 630 |
|
631 |
r=handsvr.SetTestDrive(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
test_KErrNone(r); |
0 | 633 |
|
634 |
r=fs.SetSessionToPrivate(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
test_KErrNone(r); |
0 | 636 |
|
637 |
r=file1.Open(fs,KCliFileName,EFileRead); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
638 |
test_KErrNone(r); |
0 | 639 |
|
640 |
// check the resoure count - there should be 1 open file handle |
|
641 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
test_Value(resCount, resCount == 1); |
0 | 643 |
|
644 |
// pass an invalid file handle to FHServer |
|
645 |
// by overwriting the IPC slots |
|
646 |
test.Next(_L("PassInvalidFileHandle - RFile::TransferToServer()")); |
|
647 |
||
648 |
TIpcArgs ipcArgs; |
|
649 |
||
650 |
// Pass a bad RFs handle |
|
651 |
file1.TransferToServer(ipcArgs, 0, 1); |
|
652 |
||
653 |
// check the resoure count - there should be 2 open file handles |
|
654 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
655 |
test_Value(resCount, resCount == 2); |
0 | 656 |
|
657 |
ipcArgs.Set(0, 0); // invalidate the RFs handle |
|
658 |
r = handsvr.PassInvalidFileHandle(ipcArgs); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
test_Value(r, r == KErrBadHandle); |
0 | 660 |
|
661 |
// Pass a bad RFile handle |
|
662 |
file1.TransferToServer(ipcArgs, 0, 1); |
|
663 |
||
664 |
// check the resoure count - there should be 3 open file handles |
|
665 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
666 |
test_Value(resCount, resCount == 3); |
0 | 667 |
|
668 |
ipcArgs.Set(1, 0); // invalidate the RFile handle |
|
669 |
r = handsvr.PassInvalidFileHandle(ipcArgs); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
670 |
test_Value(r, r == KErrBadHandle); |
0 | 671 |
|
672 |
// Pass bad RFs and RFile handles |
|
673 |
file1.TransferToServer(ipcArgs, 0, 1); |
|
674 |
||
675 |
// check the resoure count - there should be 4 open file handles |
|
676 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
677 |
test_Value(resCount, resCount == 4); |
0 | 678 |
|
679 |
||
680 |
ipcArgs.Set(0, 0); // invalidate the RFs handle |
|
681 |
ipcArgs.Set(1, 0); // invalidate the RFile handle |
|
682 |
r = handsvr.PassInvalidFileHandle(ipcArgs); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
test_Value(r, r == KErrBadHandle); |
0 | 684 |
|
685 |
// Close the file |
|
686 |
handsvr.Close(); |
|
687 |
file1.Close(); |
|
688 |
||
689 |
// Check the number of open file handles |
|
690 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
test_Value(resCount, resCount == 3); |
0 | 692 |
|
693 |
fs.Close(); |
|
694 |
} |
|
695 |
||
696 |
||
697 |
// Pass RFs/RFile handles to the server using |
|
698 |
// process parameter slots (RProcess::SetParameter()), |
|
699 |
// resume the process and wait for it to read the file... |
|
700 |
// The server will use RFile::AdoptFromCreator() |
|
701 |
GLDEF_C void PassFile(RProcess& aProcess) |
|
702 |
{ |
|
703 |
||
704 |
RFs fs; |
|
705 |
TInt r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
test_KErrNone(r); |
0 | 707 |
|
708 |
// Check the number of open file handles |
|
709 |
TInt resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
test_Value(resCount, resCount == 0); |
0 | 711 |
|
712 |
r=fs.ShareProtected(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
713 |
test_KErrNone(r); |
0 | 714 |
|
715 |
r=fs.CreatePrivatePath(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
test_KErrNone(r); |
0 | 717 |
r=fs.SetSessionToPrivate(drivenum); |
718 |
||
719 |
||
720 |
RFile file1; |
|
721 |
r=file1.Replace(fs,KCliFileName,EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
test_KErrNone(r); |
0 | 723 |
r=file1.Write(KTestData()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
test_KErrNone(r); |
0 | 725 |
file1.Close(); |
726 |
||
727 |
r=file1.Open(fs, KCliFileName, EFileWrite); |
|
728 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
test_KErrNone(r); |
0 | 730 |
|
731 |
// NB slot 0 is reserved for the command line |
|
732 |
||
733 |
test.Next(_L("RFile::TransferToProcess()")); |
|
734 |
||
735 |
r = file1.TransferToProcess(aProcess, 1, 2); |
|
736 |
||
737 |
r = aProcess.SetParameter(3, drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
test_KErrNone(r); |
0 | 739 |
|
740 |
r=fs.SetSessionToPrivate(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
741 |
test_KErrNone(r); |
0 | 742 |
|
743 |
// make sure we can still read from the file |
|
744 |
TBuf8<100> rbuf; |
|
745 |
r=file1.Read(0,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
test_KErrNone(r); |
0 | 747 |
r=rbuf.CompareF(KTestData()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
748 |
test_KErrNone(r); |
0 | 749 |
file1.Close(); |
750 |
||
751 |
r=fs.MkDir(_L("C:\\mdir")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
752 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
0 | 753 |
|
754 |
// Check the number of open file handles - |
|
755 |
// should be 1 (the one duplicated for the other process) |
|
756 |
resCount = fs.ResourceCount(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
test_Value(resCount, resCount == 1); |
0 | 758 |
|
759 |
fs.Close(); |
|
760 |
||
761 |
// Start the server thread |
|
762 |
aProcess.Resume(); |
|
763 |
||
764 |
||
765 |
||
766 |
// connect to the server |
|
767 |
RFileHandleSharer handsvr; |
|
768 |
do |
|
769 |
{ |
|
770 |
r=handsvr.Connect(); |
|
771 |
} |
|
772 |
while(r==KErrNotFound); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
test_KErrNone(r); |
0 | 774 |
|
775 |
||
776 |
r=handsvr.SetTestDrive(drivenum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
test_KErrNone(r); |
0 | 778 |
|
779 |
// wait for server to read the file |
|
780 |
r = handsvr.PassFileHandleProcess(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
test_KErrNone(r); |
0 | 782 |
|
783 |
handsvr.Close(); |
|
784 |
} |
|
785 |
||
786 |
||
787 |
||
788 |
GLDEF_C void CallTestsL(void) |
|
789 |
{ |
|
790 |
RFs::CharToDrive(gDriveToTest,drivenum); |
|
791 |
||
792 |
// make sure the session path exists |
|
793 |
RFs fs; |
|
794 |
TInt r = fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
795 |
test_KErrNone(r); |
0 | 796 |
|
797 |
TFileName sessionp; |
|
798 |
fs.SessionPath(sessionp); |
|
799 |
r = fs.MkDirAll(sessionp); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
800 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
0 | 801 |
fs.Close(); |
802 |
||
803 |
// Remember the number of open handles. Just for a sanity check .... |
|
804 |
TInt start_thc, start_phc; |
|
805 |
RThread().HandleCount(start_phc, start_thc); |
|
806 |
test.Printf(_L("Handles: start_phc %d, start_thc %d\n"), start_phc, start_thc); |
|
807 |
||
808 |
//create test server |
|
809 |
RProcess p; |
|
810 |
r = p.Create(_L("FHServer.exe"), KNullDesC); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
811 |
test_KErrNone(r); |
0 | 812 |
|
813 |
// RFile::Duplicate() tests |
|
814 |
Duplicate(); |
|
815 |
||
816 |
// Pass RFs/RFile handles to the server using RFile::TransferToProcess() |
|
817 |
// process parameter slots (RProcess::SetParameter()), |
|
818 |
// resume the server process and wait for it to read the file... |
|
819 |
PassFile(p); |
|
820 |
||
821 |
// Transfer the file handle to FHServer using RFile::TransferToServer(). |
|
822 |
// Get FHServer to transfer it to FHServer2 |
|
823 |
PassFile(); |
|
824 |
||
825 |
||
826 |
// Get an open writeable file from FHServer2 via FHServer |
|
827 |
// using RFile::AdoptFromServer() |
|
828 |
RequestFileWrite(); |
|
829 |
// Deprecated RFile::Adopt() test |
|
830 |
RequestFileDeprecatedAdopt(); |
|
831 |
||
832 |
// negative test |
|
833 |
// Pass an invalid file handle to the server |
|
834 |
PassInvalidFile(); |
|
835 |
||
836 |
||
837 |
// Get an open file handle from FHServer2 via FHServer |
|
838 |
// and test whether we can copy/rename/delete it etc |
|
839 |
// be able to rename it. |
|
840 |
RequestFileTest(); |
|
841 |
||
842 |
// stop the servers |
|
843 |
RFileHandleSharer handsvr; |
|
844 |
r=handsvr.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
845 |
test_KErrNone(r); |
0 | 846 |
r = handsvr.Exit(); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
test_KErrNone(r); |
0 | 848 |
handsvr.Close(); |
849 |
||
850 |
// delete the test file |
|
851 |
RFs cleanupfs; |
|
852 |
r=cleanupfs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
853 |
test_KErrNone(r); |
0 | 854 |
r=cleanupfs.SetSessionToPrivate(drivenum); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
855 |
test_KErrNone(r); |
0 | 856 |
r=cleanupfs.Delete(KCliFileName); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
857 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
0 | 858 |
cleanupfs.Close(); |
859 |
||
860 |
||
861 |
// wait for server process to end |
|
862 |
TRequestStatus status; |
|
863 |
p.Logon(status); |
|
864 |
User::WaitForRequest(status); |
|
865 |
test (status == KErrNone); |
|
866 |
||
867 |
// cleanup |
|
868 |
p.Close(); |
|
869 |
||
870 |
// Sanity check for open handles |
|
871 |
TInt end_thc, end_phc; |
|
872 |
RThread().HandleCount(end_phc, end_thc); |
|
873 |
test.Printf(_L("Handles: end_phc %d, end_thc %d\n"), end_phc, end_thc); |
|
874 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
875 |
test_Value(start_thc, start_thc == end_thc); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
876 |
test_Value(start_phc, start_phc == end_phc); |
0 | 877 |
|
878 |
// and also for pending requests ... |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
879 |
test_Value(RThread().RequestCount(), RThread().RequestCount() == 0); |
0 | 880 |
|
881 |
||
882 |
RDebug::Print(_L("End Of Tests")); |
|
883 |
} |
|
884 |
||
885 |
||
886 |