Leaked source code of windows server 2003
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.

1512 lines
36 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. StartBenchMark("Path Conversion Test (foo)",
  308. PATH_CONVERSION_TEST,
  309. &PerfInfo);
  310. for (Index = 0; Index < PATH_CONVERSION_TEST; Index += 1) {
  311. RtlDosPathNameToNtPathName_U(
  312. L"foo",
  313. &FileName,
  314. NULL,
  315. NULL
  316. );
  317. RtlFreeHeap(RtlProcessHeap(),FileName.Buffer);
  318. }
  319. //
  320. // Print out performance statistics.
  321. //
  322. FinishBenchMark(&PerfInfo);
  323. StartBenchMark("Path Conversion Test (e:\\nt\\windows\\foo)",
  324. PATH_CONVERSION_TEST,
  325. &PerfInfo);
  326. for (Index = 0; Index < PATH_CONVERSION_TEST; Index += 1) {
  327. RtlDosPathNameToNtPathName_U(
  328. L"e:\\nt\\windows\\foo",
  329. &FileName,
  330. NULL,
  331. NULL
  332. );
  333. RtlFreeHeap(RtlProcessHeap(),FileName.Buffer);
  334. }
  335. //
  336. // Print out performance statistics.
  337. //
  338. FinishBenchMark(&PerfInfo);
  339. return;
  340. }
  341. z(){}
  342. bar()
  343. {
  344. for (i=0;i<2*BASESPIN;i++)j = i++;
  345. z();
  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. }
  360. foo()
  361. {
  362. for (i=0;i<BASESPIN;i++)j = i++;
  363. bar();
  364. z();
  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. }
  379. proftst()
  380. {
  381. for (i=0;i<BASESPIN;i++)j = i++;
  382. foo();
  383. z();
  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. }
  398. VOID
  399. probtst(
  400. VOID
  401. )
  402. {
  403. LPVOID ReadOnly;
  404. LPVOID ReadWrite;
  405. LPVOID ReadWrite2;
  406. LPVOID NoReadWrite;
  407. LPVOID MappedReadWrite;
  408. LPVOID p;
  409. HANDLE MappedFile;
  410. LPSTR l;
  411. LPWSTR w;
  412. BOOL b;
  413. ReadOnly = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_READONLY);
  414. ASSERT(ReadOnly);
  415. ASSERT(!IsBadReadPtr(ReadOnly,1024));
  416. ASSERT(!IsBadReadPtr(ReadOnly,4096));
  417. ASSERT(IsBadReadPtr(ReadOnly,4097));
  418. ASSERT(!IsBadHugeReadPtr(ReadOnly,1024));
  419. ASSERT(!IsBadHugeReadPtr(ReadOnly,4096));
  420. ASSERT(IsBadHugeReadPtr(ReadOnly,4097));
  421. ASSERT(IsBadWritePtr(ReadOnly,1024));
  422. ASSERT(IsBadWritePtr(ReadOnly,4096));
  423. ASSERT(IsBadWritePtr(ReadOnly,4097));
  424. ASSERT(IsBadHugeWritePtr(ReadOnly,1024));
  425. ASSERT(IsBadHugeWritePtr(ReadOnly,4096));
  426. ASSERT(IsBadHugeWritePtr(ReadOnly,4097));
  427. ReadWrite = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_READWRITE);
  428. ASSERT(ReadWrite);
  429. ASSERT(!IsBadReadPtr(ReadWrite,1024));
  430. ASSERT(!IsBadReadPtr(ReadWrite,4096));
  431. ASSERT(IsBadReadPtr(ReadWrite,4097));
  432. ASSERT(!IsBadHugeReadPtr(ReadWrite,1024));
  433. ASSERT(!IsBadHugeReadPtr(ReadWrite,4096));
  434. ASSERT(IsBadHugeReadPtr(ReadWrite,4097));
  435. ASSERT(!IsBadWritePtr(ReadWrite,1024));
  436. ASSERT(!IsBadWritePtr(ReadWrite,4096));
  437. ASSERT(IsBadWritePtr(ReadWrite,4097));
  438. ASSERT(!IsBadHugeWritePtr(ReadWrite,1024));
  439. ASSERT(!IsBadHugeWritePtr(ReadWrite,4096));
  440. ASSERT(IsBadHugeWritePtr(ReadWrite,4097));
  441. NoReadWrite = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_NOACCESS);
  442. ASSERT(NoReadWrite);
  443. ASSERT(IsBadReadPtr(NoReadWrite,1024));
  444. ASSERT(IsBadReadPtr(NoReadWrite,4096));
  445. ASSERT(IsBadReadPtr(NoReadWrite,4097));
  446. ASSERT(IsBadHugeReadPtr(NoReadWrite,1024));
  447. ASSERT(IsBadHugeReadPtr(NoReadWrite,4096));
  448. ASSERT(IsBadHugeReadPtr(NoReadWrite,4097));
  449. ASSERT(IsBadWritePtr(NoReadWrite,1024));
  450. ASSERT(IsBadWritePtr(NoReadWrite,4096));
  451. ASSERT(IsBadWritePtr(NoReadWrite,4097));
  452. ASSERT(IsBadHugeWritePtr(NoReadWrite,1024));
  453. ASSERT(IsBadHugeWritePtr(NoReadWrite,4096));
  454. ASSERT(IsBadHugeWritePtr(NoReadWrite,4097));
  455. l = ReadWrite;
  456. l[4092]='a';
  457. l[4093]='b';
  458. l[4094]='c';
  459. l[4095]='\0';
  460. ASSERT(!IsBadStringPtrA(&l[4092],2));
  461. ASSERT(!IsBadStringPtrA(&l[4092],3));
  462. ASSERT(!IsBadStringPtrA(&l[4092],4));
  463. ASSERT(!IsBadStringPtrA(&l[4092],5));
  464. l[4095]='d';
  465. ASSERT(!IsBadStringPtrA(&l[4092],2));
  466. ASSERT(!IsBadStringPtrA(&l[4092],3));
  467. ASSERT(!IsBadStringPtrA(&l[4092],4));
  468. ASSERT(IsBadStringPtrA(&l[4092],5));
  469. w = ReadWrite;
  470. w[2044]=(WCHAR)'a';
  471. w[2045]=(WCHAR)'b';
  472. w[2046]=(WCHAR)'c';
  473. w[2047]=UNICODE_NULL;
  474. ASSERT(!IsBadStringPtrW(&w[2044],2));
  475. ASSERT(!IsBadStringPtrW(&w[2044],3));
  476. ASSERT(!IsBadStringPtrW(&w[2044],4));
  477. ASSERT(!IsBadStringPtrW(&w[2044],5));
  478. w[2047]=(WCHAR)'d';
  479. ASSERT(!IsBadStringPtrW(&w[2044],2));
  480. ASSERT(!IsBadStringPtrW(&w[2044],3));
  481. ASSERT(!IsBadStringPtrW(&w[2044],4));
  482. ASSERT(IsBadStringPtrW(&w[2044],5));
  483. ReadWrite2 = VirtualAlloc(NULL,4096,MEM_COMMIT,PAGE_READWRITE);
  484. ASSERT(ReadWrite2);
  485. ASSERT(VirtualLock(ReadWrite2,4096));
  486. ASSERT(VirtualUnlock(ReadWrite2,4));
  487. ASSERT(!VirtualUnlock(ReadWrite2,4));
  488. ASSERT(!VirtualLock(ReadWrite2,4097));
  489. ASSERT(!VirtualUnlock(ReadWrite2,4097));
  490. ASSERT(VirtualLock(ReadWrite2,4096));
  491. ASSERT(VirtualUnlock(ReadWrite2,4096));
  492. ASSERT(!VirtualUnlock(ReadWrite2,4096));
  493. MappedFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,8192,NULL);
  494. ASSERT(MappedFile);
  495. MappedReadWrite = MapViewOfFileEx(MappedFile,FILE_MAP_WRITE,0,0,0,(LPVOID)0x50000000);
  496. ASSERT(MappedReadWrite);
  497. p = MapViewOfFileEx(MappedFile,FILE_MAP_WRITE,0,0,0,(LPVOID)GetModuleHandle(NULL));
  498. ASSERT(!p);
  499. ASSERT(SetPriorityClass(GetCurrentProcess(),IDLE_PRIORITY_CLASS));
  500. ASSERT(GetPriorityClass(GetCurrentProcess()) == IDLE_PRIORITY_CLASS);
  501. ASSERT(SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS));
  502. ASSERT(GetPriorityClass(GetCurrentProcess()) == NORMAL_PRIORITY_CLASS);
  503. ASSERT(SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS));
  504. ASSERT(GetPriorityClass(GetCurrentProcess()) == HIGH_PRIORITY_CLASS);
  505. ASSERT(SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS));
  506. ASSERT(GetPriorityClass(GetCurrentProcess()) == NORMAL_PRIORITY_CLASS);
  507. }
  508. void
  509. notifytst()
  510. {
  511. HANDLE nHandle;
  512. DWORD wret;
  513. HANDLE fFile;
  514. WIN32_FIND_DATA FindFileData;
  515. int n;
  516. BOOL b;
  517. fFile = FindFirstFile(
  518. "c:\\*.*",
  519. &FindFileData
  520. );
  521. xassert(fFile != INVALID_HANDLE_VALUE);
  522. n = 0;
  523. b = TRUE;
  524. while(b) {
  525. n++;
  526. b = FindNextFile(fFile,&FindFileData);
  527. }
  528. FindClose(fFile);
  529. printf("%d files\n",n);
  530. nHandle = FindFirstChangeNotification(
  531. "C:\\",
  532. TRUE,
  533. FILE_NOTIFY_CHANGE_NAME
  534. );
  535. xassert(nHandle != INVALID_HANDLE_VALUE);
  536. wret = WaitForSingleObject(nHandle,-1);
  537. xassert(wret == 0);
  538. fFile = FindFirstFile(
  539. "c:\\*.*",
  540. &FindFileData
  541. );
  542. xassert(fFile != INVALID_HANDLE_VALUE);
  543. n = 0;
  544. b = TRUE;
  545. while(b) {
  546. n++;
  547. b = FindNextFile(fFile,&FindFileData);
  548. }
  549. FindClose(fFile);
  550. printf("%d files\n",n);
  551. b = FindNextChangeNotification(nHandle);
  552. xassert(b);
  553. wret = WaitForSingleObject(nHandle,-1);
  554. xassert(wret == 0);
  555. fFile = FindFirstFile(
  556. "c:\\*.*",
  557. &FindFileData
  558. );
  559. xassert(fFile != INVALID_HANDLE_VALUE);
  560. n = 0;
  561. b = TRUE;
  562. while(b) {
  563. n++;
  564. b = FindNextFile(fFile,&FindFileData);
  565. }
  566. FindClose(fFile);
  567. printf("%d files\n",n);
  568. xassert(FindCloseChangeNotification(nHandle));
  569. xassert(!FindCloseChangeNotification(nHandle));
  570. }
  571. void
  572. openiftst()
  573. {
  574. HANDLE NEvent, NSemaphore, NMutex;
  575. HANDLE sEvent, sSemaphore, sMutex;
  576. NEvent = CreateEvent(NULL,TRUE,TRUE,"named-event");
  577. xassert(NEvent);
  578. xassert(GetLastError()==0);
  579. sEvent = CreateEvent(NULL,TRUE,TRUE,"named-event");
  580. xassert(sEvent);
  581. xassert(GetLastError()==ERROR_ALREADY_EXISTS);
  582. NSemaphore = CreateSemaphore(NULL,1,256,"named-event");
  583. NSemaphore = CreateSemaphore(NULL,1,256,"named-semaphore");
  584. xassert(NSemaphore);
  585. xassert(GetLastError()==0);
  586. sSemaphore = CreateSemaphore(NULL,1,256,"named-semaphore");
  587. xassert(sSemaphore);
  588. xassert(GetLastError()==ERROR_ALREADY_EXISTS);
  589. NMutex = CreateMutex(NULL,FALSE,"named-mutex");
  590. xassert(NMutex);
  591. xassert(GetLastError()==0);
  592. sMutex = CreateMutex(NULL,FALSE,"named-mutex");
  593. xassert(sMutex);
  594. xassert(GetLastError()==ERROR_ALREADY_EXISTS);
  595. }
  596. void
  597. NewRip(int flag, LPSTR str)
  598. {
  599. DWORD ExceptionArguments[3];
  600. try {
  601. ExceptionArguments[0]=strlen(str);
  602. ExceptionArguments[1]=(DWORD)str;
  603. ExceptionArguments[2]=(DWORD)flag;
  604. RaiseException(0x0eab7190,0,3,ExceptionArguments);
  605. }
  606. except(EXCEPTION_EXECUTE_HANDLER) {
  607. ;
  608. }
  609. }
  610. void
  611. Ofprompt()
  612. {
  613. HFILE h;
  614. OFSTRUCT of;
  615. SetErrorMode(SEM_NOOPENFILEERRORBOX);
  616. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT);
  617. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  618. h = OpenFile("e:\\zznt\\xt.cfg",&of,OF_PROMPT);
  619. printf("OpenFile(e:\\zznt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  620. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT | OF_CANCEL);
  621. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  622. SetErrorMode(0);
  623. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT);
  624. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  625. h = OpenFile("e:\\zznt\\xt.cfg",&of,OF_PROMPT);
  626. printf("OpenFile(e:\\zznt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  627. h = OpenFile("e:\\nt\\xt.cfg",&of,OF_PROMPT | OF_CANCEL);
  628. printf("OpenFile(e:\\nt\\xt.cfg) h = %lx, GLE = %d\n",h,GetLastError());
  629. }
  630. void
  631. rtldevn()
  632. {
  633. UNICODE_STRING ustr;
  634. ANSI_STRING astr;
  635. CHAR buf[256];
  636. DWORD dw;
  637. printf("name -> ");
  638. scanf("%s",buf);
  639. RtlInitAnsiString(&astr,buf);
  640. RtlAnsiStringToUnicodeString(&ustr,&astr,TRUE);
  641. dw = RtlIsDosDeviceName_U(ustr.Buffer);
  642. printf("dw %x Name %s \n",dw,buf);
  643. }
  644. typedef struct _CMDSHOW {
  645. WORD wMustBe2;
  646. WORD wShowWindowValue;
  647. } CMDSHOW, *PCMDSHOW;
  648. typedef struct _LOAD_MODULE_PARAMS {
  649. LPSTR lpEnvAddress;
  650. LPSTR lpCmdLine;
  651. PCMDSHOW lpCmdShow;
  652. DWORD dwReserved;
  653. } LOAD_MODULE_PARAMS, *PLOAD_MODULE_PARAMS;
  654. typedef DWORD (*PFNWAITFORINPUTIDLE)(HANDLE hProcess, DWORD dwMilliseconds);
  655. void
  656. cptst()
  657. {
  658. CHAR buf[256];
  659. CHAR cline[256];
  660. DWORD dw;
  661. STARTUPINFO StartupInfo;
  662. PROCESS_INFORMATION ProcessInformation;
  663. LOAD_MODULE_PARAMS lmp;
  664. CHAR Environment[256];
  665. CMDSHOW cs;
  666. PFNWAITFORINPUTIDLE WaitForInputIdleRoutine;
  667. HANDLE hMod;
  668. hMod = LoadLibrary("user32");
  669. WaitForInputIdleRoutine = GetProcAddress(hMod,"WaitForInputIdle");
  670. printf("name -> ");
  671. scanf("%s",buf);
  672. RtlZeroMemory(&StartupInfo,sizeof(StartupInfo));
  673. StartupInfo.cb = sizeof(StartupInfo);
  674. SetLastError(0);
  675. CreateProcess(
  676. NULL,
  677. buf,
  678. NULL,
  679. NULL,
  680. FALSE,
  681. 0,
  682. NULL,
  683. NULL,
  684. &StartupInfo,
  685. &ProcessInformation
  686. );
  687. (WaitForInputIdleRoutine)(ProcessInformation.hProcess,10000);
  688. printf("GLE %d\n",GetLastError());
  689. SetLastError(0);
  690. printf("WINEXEC %d\n",WinExec(buf,0));
  691. SetLastError(0);
  692. lmp.lpEnvAddress = Environment;
  693. lmp.lpCmdLine = cline;
  694. lmp.dwReserved = 0;
  695. lmp.lpCmdShow = &cs;
  696. cs.wMustBe2 = 2;
  697. cs.wShowWindowValue = 3;
  698. cline[0] = strlen(buf);
  699. RtlMoveMemory(&cline[1],buf,cline[0]);
  700. cline[cline[0]+1] = 0x0d;
  701. printf("LOADMOD %d\n",LoadModule(buf,&lmp));
  702. }
  703. void
  704. spawntst()
  705. {
  706. CHAR buf[256];
  707. int i;
  708. printf("name -> ");
  709. scanf("%s",buf);
  710. i = _spawnlp(_P_WAIT,buf,"-l",NULL);
  711. }
  712. void
  713. badproctst()
  714. {
  715. CHAR buf[256];
  716. DWORD dw;
  717. STARTUPINFO StartupInfo;
  718. PROCESS_INFORMATION ProcessInformation;
  719. LOAD_MODULE_PARAMS lmp;
  720. CHAR Environment[256];
  721. CMDSHOW cs;
  722. printf("name -> ");
  723. scanf("%s",buf);
  724. RtlZeroMemory(&StartupInfo,sizeof(StartupInfo));
  725. StartupInfo.cb = sizeof(StartupInfo);
  726. SetLastError(0);
  727. CreateProcess(
  728. NULL,
  729. buf,
  730. NULL,
  731. NULL,
  732. FALSE,
  733. 0,
  734. NULL,
  735. "*",
  736. &StartupInfo,
  737. &ProcessInformation
  738. );
  739. printf("GLE %d\n",GetLastError());
  740. }
  741. void
  742. copytst()
  743. {
  744. CHAR src[256];
  745. CHAR dst[256];
  746. BOOL b;
  747. printf("src -> ");
  748. scanf("%s",src);
  749. printf("dst -> ");
  750. scanf("%s",dst);
  751. b = CopyFile(src,dst,FALSE);
  752. }
  753. void
  754. fftst()
  755. {
  756. CHAR buf[256];
  757. HANDLE fFile;
  758. WIN32_FIND_DATA FindFileData;
  759. BOOL b;
  760. printf("pattern -> ");
  761. scanf("%s",buf);
  762. fFile = FindFirstFile(
  763. buf,
  764. &FindFileData
  765. );
  766. if ( fFile == INVALID_HANDLE_VALUE ){
  767. printf("findfirst %s failed %d\n",buf,GetLastError());
  768. return;
  769. }
  770. b = TRUE;
  771. while(b) {
  772. printf("0x%08x %08d %s\n",
  773. FindFileData.dwFileAttributes,
  774. FindFileData.nFileSizeLow,
  775. FindFileData.cFileName
  776. );
  777. b = FindNextFile(fFile,&FindFileData);
  778. }
  779. FindClose(fFile);
  780. }
  781. void
  782. oftst()
  783. {
  784. OFSTRUCT OfStruct;
  785. HFILE rv;
  786. rv = OpenFile("",&OfStruct, OF_EXIST);
  787. printf("rv %d\n",rv);
  788. rv = OpenFile(NULL,&OfStruct, OF_EXIST);
  789. printf("rv %d\n",rv);
  790. rv = OpenFile(" ",&OfStruct, OF_EXIST);
  791. printf("rv %d\n",rv);
  792. }
  793. void
  794. spath()
  795. {
  796. char cbuff[512];
  797. SearchPath(
  798. "c:\\nt;c:\\xytty;c:\\nt\\system",
  799. "kernel32",
  800. ".dll",
  801. 512,
  802. cbuff,
  803. NULL
  804. );
  805. printf("%s\n",cbuff);
  806. }
  807. void
  808. muldivtst()
  809. {
  810. int answer,number,numerator,denom,result;
  811. PERFINFO PerfInfo;
  812. ULONG Index;
  813. StartBenchMark("MulDiv)",
  814. 50000,
  815. &PerfInfo);
  816. for(Index=0;Index<50000;Index++){
  817. //
  818. // answer = -24
  819. //
  820. number = -18;
  821. numerator = 96;
  822. denom = 72;
  823. answer = -24;
  824. result = MulDiv(number,numerator,denom);
  825. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  826. //
  827. // answer = -24
  828. //
  829. number = 18;
  830. numerator = -96;
  831. denom = 72;
  832. answer = -24;
  833. result = MulDiv(number,numerator,denom);
  834. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  835. //
  836. // answer = 24
  837. //
  838. number = -18;
  839. numerator = -96;
  840. denom = 72;
  841. answer = 24;
  842. result = MulDiv(number,numerator,denom);
  843. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  844. //
  845. // answer = -24
  846. //
  847. number = -18;
  848. numerator = -96;
  849. denom = -72;
  850. answer = -24;
  851. result = MulDiv(number,numerator,denom);
  852. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  853. //
  854. // answer = -24
  855. //
  856. number = -18;
  857. numerator = -96;
  858. denom = -72;
  859. answer = -24;
  860. result = MulDiv(number,numerator,denom);
  861. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  862. //
  863. // answer = 24
  864. //
  865. number = 18;
  866. numerator = -96;
  867. denom = -72;
  868. answer = 24;
  869. result = MulDiv(number,numerator,denom);
  870. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  871. //
  872. // answer = 2
  873. //
  874. number = 4;
  875. numerator = 2;
  876. denom = 5;
  877. answer = 2;
  878. result = MulDiv(number,numerator,denom);
  879. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  880. //
  881. // answer = 500
  882. //
  883. number = 100;
  884. numerator = 10;
  885. denom = 2;
  886. answer = 500;
  887. result = MulDiv(number,numerator,denom);
  888. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=%ld %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  889. //
  890. // answer = 3b9aca00
  891. //
  892. number = 1000000;
  893. numerator = 1000000;
  894. denom = 1000;
  895. answer = 0x3b9aca00;
  896. result = MulDiv(number,numerator,denom);
  897. if ( answer != result ) printf("MulDiv(%ld,%ld,%ld)=0x%lx %s\n",number,numerator,denom,result,answer == result ? "SUCCESS" : "FAILED");
  898. }
  899. FinishBenchMark(&PerfInfo);
  900. }
  901. void
  902. dname()
  903. {
  904. UNICODE_STRING LinkName;
  905. UNICODE_STRING DeviceName;
  906. OBJECT_ATTRIBUTES Obja;
  907. HANDLE LinkHandle;
  908. NTSTATUS Status;
  909. ULONG i;
  910. PWCHAR p;
  911. WCHAR DeviceNameBuffer[MAXIMUM_FILENAME_LENGTH];
  912. RtlInitUnicodeString(&LinkName,L"\\DosDevices\\A:");
  913. p = (PWCHAR)LinkName.Buffer;
  914. p = p+12;
  915. for(i=0;i<26;i++){
  916. *p = (WCHAR)'A'+i;
  917. InitializeObjectAttributes(
  918. &Obja,
  919. &LinkName,
  920. OBJ_CASE_INSENSITIVE,
  921. NULL,
  922. NULL
  923. );
  924. Status = NtOpenSymbolicLinkObject(
  925. &LinkHandle,
  926. SYMBOLIC_LINK_QUERY,
  927. &Obja
  928. );
  929. if (NT_SUCCESS( Status )) {
  930. //
  931. // Open succeeded, Now get the link value
  932. //
  933. DeviceName.Length = 0;
  934. DeviceName.MaximumLength = sizeof(DeviceNameBuffer);
  935. DeviceName.Buffer = DeviceNameBuffer;
  936. Status = NtQuerySymbolicLinkObject(
  937. LinkHandle,
  938. &DeviceName,
  939. NULL
  940. );
  941. NtClose(LinkHandle);
  942. if ( NT_SUCCESS(Status) ) {
  943. printf("%wZ -> %wZ\n",&LinkName,&DeviceName);
  944. }
  945. }
  946. }
  947. }
  948. void
  949. mfextst()
  950. {
  951. MoveFileExW(L"C:\\tmp\\xx.xx", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  952. }
  953. CRITICAL_SECTION cs;
  954. VOID
  955. StartBounce(PVOID pThreadBlockInfo)
  956. {
  957. EnterCriticalSection(&cs);
  958. Sleep(-1);
  959. }
  960. void
  961. lockuptst()
  962. {
  963. HANDLE hThread;
  964. DWORD id;
  965. InitializeCriticalSection(&cs);
  966. hThread = CreateThread(
  967. NULL,
  968. 0,
  969. (LPTHREAD_START_ROUTINE)StartBounce,
  970. 0,
  971. 0,
  972. &id
  973. );
  974. EnterCriticalSection(&cs);
  975. Sleep(-1);
  976. }
  977. void
  978. getdisktst()
  979. {
  980. BOOL b;
  981. DWORD spc,bps,fc,tc;
  982. b = GetDiskFreeSpace(NULL,&spc,&bps,&fc,&tc);
  983. printf("GetDiskFreeSpace NULL %s\n",b ? "WORKED" : "FAILED" );
  984. b = GetDiskFreeSpace("C:\\",&spc,&bps,&fc,&tc);
  985. printf("GetDiskFreeSpace C:\\ %s\n",b ? "WORKED" : "FAILED" );
  986. b = GetDiskFreeSpace("C:\\WINNT\\",&spc,&bps,&fc,&tc);
  987. printf("GetDiskFreeSpace C:\\winnt\\ %s\n",b ? "WORKED" : "FAILED" );
  988. }
  989. void
  990. DoChoice(
  991. int Choice
  992. )
  993. {
  994. NTSTATUS Status;
  995. LONG *p;
  996. top:
  997. printf("exception test\n");
  998. printf("1 Access Violation(r)\n");
  999. printf("2 Access Violation(w)\n");
  1000. printf("3 Array Bounds \n");
  1001. printf("4 Int Divide By Zero\n");
  1002. printf("5 Software 0x77\n");
  1003. printf("6 bigpath\n");
  1004. printf("7 set default harderror\n");
  1005. printf("8 proftests\n");
  1006. printf("9 probetests\n");
  1007. printf("10 notifytests\n");
  1008. printf("11 openif\n");
  1009. printf("12 null server\n");
  1010. printf("13 path convert\n");
  1011. printf("14 bogus ordinal\n");
  1012. printf("15 winword openfile\n");
  1013. printf("16 scroll test\n");
  1014. printf("17 winword getdrivetype\n");
  1015. printf("18 dorip\n");
  1016. printf("19 Ofprompt\n");
  1017. printf("20 rtldevn\n");
  1018. printf("21 cptst\n");
  1019. printf("22 oftst\n");
  1020. printf("23 dname\n");
  1021. printf("24 fftst\n");
  1022. printf("25 copy\n");
  1023. printf("26 badproc\n");
  1024. printf("27 loadlib\n");
  1025. printf("28 gettictst(0)\n");
  1026. printf("29 latst\n");
  1027. printf("30 gettictst(1)\n");
  1028. printf("31 spath\n");
  1029. printf("32 spawntst\n");
  1030. printf("33 muldivtst\n");
  1031. printf("34 mfextst\n");
  1032. printf("35 lockuptst\n");
  1033. printf("36 getdisktst\n");
  1034. printf("Enter Choice --> ");
  1035. scanf("%d",&Choice);
  1036. printf("Good Choice... %d\n",Choice);
  1037. switch ( Choice ) {
  1038. case 1:
  1039. SetErrorMode(SEM_NOGPFAULTERRORBOX);
  1040. printf("Good Choice... %d\n",Choice);
  1041. p = (int *)0xbaadadd0;
  1042. Choice = *p;
  1043. break;
  1044. case 2:
  1045. printf("Good Choice... %d\n",Choice);
  1046. p = (int *)0xbaadadd0;
  1047. *p = Choice;
  1048. break;
  1049. case 3:
  1050. printf("Good Choice... %d\n",Choice);
  1051. RtlRaiseStatus(STATUS_ARRAY_BOUNDS_EXCEEDED);
  1052. break;
  1053. case 4:
  1054. printf("Good Choice... %d\n",Choice);
  1055. Choice = Choice/izero;
  1056. break;
  1057. case 5:
  1058. printf("Good Choice... %d\n",Choice);
  1059. {
  1060. UINT b;
  1061. b = SetErrorMode(SEM_FAILCRITICALERRORS);
  1062. xassert(b == 0);
  1063. b = SetErrorMode(0);
  1064. xassert(b == SEM_FAILCRITICALERRORS);
  1065. }
  1066. RtlRaiseStatus(0x77);
  1067. break;
  1068. case 6:
  1069. printf("Good Choice... %d\n",Choice);
  1070. {
  1071. DWORD Bsize;
  1072. DWORD Rsize;
  1073. LPSTR Buff;
  1074. LPSTR Ruff;
  1075. DWORD Rvalue;
  1076. LPSTR whocares;
  1077. int i;
  1078. printf("Enter Size --> ");
  1079. scanf("%d",&Bsize);
  1080. printf("Enter RSize --> ");
  1081. scanf("%d",&Rsize);
  1082. Buff = LocalAlloc(0,Bsize+1);
  1083. xassert(Buff);
  1084. Ruff = LocalAlloc(0,Bsize+1);
  1085. xassert(Buff);
  1086. RtlFillMemory(Buff,Bsize,'a');
  1087. Buff[0]='c';
  1088. Buff[1]=':';
  1089. Buff[2]='\\';
  1090. Buff[Bsize+1] = '\0';
  1091. Rvalue = GetFullPathName(Buff,Rsize,Ruff,&whocares);
  1092. i = strcmp(Buff,Ruff);
  1093. printf("Bsize %d Rsize %d Rvalue %d i=%d \n",Bsize,Rsize,Rvalue,i);
  1094. }
  1095. break;
  1096. case 7:
  1097. printf("Good Choice... %d\n",Choice);
  1098. Status = NtSetDefaultHardErrorPort(NULL);
  1099. xassert(Status == STATUS_PRIVILEGE_NOT_HELD);
  1100. break;
  1101. case 8:
  1102. printf("Good Choice... %d\n",Choice);
  1103. proftst();
  1104. break;
  1105. case 9:
  1106. printf("Good Choice... %d\n",Choice);
  1107. probtst();
  1108. break;
  1109. case 10:
  1110. printf("Good Choice... %d\n",Choice);
  1111. notifytst();
  1112. break;
  1113. case 11:
  1114. printf("Good Choice... %d\n",Choice);
  1115. openiftst();
  1116. break;
  1117. case 12:
  1118. printf("Good Choice... %d\n",Choice);
  1119. NullServerSwitchTest();
  1120. break;
  1121. case 13:
  1122. PathConvertTest();
  1123. break;
  1124. case 14:
  1125. BogusOrdinalTest();
  1126. break;
  1127. case 15:
  1128. WinWordOpenFileTest();
  1129. break;
  1130. case 16:
  1131. ScrollTest();
  1132. break;
  1133. case 17:
  1134. WinWordGetDriveTypeTest();
  1135. break;
  1136. case 18:
  1137. NewRip(0,"Just a warning\n");
  1138. NewRip(1,"We Are Hosed\n");
  1139. break;
  1140. case 19:
  1141. Ofprompt();
  1142. break;
  1143. case 20:
  1144. rtldevn();
  1145. break;
  1146. case 21:
  1147. cptst();
  1148. break;
  1149. case 22:
  1150. oftst();
  1151. break;
  1152. case 23:
  1153. dname();
  1154. break;
  1155. case 24:
  1156. fftst();
  1157. break;
  1158. case 25:
  1159. copytst();
  1160. break;
  1161. case 26:
  1162. badproctst();
  1163. break;
  1164. case 27:
  1165. {
  1166. HANDLE hmods,hmodc,hmodw;
  1167. hmods = LoadLibrary("shell32");
  1168. hmodc = LoadLibrary("cmd.exe");
  1169. hmodw = LoadLibrary("winspool.drv");
  1170. FreeLibrary(hmods);
  1171. FreeLibrary(hmodc);
  1172. FreeLibrary(hmodw);
  1173. }
  1174. break;
  1175. case 28:
  1176. gettictst(0);
  1177. break;
  1178. case 29:
  1179. latst();
  1180. break;
  1181. case 30:
  1182. gettictst(1);
  1183. break;
  1184. case 31:
  1185. spath();
  1186. break;
  1187. case 32:
  1188. spawntst();
  1189. break;
  1190. case 33:
  1191. muldivtst();
  1192. break;
  1193. case 34:
  1194. mfextst();
  1195. break;
  1196. case 35:
  1197. lockuptst();
  1198. break;
  1199. case 36:
  1200. getdisktst();
  1201. break;
  1202. default:
  1203. printf( "Bad choice: %d\n", Choice );
  1204. return;
  1205. }
  1206. return;
  1207. }
  1208. //#define NtCurrentTebAsm() {PTEB Teb;_asm{mov eax,fs:[0x24]};,Teb;}
  1209. DWORD
  1210. _cdecl
  1211. main(
  1212. int argc,
  1213. char *argv[],
  1214. char *envp[]
  1215. )
  1216. {
  1217. int Choice;
  1218. char b[512];
  1219. // PTEB x;
  1220. //
  1221. // x = NtCurrentTebAsm();
  1222. GetDriveTypeW(L"A:\\");
  1223. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST));
  1224. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_HIGHEST);
  1225. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST));
  1226. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_LOWEST);
  1227. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_ABOVE_NORMAL));
  1228. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_ABOVE_NORMAL);
  1229. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_BELOW_NORMAL));
  1230. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_BELOW_NORMAL);
  1231. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL));
  1232. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_NORMAL);
  1233. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE));
  1234. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_IDLE);
  1235. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL));
  1236. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_TIME_CRITICAL);
  1237. xassert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL));
  1238. xassert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_NORMAL);
  1239. xassert(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST+1));
  1240. xassert(GetThreadPriority(GetCurrentProcess()) == THREAD_PRIORITY_ERROR_RETURN);
  1241. SetErrorMode(0);
  1242. GetSystemDirectory(b,512);
  1243. printf("%s\n",b);
  1244. GetWindowsDirectory(b,512);
  1245. printf("%s\n",b);
  1246. printf("TEBSIZE %d\n",sizeof(TEB));
  1247. Choice = GetModuleFileName(NULL,b,512);
  1248. if ( strlen(b) != Choice ) {
  1249. printf("BAD strlen(b) = %d Choice %d b= %s\n",strlen(b),Choice,b);
  1250. }
  1251. else {
  1252. printf("OK strlen(b) = %d Choice %d b= %s\n",strlen(b),Choice,b);
  1253. }
  1254. if (argc > 1) {
  1255. while (--argc) {
  1256. DoChoice( atoi( *++argv ) );
  1257. }
  1258. }
  1259. else {
  1260. while (TRUE) {
  1261. DoChoice( Choice );
  1262. }
  1263. }
  1264. //GetUserNameW(b,1);
  1265. return 0;
  1266. }