Browse Source

lolunit: free all the memory we allocated to avoid a minor memory leak,

and slightly tweak the API syntax.
legacy
Sam Hocevar sam 13 years ago
parent
commit
b64d051e6a
2 changed files with 11 additions and 9 deletions
  1. +9
    -7
      src/lol/unit.h
  2. +2
    -2
      test/lol-test.cpp

+ 9
- 7
src/lol/unit.h View File

@@ -28,7 +28,7 @@ using namespace std;


class FixtureBase class FixtureBase
{ {
friend class TestRunner;
friend class TextTestRunner;


public: public:
virtual void setUp(void) {}; virtual void setUp(void) {};
@@ -54,7 +54,7 @@ protected:
return head; return head;
} }


virtual void RunFixture() = 0;
virtual void runFixture() = 0;


/* Prevent compiler complaints about unreachable code */ /* Prevent compiler complaints about unreachable code */
static inline bool True() { return true; } static inline bool True() { return true; }
@@ -93,7 +93,7 @@ public:
} }


/* Run all test cases in this fixture. */ /* Run all test cases in this fixture. */
virtual void RunFixture()
virtual void runFixture()
{ {
m_errorlog.str(""); m_errorlog.str("");
m_testcases = 0; m_testcases = 0;
@@ -124,10 +124,10 @@ public:
} }
}; };


class TestRunner
class TextTestRunner
{ {
public: public:
bool Run()
bool run()
{ {
bool ret = true; bool ret = true;
std::stringstream errors(""); std::stringstream errors("");
@@ -136,7 +136,7 @@ public:
for (FixtureBase *f = FixtureBase::GetOrSetTest(); f; f = f->m_next) for (FixtureBase *f = FixtureBase::GetOrSetTest(); f; f = f->m_next)
{ {
f->setUp(); f->setUp();
f->RunFixture();
f->runFixture();
f->tearDown(); f->tearDown();


errors << f->m_errorlog.str(); errors << f->m_errorlog.str();
@@ -171,7 +171,9 @@ public:
class FixtureName; \ class FixtureName; \
template<typename T> struct Make##FixtureName \ template<typename T> struct Make##FixtureName \
{ \ { \
Make##FixtureName() { new T(); } \
Make##FixtureName() { p = new T(); } \
~Make##FixtureName() { delete p; } \
T *p; \
}; \ }; \
Make##FixtureName<FixtureName> lol_unit_fixture_##FixtureName; \ Make##FixtureName<FixtureName> lol_unit_fixture_##FixtureName; \
static char const *LolUnitFixtureName(FixtureName *p) \ static char const *LolUnitFixtureName(FixtureName *p) \


+ 2
- 2
test/lol-test.cpp View File

@@ -19,8 +19,8 @@


int main(void) int main(void)
{ {
lol::TestRunner runner;
bool success = runner.Run();
lol::TextTestRunner runner;
bool success = runner.run();
return success ? EXIT_SUCCESS : EXIT_FAILURE; return success ? EXIT_SUCCESS : EXIT_FAILURE;
} }



Loading…
Cancel
Save