testregistry.pp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {$mode objfpc}
  2. {$h+}
  3. {
  4. $Id$
  5. This file is part of the Free Component Library (FCL)
  6. Copyright (c) 2004 by Dean Zobec, Michael Van Canneyt
  7. Port to Free Pascal of the JUnit framework.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. unit testregistry;
  15. interface
  16. uses
  17. fpcunit;
  18. procedure RegisterTest(ATestClass: TTestClass); overload;
  19. procedure RegisterTests(ATests: Array of TTestClass);
  20. function NumberOfRegisteredTests: longint;
  21. function GetTestRegistry: TTestSuite;
  22. implementation
  23. var
  24. FTestRegistry: TTestSuite;
  25. function GetTestRegistry: TTestSuite;
  26. begin
  27. if not Assigned(FTestRegistry) then
  28. FTestRegistry := TTestSuite.Create;
  29. Result := FTestRegistry;
  30. end;
  31. procedure RegisterTest(ATestClass: TTestClass);
  32. begin
  33. GetTestRegistry.AddTestSuiteFromClass(ATestClass);
  34. end;
  35. procedure RegisterTests(ATests: Array of TTestClass);
  36. var
  37. i: integer;
  38. begin
  39. for i := Low(ATests) to High(ATests) do
  40. if Assigned(ATests[i]) then
  41. begin
  42. RegisterTest(ATests[i]);
  43. end;
  44. end;
  45. function NumberOfRegisteredTests: longint;
  46. begin
  47. Result := GetTestRegistry.CountTestCases;
  48. end;
  49. initialization
  50. FTestRegistry := nil;
  51. finalization
  52. FTestRegistry.Free;
  53. end.