testregistry.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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, testdecorator;
  18. type
  19. TTestDecoratorClass = class of TTestDecorator;
  20. procedure RegisterTest(ATestClass: TTestCaseClass); overload;
  21. procedure RegisterTests(ATests: Array of TTestCaseClass);
  22. procedure RegisterTestDecorator(ADecoratorClass: TTestDecoratorClass; ATestClass: TTestCaseClass);
  23. function NumberOfRegisteredTests: longint;
  24. function GetTestRegistry: TTestSuite;
  25. implementation
  26. var
  27. FTestRegistry: TTestSuite;
  28. function GetTestRegistry: TTestSuite;
  29. begin
  30. if not Assigned(FTestRegistry) then
  31. FTestRegistry := TTestSuite.Create;
  32. Result := FTestRegistry;
  33. end;
  34. procedure RegisterTest(ATestClass: TTestCaseClass);
  35. begin
  36. GetTestRegistry.AddTestSuiteFromClass(ATestClass);
  37. end;
  38. procedure RegisterTestDecorator(ADecoratorClass: TTestDecoratorClass; ATestClass: TTestCaseClass);
  39. begin
  40. GetTestRegistry.AddTest(ADecoratorClass.Create(TTestSuite.Create(ATestClass)));
  41. end;
  42. procedure RegisterTests(ATests: Array of TTestCaseClass);
  43. var
  44. i: integer;
  45. begin
  46. for i := Low(ATests) to High(ATests) do
  47. if Assigned(ATests[i]) then
  48. begin
  49. RegisterTest(ATests[i]);
  50. end;
  51. end;
  52. function NumberOfRegisteredTests: longint;
  53. begin
  54. Result := GetTestRegistry.CountTestCases;
  55. end;
  56. initialization
  57. FTestRegistry := nil;
  58. finalization
  59. FTestRegistry.Free;
  60. end.