From 1c4d4bfd2df78e120437d97c626e7e3244c696bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Thu, 26 Jun 2014 13:16:22 +0200 Subject: [PATCH] Added a test with a NULL string --- JsonGeneratorTests/StringBuilder.cpp | 5 +++++ JsonGeneratorTests/StringBuilderAppendEscapedTests.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/JsonGeneratorTests/StringBuilder.cpp b/JsonGeneratorTests/StringBuilder.cpp index c7230199..113ff95a 100644 --- a/JsonGeneratorTests/StringBuilder.cpp +++ b/JsonGeneratorTests/StringBuilder.cpp @@ -25,6 +25,11 @@ void StringBuilder::append(const char* s) void StringBuilder::appendEscaped(const char* s) { + if (!s) + { + return append("null"); + } + if (length > capacity - 2) { // not enough from for quotes diff --git a/JsonGeneratorTests/StringBuilderAppendEscapedTests.cpp b/JsonGeneratorTests/StringBuilderAppendEscapedTests.cpp index a4bc29c8..96e07581 100644 --- a/JsonGeneratorTests/StringBuilderAppendEscapedTests.cpp +++ b/JsonGeneratorTests/StringBuilderAppendEscapedTests.cpp @@ -28,6 +28,12 @@ namespace JsonGeneratorTests assertResultIs("\"\""); } + TEST_METHOD(Null) + { + append(NULL); + assertResultIs("null"); + } + TEST_METHOD(OneString) { append("ABCD"); @@ -45,6 +51,9 @@ namespace JsonGeneratorTests { append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); assertResultIs("\"ABCDEFGHIJKLMNOPQ\""); + + append(""); + assertResultIs("\"ABCDEFGHIJKLMNOPQ\""); } TEST_METHOD(SpecialChars)