Debian Codegraph @

gcc/testsuite/ada/acats/tests/cxa/cxaf001.a

raw
1 -- CXAF001.A
2 --
3 -- Grant of Unlimited Rights
4 --
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
14 -- to do so.
15 --
16 -- DISCLAIMER
17 --
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
24 --*
25 --
26 -- OBJECTIVE:
27 -- Check that an implementation supports the functionality defined
28 -- in Package Ada.Command_Line.
29 --
30 -- TEST DESCRIPTION:
31 -- This test verifies that an implementation supports the subprograms
32 -- contained in package Ada.Command_Line. Each of the subprograms
33 -- is exercised in a general sense, to ensure that it is available,
34 -- and that it provides the prescribed results in a known test
35 -- environment. Function Argument_Count must return zero, or the
36 -- number of arguments passed to the program calling it. Function
37 -- Argument is called with a parameter value one greater than the
38 -- actual number of arguments passed to the executing program, which
39 -- must result in Constraint_Error being raised. Function Command_Name
40 -- should return the name of the executing program that called it
41 -- (specifically, this test name). Function Set_Exit_Status is called
42 -- with two different parameter values, the constants Failure and
43 -- Success defined in package Ada.Command_Line.
44 --
45 -- The setting of the variable TC_Verbose allows for some additional
46 -- output to be displayed during the running of the test as an aid in
47 -- tracing the processing flow of the test.
48 --
49 -- APPLICABILITY CRITERIA:
50 -- This test is applicable to implementations that support the
51 -- declaration of package Command_Line as defined in the Ada Reference
52 -- manual.
53 -- An alternative declaration is allowed for package Command_Line if
54 -- different functionality is appropriate for the external execution
55 -- environment.
56 --
57 --
58 -- CHANGE HISTORY:
59 -- 10 Jul 95 SAIC Initial prerelease version.
60 -- 02 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
61 -- 05 AUG 98 EDS Allow Null string result to be returned from
62 -- Function Command
63 --!
64
65 with Ada.Command_Line;
66 with Ada.Exceptions;
67 with Report;
68
69 procedure CXAF001 is
70 begin
71
72 Report.Test ("CXAF001", "Check that an implementation supports the " &
73 "functionality defined in Package " &
74 "Ada.Command_Line");
75
76 Test_Block:
77 declare
78
79 use Ada.Exceptions;
80
81 type String_Access is access all String;
82
83 TC_Verbose : Boolean := False;
84 Number_Of_Arguments : Natural := Natural'Last;
85 Name_Of_Command : String_Access;
86
87 begin
88
89 -- Check the result of function Argument_Count.
90 -- Note: If the external environment does not support passing arguments
91 -- to the program invoking the function, the function result
92 -- will be zero.
93
94 Number_Of_Arguments := Ada.Command_Line.Argument_Count;
95 if Number_Of_Arguments = Natural'Last then
96 Report.Failed("Argument_Count did not provide a return result");
97 end if;
98 if TC_Verbose then
99 Report.Comment
100 ("Argument_Count = " & Integer'Image(Number_Of_Arguments));
101 end if;
102
103
104 -- Check that the result of Function Argument is Constraint_Error
105 -- when the Number argument is outside the range of 1..Argument_Count.
106
107 Test_Function_Argument_1 :
108 begin
109 declare
110
111 -- Define a value that will be outside the range of
112 -- 1..Argument_Count.
113 -- Note: If the external execution environment does not support
114 -- passing arguments to a program, then Argument(N) for
115 -- any N will raise Constraint_Error, since
116 -- Argument_Count = 0;
117
118 Arguments_Plus_One : Positive :=
119 Ada.Command_Line.Argument_Count + 1;
120
121 -- Using the above value in a call to Argument must result in
122 -- the raising of Constraint_Error.
123
124 Argument_String : constant String :=
125 Ada.Command_Line.Argument(Arguments_Plus_One);
126
127 begin
128 Report.Failed("Constraint_Error not raised by Function " &
129 "Argument when provided a Number argument " &
130 "out of range");
131 end;
132 exception
133 when Constraint_Error => null; -- OK, expected exception.
134 if TC_Verbose then
135 Report.Comment ("Argument_Count raised Constraint_Error");
136 end if;
137 when others =>
138 Report.Failed ("Unexpected exception raised by Argument " &
139 "in Test_Function_Argument_1 block");
140 end Test_Function_Argument_1;
141
142
143 -- Check that Function Argument returns a string result.
144
145 Test_Function_Argument_2 :
146 begin
147 if Ada.Command_Line.Argument_Count > 0 then
148 Report.Comment
149 ("Last argument is: " &
150 Ada.Command_Line.Argument(Ada.Command_Line.Argument_Count));
151 elsif TC_Verbose then
152 Report.Comment("Argument_Count is zero, no test of Function " &
153 "Argument for string result");
154 end if;
155 exception
156 when others =>
157 Report.Failed ("Unexpected exception raised by Argument " &
158 "in Test_Function_Argument_2 block");
159 end Test_Function_Argument_2;
160
161
162 -- Check the result of Function Command_Name.
163
164 Name_Of_Command := new String'(Ada.Command_Line.Command_Name);
165
166 if Name_Of_Command = null then
167 Report.Failed("Null string pointer returned from Function Command");
168 elsif Name_Of_Command.all = "" then
169 Report.Comment("Null string result returned from Function Command");
170 elsif TC_Verbose then
171 Report.Comment("Invoking command is " & Name_Of_Command.all);
172 end if;
173
174
175 -- Check that procedure Set_Exit_Status is available.
176 -- Note: If the external execution environment does not support
177 -- returning an exit value from a program, then Set_Exit_Status
178 -- does nothing.
179
180 Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
181 if TC_Verbose then
182 Report.Comment("Exit status set to Failure");
183 end if;
184
185 Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Success);
186 if TC_Verbose then
187 Report.Comment("Exit status set to Success");
188 end if;
189
190
191 exception
192 when The_Error : others =>
193 Report.Failed ("The following exception was raised in the " &
194 "Test_Block: " & Exception_Name(The_Error));
195 end Test_Block;
196
197 Report.Result;
198
199 end CXAF001;