From 786fe994aa4f0eb83654ae0173be068b30acced6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Thu, 26 Jun 2014 12:50:48 +0200 Subject: [PATCH] Added a test class for StringBuilder --- JsonGeneratorTests/JsonGeneratorTests.vcxproj | 1 + .../JsonGeneratorTests.vcxproj.filters | 3 ++ JsonGeneratorTests/StringBuilder.cpp | 9 ++++-- JsonGeneratorTests/StringBuilder.h | 1 + JsonGeneratorTests/StringBuilderTests.cpp | 32 +++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 JsonGeneratorTests/StringBuilderTests.cpp diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj b/JsonGeneratorTests/JsonGeneratorTests.vcxproj index 0a61f62f..404002f4 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj @@ -86,6 +86,7 @@ + diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters index d018d192..caee5ce1 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters @@ -27,6 +27,9 @@ Source Files + + Source Files + diff --git a/JsonGeneratorTests/StringBuilder.cpp b/JsonGeneratorTests/StringBuilder.cpp index a888e097..d9e3167a 100644 --- a/JsonGeneratorTests/StringBuilder.cpp +++ b/JsonGeneratorTests/StringBuilder.cpp @@ -1,3 +1,8 @@ +/* + * Arduino JSON library + * Benoit Blanchon 2014 - MIT License + */ + #include "StringBuilder.h" @@ -32,8 +37,8 @@ void StringBuilder::appendEscaped(const char* s) break; - default: - buffer[length++] = *s; + default: + buffer[length++] = *s; break; } diff --git a/JsonGeneratorTests/StringBuilder.h b/JsonGeneratorTests/StringBuilder.h index 08a7facf..d47a8602 100644 --- a/JsonGeneratorTests/StringBuilder.h +++ b/JsonGeneratorTests/StringBuilder.h @@ -15,6 +15,7 @@ public: StringBuilder(char* buf, size_t size) : buffer(buf), capacity(size), length(0) { + buffer[0] = 0; } void append(const char* s); diff --git a/JsonGeneratorTests/StringBuilderTests.cpp b/JsonGeneratorTests/StringBuilderTests.cpp new file mode 100644 index 00000000..34911c9d --- /dev/null +++ b/JsonGeneratorTests/StringBuilderTests.cpp @@ -0,0 +1,32 @@ +#include "CppUnitTest.h" +#include "StringBuilder.h" + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace JsonGeneratorTests +{ + TEST_CLASS(StringBuilderTests) + { + char buffer[16]; + StringBuilder* sb; + + + public: + + TEST_METHOD_INITIALIZE(Initialize) + { + sb = new StringBuilder(buffer, sizeof(buffer)); + } + + TEST_METHOD(InitialState) + { + assertResultIs(""); + } + + + void assertResultIs(const char* expected) + { + Assert::AreEqual(expected, buffer); + } + }; +} \ No newline at end of file