mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Cleaned up
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "JsonHashTable.h"
|
||||
|
||||
using namespace ArduinoJson::Generator;
|
||||
@ -8,6 +13,8 @@ size_t JsonHashTableBase::printTo(Print& p) const
|
||||
|
||||
n += p.write('{');
|
||||
|
||||
// NB: the code has been optimized for a small size on a 8-bit AVR
|
||||
|
||||
KeyValuePair* current = items;
|
||||
for (int i = count; i > 0; i--)
|
||||
{
|
||||
|
97
JsonGeneratorTests/EscapedStringTests.cpp
Normal file
97
JsonGeneratorTests/EscapedStringTests.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "CppUnitTest.h"
|
||||
#include "EscapedString.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
namespace JsonGeneratorTests
|
||||
{
|
||||
TEST_CLASS(EscapedStringTests)
|
||||
{
|
||||
char buffer[1024];
|
||||
size_t returnValue;
|
||||
EscapedString escapedString;
|
||||
|
||||
public:
|
||||
|
||||
TEST_METHOD(Null)
|
||||
{
|
||||
whenInputIs(0);
|
||||
outputMustBe("null");
|
||||
}
|
||||
|
||||
TEST_METHOD(EmptyString)
|
||||
{
|
||||
whenInputIs("");
|
||||
outputMustBe("\"\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(QuotationMark)
|
||||
{
|
||||
whenInputIs("\"");
|
||||
outputMustBe("\"\\\"\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(ReverseSolidus)
|
||||
{
|
||||
whenInputIs("\\");
|
||||
outputMustBe("\"\\\\\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(Solidus)
|
||||
{
|
||||
whenInputIs("/");
|
||||
outputMustBe("\"/\""); // but the JSON format allows \/
|
||||
}
|
||||
|
||||
TEST_METHOD(Backspace)
|
||||
{
|
||||
whenInputIs("\b");
|
||||
outputMustBe("\"\\b\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(Formfeed)
|
||||
{
|
||||
whenInputIs("\f");
|
||||
outputMustBe("\"\\f\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(Newline)
|
||||
{
|
||||
whenInputIs("\n");
|
||||
outputMustBe("\"\\n\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(CarriageReturn)
|
||||
{
|
||||
whenInputIs("\r");
|
||||
outputMustBe("\"\\r\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(HorizontalTab)
|
||||
{
|
||||
whenInputIs("\t");
|
||||
outputMustBe("\"\\t\"");
|
||||
}
|
||||
|
||||
private:
|
||||
void whenInputIs(const char* input)
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
escapedString.set(input);
|
||||
returnValue = escapedString.printTo(sb);
|
||||
}
|
||||
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
Assert::AreEqual(expected, buffer);
|
||||
Assert::AreEqual(strlen(expected), returnValue);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "CppUnitTest.h"
|
||||
#include "JsonArray.h"
|
||||
#include "JsonHashTable.h"
|
||||
@ -16,137 +21,117 @@ namespace JsonGeneratorTests
|
||||
|
||||
TEST_METHOD(Empty)
|
||||
{
|
||||
returnValueIs(2);
|
||||
jsonIs("[]");
|
||||
outputMustBe("[]");
|
||||
}
|
||||
|
||||
TEST_METHOD(Null)
|
||||
{
|
||||
addValue((char*)0);
|
||||
add((char*)0);
|
||||
|
||||
returnValueIs(6);
|
||||
jsonIs("[null]");
|
||||
outputMustBe("[null]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneString)
|
||||
{
|
||||
addValue("hello");
|
||||
add("hello");
|
||||
|
||||
returnValueIs(9);
|
||||
jsonIs("[\"hello\"]");
|
||||
outputMustBe("[\"hello\"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(TwoStrings)
|
||||
{
|
||||
addValue("hello");
|
||||
addValue("world");
|
||||
add("hello");
|
||||
add("world");
|
||||
|
||||
returnValueIs(17);
|
||||
jsonIs("[\"hello\",\"world\"]");
|
||||
outputMustBe("[\"hello\",\"world\"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneStringOverCapacity)
|
||||
{
|
||||
addValue("hello");
|
||||
addValue("world");
|
||||
addValue("lost");
|
||||
add("hello");
|
||||
add("world");
|
||||
add("lost");
|
||||
|
||||
returnValueIs(17);
|
||||
jsonIs("[\"hello\",\"world\"]");
|
||||
outputMustBe("[\"hello\",\"world\"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDoubleDefaultDigits)
|
||||
{
|
||||
addValue(3.14159265358979323846);
|
||||
jsonIs("[3.14]");
|
||||
add(3.14159265358979323846);
|
||||
outputMustBe("[3.14]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDoubleFourDigits)
|
||||
{
|
||||
addValue<4>(3.14159265358979323846);
|
||||
jsonIs("[3.1416]");
|
||||
add<4>(3.14159265358979323846);
|
||||
outputMustBe("[3.1416]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneInteger)
|
||||
{
|
||||
addValue(1);
|
||||
add(1);
|
||||
|
||||
returnValueIs(3);
|
||||
jsonIs("[1]");
|
||||
outputMustBe("[1]");
|
||||
}
|
||||
|
||||
TEST_METHOD(TwoIntegers)
|
||||
{
|
||||
addValue(1);
|
||||
addValue(2);
|
||||
add(1);
|
||||
add(2);
|
||||
|
||||
returnValueIs(5);
|
||||
jsonIs("[1,2]");
|
||||
outputMustBe("[1,2]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneIntegerOverCapacity)
|
||||
{
|
||||
addValue(1);
|
||||
addValue(2);
|
||||
addValue(3);
|
||||
add(1);
|
||||
add(2);
|
||||
add(3);
|
||||
|
||||
returnValueIs(5);
|
||||
jsonIs("[1,2]");
|
||||
outputMustBe("[1,2]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneTrue)
|
||||
{
|
||||
addValue(true);
|
||||
add(true);
|
||||
|
||||
returnValueIs(6);
|
||||
jsonIs("[true]");
|
||||
outputMustBe("[true]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneFalse)
|
||||
{
|
||||
addValue(false);
|
||||
add(false);
|
||||
|
||||
returnValueIs(7);
|
||||
jsonIs("[false]");
|
||||
outputMustBe("[false]");
|
||||
}
|
||||
|
||||
TEST_METHOD(TwoBooleans)
|
||||
{
|
||||
addValue(false);
|
||||
addValue(true);
|
||||
add(false);
|
||||
add(true);
|
||||
|
||||
returnValueIs(12);
|
||||
jsonIs("[false,true]");
|
||||
outputMustBe("[false,true]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneBooleanOverCapacity)
|
||||
{
|
||||
addValue(false);
|
||||
addValue(true);
|
||||
addValue(false);
|
||||
add(false);
|
||||
add(true);
|
||||
add(false);
|
||||
|
||||
returnValueIs(12);
|
||||
jsonIs("[false,true]");
|
||||
outputMustBe("[false,true]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneEmptyNestedArray)
|
||||
{
|
||||
JsonArray<1> nestedArray;
|
||||
|
||||
addNested(nestedArray);
|
||||
|
||||
returnValueIs(4);
|
||||
jsonIs("[[]]");
|
||||
addNested(JsonArray<1>());
|
||||
outputMustBe("[[]]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneEmptyNestedHash)
|
||||
{
|
||||
JsonHashTable<1> nestedHash;
|
||||
|
||||
addNested(nestedHash);
|
||||
|
||||
returnValueIs(4);
|
||||
jsonIs("[{}]");
|
||||
addNested(JsonHashTable<1>());
|
||||
outputMustBe("[{}]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneNestedArrayWithOneInteger)
|
||||
@ -156,8 +141,7 @@ namespace JsonGeneratorTests
|
||||
|
||||
addNested(nestedArray);
|
||||
|
||||
returnValueIs(5);
|
||||
jsonIs("[[1]]");
|
||||
outputMustBe("[[1]]");
|
||||
}
|
||||
|
||||
private:
|
||||
@ -168,27 +152,22 @@ namespace JsonGeneratorTests
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void addValue(T value)
|
||||
void add(T value)
|
||||
{
|
||||
arr.add(value);
|
||||
}
|
||||
|
||||
template<int DIGITS>
|
||||
void addValue(double value)
|
||||
void add(double value)
|
||||
{
|
||||
arr.add<DIGITS>(value);
|
||||
}
|
||||
|
||||
void jsonIs(const char* expected)
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
arr.printTo(buffer, sizeof(buffer));
|
||||
size_t n = arr.printTo(buffer, sizeof(buffer));
|
||||
Assert::AreEqual(expected, buffer);
|
||||
}
|
||||
|
||||
void returnValueIs(size_t expected)
|
||||
{
|
||||
size_t actual = arr.printTo(buffer, sizeof(buffer));
|
||||
Assert::AreEqual(expected, actual);
|
||||
Assert::AreEqual(strlen(expected), n);
|
||||
}
|
||||
};
|
||||
}
|
@ -89,6 +89,7 @@
|
||||
<ClCompile Include="..\JsonGenerator\JsonHashTableBase.cpp" />
|
||||
<ClCompile Include="..\JsonGenerator\JsonValue.cpp" />
|
||||
<ClCompile Include="..\JsonGenerator\StringBuilder.cpp" />
|
||||
<ClCompile Include="EscapedStringTests.cpp" />
|
||||
<ClCompile Include="JsonArrayTests.cpp" />
|
||||
<ClCompile Include="JsonHashTableTests.cpp" />
|
||||
<ClCompile Include="JsonValueTests.cpp" />
|
||||
|
@ -45,6 +45,9 @@
|
||||
<ClCompile Include="..\JsonGenerator\JsonArrayBase.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EscapedStringTests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\JsonGenerator\JsonArray.h">
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "CppUnitTest.h"
|
||||
#include "JsonArray.h"
|
||||
#include "JsonHashTable.h"
|
||||
@ -16,83 +21,78 @@ namespace JsonGeneratorTests
|
||||
|
||||
TEST_METHOD(Empty)
|
||||
{
|
||||
jsonIs("{}");
|
||||
outputMustBe("{}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneString)
|
||||
{
|
||||
addValue("key", "value");
|
||||
|
||||
jsonIs("{\"key\":\"value\"}");
|
||||
add("key", "value");
|
||||
outputMustBe("{\"key\":\"value\"}");
|
||||
}
|
||||
|
||||
TEST_METHOD(TwoStrings)
|
||||
{
|
||||
addValue("key1", "value1");
|
||||
addValue("key2", "value2");
|
||||
add("key1", "value1");
|
||||
add("key2", "value2");
|
||||
|
||||
jsonIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneStringOverCapacity)
|
||||
{
|
||||
addValue("key1", "value1");
|
||||
addValue("key2", "value2");
|
||||
addValue("key3", "value3");
|
||||
add("key1", "value1");
|
||||
add("key2", "value2");
|
||||
add("key3", "value3");
|
||||
|
||||
jsonIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneInteger)
|
||||
{
|
||||
addValue("key", 1);
|
||||
jsonIs("{\"key\":1}");
|
||||
add("key", 1);
|
||||
outputMustBe("{\"key\":1}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDoubleFourDigits)
|
||||
{
|
||||
addValue<4>("key", 3.14159265358979323846);
|
||||
jsonIs("{\"key\":3.1416}");
|
||||
add<4>("key", 3.14159265358979323846);
|
||||
outputMustBe("{\"key\":3.1416}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDoubleDefaultDigits)
|
||||
{
|
||||
addValue("key", 3.14159265358979323846);
|
||||
jsonIs("{\"key\":3.14}");
|
||||
add("key", 3.14159265358979323846);
|
||||
outputMustBe("{\"key\":3.14}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneNull)
|
||||
{
|
||||
addValue("key", (char*) 0);
|
||||
jsonIs("{\"key\":null}");
|
||||
add("key", (char*) 0);
|
||||
outputMustBe("{\"key\":null}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneTrue)
|
||||
{
|
||||
addValue("key", true);
|
||||
jsonIs("{\"key\":true}");
|
||||
add("key", true);
|
||||
outputMustBe("{\"key\":true}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneFalse)
|
||||
{
|
||||
addValue("key", false);
|
||||
jsonIs("{\"key\":false}");
|
||||
add("key", false);
|
||||
outputMustBe("{\"key\":false}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneEmptyNestedArray)
|
||||
{
|
||||
JsonArray<1> nestedArray;
|
||||
addNested("key", nestedArray);
|
||||
|
||||
jsonIs("{\"key\":[]}");
|
||||
addNested("key", JsonArray<1>());
|
||||
outputMustBe("{\"key\":[]}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneEmptyNestedHash)
|
||||
{
|
||||
JsonHashTable<1> nestedHash;
|
||||
addNested("key", nestedHash);
|
||||
|
||||
jsonIs("{\"key\":{}}");
|
||||
addNested("key", JsonHashTable<1>());
|
||||
outputMustBe("{\"key\":{}}");
|
||||
}
|
||||
|
||||
private:
|
||||
@ -103,18 +103,18 @@ namespace JsonGeneratorTests
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void addValue(const char* key, T value)
|
||||
void add(const char* key, T value)
|
||||
{
|
||||
hash.add(key, value);
|
||||
}
|
||||
|
||||
template<int DIGITS>
|
||||
void addValue(const char* key, double value)
|
||||
void add(const char* key, double value)
|
||||
{
|
||||
hash.add<DIGITS>(key, value);
|
||||
}
|
||||
|
||||
void jsonIs(const char* expected)
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
size_t actual = hash.printTo(buffer, sizeof(buffer));
|
||||
Assert::AreEqual(expected, buffer);
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "CppUnitTest.h"
|
||||
#include "StringBuilder.h"
|
||||
#include "JsonValue.h"
|
||||
@ -14,104 +19,64 @@ namespace JsonGeneratorTests
|
||||
|
||||
public:
|
||||
|
||||
TEST_METHOD(Null)
|
||||
TEST_METHOD(String)
|
||||
{
|
||||
write((char*)0);
|
||||
assertResultIs("null");
|
||||
whenInputIs("hello");
|
||||
outputMustBe("\"hello\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(EmptyString)
|
||||
TEST_METHOD(Float)
|
||||
{
|
||||
write("");
|
||||
assertResultIs("\"\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(QuotationMark)
|
||||
{
|
||||
write("\"");
|
||||
assertResultIs("\"\\\"\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(ReverseSolidus)
|
||||
{
|
||||
write("\\");
|
||||
assertResultIs("\"\\\\\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(Solidus)
|
||||
{
|
||||
write("/");
|
||||
assertResultIs("\"/\""); // but the JSON format allows \/
|
||||
}
|
||||
|
||||
TEST_METHOD(Backspace)
|
||||
{
|
||||
write("\b");
|
||||
assertResultIs("\"\\b\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(Formfeed)
|
||||
{
|
||||
write("\f");
|
||||
assertResultIs("\"\\f\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(Newline)
|
||||
{
|
||||
write("\n");
|
||||
assertResultIs("\"\\n\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(CarriageReturn)
|
||||
{
|
||||
write("\r");
|
||||
assertResultIs("\"\\r\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(HorizontalTab)
|
||||
{
|
||||
write("\t");
|
||||
assertResultIs("\"\\t\"");
|
||||
whenInputIs(3.1415f);
|
||||
outputMustBe("3.14");
|
||||
}
|
||||
|
||||
TEST_METHOD(DoubleZeroDigits)
|
||||
{
|
||||
write<0>(3.14159265358979323846);
|
||||
assertResultIs("3");
|
||||
whenInputIs<0>(3.14159265358979323846);
|
||||
outputMustBe("3");
|
||||
}
|
||||
|
||||
TEST_METHOD(DoubleOneDigit)
|
||||
{
|
||||
write<1>(3.14159265358979323846);
|
||||
assertResultIs("3.1");
|
||||
whenInputIs<1>(3.14159265358979323846);
|
||||
outputMustBe("3.1");
|
||||
}
|
||||
|
||||
TEST_METHOD(DoubleTwoDigits)
|
||||
{
|
||||
write<2>(3.14159265358979323846);
|
||||
assertResultIs("3.14");
|
||||
whenInputIs<2>(3.14159265358979323846);
|
||||
outputMustBe("3.14");
|
||||
}
|
||||
|
||||
TEST_METHOD(Integer)
|
||||
{
|
||||
write(314);
|
||||
assertResultIs("314");
|
||||
whenInputIs(314);
|
||||
outputMustBe("314");
|
||||
}
|
||||
|
||||
TEST_METHOD(Char)
|
||||
{
|
||||
whenInputIs('A');
|
||||
outputMustBe("65");
|
||||
}
|
||||
|
||||
TEST_METHOD(Short)
|
||||
{
|
||||
write((short)314);
|
||||
assertResultIs("314");
|
||||
whenInputIs((short)314);
|
||||
outputMustBe("314");
|
||||
}
|
||||
|
||||
TEST_METHOD(Long)
|
||||
{
|
||||
write(314L);
|
||||
assertResultIs("314");
|
||||
whenInputIs(314159265L);
|
||||
outputMustBe("314159265");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template<int DIGITS>
|
||||
void write(double value)
|
||||
void whenInputIs(double value)
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
JsonValue jsonValue;
|
||||
@ -120,7 +85,7 @@ namespace JsonGeneratorTests
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(T value)
|
||||
void whenInputIs(T value)
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
JsonValue jsonValue;
|
||||
@ -128,7 +93,7 @@ namespace JsonGeneratorTests
|
||||
returnValue = jsonValue.printTo(sb);
|
||||
}
|
||||
|
||||
void assertResultIs(const char* expected)
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
Assert::AreEqual(expected, buffer);
|
||||
Assert::AreEqual(strlen(expected), returnValue);
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "Print.h"
|
||||
#include <cstdio>
|
||||
//#include <cstring>
|
||||
|
||||
size_t Print::print(const char s[])
|
||||
{
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "CppUnitTest.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
@ -21,59 +26,58 @@ namespace JsonGeneratorTests
|
||||
|
||||
TEST_METHOD(InitialState)
|
||||
{
|
||||
assertResultIs("");
|
||||
outputMustBe("");
|
||||
}
|
||||
|
||||
TEST_METHOD(OverCapacity)
|
||||
{
|
||||
write("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
assertReturns(19);
|
||||
assertResultIs("ABCDEFGHIJKLMNOPQRS");
|
||||
print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
resultMustBe(19);
|
||||
|
||||
write("ABC");
|
||||
assertReturns(0);
|
||||
assertResultIs("ABCDEFGHIJKLMNOPQRS");
|
||||
print("ABC");
|
||||
resultMustBe(0);
|
||||
|
||||
outputMustBe("ABCDEFGHIJKLMNOPQRS");
|
||||
}
|
||||
|
||||
TEST_METHOD(EmptyString)
|
||||
{
|
||||
write("");
|
||||
|
||||
assertReturns(0);
|
||||
assertResultIs("");
|
||||
print("");
|
||||
resultMustBe(0);
|
||||
outputMustBe("");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneString)
|
||||
{
|
||||
write("ABCD");
|
||||
assertReturns(4);
|
||||
assertResultIs("ABCD");
|
||||
print("ABCD");
|
||||
resultMustBe(4);
|
||||
outputMustBe("ABCD");
|
||||
}
|
||||
|
||||
TEST_METHOD(TwoStrings)
|
||||
{
|
||||
write("ABCD");
|
||||
assertReturns(4);
|
||||
print("ABCD");
|
||||
resultMustBe(4);
|
||||
|
||||
write("EFGH");
|
||||
assertReturns(4);
|
||||
print("EFGH");
|
||||
resultMustBe(4);
|
||||
|
||||
assertResultIs("ABCDEFGH");
|
||||
outputMustBe("ABCDEFGH");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void write(const char* value)
|
||||
void print(const char* value)
|
||||
{
|
||||
returnValue = sb->print(value);
|
||||
}
|
||||
|
||||
void assertResultIs(const char* expected)
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
Assert::AreEqual(expected, buffer);
|
||||
}
|
||||
|
||||
void assertReturns(size_t expected)
|
||||
void resultMustBe(size_t expected)
|
||||
{
|
||||
Assert::AreEqual(expected, returnValue);
|
||||
}
|
||||
|
Reference in New Issue
Block a user