aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/ada/acats/tests/ca/ca110051.am
blob: 91af0682349534b4839ba08bec0647f022135908 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
-- CA110051.AM
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     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 GOVERNMENT 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.
--*
--
-- OBJECTIVE:
--      Check that entities and operations declared in a package can be used
--      in the private part of a child of a child of the package.
--
-- TEST DESCRIPTION:
--      Declare a series of library unit packages -- parent, child, and 
--      grandchild.  The grandchild package will have a private part.
--      From within the private part of the grandchild, make use of 
--      components declared in the parent and grandparent packages.
--
-- TEST FILES:
--      The test consists of the following files:
--
--         CA110050.A
--      => CA110051.AM
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--
--!

                                    -- Grandchild Package Message.Text.Encoded
package CA110050_0.CA110050_1.CA110050_2 is  

   type Coded_Message is new Text_Message_Type with private;

   procedure Send (Message : in     Coded_Message;
                   Confirm :    out Coded_Message;
                   Status  :    out Boolean);

   function Encode (Message : Text_Message_Type) return Coded_Message;
   function Decode (Message : Coded_Message)     return Boolean;
   function Test_Connection                      return Boolean;

private

   Uncoded : Descriptor renames Null_Descriptor_Value; -- Grandparent object.

   type Coded_Message is new Text_Message_Type with    -- Parent type.
      record
         Key       : Descriptor := Uncoded;
         Coded_Key : Descriptor := Next_Available_Message;
                                 -- Grandparent type, grandparent function.
         Scrambled : Text_Type  := Null_Text;          -- Parent object.
      end record;                                      

   Coded_Msg : Coded_Message;

   type Blank_Message is new Message_Type with         -- Grandparent type.
      record
         ID        : Descriptor := Next_Available_Message;
                                 -- Grandparent type, grandparent function.
      end record;                                      

   Test_Message     : Blank_Message;

   Confirm_String   : constant String := "OK";
   Scrambled_String : constant String := "KO";

   Confirm_Text : Text_Type (Confirm_String'Length) :=
     (Max_Length => Confirm_String'Length,
      Length     => Confirm_String'Length,
      Text_Field => Confirm_String);

   Scrambled_Text : Text_Type (Scrambled_String'Length) :=
     (Max_Length => Scrambled_String'Length,
      Length     => Scrambled_String'Length,
      Text_Field => Scrambled_String);
     
end CA110050_0.CA110050_1.CA110050_2; -- Grandchild Pkg Message.Text.Encoded

     --=================================================================--

                               -- Grandchild Package body Message.Text.Encoded
package body CA110050_0.CA110050_1.CA110050_2 is 

   procedure Send (Message : in     Coded_Message;
                   Confirm :    out Coded_Message;
                   Status  :    out Boolean) is

      Confirmation_Message : Coded_Message :=
        (Number    => Message.Number,
         Text      => Confirm_Text,
         Key       => Message.Number,
         Coded_Key => Message.Number,
         Scrambled => Scrambled_Text);  

   begin                                          -- Dummy processing unit.
      Confirm := Confirmation_Message;
      if Confirm.Number /= Null_Message_Descriptor then
         Status := True;                            
      else
         Status := False;
      end if;
   end Send;
   -------------------------------------------------------------------------
   function Encode (Message : Text_Message_Type)  return Coded_Message is
   begin
      Coded_Msg.Number       := Message.Number;
      if Message.Text.Length > 0 then
         Coded_Msg.Text      := Message.Text;     -- Record assignment.
         Coded_Msg.Key       := Message.Number;   -- Same as msg number.
         Coded_Msg.Coded_Key := Message.Number;   -- Same as msg number.
         Coded_Msg.Scrambled := Message.Text;     -- Dummy processing.
      end if;
      return (Coded_Msg);
   end Encode;
   -------------------------------------------------------------------------
   function Decode (Message : Coded_Message) return Boolean is
      Decoded : Boolean := False;
   begin                                                       
      if (Message.Text.Length = Confirm_String'Length)        and then
         (Message.Text.Text_Field = Confirm_String)           and then
         (Message.Scrambled.Length = Scrambled_String'Length) and then
         (Message.Scrambled.Text_Field = Scrambled_String)    and then
         (Message.Coded_Key = 15)
      then
         Decoded := True;
      end if;
      return (Decoded);
   end Decode;
   -------------------------------------------------------------------------
   function Test_Connection return Boolean is
   begin
      return Test_Message.Id = 10;
   end Test_Connection;

end CA110050_0.CA110050_1.CA110050_2;        
                               -- Grandchild Package body Message.Text.Encoded
 
     --=================================================================--

with CA110050_0.CA110050_1.CA110050_2; 
with Report;

procedure CA110051 is

   package Message_Package renames CA110050_0.CA110050_1;
   package Code_Package    renames CA110050_0.CA110050_1.CA110050_2; 

   Message_String : constant String := "One if by land, two if by sea";

   Message_Text   : Message_Package.Text_Type (Message_String'Length) := 
     (Max_Length => Message_String'Length,
      Length     => Message_String'Length,
      Text_Field => Message_String);

   Message : Message_Package.Text_Message_Type := 
     (Number => CA110050_0.Next_Available_Message,
      Text   => Message_Text);

   Confirmation_Message : Code_Package.Coded_Message;
   Verification_OK      : Boolean := False;
   Transmission_OK      : Boolean := False;

begin

-- This test simulates the use of child library unit packages to implement
-- a message encoding and transmission scheme.  The full capability of the
-- encoding and transmission mechanisms are not developed here, but the 
-- intent is to demonstrate that a grandchild library unit package with a
-- private part will provide the framework for this type of processing.

   Report.Test ("CA110051", "Check that entities and operations declared "  &
                            "in a package can be used in the private part " & 
                            "of a child of a child of the package");

                            -- The following code demonstrates the use
                            -- of functionality contained in a grandchild
                            -- library unit.  The grandchild unit made use
                            -- of components declared in the ancestor
                            -- packages.
   
   Code_Package.Send                            -- Message object declared
     (Message => Code_Package.Encode (Message), -- above in "encoded" by a
      Confirm => Confirmation_Message,          -- call to grandchild pkg
      Status  => Transmission_OK);              -- function call, reseting
                                                -- fields and returning a
                                                -- coded message to the
                                                -- parameter.  The confirm
                                                -- parameter receives an
                                                -- encoded message value
                                                -- from proc Send, which is 
                                                -- "decoded"/verified below.

   if not Code_Package.Test_Connection then
      Report.Failed ("Bad initialization");
   end if;

   Verification_OK := Code_Package.Decode (Confirmation_Message);

   if not (Transmission_OK and Verification_OK) then
      Report.Failed ("Message transmission failure");
   end if;

   Report.Result;

end CA110051;