author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:50:07 +0300 | |
changeset 201 | 43365a9b78a3 |
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 |
// File Name: f32test/fileshare/t_handshare64bit.cpp |
|
15 |
// 64 bit FileHandle Server. Used by t_file64bit for testing |
|
16 |
// RFile64::AdoptFromServer() and RFile64::TransferToServer() |
|
17 |
// functionality. |
|
18 |
// |
|
19 |
// |
|
20 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
21 |
#define __E32TEST_EXTENSION__ |
0 | 22 |
#include <e32svr.h> |
23 |
#include <e32test.h> |
|
24 |
#include "handshare64bit.h" |
|
25 |
||
26 |
#ifdef __VC32__ |
|
27 |
#pragma warning(disable:4706) |
|
28 |
#endif |
|
29 |
||
30 |
||
31 |
||
32 |
GLDEF_D RTest test(_L("HANDSHARE_SVR")); |
|
33 |
const TInt64 KGB = 1<<30; |
|
34 |
const TInt64 K4GB = 4 * KGB; |
|
35 |
||
36 |
||
37 |
#define PANIC() FHSvrPanic(__LINE__) |
|
38 |
#define FHS_ASSERT(c) ((void)((c)||(PANIC(),0))) |
|
39 |
||
40 |
const TTimeIntervalMicroSeconds32 KHalfSecond(500000); |
|
41 |
||
42 |
||
43 |
void FHSvrPanic(TInt aLine) |
|
44 |
{ |
|
45 |
User::Panic(_L("FHServer"),aLine); |
|
46 |
} |
|
47 |
||
48 |
LOCAL_D TInt gTestDrive; |
|
49 |
||
50 |
/****************************************************************************** |
|
51 |
* Class Definitions |
|
52 |
******************************************************************************/ |
|
53 |
||
54 |
||
55 |
class CFHServer64Bit : public CServer2 |
|
56 |
{ |
|
57 |
public: |
|
58 |
static CFHServer64Bit* NewL(); |
|
59 |
void ConstructL(); |
|
60 |
virtual ~CFHServer64Bit(); |
|
61 |
virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const; |
|
62 |
virtual TInt RunError(TInt aError); |
|
63 |
private: |
|
64 |
CFHServer64Bit(); |
|
65 |
}; |
|
66 |
||
67 |
class CFHSession64Bit : public CSession2 |
|
68 |
{ |
|
69 |
public: |
|
70 |
virtual ~CFHSession64Bit(); |
|
71 |
virtual void CreateL(); |
|
72 |
virtual void ServiceL(const RMessage2& aMessage); |
|
73 |
public: |
|
74 |
||
75 |
void GetFileHandleLargeFile2(const RMessage2& aMsg); |
|
76 |
void PassFileHandleLargeFile(const RMessage2& aMsg); |
|
77 |
void PassFileHandleProcessLargeFile(const RMessage2& aMsg); |
|
78 |
}; |
|
79 |
||
80 |
/****************************************************************************** |
|
81 |
* Class CFHSession/CFHServer |
|
82 |
******************************************************************************/ |
|
83 |
void ExceptionHandler(TExcType) |
|
84 |
{ |
|
85 |
User::Leave(KErrGeneral); |
|
86 |
} |
|
87 |
||
88 |
||
89 |
||
90 |
CFHSession64Bit::~CFHSession64Bit() |
|
91 |
{ |
|
92 |
} |
|
93 |
||
94 |
void CFHSession64Bit::CreateL() |
|
95 |
{ |
|
96 |
||
97 |
} |
|
98 |
||
99 |
void CFHSession64Bit::ServiceL(const RMessage2& aMessage) |
|
100 |
{ |
|
101 |
__UHEAP_MARK; |
|
102 |
TInt mid=aMessage.Function(); |
|
103 |
switch(mid) |
|
104 |
{ |
|
105 |
case RFileHandleSharer64Bit::EMsgGetFileHandleLargeFile: |
|
106 |
GetFileHandleLargeFile2(aMessage); |
|
107 |
break; |
|
108 |
||
109 |
case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileClient: |
|
110 |
PassFileHandleLargeFile(aMessage); |
|
111 |
break; |
|
112 |
||
113 |
case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileCreator: |
|
114 |
PassFileHandleProcessLargeFile(aMessage); |
|
115 |
break; |
|
116 |
||
117 |
case RFileHandleSharer64Bit::EMsgExit: |
|
118 |
{ |
|
119 |
aMessage.Complete(KErrNone); |
|
120 |
||
121 |
CActiveScheduler::Stop(); |
|
122 |
} |
|
123 |
break; |
|
124 |
||
125 |
case RFileHandleSharer64Bit::EMsgSync: |
|
126 |
aMessage.Complete(KErrNone); |
|
127 |
break; |
|
128 |
||
129 |
case RFileHandleSharer64Bit::EMsgDrive: |
|
130 |
gTestDrive=aMessage.Int0(); |
|
131 |
aMessage.Complete(KErrNone); |
|
132 |
break; |
|
133 |
default: |
|
134 |
break; |
|
135 |
} |
|
136 |
__UHEAP_MARKEND; |
|
137 |
} |
|
138 |
||
139 |
// |
|
140 |
// Returns a file handle from server |
|
141 |
// |
|
142 |
void CFHSession64Bit::GetFileHandleLargeFile2(const RMessage2& aMsg) |
|
143 |
{ |
|
144 |
test.Next(_L("RFile64::AdoptFromServer()")); |
|
145 |
// get the requested file mode |
|
146 |
TFileMode fileMode = TFileMode(aMsg.Int1()); |
|
147 |
||
148 |
RFs fs; |
|
149 |
TInt r = fs.Connect(); |
|
150 |
||
151 |
if (r == KErrNone) |
|
152 |
r = fs.CreatePrivatePath(gTestDrive); |
|
153 |
||
154 |
if (r == KErrNone) |
|
155 |
r = fs.SetSessionToPrivate(gTestDrive); |
|
156 |
||
157 |
if (r == KErrNone) |
|
158 |
r = fs.ShareProtected(); |
|
159 |
||
160 |
// make sure file exists & has valid data in it |
|
161 |
RFile64 file1; |
|
162 |
if (r == KErrNone) |
|
163 |
r = file1.Replace(fs,KServerFileName,EFileWrite); |
|
164 |
r=file1.SetSize(K4GB-1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
test_KErrNone(r); |
0 | 166 |
r = file1.Write(K4GB-10,KTestData4()); |
167 |
||
168 |
file1.Close(); |
|
169 |
||
170 |
||
171 |
// re-open the file with the mode the client has requested & pass it to the client |
|
172 |
||
173 |
if (r == KErrNone) |
|
174 |
r = file1.Open(fs,KServerFileName, fileMode); |
|
175 |
if (r == KErrNone) |
|
176 |
||
177 |
test.Next(_L("RFile::TransferToClient()")); |
|
178 |
||
179 |
// transfer the file to the client |
|
180 |
r = file1.TransferToClient(aMsg, 0); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
test_KErrNone(r); |
0 | 182 |
|
183 |
// test we can still use the file |
|
184 |
TInt64 pos = 0; |
|
185 |
r = file1.Seek(ESeekStart, pos); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
test_KErrNone(r); |
0 | 187 |
TBuf8<9> rbuf; |
188 |
r=file1.Read(K4GB-10,rbuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
test_KErrNone(r); |
0 | 190 |
r=rbuf.CompareF(KTestData4()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
test_KErrNone(r); |
0 | 192 |
|
193 |
file1.Close(); |
|
194 |
fs.Close(); |
|
195 |
RDebug::Print(_L("completed")); |
|
196 |
} |
|
197 |
||
198 |
||
199 |
void CFHSession64Bit::PassFileHandleLargeFile(const RMessage2& aMsg) |
|
200 |
// |
|
201 |
// Adopts file from test program and tests what it can and can't do |
|
202 |
// Uses RFile64::AdoptFromClient() API |
|
203 |
// |
|
204 |
{ |
|
205 |
test.Next(_L("RFile64::AdoptFromClient()")); |
|
206 |
||
207 |
RFile64 file; |
|
208 |
||
209 |
// Message slot 0 is a RFs handle |
|
210 |
// Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
|
211 |
TInt r = file.AdoptFromClient(aMsg, 0, 1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
test_KErrNone(r); |
0 | 213 |
|
214 |
TBuf8<9> rbuf; |
|
215 |
r=file.Read(K4GB-10,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(KTestData3()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
test_KErrNone(r); |
0 | 219 |
r=file.Write(KTestData1()); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
test_Value(r, r==KErrAccessDenied); |
0 | 221 |
r=file.ChangeMode(EFileWrite); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
test_Value(r, r==KErrArgument); |
0 | 223 |
r=file.Rename(_L("\\newname.txt")); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied); |
0 | 225 |
file.Close(); |
226 |
||
227 |
aMsg.Complete(KErrNone); |
|
228 |
} |
|
229 |
||
230 |
// |
|
231 |
// Adopts file from test program and tests what it can and can't do |
|
232 |
// Uses RFile64::AdoptFromCreator() API |
|
233 |
// |
|
234 |
void CFHSession64Bit::PassFileHandleProcessLargeFile(const RMessage2& aMsg) |
|
235 |
{ |
|
236 |
test.Next(_L("RFile64::AdoptFromCreator()")); |
|
237 |
||
238 |
RFile64 file; |
|
239 |
TInt r = file.AdoptFromCreator(1, 2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
test_KErrNone(r); |
0 | 241 |
|
242 |
TBuf8<3> rbuf; |
|
243 |
r=file.Read(K4GB-10,rbuf,3); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
test_KErrNone(r); |
0 | 245 |
r=rbuf.CompareF(KTestData2()); |
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 |
test.Next(_L("RFile::Rename()")); |
|
249 |
||
250 |
// define a filename in our private path |
|
251 |
RFs fs; |
|
252 |
r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
test_KErrNone(r); |
0 | 254 |
|
255 |
TFileName sessionp; |
|
256 |
fs.SessionPath(sessionp); |
|
257 |
r = fs.MkDirAll(sessionp); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
0 | 259 |
|
260 |
r=fs.ShareProtected(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
test_KErrNone(r); |
0 | 262 |
|
263 |
r=fs.CreatePrivatePath(gTestDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
test_KErrNone(r); |
0 | 265 |
r=fs.SetSessionToPrivate(gTestDrive); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
test_KErrNone(r); |
0 | 267 |
|
268 |
TPath newPath; |
|
269 |
fs.PrivatePath(newPath); |
|
270 |
TFileName newFileName; |
|
271 |
newFileName = newPath; |
|
272 |
newFileName.Append(_L("newname.txt")); |
|
273 |
||
274 |
// delete the file before we try to rename anything to it |
|
275 |
r = fs.Delete(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 277 |
|
278 |
TFileName fileName; |
|
279 |
r = file.FullName(fileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
test_KErrNone(r); |
0 | 281 |
|
282 |
r=file.Rename(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
test_KErrNone(r); |
0 | 284 |
|
285 |
file.Close(); |
|
286 |
||
287 |
// Next verify that we can delete the file (which should now |
|
288 |
// have been moved to our private directory) |
|
289 |
test.Next(_L("RFs::Delete()")); |
|
290 |
r = fs.Delete(newFileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
test_KErrNone(r); |
0 | 292 |
|
293 |
fs.Close(); |
|
294 |
||
295 |
||
296 |
aMsg.Complete(KErrNone); |
|
297 |
} |
|
298 |
||
299 |
||
300 |
||
301 |
||
302 |
CFHServer64Bit* CFHServer64Bit::NewL() |
|
303 |
{ |
|
304 |
CFHServer64Bit* server = new (ELeave) CFHServer64Bit; |
|
305 |
CleanupStack::PushL(server); |
|
306 |
server->ConstructL(); |
|
307 |
CleanupStack::Pop(server); |
|
308 |
return server; |
|
309 |
} |
|
310 |
||
311 |
void CFHServer64Bit::ConstructL() |
|
312 |
{ |
|
313 |
} |
|
314 |
||
315 |
CFHServer64Bit::CFHServer64Bit() |
|
316 |
: CServer2(0,ESharableSessions) |
|
317 |
{ |
|
318 |
} |
|
319 |
||
320 |
CFHServer64Bit::~CFHServer64Bit() |
|
321 |
{ |
|
322 |
} |
|
323 |
||
324 |
CSession2* CFHServer64Bit::NewSessionL(const TVersion& aVersion, const RMessage2&) const |
|
325 |
// |
|
326 |
// Create New Session |
|
327 |
// |
|
328 |
{ |
|
329 |
(void)aVersion; |
|
330 |
CFHSession64Bit* s = new (ELeave) CFHSession64Bit; |
|
331 |
return s; |
|
332 |
} |
|
333 |
||
334 |
_LIT(KErr,"FHSERVER64BIT_ERR"); |
|
335 |
||
336 |
||
337 |
TInt CFHServer64Bit::RunError(TInt aError) |
|
338 |
{ |
|
339 |
User::Panic(KErr,aError); |
|
340 |
return 0; |
|
341 |
} |
|
342 |
||
343 |
||
344 |
||
345 |
||
346 |
TInt E32Main() |
|
347 |
// |
|
348 |
// Test Server for file handle sharing |
|
349 |
// |
|
350 |
{ |
|
351 |
test.Title(); |
|
352 |
test.Start(_L("Starting FHServer64bit...")); |
|
353 |
||
354 |
// Remember the number of open handles. Just for a sanity check .... |
|
355 |
TInt start_thc, start_phc; |
|
356 |
RThread().HandleCount(start_phc, start_thc); |
|
357 |
||
358 |
CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
359 |
||
360 |
FHS_ASSERT(cleanup); |
|
361 |
CActiveScheduler* sched=new CActiveScheduler; |
|
362 |
FHS_ASSERT(sched); |
|
363 |
CActiveScheduler::Install(sched); |
|
364 |
||
365 |
// start server1 |
|
366 |
CFHServer64Bit* svr = NULL; |
|
367 |
TRAP_IGNORE(svr = CFHServer64Bit::NewL()); |
|
368 |
FHS_ASSERT(svr); |
|
369 |
FHS_ASSERT(svr->Start(_L("FHServer64bit"))== KErrNone||KErrAlreadyExists); |
|
370 |
||
371 |
test.Title(); |
|
372 |
test.Start(_L("Starting tests...")); |
|
373 |
||
374 |
||
375 |
CActiveScheduler::Start(); |
|
376 |
||
377 |
RFs cleanupfs; |
|
378 |
TInt r = cleanupfs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
test_KErrNone(r); |
0 | 380 |
r=cleanupfs.SetSessionToPrivate(gTestDrive); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
test_KErrNone(r); |
0 | 382 |
r=cleanupfs.Delete(KSvrFileName); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
0 | 384 |
cleanupfs.Close(); |
385 |
||
386 |
||
387 |
test.End(); |
|
388 |
||
389 |
delete svr; |
|
390 |
delete sched; |
|
391 |
delete cleanup; |
|
392 |
||
393 |
// Sanity check for open handles and pending requests |
|
394 |
TInt end_thc, end_phc; |
|
395 |
RThread().HandleCount(end_phc, end_thc); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
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
|
397 |
test_Value(start_phc, start_phc == end_phc); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
test_Value(RThread().RequestCount(), RThread().RequestCount() == 0); |
0 | 399 |
|
400 |
return 0; |
|
401 |
} |