test_generic.adb 2.7 KB
Newer Older
1 2
with ASN1_Ada_Iterators.Iterators;
use  ASN1_Ada_Iterators.Iterators;
3

4 5
with TASTE_Dataview;
use  TASTE_Dataview;
6

7 8
with Ada.Text_IO;
use Ada.Text_IO;
9 10 11

procedure test_generic is

12
--  THIS IS HOW TO DO IT MANUALLY:
13 14 15 16 17 18 19 20 21 22 23 24 25
--   -- create an Integer type with a range constraint
--   package MyInteger is new Generic_Integer (1, 4);
--
--   -- create an iterator for a variable size array of integers
--   Package MyVarSeqOf_Pkg is new Generic_SeqOf (Min => 1,
--                                                Max => 5,
--                                                Basic => MyInteger.It);
--
--   -- create an iterator for an array of integers as defined above
--   Package MySeqOF_Pkg is new Generic_SeqOf (Min => 3,
--                                             Max => 3,
--                                             Basic => MyInteger.It);
--
26 27 28 29 30 31
   use MyInteger_Pkg;
   use MySeqOf_Pkg;
   use MyVarSeqOf_Pkg;
   use MyEnum_Pkg;
   use MySeqOfEnum_Pkg;
   use MySeq_Pkg;
32

33 34 35 36 37 38
   --  Test cases
   MyIt         : MyInteger_Pkg.Instance;
   Fixed_SeqOf  : MySeqOf_Pkg.Instance;
   Var_SeqOf    : MyVarSeqOf_Pkg.Instance;
   Enum         : MyEnum_Pkg.Instance;
   SeqOfEnum    : MySeqOfEnum_Pkg.Instance;
39

40
   Seq : MySeq_Pkg.Instance;
Maxime Perrotin's avatar
Maxime Perrotin committed
41

42 43 44 45
   SeqOfItm     : asn1SccMySeqOf;
   VarSeqOfItm  : asn1SccMyVarSeqOf;
   SeqOfEnumItm : asn1SccMySeqOfEnum;
   i            : Natural := 1;
46 47

begin
48 49
   --  test: compute all possible values of the integer type
   --  (equivalent to "for each in 1..3 loop put_line(each'img); end loop;")
50
   for each of MyIt loop
51 52
      --  Put_Line(each'img);
      Put_Line (Image (each));
53
   end loop;
Maxime Perrotin's avatar
Maxime Perrotin committed
54

55
   --  test: compute all combinations of values for the fixed-size array
56 57 58
   Put_Line ("Variable-size array:");
   for each of Var_SeqOf loop
      To_ASN1 (From => each, To => VarSeqOfItm);
59
      Put (Image (VarSeqOfItm));
60 61 62 63 64
      i := (if i mod 10 = 0 then 1 else i + 1);
      if i = 1 then
         New_Line;
      end if;
   end loop;
65
   --  test: compute all combination of values for the variable-size array
66
   New_Line;
67

68 69 70 71
   Put_Line ("Fixed-size array:");
   i := 1;
   for each of Fixed_SeqOf loop
      To_ASN1 (From => each, To => SeqOfItm);
72
      Put (Image (SeqOfItm));
73 74 75 76 77 78
      i := (if i mod 10 = 0 then 1 else i + 1);
      if i = 1 then
         New_Line;
      end if;
   end loop;
   New_Line;
Maxime Perrotin's avatar
Maxime Perrotin committed
79

80 81 82 83
   Put_Line ("Enumerated type");
   for Each of Enum loop
      Put_Line (Image (Each));
   end loop;
Maxime Perrotin's avatar
Maxime Perrotin committed
84 85 86 87 88 89 90 91
   New_Line;

   Put_Line ("Sequence of Enumerated type");
   for Each of SeqOfEnum loop
      To_ASN1 (From => Each, To => SeqOfEnumItm);
      Put (Image (SeqOfEnumItm) & " ");
   end loop;
   New_Line;
92

Maxime Perrotin's avatar
Maxime Perrotin committed
93 94 95 96 97
   Put_Line ("Sequence with 2 fields");
   for Each of Seq loop
      Put (Image (Each) & " ");
   end loop;
   New_Line;
98
end test_generic;