gtest.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "gtest.h"
  2. #include "simple.h"
  3. #include <util/generic/map.h>
  4. #include <util/generic/vector.h>
  5. #include <util/system/type_name.h>
  6. using namespace NUnitTest;
  7. using namespace NUnitTest::NPrivate;
  8. IGTestFactory::~IGTestFactory() {
  9. }
  10. namespace {
  11. struct TCurrentTest: public TSimpleTestExecutor {
  12. inline TCurrentTest(TStringBuf name)
  13. : MyName(name)
  14. {
  15. }
  16. TString TypeId() const override {
  17. return TypeName(*this) + "-" + MyName;
  18. }
  19. TString Name() const noexcept override {
  20. return TString(MyName);
  21. }
  22. const TStringBuf MyName;
  23. };
  24. struct TGTestFactory: public IGTestFactory {
  25. inline TGTestFactory(TStringBuf name)
  26. : Test(name)
  27. {
  28. }
  29. ~TGTestFactory() override {
  30. }
  31. TString Name() const noexcept override {
  32. return Test.Name();
  33. }
  34. TTestBase* ConstructTest() override {
  35. return new TCurrentTest(Test);
  36. }
  37. void AddTest(const char* name, void (*body)(TTestContext&), bool forceFork) override {
  38. Test.Tests.push_back(TBaseTestCase(name, body, forceFork));
  39. }
  40. TCurrentTest Test;
  41. };
  42. }
  43. IGTestFactory* NUnitTest::NPrivate::ByName(const char* name) {
  44. static TMap<TStringBuf, TAutoPtr<TGTestFactory>> tests;
  45. auto& ret = tests[name];
  46. if (!ret) {
  47. ret = new TGTestFactory(name);
  48. }
  49. return ret.Get();
  50. }