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.

686 lines
22 KiB

  1. //
  2. // Program to test boundry conditions of APIs which take a string buffer.
  3. // Conditions tested are strlen-1, strlen, and strlen+1
  4. //
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <ctype.h>
  9. #include <wchar.h>
  10. //
  11. // Define these to match your machine. If these are not set properly, its
  12. // very likely the tests will pass when they didn't deserve to.
  13. //
  14. // List of all logical drives
  15. #define LOGICAL_DRIVES "a:\\\0c:\\\0"
  16. #define LOGICAL_DRIVES_W L"a:\\\0c:\\\0"
  17. #define LEN_LOGICAL_DRIVES 8
  18. #define SYSTEM_DIR "c:\\winnt\\system32" // Where is system dir
  19. #define SYSTEM_DIR_W L"c:\\winnt\\system32" // Where is system dir
  20. #define WINDOWS_DIR "c:\\winnt" // Where is windows dir
  21. #define WINDOWS_DIR_W L"c:\\winnt" // Where is windows dir
  22. #define TEMP_DIRA "c:\\tmp" // For GetTempPath, env var tmp or temp
  23. #define TEMP_DIR_WA L"c:\\tmp" // For GetTempPath, env var tmp or temp
  24. #define TEMP_DIRB "c:\\tmp\\" // For GetTempPath, env var tmp or temp
  25. #define TEMP_DIR_WB L"c:\\tmp\\" // For GetTempPath, env var tmp or temp
  26. #define TEMP_DIRC "c:\\" // For GetTempPath, env var tmp or temp
  27. #define TEMP_DIR_WC L"c:\\" // For GetTempPath, env var tmp or temp
  28. #define VOLUME_NAME "MARKLTST433" // Name of volume where c: partition is
  29. #define VOLUME_NAME_W L"MARKLTST433" // Name of volume where c: partition is
  30. #define FILE_SYSTEM_NAME "FAT" // Name of file system on c: partition
  31. #define FILE_SYSTEM_NAME_W L"FAT" // Name of file system on c: partition
  32. // { FAT, HPFS, NTFS }
  33. //
  34. // Global vars, constants and prototypes
  35. //
  36. #define SIGNATURE 0xf
  37. #define SIGNATURE_W 0xaaff
  38. #define SIZE_BUFF 128
  39. void init_buff();
  40. void init_buffw();
  41. void check(DWORD retcode, DWORD size_passed, int expected_ret,BOOL shouldxfer);
  42. void checkw(DWORD retcode, DWORD size_passed, int expected_ret,BOOL shouldxfer);
  43. char buff[SIZE_BUFF], *cur_test;
  44. wchar_t buffw[SIZE_BUFF];
  45. LPSTR exp_val;
  46. LPWSTR exp_valw;
  47. //
  48. // main
  49. //
  50. void _cdecl main(void)
  51. {
  52. int exp_len;
  53. int wexp_len;
  54. LPSTR lpJunk;
  55. LPWSTR lpwJunk;
  56. BOOL bRet;
  57. //
  58. // GetSystemDirectory
  59. //
  60. cur_test = "GetSystemDirectory";
  61. exp_len = strlen(SYSTEM_DIR);
  62. exp_val = SYSTEM_DIR;
  63. exp_valw = SYSTEM_DIR_W;
  64. printf("\nGetSystemDirectory: Expected string is <%s>\n", SYSTEM_DIR);
  65. init_buff();
  66. check(GetSystemDirectory(buff, exp_len-1), exp_len-1, exp_len+1,FALSE);
  67. init_buff();
  68. check(GetSystemDirectory(buff, exp_len), exp_len, exp_len+1,FALSE);
  69. init_buff();
  70. check(GetSystemDirectory(buff, exp_len+1), exp_len+1, exp_len,TRUE);
  71. init_buffw();
  72. checkw(GetSystemDirectoryW(buffw, exp_len-1), exp_len-1, exp_len+1,FALSE);
  73. init_buffw();
  74. checkw(GetSystemDirectoryW(buffw, exp_len), exp_len, exp_len+1,FALSE);
  75. init_buffw();
  76. checkw(GetSystemDirectoryW(buffw, exp_len+1), exp_len+1, exp_len,TRUE);
  77. //
  78. // GetWindowsDirectory
  79. //
  80. cur_test = "GetWindowsDirectory";
  81. exp_len = strlen(WINDOWS_DIR);
  82. exp_val = WINDOWS_DIR;
  83. exp_valw = WINDOWS_DIR_W;
  84. printf("\nGetWindowsDirectory: Expected string is <%s>\n", WINDOWS_DIR);
  85. init_buff();
  86. check(GetWindowsDirectory(buff, exp_len-1), exp_len-1, exp_len+1,FALSE);
  87. init_buff();
  88. check(GetWindowsDirectory(buff, exp_len), exp_len, exp_len+1,FALSE);
  89. init_buff();
  90. check(GetWindowsDirectory(buff, exp_len+1), exp_len+1, exp_len,TRUE);
  91. init_buffw();
  92. checkw(GetWindowsDirectoryW(buffw, exp_len-1), exp_len-1, exp_len+1,FALSE);
  93. init_buffw();
  94. checkw(GetWindowsDirectoryW(buffw, exp_len), exp_len, exp_len+1,FALSE);
  95. init_buffw();
  96. checkw(GetWindowsDirectoryW(buffw, exp_len+1), exp_len+1, exp_len,TRUE);
  97. //
  98. // GetLogicalDriveStrings
  99. //
  100. cur_test = "GetLogicalDriveStrings";
  101. exp_len = LEN_LOGICAL_DRIVES;
  102. exp_val = LOGICAL_DRIVES;
  103. exp_valw = LOGICAL_DRIVES_W;
  104. printf("\nGetLogicalDriveStrings: Expected string is <%s>\n",
  105. LOGICAL_DRIVES);
  106. init_buff();
  107. check(GetLogicalDriveStrings(exp_len-1, buff), exp_len-1, exp_len+1,FALSE);
  108. init_buff();
  109. check(GetLogicalDriveStrings(exp_len, buff), exp_len, exp_len+1,FALSE);
  110. init_buff();
  111. check(GetLogicalDriveStrings(exp_len+1, buff), exp_len+1, exp_len,TRUE);
  112. init_buffw();
  113. checkw(GetLogicalDriveStringsW(exp_len-1, buffw), exp_len-1, exp_len+1,FALSE);
  114. init_buffw();
  115. checkw(GetLogicalDriveStringsW(exp_len, buffw), exp_len, exp_len+1,FALSE);
  116. init_buffw();
  117. checkw(GetLogicalDriveStringsW(exp_len+1, buffw), exp_len+1, exp_len,TRUE);
  118. //
  119. // GetVolumeInformation: Be sure that does not stomp on VolumeName buffer,
  120. // and be sure it returns FALSE when the volume name would not fit into
  121. // the provided buffer
  122. //
  123. cur_test = "GetVolumeInformation 1";
  124. exp_len = strlen(VOLUME_NAME);
  125. exp_val = VOLUME_NAME;
  126. exp_valw = VOLUME_NAME_W;
  127. printf("\nGetVolumeInformation 1: Expected string is <%s>\n", VOLUME_NAME);
  128. init_buff();
  129. bRet = GetVolumeInformation("c:\\",
  130. buff, // volume name buffer
  131. exp_len-1,
  132. NULL, NULL, NULL, NULL, 0);
  133. check(bRet, exp_len-1, FALSE,FALSE);
  134. init_buff();
  135. bRet = GetVolumeInformation("c:\\",
  136. buff, // volume name buffer
  137. exp_len,
  138. NULL, NULL, NULL, NULL, 0);
  139. check(bRet, exp_len, FALSE,FALSE);
  140. init_buff();
  141. bRet = GetVolumeInformation("c:\\",
  142. buff, // volume name buffer
  143. exp_len+1,
  144. NULL, NULL, NULL, NULL, 0);
  145. check(bRet, exp_len+1, TRUE,TRUE);
  146. init_buffw();
  147. bRet = GetVolumeInformationW(L"c:\\",
  148. buffw, // volume name buffer
  149. exp_len-1,
  150. NULL, NULL, NULL, NULL, 0);
  151. checkw(bRet, exp_len-1, FALSE,FALSE);
  152. init_buffw();
  153. bRet = GetVolumeInformationW(L"c:\\",
  154. buffw, // volume name buffer
  155. exp_len,
  156. NULL, NULL, NULL, NULL, 0);
  157. checkw(bRet, exp_len, FALSE,FALSE);
  158. init_buffw();
  159. bRet = GetVolumeInformationW(L"c:\\",
  160. buffw, // volume name buffer
  161. exp_len+1,
  162. NULL, NULL, NULL, NULL, 0);
  163. checkw(bRet, exp_len+1, TRUE,TRUE);
  164. //
  165. // GetVolumeInformation: Be sure that does not stomp on the File system
  166. // name buffer this time, and be sure returns FALSE when not enough room.
  167. //
  168. cur_test = "GetVolumeInformation 2";
  169. exp_len = strlen(FILE_SYSTEM_NAME);
  170. exp_val = FILE_SYSTEM_NAME;
  171. exp_valw = FILE_SYSTEM_NAME_W;
  172. printf("\nGetVolumeInformation 2: Expected string is <%s>\n",
  173. FILE_SYSTEM_NAME);
  174. init_buff();
  175. bRet = GetVolumeInformation("c:\\",
  176. NULL, 0, NULL, NULL, NULL,
  177. buff, // file system name buffer, ex: FAT
  178. exp_len-1);
  179. check(bRet, exp_len-1, FALSE,FALSE);
  180. init_buff();
  181. bRet = GetVolumeInformation("c:\\",
  182. NULL, 0, NULL, NULL, NULL,
  183. buff, // file system name buffer, ex: FAT
  184. exp_len);
  185. check(bRet, exp_len, FALSE,FALSE);
  186. init_buff();
  187. bRet = GetVolumeInformation("c:\\",
  188. NULL, 0, NULL, NULL, NULL,
  189. buff, // file system name buffer, ex: FAT
  190. exp_len+1);
  191. check(bRet, exp_len+1, TRUE,TRUE);
  192. init_buffw();
  193. bRet = GetVolumeInformationW(L"c:\\",
  194. NULL, 0, NULL, NULL, NULL,
  195. buffw, // file system name buffer, ex: FAT
  196. exp_len-1);
  197. checkw(bRet, exp_len-1, FALSE,FALSE);
  198. init_buffw();
  199. bRet = GetVolumeInformationW(L"c:\\",
  200. NULL, 0, NULL, NULL, NULL,
  201. buffw, // file system name buffer, ex: FAT
  202. exp_len);
  203. checkw(bRet, exp_len, FALSE,FALSE);
  204. init_buffw();
  205. bRet = GetVolumeInformationW(L"c:\\",
  206. NULL, 0, NULL, NULL, NULL,
  207. buffw, // file system name buffer, ex: FAT
  208. exp_len+1);
  209. checkw(bRet, exp_len+1, TRUE,TRUE);
  210. //
  211. // GetEnvironmentVariable: set variable JUNK=junk and check
  212. //
  213. cur_test = "GetEnvironmentVariable";
  214. exp_val = "junk";
  215. exp_valw = L"junk";
  216. printf("\nGetEnvironmentVariable: Expected string is <%s>\n", "junk");
  217. if ( ! SetEnvironmentVariable("JUNK", "junk") ) {
  218. printf("Error setting environment variable\n");
  219. exit(1);
  220. }
  221. init_buff();
  222. check(GetEnvironmentVariable("JUNK", buff, 3), 3, 5,FALSE);
  223. init_buff();
  224. check(GetEnvironmentVariable("JUNK", buff, 4), 4, 5,FALSE);
  225. init_buff();
  226. check(GetEnvironmentVariable("JUNK", buff, 5), 5, 4,TRUE);
  227. init_buffw();
  228. checkw(GetEnvironmentVariableW(L"JUNK", buffw, 3), 3, 5,FALSE);
  229. init_buffw();
  230. checkw(GetEnvironmentVariableW(L"JUNK", buffw, 4), 4, 5,FALSE);
  231. init_buffw();
  232. checkw(GetEnvironmentVariableW(L"JUNK", buffw, 5), 5, 4,TRUE);
  233. //
  234. // GetCurrentDirectory: set to c:\ and check
  235. //
  236. cur_test = "GetCurrentDirectory";
  237. exp_val = "c:\\winnt";
  238. exp_valw = L"c:\\winnt";
  239. exp_len = strlen(exp_val);
  240. printf("\nGetCurrentDirectory: Expected string is <%s>\n", "c:\\winnt");
  241. if ( ! SetCurrentDirectory("c:\\winnt") ) {
  242. printf("Error setting cur dir\n");
  243. exit(1);
  244. }
  245. init_buff();
  246. check(GetCurrentDirectory(exp_len-1, buff), exp_len-1,exp_len+1,FALSE);
  247. init_buff();
  248. check(GetCurrentDirectory(exp_len, buff), exp_len, exp_len+1,FALSE);
  249. init_buff();
  250. check(GetCurrentDirectory(exp_len+1, buff), exp_len+1, exp_len,TRUE);
  251. init_buffw();
  252. checkw(GetCurrentDirectoryW(exp_len-1, buffw), exp_len-1,exp_len+1,FALSE);
  253. init_buffw();
  254. checkw(GetCurrentDirectoryW(exp_len, buffw), exp_len, exp_len+1,FALSE);
  255. init_buffw();
  256. checkw(GetCurrentDirectoryW(exp_len+1, buffw), exp_len+1, exp_len,TRUE);
  257. cur_test = "GetCurrentDirectory";
  258. exp_val = "c:\\";
  259. exp_valw = L"c:\\";
  260. exp_len = strlen(exp_val);
  261. printf("\nGetCurrentDirectory: Expected string is <%s>\n", "c:\\");
  262. if ( ! SetCurrentDirectory("c:\\") ) {
  263. printf("Error setting cur dir\n");
  264. exit(1);
  265. }
  266. init_buff();
  267. check(GetCurrentDirectory(exp_len-1, buff), exp_len-1,exp_len+1,FALSE);
  268. init_buff();
  269. check(GetCurrentDirectory(exp_len, buff), exp_len, exp_len+1,FALSE);
  270. init_buff();
  271. check(GetCurrentDirectory(exp_len+1, buff), exp_len+1, exp_len,TRUE);
  272. init_buffw();
  273. checkw(GetCurrentDirectoryW(exp_len-1, buffw), exp_len-1,exp_len+1,FALSE);
  274. init_buffw();
  275. checkw(GetCurrentDirectoryW(exp_len, buffw), exp_len, exp_len+1,FALSE);
  276. init_buffw();
  277. checkw(GetCurrentDirectoryW(exp_len+1, buffw), exp_len+1, exp_len,TRUE);
  278. //
  279. // GetFullPathName: this assumes that the current directory is c:\, which
  280. // was set earlier as part of the GetCurrentDirectory test. c:\junk.txt
  281. // is a total of 11 chars.
  282. //
  283. cur_test = "GetFullPathName";
  284. exp_val = "c:\\junk.txt";
  285. exp_valw = L"c:\\junk.txt";
  286. exp_len = strlen(exp_val);
  287. printf("\nGetFullPathName: Expected string is <%s>\n", exp_val);
  288. init_buff();
  289. check(GetFullPathName(exp_val, exp_len-1, buff, &lpJunk), exp_len-1,exp_len+1,FALSE);
  290. init_buff();
  291. check(GetFullPathName(exp_val, exp_len, buff, &lpJunk), exp_len,exp_len+1,FALSE);
  292. init_buff();
  293. check(GetFullPathName(exp_val, exp_len+1, buff, &lpJunk), exp_len+1,exp_len,TRUE);
  294. init_buffw();
  295. checkw(GetFullPathNameW(exp_valw, exp_len-1, buffw, &lpwJunk), exp_len-1,exp_len+1,FALSE);
  296. init_buffw();
  297. checkw(GetFullPathNameW(exp_valw, exp_len, buffw, &lpwJunk), exp_len,exp_len+1,FALSE);
  298. init_buffw();
  299. checkw(GetFullPathNameW(exp_valw, exp_len+1, buffw, &lpwJunk), exp_len+1,exp_len,TRUE);
  300. cur_test = "GetFullPathName";
  301. exp_val = "\\\\.\\lpt1";
  302. exp_valw = L"\\\\.\\lpt1";
  303. exp_len = strlen(exp_val);
  304. printf("\nGetFullPathName: Expected string is <%s>\n", exp_val);
  305. init_buff();
  306. check(GetFullPathName("lpt1", exp_len-1, buff, &lpJunk), exp_len-1,exp_len+1,FALSE);
  307. init_buff();
  308. check(GetFullPathName("lpt1", exp_len, buff, &lpJunk), exp_len,exp_len+1,FALSE);
  309. init_buff();
  310. check(GetFullPathName("lpt1", exp_len+1, buff, &lpJunk), exp_len+1,exp_len,TRUE);
  311. init_buffw();
  312. checkw(GetFullPathNameW(L"lpt1", exp_len-1, buffw, &lpwJunk), exp_len-1,exp_len+1,FALSE);
  313. init_buffw();
  314. checkw(GetFullPathNameW(L"lpt1", exp_len, buffw, &lpwJunk), exp_len,exp_len+1,FALSE);
  315. init_buffw();
  316. checkw(GetFullPathNameW(L"lpt1", exp_len+1, buffw, &lpwJunk), exp_len+1,exp_len,TRUE);
  317. if ( ! SetCurrentDirectory("c:\\winnt\\dump") ) {
  318. printf("Error setting cur dir\n");
  319. exit(1);
  320. }
  321. cur_test = "GetFullPathName";
  322. exp_val = "c:\\winnt\\dump";
  323. exp_valw = L"c:\\winnt\\dump";
  324. exp_len = strlen(exp_val);
  325. printf("\nGetFullPathName: Expected string is <%s>\n", exp_val);
  326. init_buff();
  327. check(GetFullPathName(".", exp_len-1, buff, &lpJunk), exp_len-1,exp_len+1,FALSE);
  328. init_buff();
  329. check(GetFullPathName(".", exp_len, buff, &lpJunk), exp_len,exp_len+1,FALSE);
  330. init_buff();
  331. check(GetFullPathName(".", exp_len+1, buff, &lpJunk), exp_len+1,exp_len,TRUE);
  332. init_buffw();
  333. checkw(GetFullPathNameW(L".", exp_len-1, buffw, &lpwJunk), exp_len-1,exp_len+1,FALSE);
  334. init_buffw();
  335. checkw(GetFullPathNameW(L".", exp_len, buffw, &lpwJunk), exp_len,exp_len+1,FALSE);
  336. init_buffw();
  337. checkw(GetFullPathNameW(L".", exp_len+1, buffw, &lpwJunk), exp_len+1,exp_len,TRUE);
  338. if ( ! SetCurrentDirectory("c:\\winnt") ) {
  339. printf("Error setting cur dir\n");
  340. exit(1);
  341. }
  342. cur_test = "GetFullPathName";
  343. exp_val = "c:\\winnt\\dump";
  344. exp_valw = L"c:\\winnt\\dump";
  345. exp_len = strlen(exp_val);
  346. printf("\nGetFullPathName: Expected string is <%s>\n", exp_val);
  347. init_buff();
  348. check(GetFullPathName("c:dump", exp_len-1, buff, &lpJunk), exp_len-1,exp_len+1,FALSE);
  349. init_buff();
  350. check(GetFullPathName("c:dump", exp_len, buff, &lpJunk), exp_len,exp_len+1,FALSE);
  351. init_buff();
  352. check(GetFullPathName("c:dump", exp_len+1, buff, &lpJunk), exp_len+1,exp_len,TRUE);
  353. init_buffw();
  354. checkw(GetFullPathNameW(L"c:dump", exp_len-1, buffw, &lpwJunk), exp_len-1,exp_len+1,FALSE);
  355. init_buffw();
  356. checkw(GetFullPathNameW(L"c:dump", exp_len, buffw, &lpwJunk), exp_len,exp_len+1,FALSE);
  357. init_buffw();
  358. checkw(GetFullPathNameW(L"c:dump", exp_len+1, buffw, &lpwJunk), exp_len+1,exp_len,TRUE);
  359. if ( ! SetCurrentDirectory("c:\\") ) {
  360. printf("Error setting cur dir\n");
  361. exit(1);
  362. }
  363. cur_test = "GetFullPathName";
  364. exp_val = "c:\\";
  365. exp_valw = L"c:\\";
  366. exp_len = strlen(exp_val);
  367. printf("\nGetFullPathName: Expected string is <%s>\n", exp_val);
  368. init_buff();
  369. check(GetFullPathName(".", exp_len-1, buff, &lpJunk), exp_len-1,exp_len+1,FALSE);
  370. init_buff();
  371. check(GetFullPathName(".", exp_len, buff, &lpJunk), exp_len,exp_len+1,FALSE);
  372. init_buff();
  373. check(GetFullPathName(".", exp_len+1, buff, &lpJunk), exp_len+1,exp_len,TRUE);
  374. init_buffw();
  375. checkw(GetFullPathNameW(L".", exp_len-1, buffw, &lpwJunk), exp_len-1,exp_len+1,FALSE);
  376. init_buffw();
  377. checkw(GetFullPathNameW(L".", exp_len, buffw, &lpwJunk), exp_len,exp_len+1,FALSE);
  378. init_buffw();
  379. checkw(GetFullPathNameW(L".", exp_len+1, buffw, &lpwJunk), exp_len+1,exp_len,TRUE);
  380. //
  381. // GetTempPath
  382. //
  383. cur_test = "GetTempPath";
  384. exp_len = strlen(TEMP_DIRB);
  385. exp_val = TEMP_DIRB;
  386. exp_valw = TEMP_DIR_WB;
  387. if ( ! SetEnvironmentVariable("TMP", TEMP_DIRA)) {
  388. printf("Error setting tmp environment variable\n");
  389. exit(1);
  390. }
  391. printf("\nGetTempPath: Expected string is <%s>\n", TEMP_DIRB);
  392. init_buff();
  393. check(GetTempPath(exp_len-1, buff), exp_len-1, exp_len+1,FALSE);
  394. init_buff();
  395. check(GetTempPath(exp_len, buff), exp_len, exp_len+1,FALSE);
  396. init_buff();
  397. check(GetTempPath(exp_len+1, buff), exp_len+1, exp_len,TRUE);
  398. init_buffw();
  399. checkw(GetTempPathW(exp_len-1, buffw), exp_len-1, exp_len+1,FALSE);
  400. init_buffw();
  401. checkw(GetTempPathW(exp_len, buffw), exp_len, exp_len+1,FALSE);
  402. init_buffw();
  403. checkw(GetTempPathW(exp_len+1, buffw), exp_len+1, exp_len,TRUE);
  404. cur_test = "GetTempPath";
  405. exp_len = strlen(TEMP_DIRB);
  406. exp_val = TEMP_DIRB;
  407. exp_valw = TEMP_DIR_WB;
  408. if ( ! SetEnvironmentVariable("TMP", TEMP_DIRB)) {
  409. printf("Error setting tmp environment variable\n");
  410. exit(1);
  411. }
  412. printf("\nGetTempPath: Expected string is <%s>\n", TEMP_DIRB);
  413. init_buff();
  414. check(GetTempPath(exp_len-1, buff), exp_len-1, exp_len+1,FALSE);
  415. init_buff();
  416. check(GetTempPath(exp_len, buff), exp_len, exp_len+1,FALSE);
  417. init_buff();
  418. check(GetTempPath(exp_len+1, buff), exp_len+1, exp_len,TRUE);
  419. init_buffw();
  420. checkw(GetTempPathW(exp_len-1, buffw), exp_len-1, exp_len+1,FALSE);
  421. init_buffw();
  422. checkw(GetTempPathW(exp_len, buffw), exp_len, exp_len+1,FALSE);
  423. init_buffw();
  424. checkw(GetTempPathW(exp_len+1, buffw), exp_len+1, exp_len,TRUE);
  425. cur_test = "GetTempPath";
  426. exp_len = strlen(TEMP_DIRC);
  427. exp_val = TEMP_DIRC;
  428. exp_valw = TEMP_DIR_WC;
  429. if ( ! SetEnvironmentVariable("TMP", TEMP_DIRC)) {
  430. printf("Error setting tmp environment variable\n");
  431. exit(1);
  432. }
  433. printf("\nGetTempPath: Expected string is <%s>\n", TEMP_DIRC);
  434. init_buff();
  435. check(GetTempPath(exp_len-1, buff), exp_len-1, exp_len+1,FALSE);
  436. init_buff();
  437. check(GetTempPath(exp_len, buff), exp_len, exp_len+1,FALSE);
  438. init_buff();
  439. check(GetTempPath(exp_len+1, buff), exp_len+1, exp_len,TRUE);
  440. init_buffw();
  441. checkw(GetTempPathW(exp_len-1, buffw), exp_len-1, exp_len+1,FALSE);
  442. init_buffw();
  443. checkw(GetTempPathW(exp_len, buffw), exp_len, exp_len+1,FALSE);
  444. init_buffw();
  445. checkw(GetTempPathW(exp_len+1, buffw), exp_len+1, exp_len,TRUE);
  446. cur_test = "SearchPath";
  447. exp_len = strlen("c:\\winnt\\system32\\kernel32.dll");
  448. exp_val = "c:\\winnt\\system32\\kernel32.dll";
  449. exp_valw = L"c:\\winnt\\system32\\kernel32.dll";
  450. printf("\nSearchPath: Expected string is <%s>\n", exp_val);
  451. init_buff();
  452. check(SearchPath(NULL,"kernel32",".dll",exp_len-1,buff,&lpJunk),exp_len-1,exp_len+1,FALSE);
  453. init_buff();
  454. check(SearchPath(NULL,"kernel32",".dll",exp_len,buff,&lpJunk),exp_len,exp_len+1,FALSE);
  455. init_buff();
  456. check(SearchPath(NULL,"kernel32",".dll",exp_len+1,buff,&lpJunk),exp_len+1,exp_len,TRUE);
  457. init_buffw();
  458. checkw(SearchPathW(NULL,L"kernel32",L".dll",exp_len-1,buffw,&lpwJunk),exp_len-1,exp_len+1,FALSE);
  459. init_buffw();
  460. checkw(SearchPathW(NULL,L"kernel32",L".dll",exp_len,buffw,&lpwJunk),exp_len,exp_len+1,FALSE);
  461. init_buffw();
  462. checkw(SearchPathW(NULL,L"kernel32",L".dll",exp_len+1,buffw,&lpwJunk),exp_len+1,exp_len,TRUE);
  463. cur_test = "GetModuleFileName";
  464. exp_len = strlen("c:\\winnt\\system32\\bnd.exe");
  465. exp_val = "c:\\winnt\\system32\\bnd.exe";
  466. exp_valw = L"c:\\winnt\\system32\\bnd.exe";
  467. printf("\nGetModuleFileName: Expected string is <%s>\n", exp_val);
  468. init_buff();
  469. check(GetModuleFileName(NULL,buff,exp_len-1),exp_len-1,exp_len+1,FALSE);
  470. init_buff();
  471. check(GetModuleFileName(NULL,buff,exp_len),exp_len,exp_len+1,FALSE);
  472. init_buff();
  473. check(GetModuleFileName(NULL,buff,exp_len+1),exp_len+1,exp_len,TRUE);
  474. init_buffw();
  475. checkw(GetModuleFileNameW(NULL,buffw,exp_len-1),exp_len-1,exp_len+1,FALSE);
  476. init_buffw();
  477. checkw(GetModuleFileNameW(NULL,buffw,exp_len),exp_len,exp_len+1,FALSE);
  478. init_buffw();
  479. checkw(GetModuleFileNameW(NULL,buffw,exp_len+1),exp_len+1,exp_len,TRUE);
  480. }
  481. //
  482. // Function to init the global buffer to the SIGNATURE
  483. //
  484. void init_buff()
  485. {
  486. int i;
  487. for ( i=0; i<SIZE_BUFF; i++ )
  488. buff[i] = SIGNATURE;
  489. buff[SIZE_BUFF-1] = '\0'; // to ensure its null-terminated somewhere
  490. // (for debugging)
  491. }
  492. void init_buffw()
  493. {
  494. int i;
  495. for ( i=0; i<SIZE_BUFF; i++ )
  496. buffw[i] = SIGNATURE_W;
  497. buffw[SIZE_BUFF-1] = 0;
  498. }
  499. //
  500. // Function to check whether the API wrote past the end of the buffer, and
  501. // whether it returned what was expected
  502. //
  503. // It assumes that the global vars cur_test is set and buff was used
  504. //
  505. void check(DWORD retcode, DWORD size_passed, int expected_ret, BOOL shouldxfer)
  506. {
  507. int i;
  508. if ( buff[size_passed] != SIGNATURE ) {
  509. printf("\nFAILURE: %s wrote past end of buffer, when passed %d\n",
  510. cur_test, size_passed);
  511. return;
  512. }
  513. if ( retcode != (DWORD)expected_ret ) {
  514. printf("\nFAILURE: %s returned %d, expected %d, when passed %d\n",
  515. cur_test, retcode, expected_ret, size_passed);
  516. return;
  517. }
  518. if ( shouldxfer ) {
  519. for (i=0;i<expected_ret;i++){
  520. if ( toupper(buff[i]) != toupper(exp_val[i]) ) {
  521. printf("\nFAILURE: %s mismatch at %d",cur_test, i);
  522. return;
  523. }
  524. }
  525. }
  526. printf("\nPASSED: %s when passed %d\n", cur_test, size_passed);
  527. }
  528. void checkw(DWORD retcode, DWORD size_passed, int expected_ret,BOOL shouldxfer)
  529. {
  530. int i;
  531. if ( buffw[size_passed] != SIGNATURE_W ) {
  532. printf("\nFAILURE: %s wrote past end of buffer, when passed %d\n",
  533. cur_test, size_passed);
  534. return;
  535. }
  536. if ( retcode != (DWORD)expected_ret ) {
  537. printf("\nFAILURE: %s returned %d, expected %d, when passed %d\n",
  538. cur_test, retcode, expected_ret, size_passed);
  539. return;
  540. }
  541. if (shouldxfer) {
  542. for (i=0;i<expected_ret;i++){
  543. if ( towupper(buffw[i]) != towupper(exp_valw[i]) ) {
  544. printf("\nFAILURE: %s mismatch at %d",cur_test, i);
  545. return;
  546. }
  547. }
  548. }
  549. printf("\nPASSED: %s when passed %d\n", cur_test, size_passed);
  550. }