Natools

Check-in [0bbab0a171]
Login
Overview
Comment:s_expressions-lockable-tests: new package with a test suite for lock level stack
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0bbab0a171606e4f723346306d4986a992104ab8
User & Date: nat on 2014-03-01 11:25:26
Other Links: manifest | tags
Context
2014-03-02
17:03
s_expressions-lockable-tests: add a test suite for Loackable.Descriptor objects and use it to tester Wrapper check-in: 5fce88a981 user: nat tags: trunk
2014-03-01
11:25
s_expressions-lockable-tests: new package with a test suite for lock level stack check-in: 0bbab0a171 user: nat tags: trunk
2014-02-28
19:00
s_expressions-lockable: new package with an interface and a wrapper to lock a descriptor in the current sub-expression check-in: e61f083c1a user: nat tags: trunk
Changes

Added tests/natools-s_expressions-lockable-tests.adb version [75b7ead240].

















































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

with Natools.S_Expressions.Test_Tools;
with Natools.S_Expressions.Parsers;

package body Natools.S_Expressions.Lockable.Tests is

   -------------------------
   -- Complete Test Suite --
   -------------------------

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Test_Stack (Report);
      Test_Wrapper_Interface (Report);
      Test_Wrapper_Extra (Report);
   end All_Tests;



   ---------------------------
   -- Individual Test Cases --
   ---------------------------

   procedure Test_Stack (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Level stack");
   begin
      declare
         Stack : Lock_Stack;
         State : array (1 .. 4) of Lock_State;

         procedure Check_Level
           (Stack : in Lock_Stack;
            Expected : in Natural;
            Context : in String);
         procedure Dump_Data;

         procedure Check_Level
           (Stack : in Lock_Stack;
            Expected : in Natural;
            Context : in String)
         is
            Level : constant Natural := Current_Level (Stack);
         begin
            if Level /= Expected then
               Test.Fail (Context & ": level is"
                 & Natural'Image (Level) & ", expected"
                 & Natural'Image (Expected));
               Dump_Data;
            end if;
         end Check_Level;

         procedure Dump_Data is
         begin
            Test.Info ("   Stack: (Depth =>"
              & Natural'Image (Stack.Depth)
              & ", Level =>"
              & Natural'Image (Stack.Level) & ')');
            for I in State'Range loop
               Test.Info ("   State"
                 & Natural'Image (I)
                 & ": (Depth =>"
                 & Natural'Image (Stack.Depth)
                 & ", Level =>"
                 & Natural'Image (Stack.Level) & ')');
            end loop;
         end Dump_Data;
      begin
         Check_Level (Stack, 0, "1");
         Push_Level (Stack, 14, State (1));
         Check_Level (Stack, 14, "2");

         begin
            Pop_Level (Stack, State (2));
            Test.Fail ("No exception raised after popping blank state");
         exception
            when Constraint_Error =>
               null;
            when Error : others =>
               Test.Fail
                 ("Unexpected exception raised after popping blank state");
               Test.Report_Exception (Error, NT.Fail);
         end;

         Pop_Level (Stack, State (1));
         Check_Level (Stack, 0, "3");
         Push_Level (Stack, 15, State (1));
         Check_Level (Stack, 15, "4");
         Push_Level (Stack, 92, State (2));
         Check_Level (Stack, 92, "5");
         Push_Level (Stack, 65, State (3));
         Check_Level (Stack, 65, "6");
         Pop_Level (Stack, State (3));
         Check_Level (Stack, 92, "7");
         Push_Level (Stack, 35, State (3));
         Check_Level (Stack, 35, "8");
         Push_Level (Stack, 89, State (4));
         Check_Level (Stack, 89, "9");

         begin
            Pop_Level (Stack, State (3));
            Test.Fail ("No exception raised after popping a forbidden gap");
         exception
            when Constraint_Error =>
               null;
            when Error : others =>
               Test.Fail
                 ("Unexpected exception raised after popping a forbidden gap");
               Test.Report_Exception (Error, NT.Fail);
         end;

         Check_Level (Stack, 89, "10");
         Pop_Level (Stack, State (3), True);
         Check_Level (Stack, 92, "11");

         begin
            Pop_Level (Stack, State (4));
            Test.Fail ("No exception raised after popping stale state");
         exception
            when Constraint_Error =>
               null;
            when Error : others =>
               Test.Fail
                 ("Unexpected exception raised after popping stale state");
               Test.Report_Exception (Error, NT.Fail);
         end;

         Check_Level (Stack, 92, "12");
         Pop_Level (Stack, State (2));
         Check_Level (Stack, 15, "13");
         Pop_Level (Stack, State (1));
         Check_Level (Stack, 0, "14");
      end;
   exception
      when Error : others => Test.Report_Exception (Error);
   end Test_Stack;

end Natools.S_Expressions.Lockable.Tests;

Added tests/natools-s_expressions-lockable-tests.ads version [f578c376f2].





































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.S_Expressions.Lockable.Tests provides both test suites for lock  --
-- stack and the lockable wrapper, and tools to test Lockable.Descriptor    --
-- interface for other types.                                               --
------------------------------------------------------------------------------

with Natools.Tests;

package Natools.S_Expressions.Lockable.Tests is
   pragma Preelaborate (Tests);

   package NT renames Natools.Tests;

   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Test_Stack (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Lockable.Tests;

Modified tests/test_all.adb from [0e9aecb08c] to [70641a698b].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
with Ada.Text_IO;
with Natools.Chunked_Strings.Tests;
with Natools.Getopt_Long_Tests;
with Natools.Reference_Tests;
with Natools.S_Expressions.Atom_Buffers.Tests;
with Natools.S_Expressions.Cache_Tests;
with Natools.S_Expressions.Encodings.Tests;

with Natools.S_Expressions.Parsers.Tests;
with Natools.S_Expressions.Printers.Tests;
with Natools.S_Expressions.Printers.Pretty.Tests;
with Natools.String_Slice_Set_Tests;
with Natools.String_Slice_Tests;
with Natools.Tests.Text_IO;








>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
with Ada.Text_IO;
with Natools.Chunked_Strings.Tests;
with Natools.Getopt_Long_Tests;
with Natools.Reference_Tests;
with Natools.S_Expressions.Atom_Buffers.Tests;
with Natools.S_Expressions.Cache_Tests;
with Natools.S_Expressions.Encodings.Tests;
with Natools.S_Expressions.Lockable.Tests;
with Natools.S_Expressions.Parsers.Tests;
with Natools.S_Expressions.Printers.Tests;
with Natools.S_Expressions.Printers.Pretty.Tests;
with Natools.String_Slice_Set_Tests;
with Natools.String_Slice_Tests;
with Natools.Tests.Text_IO;

81
82
83
84
85
86
87




88
89
90
91
92
93
94
   Report.Section ("S_Expressions.Caches");
   Natools.S_Expressions.Cache_Tests.All_Tests (Report);
   Report.End_Section;

   Report.Section ("S_Expressions.Encodings");
   Natools.S_Expressions.Encodings.Tests.All_Tests (Report);
   Report.End_Section;





   Report.Section ("S_Expressions.Parsers");
   Natools.S_Expressions.Parsers.Tests.All_Tests (Report);
   Report.End_Section;

   Report.Section ("S_Expressions.Printers");
   Natools.S_Expressions.Printers.Tests.All_Tests (Report);







>
>
>
>







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
   Report.Section ("S_Expressions.Caches");
   Natools.S_Expressions.Cache_Tests.All_Tests (Report);
   Report.End_Section;

   Report.Section ("S_Expressions.Encodings");
   Natools.S_Expressions.Encodings.Tests.All_Tests (Report);
   Report.End_Section;

   Report.Section ("S_Expressions.Lockable");
   Natools.S_Expressions.Lockable.Tests.All_Tests (Report);
   Report.End_Section;

   Report.Section ("S_Expressions.Parsers");
   Natools.S_Expressions.Parsers.Tests.All_Tests (Report);
   Report.End_Section;

   Report.Section ("S_Expressions.Printers");
   Natools.S_Expressions.Printers.Tests.All_Tests (Report);