3 -- Grant of Unlimited Rights
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
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.
27 -- Check that if X denotes a scalar object, X'Valid
28 -- yields true if an only if the object denoted by X is normal and
29 -- has a valid representation.
32 -- Using Unchecked_Conversion, Image and Value attributes, combined
33 -- with string manipulation, cause valid and invalid values to be
34 -- stored in various objects. Check their validity with the
35 -- attribute 'Valid. Invalid objects are created in a loop which
36 -- performs a simplistic check to ensure that the values being used
37 -- are indeed not valid, then assigns the value using an instance of
38 -- Unchecked_Conversion. The creation of the tables of valid values
41 -- APPLICABILITY CRITERIA:
42 -- All implementations must attempt to compile this test.
44 -- For implementations validating against Systems Programming Annex (C):
45 -- this test must execute and report PASSED.
47 -- For implementations not validating against Annex C:
48 -- this test may report compile time errors at one or more points
49 -- indicated by "-- N/A => ERROR", in which case it may be graded as
50 -- inapplicable. Otherwise, the test must execute and report PASSED.
54 -- 10 MAY 95 SAIC Initial version
55 -- 07 MAY 96 SAIC Changed U_C to Ada.U_C for 2.1
56 -- 05 JAN 99 RLB Added Component_Size clauses to compensate
57 -- for the fact that there is no required size
58 -- for either the enumeration or modular components.
62 with Ada
.Unchecked_Conversion
;
66 type Sparse_Enumerated
is
67 ( Help
, Home
, Page_Up
, Del
, EndK
,
68 Page_Down
, Up
, Left
, Down
, Right
);
70 for Sparse_Enumerated
use ( Help
=> 2,
81 type Mod_10
is mod 10;
83 type Default_Enumerated
is ( Zero
, One
, Two
, Three
, Four
,
84 Five
, Six
, Seven
, Eight
, Nine
,
85 Clear
, '=', '/', '*', '-',
87 for Default_Enumerated
'Size use 8;
89 Default_Enumerated_Count
: constant := 17;
91 type Mod_By_Enum_Items
is mod Default_Enumerated_Count
;
93 type Mod_Same_Size_As_Sparse_Enum
is mod 2**12;
94 -- Sparse_Enumerated 'Size;
96 type Mod_Same_Size_As_Def_Enum
is mod 2**8;
97 -- Default_Enumerated'Size;
99 subtype Test_Width
is Positive range 1..100;
101 -- Note: There is no required relationship between 'Size and 'Component_Size,
102 -- so we must use component_size clauses here.
103 -- We use the following expressions to insure that the component size is a
104 -- multiple of the Storage_Unit.
105 Sparse_Component_Size
: constant := ((Sparse_Enumerated
'Size / System
.Storage_Unit
) +
106 Boolean'Pos((Sparse_Enumerated
'Size mod System
.Storage_Unit
) /= 0)) *
108 Default_Component_Size
: constant := ((Default_Enumerated
'Size / System
.Storage_Unit
) +
109 Boolean'Pos((Sparse_Enumerated
'Size mod System
.Storage_Unit
) /= 0)) *
112 type Sparse_Enum_Table
is array(Test_Width
) of Sparse_Enumerated
;
113 for Sparse_Enum_Table
'Component_Size use Sparse_Component_Size
; -- N/A => ERROR.
114 type Def_Enum_Table
is array(Test_Width
) of Default_Enumerated
;
115 for Def_Enum_Table
'Component_Size use Default_Component_Size
; -- N/A => ERROR.
117 type Sparse_Mod_Table
is
118 array(Test_Width
) of Mod_Same_Size_As_Sparse_Enum
;
119 for Sparse_Mod_Table
'Component_Size use Sparse_Component_Size
; -- N/A => ERROR.
121 type Default_Mod_Table
is
122 array(Test_Width
) of Mod_Same_Size_As_Def_Enum
;
123 for Default_Mod_Table
'Component_Size use Default_Component_Size
; -- N/A => ERROR.
125 function UC_Sparse_Mod_Enum
is
126 new Ada
.Unchecked_Conversion
( Sparse_Mod_Table
, Sparse_Enum_Table
);
128 function UC_Def_Mod_Enum
is
129 new Ada
.Unchecked_Conversion
( Default_Mod_Table
, Def_Enum_Table
);
131 Valid_Sparse_Values
: Sparse_Enum_Table
;
132 Valid_Def_Values
: Def_Enum_Table
;
134 Sample_Enum_Value_Table
: Sparse_Mod_Table
;
135 Sample_Def_Value_Table
: Default_Mod_Table
;
138 -- fill the Valid tables with valid values for conversion
139 procedure Fill_Valid
is
141 P
: Mod_By_Enum_Items
:= 0;
143 for I
in Test_Width
loop
144 Valid_Sparse_Values
(I
) := Sparse_Enumerated
'Val( K
);
145 Valid_Def_Values
(I
) := Default_Enumerated
'Val( Integer(P
) );
151 -- fill the Sample tables with invalid values for conversion
152 procedure Fill_Invalid
is
153 K
: Mod_Same_Size_As_Sparse_Enum
:= 1;
154 P
: Mod_Same_Size_As_Def_Enum
:= 1;
156 for I
in Test_Width
loop
158 if K
mod 2 = 0 then -- oops, that would be a valid value
161 if P
= Mod_Same_Size_As_Def_Enum
'Last
162 or P
< Default_Enumerated_Count
then -- that would be valid
163 P
:= Default_Enumerated_Count
+ 1;
167 Sample_Enum_Value_Table
(I
) := K
;
168 Sample_Def_Value_Table
(I
) := P
;
171 Valid_Sparse_Values
:= UC_Sparse_Mod_Enum
(Sample_Enum_Value_Table
);
172 Valid_Def_Values
:= UC_Def_Mod_Enum
(Sample_Def_Value_Table
);
176 -- fill the tables with second set of valid values for conversion
177 procedure Refill_Valid
is
179 P
: Mod_By_Enum_Items
:= 0;
181 Table
: Array(Mod_10
) of Mod_Same_Size_As_Sparse_Enum
182 := ( 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 );
185 for I
in Test_Width
loop
186 Sample_Enum_Value_Table
(I
) := Table
(K
);
187 Sample_Def_Value_Table
(I
) := Mod_Same_Size_As_Def_Enum
(P
);
191 Valid_Sparse_Values
:= UC_Sparse_Mod_Enum
(Sample_Enum_Value_Table
);
192 Valid_Def_Values
:= UC_Def_Mod_Enum
(Sample_Def_Value_Table
);
195 procedure Validate
(Expect_Valid
: Boolean) is
196 begin -- here's where we actually use the tested attribute
198 for K
in Test_Width
loop
199 if Valid_Sparse_Values
(K
)'Valid /= Expect_Valid
then
200 Report
.Failed
("Expected 'Valid =" & Boolean'Image(Expect_Valid
)
201 & " for Sparse item " & Integer'Image(K
) );
205 for P
in Test_Width
loop
206 if Valid_Def_Values
(P
)'Valid /= Expect_Valid
then
207 Report
.Failed
("Expected 'Valid =" & Boolean'Image(Expect_Valid
)
208 & " for Default item " & Integer'Image(P
) );
214 begin -- Main test procedure.
216 Report
.Test
("CD92001", "Check object attribute: X'Valid" );