Skip to content

Commit

Permalink
Fixed memory leak in test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Dec 20, 2014
1 parent d7ac7ff commit e8c127a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/StringBuilderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ using namespace ArduinoJson::Internals;

class StringBuilderTests : public testing::Test {
protected:
virtual void SetUp() { sb = new StringBuilder(buffer, sizeof(buffer)); }
virtual void SetUp() {
_stringBuilder = new StringBuilder(_buffer, sizeof(_buffer));
}

void print(const char *value) { returnValue = sb->print(value); }
virtual void TearDown() { delete _stringBuilder; }

void outputMustBe(const char *expected) { EXPECT_STREQ(expected, buffer); }
void print(const char *value) { _returnValue = _stringBuilder->print(value); }

void resultMustBe(size_t expected) { EXPECT_EQ(expected, returnValue); }
void outputMustBe(const char *expected) { EXPECT_STREQ(expected, _buffer); }

void resultMustBe(size_t expected) { EXPECT_EQ(expected, _returnValue); }

private:
char buffer[20];
Print *sb;
size_t returnValue;
char _buffer[20];
Print *_stringBuilder;
size_t _returnValue;
};

TEST_F(StringBuilderTests, InitialState) { outputMustBe(""); }
Expand Down

0 comments on commit e8c127a

Please sign in to comment.