Debian Codegraph @

gcc/testsuite/ada/acats/support/tctouch.ada

raw
1 -- TCTouch.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 -- FOUNDATION DESCRIPTION:
27 -- The tools in this foundation are not peculiar to any particular
28 -- aspect of the language, but simplify the test writing and reading
29 -- process. Assert and Assert_Not are used to reduce the textual
30 -- overhead of the test-that-this-condition-is-(not)-true paradigm.
31 -- Touch and Validate are used to simplify tracing an expected path
32 -- of execution.
33 -- A tag comment of the form:
34 --
35 -- TCTouch.Touch( 'A' ); ----------------------------------------- A
36 --
37 -- is recommended to improve readability of this feature.
38 --
39 -- Report.Test must be called before any of the procedures in this
40 -- package with the exception of Touch.
41 -- The usage paradigm is to call Touch in locations in the test where you
42 -- want a trace of execution. Each call to Touch should have a unique
43 -- character associated with it. At each place where a check can
44 -- reasonably be performed to determine correct execution of a
45 -- sub-test, a call to Validate should be made. The first parameter
46 -- passed to Validate is the expected string of characters produced by
47 -- call(s) to Touch in the subtest just executed. The second parameter
48 -- is the message to pass to Report.Failed if the expected sequence was
49 -- not executed.
50 --
51 -- Validate should always be called after calls to Touch before a test
52 -- completes.
53 --
54 -- In the event that calls may have been made to Touch that are not
55 -- intended to be recorded, or, the failure of a previous subtest may
56 -- leave Touch calls "Unvalidated", the procedure Flush will reset the
57 -- tracker to the "empty" state. Flush does not make any calls to
58 -- Report.
59 --
60 -- Calls to Assert and Assert_Not are to replace the idiom:
61 --
62 -- if BadCondition then -- or if not PositiveTest then
63 -- Report.Failed(Message);
64 -- end if;
65 --
66 -- with:
67 --
68 -- Assert_Not( BadCondition, Message ); -- or
69 -- Assert( PositiveTest, Message );
70 --
71 -- Implementation_Check is for use with tests that cross the boundary
72 -- between the core and the Special Needs Annexes. There are several
73 -- instances where language in the core becomes enforceable only when
74 -- a Special Needs Annex is supported. Implementation_Check should be
75 -- called in place of Report.Failed in these cases; it examines the
76 -- constants in Impdef that indicate if the particular Special Needs
77 -- Annex is being validated with this validation; and acts accordingly.
78 --
79 -- The constant Foundation_ID contains the internal change version
80 -- for this software.
81 --
82 -- ERROR CONDITIONS:
83 --
84 -- It is an error to perform more than Max_Touch_Count (80) calls to
85 -- Touch without a subsequent call to Validate. To do so will cause
86 -- a false test failure.
87 --
88 -- CHANGE HISTORY:
89 -- 02 JUN 94 SAIC Initial version
90 -- 27 OCT 94 SAIC Revised version
91 -- 07 AUG 95 SAIC Added Implementation_Check
92 -- 07 FEB 96 SAIC Changed to match new Impdef for 2.1
93 -- 16 MAR 00 RLB Changed foundation id to reflect test suite version.
94 -- 22 MAR 01 RLB Changed foundation id to reflect test suite version.
95 -- 29 MAR 02 RLB Changed foundation id to reflect test suite version.
96 -- 06 MAR 07 RLB Changed foundation id to reflect test suite version.
97 --
98 --!
99
100 package TCTouch is
101 Foundation_ID : constant String := "TCTouch ACATS 2.6";
102 Max_Touch_Count : constant := 80;
103
104 procedure Assert ( SB_True : Boolean; Message : String );
105 procedure Assert_Not( SB_False : Boolean; Message : String );
106
107 procedure Touch ( A_Tag : Character );
108 procedure Validate( Expected: String;
109 Message : String;
110 Order_Meaningful : Boolean := True );
111
112 procedure Flush;
113
114 type Special_Needs_Annexes is ( Annex_C, Annex_D, Annex_E,
115 Annex_F, Annex_G, Annex_H );
116
117 procedure Implementation_Check( Message : in String;
118 Annex : in Special_Needs_Annexes
119 := Annex_C );
120 -- If Impdef.Validating_Annex_<Annex> is true, will call Report.Failed
121 -- otherwise will call Report.Not_Applicable. This is to allow tests
122 -- which are driven by wording in the core of the language, yet have
123 -- their functionality dictated by the Special Needs Annexes to perform
124 -- dual purpose.
125 -- The default of Annex_C for the Annex parameter is to support early
126 -- tests written with the assumption that Implementation_Check was
127 -- expressly for use with the Systems Programming Annex.
128
129 end TCTouch;
130
131 with Report;
132 with Impdef;
133 package body TCTouch is
134
135 procedure Assert( SB_True : Boolean; Message : String ) is
136 begin
137 if not SB_True then
138 Report.Failed( "Assertion failed: " & Message );
139 end if;
140 end Assert;
141
142 procedure Assert_Not( SB_False : Boolean; Message : String ) is
143 begin
144 if SB_False then
145 Report.Failed( "Assertion failed: " & Message );
146 end if;
147 end Assert_Not;
148
149 Collection : String(1..Max_Touch_Count);
150 Finger : Natural := 0;
151
152 procedure Touch ( A_Tag : Character ) is
153 begin
154 Finger := Finger+1;
155 Collection(Finger) := A_Tag;
156 exception
157 when Constraint_Error =>
158 Report.Failed("Trace Overflow: " & Collection);
159 Finger := 0;
160 end Touch;
161
162 procedure Sort_String( S: in out String ) is
163 -- algorithm from Booch Components Page 472
164 No_Swaps : Boolean;
165 procedure Swap(C1, C2: in out Character) is
166 T: Character := C1;
167 begin C1 := C2; C2 := T; end Swap;
168 begin
169 for OI in S'First+1..S'Last loop
170 No_Swaps := True;
171 for II in reverse OI..S'Last loop
172 if S(II) < S(II-1) then
173 Swap(S(II),S(II-1));
174 No_Swaps := False;
175 end if;
176 end loop;
177 exit when No_Swaps;
178 end loop;
179 end Sort_String;
180
181 procedure Validate( Expected: String;
182 Message : String;
183 Order_Meaningful : Boolean := True) is
184 Want : String(1..Expected'Length) := Expected;
185 begin
186 if not Order_Meaningful then
187 Sort_String( Want );
188 Sort_String( Collection(1..Finger) );
189 end if;
190 if Collection(1..Finger) /= Want then
191 Report.Failed( Message & " Expecting: " & Want
192 & " Got: " & Collection(1..Finger) );
193 end if;
194 Finger := 0;
195 end Validate;
196
197 procedure Flush is
198 begin
199 Finger := 0;
200 end Flush;
201
202 procedure Implementation_Check( Message : in String;
203 Annex : in Special_Needs_Annexes
204 := Annex_C ) is
205 -- default to cover some legacy
206 -- USAGE DISCIPLINE:
207 -- Implementation_Check is designed to be used in tests that have
208 -- interdependency on one of the Special Needs Annexes, yet are _really_
209 -- tests based in the core language. There will be instances where the
210 -- execution of a test would be failing in the light of the requirements
211 -- of the annex, yet from the point of view of the core language without
212 -- the additional requirements of the annex, the test does not apply.
213 -- In these cases, rather than issuing a call to Report.Failed, calling
214 -- TCTouch.Implementation_Check will check that sensitivity, and if
215 -- the implementation is attempting to validate against the specific
216 -- annex, Report.Failed will be called, otherwise, Report.Not_Applicable
217 -- will be called.
218 begin
219
220 case Annex is
221 when Annex_C =>
222 if ImpDef.Validating_Annex_C then
223 Report.Failed( Message );
224 else
225 Report.Not_Applicable( Message & " Annex C not supported" );
226 end if;
227
228 when Annex_D =>
229 if ImpDef.Validating_Annex_D then
230 Report.Failed( Message );
231 else
232 Report.Not_Applicable( Message & " Annex D not supported" );
233 end if;
234
235 when Annex_E =>
236 if ImpDef.Validating_Annex_E then
237 Report.Failed( Message );
238 else
239 Report.Not_Applicable( Message & " Annex E not supported" );
240 end if;
241
242 when Annex_F =>
243 if ImpDef.Validating_Annex_F then
244 Report.Failed( Message );
245 else
246 Report.Not_Applicable( Message & " Annex F not supported" );
247 end if;
248
249 when Annex_G =>
250 if ImpDef.Validating_Annex_G then
251 Report.Failed( Message );
252 else
253 Report.Not_Applicable( Message & " Annex G not supported" );
254 end if;
255
256 when Annex_H =>
257 if ImpDef.Validating_Annex_H then
258 Report.Failed( Message );
259 else
260 Report.Not_Applicable( Message & " Annex H not supported" );
261 end if;
262 end case;
263 end Implementation_Check;
264
265 end TCTouch;