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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 | -- Abstract :
--
-- See spec
--
-- Copyright (C) 2003, 2004, 2008, 2009, 2015 Stephen Leake. All Rights Reserved.
--
-- This program is free software; you can redistribute it and/or
-- modify it under terms of the GNU General Public License as
-- published by the Free Software Foundation; either version 3, or (at
-- your option) any later version. This program is distributed in the
-- hope that it will be useful, but WITHOUT ANY WARRANTY; without even
-- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU General Public License for more details. You
-- should have received a copy of the GNU General Public License
-- distributed with this program; see file COPYING. If not, write to
-- the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-- MA 02111-1307, USA.
pragma License (GPL);
with AUnit.Assertions;
with Ada.Environment_Variables;
with Ada.Exceptions;
with Ada.IO_Exceptions;
with Ada.Text_IO;
with GNAT.OS_Lib;
with SAL.Config_Files; use SAL.Config_Files;
with SAL.File_Names;
package body Test.Config_Files.Abs_File is
procedure Test_Env_Var (T : in out AUnit.Test_Cases.Test_Case'Class)
is
pragma Unreferenced (T);
begin
Ada.Environment_Variables.Set ("SAL_TEST_FILE", "test-config_files-abs.config");
declare
Expanded_File_Name : constant String := SAL.File_Names.Replace_Environment_Variables ("$SAL_TEST_FILE");
Abs_File_Name : constant String := GNAT.OS_Lib.Normalize_Pathname (Expanded_File_Name);
Config : Configuration_Type;
begin
-- Delete Abs_File_Name if it exists, to erase previous tests.
declare
use Ada.Text_IO;
File : File_Type;
begin
Open (File, In_File, Abs_File_Name);
Delete (File);
exception
when Ada.IO_Exceptions.Name_Error =>
null;
end;
begin
Open (Config, Abs_File_Name, Missing_File => Ignore, Read_Only => False);
Write (Config, "Hello", "Hello");
Close (Config);
AUnit.Assertions.Assert (True, ""); -- Just count the test
exception
when E : others =>
AUnit.Assertions.Assert (False, "unexpected exceptions raised: " & Ada.Exceptions.Exception_Name (E));
end;
-- Cleanup; delete file
declare
use Ada.Text_IO;
File : File_Type;
begin
Open (File, In_File, Abs_File_Name);
Delete (File);
end;
end;
end Test_Env_Var;
procedure Test_Open_Close (T : in out AUnit.Test_Cases.Test_Case'Class)
is
pragma Unreferenced (T);
File_Name : constant String := "test-config_files-abs.config";
Abs_File_Name : constant String := GNAT.OS_Lib.Normalize_Pathname (File_Name);
Config : Configuration_Type;
begin
-- Delete Abs_File_Name if it exists, to erase previous tests.
declare
use Ada.Text_IO;
File : File_Type;
begin
Open (File, In_File, Abs_File_Name);
Delete (File);
exception
when Ada.IO_Exceptions.Name_Error =>
null;
end;
begin
Open (Config, File_Name, Missing_File => Ignore, Read_Only => False);
Write (Config, "Hello", "Hello");
Close (Config);
AUnit.Assertions.Assert (True, ""); -- Just count the test
exception
when others =>
AUnit.Assertions.Assert (False, "unexpected exceptions raised");
end;
-- Cleanup; delete file
declare
use Ada.Text_IO;
File : File_Type;
begin
Open (File, In_File, File_Name);
Delete (File);
end;
end Test_Open_Close;
----------
-- public bodies
overriding function Name (T : Test_Case) return AUnit.Message_String
is
pragma Unreferenced (T);
begin
return new String'("Test.Config_Files.Abs_File");
end Name;
overriding procedure Register_Tests (T : in out Test_Case)
is
use AUnit.Test_Cases.Registration;
begin
Register_Routine (T, Test_Env_Var'Access, "Test_Env_Var");
Register_Routine (T, Test_Open_Close'Access, "Test_Open_Close");
end Register_Tests;
end Test.Config_Files.Abs_File;
|