aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats-4/tests/ca/ca21002.a
blob: 60be00fef481886ecf93120b2e41c2f60d0f5dbe (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
-- CA21002.A
--
--                             Grant of Unlimited Rights
--
--     The Ada Conformity Assessment Authority (ACAA) holds unlimited
--     rights in the software and documentation contained herein. Unlimited
--     rights are the same as those granted by the U.S. Government for older
--     parts of the Ada Conformity Assessment Test Suite, and are defined
--     in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
--     intends to confer upon all recipients unlimited rights equal to those
--     held by the ACAA. These rights include rights to use, duplicate,
--     release or disclose the released technical data and computer software
--     in whole or in part, in any manner and for any purpose whatsoever, and
--     to have or permit others to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS. THE ACAA MAKES NO EXPRESS OR IMPLIED
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--
--                                     Notice
--
--     The ACAA has created and maintains the Ada Conformity Assessment Test
--     Suite for the purpose of conformity assessments conducted in accordance
--     with the International Standard ISO/IEC 18009 - Ada: Conformity
--     assessment of a language processor. This test suite should not be used
--     to make claims of conformance unless used in accordance with
--     ISO/IEC 18009 and any applicable ACAA procedures.
--
--*
-- OBJECTIVE:
--     Check that the categorization aspects Pure and Preelaborate can
--     be specified by a constant in another package.
--
--     Check that the categorization aspects Pure and Preelaborate can
--     specified as False, in which case they have no effect.
--
-- TEST DESCRIPTION:
--     We imagine that a subsystem of related packages are all specified
--     Pure (resp. Preelaborate) via an external constant, which allows
--     their categorization to be changed as a group by changing the constant.
--     Further, we imagine that the categorization has been turned off
--     to add some debugging code (emulated in this test by package Report)
--     that doesn't have the appropriate categorization. (After the debugging
--     is completed, the debugging code would be removed or commented out,
--     and the flag changed to True to re-apply the categorization.)
--
--     We try two subsystems, one for Pure and one for Preelaborate.
--
--     Note that the test can act as a kind of B-Test by changing the
--     values of the constants Is_Pure and Is_Preelab to True; the
--     withs of Report in the packages should be rejected in that case.
--
-- CHANGE HISTORY:
--     18 Feb 2015  RLB  Created test.
--
--!
package CA21002_Consts is
   Is_Pure    : constant Boolean := False;
   Is_Preelab : constant Boolean := False;
end CA21002_Consts;

with CA21002_Consts;
package CA21002_Pure1 with Pure => CA21002_Consts.Is_Pure is

   function Double (I : in Integer) return Integer;

end CA21002_Pure1;

with Report; -- OK only if Is_Pure = False.
package body CA21002_Pure1 is

   function Double (I : in Integer) return Integer is
   begin
      Report.Comment ("In Pure1.Double");
      return I * 2;
   end Double;

end CA21002_Pure1;

with CA21002_Consts;
package CA21002_Pure2 with Pure => CA21002_Consts.Is_Pure is

   function Quad (I : in Integer) return Integer;

end CA21002_Pure2;

with CA21002_Pure1;
package body CA21002_Pure2 is

   function Quad (I : in Integer) return Integer is
   begin
      return CA21002_Pure1.Double(I) * 2;
   end Quad;

end CA21002_Pure2;

with CA21002_Consts;
package CA21002_Preelab1 with Preelaborate => CA21002_Consts.Is_Preelab is

   procedure Triple (Val : in out Integer);

end CA21002_Preelab1;

with Report; -- OK only if Is_Preelab = False.
package body CA21002_Preelab1 is

   procedure Triple (Val : in out Integer) is
   begin
      Report.Comment ("In Preelab1.Triple with" & Integer'Image(Val));
      Val := Val * 3;
   end Triple;

end CA21002_Preelab1;

with CA21002_Consts;
package CA21002_Preelab2 with Preelaborate => CA21002_Consts.Is_Preelab is

   procedure Hex (Val : in out Integer);

end CA21002_Preelab2;

with CA21002_Preelab1;
package body CA21002_Preelab2 is

   procedure Hex (Val : in out Integer) is
   begin
      CA21002_Preelab1.Triple (Val);
      Val := Val * 2;
   end Hex;

end CA21002_Preelab2;

with CA21002_Pure2, CA21002_Preelab2, Report;
procedure CA21002 is
   Val : Integer := Report.Ident_Int (4);
begin
   Report.Test ("CA21002", "Check that the categorization aspects Pure and " &
                           "Preelaborate can be specified by a constant in " &
                           "another package. Check that the categorization " &
                           "aspects Pure and Preelaborate can specified as " &
                           "False, in which case they have no effect");

   CA21002_Preelab2.Hex (Val);
   if Val /= 24 then
      Report.Failed ("Wrong result - Hex (1)");
   end if;

   Val := CA21002_Pure2.Quad (12);
   if Val /= 48 then
      Report.Failed ("Wrong result - Quad (1)");
   end if;

   Val := Report.Ident_Int (52);
   CA21002_Preelab2.Hex (Val);
   if Val /= 312 then
      Report.Failed ("Wrong result - Hex (2)");
   end if;

   Report.Result;
end CA21002;