| 1 |
-- CXAC002.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 |
-- OBJECTIVE: |
| 27 |
-- Check that the subprograms defined in package Ada.Streams.Stream_IO |
| 28 |
-- are accessible, and that they provide the appropriate functionality. |
| 29 |
-- |
| 30 |
-- TEST DESCRIPTION: |
| 31 |
-- This test simulates a user filter designed to capitalize the |
| 32 |
-- characters of a string. It utilizes a variety of the subprograms |
| 33 |
-- contained in the package Ada.Streams.Stream_IO. |
| 34 |
-- Its purpose is to demonstrate the use of a variety of the capabilities |
| 35 |
-- found in the Ada.Streams.Stream_IO package. |
| 36 |
-- |
| 37 |
-- APPLICABILITY CRITERIA: |
| 38 |
-- This test is applicable to all implementations capable of supporting |
| 39 |
-- external Stream_IO files. |
| 40 |
-- |
| 41 |
-- |
| 42 |
-- CHANGE HISTORY: |
| 43 |
-- 06 Dec 94 SAIC ACVC 2.0 |
| 44 |
-- 14 Nov 95 SAIC Corrected visibility problems; corrected |
| 45 |
-- subtest validating result from function Name |
| 46 |
-- for ACVC 2.0.1. |
| 47 |
-- 05 Oct 96 SAIC Removed calls to Close/Open in test and replaced |
| 48 |
-- them with a single call to Reset (per AI95-0001) |
| 49 |
-- 26 Feb 97 PWB.CTA Allowed for non-support of some IO operations. |
| 50 |
-- 09 Feb 01 RLB Corrected non-support check to avoid unintended |
| 51 |
-- failures. |
| 52 |
--! |
| 53 |
|
| 54 |
package CXAC002_0 is |
| 55 |
|
| 56 |
-- This function searches for the first instance of a specified substring |
| 57 |
-- within a specified string, returning boolean result. (Case insensitive |
| 58 |
-- analysis) |
| 59 |
|
| 60 |
function Find (Str : in String; Sub : in String) return Boolean; |
| 61 |
|
| 62 |
end CXAC002_0; |
| 63 |
|
| 64 |
package body CXAC002_0 is |
| 65 |
|
| 66 |
function Find (Str : in String; Sub : in String) return Boolean is |
| 67 |
|
| 68 |
New_Str : String(Str'First..Str'Last); |
| 69 |
New_Sub : String(Sub'First..Sub'Last); |
| 70 |
Pos : Integer := Str'First; -- Character index. |
| 71 |
|
| 72 |
function Upper_Case (Str : in String) return String is |
| 73 |
subtype Upper is Character range 'A'..'Z'; |
| 74 |
subtype Lower is Character range 'a'..'z'; |
| 75 |
Ret : String(Str'First..Str'Last); |
| 76 |
Pos : Integer; |
| 77 |
begin |
| 78 |
for I in Str'Range loop |
| 79 |
if (Str(I) in Lower) then |
| 80 |
Pos := Upper'Pos(Upper'First) + |
| 81 |
(Lower'Pos(Str(I)) - Lower'Pos(Lower'First)); |
| 82 |
Ret(I) := Upper'Val(Pos); |
| 83 |
else |
| 84 |
Ret(I) := Str (I); |
| 85 |
end if; |
| 86 |
end loop; |
| 87 |
return Ret; |
| 88 |
end Upper_Case; |
| 89 |
|
| 90 |
begin |
| 91 |
|
| 92 |
New_Str := Upper_Case(Str); -- Convert Str and Sub to upper |
| 93 |
New_Sub := Upper_Case(Sub); -- case for comparison. |
| 94 |
|
| 95 |
while (Pos <= New_Str'Last-New_Sub'Length+1) -- Search until no more |
| 96 |
and then -- sub-string-length |
| 97 |
(New_Str(Pos..Pos+New_Sub'Length-1) /= New_Sub) -- slices remain. |
| 98 |
loop |
| 99 |
Pos := Pos + 1; |
| 100 |
end loop; |
| 101 |
|
| 102 |
if (Pos > New_Str'Last-New_Sub'Length+1) then -- Substring not found. |
| 103 |
return False; |
| 104 |
else |
| 105 |
return True; |
| 106 |
end if; |
| 107 |
|
| 108 |
end Find; |
| 109 |
|
| 110 |
end CXAC002_0; |
| 111 |
|
| 112 |
|
| 113 |
with Ada.Streams.Stream_IO, CXAC002_0, Report; |
| 114 |
procedure CXAC002 is |
| 115 |
Filter_File : Ada.Streams.Stream_IO.File_Type; |
| 116 |
Filter_Stream : Ada.Streams.Stream_IO.Stream_Access; |
| 117 |
Filter_Filename : constant String := |
| 118 |
Report.Legal_File_Name ( Nam => "CXAC002" ); |
| 119 |
Incomplete : Exception; |
| 120 |
|
| 121 |
begin |
| 122 |
|
| 123 |
Report.Test ("CXAC002", "Check that the subprograms defined in " & |
| 124 |
"package Ada.Streams.Stream_IO are accessible, " & |
| 125 |
"and that they provide the appropriate " & |
| 126 |
"functionality"); |
| 127 |
|
| 128 |
Test_for_Stream_IO_Support: |
| 129 |
|
| 130 |
begin |
| 131 |
|
| 132 |
-- If an implementation does not support Stream_IO in a particular |
| 133 |
-- environment, the exception Use_Error or Name_Error will be raised on |
| 134 |
-- calls to various Stream_IO operations. This block statement |
| 135 |
-- encloses a call to Create, which should produce an exception in a |
| 136 |
-- non-supportive environment. These exceptions will be handled to |
| 137 |
-- produce a Not_Applicable result. |
| 138 |
|
| 139 |
Ada.Streams.Stream_IO.Create (Filter_File, -- Create. |
| 140 |
Ada.Streams.Stream_IO.Out_File, |
| 141 |
Filter_Filename); |
| 142 |
exception |
| 143 |
|
| 144 |
when Ada.Streams.Stream_IO.Use_Error | Ada.Streams.Stream_IO.Name_Error => |
| 145 |
Report.Not_Applicable |
| 146 |
( "Files not supported - Create as Out_File for Stream_IO" ); |
| 147 |
raise Incomplete; |
| 148 |
|
| 149 |
end Test_for_Stream_IO_Support; |
| 150 |
|
| 151 |
Operational_Test_Block: |
| 152 |
declare |
| 153 |
|
| 154 |
use CXAC002_0; |
| 155 |
use type Ada.Streams.Stream_IO.File_Mode; |
| 156 |
use type Ada.Streams.Stream_IO.Count; |
| 157 |
|
| 158 |
File_Size : Ada.Streams.Stream_IO.Count := -- Count. |
| 159 |
Ada.Streams.Stream_IO.Count'First; -- (0) |
| 160 |
File_Index : Ada.Streams.Stream_IO.Positive_Count := -- Pos. Count. |
| 161 |
Ada.Streams.Stream_IO.Positive_Count'First; -- (1) |
| 162 |
|
| 163 |
First_String : constant String := "this is going to be "; |
| 164 |
Second_String : constant String := "the best year of your life"; |
| 165 |
Total_Length : constant Natural := First_String'Length + |
| 166 |
Second_String'Length; |
| 167 |
Current_Char : Character := ' '; |
| 168 |
|
| 169 |
Cap_String : String (1..Total_Length) := (others => ' '); |
| 170 |
|
| 171 |
TC_Capital_String : constant String := |
| 172 |
"THIS IS GOING TO BE THE BEST YEAR OF YOUR LIFE"; |
| 173 |
|
| 174 |
begin |
| 175 |
|
| 176 |
if not Ada.Streams.Stream_IO.Is_Open (Filter_File) then -- Is_Open |
| 177 |
Report.Failed ("File not open following Create"); |
| 178 |
end if; |
| 179 |
|
| 180 |
-- Call function Find to determine if the filename (Sub) is contained |
| 181 |
-- in the result of Function Name. |
| 182 |
|
| 183 |
if not Find(Str => Ada.Streams.Stream_IO.Name(Filter_File), -- Name. |
| 184 |
Sub => Filter_Filename) |
| 185 |
then |
| 186 |
Report.Failed ("Function Name provided incorrect filename"); |
| 187 |
end if; |
| 188 |
-- Stream. |
| 189 |
Filter_Stream := Ada.Streams.Stream_IO.Stream (Filter_File); |
| 190 |
|
| 191 |
--- |
| 192 |
|
| 193 |
Enter_Data_In_Stream: |
| 194 |
declare |
| 195 |
Pos : Natural := 1; |
| 196 |
Bad_Character_Found : Boolean := False; |
| 197 |
begin |
| 198 |
|
| 199 |
-- Enter data from the first string into the stream. |
| 200 |
while Pos <= Natural(First_String'Length) loop |
| 201 |
-- Write all characters of the First_String to the stream. |
| 202 |
Character'Write (Filter_Stream, First_String (Pos)); |
| 203 |
Pos := Pos + 1; |
| 204 |
-- Ensure data put in file on a regular basis. |
| 205 |
if Pos mod 5 = 0 then |
| 206 |
Ada.Streams.Stream_IO.Flush (Filter_File); -- Flush. |
| 207 |
end if; |
| 208 |
end loop; |
| 209 |
|
| 210 |
Ada.Streams.Stream_IO.Flush (Filter_File); -- Flush. |
| 211 |
-- Reset to In_File mode and read stream contents. |
| 212 |
Reset1: |
| 213 |
begin |
| 214 |
Ada.Streams.Stream_IO.Reset (Filter_File, -- Reset. |
| 215 |
Ada.Streams.Stream_IO.In_File); |
| 216 |
exception |
| 217 |
when Ada.Streams.Stream_IO.Use_Error => |
| 218 |
Report.Not_Applicable |
| 219 |
( "Reset to In_File not supported for Stream_IO" ); |
| 220 |
raise Incomplete; |
| 221 |
end Reset1; |
| 222 |
|
| 223 |
Pos := 1; |
| 224 |
while Pos <= First_String'Length loop |
| 225 |
-- Read one character from the stream. |
| 226 |
Character'Read (Filter_Stream, Current_Char); -- 'Read |
| 227 |
-- Verify character against the original string. |
| 228 |
if Current_Char /= First_String(Pos) then |
| 229 |
Bad_Character_Found := True; |
| 230 |
end if; |
| 231 |
Pos := Pos + 1; |
| 232 |
end loop; |
| 233 |
|
| 234 |
if Bad_Character_Found then |
| 235 |
Report.Failed ("Incorrect character read from stream"); |
| 236 |
end if; |
| 237 |
|
| 238 |
-- Following user stream/string processing, the stream file is |
| 239 |
-- appended to as follows: |
| 240 |
|
| 241 |
Reset2: |
| 242 |
begin |
| 243 |
Ada.Streams.Stream_IO.Reset (Filter_File, -- Reset. |
| 244 |
Ada.Streams.Stream_IO.Append_File); |
| 245 |
exception |
| 246 |
when Ada.Streams.Stream_IO.Use_Error => |
| 247 |
Report.Not_Applicable |
| 248 |
( "Reset to Append_File not supported for Stream_IO" ); |
| 249 |
raise Incomplete; |
| 250 |
end Reset2; |
| 251 |
|
| 252 |
if Ada.Streams.Stream_IO.Mode (Filter_File) /= -- Mode. |
| 253 |
Ada.Streams.Stream_IO.Append_File |
| 254 |
then |
| 255 |
Report.Failed ("Incorrect mode following Reset to Append"); |
| 256 |
end if; |
| 257 |
|
| 258 |
Pos := 1; |
| 259 |
while Pos <= Natural(Second_String'Length) loop |
| 260 |
-- Write all characters of the Second_String to the stream. |
| 261 |
Character'Write (Filter_Stream, Second_String (Pos)); -- 'Write |
| 262 |
Pos := Pos + 1; |
| 263 |
end loop; |
| 264 |
|
| 265 |
Ada.Streams.Stream_IO.Flush (Filter_File); -- Flush. |
| 266 |
|
| 267 |
-- Record file statistics. |
| 268 |
File_Size := Ada.Streams.Stream_IO.Size (Filter_File); -- Size. |
| 269 |
|
| 270 |
Index_Might_Not_Be_Supported: |
| 271 |
begin |
| 272 |
File_Index := Ada.Streams.Stream_IO.Index (Filter_File); -- Index. |
| 273 |
exception |
| 274 |
when Ada.Streams.Stream_IO.Use_Error => |
| 275 |
Report.Not_Applicable ( "Index not supported for Stream_IO" ); |
| 276 |
raise Incomplete; |
| 277 |
end Index_Might_Not_Be_Supported; |
| 278 |
|
| 279 |
exception |
| 280 |
when Incomplete => |
| 281 |
raise; |
| 282 |
when others => |
| 283 |
Report.Failed ("Exception in Enter_Data_In_Stream block"); |
| 284 |
raise; |
| 285 |
end Enter_Data_In_Stream; |
| 286 |
|
| 287 |
--- |
| 288 |
|
| 289 |
Filter_Block: |
| 290 |
declare |
| 291 |
Pos : Positive := 1; |
| 292 |
Full_String : constant String := First_String & Second_String; |
| 293 |
|
| 294 |
function Capitalize (Char : Character) return Character is |
| 295 |
begin |
| 296 |
if Char /= ' ' then |
| 297 |
return Character'Val( Character'Pos(Char) - |
| 298 |
(Character'Pos('a') - Character'Pos('A'))); |
| 299 |
else |
| 300 |
return Char; |
| 301 |
end if; |
| 302 |
end Capitalize; |
| 303 |
|
| 304 |
begin |
| 305 |
|
| 306 |
Reset3: |
| 307 |
begin |
| 308 |
Ada.Streams.Stream_IO.Reset (Filter_File, -- Reset. |
| 309 |
Ada.Streams.Stream_IO.In_File); |
| 310 |
exception |
| 311 |
when Ada.Streams.Stream_IO.Use_Error => |
| 312 |
Report.Not_Applicable |
| 313 |
( "Reset to In_File not supported for Stream_IO" ); |
| 314 |
raise Incomplete; |
| 315 |
end Reset3; |
| 316 |
|
| 317 |
if Ada.Streams.Stream_IO.Mode (Filter_File) /= -- Mode. |
| 318 |
Ada.Streams.Stream_IO.In_File |
| 319 |
then |
| 320 |
Report.Failed ("Incorrect mode following Reset to In_File"); |
| 321 |
end if; |
| 322 |
|
| 323 |
if not Ada.Streams.Stream_IO.Is_Open (Filter_File) then -- Is_Open |
| 324 |
Report.Failed ( "Reset command did not leave file open" ); |
| 325 |
end if; |
| 326 |
|
| 327 |
if Ada.Streams.Stream_IO.Size (Filter_File) /= -- Size. |
| 328 |
File_Size |
| 329 |
then |
| 330 |
Report.Failed ("Reset file is not correct size"); |
| 331 |
end if; |
| 332 |
|
| 333 |
if Ada.Streams.Stream_IO.Index (Filter_File) /= 1 then -- Index. |
| 334 |
-- File position should have been reset to start of file. |
| 335 |
Report.Failed ("Index of file not set to 1 following Reset"); |
| 336 |
end if; |
| 337 |
|
| 338 |
while Pos <= Full_String'Length loop |
| 339 |
-- Read one character from the stream. |
| 340 |
Character'Read (Filter_Stream, Current_Char); -- 'Read |
| 341 |
-- Verify character against the original string. |
| 342 |
if Current_Char /= Full_String(Pos) then |
| 343 |
Report.Failed ("Incorrect character read from stream"); |
| 344 |
else |
| 345 |
-- Capitalize the characters read from the stream, and |
| 346 |
-- place them in a string variable. |
| 347 |
Cap_String(Pos) := Capitalize (Current_Char); |
| 348 |
end if; |
| 349 |
Pos := Pos + 1; |
| 350 |
end loop; |
| 351 |
|
| 352 |
-- File index should now be set to the position following the final |
| 353 |
-- character in the file (the same as the index value stored at |
| 354 |
-- the completion of the Enter_Data_In_Stream block). |
| 355 |
if Ada.Streams.Stream_IO.Index (Filter_File) /= -- Index. |
| 356 |
File_Index |
| 357 |
then |
| 358 |
Report.Failed ("Incorrect file index position"); |
| 359 |
end if; |
| 360 |
|
| 361 |
-- The stream file should now be at EOF. -- EOF. |
| 362 |
if not Ada.Streams.Stream_IO.End_Of_File (Filter_File) then |
| 363 |
Report.Failed ("File not empty following filtering"); |
| 364 |
end if; |
| 365 |
|
| 366 |
exception |
| 367 |
|
| 368 |
when Incomplete => |
| 369 |
raise; |
| 370 |
when others => |
| 371 |
Report.Failed ("Exception in Filter_Block"); |
| 372 |
raise; |
| 373 |
end Filter_Block; |
| 374 |
|
| 375 |
--- |
| 376 |
|
| 377 |
Verification_Block: |
| 378 |
begin |
| 379 |
|
| 380 |
-- Verify that the entire string was examined, and that the |
| 381 |
-- process of capitalizing the character data was successful. |
| 382 |
if Cap_String /= TC_Capital_String then |
| 383 |
Report.Failed ("Incorrect Capitalization"); |
| 384 |
end if; |
| 385 |
|
| 386 |
exception |
| 387 |
when others => |
| 388 |
Report.Failed ("Exception in Verification_Block"); |
| 389 |
end Verification_Block; |
| 390 |
|
| 391 |
|
| 392 |
exception |
| 393 |
|
| 394 |
when Incomplete => |
| 395 |
raise; |
| 396 |
when others => |
| 397 |
Report.Failed ("Exception raised in Operational Test Block"); |
| 398 |
|
| 399 |
end Operational_Test_Block; |
| 400 |
|
| 401 |
Deletion: |
| 402 |
begin |
| 403 |
if Ada.Streams.Stream_IO.Is_Open (Filter_File) then -- Is_Open. |
| 404 |
Ada.Streams.Stream_IO.Delete (Filter_File); -- Delete. |
| 405 |
else |
| 406 |
Ada.Streams.Stream_IO.Open (Filter_File, -- Open. |
| 407 |
Ada.Streams.Stream_IO.Out_File, |
| 408 |
Filter_Filename); |
| 409 |
Ada.Streams.Stream_IO.Delete (Filter_File); -- Delete. |
| 410 |
end if; |
| 411 |
exception |
| 412 |
when others => |
| 413 |
Report.Failed |
| 414 |
( "Delete not properly implemented for Stream_IO" ); |
| 415 |
end Deletion; |
| 416 |
|
| 417 |
Report.Result; |
| 418 |
|
| 419 |
exception |
| 420 |
when Incomplete => |
| 421 |
Report.Result; |
| 422 |
when others => |
| 423 |
Report.Failed ( "Unexpected exception" ); |
| 424 |
Report.Result; |
| 425 |
|
| 426 |
end CXAC002; |