testregistry.pp 1.8 KB

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