utdfexp.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. { %skiptarget=wince }
  2. {
  3. This file is part of the Free Pascal test suite.
  4. Copyright (c) 1999-2004 by the Free Pascal development team.
  5. Test for possible bugs in Dos.FExpand
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. unit utdfexp;
  14. interface
  15. uses punit, utrtl;
  16. {$DEFINE DEBUG}
  17. (* Defining DEBUG causes all the source and target strings *)
  18. (* to be written to the console to make debugging easier. *)
  19. { $DEFINE DIRECT}
  20. (* Defining DIRECT causes direct embedding of fexpand.inc instead *)
  21. (* of using FExpand implementation in (previously compiled) unit Dos. *)
  22. implementation
  23. uses
  24. Dos;
  25. {$IFDEF DIRECT}
  26. (* For testing purposes on non-native platforms *)
  27. {$DEFINE VOLUMES}
  28. {$DEFINE NODOTS}
  29. { $DEFINE AMIGA}
  30. { $DEFINE UNIX}
  31. {$DEFINE MACOS}
  32. { $DEFINE FPC_FEXPAND_DRIVES}
  33. { $DEFINE FPC_FEXPAND_UNC}
  34. {$DEFINE FPC_FEXPAND_VOLUMES}
  35. {$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
  36. {$DEFINE FPC_FEXPAND_DRIVESEP_IS_ROOT}
  37. { $DEFINE FPC_FEXPAND_DIRSEP_IS_UPDIR}
  38. {$DEFINE FPC_FEXPAND_NO_DOTS_UPDIR}
  39. { $DEFINE FPC_FEXPAND_NO_CURDIR}
  40. { $DEFINE FPC_FEXPAND_TILDE}
  41. { $DEFINE FPC_FEXPAND_MULTIPLE_UPDIR}
  42. {$DEFINE FPC_FEXPAND_DIRSEP_IS_CURDIR}
  43. { $DEFINE FPC_FEXPAND_GETENV_PCHAR}
  44. {$ENDIF DIRECT}
  45. {$IFDEF LINUX}
  46. {$IFNDEF UNIX}
  47. {$DEFINE UNIX}
  48. {$ENDIF UNIX}
  49. {$ENDIF LINUX}
  50. {$IFDEF AMIGA}
  51. {$IFNDEF HASAMIGA}
  52. {$DEFINE HASAMIGA}
  53. {$ENDIF HASAMIGA}
  54. {$ENDIF AMIGA}
  55. {$IFDEF HASAMIGA}
  56. {$DEFINE VOLUMES}
  57. {$DEFINE NODRIVEC}
  58. {$DEFINE NODOTS}
  59. {$ENDIF HASAMIGA}
  60. {$IFDEF NETWARE}
  61. {$DEFINE VOLUMES}
  62. {$DEFINE NODRIVEC}
  63. {$ENDIF NETWARE}
  64. {$IFDEF UNIX}
  65. {$DEFINE NODRIVEC}
  66. {$ENDIF UNIX}
  67. {$IFDEF MACOS}
  68. {$DEFINE VOLUMES}
  69. {$DEFINE NODRIVEC}
  70. {$DEFINE NODOTS}
  71. {$ENDIF MACOS}
  72. const
  73. {$IFNDEF NODRIVEC}
  74. CC = 'C:';
  75. {$ENDIF NODRIVEC}
  76. {$IFNDEF FPC}
  77. FileNameCasePreserving = false;
  78. DirectorySeparator = '\';
  79. DirectorySeparator2 = '\';
  80. DirSep = '\';
  81. CDrive = 'C:';
  82. DriveSep = ':';
  83. {$ELSE FPC}
  84. (* Used for ChDir/MkDir *)
  85. DirectorySeparator2 = System.DirectorySeparator;
  86. {$IFDEF DIRECT}
  87. {$IFDEF MACOS}
  88. DirectorySeparator = ':';
  89. LFNSupport = true;
  90. FileNameCasePreserving = true;
  91. {$ELSE MACOS}
  92. {$IFDEF UNIX}
  93. DirectorySeparator = '/';
  94. DriveSeparator = '/';
  95. FileNameCasePreserving = true;
  96. {$ELSE UNIX}
  97. {$IFDEF HASAMIGA}
  98. DirectorySeparator = '/';
  99. FileNameCasePreserving = true;
  100. {$ELSE HASAMIGA}
  101. DirectorySeparator = '\';
  102. FileNameCasePreserving = false;
  103. {$ENDIF HASAMIGA}
  104. {$ENDIF UNIX}
  105. {$ENDIF MACOS}
  106. {$ENDIF DIRECT}
  107. DirSep = DirectorySeparator;
  108. {$IFDEF MACOS}
  109. DriveSep = '';
  110. {$ELSE MACOS}
  111. DriveSep = DriveSeparator;
  112. {$ENDIF MACOS}
  113. {$IFDEF UNIX}
  114. CDrive = '';
  115. {$ELSE UNIX}
  116. {$IFDEF MACOS}
  117. CDrive = 'C';
  118. {$ELSE MACOS}
  119. {$IFDEF HASAMIGA}
  120. CDrive = 'C';
  121. {$ELSE HASAMIGA}
  122. CDrive = 'C:';
  123. {$ENDIF HASAMIGA}
  124. {$ENDIF MACOS}
  125. {$ENDIF UNIX}
  126. {$ENDIF FPC}
  127. TestFileName = 'testfile.tst';
  128. TestDir1Name = 'TESTDIR1';
  129. TestDir2Name = 'TESTDIR2';
  130. {$IFDEF DIRECT}
  131. procedure XToDirect (var S: string);
  132. var
  133. I: byte;
  134. begin
  135. if DirectorySeparator2 <> DirectorySeparator then
  136. for I := 1 to Length (S) do
  137. if S [I] = DirectorySeparator2 then
  138. S [I] := DirectorySeparator;
  139. {$IFNDEF FPC_FEXPAND_DRIVES}
  140. if DriveSeparator = DirectorySeparator then
  141. I := Pos (DirectorySeparator + DirectorySeparator, S)
  142. else
  143. I := Pos (DriveSeparator, S);
  144. if I <> 0 then
  145. Delete (S, 1, I);
  146. {$ENDIF FPC_FEXPAND_DRIVES}
  147. end;
  148. procedure GetDir (Drive: byte; var Directory: string);
  149. begin
  150. System.GetDir (Drive, Directory);
  151. XToDirect (Directory);
  152. end;
  153. {$I fexpand.inc}
  154. {$ENDIF DIRECT}
  155. var
  156. {$IFNDEF NODRIVEC}
  157. CDir,
  158. {$endif}
  159. TestDir, TestDir0, OrigDir, CurDir, S: DirStr;
  160. TestDrive: string [2];
  161. F: file;
  162. function Translate (S: PathStr): PathStr;
  163. var
  164. I: byte;
  165. begin
  166. {$IFDEF UNIX}
  167. if (Length (S) > 1) and (S [2] = ':') then Delete (S, 1, 2);
  168. {$ELSE UNIX}
  169. for I := 1 to Length (S) do if S [I] = '/' then S [I] := DirSep;
  170. if (Length (S) > 1) and (S [1] in ['a'..'z']) and (S[2]=DriveSep) then
  171. S [1] := UpCase (S [1]);
  172. {$ENDIF UNIX}
  173. if not (FileNameCasePreserving) then
  174. for I := 1 to Length (S) do S [I] := UpCase (S [I]);
  175. Translate := S;
  176. end;
  177. Function Check (ID : Integer; Src, Rslt: PathStr) : Boolean;
  178. var
  179. Rslt2: PathStr;
  180. S : string;
  181. begin
  182. {$IFDEF DEBUG}
  183. if ShowDebugOutput then
  184. WriteLn (ID,' : ',Src, '=>', Rslt);
  185. {$ENDIF DEBUG}
  186. Rslt := Translate (Rslt);
  187. Rslt2 := FExpand (Src);
  188. {$IFDEF DIRECT}
  189. {$IFNDEF FPC_FEXPAND_DRIVES}
  190. I := Pos (System.DriveSeparator, Rslt2);
  191. if I <> 0 then
  192. Delete (Rslt2, 1, I);
  193. {$ENDIF FPC_FEXPAND_DRIVES}
  194. {$ENDIF DIRECT}
  195. {$IFNDEF UNIX}
  196. if (Length (Rslt2) > 1) and (Rslt2 [1] in ['a'..'z']) and (Rslt2[2]=DriveSep) then
  197. Rslt2 [1] := UpCase (Rslt2 [1]);
  198. {$ENDIF NDEF UNIX}
  199. Str(ID,S);
  200. Check:=AssertEquals(S+': FExpand ('+Src+ ')', Rslt,Rslt2);
  201. end;
  202. Function DoTest : TTestString;
  203. begin
  204. Result:='';
  205. {$IFDEF DIRECT}
  206. {$IFNDEF FPC_FEXPAND_DRIVES}
  207. I := Pos (System.DriveSeparator, CurDir);
  208. if I <> 0 then
  209. Delete (CurDir, 1, I);
  210. {$ENDIF FPC_FEXPAND_DRIVES}
  211. {$ENDIF DIRECT}
  212. {$IFNDEF NODRIVEC}
  213. GetDir (3, CDir);
  214. {$ENDIF NODRIVEC}
  215. if not Check (1,' ', CurDir + DirSep + ' ') then exit;
  216. {$IFDEF HASAMIGA}
  217. if not Check (2, '', CurDir) then exit;
  218. {$ELSE HASAMIGA}
  219. if not Check (3,'', CurDir + DirSep) then exit;
  220. {$ENDIF HASAMIGA}
  221. {$IFDEF MACOS}
  222. if not Check (4,':', CurDir + DirSep) then exit;
  223. {$ELSE MACOS}
  224. if not Check (5,'.', CurDir) then exit;
  225. {$ENDIF MACOS}
  226. {$IFNDEF NODRIVEC}
  227. if CDir [Length (CDir)] = DirSep then
  228. begin
  229. if not Check (6,'c:anything', CDir + 'anything') then
  230. exit,
  231. end
  232. else
  233. if not Check (7,'c:anything', CDir + DirSep + 'anything') then exit;
  234. if not Check (8,CC + DirSep, CDrive + DirSep) then exit;
  235. {$IFDEF NODOTS}
  236. if not Check (9,'C:.', 'C:.') then exit;
  237. if not Check (10,CC + DirSep + '.', CDrive + DirSep + '.') then exit;
  238. if not Check (CC + DirSep + '..', CDrive + DirSep + '..') then exit;
  239. {$ELSE NODOTS}
  240. if not Check (11,'C:.', CDir) then exit;
  241. if not Check (12,CC + DirSep + '.', CDrive + DirSep) then exit;
  242. if not Check (13,CC + DirSep + '..', CDrive + DirSep) then exit;
  243. {$ENDIF NODOTS}
  244. if not Check (14,CC + DirSep + 'DOS', CDrive + DirSep + 'DOS') then exit;
  245. {$IFNDEF NODOTS}
  246. if not Check (15,CC + DirSep + '..' + DirSep + 'DOS', CDrive + DirSep + 'DOS') then exit;
  247. {$ENDIF NODOTS}
  248. if not Check (16,CC + DirSep + 'DOS.', CDrive + DirSep + 'DOS.') then exit;
  249. {$IFDEF HASAMIGA} (* This has no effect - AMIGA has NODRIVEC defined... *)
  250. if not Check (17,CC + DirSep + 'DOS' + DirSep, CDrive + DirSep) then exit;
  251. {$ELSE HASAMIGA}
  252. if not Check (18,CC + DirSep + 'DOS' + DirSep, CDrive + DirSep + 'DOS' + DirSep) then exit;
  253. {$ENDIF HASAMIGA}
  254. {$IFNDEF NODOTS}
  255. if not Check (19,CC + DirSep + 'DOS' + DirSep + '.', CDrive + DirSep + 'DOS') then exit;
  256. if not Check (20,CC + DirSep + 'DOS' + DirSep + '..', CDrive + DirSep) then exit;
  257. if not Check (21,CC + DirSep + 'DOS' + DirSep + '..' + DirSep, CDrive + DirSep) then exit;
  258. if not Check (22,CC + DirSep + 'DOS' + DirSep + 'TEST' + DirSep + '..', CDrive +
  259. DirSep + 'DOS') then exit;
  260. if not Check (23,ID,'C:' + DirSep + 'DOS' + DirSep + 'TEST' + DirSep + '..' + DirSep,
  261. CDrive + DirSep + 'DOS' + DirSep) then exit;
  262. {$ENDIF NODOTS}
  263. {$ENDIF NODRIVEC}
  264. {$IFNDEF MACOS}
  265. {$IFDEF HASAMIGA}
  266. if not Check (24,DirSep, TestDir + TestDir1Name) then exit;
  267. if not Check (25,DirSep + DirSep + TestFileName, TestDir + TestFileName) then exit;
  268. if not Check (26,DirSep + 'DOS', TestDir + TestDir1Name + DirSep + 'DOS') then exit;
  269. {$ELSE HASAMIGA}
  270. if not Check (27,DirSep, TestDrive + DirSep) then exit;
  271. if not Check (28,DirSep + '.', TestDrive + DirSep) then exit;
  272. if not Check (29,DirSep + '..', TestDrive + DirSep)then exit;
  273. if not Check (30,DirSep + 'DOS', TestDrive + DirSep + 'DOS') then exit;
  274. {$ENDIF HASAMIGA}
  275. {$ENDIF MACOS}
  276. if not Check (31,'d', CurDir + DirSep + 'd')then exit;
  277. {$IFDEF MACOS}
  278. if not Check (32,DirSep + 'd', CurDir + DirSep + 'd') then exit;
  279. {$ELSE MACOS}
  280. {$IFNDEF NODOTS}
  281. if not Check (33,'.' + DirSep + 'd', CurDir + DirSep + 'd') then exit;
  282. {$ENDIF NODOTS}
  283. {$ENDIF MACOS}
  284. if not Check (34,'d' + DirSep + TestFileName, CurDir + DirSep + 'd' + DirSep + TestFileName) then exit;
  285. if not Check (35,' d', CurDir + DirSep + ' d') then exit;
  286. if not Check (36,'dd', CurDir + DirSep + 'dd') then exit;
  287. {$IFDEF MACOS}
  288. if not Check (37,DirSep + 'dd' + DirSep + 'dd', CurDir + DirSep + 'dd' + DirSep + 'dd') then exit;
  289. if not Check (38,'dd' + DirSep + 'dd', 'dd' + DirSep + 'dd') then exit;
  290. {$ELSE MACOS}
  291. if not Check (39,'dd' + DirSep + 'dd', CurDir + DirSep + 'dd' + DirSep + 'dd') then exit;
  292. {$ENDIF MACOS}
  293. if not Check (40,'ddd', CurDir + DirSep + 'ddd') then exit;
  294. {$IFDEF MACOS}
  295. if not Check (41,'dddd' + DirSep + 'eeee.ffff', 'dddd' + DirSep + 'eeee.ffff') then exit;
  296. {$ELSE MACOS}
  297. if not Check (42,'dddd' + DirSep + 'eeee.ffff', CurDir + DirSep + 'dddd' + DirSep
  298. + 'eeee.ffff') then exit;
  299. {$ENDIF MACOS}
  300. if not Check (43,'.special', CurDir + DirSep + '.special') then exit;
  301. if not Check (44,'..special', CurDir + DirSep + '..special') then exit;
  302. if not Check (45,'special..', CurDir + DirSep + 'special..') then exit;
  303. {$IFDEF HASAMIGA}
  304. if not Check (46,'special.' + DirSep, CurDir + DirSep + 'special.' + DirSep) then exit;
  305. {$ELSE HASAMIGA}
  306. {$IFDEF MACOS}
  307. if not Check (47,'special.' + DirSep, 'special.' + DirSep) then exit;
  308. {$ELSE MACOS}
  309. if not Check (48,'special.' + DirSep, CurDir + DirSep + 'special.' + DirSep) then exit;
  310. {$ENDIF MACOS}
  311. {$ENDIF HASAMIGA}
  312. {$IFDEF MACOS}
  313. if not Check (49,DirSep + DirSep, TestDir + TestDir1Name + DirSep) then exit;
  314. if not Check (50,DirSep + DirSep + TestFileName, TestDir + TestDir1Name + DirSep
  315. + TestFileName) then exit;
  316. {$ELSE MACOS}
  317. if not Check (51,DirSep + '.special', TestDrive + DirSep + '.special') then exit;
  318. {$IFNDEF NODOTS}
  319. if not Check (52,'..', TestDir + TestDir1Name) then exit;
  320. if not Check (53,'.' + DirSep + '..', TestDir + TestDir1Name) then exit;
  321. if not Check (54,'..' + DirSep + '.', TestDir + TestDir1Name) then exit;
  322. {$ENDIF NODOTS}
  323. {$ENDIF MACOS}
  324. {$IFDEF NETWARE}
  325. if not Check (55,'...', TestDir) then exit;
  326. {$ELSE NETWARE}
  327. if not Check (56,'...', CurDir + DirSep + '...') then exit;
  328. {$ENDIF NETWARE}
  329. if not Check (57,TestFileName, CurDir + DirSep + TestFileName) then exit;
  330. {$IFDEF UNIX}
  331. S := GetEnv ('HOME');
  332. { On m68k netbsd at least, HOME contains a final slash
  333. remove it PM }
  334. if (Length (S) > 1) and (S [Length (S)] = DirSep) then
  335. S:=Copy(S,1,Length(S)-1);
  336. if Length (S) = 0 then
  337. begin
  338. if not Check (58,'~', CurDir) then exit;
  339. if not Check (59,'~' + DirSep + '.', DirSep) then exit;
  340. end
  341. else
  342. begin
  343. if not Check (60,'~', S) then exit;
  344. if not Check (61,'~' + DirSep + '.', S) then exit;
  345. end;
  346. if (Length (S) > 0) and (S [Length (S)] <> DirSep) then
  347. S := S + DirSep;
  348. if not Check (62,'~NobodyWithThisNameShouldEverExist.test/nothing', CurDir + DirSep +
  349. '~NobodyWithThisNameShouldEverExist.test/nothing') then exit;
  350. if not Check (63,'/tmp/~NoSuchUserAgain', '/tmp/~NoSuchUserAgain') then exit;
  351. if Length (S) = 0 then
  352. begin
  353. if not Check (64,'~' + DirSep, DirSep) then exit;
  354. if not Check (65,'~' + DirSep + '.' + DirSep, DirSep) then exit;
  355. if not Check (66,'~' + DirSep + 'directory' + DirSep + 'another',
  356. DirSep + 'directory' + DirSep + 'another') then exit;
  357. end
  358. else
  359. begin
  360. if not Check (67,'~' + DirSep, S) then exit;
  361. if not Check (68,'~' + DirSep + '.' + DirSep, S) then exit;
  362. if not Check (69,'~' + DirSep + 'directory' + DirSep + 'another',
  363. S + 'directory' + DirSep + 'another') then exit;
  364. end;
  365. {$ELSE UNIX}
  366. {$IFNDEF NODRIVEC}
  367. if not Check (70,TestDrive + '..', TestDir + TestDir1Name) then exit;
  368. if not Check (71,TestDrive + '..' + DirSep, TestDir + TestDir1Name + DirSep) then exit;
  369. if not Check (72,TestDrive + '.' + DirSep + '.', CurDir) then exit;
  370. if not Check (73,TestDrive + '.' + DirSep + '..', TestDir + TestDir1Name) then exit;
  371. {$I-}
  372. (*
  373. { $ ifndef unix }
  374. { avoid a and b drives for
  375. no unix systems to reduce the
  376. probablility of getting an alert message box }
  377. { This should not be needed - unit popuperr should solve this?! TH }
  378. I := 3;
  379. {$else unix} *)
  380. I := 1;
  381. { $ endif unix}
  382. repeat
  383. S := '';
  384. GetDir (I, S);
  385. IOR := IOResult;
  386. if IOR = 0 then Inc (I);
  387. until (I > 26) or (IOR <> 0);
  388. if I <= 26 then
  389. begin
  390. S := Chr (I + 64) + ':ddd';
  391. if not Check (74,S, Chr (I + 64) + ':' + DirSep + 'ddd') then exit;
  392. end else
  393. if ShowDebugOutput then
  394. WriteLn ('Sorry, cannot test FExpand behaviour for incorrect drives here.');
  395. {$I+}
  396. {$IFDEF FPC}
  397. if not Check (75,'d\d/d', CurDir + DirSep + 'd' + DirSep + 'd' + DirSep + 'd') then exit;
  398. if not Check (76,'\\server\share\directory', '\\server\share\directory') then exit;
  399. if not Check (77,'\\server\share\directory1\directory2\..',
  400. '\\server\share\directory1') then exit;
  401. if not Check (78,'\\', '\\') then exit;
  402. if not Check (79,'\\.', '\\.\') then exit;
  403. if not Check (80,'\\.\', '\\.\') then exit;
  404. if not Check (81,'\\.\.', '\\.\.') then exit;
  405. if not Check (82,'\\.\..', '\\.\..') then exit;
  406. if not Check (83,'\\.\...', '\\.\...') then exit;
  407. if not Check (84,'\\.\TEST', '\\.\TEST') then exit;
  408. if not Check (85,'\\..\', '\\..\') then exit;
  409. if not Check (86,'\\..\TEST', '\\..\TEST') then exit;
  410. if not Check (87,'\\..\TEST\.', '\\..\TEST') then exit;
  411. if not Check (88,'\\..\TEST1\TEST2\..', '\\..\TEST1') then exit;
  412. if not Check (89,'\\..\TEST\..', '\\..\TEST') then exit;
  413. if not Check (90,'\\..\TEST\..\..', '\\..\TEST') then exit;
  414. {$ENDIF FPC}
  415. {$ENDIF NODRIVEC}
  416. {$ENDIF UNIX}
  417. {$IFDEF VOLUMES}
  418. {$IFDEF HASAMIGA}
  419. if not Check (91,'VolName' + DriveSep + 'DIR1', 'VolName' + DriveSep + 'DIR1') then exit;
  420. {$ELSE HASAMIGA}
  421. if not Check (92,'VolName' + DriveSep + DirSep + 'DIR1', 'VolName' + DriveSep + DirSep + 'DIR1') then exit;
  422. {$ENDIF HASAMIGA}
  423. {$IFNDEF NODOTS}
  424. if not Check (93,'VolName' + DriveSep + DirSep + 'DIR1' + DirSep + '..', 'VolName' + DriveSep + DirSep) then exit;
  425. if not Check (94,'VolName' + DriveSep + DirSep + 'DIR1' + DirSep + '..' + DirSep + '..',
  426. 'VolName' + DriveSep + DirSep) then exit;
  427. if not Check (95,'VolName' + DriveSep + DirSep + '.', 'VolName:' + DirSep) then exit;
  428. if not Check (96,'VolName' + DriveSep + DirSep + '..', 'VolName:' + DirSep) then exit;
  429. if not Check (97,'VolName' + DriveSep + DirSep + '..' + DirSep, 'VolName' + DriveSep + DirSep) then exit;
  430. {$ENDIF NODOTS}
  431. {$IFDEF NETWARE}
  432. if not Check (98,'SrvName\VolName' + DriveSep + DirSep + 'TEST', 'SrvName' + DirSep + 'VolName' +
  433. DriveSep + DirSep + 'TEST') then exit;
  434. if not Check (99,'SrvName/VolName' + DriveSep + DirSep + 'TEST', 'SrvName' + DirSep + 'VolName' +
  435. DriveSep + DirSep + 'TEST') then exit;
  436. {$ENDIF NETWARE}
  437. {$IFDEF HASAMIGA}
  438. {$IFDEF NODOTS}
  439. if not Check (100,'.', CurDir + DirSep + '.') then exit;
  440. {$ELSE NODOTS}
  441. if not Check (101,'.', CurDir) then exit;
  442. {$ENDIF NODOTS}
  443. {$ENDIF HASAMIGA}
  444. {$ENDIF VOLUMES}
  445. end;
  446. Function TestDosFExpand : TTestString;
  447. begin
  448. Result:='';
  449. TestDir:=SysGetSetting('fexpanddir');
  450. if (TestDir='') then
  451. begin
  452. if ShowDebugOutput then
  453. begin
  454. WriteLn ('Warning: Parameter missing!');
  455. WriteLN('Full path to a directory with write access' +
  456. {$IFNDEF UNIX}
  457. {$IFNDEF VOLUMES}
  458. #13#10'(preferably not on a C: drive)' +
  459. {$ENDIF VOLUMES}
  460. {$ENDIF UNIX}
  461. ' expected.');
  462. WriteLn ('Trying to use the current directory instead ' +
  463. {$IFDEF UNIX}
  464. '(not quite ideal).');
  465. {$ELSE UNIX}
  466. '(problems might arise).');
  467. {$ENDIF UNIX}
  468. end;
  469. // Get current dir
  470. {$IFDEF DIRECT}System.{$ENDIF DIRECT}GetDir(0,TestDir);
  471. end;
  472. if TestDir[Length(TestDir)]<>DirectorySeparator2 then
  473. TestDir := TestDir + DirectorySeparator2;
  474. {$IFDEF DIRECT}System.{$ENDIF DIRECT}GetDir (0,OrigDir);
  475. {$IFDEF NODRIVEC}
  476. TestDrive := '';
  477. {$ELSE NODRIVEC}
  478. TestDrive := Copy (TestDir, 1, 2);
  479. GetDir ((Ord (TestDir [1]) and not ($20)) - 64, OrigTstDir);
  480. {$ENDIF NODRIVEC}
  481. {$I-}
  482. MkDir (TestDir + TestDir1Name);
  483. if IOResult <> 0 then ;
  484. MkDir (TestDir + TestDir1Name + DirectorySeparator2 + TestDir2Name);
  485. if IOResult <> 0 then ;
  486. {$I+}
  487. ChDir (TestDir + TestDir1Name + DirectorySeparator2 + TestDir2Name);
  488. {$I-}
  489. TestDir0 := TestDir;
  490. {$IFDEF DIRECT}
  491. XToDirect (TestDir);
  492. {$IFNDEF FPC_FEXPAND_DRIVES}
  493. I := Pos (System.DriveSeparator, TestDir);
  494. if I <> 0 then
  495. Delete (TestDir, 1, I);
  496. {$ENDIF FPC_FEXPAND_DRIVES}
  497. {$ENDIF DIRECT}
  498. Assign (F, TestFileName);
  499. Rewrite (F);
  500. Close (F);
  501. if IOResult <> 0 then ;
  502. {$IFNDEF DIRECT}
  503. Assign (F, FExpand (TestFileName));
  504. {$ENDIF DIRECT}
  505. {$I+}
  506. GetDir (0, CurDir);
  507. // Do the actual tests.
  508. // The test exits at the first error, so we put it in a subroutine to be able to clean up.
  509. Result:=DoTest;
  510. // Clean up
  511. Erase (F);
  512. {$IFNDEF NODRIVEC}
  513. ChDir (OrigTstDir);
  514. {$ENDIF NODRIVEC}
  515. ChDir (OrigDir);
  516. RmDir (TestDir0 + TestDir1Name + DirectorySeparator2 + TestDir2Name);
  517. RmDir (TestDir0 + TestDir1Name);
  518. end;
  519. begin
  520. AddTest('DosFExpand',@TestDosFExpand,EnsureSuite('Dos'));
  521. end.