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