1-- C460014.A 2-- 3-- Grant of Unlimited Rights 4-- 5-- The Ada Conformity Assessment Authority (ACAA) holds unlimited 6-- rights in the software and documentation contained herein. Unlimited 7-- rights are the same as those granted by the U.S. Government for older 8-- parts of the Ada Conformity Assessment Test Suite, and are defined 9-- in DFAR 252.227-7013(a)(19). By making this public release, the ACAA 10-- intends to confer upon all recipients unlimited rights equal to those 11-- held by the ACAA. These rights include rights to use, duplicate, 12-- release or disclose the released technical data and computer software 13-- in whole or in part, in any manner and for any purpose whatsoever, and 14-- to have or permit others to do so. 15-- 16-- DISCLAIMER 17-- 18-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR 19-- DISCLOSED ARE AS IS. THE ACAA 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-- Notice 26-- 27-- The ACAA has created and maintains the Ada Conformity Assessment Test 28-- Suite for the purpose of conformity assessments conducted in accordance 29-- with the International Standard ISO/IEC 18009 - Ada: Conformity 30-- assessment of a language processor. This test suite should not be used 31-- to make claims of conformance unless used in accordance with 32-- ISO/IEC 18009 and any applicable ACAA procedures. 33--* 34-- OBJECTIVES: 35-- Check that if the operand type of a type conversion is 36-- access-to-class-wide, Constraint_Error is raised if the tag of the 37-- object designated by the operand does not identify a specific type 38-- that is covered by or descended from the target type. 39-- 40-- TEST DESCRIPTION: 41-- Attempt to convert a parameter of a type that designates a class-wide 42-- type to an object of a type that designates a specific member of that 43-- class, for both an actual with a different tag and an actual with a 44-- matching tag. 45-- 46-- This test checks 4.6(42) as required by 4.6(50). 47-- 48-- CHANGE HISTORY: 49-- 19 Aug 16 JAC Initial pre-release version. 50-- 19 Jan 17 RLB Readied for release: replaced objective, renamed 51-- to appropriate number, added class-wide cases, 52-- eliminated 11.6 problems, added third level of 53-- types, and checks on null. 54-- 55--! 56package C460014_1 is 57 type Root_Facade_Type is tagged record 58 Error_Code : Integer; 59 end record; 60 61 type Root_Facade_Ptr_Type is access all Root_Facade_Type; 62 63 type Facade_Class_Ptr_Type is access all Root_Facade_Type'Class; 64 65 type Data_A_Type is 66 record 67 A : Boolean; 68 end record; 69 70 type Facade_A_Type is new Root_Facade_Type with 71 record 72 Data_A : Data_A_Type; 73 end record; 74 75 type Facade_A_Ptr_Type is access all Facade_A_Type; 76 77 type Facade_A_Class_Ptr_Type is access all Facade_A_Type'Class; 78 79 type Facade_B_Type is new Facade_A_Type with 80 record 81 B : Character; 82 end record; 83 84 type Facade_B_Ptr_Type is access all Facade_B_Type; 85 86 type Facade_B_Class_Ptr_Type is access all Facade_B_Type'Class; 87 88 procedure Define_Construct 89 (Facade_Class_Ptr : in Facade_Class_Ptr_Type); 90 91 procedure Define_Class_Construct 92 (Facade_Class_Ptr : in Facade_Class_Ptr_Type); 93 94 function Init_Root_Facade_Ptr return Root_Facade_Ptr_Type; 95 96 function Init_Facade_A_Ptr return Facade_A_Ptr_Type; 97 98 function Init_Facade_B_Ptr return Facade_B_Ptr_Type; 99 100 function Init_Facade_Class_Ptr_with_Root return Facade_Class_Ptr_Type; 101 102 function Init_Facade_Class_Ptr_with_A return Facade_Class_Ptr_Type; 103 104 function Init_Facade_Class_Ptr_with_B return Facade_Class_Ptr_Type; 105 106end C460014_1; 107 108with Report; 109package body C460014_1 is 110 111 procedure Define_Construct 112 (Facade_Class_Ptr : in Facade_Class_Ptr_Type) is 113 114 Facade_A_Ptr : constant Facade_A_Ptr_Type := 115 Facade_A_Ptr_Type (Facade_Class_Ptr); 116 117 My_A : Data_A_Type renames Facade_A_Ptr.Data_A; 118 begin 119 if not My_A.A then 120 Report.Comment ("Wrong value"); -- So My_A is not dead by 11.6(5). 121 end if; 122 end Define_Construct; 123 124 procedure Define_Class_Construct 125 (Facade_Class_Ptr : in Facade_Class_Ptr_Type) is 126 127 Facade_Class_A_Ptr : constant Facade_A_Class_Ptr_Type := 128 Facade_A_Class_Ptr_Type (Facade_Class_Ptr); 129 130 begin 131 if Facade_Class_A_Ptr /= null and then 132 (not Facade_Class_A_Ptr.Data_A.A) then 133 Report.Comment ("Wrong value"); -- So the ptr is not dead by 11.6(5). 134 end if; 135 end Define_Class_Construct; 136 137 Dummy_Root_Facade : aliased Root_Facade_Type := (Error_Code => 123); 138 139 function Init_Root_Facade_Ptr return Root_Facade_Ptr_Type is 140 begin 141 return Dummy_Root_Facade'Access; 142 end Init_Root_Facade_Ptr; 143 144 Dummy_Facade_A : aliased Facade_A_Type := (Error_Code => 123, 145 Data_A => (A => True)); 146 147 function Init_Facade_A_Ptr return Facade_A_Ptr_Type is 148 begin 149 return Dummy_Facade_A'Access; 150 end Init_Facade_A_Ptr; 151 152 Dummy_Facade_B : aliased Facade_B_Type := (Error_Code => 234, 153 Data_A => (A => True), 154 B => 'P'); 155 156 function Init_Facade_B_Ptr return Facade_B_Ptr_Type is 157 begin 158 return Dummy_Facade_B'Access; 159 end Init_Facade_B_Ptr; 160 161 function Init_Facade_Class_Ptr_with_Root return Facade_Class_Ptr_Type is 162 begin 163 return Dummy_Root_Facade'Access; 164 end Init_Facade_Class_Ptr_with_Root; 165 166 function Init_Facade_Class_Ptr_with_A return Facade_Class_Ptr_Type is 167 begin 168 return Dummy_Facade_A'Access; 169 end Init_Facade_Class_Ptr_with_A; 170 171 function Init_Facade_Class_Ptr_with_B return Facade_Class_Ptr_Type is 172 begin 173 return Dummy_Facade_B'Access; 174 end Init_Facade_Class_Ptr_with_B; 175 176end C460014_1; 177 178 179with C460014_1; 180with Report; 181 182procedure C460014 is 183 184 My_Root_Facade_Ptr : constant C460014_1.Facade_Class_Ptr_Type := 185 C460014_1.Init_Facade_Class_Ptr_with_Root; 186 187 My_Facade_A_Ptr : constant C460014_1.Facade_Class_Ptr_Type := 188 C460014_1.Init_Facade_Class_Ptr_with_A; 189 190 My_Facade_B_Ptr : constant C460014_1.Facade_Class_Ptr_Type := 191 C460014_1.Init_Facade_Class_Ptr_with_B; 192 193 My_Null_Facade_B_Ptr : constant C460014_1.Facade_B_Ptr_Type := null; 194 195 Constraint_Error_Raised : Boolean; 196 197 procedure Test_Define_Construct 198 (Facade_Class_Ptr : in C460014_1.Facade_Class_Ptr_Type) is 199 begin 200 Constraint_Error_Raised := False; 201 -- Should fail Tag_Check and therefore raise Constraint_Error if 202 -- parameter doesn't designate an object of Facade_A_Type 203 -- or Facade_B_Type. 204 C460014_1.Define_Construct (Facade_Class_Ptr => Facade_Class_Ptr); 205 exception 206 when Constraint_Error => 207 Constraint_Error_Raised := True; 208 end Test_Define_Construct; 209 210 211 procedure Test_Define_Class_Construct 212 (Facade_Class_Ptr : in C460014_1.Facade_Class_Ptr_Type) is 213 begin 214 Constraint_Error_Raised := False; 215 -- Should fail Tag_Check and therefore raise Constraint_Error if 216 -- parameter doesn't designate an object of Facade_A_Type 217 -- or Facade_B_Type. 218 C460014_1.Define_Class_Construct (Facade_Class_Ptr => Facade_Class_Ptr); 219 exception 220 when Constraint_Error => 221 Constraint_Error_Raised := True; 222 end Test_Define_Class_Construct; 223 224begin 225 226 Report.Test 227 ("C460014", 228 "Check that if the operand type of a type conversion is " & 229 "access-to-class-wide, Constraint_Error is raised if the tag of the " & 230 "object designated by the operand does not identify a specific type " & 231 "that is covered by or descended from the target type"); 232 233 Test_Define_Construct (Facade_Class_Ptr => My_Root_Facade_Ptr); 234 235 if not Constraint_Error_Raised then 236 Report.Failed ("Didn't get expected Constraint_Error (1)"); 237 end if; 238 239 Test_Define_Construct 240 (Facade_Class_Ptr => My_Facade_A_Ptr); 241 242 if Constraint_Error_Raised then 243 Report.Failed ("Unexpected Constraint_Error (2)"); 244 end if; 245 246 Test_Define_Construct 247 (Facade_Class_Ptr => My_Facade_B_Ptr); 248 249 if Constraint_Error_Raised then 250 Report.Failed ("Unexpected Constraint_Error (3)"); 251 end if; 252 253 Test_Define_Class_Construct (Facade_Class_Ptr => My_Root_Facade_Ptr); 254 255 if not Constraint_Error_Raised then 256 Report.Failed ("Didn't get expected Constraint_Error (4)"); 257 end if; 258 259 Test_Define_Class_Construct 260 (Facade_Class_Ptr => My_Facade_A_Ptr); 261 262 if Constraint_Error_Raised then 263 Report.Failed ("Unexpected Constraint_Error (5)"); 264 end if; 265 266 Test_Define_Class_Construct 267 (Facade_Class_Ptr => My_Facade_B_Ptr); 268 269 if Constraint_Error_Raised then 270 Report.Failed ("Unexpected Constraint_Error (6)"); 271 end if; 272 273 -- Check that it is OK to pass null and that does not cause some failure. 274 Test_Define_Class_Construct (Facade_Class_Ptr => null); 275 276 if Constraint_Error_Raised then 277 Report.Failed ("Unexpected Constraint_Error (7)"); 278 end if; 279 280 Test_Define_Class_Construct (Facade_Class_Ptr => 281 C460014_1.Facade_Class_Ptr_Type (My_Null_Facade_B_Ptr)); 282 283 if Constraint_Error_Raised then 284 Report.Failed ("Unexpected Constraint_Error (8)"); 285 end if; 286 287 Report.Result; 288 289end C460014; 290