1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNATCOLL.VFS; use GNATCOLL.VFS;
with Ada.Text_IO; use Ada.Text_IO;
with Test_Assert;
function Test return Integer is
package A renames Test_Assert;
DS : constant Character := GNAT.OS_Lib.Directory_Separator;
Folder : Virtual_File;
F : Virtual_File;
begin
------------
-- Case 1 --
------------
-- Using a directory that is not a full name (and where the .. cannot
-- be resolved)
Folder := Create (+".." & DS & ".." & DS & "foo" & DS);
F := Create_From_Dir
(Dir => Folder, Base_name => +"file.ads");
A.Assert (".." & DS & ".." & DS & "foo" & DS & "file.ads",
F.Display_Full_Name,
"With base name and relative directory");
A.Assert (".." & DS & ".." & DS & "foo" & DS & "file.ads",
F.Display_Full_Name (Normalize => True),
"Normalized with base name and relative directory");
F := Create_From_Dir
(Dir => Folder, Base_name => +"file.ads", Normalize => True);
A.Assert (".." & DS & ".." & DS & "foo" & DS & "file.ads",
F.Display_Full_Name,
"With base name and relative directory");
A.Assert (".." & DS & ".." & DS & "foo" & DS & "file.ads",
F.Display_Full_Name (Normalize => True),
"Normalized with base name and relative directory");
------------
-- Case 2 --
------------
Folder := Create (+"foo1" & DS & "foo2" & DS & "foo3" & DS & "");
F := Create_From_Dir
(Dir => Folder, Base_name => +".." & DS & ".." & DS & "file.ads");
A.Assert ("foo1" & DS & "foo2" & DS & "foo3" & DS
& ".." & DS & ".." & DS & "file.ads",
F.Display_Full_Name,
"When file is relative to absolute directory");
A.Assert ("foo1" & DS & "file.ads",
F.Display_Full_Name (Normalize => True),
"Normalized name when file is relative to absolute directory");
F := Create_From_Dir (
Dir => Folder, Base_name => +".." & DS & ".." & DS & "file.ads",
Normalize => True);
A.Assert ("foo1" & DS & "foo2" & DS & "foo3" & DS & ".."
& DS & ".." & DS & "file.ads",
F.Display_Full_Name,
"When file is relative to normalized absolute directory");
A.Assert ("foo1" & DS & "file.ads",
F.Display_Full_Name (Normalize => True),
"Normalized name when file is relative to normalized absolute"
& " directory");
------------
-- Case 3 --
------------
-- Using an absolute directory, where the .. can be resolved
Folder := Create
(+"" & DS & "foo1" & DS & "foo2" & DS & "foo3" & DS
& ".." & DS & ".." & DS & "foo" & DS & "");
F := Create_From_Dir
(Dir => Folder, Base_name => +"file.ads");
A.Assert ("" & DS & "foo1" & DS & "foo2" & DS & "foo3" & DS & ".."
& DS & ".." & DS & "foo" & DS & "file.ads",
F.Display_Full_Name,
"When file is relative to absolute directory with ..");
A.Assert ("" & DS & "foo1" & DS & "foo" & DS & "file.ads",
F.Display_Full_Name (Normalize => True),
"Normalized name when file is relative to absolute directory"
& " with ..");
F := Create_From_Dir
(Dir => Folder, Base_name => +"file.ads", Normalize => True);
A.Assert ("" & DS & "foo1" & DS & "foo" & DS & "file.ads",
F.Display_Full_Name,
"When file is relative to normalized absolute directory with ..");
A.Assert ("" & DS & "foo1" & DS & "foo" & DS & "file.ads",
F.Display_Full_Name (Normalize => True),
"Normalized name when file is relative to normalized absolute"
& " directory with ..");
-- Check Create_From_Dir with a No_File entry
declare
Test_Success : Boolean := False;
begin
begin
F := Create_From_Dir (No_File, +"file.ads");
exception
when VFS_Invalid_File_Error =>
Test_Success := True;
end;
A.Assert (Test_Success, "Should raise Invalid_File_Error");
end;
return A.Report;
end Test;
|