aunit-test_cases.ads

1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- A U N I T . T E S T _ C A S E S --
6-- --
7-- S p e c --
8-- --
9-- --
10-- Copyright (C) 2000-2011, AdaCore --
11-- --
12-- GNAT is free software; you can redistribute it and/or modify it under --
13-- terms of the GNU General Public License as published by the Free Soft- --
14-- ware Foundation; either version 3, or (at your option) any later ver- --
15-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17-- or FITNESS FOR A PARTICULAR PURPOSE. --
18-- --
19-- As a special exception under Section 7 of GPL version 3, you are granted --
20-- additional permissions described in the GCC Runtime Library Exception, --
21-- version 3.1, as published by the Free Software Foundation. --
22-- --
23-- You should have received a copy of the GNU General Public License and --
24-- a copy of the GCC Runtime Library Exception along with this program; --
25-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26-- <http://www.gnu.org/licenses/>. --
27-- --
28-- GNAT is maintained by AdaCore (http://www.adacore.com) --
29-- --
30------------------------------------------------------------------------------
31
32with Ada_Containers; use Ada_Containers;
33with Ada_Containers.AUnit_Lists;
34with AUnit.Options;
35with AUnit.Simple_Test_Cases;
36with AUnit.Test_Results; use AUnit.Test_Results;
37
38-- Test case: a collection of test routines
39package AUnit.Test_Cases is
40
41 type Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with
42 private;
43 type Test_Case_Access is access all Test_Case'Class;
44
45 type Test_Routine is access procedure (Test : in out Test_Case'Class);
46
47 type Routine_Spec is record
48 Routine : Test_Routine;
49 Routine_Name : Message_String;
50 end record;
51
52 procedure Add_Routine (T : in out Test_Case'Class; Val : Routine_Spec);
53
54 procedure Register_Tests (Test : in out Test_Case) is abstract;
55 -- Register test methods with test suite
56
57 procedure Set_Up_Case (Test : in out Test_Case);
58 -- Set up performed before each test case (set of test routines)
59
60 procedure Tear_Down_Case (Test : in out Test_Case);
61 -- Tear down performed after each test case
62
63 package Registration is
64
65 procedure Register_Routine
66 (Test : in out Test_Case'Class;
67 Routine : Test_Routine;
68 Name : String);
69 -- Add test routine to test case
70
71 function Routine_Count (Test : Test_Case'Class) return Count_Type;
72 -- Count of registered routines in test case
73
74 end Registration;
75
76 generic
77 type Specific_Test_Case is abstract new Test_Case with private;
78 package Specific_Test_Case_Registration is
79 -- Specific Test Case registration
80
81 type Specific_Test_Routine is access procedure
82 (Test : in out Specific_Test_Case'Class);
83
84 procedure Register_Wrapper
85 (Test : in out Specific_Test_Case'Class;
86 Routine : Specific_Test_Routine;
87 Name : String);
88 -- Add test routine for a specific test case
89 end Specific_Test_Case_Registration;
90
91 procedure Run
92 (Test : access Test_Case;
93 Options : AUnit.Options.AUnit_Options;
94 R : in out Result'Class;
95 Outcome : out Status);
96 -- Run test case. Do not override.
97
98 procedure Run_Test (Test : in out Test_Case);
99 -- Perform the current test procedure. Do not override.
100
101 function Routine_Name (Test : Test_Case) return Message_String;
102 -- Routine name. Returns the routine under test. Do not override.
103
104private
105
106 type Routine_Access is access all Routine_Spec;
107 -- Test routine description
108
109 package Routine_Lists is new Ada_Containers.AUnit_Lists (Routine_Spec);
110 -- Container for test routines
111
112 package Failure_Lists is
113 new Ada_Containers.AUnit_Lists (Message_String);
114 -- Container for failed assertion messages per routine
115
116 type Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with record
117 Routines : aliased Routine_Lists.List;
118 Routine : Routine_Spec;
119 end record;
120
121end AUnit.Test_Cases;