test_generic.adb 2.57 KB
Newer Older
1
with ASN1_Ada_Iterators.iterators;  -- Generated by asn1scc using custom stg file
2 3
use  ASN1_Ada_Iterators.iterators;

4
with TASTE_DataView;
5
use  TASTE_DataView;
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

with ada.text_io;
use ada.text_io;

procedure test_generic is

-- THIS IS HOW TO DO IT MANUALLY:
--   -- 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);
--
    use MyInteger_Pkg;
    use MySeqOf_Pkg;
    use MyVarSeqOf_Pkg;
29
    use MyEnum_Pkg;
Maxime Perrotin's avatar
Maxime Perrotin committed
30
    use MySeqOfEnum_Pkg;
31 32

    -- Test cases
Maxime Perrotin's avatar
Maxime Perrotin committed
33 34 35 36 37
    MyIt         : MyInteger_Pkg.Instance;
    Fixed_SeqOf  : MySeqOf_Pkg.Instance;
    Var_SeqOf    : MyVarSeqOf_Pkg.Instance;
    Enum         : MyEnum_Pkg.Instance;
    SeqOfEnum    : MySeqOfEnum_Pkg.Instance;
38

Maxime Perrotin's avatar
Maxime Perrotin committed
39 40 41 42
    SeqOfItm     : asn1SccMySeqOf;
    VarSeqOfItm  : asn1SccMyVarSeqOf;
    SeqOfEnumItm : asn1SccMySeqOfEnum;
    i            : Natural := 1;
43 44

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

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

65 66 67 68 69 70 71 72 73 74 75
   Put_Line ("Fixed-size array:");
   i := 1;
   for each of Fixed_SeqOf loop
      To_ASN1 (From => each, To => SeqOfItm);
      Put(Image(SeqOfItm));
      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
76

77 78 79 80
   Put_Line ("Enumerated type");
   for Each of Enum loop
      Put_Line (Image (Each));
   end loop;
Maxime Perrotin's avatar
Maxime Perrotin committed
81 82 83 84 85 86 87 88
   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;
89 90 91

end;