author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 19 | 4a8fed1c0ef6 |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1999-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\loader\handshare.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <e32svr.h> |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
19 |
#define __E32TEST_EXTENSION__ |
0 | 20 |
#include <e32test.h> |
21 |
#include "handshare.h" |
|
22 |
||
23 |
#ifdef __VC32__ |
|
24 |
#pragma warning(disable:4706) |
|
25 |
#endif |
|
26 |
||
27 |
||
28 |
||
29 |
GLDEF_D RTest test(_L("HANDSHARE_SVR")); |
|
30 |
||
31 |
#define PANIC() FHSvrPanic(__LINE__) |
|
32 |
#define FHS_ASSERT(c) ((void)((c)||(PANIC(),0))) |
|
33 |
||
34 |
const TTimeIntervalMicroSeconds32 KHalfSecond(500000); |
|
35 |
||
36 |
const TInt KHeapSize=0x2000; |
|
37 |
||
38 |
void FHSvrPanic(TInt aLine) |
|
39 |
{ |
|
40 |
User::Panic(_L("FHServer"),aLine); |
|
41 |
} |
|
42 |
||
43 |
LOCAL_D TInt gTestDrive; |
|
44 |
||
45 |
/****************************************************************************** |
|
46 |
* Class Definitions |
|
47 |
******************************************************************************/ |
|
48 |
||
49 |
||
50 |
class CFHServer : public CServer2 |
|
51 |
{ |
|
52 |
public: |
|
53 |
static CFHServer* NewL(); |
|
54 |
void ConstructL(); |
|
55 |
virtual ~CFHServer(); |
|
56 |
virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const; |
|
57 |
virtual TInt RunError(TInt aError); |
|
58 |
private: |
|
59 |
CFHServer(); |
|
60 |
}; |
|
61 |
||
62 |
class CFHSession : public CSession2 |
|
63 |
{ |
|
64 |
public: |
|
65 |
virtual ~CFHSession(); |
|
66 |
virtual void CreateL(); |
|
67 |
virtual void ServiceL(const RMessage2& aMessage); |
|
68 |
public: |
|
69 |
||
70 |
void GetFileHandle(const RMessage2& aMsg); |
|
71 |
void GetFileHandle2(const RMessage2& aMsg); |
|
72 |
void PassFileHandle(const RMessage2& aMsg); |
|
73 |
void PassFileHandleProcess(const RMessage2& aMsg); |
|
74 |
void PassInvalidFileHandle(const RMessage2& aMsg); |
|
75 |
}; |
|
76 |
||
77 |
// a second server so we can test passing file handles from |
|
78 |
// client to server to server2 |
|
79 |
class CFHServer2 : public CServer2 |
|
80 |
{ |
|
81 |
public: |
|
82 |
static CFHServer2* NewL(); |
|
83 |
void ConstructL(); |
|
84 |
virtual ~CFHServer2(); |
|
85 |
virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const; |
|
86 |
virtual TInt RunError(TInt aError); |
|
87 |
private: |
|
88 |
CFHServer2(); |
|
89 |
public: |
|
90 |
}; |
|
91 |
||
92 |
||
93 |
class CFHSession2 : public CSession2 |
|
94 |
{ |
|
95 |
public: |
|
96 |
virtual ~CFHSession2(); |
|
97 |
virtual void CreateL(); |
|
98 |
virtual void ServiceL(const RMessage2& aMessage); |
|
99 |
public: |
|
100 |
void PassFileHandle(const RMessage2& aMsg); |
|
101 |
void GetFileHandle(const RMessage2& aMsg); |
|
102 |
}; |
|
103 |
||
104 |
||
105 |
/****************************************************************************** |
|
106 |
* Class CFHSession/CFHServer |
|
107 |
******************************************************************************/ |
|
108 |
void ExceptionHandler(TExcType) |
|
109 |
{ |
|
110 |
User::Leave(KErrGeneral); |
|
111 |
} |
|
112 |
||
113 |
||
114 |
||
115 |
CFHSession::~CFHSession() |
|
116 |
{ |
|
117 |
} |
|
118 |
||
119 |
void CFHSession::CreateL() |
|
120 |
{ |
|
121 |
||
122 |
} |
|
123 |
||
124 |
void CFHSession::ServiceL(const RMessage2& aMessage) |
|
125 |
{ |
|
126 |
__UHEAP_MARK; |
|
127 |
TInt mid=aMessage.Function(); |
|
128 |
switch(mid) |
|
129 |
{ |
|
130 |
case RFileHandleSharer::EMsgGetFileHandle: |
|
131 |
GetFileHandle(aMessage); |
|
132 |
break; |
|
133 |
||
134 |
case RFileHandleSharer::EMsgGetFileHandle2: |
|
135 |
GetFileHandle2(aMessage); |
|
136 |
break; |
|
137 |
||
138 |
case RFileHandleSharer::EMsgPassFileHandle: |
|
139 |
PassFileHandle(aMessage); |
|
140 |
break; |
|
141 |
||
142 |
case RFileHandleSharer::EMsgPassFileHandleProcess: |
|
143 |
PassFileHandleProcess(aMessage); |
|
144 |
break; |
|
145 |
||
146 |
case RFileHandleSharer::EMsgPassInvalidFileHandle: |
|
147 |
PassInvalidFileHandle(aMessage); |
|
148 |
break; |
|
149 |
||
150 |
case RFileHandleSharer::EMsgExit: |
|
151 |
{ |
|
152 |
// stop server2 |
|
153 |
RFileHandleSharer2 handsvr2; |
|
154 |
TInt r=handsvr2.Connect(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
155 |
test_KErrNone(r); |
0 | 156 |
r = handsvr2.Exit(); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
157 |
test_Value(r, r ==KErrNone || r == KErrServerTerminated); |
0 | 158 |
handsvr2.Close(); |
159 |
||
160 |
aMessage.Complete(KErrNone); |
|
161 |
||
162 |
CActiveScheduler::Stop(); |
|
163 |
} |
|
164 |
break; |
|
165 |
||
166 |
case RFileHandleSharer::EMsgSync: |
|
167 |
aMessage.Complete(KErrNone); |
|
168 |
break; |
|
169 |
||
170 |
case RFileHandleSharer::EMsgDrive: |
|
171 |
gTestDrive=aMessage.Int0(); |
|
172 |
aMessage.Complete(KErrNone); |
|
173 |
break; |
|
174 |
default: |
|
175 |
break; |
|
176 |
} |
|
177 |
__UHEAP_MARKEND; |
|
178 |
} |
|
179 |
||
180 |
||
181 |
// |
|
182 |
// Returns session and relevant file handle to Client in read mode |
|
183 |
// This is to allow the client to test the deprcated function RFile::Adopt() |
|
184 |
void CFHSession::GetFileHandle(const RMessage2& aMsg) |
|
185 |
{ |
|
186 |
test.Printf(_L("Get file handle")); |
|
187 |
||
188 |
// get the requested file mode |
|
189 |
TInt fileMode = aMsg.Int1(); |
|
190 |
||
191 |
RFs fs; |
|
192 |
TInt r=fs.Connect(); |
|
193 |
r=fs.CreatePrivatePath(gTestDrive); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
194 |
test_KErrNone(r); |
0 | 195 |
r=fs.SetSessionToPrivate(gTestDrive); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
196 |
test_KErrNone(r); |
0 | 197 |
r=fs.ShareProtected(); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
198 |
test_KErrNone(r); |
0 | 199 |
RFile file1; |
200 |
r=file1.Create(fs,KSvrFileName,EFileWrite); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
201 |
test_Value(r, r ==KErrNone || r==KErrAlreadyExists); |
0 | 202 |
if (r==KErrAlreadyExists) |
203 |
{ |
|
204 |
r=file1.Open(fs,KSvrFileName, EFileWrite); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
205 |
test_KErrNone(r); |
0 | 206 |
} |
207 |
r=file1.Write(KTestData1()); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
208 |
test_KErrNone(r); |
0 | 209 |
file1.Close(); |
210 |
||
211 |
r=file1.Open(fs,KSvrFileName, fileMode); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
212 |
test_KErrNone(r); |
0 | 213 |
|
214 |
TInt fssh=file1.SubSessionHandle(); |
|
215 |
r=aMsg.Write(0, TPckgC<TInt>(fssh)); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
216 |
test_KErrNone(r); |
0 | 217 |
aMsg.Complete(fs); |
218 |
fs.Close(); |
|
219 |
} |
|
220 |
||
221 |
// |
|
222 |
// Returns a file handle from server2 |
|
223 |
// |
|
224 |
void CFHSession::GetFileHandle2(const RMessage2& aMsg) |
|
225 |
{ |
|
226 |
test.Next(_L("RFile::AdoptFromServer()")); |
|
227 |
||
228 |
// pass the request on to FHServer2 - this will create a file |
|
229 |
// which we can then adopt before returning it to the client |
|
230 |
||
231 |
// get the requested file mode |
|
232 |
TInt fileMode = aMsg.Int1(); |
|
233 |
||
234 |
RFileHandleSharer2 handsvr2; |
|
235 |
TInt r = handsvr2.Connect(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
236 |
test_KErrNone(r); |
0 | 237 |
|
238 |
TInt ssh; |
|
239 |
TInt fsh = handsvr2.GetFileHandle(ssh, TFileMode(fileMode)); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
240 |
test_Value(fsh, fsh >= 0); |
0 | 241 |
|
242 |
// adopt the file from FHServer2 |
|
243 |
RFile file; |
|
244 |
r=file.AdoptFromServer(fsh, ssh); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
245 |
test_KErrNone(r); |
0 | 246 |
|
247 |
test.Next(_L("RFile::TransferToClient()")); |
|
248 |
||
249 |
// transfer the file to the client |
|
250 |
r = file.TransferToClient(aMsg, 0); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
251 |
test_KErrNone(r); |
0 | 252 |
|
253 |
// test we can still use the file |
|
254 |
TInt pos = 0; |
|
255 |
r = file.Seek(ESeekStart, pos); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
256 |
test_KErrNone(r); |
0 | 257 |
TBuf8<100> rbuf; |
258 |
r=file.Read(0,rbuf); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
259 |
test_KErrNone(r); |
0 | 260 |
r=rbuf.CompareF(KTestData1()); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
261 |
test_KErrNone(r); |
0 | 262 |
|
263 |
handsvr2.Close(); |
|
264 |
||
265 |
file.Close(); |
|
266 |
||
267 |
RDebug::Print(_L("completed")); |
|
268 |
} |
|
269 |
||
270 |
void CFHSession::PassFileHandle(const RMessage2& aMsg) |
|
271 |
// |
|
272 |
// Adopts file from test program and tests what it can and can't do |
|
273 |
// Uses new AdoptFromClient() API |
|
274 |
// |
|
275 |
{ |
|
276 |
test.Next(_L("RFile::AdoptFromClient()")); |
|
277 |
||
278 |
// connect to FHServer2 |
|
279 |
RFileHandleSharer2 handsvr2; |
|
280 |
TInt r = handsvr2.Connect(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
281 |
test_KErrNone(r); |
0 | 282 |
|
283 |
RFile file; |
|
284 |
||
285 |
// Message slot 0 is a RFs handle |
|
286 |
// Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
|
287 |
r = file.AdoptFromClient(aMsg, 0, 1); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
288 |
test_KErrNone(r); |
0 | 289 |
|
290 |
||
291 |
||
292 |
TBuf8<100> rbuf; |
|
293 |
r=file.Read(0,rbuf); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
294 |
test_KErrNone(r); |
0 | 295 |
r=rbuf.CompareF(KTestData()); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
296 |
test_KErrNone(r); |
0 | 297 |
r=file.Write(KTestData1()); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
298 |
test_Value(r, r ==KErrAccessDenied); |
0 | 299 |
r=file.ChangeMode(EFileWrite); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
300 |
test_Value(r, r ==KErrArgument); |
0 | 301 |
r=file.Rename(_L("\\newname.txt")); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
302 |
test_Value(r, r ==KErrPermissionDenied || r==KErrAccessDenied); |
0 | 303 |
// should try a delete |
304 |
||
305 |
// pass the file handle to FHServer2 |
|
306 |
test.Next(_L("RFile::TransferToServer()")); |
|
307 |
||
308 |
TIpcArgs ipcArgs; |
|
309 |
file.TransferToServer(ipcArgs, 0, 1); |
|
310 |
r = handsvr2.PassFileHandle(ipcArgs); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
311 |
test_KErrNone(r); |
0 | 312 |
|
313 |
TInt pos = 0; |
|
314 |
r = file.Seek(ESeekStart, pos); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
315 |
test_KErrNone(r); |
0 | 316 |
r=file.Read(0,rbuf); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
317 |
test_KErrNone(r); |
0 | 318 |
r=rbuf.CompareF(KTestData()); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
319 |
test_KErrNone(r); |
0 | 320 |
|
321 |
file.Close(); |
|
322 |
||
323 |
handsvr2.Close(); |
|
324 |
||
325 |
aMsg.Complete(KErrNone); |
|
326 |
} |
|
327 |
||
328 |
// |
|
329 |
// Adopts file from test program and tests what it can and can't do |
|
330 |
// Uses new AdoptFromCreator() API |
|
331 |
// |
|
332 |
void CFHSession::PassFileHandleProcess(const RMessage2& aMsg) |
|
333 |
{ |
|
334 |
test.Next(_L("RFile::AdoptFromCreator()")); |
|
335 |
||
336 |
RFile file; |
|
337 |
TInt r = file.AdoptFromCreator(1, 2); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
338 |
test_KErrNone(r); |
0 | 339 |
|
340 |
TBuf8<100> rbuf; |
|
341 |
r=file.Read(0,rbuf); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
342 |
test_KErrNone(r); |
0 | 343 |
r=rbuf.CompareF(KTestData()); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
344 |
test_KErrNone(r); |
0 | 345 |
|
346 |
test.Next(_L("RFile::Rename()")); |
|
347 |
||
348 |
// define a filename in our private path |
|
349 |
RFs fs; |
|
350 |
r=fs.Connect(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
351 |
test_KErrNone(r); |
0 | 352 |
|
353 |
TFileName sessionp; |
|
354 |
fs.SessionPath(sessionp); |
|
355 |
r = fs.MkDirAll(sessionp); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
356 |
test_Value(r, r ==KErrNone || r==KErrAlreadyExists); |
0 | 357 |
|
358 |
r=fs.ShareProtected(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
359 |
test_KErrNone(r); |
0 | 360 |
|
361 |
r=fs.CreatePrivatePath(gTestDrive); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
362 |
test_KErrNone(r); |
0 | 363 |
r=fs.SetSessionToPrivate(gTestDrive); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
364 |
test_KErrNone(r); |
0 | 365 |
|
366 |
TPath newPath; |
|
367 |
fs.PrivatePath(newPath); |
|
368 |
TFileName newFileName; |
|
369 |
newFileName = newPath; |
|
370 |
newFileName.Append(_L("newname.txt")); |
|
371 |
||
372 |
// delete the file before we try to rename anything to it |
|
373 |
r = fs.Delete(newFileName); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
374 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 375 |
|
376 |
r=file.Rename(newFileName); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
377 |
test_KErrNone(r); |
0 | 378 |
|
379 |
file.Close(); |
|
380 |
||
381 |
// Next verify that we can delete the file (which should now |
|
382 |
// have been moved to our private directory) |
|
383 |
test.Next(_L("RFs::Delete()")); |
|
384 |
r = fs.Delete(newFileName); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
385 |
test_KErrNone(r); |
0 | 386 |
|
387 |
fs.Close(); |
|
388 |
||
389 |
||
390 |
aMsg.Complete(KErrNone); |
|
391 |
} |
|
392 |
||
393 |
void CFHSession::PassInvalidFileHandle(const RMessage2& aMsg) |
|
394 |
// |
|
395 |
// Attempts to adopt an invalid file handle from test program |
|
396 |
// and tests that KErrBadHandle is returned by AdoptFromClient() |
|
397 |
// |
|
398 |
{ |
|
399 |
test.Next(_L("PassInvalidFileHandle - RFile::AdoptFromClient()")); |
|
400 |
||
401 |
RFile file; |
|
402 |
||
403 |
// Message slot 0 is a RFs handle |
|
404 |
// Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
|
405 |
TInt r = file.AdoptFromClient(aMsg, 0, 1); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
406 |
test_Value(r, r ==KErrBadHandle); |
0 | 407 |
|
408 |
||
409 |
aMsg.Complete(r); |
|
410 |
} |
|
411 |
||
412 |
CFHServer* CFHServer::NewL() |
|
413 |
{ |
|
414 |
CFHServer* server = new (ELeave) CFHServer; |
|
415 |
CleanupStack::PushL(server); |
|
416 |
server->ConstructL(); |
|
417 |
CleanupStack::Pop(server); |
|
418 |
return server; |
|
419 |
} |
|
420 |
||
421 |
void CFHServer::ConstructL() |
|
422 |
{ |
|
423 |
} |
|
424 |
||
425 |
CFHServer::CFHServer() |
|
426 |
: CServer2(0,ESharableSessions) |
|
427 |
{ |
|
428 |
} |
|
429 |
||
430 |
CFHServer::~CFHServer() |
|
431 |
{ |
|
432 |
} |
|
433 |
||
434 |
CSession2* CFHServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const |
|
435 |
// |
|
436 |
// Create New Session |
|
437 |
// |
|
438 |
{ |
|
439 |
(void)aVersion; |
|
440 |
CFHSession* s = new (ELeave) CFHSession; |
|
441 |
return s; |
|
442 |
} |
|
443 |
||
444 |
_LIT(KErr,"FHSERVER_ERR"); |
|
445 |
CFHServer2* CFHServer2::NewL() |
|
446 |
{ |
|
447 |
CFHServer2* server = new (ELeave) CFHServer2; |
|
448 |
CleanupStack::PushL(server); |
|
449 |
server->ConstructL(); |
|
450 |
CleanupStack::Pop(server); |
|
451 |
return server; |
|
452 |
} |
|
453 |
||
454 |
void CFHServer2::ConstructL() |
|
455 |
{ |
|
456 |
} |
|
457 |
||
458 |
TInt CFHServer::RunError(TInt aError) |
|
459 |
{ |
|
460 |
User::Panic(KErr,aError); |
|
461 |
return 0; |
|
462 |
} |
|
463 |
||
464 |
// File handle server #2 |
|
465 |
CFHServer2::CFHServer2() |
|
466 |
: CServer2(0,ESharableSessions) |
|
467 |
{ |
|
468 |
} |
|
469 |
||
470 |
CFHServer2::~CFHServer2() |
|
471 |
{ |
|
472 |
} |
|
473 |
||
474 |
CSession2* CFHServer2::NewSessionL(const TVersion& aVersion, const RMessage2&) const |
|
475 |
// |
|
476 |
// Create New Session |
|
477 |
// |
|
478 |
{ |
|
479 |
(void)aVersion; |
|
480 |
CFHSession2* s = new (ELeave) CFHSession2; |
|
481 |
return s; |
|
482 |
} |
|
483 |
||
484 |
_LIT(KErr2,"FHSERVER2_ERR"); |
|
485 |
TInt CFHServer2::RunError(TInt aError) |
|
486 |
{ |
|
487 |
User::Panic(KErr2,aError); |
|
488 |
return 0; |
|
489 |
} |
|
490 |
||
491 |
CFHSession2::~CFHSession2() |
|
492 |
{ |
|
493 |
} |
|
494 |
||
495 |
void CFHSession2::CreateL() |
|
496 |
{ |
|
497 |
||
498 |
} |
|
499 |
||
500 |
void CFHSession2::ServiceL(const RMessage2& aMessage) |
|
501 |
{ |
|
502 |
__UHEAP_MARK; |
|
503 |
TInt mid=aMessage.Function(); |
|
504 |
switch(mid) |
|
505 |
{ |
|
506 |
case RFileHandleSharer::EMsgPassFileHandle: |
|
507 |
PassFileHandle(aMessage); |
|
508 |
break; |
|
509 |
||
510 |
case RFileHandleSharer::EMsgGetFileHandle: |
|
511 |
GetFileHandle(aMessage); |
|
512 |
break; |
|
513 |
||
514 |
case RFileHandleSharer::EMsgExit: |
|
515 |
aMessage.Complete(KErrNone); |
|
516 |
CActiveScheduler::Stop(); |
|
517 |
break; |
|
518 |
||
519 |
default: |
|
520 |
break; |
|
521 |
} |
|
522 |
__UHEAP_MARKEND; |
|
523 |
} |
|
524 |
||
525 |
||
526 |
// |
|
527 |
// Adopts file from server 1 |
|
528 |
// |
|
529 |
void CFHSession2::PassFileHandle(const RMessage2& aMsg) |
|
530 |
{ |
|
531 |
RFile file; |
|
532 |
||
533 |
// Message slot 0 is a RFs handle |
|
534 |
// Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
|
535 |
TInt r = file.AdoptFromClient(aMsg, 0, 1); |
|
536 |
if (r != KErrNone) |
|
537 |
{ |
|
538 |
aMsg.Complete(r); |
|
539 |
return; |
|
540 |
} |
|
541 |
||
542 |
||
543 |
TBuf8<100> rbuf; |
|
544 |
||
545 |
if (r == KErrNone) |
|
546 |
r=file.Read(0,rbuf); |
|
547 |
||
548 |
if (r == KErrNone) |
|
549 |
r = rbuf.CompareF(KTestData()); |
|
550 |
||
551 |
if (r == KErrNone) |
|
552 |
{ |
|
553 |
r = file.Write(KTestData1()); |
|
554 |
if (r == KErrAccessDenied) |
|
555 |
r = KErrNone; |
|
556 |
} |
|
557 |
||
558 |
if (r == KErrNone) |
|
559 |
{ |
|
560 |
r = file.ChangeMode(EFileWrite); |
|
561 |
if (r == KErrArgument) |
|
562 |
r = KErrNone; |
|
563 |
} |
|
564 |
||
565 |
if (r == KErrNone) |
|
566 |
{ |
|
567 |
r = file.Rename(_L("\\newname.txt")); |
|
568 |
if (r == KErrPermissionDenied || r == KErrAccessDenied) |
|
569 |
r = KErrNone; |
|
570 |
} |
|
571 |
||
572 |
file.Close(); |
|
573 |
||
574 |
aMsg.Complete(r); |
|
575 |
} |
|
576 |
||
577 |
||
578 |
void CFHSession2::GetFileHandle(const RMessage2& aMsg) |
|
579 |
// |
|
580 |
// Returns a file handle in write mode |
|
581 |
// |
|
582 |
{ |
|
583 |
RFs fs; |
|
584 |
TInt r = fs.Connect(); |
|
585 |
||
586 |
if (r == KErrNone) |
|
587 |
r = fs.CreatePrivatePath(gTestDrive); |
|
588 |
||
589 |
if (r == KErrNone) |
|
590 |
r = fs.SetSessionToPrivate(gTestDrive); |
|
591 |
||
592 |
if (r == KErrNone) |
|
593 |
r = fs.ShareProtected(); |
|
594 |
||
595 |
// make sure file exists & has valid data in it |
|
596 |
RFile file1; |
|
597 |
if (r == KErrNone) |
|
598 |
r = file1.Replace(fs,KSvrFileName,EFileWrite); |
|
599 |
||
600 |
if (r == KErrNone) |
|
601 |
r = file1.Write(KTestData1()); |
|
602 |
||
603 |
file1.Close(); |
|
604 |
||
605 |
||
606 |
// re-open the file with the mode the client has requested & pass it to the client |
|
607 |
TFileMode fileMode = TFileMode(aMsg.Int1()); |
|
608 |
if (r == KErrNone) |
|
609 |
r = file1.Open(fs,KSvrFileName, fileMode); |
|
610 |
if (r == KErrNone) |
|
611 |
r = file1.TransferToClient(aMsg, 0); |
|
612 |
file1.Close(); |
|
613 |
||
614 |
fs.Close(); |
|
615 |
||
616 |
if (r != KErrNone) |
|
617 |
aMsg.Complete(r); |
|
618 |
} |
|
619 |
||
620 |
LOCAL_C TInt FHServer2(TAny * /*anArg*/) |
|
621 |
{ |
|
622 |
RTest test(_L("FHServer2")); |
|
623 |
||
624 |
// Remember the number of open handles. Just for a sanity check .... |
|
625 |
TInt start_thc, start_phc; |
|
626 |
RThread().HandleCount(start_phc, start_thc); |
|
627 |
||
628 |
||
629 |
CTrapCleanup* cleanup; |
|
630 |
cleanup=CTrapCleanup::New(); |
|
631 |
||
632 |
CActiveScheduler* sched=new CActiveScheduler; |
|
633 |
FHS_ASSERT(sched); |
|
634 |
CActiveScheduler::Install(sched); |
|
635 |
||
636 |
CFHServer2* svr2 = NULL; |
|
637 |
TRAP_IGNORE(svr2 = CFHServer2::NewL()); |
|
638 |
FHS_ASSERT(svr2); |
|
639 |
FHS_ASSERT(svr2->Start(_L("FHServer2"))==KErrNone); |
|
640 |
||
641 |
CActiveScheduler::Start(); |
|
642 |
||
643 |
delete svr2; |
|
644 |
delete sched; |
|
645 |
||
646 |
delete cleanup; |
|
647 |
||
648 |
// Sanity check for open handles |
|
649 |
TInt end_thc, end_phc; |
|
650 |
RThread().HandleCount(end_phc, end_thc); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
651 |
test_Value(start_thc, start_thc == end_thc); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
652 |
// test(start_phc == end_phc); |
0 | 653 |
// and also for pending requests ... |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
654 |
test_Value(RThread().RequestCount(), RThread().RequestCount() == 0); |
0 | 655 |
|
656 |
||
657 |
return KErrNone; |
|
658 |
} |
|
659 |
||
660 |
||
661 |
||
662 |
GLDEF_C TInt E32Main() |
|
663 |
// |
|
664 |
// Test Server for file handle sharing |
|
665 |
// |
|
666 |
{ |
|
667 |
test.Title(); |
|
668 |
test.Start(_L("Starting FHServer...")); |
|
669 |
||
670 |
// Remember the number of open handles. Just for a sanity check .... |
|
671 |
TInt start_thc, start_phc; |
|
672 |
RThread().HandleCount(start_phc, start_thc); |
|
673 |
||
674 |
CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
675 |
||
676 |
FHS_ASSERT(cleanup); |
|
677 |
CActiveScheduler* sched=new CActiveScheduler; |
|
678 |
FHS_ASSERT(sched); |
|
679 |
CActiveScheduler::Install(sched); |
|
680 |
||
681 |
// start server1 |
|
682 |
CFHServer* svr = NULL; |
|
683 |
TRAP_IGNORE(svr = CFHServer::NewL()); |
|
684 |
FHS_ASSERT(svr); |
|
685 |
FHS_ASSERT(svr->Start(_L("FHServer"))==KErrNone); |
|
686 |
||
687 |
test.Title(); |
|
688 |
test.Start(_L("Starting tests...")); |
|
689 |
||
690 |
// start server2 in a seperate thread |
|
691 |
RThread server2Thread; |
|
692 |
TInt r = server2Thread.Create(_L("FHServer2"), FHServer2, KDefaultStackSize, KHeapSize, KHeapSize, NULL); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
693 |
test_KErrNone(r); |
0 | 694 |
TRequestStatus statq; |
695 |
server2Thread.Logon(statq); |
|
696 |
server2Thread.Resume(); |
|
697 |
||
698 |
CActiveScheduler::Start(); |
|
699 |
||
700 |
||
701 |
// wait for server2's thread to end gracefully |
|
702 |
User::WaitForRequest(statq); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
703 |
test_KErrNone(statq.Int()); |
0 | 704 |
|
705 |
server2Thread.Close(); |
|
706 |
||
707 |
RFs cleanupfs; |
|
708 |
r = cleanupfs.Connect(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
709 |
test_KErrNone(r); |
0 | 710 |
r=cleanupfs.SetSessionToPrivate(gTestDrive); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
711 |
test_KErrNone(r); |
0 | 712 |
r=cleanupfs.Delete(KSvrFileName); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
713 |
test_Value(r, r ==KErrNone || r==KErrNotFound); |
0 | 714 |
cleanupfs.Close(); |
715 |
||
716 |
||
717 |
test.End(); |
|
718 |
||
719 |
delete svr; |
|
720 |
delete sched; |
|
721 |
delete cleanup; |
|
722 |
||
723 |
// Sanity check for open handles and pending requests |
|
724 |
TInt end_thc, end_phc; |
|
725 |
RThread().HandleCount(end_phc, end_thc); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
726 |
test_Value(start_thc, start_thc == end_thc); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
727 |
test_Value(start_phc, start_phc == end_phc); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
728 |
test_Value(RThread().RequestCount(), RThread().RequestCount() == 0); |
0 | 729 |
|
730 |
return 0; |
|
731 |
} |