From b64d051e6aef1bbe9454c1e4d9bc84c2acf7b2f4 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 8 Sep 2011 01:35:55 +0000 Subject: [PATCH] lolunit: free all the memory we allocated to avoid a minor memory leak, and slightly tweak the API syntax. --- src/lol/unit.h | 16 +++++++++------- test/lol-test.cpp | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lol/unit.h b/src/lol/unit.h index 47cad32f..4fc9d213 100644 --- a/src/lol/unit.h +++ b/src/lol/unit.h @@ -28,7 +28,7 @@ using namespace std; class FixtureBase { - friend class TestRunner; + friend class TextTestRunner; public: virtual void setUp(void) {}; @@ -54,7 +54,7 @@ protected: return head; } - virtual void RunFixture() = 0; + virtual void runFixture() = 0; /* Prevent compiler complaints about unreachable code */ static inline bool True() { return true; } @@ -93,7 +93,7 @@ public: } /* Run all test cases in this fixture. */ - virtual void RunFixture() + virtual void runFixture() { m_errorlog.str(""); m_testcases = 0; @@ -124,10 +124,10 @@ public: } }; -class TestRunner +class TextTestRunner { public: - bool Run() + bool run() { bool ret = true; std::stringstream errors(""); @@ -136,7 +136,7 @@ public: for (FixtureBase *f = FixtureBase::GetOrSetTest(); f; f = f->m_next) { f->setUp(); - f->RunFixture(); + f->runFixture(); f->tearDown(); errors << f->m_errorlog.str(); @@ -171,7 +171,9 @@ public: class FixtureName; \ template struct Make##FixtureName \ { \ - Make##FixtureName() { new T(); } \ + Make##FixtureName() { p = new T(); } \ + ~Make##FixtureName() { delete p; } \ + T *p; \ }; \ Make##FixtureName lol_unit_fixture_##FixtureName; \ static char const *LolUnitFixtureName(FixtureName *p) \ diff --git a/test/lol-test.cpp b/test/lol-test.cpp index cbab6f8f..e099c2ca 100644 --- a/test/lol-test.cpp +++ b/test/lol-test.cpp @@ -19,8 +19,8 @@ int main(void) { - lol::TestRunner runner; - bool success = runner.Run(); + lol::TextTestRunner runner; + bool success = runner.run(); return success ? EXIT_SUCCESS : EXIT_FAILURE; }