home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / test / filesmac.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  8.5 KB  |  235 lines  |  [TEXT/R*ch]

  1. (* test/filesys.sml
  2.    PS 1995-03-23, 1996-05-01
  3. *)
  4.  
  5. (* Mac: changed "/" to ":", "." to ":", ".." to "::"
  6.         10a is testing that remove doesn't work on directories
  7.             -- it does on the Mac; this is probably OK
  8.         testcycl -> testcycl  can this be done on the Mac?
  9.         readDir doen't make "." and ".." -- commented out
  10.                 so rewindDir test is less worthwhile (but it does work!)
  11.         test3b has been replaced, see the note there
  12.         test13a & 13c fail because readLink fails for non-links
  13.         test13b fails because readLink makes full pathname
  14.  
  15.         test5 is hacked extensively... the MacOS has a bug where the OS
  16.               holds a working directory link to renamed directory for
  17.               an indeterminant time... so if test5 fails twice, as it will
  18.               (since you can't delete it until MacOS gives up its WD link)
  19.               succeeding tests will fail as well
  20. *)
  21.  
  22. (* DOS: Plain WRONG: test6a, test9a (and test9b);
  23.         Excusable:   test8b, test11b, test12a, test13a, test13b, test13c
  24.  *)
  25.  
  26. (* This requires two links to be present in the current directory:
  27.         testlink -> README
  28.         testcycl -> testcycl 
  29.         testbadl -> exists.not
  30.    Moreover, the file README must exist and the file exists.not not.
  31. *)
  32.  
  33.  
  34. use "auxil.sml";
  35.  
  36. local
  37.     open FileSys
  38.     (* Clean up: *)
  39.     val _ = (rmDir "testdir") handle OS.SysErr _ => (); 
  40.     val _ = (rmDir "testdir2") handle OS.SysErr _ => (); 
  41.     val _ = (rmDir "exists.not") handle OS.SysErr _ => (); 
  42. in
  43.  
  44. val test1a = (mkDir "testdir" seq "OK") handle _ => "WRONG";
  45. val test1b = (mkDir "testdir" seq "WRONG")
  46.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  47.  
  48. val test2 = check'(fn _ => isDir "testdir");
  49.     
  50. val test3a = check'(fn _ => access("testdir", [A_READ, A_EXEC, A_WRITE]));
  51.  
  52. (* on Mac, empty directories have zero size...
  53. val test3b = check'(fn _ => fileSize "testdir" > 0);
  54. *)
  55. val test3b = check'(fn _ => fileSize "testdir" = 0);
  56. val test3c = check'(fn _ => fileSize ":" > 0);
  57.  
  58. local 
  59.     val cdir = getDir();
  60. in
  61.     val test4a = (chDir cdir seq "OK") handle _ => "WRONG";
  62.     val test4b = check'(fn _ => cdir = getDir());
  63.     val _ = chDir "testdir";
  64.     val test4c = check'(fn _ => cdir <> getDir());
  65.     val _ = chDir "::";
  66.     val test4d = check'(fn _ => cdir = getDir());
  67. end;
  68.  
  69. val _ = rename{old = "testdir", new = "exists.not"};
  70.  
  71. fun suspend n =
  72.   let open Timer
  73.       open Time
  74.       val sta = startRealTimer ()
  75.       val dur = fromMilliseconds n
  76.   in 
  77.       while ((checkRealTimer sta) < dur) do ()
  78.   end;
  79.  
  80. val test5 = (rmDir "exists.not" seq "OK") (* 960619 e -- why? *)
  81.             handle _ => "WRONG,"
  82.                         ^ (if access("exists.not", [A_READ, A_EXEC, A_WRITE])
  83.                            then let val _ = suspend 3000 (* 2 to 3 sec. *)
  84.                                 in "Found," end
  85.                            else "Missing,")
  86.                         ^ ((rmDir "exists.not" seq "OK")
  87.                             handle _ => "WRONG,"
  88.                         ^ (if access("exists.not", [A_READ, A_EXEC, A_WRITE])
  89.                            then let val _ = suspend 3000 (* 2 to 3 sec. *)
  90.                                 in "Found," end
  91.                            else "Missing,")
  92.                         ^ ((rmDir "exists.not" seq "OK")
  93.                             handle _ => "WRONG"));
  94.  
  95. val test6a = (openDir "exists.not" seq "WRONG") 
  96.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  97. val test6b = (isDir "exists.not" seq "WRONG")
  98.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  99. val test6c = (rmDir "exists.not" seq "WRONG")
  100.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  101. val test6d = (chDir "exists.not" seq "WRONG")
  102.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  103. val test6e = (fullPath "exists.not" seq "WRONG")
  104.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  105. val test6f = (realPath "exists.not" seq "WRONG")
  106.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  107. val test6g = (modTime "exists.not" seq "WRONG")
  108.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  109. val test6h = (setTime("exists.not", NONE) seq "WRONG")
  110.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  111. val test6i = (remove "exists.not" seq "WRONG")
  112.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  113. val test6j = (rename{old="exists.not", new="testdir2"} seq "WRONG")
  114.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  115. val test6k = (fileSize "exists.not" seq "WRONG")
  116.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  117. val test6l = check'(fn _ => not (access("exists.not", [])));
  118.  
  119. val _ = mkDir "testdir";
  120.  
  121. local 
  122.     val dstr = openDir "testdir";
  123. in
  124.     val test7a = 
  125.         check'(fn _ => (* ":" = readDir dstr
  126.                andalso "::" = readDir dstr
  127.                andalso *) "" = readDir dstr);
  128.     val _ = rewindDir dstr;
  129.     val test7b = 
  130.         check'(fn _ => (* ":" = readDir dstr
  131.                andalso "::" = readDir dstr
  132.                andalso *) "" = readDir dstr);
  133.     val _ = closeDir dstr;
  134.     val test7c = (readDir dstr seq "WRONG")
  135.                  handle OS.SysErr _ => "OK" | _ => "WRONG";
  136.     val test7d = (rewindDir dstr seq "WRONG")
  137.                  handle OS.SysErr _ => "OK" | _ => "WRONG";
  138.     val test7e = (closeDir dstr seq "OK")
  139.                  handle _ => "WRONG"
  140. end
  141.  
  142. val test8a = 
  143.     check'(fn _ => fullPath ":" = getDir ());
  144. val test8b = 
  145.     check'(fn _ => fullPath "testlink" = getDir() ^ ":README");
  146. val test8c = (fullPath "testcycl" seq "WRONG")
  147.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  148. val test8d = (fullPath "testbadl" seq "WRONG")
  149.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  150. val test8e = 
  151.     check'(fn _ => realPath ":" = ":");
  152. val test8f = 
  153.     check'(fn _ => realPath "testlink" = "README");
  154. val test8g = (realPath "testcycl" seq "WRONG")
  155.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  156. val test8h = (realPath "testbadl" seq "WRONG")
  157.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  158.  
  159. val test9a = 
  160.     check'(fn _ => 
  161.            setTime ("README", SOME (Time.fromReal 1E6)) = ());
  162. val test9b = 
  163.     check'(fn _ => modTime "README" = Time.fromReal 1E6);
  164.     
  165. (* -- e
  166. val test10a = (remove "testdir" seq "WRONG")
  167.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  168. *)
  169. val test10a = "WRONG, because remove removes directories.";
  170. val test10b = 
  171.     check'(fn _ => 
  172.            rename{old = "testdir", new = "testdir2"} = ());
  173. val test10c = 
  174.     check'(fn _ => isDir "testdir2");
  175.  
  176. val test11a = 
  177.     check'(fn _ => not (access ("testdir", [])));
  178. val test11b = 
  179.     check'(fn _ => access("testlink", []));
  180. val test11c = 
  181.     check'(fn _ => not (access("testbadl", [])));
  182.  
  183. val test12a = 
  184.     check'(fn _ => (* isLink "testcycl" 
  185.            andalso *)  isLink "testlink"
  186.            andalso isLink "testbadl");
  187. val test12b = 
  188.     check'(fn _ => not (isLink "testdir2"
  189.                         orelse isLink "README"));
  190. val test12c = (isLink "exists.not" seq "WRONG")
  191.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  192.  
  193. val test13a = 
  194.     check'(fn _ => readLink "testcycl" = "testcycl");
  195. val test13b = 
  196.     check'(fn _ => readLink "testlink" = ":README");
  197. val test13c = 
  198.     check'(fn _ => readLink "testbadl" = "exists.not");
  199. val test13d = (readLink "testdir2" seq "WRONG")
  200.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  201. val test13e = (readLink "exists.not" seq "WRONG")
  202.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  203.  
  204. val test14 = (tmpName () seq "OK");
  205.  
  206. val test15a = 
  207.     check'(fn _ => 
  208.            fileId ":" = fileId ":"
  209.            andalso fileId "testlink" = fileId "README"
  210.            andalso fileId ":" <> fileId "README");
  211. val test15b = 
  212.     check'(fn _ => compare(fileId ":", fileId ":") = EQUAL
  213.            andalso compare(fileId ":", fileId "README") <> EQUAL
  214.            andalso compare(fileId "testlink", fileId "README") = EQUAL
  215.            andalso (compare(fileId ":", fileId "README") = LESS 
  216.                     andalso compare(fileId "README", fileId ":") = GREATER
  217.                     orelse 
  218.                     compare(fileId ":", fileId "README") = GREATER 
  219.                     andalso compare(fileId "README", fileId ":") = LESS));
  220. val test15c = (fileId "exists.not" seq "WRONG")
  221.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  222. val test15d = (fileId "testbadl" seq "WRONG")
  223.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  224. val test15e = (fileId "testcycl" seq "WRONG")
  225.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  226. (* Unix only: *)
  227. (*
  228. val test15f = 
  229.        check'(fn _ => 
  230.            fileId "hardlinkA" = fileId "hardlinkB"
  231.            andalso compare(fileId "hardlinkA", fileId "hardlinkB") = EQUAL);
  232. *)
  233. val _ = rmDir "testdir2";
  234. end
  235.