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.

1513 lines
35 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. old tth.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 <stdlib.h>
  16. #include <stdio.h>
  17. #include <windows.h>
  18. #include <string.h>
  19. #include <memory.h>
  20. #include <process.h>
  21. #define xassert ASSERT
  22. int izero;
  23. int i,j;
  24. #define BASESPIN 1000000
  25. #define NULL_SERVER_SWITCHES 10000
  26. #define PATH_CONVERSION_TEST 1000
  27. //
  28. // Define local types.
  29. //
  30. typedef struct _PERFINFO {
  31. LARGE_INTEGER StartTime;
  32. LARGE_INTEGER StopTime;
  33. ULONG ContextSwitches;
  34. ULONG FirstLevelFills;
  35. ULONG SecondLevelFills;
  36. ULONG SystemCalls;
  37. PCHAR Title;
  38. ULONG Iterations;
  39. } PERFINFO, *PPERFINFO;
  40. VOID
  41. FinishBenchMark (
  42. IN PPERFINFO PerfInfo
  43. )
  44. {
  45. ULONG ContextSwitches;
  46. LARGE_INTEGER Duration;
  47. ULONG FirstLevelFills;
  48. ULONG Length;
  49. ULONG Performance;
  50. ULONG SecondLevelFills;
  51. NTSTATUS Status;
  52. ULONG SystemCalls;
  53. SYSTEM_PERFORMANCE_INFORMATION SystemInfo;
  54. //
  55. // Print results and announce end of test.
  56. //
  57. NtQuerySystemTime((PLARGE_INTEGER)&PerfInfo->StopTime);
  58. Status = NtQuerySystemInformation(SystemPerformanceInformation,
  59. (PVOID)&SystemInfo,
  60. sizeof(SYSTEM_PERFORMANCE_INFORMATION),
  61. NULL);
  62. if (NT_SUCCESS(Status) == FALSE) {
  63. printf("Failed to query performance information, status = %lx\n", Status);
  64. return;
  65. }
  66. Duration = RtlLargeIntegerSubtract(PerfInfo->StopTime, PerfInfo->StartTime);
  67. Length = Duration.LowPart / 10000;
  68. printf(" Test time in milliseconds %d\n", Length);
  69. printf(" Number of iterations %d\n", PerfInfo->Iterations);
  70. Performance = PerfInfo->Iterations * 1000 / Length;
  71. printf(" Iterations per second %d\n", Performance);
  72. ContextSwitches = SystemInfo.ContextSwitches - PerfInfo->ContextSwitches;
  73. FirstLevelFills = SystemInfo.FirstLevelTbFills - PerfInfo->FirstLevelFills;
  74. SecondLevelFills = SystemInfo.SecondLevelTbFills - PerfInfo->SecondLevelFills;
  75. SystemCalls = SystemInfo.SystemCalls - PerfInfo->SystemCalls;
  76. printf(" First Level TB Fills %d\n", FirstLevelFills);
  77. printf(" Second Level TB Fills %d\n", SecondLevelFills);
  78. printf(" Total Context Switches %d\n", ContextSwitches);
  79. printf(" Number of System Calls %d\n", SystemCalls);
  80. printf("*** End of Test ***\n\n");
  81. return;
  82. }
  83. VOID
  84. StartBenchMark (
  85. IN PCHAR Title,
  86. IN ULONG Iterations,
  87. IN PPERFINFO PerfInfo
  88. )
  89. {
  90. NTSTATUS Status;
  91. SYSTEM_PERFORMANCE_INFORMATION SystemInfo;
  92. //
  93. // Announce start of test and the number of iterations.
  94. //
  95. printf("*** Start of test ***\n %s\n", Title);
  96. PerfInfo->Title = Title;
  97. PerfInfo->Iterations = Iterations;
  98. NtQuerySystemTime((PLARGE_INTEGER)&PerfInfo->StartTime);
  99. Status = NtQuerySystemInformation(SystemPerformanceInformation,
  100. (PVOID)&SystemInfo,
  101. sizeof(SYSTEM_PERFORMANCE_INFORMATION),
  102. NULL);
  103. if (NT_SUCCESS(Status) == FALSE) {
  104. printf("Failed to query performance information, status = %lx\n", Status);
  105. return;
  106. }
  107. PerfInfo->ContextSwitches = SystemInfo.ContextSwitches;
  108. PerfInfo->FirstLevelFills = SystemInfo.FirstLevelTbFills;
  109. PerfInfo->SecondLevelFills = SystemInfo.SecondLevelTbFills;
  110. PerfInfo->SystemCalls = SystemInfo.SystemCalls;
  111. return;
  112. }
  113. VOID
  114. ScrollTest()
  115. {
  116. COORD dest,cp;
  117. SMALL_RECT Sm;
  118. CHAR_INFO ci;
  119. CONSOLE_SCREEN_BUFFER_INFO sbi;
  120. HANDLE ScreenHandle;
  121. SMALL_RECT Window;
  122. GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi);
  123. Window.Left = 0;
  124. Window.Top = 0;
  125. Window.Right = 79;
  126. Window.Bottom = 49;
  127. dest.X = 0;
  128. dest.Y = 0;
  129. ci.Char.AsciiChar = ' ';
  130. ci.Attributes = sbi.wAttributes;
  131. SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE),
  132. TRUE,
  133. &Window);
  134. cp.X = 0;
  135. cp.Y = 0;
  136. Sm.Left = 0;
  137. Sm.Top = 1;
  138. Sm.Right = 79;
  139. Sm.Bottom = 49;
  140. ScrollConsoleScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE),
  141. &Sm,
  142. NULL,
  143. dest,
  144. &ci);
  145. }
  146. VOID
  147. WinWordOpenFileTest()
  148. {
  149. PERFINFO PerfInfo;
  150. ULONG Index;
  151. OFSTRUCT ofstr;
  152. HANDLE iFile;
  153. StartBenchMark("WinWord OpenFile)",
  154. 3,
  155. &PerfInfo);
  156. for ( Index=0;Index<3;Index++){
  157. iFile = (HANDLE)OpenFile("foo",&ofstr, OF_PARSE);
  158. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\winword.ini",&ofstr, 0x20);
  159. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\perftest.doc",&ofstr, 0x22);
  160. iFile = (HANDLE)OpenFile("E:foo",&ofstr, OF_PARSE);
  161. iFile = (HANDLE)OpenFile("E:foo",&ofstr, OF_PARSE);
  162. iFile = (HANDLE)OpenFile("E:foo",&ofstr, OF_PARSE);
  163. iFile = (HANDLE)OpenFile("E:foo",&ofstr, OF_PARSE);
  164. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\custom.dic",&ofstr, 0x4022 );
  165. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\sp_am.exc",&ofstr, 0x4040 );
  166. iFile = (HANDLE)OpenFile("E:foo",&ofstr, OF_PARSE);
  167. iFile = (HANDLE)OpenFile("foo",&ofstr, OF_PARSE);
  168. iFile = (HANDLE)OpenFile("E:~doc3d08.tmp",&ofstr, 0x1022);
  169. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\tempx.doc",&ofstr, 0xa022 );
  170. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\~$rftest.doc",&ofstr, 0x4012 );
  171. iFile = (HANDLE)OpenFile("foo",&ofstr, OF_PARSE);
  172. iFile = (HANDLE)OpenFile("E:~doc391f.tmp",&ofstr, 0x1022);
  173. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\tempy.doc",&ofstr, 0xa022 );
  174. iFile = (HANDLE)OpenFile("E:\\xxxxxxx\\winword.ini",&ofstr, 0x12);
  175. }
  176. FinishBenchMark(&PerfInfo);
  177. }
  178. VOID
  179. gettictst(int x)
  180. {
  181. PERFINFO PerfInfo;
  182. ULONG i,j;
  183. ULONG tnt,tw32;
  184. if ( !x ) {
  185. StartBenchMark("NtGetTickCount)",
  186. 100000,
  187. &PerfInfo);
  188. for ( i=0;i<100000;i++){
  189. j = GetTickCount();
  190. }
  191. FinishBenchMark(&PerfInfo);
  192. }
  193. else {
  194. while(1)GetTickCount();
  195. }
  196. }
  197. VOID
  198. latst()
  199. {
  200. PERFINFO PerfInfo;
  201. ULONG i,j;
  202. HANDLE h1, h2, h3, h4, h5;
  203. StartBenchMark("LocalAlloc/Free)",
  204. 200,
  205. &PerfInfo);
  206. for ( i=0;i<200/5;i++){
  207. h1 = LocalAlloc(0, 500);
  208. h2 = LocalAlloc(0, 600);
  209. h3 = LocalAlloc(0, 700);
  210. LocalFree(h2);
  211. h4 = LocalAlloc(0, 1000);
  212. h5 = LocalAlloc(0, 100);
  213. LocalFree(h1);
  214. LocalFree(h3);
  215. LocalFree(h4);
  216. LocalFree(h5);
  217. }
  218. FinishBenchMark(&PerfInfo);
  219. }
  220. VOID
  221. WinWordGetDriveTypeTest()
  222. {
  223. PERFINFO PerfInfo;
  224. ULONG Index,Reps;
  225. OFSTRUCT ofstr;
  226. HANDLE iFile;
  227. CHAR DiskName[4];
  228. WCHAR WDiskName[4];
  229. // StartBenchMark("WinWord GetDriveType (1-26)",
  230. // 26,
  231. // &PerfInfo);
  232. //
  233. // for ( Index=1;Index<27;Index++){
  234. // GetDriveType(Index);
  235. // }
  236. //
  237. // FinishBenchMark(&PerfInfo);
  238. DiskName[0]='a';
  239. DiskName[1]=':';
  240. DiskName[2]='\\';
  241. DiskName[3]='\0';
  242. StartBenchMark("WinWord GetDriveTypeA (a-z)",
  243. 100,
  244. &PerfInfo);
  245. for(Reps=0;Reps<100;Reps++){
  246. for ( Index=0;Index<26;Index++){
  247. DiskName[0]='a'+Index;
  248. GetDriveTypeA(DiskName);
  249. }
  250. }
  251. FinishBenchMark(&PerfInfo);
  252. WDiskName[0]=(WCHAR)'a';
  253. WDiskName[1]=(WCHAR)':';
  254. WDiskName[2]=(WCHAR)'\\';
  255. WDiskName[3]=(WCHAR)'\0';
  256. StartBenchMark("WinWord GetDriveTypeW (a-z)",
  257. 100,
  258. &PerfInfo);
  259. for(Reps=0;Reps<100;Reps++){
  260. for ( Index=0;Index<26;Index++){
  261. WDiskName[0]=(WCHAR)'a'+Index;
  262. GetDriveTypeW(WDiskName);
  263. }
  264. }
  265. FinishBenchMark(&PerfInfo);
  266. }
  267. VOID
  268. BogusOrdinalTest()
  269. {
  270. HANDLE hBase;
  271. FARPROC z;
  272. WaitForSingleObject(0,-2);
  273. hBase = GetModuleHandle("base");
  274. xassert(hBase);
  275. z = GetProcAddress(hBase,0x00001345);
  276. }
  277. VOID
  278. NullServerSwitchTest (
  279. VOID
  280. )
  281. {
  282. PERFINFO PerfInfo;
  283. NTSTATUS Status;
  284. ULONG Index;
  285. StartBenchMark("Null Server Call Benchmark)",
  286. NULL_SERVER_SWITCHES,
  287. &PerfInfo);
  288. for (Index = 0; Index < NULL_SERVER_SWITCHES; Index += 1) {
  289. CsrIdentifyAlertableThread();
  290. }
  291. //
  292. // Print out performance statistics.
  293. //
  294. FinishBenchMark(&PerfInfo);
  295. return;
  296. }
  297. VOID
  298. PathConvertTest (
  299. VOID
  300. )
  301. {
  302. PERFINFO PerfInfo;
  303. NTSTATUS Status;
  304. ULONG Index;
  305. UNICODE_STRING FileName;
  306. BOOLEAN TranslationStatus;
  307. RTL_RELATIVE_NAME RelativeName;
  308. StartBenchMark("Path Conversion Test (foo)",
  309. PATH_CONVERSION_TEST,
  310. &PerfInfo);
  311. for (Index = 0; Index < PATH_CONVERSION_TEST; Index += 1) {
  312. RtlDosPathNameToNtPathName_U(
  313. L"foo",
  314. &FileName,
  315. NULL,
  316. &RelativeName
  317. );
  318. RtlFreeHeap(RtlProcessHeap(),FileName.Buffer);
  319. }
  320. //
  321. // Print out performance statistics.
  322. //
  323. FinishBenchMark(&PerfInfo);
  324. StartBenchMark("Path Conversion Test (e:\\nt\\windows\\foo)",
  325. PATH_CONVERSION_TEST,
  326. &PerfInfo);
  327. for (Index = 0; Index < PATH_CONVERSION_TEST; Index += 1) {
  328. RtlDosPathNameToNtPathName_U(
  329. L"e:\\nt\\windows\\foo",
  330. &FileName,
  331. NULL,
  332. &RelativeName
  333. );
  334. RtlFreeHeap(RtlProcessHeap(),FileName.Buffer);
  335. }
  336. //
  337. // Print out performance statistics.
  338. //
  339. FinishBenchMark(&PerfInfo);
  340. return;
  341. }
  342. z(){}
  343. bar()
  344. {
  345. for (i=0;i<2*BASESPIN;i++)j = i++;
  346. z();
  347. z();
  348. z();
  349. z();
  350. z();
  351. z();
  352. z();
  353. z();
  354. z();
  355. z();
  356. z();
  357. z();
  358. z();
  359. z();
  360. }
  361. foo()
  362. {
  363. for (i=0;i<BASESPIN;i++)j = i++;
  364. bar();
  365. z();
  366. z();
  367. z();
  368. z();
  369. z();
  370. z();
  371. z();
  372. z();
  373. z();
  374. z();
  375. z();
  376. z();
  377. z();
  378. z();
  379. }
  380. proftst()
  381. {
  382. for (i=0;i<BASESPIN;i++)j = i++;
  383. foo();
  384. z();
  385. z();
  386. z();
  387. z();
  388. z();
  389. z();
  390. z();
  391. z();
  392. z();
  393. z();
  394. z();
  395. z();
  396. z();
  397. z();
  398. }
  399. VOID
  400. probtst(
  401. VOID
  402. )
  403. {
  404. LPVOID ReadOnly;
  405. LPVOID ReadWrite;
  406. LPVOID ReadWrite2;
  407. LPVOID NoReadWrite;
  408. LPVOID MappedReadWrite;
  409. LPVOID p;
  410. HANDLE MappedFile;
  411. LPSTR l;
  412. LPWSTR w;
  413. BOOL b;
  414. ReadOnly = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_READONLY);
  415. ASSERT(ReadOnly);
  416. ASSERT(!IsBadReadPtr(ReadOnly,1024));
  417. ASSERT(!IsBadReadPtr(ReadOnly,4096));
  418. ASSERT(IsBadReadPtr(ReadOnly,4097));
  419. ASSERT(!IsBadHugeReadPtr(ReadOnly,1024));
  420. ASSERT(!IsBadHugeReadPtr(ReadOnly,4096));
  421. ASSERT(IsBadHugeReadPtr(ReadOnly,4097));
  422. ASSERT(IsBadWritePtr(ReadOnly,1024));
  423. ASSERT(IsBadWritePtr(ReadOnly,4096));
  424. ASSERT(IsBadWritePtr(ReadOnly,4097));
  425. ASSERT(IsBadHugeWritePtr(ReadOnly,1024));
  426. ASSERT(IsBadHugeWritePtr(ReadOnly,4096));
  427. ASSERT(IsBadHugeWritePtr(ReadOnly,4097));
  428. ReadWrite = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_READWRITE);
  429. ASSERT(ReadWrite);
  430. ASSERT(!IsBadReadPtr(ReadWrite,1024));
  431. ASSERT(!IsBadReadPtr(ReadWrite,4096));
  432. ASSERT(IsBadReadPtr(ReadWrite,4097));
  433. ASSERT(!IsBadHugeReadPtr(ReadWrite,1024));
  434. ASSERT(!IsBadHugeReadPtr(ReadWrite,4096));
  435. ASSERT(IsBadHugeReadPtr(ReadWrite,4097));
  436. ASSERT(!IsBadWritePtr(ReadWrite,1024));
  437. ASSERT(!IsBadWritePtr(ReadWrite,4096));
  438. ASSERT(IsBadWritePtr(ReadWrite,4097));
  439. ASSERT(!IsBadHugeWritePtr(ReadWrite,1024));
  440. ASSERT(!IsBadHugeWritePtr(ReadWrite,4096));
  441. ASSERT(IsBadHugeWritePtr(ReadWrite,4097));
  442. NoReadWrite = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_NOACCESS);
  443. ASSERT(NoReadWrite);
  444. ASSERT(IsBadReadPtr(NoReadWrite,1024));
  445. ASSERT(IsBadReadPtr(NoReadWrite,4096));
  446. ASSERT(IsBadReadPtr(NoReadWrite,4097));
  447. ASSERT(IsBadHugeReadPtr(NoReadWrite,1024));
  448. ASSERT(IsBadHugeReadPtr(NoReadWrite,4096));
  449. ASSERT(IsBadHugeReadPtr(NoReadWrite,4097));
  450. ASSERT(IsBadWritePtr(NoReadWrite,1024));
  451. ASSERT(IsBadWritePtr(NoReadWrite,4096));
  452. ASSERT(IsBadWritePtr(NoReadWrite,4097));
  453. ASSERT(IsBadHugeWritePtr(NoReadWrite,1024));
  454. ASSERT(IsBadHugeWritePtr(NoReadWrite,4096));
  455. ASSERT(IsBadHugeWritePtr(NoReadWrite,4097));
  456. l = ReadWrite;
  457. l[4092]='a';
  458. l[4093]='b';
  459. l[4094]='c';
  460. l[4095]='\0';
  461. ASSERT(!IsBadStringPtrA(&l[4092],2));
  462. ASSERT(!IsBadStringPtrA(&l[4092],3));
  463. ASSERT(!IsBadStringPtrA(&l[4092],4));
  464. ASSERT(!IsBadStringPtrA(&l[4092],5));
  465. l[4095]='d';
  466. ASSERT(!IsBadStringPtrA(&l[4092],2));
  467. ASSERT(!IsBadStringPtrA(&l[4092],3));
  468. ASSERT(!IsBadStringPtrA(&l[4092],4));
  469. ASSERT(IsBadStringPtrA(&l[4092],5));
  470. w = ReadWrite;
  471. w[2044]=(WCHAR)'a';
  472. w[2045]=(WCHAR)'b';
  473. w[2046]=(WCHAR)'c';
  474. w[2047]=UNICODE_NULL;
  475. ASSERT(!IsBadStringPtrW(&w[2044],2));
  476. ASSERT(!IsBadStringPtrW(&w[2044],3));
  477. ASSERT(!IsBadStringPtrW(&w[2044],4));
  478. ASSERT(!IsBadStringPtrW(&w[2044],5));
  479. w[2047]=(WCHAR)'d';
  480. ASSERT(!IsBadStringPtrW(&w[2044],2));
  481. ASSERT(!IsBadStringPtrW(&w[2044],3));
  482. ASSERT(!IsBadStringPtrW(&w[2044],4));
  483. ASSERT(IsBadStringPtrW(&w[2044],5));
  484. ReadWrite2 = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_READWRITE);
  485. ASSERT(ReadWrite2);
  486. ASSERT(VirtualLock(ReadWrite2,4096));
  487. ASSERT(VirtualUnlock(ReadWrite2,4));
  488. ASSERT(!VirtualUnlock(ReadWrite2,4));
  489. ASSERT(!VirtualLock(ReadWrite2,4097));
  490. ASSERT(!VirtualUnlock(ReadWrite2,4097));
  491. ASSERT(VirtualLock(ReadWrite2,4096));
  492. ASSERT(VirtualUnlock(ReadWrite2,4096));
  493. ASSERT(!VirtualUnlock(ReadWrite2,4096));
  494. MappedFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,8192,NULL);
  495. ASSERT(MappedFile);
  496. MappedReadWrite = MapViewOfFileEx(MappedFile,FILE_MAP_WRITE,0,0,0,(LPVOID)0x50000000);
  497. ASSERT(MappedReadWrite);
  498. p = MapViewOfFileEx(MappedFile,FILE_MAP_WRITE,0,0,0,(LPVOID)GetModuleHandle(NULL));
  499. ASSERT(!p);
  500. ASSERT(SetPriorityClass(GetCurrentProcess(),IDLE_PRIORITY_CLASS));
  501. ASSERT(GetPriorityClass(GetCurrentProcess()) == IDLE_PRIORITY_CLASS);
  502. ASSERT(SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS));
  503. ASSERT(GetPriorityClass(GetCurrentProcess()) == NORMAL_PRIORITY_CLASS);
  504. ASSERT(SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS));
  505. ASSERT(GetPriorityClass(GetCurrentProcess()) == HIGH_PRIORITY_CLASS);
  506. ASSERT(SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS));
  507. ASSERT(GetPriorityClass(GetCurrentProcess()) == NORMAL_PRIORITY_CLASS);
  508. }
  509. void
  510. notifytst()
  511. {
  512. HANDLE nHandle;
  513. DWORD wret;
  514. HANDLE fFile;
  515. WIN32_FIND_DATA FindFileData;
  516. int n;
  517. BOOL b;
  518. fFile = FindFirstFile(
  519. "c:\\*.*",
  520. &FindFileData
  521. );
  522. xassert(fFile != INVALID_HANDLE_VALUE);
  523. n = 0;
  524. b = TRUE;
  525. while(b) {
  526. n++;
  527. b = FindNextFile(fFile,&FindFileData);
  528. }
  529. FindClose(fFile);
  530. printf("%d files\n",n);
  531. nHandle = FindFirstChangeNotification(
  532. "C:\\",
  533. TRUE,
  534. FILE_NOTIFY_CHANGE_NAME
  535. );
  536. xassert(nHandle != INVALID_HANDLE_VALUE);
  537. wret = WaitForSingleObject(nHandle,-1);
  538. xassert(wret == 0);
  539. fFile = FindFirstFile(
  540. "c:\\*.*",
  541. &FindFileData
  542. );
  543. xassert(fFile != INVALID_HANDLE_VALUE);
  544. n = 0;
  545. b = TRUE;
  546. while(b) {
  547. n++;
  548. b = FindNextFile(fFile,&FindFileData);
  549. }
  550. FindClose(fFile);
  551. printf("%d files\n",n);
  552. b = FindNextChangeNotification(nHandle);
  553. xassert(b);
  554. wret = WaitForSingleObject(nHandle,-1);
  555. xassert(wret == 0);
  556. fFile = FindFirstFile(
  557. "c:\\*.*",
  558. &FindFileData
  559. );
  560. xassert(fFile != INVALID_HANDLE_VALUE);
  561. n = 0;
  562. b = TRUE;
  563. while(b) {
  564. n++;
  565. b = FindNextFile(fFile,&FindFileData);
  566. }
  567. FindClose(fFile);
  568. printf("%d files\n",n);
  569. xassert(FindCloseChangeNotification(nHandle));
  570. xassert(!FindCloseChangeNotification(nHandle));
  571. }
  572. void
  573. openiftst()
  574. {
  575. HANDLE NEvent, NSemaphore, NMutex;
  576. HANDLE sEvent, sSemaphore, sMutex;
  577. NEvent = CreateEvent(NULL,TRUE,TRUE,"named-event");
  578. xassert(NEvent);
  579. xassert(GetLastError()==0);
  580. sEvent = CreateEvent(NULL,TRUE,TRUE,"named-event");
  581. xassert(sEvent);
  582. xassert(GetLastError()==ERROR_ALREADY_EXISTS);
  583. NSemaphore = CreateSemaphore(NULL,1,256,"named-event");
  584. NSemaphore = CreateSemaphore(NULL,1,256,"named-semaphore");
  585. xassert(NSemaphore);
  586. xassert(GetLastError()==0);
  587. sSemaphore = CreateSemaphore(NULL,1,256,"named-semaphore");
  588. xassert(sSemaphore);
  589. xassert(GetLastError()==ERROR_ALREADY_EXISTS);
  590. NMutex = CreateMutex(NULL,FALSE,"named-mutex");
  591. xassert(NMutex);
  592. xassert(GetLastError()==0);
  593. sMutex = CreateMutex(NULL,FALSE,"named-mutex");
  594. xassert(sMutex);
  595. xassert(GetLastError()==ERROR_ALREADY_EXISTS);
  596. }
  597. void
  598. NewRip(int flag, LPSTR str)
  599. {
  600. DWORD ExceptionArguments[3];
  601. try {
  602. ExceptionArguments[0]=strlen(str);
  603. ExceptionArguments[1]=(DWORD)str;
  604. ExceptionArguments[2]=(DWORD)flag;
  605. RaiseException(0x0eab7190,0,3,ExceptionArguments);
  606. }
  607. except(EXCEPTION_EXECUTE_HANDLER) {
  608. ;
  609. }
  610. }
  611. void
  612. Ofprompt()
  613. {
  614. HFILE h;
  615. OFSTRUCT of;
  616. SetErrorMode(SEM_NOOPENFILEERRORBOX);
  617. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT);
  618. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  619. h = OpenFile("e:\\zznt\\xt.cfg",&of,OF_PROMPT);
  620. printf("OpenFile(e:\\zznt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  621. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT | OF_CANCEL);
  622. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  623. SetErrorMode(0);
  624. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT);
  625. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  626. h = OpenFile("e:\\zznt\\xt.cfg",&of,OF_PROMPT);
  627. printf("OpenFile(e:\\zznt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  628. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT | OF_CANCEL);
  629. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  630. }
  631. void
  632. rtldevn()
  633. {
  634. UNICODE_STRING ustr;
  635. ANSI_STRING astr;
  636. CHAR buf[256];
  637. DWORD dw;
  638. printf("name -> ");
  639. scanf("%s",buf);
  640. RtlInitAnsiString(&astr,buf);
  641. RtlAnsiStringToUnicodeString(&ustr,&astr,TRUE);
  642. dw = RtlIsDosDeviceName_U(ustr.Buffer);
  643. printf("dw %x Name %s \n",dw,buf);
  644. }
  645. typedef struct _CMDSHOW {
  646. WORD wMustBe2;
  647. WORD wShowWindowValue;
  648. } CMDSHOW, *PCMDSHOW;
  649. typedef struct _LOAD_MODULE_PARAMS {
  650. LPSTR lpEnvAddress;
  651. LPSTR lpCmdLine;
  652. PCMDSHOW lpCmdShow;
  653. DWORD dwReserved;
  654. } LOAD_MODULE_PARAMS, *PLOAD_MODULE_PARAMS;
  655. typedef DWORD (*PFNWAITFORINPUTIDLE)(HANDLE hProcess, DWORD dwMilliseconds);
  656. void
  657. cptst()
  658. {
  659. CHAR buf[256];
  660. CHAR cline[256];
  661. DWORD dw;
  662. STARTUPINFO StartupInfo;
  663. PROCESS_INFORMATION ProcessInformation;
  664. LOAD_MODULE_PARAMS lmp;
  665. CHAR Environment[256];
  666. CMDSHOW cs;
  667. PFNWAITFORINPUTIDLE WaitForInputIdleRoutine;
  668. HANDLE hMod;
  669. hMod = LoadLibrary("user32");
  670. WaitForInputIdleRoutine = GetProcAddress(hMod,"WaitForInputIdle");
  671. printf("name -> ");
  672. scanf("%s",buf);
  673. RtlZeroMemory(&StartupInfo,sizeof(StartupInfo));
  674. StartupInfo.cb = sizeof(StartupInfo);
  675. SetLastError(0);
  676. CreateProcess(
  677. NULL,
  678. buf,
  679. NULL,
  680. NULL,
  681. FALSE,
  682. 0,
  683. NULL,
  684. NULL,
  685. &StartupInfo,
  686. &ProcessInformation
  687. );
  688. (WaitForInputIdleRoutine)(ProcessInformation.hProcess,10000);
  689. printf("GLE %d\n",GetLastError());
  690. SetLastError(0);
  691. printf("WINEXEC %d\n",WinExec(buf,0));
  692. SetLastError(0);
  693. lmp.lpEnvAddress = Environment;
  694. lmp.lpCmdLine = cline;
  695. lmp.dwReserved = 0;
  696. lmp.lpCmdShow = &cs;
  697. cs.wMustBe2 = 2;
  698. cs.wShowWindowValue = 3;
  699. cline[0] = strlen(buf);
  700. RtlMoveMemory(&cline[1],buf,cline[0]);
  701. cline[cline[0]+1] = 0x0d;
  702. printf("LOADMOD %d\n",LoadModule(buf,&lmp));
  703. }
  704. void
  705. spawntst()
  706. {
  707. CHAR buf[256];
  708. int i;
  709. printf("name -> ");
  710. scanf("%s",buf);
  711. i = _spawnlp(_P_WAIT,buf,"-l",NULL);
  712. }
  713. void
  714. badproctst()
  715. {
  716. CHAR buf[256];
  717. DWORD dw;
  718. STARTUPINFO StartupInfo;
  719. PROCESS_INFORMATION ProcessInformation;
  720. LOAD_MODULE_PARAMS lmp;
  721. CHAR Environment[256];
  722. CMDSHOW cs;
  723. printf("name -> ");
  724. scanf("%s",buf);
  725. RtlZeroMemory(&StartupInfo,sizeof(StartupInfo));
  726. StartupInfo.cb = sizeof(StartupInfo);
  727. SetLastError(0);
  728. CreateProcess(
  729. NULL,
  730. buf,
  731. NULL,
  732. NULL,
  733. FALSE,
  734. 0,
  735. NULL,
  736. "*",
  737. &StartupInfo,
  738. &ProcessInformation
  739. );
  740. printf("GLE %d\n",GetLastError());
  741. }
  742. void
  743. copytst()
  744. {
  745. CHAR src[256];
  746. CHAR dst[256];
  747. BOOL b;
  748. printf("src -> ");
  749. scanf("%s",src);
  750. printf("dst -> ");
  751. scanf("%s",dst);
  752. b = CopyFile(src,dst,FALSE);
  753. }
  754. void
  755. fftst()
  756. {
  757. CHAR buf[256];
  758. HANDLE fFile;
  759. WIN32_FIND_DATA FindFileData;
  760. BOOL b;
  761. printf("pattern -> ");
  762. scanf("%s",buf);
  763. fFile = FindFirstFile(
  764. buf,
  765. &FindFileData
  766. );
  767. if ( fFile == INVALID_HANDLE_VALUE ){
  768. printf("findfirst %s failed %d\n",buf,GetLastError());
  769. return;
  770. }
  771. b = TRUE;
  772. while(b) {
  773. printf("0x%08x %08d %s\n",
  774. FindFileData.dwFileAttributes,
  775. FindFileData.nFileSizeLow,
  776. FindFileData.cFileName
  777. );
  778. b = FindNextFile(fFile,&FindFileData);
  779. }
  780. FindClose(fFile);
  781. }
  782. void
  783. oftst()
  784. {
  785. OFSTRUCT OfStruct;
  786. HFILE rv;
  787. rv = OpenFile("",&OfStruct, OF_EXIST);
  788. printf("rv %d\n",rv);
  789. rv = OpenFile(NULL,&OfStruct, OF_EXIST);
  790. printf("rv %d\n",rv);
  791. rv = OpenFile(" ",&OfStruct, OF_EXIST);
  792. printf("rv %d\n",rv);
  793. }
  794. void
  795. spath()
  796. {
  797. char cbuff[512];
  798. SearchPath(
  799. "c:\\nt;c:\\xytty;c:\\nt\\system",
  800. "kernel32",
  801. ".dll",
  802. 512,
  803. cbuff,
  804. NULL
  805. );
  806. printf("%s\n",cbuff);
  807. }
  808. void
  809. muldivtst()
  810. {
  811. int answer,number,numerator,denom,result;
  812. PERFINFO PerfInfo;
  813. ULONG Index;
  814. StartBenchMark("MulDiv)",
  815. 50000,
  816. &PerfInfo);
  817. for(Index=0;Index<50000;Index++){
  818. //
  819. // answer = -24
  820. //
  821. number = -18;
  822. numerator = 96;
  823. denom = 72;
  824. answer = -24;
  825. result = MulDiv(number,numerator,denom);
  826. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  827. //
  828. // answer = -24
  829. //
  830. number = 18;
  831. numerator = -96;
  832. denom = 72;
  833. answer = -24;
  834. result = MulDiv(number,numerator,denom);
  835. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  836. //
  837. // answer = 24
  838. //
  839. number = -18;
  840. numerator = -96;
  841. denom = 72;
  842. answer = 24;
  843. result = MulDiv(number,numerator,denom);
  844. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  845. //
  846. // answer = -24
  847. //
  848. number = -18;
  849. numerator = -96;
  850. denom = -72;
  851. answer = -24;
  852. result = MulDiv(number,numerator,denom);
  853. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  854. //
  855. // answer = -24
  856. //
  857. number = -18;
  858. numerator = -96;
  859. denom = -72;
  860. answer = -24;
  861. result = MulDiv(number,numerator,denom);
  862. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  863. //
  864. // answer = 24
  865. //
  866. number = 18;
  867. numerator = -96;
  868. denom = -72;
  869. answer = 24;
  870. result = MulDiv(number,numerator,denom);
  871. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  872. //
  873. // answer = 2
  874. //
  875. number = 4;
  876. numerator = 2;
  877. denom = 5;
  878. answer = 2;
  879. result = MulDiv(number,numerator,denom);
  880. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  881. //
  882. // answer = 500
  883. //
  884. number = 100;
  885. numerator = 10;
  886. denom = 2;
  887. answer = 500;
  888. result = MulDiv(number,numerator,denom);
  889. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  890. //
  891. // answer = 3b9aca00
  892. //
  893. number = 1000000;
  894. numerator = 1000000;
  895. denom = 1000;
  896. answer = 0x3b9aca00;
  897. result = MulDiv(number,numerator,denom);
  898. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=0x%lx %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  899. }
  900. FinishBenchMark(&PerfInfo);
  901. }
  902. void
  903. dname()
  904. {
  905. UNICODE_STRING LinkName;
  906. UNICODE_STRING DeviceName;
  907. OBJECT_ATTRIBUTES Obja;
  908. HANDLE LinkHandle;
  909. NTSTATUS Status;
  910. ULONG i;
  911. PWCHAR p;
  912. WCHAR DeviceNameBuffer[MAXIMUM_FILENAME_LENGTH];
  913. RtlInitUnicodeString(&LinkName,L"\\DosDevices\\A:");
  914. p = (PWCHAR)LinkName.Buffer;
  915. p = p+12;
  916. for(i=0;i<26;i++){
  917. *p = (WCHAR)'A'+i;
  918. InitializeObjectAttributes(
  919. &Obja,
  920. &LinkName,
  921. OBJ_CASE_INSENSITIVE,
  922. NULL,
  923. NULL
  924. );
  925. Status = NtOpenSymbolicLinkObject(
  926. &LinkHandle,
  927. SYMBOLIC_LINK_QUERY,
  928. &Obja
  929. );
  930. if (NT_SUCCESS( Status )) {
  931. //
  932. // Open succeeded, Now get the link value
  933. //
  934. DeviceName.Length = 0;
  935. DeviceName.MaximumLength = sizeof(DeviceNameBuffer);
  936. DeviceName.Buffer = DeviceNameBuffer;
  937. Status = NtQuerySymbolicLinkObject(
  938. LinkHandle,
  939. &DeviceName,
  940. NULL
  941. );
  942. NtClose(LinkHandle);
  943. if ( NT_SUCCESS(Status) ) {
  944. printf("%wZ -> %wZ\n",&LinkName,&DeviceName);
  945. }
  946. }
  947. }
  948. }
  949. void
  950. mfextst()
  951. {
  952. MoveFileExW(L"C:\\tmp\\xx.xx", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  953. }
  954. CRITICAL_SECTION cs;
  955. VOID
  956. StartBounce(PVOID pThreadBlockInfo)
  957. {
  958. EnterCriticalSection(&cs);
  959. Sleep(-1);
  960. }
  961. void
  962. lockuptst()
  963. {
  964. HANDLE hThread;
  965. DWORD id;
  966. InitializeCriticalSection(&cs);
  967. hThread = CreateThread(
  968. NULL,
  969. 0,
  970. (LPTHREAD_START_ROUTINE)StartBounce,
  971. 0,
  972. 0,
  973. &id
  974. );
  975. EnterCriticalSection(&cs);
  976. Sleep(-1);
  977. }
  978. void
  979. getdisktst()
  980. {
  981. BOOL b;
  982. DWORD spc,bps,fc,tc;
  983. b = GetDiskFreeSpace(NULL,&spc,&bps,&fc,&tc);
  984. printf("GetDiskFreeSpace NULL %s\n",b ? "WORKED" : "FAILED" );
  985. b = GetDiskFreeSpace("C:\\",&spc,&bps,&fc,&tc);
  986. printf("GetDiskFreeSpace C:\\ %s\n",b ? "WORKED" : "FAILED" );
  987. b = GetDiskFreeSpace("C:\\WINNT\\",&spc,&bps,&fc,&tc);
  988. printf("GetDiskFreeSpace C:\\winnt\\ %s\n",b ? "WORKED" : "FAILED" );
  989. }
  990. void
  991. DoChoice(
  992. int Choice
  993. )
  994. {
  995. NTSTATUS Status;
  996. LONG *p;
  997. top:
  998. printf("exception test\n");
  999. printf("1 Access Violation(r)\n");
  1000. printf("2 Access Violation(w)\n");
  1001. printf("3 Array Bounds \n");
  1002. printf("4 Int Divide By Zero\n");
  1003. printf("5 Software 0x77\n");
  1004. printf("6 bigpath\n");
  1005. printf("7 set default harderror\n");
  1006. printf("8 proftests\n");
  1007. printf("9 probetests\n");
  1008. printf("10 notifytests\n");
  1009. printf("11 openif\n");
  1010. printf("12 null server\n");
  1011. printf("13 path convert\n");
  1012. printf("14 bogus ordinal\n");
  1013. printf("15 winword openfile\n");
  1014. printf("16 scroll test\n");
  1015. printf("17 winword getdrivetype\n");
  1016. printf("18 dorip\n");
  1017. printf("19 Ofprompt\n");
  1018. printf("20 rtldevn\n");
  1019. printf("21 cptst\n");
  1020. printf("22 oftst\n");
  1021. printf("23 dname\n");
  1022. printf("24 fftst\n");
  1023. printf("25 copy\n");
  1024. printf("26 badproc\n");
  1025. printf("27 loadlib\n");
  1026. printf("28 gettictst(0)\n");
  1027. printf("29 latst\n");
  1028. printf("30 gettictst(1)\n");
  1029. printf("31 spath\n");
  1030. printf("32 spawntst\n");
  1031. printf("33 muldivtst\n");
  1032. printf("34 mfextst\n");
  1033. printf("35 lockuptst\n");
  1034. printf("36 getdisktst\n");
  1035. printf("Enter Choice --> ");
  1036. scanf("%d",&Choice);
  1037. printf("Good Choice... %d\n",Choice);
  1038. switch ( Choice ) {
  1039. case 1:
  1040. SetErrorMode(SEM_NOGPFAULTERRORBOX);
  1041. printf("Good Choice... %d\n",Choice);
  1042. p = (int *)0xbaadadd0;
  1043. Choice = *p;
  1044. break;
  1045. case 2:
  1046. printf("Good Choice... %d\n",Choice);
  1047. p = (int *)0xbaadadd0;
  1048. *p = Choice;
  1049. break;
  1050. case 3:
  1051. printf("Good Choice... %d\n",Choice);
  1052. RtlRaiseStatus(STATUS_ARRAY_BOUNDS_EXCEEDED);
  1053. break;
  1054. case 4:
  1055. printf("Good Choice... %d\n",Choice);
  1056. Choice = Choice/izero;
  1057. break;
  1058. case 5:
  1059. printf("Good Choice... %d\n",Choice);
  1060. {
  1061. UINT b;
  1062. b = SetErrorMode(SEM_FAILCRITICALERRORS);
  1063. xassert(b == 0);
  1064. b = SetErrorMode(0);
  1065. xassert(b == SEM_FAILCRITICALERRORS);
  1066. }
  1067. RtlRaiseStatus(0x77);
  1068. break;
  1069. case 6:
  1070. printf("Good Choice... %d\n",Choice);
  1071. {
  1072. DWORD Bsize;
  1073. DWORD Rsize;
  1074. LPSTR Buff;
  1075. LPSTR Ruff;
  1076. DWORD Rvalue;
  1077. LPSTR whocares;
  1078. int i;
  1079. printf("Enter Size --> ");
  1080. scanf("%d",&Bsize);
  1081. printf("Enter RSize --> ");
  1082. scanf("%d",&Rsize);
  1083. Buff = LocalAlloc(0,Bsize+1);
  1084. xassert(Buff);
  1085. Ruff = LocalAlloc(0,Bsize+1);
  1086. xassert(Buff);
  1087. RtlFillMemory(Buff,Bsize,'a');
  1088. Buff[0]='c';
  1089. Buff[1]=':';
  1090. Buff[2]='\\';
  1091. Buff[Bsize+1] = '\0';
  1092. Rvalue = GetFullPathName(Buff,Rsize,Ruff,&whocares);
  1093. i = strcmp(Buff,Ruff);
  1094. printf("Bsize %d Rsize %d Rvalue %d i=%d \n",Bsize,Rsize,Rvalue,i);
  1095. }
  1096. break;
  1097. case 7:
  1098. printf("Good Choice... %d\n",Choice);
  1099. Status = NtSetDefaultHardErrorPort(NULL);
  1100. xassert(Status == STATUS_PRIVILEGE_NOT_HELD);
  1101. break;
  1102. case 8:
  1103. printf("Good Choice... %d\n",Choice);
  1104. proftst();
  1105. break;
  1106. case 9:
  1107. printf("Good Choice... %d\n",Choice);
  1108. probtst();
  1109. break;
  1110. case 10:
  1111. printf("Good Choice... %d\n",Choice);
  1112. notifytst();
  1113. break;
  1114. case 11:
  1115. printf("Good Choice... %d\n",Choice);
  1116. openiftst();
  1117. break;
  1118. case 12:
  1119. printf("Good Choice... %d\n",Choice);
  1120. NullServerSwitchTest();
  1121. break;
  1122. case 13:
  1123. PathConvertTest();
  1124. break;
  1125. case 14:
  1126. BogusOrdinalTest();
  1127. break;
  1128. case 15:
  1129. WinWordOpenFileTest();
  1130. break;
  1131. case 16:
  1132. ScrollTest();
  1133. break;
  1134. case 17:
  1135. WinWordGetDriveTypeTest();
  1136. break;
  1137. case 18:
  1138. NewRip(0,"Just a warning\n");
  1139. NewRip(1,"We Are Hosed\n");
  1140. break;
  1141. case 19:
  1142. Ofprompt();
  1143. break;
  1144. case 20:
  1145. rtldevn();
  1146. break;
  1147. case 21:
  1148. cptst();
  1149. break;
  1150. case 22:
  1151. oftst();
  1152. break;
  1153. case 23:
  1154. dname();
  1155. break;
  1156. case 24:
  1157. fftst();
  1158. break;
  1159. case 25:
  1160. copytst();
  1161. break;
  1162. case 26:
  1163. badproctst();
  1164. break;
  1165. case 27:
  1166. {
  1167. HANDLE hmods,hmodc,hmodw;
  1168. hmods = LoadLibrary("shell32");
  1169. hmodc = LoadLibrary("cmd.exe");
  1170. hmodw = LoadLibrary("winspool.drv");
  1171. FreeLibrary(hmods);
  1172. FreeLibrary(hmodc);
  1173. FreeLibrary(hmodw);
  1174. }
  1175. break;
  1176. case 28:
  1177. gettictst(0);
  1178. break;
  1179. case 29:
  1180. latst();
  1181. break;
  1182. case 30:
  1183. gettictst(1);
  1184. break;
  1185. case 31:
  1186. spath();
  1187. break;
  1188. case 32:
  1189. spawntst();
  1190. break;
  1191. case 33:
  1192. muldivtst();
  1193. break;
  1194. case 34:
  1195. mfextst();
  1196. break;
  1197. case 35:
  1198. lockuptst();
  1199. break;
  1200. case 36:
  1201. getdisktst();
  1202. break;
  1203. default:
  1204. printf( "Bad choice: %d\n", Choice );
  1205. return;
  1206. }
  1207. return;
  1208. }
  1209. //#define NtCurrentTebAsm() {PTEB Teb;_asm{mov eax,fs:[0x24]};,Teb;}
  1210. DWORD
  1211. _cdecl
  1212. main(
  1213. int argc,
  1214. char *argv[],
  1215. char *envp[]
  1216. )
  1217. {
  1218. int Choice;
  1219. char b[512];
  1220. // PTEB x;
  1221. //
  1222. // x = NtCurrentTebAsm();
  1223. GetDriveTypeW(L"A:\\");
  1224. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST));
  1225. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_HIGHEST);
  1226. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST));
  1227. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_LOWEST);
  1228. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_ABOVE_NORMAL));
  1229. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_ABOVE_NORMAL);
  1230. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_BELOW_NORMAL));
  1231. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_BELOW_NORMAL);
  1232. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL));
  1233. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_NORMAL);
  1234. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE));
  1235. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_IDLE);
  1236. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL));
  1237. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_TIME_CRITICAL);
  1238. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL));
  1239. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_NORMAL);
  1240. xassert(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST+1));
  1241. xassert(GetThreadPriority(GetCurrentProcess()) == THREAD_PRIORITY_ERROR_RETURN);
  1242. SetErrorMode(0);
  1243. GetSystemDirectory(b,512);
  1244. printf("%s\n",b);
  1245. GetWindowsDirectory(b,512);
  1246. printf("%s\n",b);
  1247. printf("TEBSIZE %d\n",sizeof(TEB));
  1248. Choice = GetModuleFileName(NULL,b,512);
  1249. if ( strlen(b) != Choice ) {
  1250. printf("BAD strlen(b) = %d Choice %d b= %s\n",strlen(b),Choice,b);
  1251. }
  1252. else {
  1253. printf("OK strlen(b) = %d Choice %d b= %s\n",strlen(b),Choice,b);
  1254. }
  1255. if (argc > 1) {
  1256. while (--argc) {
  1257. DoChoice( atoi( *++argv ) );
  1258. }
  1259. }
  1260. else {
  1261. while (TRUE) {
  1262. DoChoice( Choice );
  1263. }
  1264. }
  1265. //GetUserNameW(b,1);
  1266. return 0;
  1267. }