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