diff --git a/tests/StringBuilderTests.cpp b/tests/StringBuilderTests.cpp new file mode 100644 index 00000000..847c972f --- /dev/null +++ b/tests/StringBuilderTests.cpp @@ -0,0 +1,76 @@ +#include + +#include "StringBuilder.h" + +using namespace ArduinoJson::Internals; + +class StringBuilderTests : public testing::Test +{ +protected: + + virtual void SetUp() + { + sb = new StringBuilder(buffer, sizeof(buffer)); + } + + void print(const char* value) + { + returnValue = sb->print(value); + } + + 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; +}; + +TEST_F(StringBuilderTests, InitialState) +{ + outputMustBe(""); +} + +TEST_F(StringBuilderTests, OverCapacity) +{ + print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + resultMustBe(19); + + print("ABC"); + resultMustBe(0); + + outputMustBe("ABCDEFGHIJKLMNOPQRS"); +} + +TEST_F(StringBuilderTests, EmptyString) +{ + print(""); + resultMustBe(0); + outputMustBe(""); +} + +TEST_F(StringBuilderTests, OneString) +{ + print("ABCD"); + resultMustBe(4); + outputMustBe("ABCD"); +} + +TEST_F(StringBuilderTests, TwoStrings) +{ + print("ABCD"); + resultMustBe(4); + + print("EFGH"); + resultMustBe(4); + + outputMustBe("ABCDEFGH"); +} \ No newline at end of file diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj index 01ae50a5..5c412108 100644 --- a/tests/tests.vcxproj +++ b/tests/tests.vcxproj @@ -90,6 +90,7 @@ + diff --git a/tests/tests.vcxproj.filters b/tests/tests.vcxproj.filters index 37fa031f..cc117b4f 100644 --- a/tests/tests.vcxproj.filters +++ b/tests/tests.vcxproj.filters @@ -39,5 +39,8 @@ Source Files + + Source Files + \ No newline at end of file