Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

679 lines
20 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tfile.c
  5. Abstract:
  6. Test program for Win32 Base File API calls
  7. Author:
  8. Mark Lucovsky (markl) 26-Sep-1990
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <assert.h>
  15. #include <stdio.h>
  16. #include <windows.h>
  17. #include <string.h>
  18. #include <memory.h>
  19. #define xassert ASSERT
  20. DWORD
  21. main(
  22. int argc,
  23. char *argv[],
  24. char *envp[]
  25. )
  26. {
  27. HANDLE iFile,oFile,fFile,mFile,n1,o1;
  28. DWORD n,n2;
  29. LONG Size;
  30. BYTE buff[512],cbuff[512];
  31. DWORD attr;
  32. FILETIME Mtime, Mtime0, Mtime1;
  33. PWIN32_FIND_DATA FindFileData;
  34. BOOL b;
  35. WORD w1,w2;
  36. DWORD dw,spc,bps,fc,tc;
  37. LPSTR base;
  38. LPSTR l;
  39. OFSTRUCT reopen1, reopen2;
  40. DWORD volsn[2];
  41. printf("Drives = 0x%lx\n",GetLogicalDrives());
  42. n = GetLogicalDriveStrings(511,buff);
  43. if ( n < 512 ) {
  44. l = buff;
  45. while ( *l ) {
  46. printf("%s\n",l);
  47. n2 = strlen(l);
  48. l += (n2+1);;
  49. }
  50. }
  51. n = GetLogicalDriveStringsW(511,buff);
  52. xassert(!SetCurrentDirectory("X:\\"));
  53. FindFileData = (PWIN32_FIND_DATA)buff;
  54. fFile = FindFirstFile(
  55. "e:\\nt\\dll\\nul",
  56. FindFileData
  57. );
  58. xassert(fFile != INVALID_HANDLE_VALUE);
  59. FindClose(fFile);
  60. FindFileData = (PWIN32_FIND_DATA)buff;
  61. fFile = FindFirstFile(
  62. "e:\\",
  63. FindFileData
  64. );
  65. xassert(fFile == INVALID_HANDLE_VALUE);
  66. b = GetVolumeInformation("",NULL,0,volsn,NULL,NULL,NULL,0);
  67. assert(!b);
  68. b = GetVolumeInformation("e:\\",NULL,0,volsn,NULL,NULL,NULL,0);
  69. assert(b);
  70. w2 = GetTempFileName("e:\\zzzxtmp","zz",0,buff);
  71. xassert(w2 == 0 );
  72. b = GetDiskFreeSpace(NULL,&spc,&bps,&fc,&tc);
  73. xassert(b && spc && (bps == 512) && fc && tc);
  74. printf("SPC = %d, BPS = %d, FC = %d, TC = %d\n",spc,bps,fc,tc);
  75. SearchPath(
  76. ".;e:\\nt;e:\\nt\\dll",
  77. "base",
  78. ".dll",
  79. 512,
  80. cbuff,
  81. NULL
  82. );
  83. SearchPath(
  84. NULL,
  85. "win386.exe",
  86. ".EXe",
  87. 512,
  88. cbuff,
  89. NULL
  90. );
  91. (VOID)argc;
  92. (VOID)argv;
  93. (VOID)envp;
  94. #if 0
  95. CreateDirectory("e:\\zyx",NULL);
  96. xassert(SetCurrentDirectory("e:\\zyx"));
  97. *buff = '\0';
  98. xassert(GetTempPath(8,buff) == 7 && !_strcmpi(buff,"e:\\zyx\\") );
  99. *buff = '\0';
  100. xassert(GetTempPath(7,buff) == 7 && !_strcmpi(buff,"e:\\zyx\\") );
  101. *buff = '\0';
  102. xassert(GetTempPath(6,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  103. *buff = '\0';
  104. xassert(GetTempPath(5,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  105. *buff = '\0';
  106. xassert(GetTempPath(4,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  107. *buff = '\0';
  108. xassert(GetTempPath(3,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  109. *buff = '\0';
  110. xassert(GetTempPath(2,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  111. *buff = '\0';
  112. xassert(GetTempPath(1,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  113. *buff = '\0';
  114. xassert(GetTempPath(0,buff) == 7 && _strcmpi(buff,"e:\\zyx\\") );
  115. #endif
  116. xassert(SetCurrentDirectory("e:\\nt"));
  117. b = SetEnvironmentVariable("TMP","d:\\tmp");
  118. xassert(b);
  119. #if 0
  120. *buff = '\0';
  121. xassert(GetTempPath(8,buff) == 7 && !_strcmpi(buff,"d:\\tmp\\") );
  122. *buff = '\0';
  123. xassert(GetTempPath(7,buff) == 7 && !_strcmpi(buff,"d:\\tmp\\") );
  124. *buff = '\0';
  125. xassert(GetTempPath(6,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  126. *buff = '\0';
  127. xassert(GetTempPath(5,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  128. *buff = '\0';
  129. xassert(GetTempPath(4,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  130. *buff = '\0';
  131. xassert(GetTempPath(3,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  132. *buff = '\0';
  133. xassert(GetTempPath(2,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  134. *buff = '\0';
  135. xassert(GetTempPath(1,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  136. *buff = '\0';
  137. xassert(GetTempPath(0,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  138. #endif
  139. b = SetEnvironmentVariable("TMP","d:\\tmp\\");
  140. xassert(b);
  141. #if 0
  142. *buff = '\0';
  143. xassert(GetTempPath(8,buff) == 7 && !_strcmpi(buff,"d:\\tmp\\") );
  144. *buff = '\0';
  145. xassert(GetTempPath(7,buff) == 7 && !_strcmpi(buff,"d:\\tmp\\") );
  146. *buff = '\0';
  147. xassert(GetTempPath(6,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  148. *buff = '\0';
  149. xassert(GetTempPath(5,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  150. *buff = '\0';
  151. xassert(GetTempPath(4,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  152. *buff = '\0';
  153. xassert(GetTempPath(3,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  154. *buff = '\0';
  155. xassert(GetTempPath(2,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  156. *buff = '\0';
  157. xassert(GetTempPath(1,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  158. *buff = '\0';
  159. xassert(GetTempPath(0,buff) == 7 && _strcmpi(buff,"d:\\tmp\\") );
  160. #endif
  161. w1 = GetTempFileName("e:\\tmp\\","foo",0,buff);
  162. iFile = CreateFile(
  163. buff,
  164. GENERIC_WRITE,
  165. FILE_SHARE_READ,
  166. NULL,
  167. OPEN_EXISTING,
  168. 0,
  169. NULL
  170. );
  171. xassert(iFile != INVALID_HANDLE_VALUE);
  172. w2 = GetTempFileName("e:\\tmp","foobar",w1,buff);
  173. xassert(w1 == w2);
  174. oFile = CreateFile(
  175. buff,
  176. GENERIC_WRITE,
  177. 0,
  178. NULL,
  179. OPEN_EXISTING,
  180. 0,
  181. NULL
  182. );
  183. xassert(oFile == INVALID_HANDLE_VALUE);
  184. CloseHandle(iFile);
  185. xassert(CopyFile("e:\\nt\\dll\\usersrv.dll",buff,FALSE));
  186. DeleteFile("xyzzy");
  187. xassert(MoveFile(buff,"xyzzy"));
  188. xassert(!DeleteFile(buff));
  189. DeleteFile("rrxyzzy");
  190. xassert(MoveFile("xyzzy","rrxyzzy"));
  191. oFile = CreateFile(
  192. "rrxyzzy",
  193. GENERIC_READ,
  194. 0,
  195. NULL,
  196. OPEN_EXISTING,
  197. 0,
  198. NULL
  199. );
  200. xassert(oFile != INVALID_HANDLE_VALUE);
  201. iFile = CreateFile(
  202. "e:\\nt\\dll\\usersrv.dll",
  203. GENERIC_READ,
  204. 0,
  205. NULL,
  206. OPEN_EXISTING,
  207. 0,
  208. NULL
  209. );
  210. xassert(iFile != INVALID_HANDLE_VALUE);
  211. fFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,8192,NULL);
  212. xassert(fFile);
  213. base = MapViewOfFile(fFile,FILE_MAP_WRITE,0,0,0);
  214. xassert(base);
  215. strcpy(base,"Hello World\n");
  216. printf("%s",base);
  217. xassert(UnmapViewOfFile(base));
  218. CloseHandle(fFile);
  219. fFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READONLY,0,8192,NULL);
  220. xassert(fFile);
  221. CloseHandle(fFile);
  222. fFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READONLY,0,0,NULL);
  223. xassert(!fFile);
  224. mFile = CreateFileMapping(oFile,NULL,PAGE_READONLY,0,0,NULL);
  225. xassert(mFile);
  226. n1 = CreateFileMapping(oFile,NULL,PAGE_READONLY,0,0,"named-map");
  227. xassert(n1);
  228. o1 = OpenFileMapping(FILE_MAP_WRITE,FALSE,"named-map");
  229. xassert(o1);
  230. base = MapViewOfFile(o1,FILE_MAP_WRITE,0,0,0);
  231. xassert(!base);
  232. base = MapViewOfFile(n1,FILE_MAP_READ,0,0,0);
  233. xassert(base);
  234. FindFileData = (PWIN32_FIND_DATA)buff;
  235. fFile = FindFirstFile(
  236. "e:\\nt\\dll\\usersrv.dll",
  237. FindFileData
  238. );
  239. xassert(fFile != INVALID_HANDLE_VALUE);
  240. l = LocalAlloc(LMEM_ZEROINIT,FindFileData->nFileSizeLow);
  241. xassert(l);
  242. b = ReadFile(iFile,l,FindFileData->nFileSizeLow,&n,NULL);
  243. xassert(b);
  244. xassert(n == FindFileData->nFileSizeLow);
  245. CloseHandle(oFile);
  246. xassert(memcmp(l,base,FindFileData->nFileSizeLow) == 0 );
  247. xassert(DeleteFile("rrxyzzy"));
  248. w2 = GetTempFileName("e:\\tmp","foobar",(WORD)0xf7ff,buff);
  249. xassert(w2 == 0xf7ff);
  250. oFile = CreateFile(
  251. buff,
  252. GENERIC_WRITE,
  253. 0,
  254. NULL,
  255. OPEN_EXISTING,
  256. 0,
  257. NULL
  258. );
  259. xassert(oFile == INVALID_HANDLE_VALUE);
  260. w2 = GetTempFileName("e:\\xtmp","foobar",0,buff);
  261. xassert(w2 == 0);
  262. xassert(!RemoveDirectory("e:\\"));
  263. xassert(SetCurrentDirectory("e:\\nt"));
  264. xassert(!RemoveDirectory("."));
  265. n = GetCurrentDirectory(0,buff);
  266. xassert(n == 5);
  267. n = GetCurrentDirectory(4,buff);
  268. xassert(n == 5);
  269. *buff = '\0';
  270. n = GetCurrentDirectory(5,buff);
  271. xassert(n == 5 && strcmp(buff,"e:\\nt") == 0 );
  272. *buff = '\0';
  273. n = GetCurrentDirectory(500,buff);
  274. xassert(n == 5 && strcmp(buff,"e:\\nt") == 0 );
  275. xassert(SetCurrentDirectory("e:\\"));
  276. *buff = '\0';
  277. n = GetCurrentDirectory(500,buff);
  278. xassert(n == 3 && strcmp(buff,"e:\\") == 0 );
  279. *buff = '\0';
  280. n = GetCurrentDirectory(3,buff);
  281. xassert(n == 3 && strcmp(buff,"e:\\") == 0 );
  282. *buff = '\0';
  283. n = GetCurrentDirectory(2,buff);
  284. xassert(n == 3 && strcmp(buff,"e:\\") != 0 );
  285. xassert(SetCurrentDirectory("e:\\nt"));
  286. *buff = '\0';
  287. n = GetCurrentDirectory(500,buff);
  288. xassert(n == 5 && strcmp(buff,"e:\\nt") == 0 );
  289. xassert(SetCurrentDirectory("."));
  290. *buff = '\0';
  291. n = GetCurrentDirectory(500,buff);
  292. xassert(n == 5 && strcmp(buff,"e:\\nt") == 0 );
  293. xassert(GetDriveType("Z:\\") == 1);
  294. xassert(GetDriveType(".") == 1);
  295. xassert(GetDriveType("e:\\NT") == 1);
  296. xassert(GetDriveType(NULL) == DRIVE_FIXED);
  297. xassert(GetDriveType("e:\\") == DRIVE_FIXED);
  298. xassert(GetDriveType("A:\\") == DRIVE_REMOVABLE);
  299. xassert(!CreateDirectory(".",NULL));
  300. xassert(CreateDirectory("xyzzy",NULL));
  301. FindFileData = (PWIN32_FIND_DATA)buff;
  302. fFile = FindFirstFile(
  303. "xyzzy\\*.*",
  304. FindFileData
  305. );
  306. xassert(fFile != INVALID_HANDLE_VALUE);
  307. b = TRUE;
  308. while(b) {
  309. printf("0x%08x %08d %s\n",
  310. FindFileData->dwFileAttributes,
  311. FindFileData->nFileSizeLow,
  312. FindFileData->cFileName
  313. );
  314. b = FindNextFile(fFile,FindFileData);
  315. }
  316. FindClose(fFile);
  317. xassert(!FindClose(fFile));
  318. xassert(RemoveDirectory("xyzzy"));
  319. iFile = CreateFile(
  320. "",
  321. GENERIC_READ,
  322. FILE_SHARE_READ,
  323. NULL,
  324. OPEN_EXISTING,
  325. 0,
  326. NULL
  327. );
  328. xassert(iFile == INVALID_HANDLE_VALUE);
  329. iFile = CreateFile(
  330. "nt.cfg",
  331. GENERIC_READ,
  332. FILE_SHARE_READ,
  333. NULL,
  334. OPEN_EXISTING,
  335. 0,
  336. NULL
  337. );
  338. xassert(iFile != INVALID_HANDLE_VALUE);
  339. xassert(!FlushFileBuffers(iFile));
  340. xassert(LockFile(iFile,0,0,10,0));
  341. xassert(LockFile(iFile,10,0,10,0));
  342. xassert(!LockFile(iFile,1,0,1,0));
  343. xassert(!LockFile(iFile,0,0,11,0));
  344. xassert(!LockFile(iFile,0,0,20,0));
  345. xassert(!UnlockFile(iFile,1,0,1,0));
  346. xassert(!UnlockFile(iFile,0,0,11,0));
  347. xassert(!UnlockFile(iFile,0,0,20,0));
  348. xassert(UnlockFile(iFile,0,0,10,0));
  349. xassert(UnlockFile(iFile,10,0,10,0));
  350. xassert(LockFile(iFile,0,0,10,0));
  351. xassert(LockFile(iFile,10,0,10,0));
  352. fFile = CreateFile(
  353. "nt.cfg",
  354. GENERIC_READ,
  355. FILE_SHARE_READ,
  356. NULL,
  357. OPEN_EXISTING,
  358. 0,
  359. NULL
  360. );
  361. xassert(fFile != INVALID_HANDLE_VALUE);
  362. b = ReadFile(fFile,&buff,1, &n, NULL);
  363. xassert(!b);
  364. xassert(SetFilePointer(INVALID_HANDLE_VALUE,0,NULL,FILE_BEGIN) == 0xffffffff);
  365. b = ReadFile(fFile,&buff,11, &n, NULL);
  366. xassert(SetFilePointer(fFile,0,NULL,FILE_BEGIN) == 0);
  367. b = ReadFile(fFile,&buff,11, &n, NULL);
  368. xassert(!b);
  369. xassert(SetFilePointer(fFile,10,NULL,FILE_BEGIN) == 10);
  370. b = ReadFile(fFile,&buff,1,&n,NULL);
  371. xassert(!b);
  372. xassert(SetFilePointer(fFile,10,NULL,FILE_BEGIN) == 10);
  373. b = ReadFile(fFile,&buff,1,&n,NULL);
  374. xassert(!b);
  375. xassert(SetFilePointer(fFile,20,NULL,FILE_BEGIN) == 20);
  376. b = ReadFile(fFile,&buff,1, &n, NULL);
  377. xassert(b && n == 1);
  378. xassert(UnlockFile(iFile,0,0,10,0));
  379. xassert(UnlockFile(iFile,10,0,10,0));
  380. CloseHandle(fFile);
  381. SetHandleCount(255);
  382. oFile = CreateFile(
  383. "ntos3.cfg",
  384. GENERIC_READ | GENERIC_WRITE,
  385. FILE_SHARE_READ,
  386. NULL,
  387. CREATE_ALWAYS,
  388. FILE_ATTRIBUTE_HIDDEN,
  389. NULL
  390. );
  391. xassert(oFile != INVALID_HANDLE_VALUE);
  392. xassert(FlushFileBuffers(oFile));
  393. //
  394. // Copy iFile to oFile
  395. //
  396. Size = 0;
  397. b = ReadFile(iFile,&buff,512, &n, NULL);
  398. while(b && n){
  399. Size += n;
  400. b = WriteFile(oFile,&buff,n, &n, NULL);
  401. xassert(b && n);
  402. b = ReadFile(iFile,&buff,512, &n, NULL);
  403. }
  404. //
  405. // Make sure that we can not truncate a read only file
  406. //
  407. xassert(!SetEndOfFile(iFile));
  408. //
  409. // Go back to beginning of the iFile
  410. //
  411. xassert(SetFilePointer(iFile,0,NULL,FILE_BEGIN) == 0);
  412. xassert(SetFilePointer(oFile,-Size,NULL,FILE_CURRENT) == 0);
  413. b = ReadFile(iFile,&buff,512, &n, NULL);
  414. xassert(b && n);
  415. b = ReadFile(oFile,&cbuff,n, &n2, NULL);
  416. xassert(b && (n2 == n) );
  417. while(n && (n == n2) ){
  418. xassert(memcmp(&buff,&cbuff,n) == 0);
  419. ReadFile(iFile,&buff,512, &n, NULL);
  420. ReadFile(oFile,&cbuff,n, &n2, NULL);
  421. xassert(n2 == n);
  422. }
  423. printf("End of Loop. n2 = %ld GLE = 0x%lx\n",n2,GetLastError());
  424. //
  425. // Truncate the file to 128 bytes
  426. //
  427. xassert(SetFilePointer(oFile,128,NULL,FILE_BEGIN) == 128);
  428. xassert(SetEndOfFile(oFile));
  429. xassert(SetFilePointer(oFile,0,NULL,FILE_BEGIN) == 0);
  430. xassert(SetFilePointer(oFile,0,NULL,FILE_END) != -1);
  431. xassert(SetFilePointer(oFile,0,NULL,FILE_BEGIN) == 0);
  432. ReadFile(oFile,&cbuff,512, &n2, NULL);
  433. xassert(n2 == 128);
  434. CloseHandle(iFile);
  435. CloseHandle(oFile);
  436. oFile = CreateFile(
  437. "ntos3.cfg",
  438. GENERIC_READ | GENERIC_WRITE,
  439. FILE_SHARE_READ,
  440. NULL,
  441. CREATE_NEW,
  442. FILE_ATTRIBUTE_NORMAL,
  443. NULL
  444. );
  445. xassert(oFile == INVALID_HANDLE_VALUE);
  446. attr = GetFileAttributes("ntos3.cfg");
  447. xassert(attr == (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE));
  448. xassert(SetFileAttributes("ntos3.cfg", FILE_ATTRIBUTE_NORMAL));
  449. attr = GetFileAttributes("ntos3.cfg");
  450. xassert(attr == FILE_ATTRIBUTE_NORMAL);
  451. oFile = CreateFile(
  452. "ntos3.cfg",
  453. GENERIC_WRITE | GENERIC_READ,
  454. FILE_SHARE_READ,
  455. NULL,
  456. OPEN_EXISTING,
  457. 0,
  458. NULL
  459. );
  460. xassert(oFile != INVALID_HANDLE_VALUE);
  461. xassert(!DeleteFile("ntos3.cfg"));
  462. CloseHandle(oFile);
  463. xassert(DeleteFile("ntos3.cfg"));
  464. oFile = CreateFile(
  465. "ntos3.cfg",
  466. GENERIC_WRITE | GENERIC_READ,
  467. FILE_SHARE_READ,
  468. NULL,
  469. OPEN_EXISTING,
  470. 0,
  471. NULL
  472. );
  473. xassert(oFile == INVALID_HANDLE_VALUE);
  474. FindFileData = (PWIN32_FIND_DATA)buff;
  475. fFile = FindFirstFile(
  476. "dll\\*.*",
  477. FindFileData
  478. );
  479. xassert(fFile != INVALID_HANDLE_VALUE);
  480. b = TRUE;
  481. while(b) {
  482. printf("0x%08x %08d %s\n",
  483. FindFileData->dwFileAttributes,
  484. FindFileData->nFileSizeLow,
  485. FindFileData->cFileName
  486. );
  487. b = FindNextFile(fFile,FindFileData);
  488. }
  489. FindClose(fFile);
  490. xassert(!FindClose(fFile));
  491. n = GetWindowsDirectory(cbuff,512);
  492. printf("Windows directory %s length %d\n",cbuff,n);
  493. strcat(cbuff,"\\*.*");
  494. fFile = FindFirstFile(
  495. cbuff,
  496. FindFileData
  497. );
  498. xassert(fFile != INVALID_HANDLE_VALUE);
  499. b = TRUE;
  500. while(b) {
  501. printf("0x%08x %08d %s\n",
  502. FindFileData->dwFileAttributes,
  503. FindFileData->nFileSizeLow,
  504. FindFileData->cFileName
  505. );
  506. b = FindNextFile(fFile,FindFileData);
  507. }
  508. FindClose(fFile);
  509. xassert(!FindClose(fFile));
  510. GetSystemDirectory(cbuff,512);
  511. strcat(cbuff,"\\*.*");
  512. fFile = FindFirstFile(
  513. cbuff,
  514. FindFileData
  515. );
  516. xassert(fFile != INVALID_HANDLE_VALUE);
  517. b = TRUE;
  518. while(b) {
  519. printf("0x%08x %08d %s\n",
  520. FindFileData->dwFileAttributes,
  521. FindFileData->nFileSizeLow,
  522. FindFileData->cFileName
  523. );
  524. b = FindNextFile(fFile,FindFileData);
  525. }
  526. FindClose(fFile);
  527. xassert(!FindClose(fFile));
  528. iFile = (HANDLE)OpenFile("xyzzy.ggg",&reopen1, OF_PARSE);
  529. xassert(iFile == 0);
  530. dw = GetFullPathName("xyzzy.ggg",512,buff,&l);
  531. xassert(!_stricmp(buff,&reopen1.szPathName[0]));
  532. iFile = (HANDLE)OpenFile("",&reopen1, OF_READ);
  533. xassert(iFile == INVALID_HANDLE_VALUE);
  534. iFile = (HANDLE)OpenFile("ls.exe",&reopen1, OF_READ);
  535. xassert(iFile && iFile != INVALID_HANDLE_VALUE);
  536. xassert(!_stricmp("e:\\nt\\bin\\ls.exe",&reopen1.szPathName[0]));
  537. CloseHandle(iFile);
  538. reopen2 = reopen1;
  539. iFile = (HANDLE)OpenFile("ls.exe",&reopen1, OF_VERIFY | OF_READ);
  540. xassert(iFile && iFile != INVALID_HANDLE_VALUE);
  541. xassert(!_stricmp("e:\\nt\\bin\\ls.exe",&reopen1.szPathName[0]));
  542. CloseHandle(iFile);
  543. iFile = (HANDLE)OpenFile("",&reopen1, OF_REOPEN | OF_READ);
  544. xassert(iFile && iFile != INVALID_HANDLE_VALUE);
  545. xassert(!_stricmp("e:\\nt\\bin\\ls.exe",&reopen1.szPathName[0]));
  546. CloseHandle(iFile);
  547. iFile = (HANDLE)OpenFile("ls.exe",&reopen2, OF_VERIFY | OF_READ);
  548. xassert(iFile && iFile != INVALID_HANDLE_VALUE);
  549. xassert(!_stricmp("e:\\nt\\bin\\ls.exe",&reopen2.szPathName[0]));
  550. CloseHandle(iFile);
  551. iFile = (HANDLE)OpenFile("ls.exe",&reopen2, OF_EXIST );
  552. xassert(!CloseHandle(iFile));
  553. xassert(CopyFile("e:\\nt\\bin\\ls.exe","xxx.xxx",FALSE));
  554. iFile = (HANDLE)OpenFile("xxx.xxx",&reopen1, OF_EXIST );
  555. xassert(!CloseHandle(iFile));
  556. iFile = (HANDLE)OpenFile("xxx.xxx",&reopen1, OF_READWRITE );
  557. xassert(iFile && iFile != INVALID_HANDLE_VALUE);
  558. Sleep(3000);
  559. b = WriteFile(iFile,"Hello World",12,&n,NULL);
  560. xassert(b && n == 12);
  561. CloseHandle(iFile);
  562. iFile = (HANDLE)OpenFile("xxx.xxx",&reopen1, OF_VERIFY | OF_READ);
  563. xassert(iFile == INVALID_HANDLE_VALUE);
  564. iFile = (HANDLE)OpenFile("xxx.xxx",&reopen1, OF_DELETE );
  565. xassert(!CloseHandle(iFile));
  566. iFile = (HANDLE)OpenFile("xxx.xxx",&reopen1, OF_EXIST );
  567. printf("iFile %lx nErrCode %d\n",iFile,reopen1.nErrCode);
  568. xassert(iFile == INVALID_HANDLE_VALUE && reopen1.nErrCode == ERROR_FILE_NOT_FOUND);
  569. fFile = FindFirstFile(
  570. "e:\\nt\\nt.cfg",
  571. FindFileData
  572. );
  573. xassert(fFile != INVALID_HANDLE_VALUE);
  574. iFile = (HANDLE)OpenFile("e:\\nt\\nt.cfg",&reopen1, OF_READ);
  575. xassert(iFile && iFile != INVALID_HANDLE_VALUE);
  576. n = GetFileSize(iFile,NULL);
  577. xassert(n != -1);
  578. xassert(n==FindFileData->nFileSizeLow);
  579. FindClose(fFile);
  580. CloseHandle(iFile);
  581. xassert(CopyFile("e:\\nt\\bin\\ls.exe","xxx.xxx",FALSE));
  582. iFile = _lopen("xxx.xxx",OF_READ);
  583. xassert(iFile != INVALID_HANDLE_VALUE);
  584. oFile = _lcreat("xxx.zzz",0);
  585. xassert(oFile != INVALID_HANDLE_VALUE);
  586. Size = 0;
  587. b = ReadFile(iFile,&buff,512, &n, NULL);
  588. while(b && n){
  589. Size += n;
  590. b = WriteFile(oFile,&buff,n, &n, NULL);
  591. xassert(b && n);
  592. b = ReadFile(iFile,&buff,512, &n, NULL);
  593. }
  594. CloseHandle(iFile);
  595. CloseHandle(oFile);
  596. iFile = _lopen("xxx.xxx",OF_WRITE);
  597. xassert(iFile != INVALID_HANDLE_VALUE);
  598. CloseHandle(iFile);
  599. iFile = _lopen("xxx.xxx",OF_READ);
  600. b = ReadFile(iFile,&buff,512, &n, NULL);
  601. xassert(b && n == 0 && GetLastError() == 0);
  602. return 1;
  603. }