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_open.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
189
|
18 |
#define __E32TEST_EXTENSION__
|
0
|
19 |
#include <f32file.h>
|
|
20 |
#include <e32test.h>
|
|
21 |
#include "t_server.h"
|
|
22 |
|
|
23 |
GLDEF_D RTest test(_L("T_OPEN"));
|
|
24 |
|
|
25 |
LOCAL_D TFileName gBatchFile;
|
|
26 |
LOCAL_D TBool gRunByBatch=EFalse;
|
|
27 |
|
|
28 |
TFileName filename1=_L("Z:\\TEST\\T_FSRV.CPP");
|
|
29 |
TFileName filename2=_L("Z:\\TEST\\T_FILE.CPP");
|
|
30 |
TFileName dirname1=_L("Z:\\TEST\\*.XDE");
|
|
31 |
|
|
32 |
|
|
33 |
LOCAL_C void Test0()
|
|
34 |
//
|
|
35 |
// Scan for open files - no sessions
|
|
36 |
//
|
|
37 |
{
|
|
38 |
|
|
39 |
test.Next(_L("Scan for open files with no sessions open"));
|
|
40 |
CFileList* list;
|
|
41 |
TOpenFileScan fileScan(TheFs);
|
|
42 |
fileScan.NextL(list);
|
|
43 |
if (list==NULL)
|
|
44 |
return;
|
|
45 |
TInt count=list->Count();
|
|
46 |
if (count==1)
|
|
47 |
{
|
|
48 |
gRunByBatch=ETrue;
|
|
49 |
gBatchFile=(*list)[0].iName;
|
|
50 |
delete list;
|
|
51 |
fileScan.NextL(list);
|
|
52 |
if (list==NULL)
|
|
53 |
return;
|
|
54 |
count=list->Count();
|
|
55 |
}
|
|
56 |
while (count--)
|
|
57 |
{
|
|
58 |
TEntry entry=(*list)[count];
|
|
59 |
test.Printf(_L("%d) EntryName = %S\n"),count,&entry.iName);
|
|
60 |
}
|
|
61 |
test.Printf(_L("Test will fail unless files are closed.\n"));
|
|
62 |
test(0);
|
|
63 |
//test.Printf(_L("Press any key ...\n"));
|
|
64 |
//test.Getch();
|
|
65 |
}
|
|
66 |
|
|
67 |
LOCAL_C void Test1()
|
|
68 |
//
|
|
69 |
// Test OpenFileScan
|
|
70 |
//
|
|
71 |
{
|
|
72 |
|
|
73 |
test.Next(_L("Scan for open files - one session only"));
|
|
74 |
|
|
75 |
RFile file1,file2,file3;
|
|
76 |
|
|
77 |
TInt r=file1.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
78 |
test_KErrNone(r);
|
0
|
79 |
|
|
80 |
r=file2.Open(TheFs,filename2,EFileRead);
|
189
|
81 |
test_KErrNone(r);
|
0
|
82 |
|
|
83 |
r=file3.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
84 |
test_KErrNone(r);
|
0
|
85 |
|
|
86 |
CFileList* list=NULL;
|
|
87 |
TOpenFileScan fileScan(TheFs);
|
|
88 |
TRAP(r,fileScan.NextL(list));
|
189
|
89 |
test_KErrNone(r);
|
0
|
90 |
|
|
91 |
if (gRunByBatch)
|
|
92 |
{
|
|
93 |
test(list!=NULL);
|
|
94 |
test(list->Count()==1);
|
|
95 |
TEntry entry=(*list)[0];
|
|
96 |
test(entry.iName.FindF(_L(".BAT"))>=0);
|
|
97 |
delete list;
|
|
98 |
fileScan.NextL(list);
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
test(list!=NULL);
|
|
103 |
TInt count=list->Count();
|
|
104 |
test(count==3);
|
|
105 |
TEntry entry=(*list)[0];
|
|
106 |
|
|
107 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
108 |
entry=(*list)[1];
|
|
109 |
test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
|
|
110 |
entry=(*list)[2];
|
|
111 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
112 |
TThreadId threadId=fileScan.ThreadId();
|
|
113 |
RThread current;
|
|
114 |
TThreadId currentId=current.Id();
|
|
115 |
test(threadId==currentId);
|
|
116 |
delete list;
|
|
117 |
|
|
118 |
fileScan.NextL(list);
|
|
119 |
test(list==NULL);
|
|
120 |
|
|
121 |
file1.Close();
|
|
122 |
file2.Close();
|
|
123 |
file3.Close();
|
|
124 |
}
|
|
125 |
|
|
126 |
LOCAL_C void Test2()
|
|
127 |
//
|
|
128 |
// Test openfilescan - empty, full, empty.
|
|
129 |
//
|
|
130 |
{
|
|
131 |
|
|
132 |
|
|
133 |
test.Next(_L("Scan for open files - empty sessions"));
|
|
134 |
|
|
135 |
RFs fs1,fs2,fs3,fs4;
|
|
136 |
TInt r=fs1.Connect();
|
189
|
137 |
test_KErrNone(r);
|
0
|
138 |
r=fs2.Connect();
|
189
|
139 |
test_KErrNone(r);
|
0
|
140 |
r=fs3.Connect();
|
189
|
141 |
test_KErrNone(r);
|
0
|
142 |
r=fs4.Connect();
|
189
|
143 |
test_KErrNone(r);
|
0
|
144 |
|
|
145 |
RFile file1,file2,file3;
|
|
146 |
|
|
147 |
r=file1.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
148 |
test_KErrNone(r);
|
0
|
149 |
|
|
150 |
r=file2.Open(fs2,filename2,EFileRead);
|
189
|
151 |
test_KErrNone(r);
|
0
|
152 |
|
|
153 |
r=file3.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
154 |
test_KErrNone(r);
|
0
|
155 |
|
|
156 |
CFileList* list;
|
|
157 |
TOpenFileScan fileScan(TheFs);
|
|
158 |
fileScan.NextL(list);
|
|
159 |
|
|
160 |
if (gRunByBatch)
|
|
161 |
{
|
|
162 |
test(list!=NULL);
|
|
163 |
test(list->Count()==1);
|
|
164 |
TEntry entry=(*list)[0];
|
|
165 |
test(entry.iName.FindF(_L(".BAT"))>=0);
|
|
166 |
delete list;
|
|
167 |
fileScan.NextL(list);
|
|
168 |
}
|
|
169 |
|
|
170 |
test(list!=NULL);
|
|
171 |
TInt count=list->Count();
|
|
172 |
test(count==3);
|
|
173 |
TEntry entry=(*list)[0];
|
|
174 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
175 |
entry=(*list)[1];
|
|
176 |
test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
|
|
177 |
entry=(*list)[2];
|
|
178 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
179 |
TThreadId threadId=fileScan.ThreadId();
|
|
180 |
RThread current;
|
|
181 |
TThreadId currentId=current.Id();
|
|
182 |
test(threadId==currentId);
|
|
183 |
delete list;
|
|
184 |
|
|
185 |
fileScan.NextL(list);
|
|
186 |
test(list==NULL);
|
|
187 |
|
|
188 |
file1.Close();
|
|
189 |
file2.Close();
|
|
190 |
file3.Close();
|
|
191 |
fs1.Close();
|
|
192 |
fs2.Close();
|
|
193 |
fs3.Close();
|
|
194 |
fs4.Close();
|
|
195 |
}
|
|
196 |
|
|
197 |
LOCAL_C void Test3()
|
|
198 |
//
|
|
199 |
// Test openfilescan - empty, full, empty full
|
|
200 |
//
|
|
201 |
{
|
|
202 |
|
|
203 |
test.Next(_L("Scan for open files - multiple sessions"));
|
|
204 |
|
|
205 |
RFs fs1,fs2,fs3,fs4;
|
|
206 |
TInt r=fs1.Connect();
|
189
|
207 |
test_KErrNone(r);
|
0
|
208 |
r=fs2.Connect();
|
189
|
209 |
test_KErrNone(r);
|
0
|
210 |
r=fs3.Connect();
|
189
|
211 |
test_KErrNone(r);
|
0
|
212 |
r=fs4.Connect();
|
189
|
213 |
test_KErrNone(r);
|
0
|
214 |
|
|
215 |
RFile file1,file2,file3;
|
|
216 |
|
|
217 |
r=file1.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
218 |
test_KErrNone(r);
|
0
|
219 |
|
|
220 |
r=file2.Open(fs2,filename2,EFileRead|EFileShareReadersOnly);
|
189
|
221 |
test_KErrNone(r);
|
0
|
222 |
|
|
223 |
r=file3.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
224 |
test_KErrNone(r);
|
0
|
225 |
|
|
226 |
r=file1.Open(fs4,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
227 |
test_KErrNone(r);
|
0
|
228 |
|
|
229 |
r=file2.Open(fs4,filename2,EFileRead|EFileShareReadersOnly);
|
189
|
230 |
test_KErrNone(r);
|
0
|
231 |
|
|
232 |
r=file3.Open(fs4,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
233 |
test_KErrNone(r);
|
0
|
234 |
|
|
235 |
CFileList* list;
|
|
236 |
TOpenFileScan fileScan(TheFs);
|
|
237 |
fileScan.NextL(list);
|
|
238 |
|
|
239 |
if (gRunByBatch)
|
|
240 |
{
|
|
241 |
test(list!=NULL);
|
|
242 |
test(list->Count()==1);
|
|
243 |
TEntry entry=(*list)[0];
|
|
244 |
test(entry.iName.FindF(_L(".BAT"))>=0);
|
|
245 |
delete list;
|
|
246 |
fileScan.NextL(list);
|
|
247 |
}
|
|
248 |
|
|
249 |
test(list!=NULL);
|
|
250 |
TInt count=list->Count();
|
|
251 |
test(count==3);
|
|
252 |
TEntry entry=(*list)[0];
|
|
253 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
254 |
entry=(*list)[1];
|
|
255 |
test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
|
|
256 |
entry=(*list)[2];
|
|
257 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
258 |
TThreadId threadId=fileScan.ThreadId();
|
|
259 |
RThread current;
|
|
260 |
TThreadId currentId=current.Id();
|
|
261 |
test(threadId==currentId);
|
|
262 |
delete list;
|
|
263 |
|
|
264 |
fileScan.NextL(list);
|
|
265 |
test(list!=NULL);
|
|
266 |
count=list->Count();
|
|
267 |
test(count==3);
|
|
268 |
entry=(*list)[0];
|
|
269 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
270 |
entry=(*list)[1];
|
|
271 |
test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
|
|
272 |
entry=(*list)[2];
|
|
273 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
274 |
threadId=fileScan.ThreadId();
|
|
275 |
currentId=current.Id();
|
|
276 |
test(threadId==currentId);
|
|
277 |
delete list;
|
|
278 |
|
|
279 |
fileScan.NextL(list);
|
|
280 |
test(list==NULL);
|
|
281 |
|
|
282 |
file1.Close();
|
|
283 |
file2.Close();
|
|
284 |
file3.Close();
|
|
285 |
fs1.Close();
|
|
286 |
fs2.Close();
|
|
287 |
fs3.Close();
|
|
288 |
fs4.Close();
|
|
289 |
}
|
|
290 |
|
|
291 |
LOCAL_C void Test4()
|
|
292 |
//
|
|
293 |
// Test openfilescan - rdirs, empty, full, empty rdirs.
|
|
294 |
//
|
|
295 |
{
|
|
296 |
test.Next(_L("Scan for open files - check RDir sessions are ignored"));
|
|
297 |
|
|
298 |
RFs fs1,fs2,fs3,fs4;
|
|
299 |
TInt r=fs1.Connect();
|
189
|
300 |
test_KErrNone(r);
|
0
|
301 |
r=fs2.Connect();
|
189
|
302 |
test_KErrNone(r);
|
0
|
303 |
r=fs3.Connect();
|
189
|
304 |
test_KErrNone(r);
|
0
|
305 |
r=fs4.Connect();
|
189
|
306 |
test_KErrNone(r);
|
0
|
307 |
|
|
308 |
RDir dir1,dir2,dir3,dir4;
|
|
309 |
r=dir1.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
310 |
test_KErrNone(r);
|
0
|
311 |
r=dir2.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
312 |
test_KErrNone(r);
|
0
|
313 |
r=dir3.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
314 |
test_KErrNone(r);
|
0
|
315 |
r=dir4.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
316 |
test_KErrNone(r);
|
0
|
317 |
|
|
318 |
RFile file1,file2,file3;
|
|
319 |
r=file1.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
320 |
test_KErrNone(r);
|
0
|
321 |
r=file2.Open(fs2,filename2,EFileRead);
|
189
|
322 |
test_KErrNone(r);
|
0
|
323 |
r=file3.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
324 |
test_KErrNone(r);
|
0
|
325 |
|
|
326 |
RDir dir5,dir6,dir7,dir8;
|
|
327 |
r=dir5.Open(fs4,dirname1,KEntryAttMaskSupported);
|
189
|
328 |
test_KErrNone(r);
|
0
|
329 |
r=dir6.Open(fs4,dirname1,KEntryAttMaskSupported);
|
189
|
330 |
test_KErrNone(r);
|
0
|
331 |
r=dir7.Open(fs4,dirname1,KEntryAttMaskSupported);
|
189
|
332 |
test_KErrNone(r);
|
0
|
333 |
r=dir8.Open(fs4,dirname1,KEntryAttMaskSupported);
|
189
|
334 |
test_KErrNone(r);
|
0
|
335 |
|
|
336 |
CFileList* list;
|
|
337 |
TOpenFileScan fileScan(TheFs);
|
|
338 |
fileScan.NextL(list);
|
|
339 |
|
|
340 |
if (gRunByBatch)
|
|
341 |
{
|
|
342 |
test(list!=NULL);
|
|
343 |
test(list->Count()==1);
|
|
344 |
TEntry entry=(*list)[0];
|
|
345 |
test(entry.iName.FindF(_L(".BAT"))>=0);
|
|
346 |
delete list;
|
|
347 |
fileScan.NextL(list);
|
|
348 |
}
|
|
349 |
|
|
350 |
test(list!=NULL);
|
|
351 |
TInt count=list->Count();
|
|
352 |
test(count==3);
|
|
353 |
TEntry entry=(*list)[0];
|
|
354 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
355 |
entry=(*list)[1];
|
|
356 |
test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
|
|
357 |
entry=(*list)[2];
|
|
358 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
359 |
TThreadId threadId=fileScan.ThreadId();
|
|
360 |
RThread current;
|
|
361 |
TThreadId currentId=current.Id();
|
|
362 |
test(threadId==currentId);
|
|
363 |
delete list;
|
|
364 |
|
|
365 |
fileScan.NextL(list);
|
|
366 |
test(list==NULL);
|
|
367 |
|
|
368 |
file1.Close();
|
|
369 |
file2.Close();
|
|
370 |
file3.Close();
|
|
371 |
dir1.Close(); dir2.Close();
|
|
372 |
dir3.Close(); dir4.Close();
|
|
373 |
dir5.Close(); dir6.Close();
|
|
374 |
dir7.Close(); dir8.Close();
|
|
375 |
fs1.Close(); fs2.Close();
|
|
376 |
fs3.Close(); fs4.Close();
|
|
377 |
}
|
|
378 |
|
|
379 |
LOCAL_C void Test5()
|
|
380 |
//
|
|
381 |
// Test OpenFileScan
|
|
382 |
//
|
|
383 |
{
|
|
384 |
|
|
385 |
test.Next(_L("Scan for open files - mixed RDirs and RFiles"));
|
|
386 |
|
|
387 |
RFile file1,file2,file3;
|
|
388 |
TInt r=file1.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
389 |
test_KErrNone(r);
|
0
|
390 |
r=file2.Open(TheFs,filename2,EFileRead);
|
189
|
391 |
test_KErrNone(r);
|
0
|
392 |
r=file3.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
|
189
|
393 |
test_KErrNone(r);
|
0
|
394 |
|
|
395 |
RDir dir1,dir2,dir3,dir4;
|
|
396 |
r=dir1.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
397 |
test_KErrNone(r);
|
0
|
398 |
r=dir2.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
399 |
test_KErrNone(r);
|
0
|
400 |
r=dir3.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
401 |
test_KErrNone(r);
|
0
|
402 |
r=dir4.Open(TheFs,dirname1,KEntryAttMaskSupported);
|
189
|
403 |
test_KErrNone(r);
|
0
|
404 |
|
|
405 |
CFileList* list;
|
|
406 |
TOpenFileScan fileScan(TheFs);
|
|
407 |
fileScan.NextL(list);
|
|
408 |
|
|
409 |
if (gRunByBatch)
|
|
410 |
{
|
|
411 |
test(list!=NULL);
|
|
412 |
test(list->Count()==1);
|
|
413 |
TEntry entry=(*list)[0];
|
|
414 |
test(entry.iName.FindF(_L(".BAT"))>=0);
|
|
415 |
delete list;
|
|
416 |
fileScan.NextL(list);
|
|
417 |
}
|
|
418 |
|
|
419 |
test(list!=NULL);
|
|
420 |
TInt count=list->Count();
|
|
421 |
test(count==3);
|
|
422 |
TEntry entry=(*list)[0];
|
|
423 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
424 |
entry=(*list)[1];
|
|
425 |
test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
|
|
426 |
entry=(*list)[2];
|
|
427 |
test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
|
|
428 |
TThreadId threadId=fileScan.ThreadId();
|
|
429 |
RThread current;
|
|
430 |
TThreadId currentId=current.Id();
|
|
431 |
test(threadId==currentId);
|
|
432 |
delete list;
|
|
433 |
|
|
434 |
fileScan.NextL(list);
|
|
435 |
test(list==NULL);
|
|
436 |
|
|
437 |
file1.Close();
|
|
438 |
file2.Close();
|
|
439 |
file3.Close();
|
|
440 |
dir1.Close();
|
|
441 |
dir2.Close();
|
|
442 |
dir3.Close();
|
|
443 |
dir4.Close();
|
|
444 |
}
|
|
445 |
|
|
446 |
|
|
447 |
NONSHARABLE_STRUCT(TThreadData)
|
|
448 |
//
|
|
449 |
// Encapsulates the data required by the worker thread.
|
|
450 |
//
|
|
451 |
{
|
|
452 |
// Thread identifier for debug output
|
|
453 |
TInt iNumber;
|
|
454 |
|
|
455 |
// ID of the thread that started the worker thread, and the
|
|
456 |
// worker thread itself
|
|
457 |
TThreadId iMain;
|
|
458 |
TThreadId iWorker;
|
|
459 |
|
|
460 |
// Request status object of the parent thread, used for signalling
|
|
461 |
TRequestStatus* iStatus;
|
|
462 |
|
|
463 |
// Name of the file the parent thread requires this thread to open
|
|
464 |
TFileName iFilename;
|
|
465 |
|
|
466 |
// Number of files opened by the thread;
|
|
467 |
TInt iNumFiles;
|
|
468 |
};
|
|
469 |
|
|
470 |
|
|
471 |
LOCAL_C TInt WorkerThread(TAny* aParameter)
|
|
472 |
//
|
|
473 |
// This function is designed to run as a separate thread in order to verify the
|
|
474 |
// fix for DEF062875.
|
|
475 |
//
|
|
476 |
// When the thread is started it opens the file specified in the startup
|
|
477 |
// parameter, signals the main thread and then suspends. Once the main thread
|
|
478 |
// has completed its checking the worker thread is resumed and allowed to run
|
|
479 |
// to completion.
|
|
480 |
//
|
|
481 |
// @param aParameter Thread specific data supplied by the main thread when the
|
|
482 |
// worker thread is started. The data may be accessed by
|
|
483 |
// casting this pointer to a TThreadData*
|
|
484 |
//
|
|
485 |
{
|
|
486 |
// Can't use our global "test" object here
|
|
487 |
RTest myTest(_L("Worker thread"));
|
|
488 |
|
|
489 |
|
|
490 |
// Extract the parameters that this thread will need to use
|
|
491 |
TThreadData* threadData = (TThreadData*)aParameter;
|
|
492 |
|
|
493 |
|
|
494 |
RThread current;
|
|
495 |
TThreadId currentId = current.Id();
|
|
496 |
|
|
497 |
|
|
498 |
myTest.Printf(_L("WORK%d: Worker thread %d started\n"), threadData->iNumber, threadData->iNumber);
|
|
499 |
myTest.Printf(_L("WORK%d: File: %S\n"), threadData->iNumber, &threadData->iFilename);
|
|
500 |
myTest.Printf(_L("WORK%d: Thread: %d\n"), threadData->iNumber, (TUint)currentId);
|
|
501 |
myTest.Printf(_L("WORK%d: Parent: %d\n"), threadData->iNumber, (TUint)threadData->iMain);
|
|
502 |
|
|
503 |
|
|
504 |
// Open the file specified by the parameter passed to us from the main
|
|
505 |
// thread
|
|
506 |
RFs myFs;
|
|
507 |
myFs.Connect();
|
|
508 |
RFile file;
|
|
509 |
User::LeaveIfError(file.Open(myFs, threadData->iFilename, EFileRead | EFileShareReadersOnly));
|
|
510 |
|
|
511 |
// Signal the parent thread to continue then wait
|
|
512 |
myTest.Printf(_L("WORK%d: Signalling parent thread\n"), threadData->iNumber);
|
|
513 |
RThread parent;
|
|
514 |
User::LeaveIfError(parent.Open(threadData->iMain));
|
|
515 |
parent.RequestComplete(threadData->iStatus, KErrNone);
|
|
516 |
|
|
517 |
|
|
518 |
myTest.Printf(_L("WORK%d: Waiting for parent thread to restart us\n"), threadData->iNumber);
|
|
519 |
current.Suspend();
|
|
520 |
|
|
521 |
|
|
522 |
// Tidy up
|
|
523 |
myTest.Printf(_L("WORK%d: Closing file\n"), threadData->iNumber);
|
|
524 |
file.Close();
|
|
525 |
|
|
526 |
|
|
527 |
return KErrNone;
|
|
528 |
}
|
|
529 |
|
|
530 |
|
|
531 |
LOCAL_C void TestDEF062875()
|
|
532 |
//
|
|
533 |
// Verify that TOpenFileScan::ThreadId() returns the ID of the thread that
|
|
534 |
// opened the file.
|
|
535 |
//
|
|
536 |
// The object of the exercise here is to create several worker threads, each
|
|
537 |
// one will open a file, signal the main thread and then suspend. Once all
|
|
538 |
// the worker threads have suspended the main thread then uses
|
|
539 |
// TOpenFileScan::NextL() to verify that the thread IDs correspond to the
|
|
540 |
// worker threads that opened each file and not that of the main thread.
|
|
541 |
//
|
|
542 |
// The worker threads are then restarted and allowed to terminate naturally by
|
|
543 |
// running to completion
|
|
544 |
//
|
|
545 |
{
|
|
546 |
test.Start(_L("Test TOpenFileScan::ThreadId()"));
|
|
547 |
|
|
548 |
const TInt KHeapSize = 32768;
|
|
549 |
|
|
550 |
RThread thread1;
|
|
551 |
RThread thread2;
|
|
552 |
|
|
553 |
TRequestStatus status1;
|
|
554 |
TRequestStatus status2;
|
|
555 |
|
|
556 |
TThreadId id = RThread().Id();
|
|
557 |
|
|
558 |
TThreadData threadData[3];
|
|
559 |
|
|
560 |
threadData[0].iNumber = 0;
|
|
561 |
threadData[0].iMain = id;
|
|
562 |
threadData[0].iWorker = id;
|
|
563 |
threadData[0].iStatus = 0;
|
|
564 |
threadData[0].iFilename = filename1;
|
|
565 |
threadData[0].iNumFiles = 2;
|
|
566 |
|
|
567 |
threadData[1].iNumber = 1;
|
|
568 |
threadData[1].iMain = id;
|
|
569 |
threadData[1].iStatus = &status1;
|
|
570 |
threadData[1].iFilename = filename1;
|
|
571 |
threadData[1].iNumFiles = 1;
|
|
572 |
|
|
573 |
threadData[2].iNumber = 2;
|
|
574 |
threadData[2].iMain = id;
|
|
575 |
threadData[2].iStatus = &status2;
|
|
576 |
threadData[2].iFilename = filename2;
|
|
577 |
threadData[2].iNumFiles = 1;
|
|
578 |
|
|
579 |
TInt numThreads = sizeof(threadData)/sizeof(threadData[0]);
|
|
580 |
|
|
581 |
|
|
582 |
// Open the files in the MAIN thread.
|
|
583 |
RFile file1;
|
|
584 |
User::LeaveIfError(file1.Open(TheFs, filename1, EFileRead | EFileShareReadersOnly));
|
|
585 |
|
|
586 |
RFile file2;
|
|
587 |
User::LeaveIfError(file2.Open(TheFs, filename2, EFileRead | EFileShareReadersOnly));
|
|
588 |
|
|
589 |
|
|
590 |
// Create the first worker thread
|
|
591 |
test.Printf(_L("MAIN: Creating worker threads\n"));
|
|
592 |
thread1.Create(_L("WorkerThread1"), WorkerThread, KDefaultStackSize, KHeapSize, KHeapSize, &threadData[1]);
|
|
593 |
threadData[1].iWorker = thread1.Id();
|
|
594 |
|
|
595 |
// Start it and wait for it to suspend
|
|
596 |
thread1.Logon(status1);
|
|
597 |
thread1.Resume();
|
|
598 |
test.Printf(_L("MAIN: Waiting for worker thread 1\n"));
|
|
599 |
User::WaitForRequest(status1);
|
|
600 |
|
|
601 |
|
|
602 |
// Create the second worker thread
|
|
603 |
thread2.Create(_L("WorkerThread2"), WorkerThread, KDefaultStackSize, KHeapSize, KHeapSize, &threadData[2]);
|
|
604 |
threadData[2].iWorker = thread2.Id();
|
|
605 |
|
|
606 |
|
|
607 |
// Start it and wait for it to suspend
|
|
608 |
thread2.Logon(status2);
|
|
609 |
thread2.Resume();
|
|
610 |
test.Printf(_L("MAIN: Waiting for worker thread 2\n"));
|
|
611 |
User::WaitForRequest(status2);
|
|
612 |
|
|
613 |
|
|
614 |
// Obtain a list of open files. At this point we should have a single open
|
|
615 |
// file, as opened by our worker thread. The thread ID reported by
|
|
616 |
// TOpenFileScan should be that of our worker thread rather than the main
|
|
617 |
// thread.
|
|
618 |
test.Printf(_L("MAIN: Verifying thread ID of open file(s)\n"));
|
|
619 |
CFileList* list;
|
|
620 |
TOpenFileScan fileScan(TheFs);
|
|
621 |
|
|
622 |
|
|
623 |
TInt count = 0;
|
|
624 |
FOREVER
|
|
625 |
{
|
|
626 |
fileScan.NextL(list);
|
|
627 |
|
|
628 |
|
|
629 |
// The NULL list indicates we've run out of sessions.
|
|
630 |
if(!list)
|
|
631 |
{
|
|
632 |
break;
|
|
633 |
}
|
|
634 |
|
|
635 |
|
|
636 |
TThreadId threadId=fileScan.ThreadId();
|
|
637 |
TThreadData* data = 0;
|
|
638 |
for (count = 0; count < numThreads; count++)
|
|
639 |
{
|
|
640 |
if (threadId == threadData[count].iWorker)
|
|
641 |
{
|
|
642 |
data = &threadData[count];
|
|
643 |
break;
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
|
|
648 |
if (data)
|
|
649 |
{
|
|
650 |
test.Next(_L("Check number of open files..."));
|
|
651 |
test.Printf(_L("MAIN: Number of open files: %d (expecting %d)\n"), list->Count(), data->iNumFiles);
|
|
652 |
test(list->Count() == threadData[count].iNumFiles);
|
|
653 |
|
|
654 |
|
|
655 |
test.Next(_L("Check TThreadIds..."));
|
|
656 |
test.Printf(_L("MAIN: Main thread ID : %d\n"), (TUint)data->iMain);
|
|
657 |
test.Printf(_L("MAIN: Worker thread ID: %d\n"), (TUint)data->iWorker);
|
|
658 |
test.Printf(_L("MAIN: File thread ID : %d\n"), (TUint)threadId);
|
|
659 |
|
|
660 |
|
|
661 |
TInt loop = 0;
|
|
662 |
for (loop = 0; loop < list->Count(); loop++)
|
|
663 |
{
|
|
664 |
const TEntry& theEntry = (*list)[loop];
|
|
665 |
test.Printf(_L(" "));
|
|
666 |
test.Printf(theEntry.iName);
|
|
667 |
test.Printf(_L("\n"));
|
|
668 |
}
|
|
669 |
}
|
|
670 |
else
|
|
671 |
{
|
|
672 |
test.Printf(_L("Ignored thread %d\n"), (TUint)threadId);
|
|
673 |
}
|
|
674 |
|
|
675 |
|
|
676 |
delete list;
|
|
677 |
list = 0;
|
|
678 |
|
|
679 |
|
|
680 |
test.Printf(_L("\n"));
|
|
681 |
}
|
|
682 |
|
|
683 |
|
|
684 |
// Signal the two worker threads to tidy up and run to normal termination
|
|
685 |
test.Printf(_L("MAIN: Signalling worker thread 1\n"));
|
|
686 |
thread1.Logon(status1);
|
|
687 |
thread1.Resume();
|
|
688 |
User::WaitForRequest(status1);
|
|
689 |
|
|
690 |
test.Printf(_L("MAIN: Signalling worker thread 2\n"));
|
|
691 |
thread2.Logon(status2);
|
|
692 |
thread2.Resume();
|
|
693 |
User::WaitForRequest(status2);
|
|
694 |
|
|
695 |
|
|
696 |
// Tidy up and finish
|
|
697 |
test.Printf(_L("MAIN: Closing worker thread 1\n"));
|
|
698 |
thread1.Close();
|
|
699 |
|
|
700 |
test.Printf(_L("MAIN: Closing worker thread 2\n"));
|
|
701 |
thread2.Close();
|
|
702 |
|
|
703 |
file1.Close();
|
|
704 |
file2.Close();
|
|
705 |
|
|
706 |
test.End();
|
|
707 |
}
|
|
708 |
|
|
709 |
|
|
710 |
GLDEF_C void CallTestsL()
|
|
711 |
//
|
|
712 |
// Call tests that may leave
|
|
713 |
//
|
|
714 |
{
|
|
715 |
filename1[0] = gExeFileName[0];
|
|
716 |
filename2[0] = gExeFileName[0];
|
|
717 |
dirname1[0] = gExeFileName[0];
|
|
718 |
Test0();
|
|
719 |
Test1();
|
|
720 |
Test2();
|
|
721 |
Test3();
|
|
722 |
Test4();
|
|
723 |
Test5();
|
|
724 |
|
|
725 |
TestDEF062875();
|
|
726 |
}
|