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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- A U N I T . T E S T _ R E S U L T S --
-- --
-- B o d y --
-- --
-- --
-- Copyright (C) 2000-2011, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT is maintained by AdaCore (http://www.adacore.com) --
-- --
------------------------------------------------------------------------------
with AUnit.Memory.Utils;
-- Record test results.
package body AUnit.Test_Results is
-----------------------
-- Local Subprograms --
-----------------------
function Alloc_Failure is new AUnit.Memory.Utils.Gen_Alloc
(Test_Failure, Test_Failure_Access);
function Alloc_Error is new AUnit.Memory.Utils.Gen_Alloc
(Test_Error, Test_Error_Access);
E_Count : Count_Type;
F_Count : Count_Type;
S_Count : Count_Type;
procedure Iterate_Error (Position : Result_Lists.Cursor);
procedure Iterate_Failure (Position : Result_Lists.Cursor);
procedure Iterate_Success (Position : Result_Lists.Cursor);
function Is_Error (Position : Result_Lists.Cursor) return Boolean;
function Is_Failure (Position : Result_Lists.Cursor) return Boolean;
function Is_Success (Position : Result_Lists.Cursor) return Boolean;
generic
with function Test (Position : Result_Lists.Cursor) return Boolean;
procedure Gen_Extract (R : in out Result;
E : in out Result_Lists.List);
-------------------
-- Iterate_Error --
-------------------
procedure Iterate_Error (Position : Result_Lists.Cursor) is
begin
if Result_Lists.Element (Position).Error /= null then
E_Count := E_Count + 1;
end if;
end Iterate_Error;
---------------------
-- Iterate_Failure --
---------------------
procedure Iterate_Failure (Position : Result_Lists.Cursor) is
begin
if Result_Lists.Element (Position).Failure /= null then
F_Count := F_Count + 1;
end if;
end Iterate_Failure;
---------------------
-- Iterate_Success --
---------------------
procedure Iterate_Success (Position : Result_Lists.Cursor) is
begin
if Result_Lists.Element (Position).Error = null
and then Result_Lists.Element (Position).Failure = null
then
S_Count := S_Count + 1;
end if;
end Iterate_Success;
-----------------
-- Gen_Extract --
-----------------
procedure Gen_Extract
(R : in out Result;
E : in out Result_Lists.List)
is
C : Result_Lists.Cursor;
Prev : Result_Lists.Cursor;
use Result_Lists;
begin
C := First (R.Result_List);
Prev := No_Element;
while Has_Element (C) loop
if Test (C) then
Splice (Target => E,
Before => No_Element,
Source => R.Result_List,
Position => C);
if Prev = No_Element then
C := First (R.Result_List);
else
C := Next (Prev);
end if;
else
Prev := C;
Next (C);
end if;
end loop;
end Gen_Extract;
--------------
-- Is_Error --
--------------
function Is_Error (Position : Result_Lists.Cursor) return Boolean is
begin
return Result_Lists.Element (Position).Error /= null;
end Is_Error;
----------------
-- Is_Failure --
----------------
function Is_Failure (Position : Result_Lists.Cursor) return Boolean is
begin
return Result_Lists.Element (Position).Failure /= null;
end Is_Failure;
----------------
-- Is_Success --
----------------
function Is_Success (Position : Result_Lists.Cursor) return Boolean is
begin
return not Is_Error (Position) and then not Is_Failure (Position);
end Is_Success;
---------------
-- Add_Error --
---------------
procedure Add_Error
(R : in out Result;
Test_Name : Message_String;
Routine_Name : Message_String;
Error : Test_Error;
Elapsed : Time)
is
Val : constant Test_Result := (Test_Name, Routine_Name,
Failure => null,
Error => Alloc_Error,
Elapsed => Elapsed);
use Result_Lists;
begin
Val.Error.all := Error;
Append (R.Result_List, Val);
end Add_Error;
-----------------
-- Add_Failure --
-----------------
procedure Add_Failure
(R : in out Result;
Test_Name : Message_String;
Routine_Name : Message_String;
Failure : Test_Failure;
Elapsed : Time) is
Val : constant Test_Result := (Test_Name, Routine_Name,
Failure => Alloc_Failure,
Error => null,
Elapsed => Elapsed);
use Result_Lists;
begin
Val.Failure.all := Failure;
Append (R.Result_List, Val);
end Add_Failure;
-----------------
-- Add_Success --
-----------------
procedure Add_Success
(R : in out Result;
Test_Name : Message_String;
Routine_Name : Message_String;
Elapsed : Time) is
Val : constant Test_Result :=
(Test_Name, Routine_Name, null, null, Elapsed);
use Result_Lists;
begin
Append (R.Result_List, Val);
end Add_Success;
-----------------
-- Set_Elapsed --
-----------------
procedure Set_Elapsed (R : in out Result;
T : Time_Measure.Time) is
begin
R.Elapsed_Time := T;
end Set_Elapsed;
-----------------
-- Error_Count --
-----------------
function Error_Count (R : Result) return Count_Type is
use Result_Lists;
begin
E_Count := 0;
Iterate (R.Result_List, Iterate_Error'Access);
return E_Count;
end Error_Count;
------------
-- Errors --
------------
procedure Errors (R : in out Result;
E : in out Result_Lists.List) is
procedure Extract is new Gen_Extract (Is_Error);
begin
Extract (R, E);
end Errors;
-------------------
-- Failure_Count --
-------------------
function Failure_Count (R : Result) return Count_Type is
use Result_Lists;
begin
F_Count := 0;
Iterate (R.Result_List, Iterate_Failure'Access);
return F_Count;
end Failure_Count;
--------------
-- Failures --
--------------
procedure Failures (R : in out Result;
F : in out Result_Lists.List) is
procedure Extract is new Gen_Extract (Is_Failure);
begin
Extract (R, F);
end Failures;
-------------
-- Elapsed --
-------------
function Elapsed (R : Result) return Time_Measure.Time is
begin
return R.Elapsed_Time;
end Elapsed;
----------------
-- Start_Test --
----------------
procedure Start_Test (R : in out Result; Subtest_Count : Count_Type) is
begin
R.Tests_Run := R.Tests_Run + Subtest_Count;
end Start_Test;
-------------------
-- Success_Count --
-------------------
function Success_Count (R : Result) return Count_Type is
begin
S_Count := 0;
Result_Lists.Iterate (R.Result_List, Iterate_Success'Access);
return S_Count;
end Success_Count;
---------------
-- Successes --
---------------
procedure Successes (R : in out Result;
S : in out Result_Lists.List) is
procedure Extract is new Gen_Extract (Is_Success);
begin
Extract (R, S);
end Successes;
----------------
-- Successful --
----------------
function Successful (R : Result) return Boolean is
begin
return Success_Count (R) = Test_Count (R);
end Successful;
----------------
-- Test_Count --
----------------
function Test_Count (R : Result) return Ada_Containers.Count_Type is
begin
return R.Tests_Run;
end Test_Count;
-----------
-- Clear --
-----------
procedure Clear (R : in out Result) is
begin
R.Tests_Run := 0;
R.Elapsed_Time := Time_Measure.Null_Time;
Result_Lists.Clear (R.Result_List);
end Clear;
end AUnit.Test_Results;
|