Removed Print class and converted printTo() to a template method (issue #276)

This commit is contained in:
Benoit Blanchon
2017-04-22 11:33:40 +02:00
parent c3e1677b7d
commit 9afa05e2f4
19 changed files with 147 additions and 173 deletions

View File

@ -10,20 +10,12 @@
using namespace ArduinoJson::Internals;
TEST_CASE("StringBuilder") {
char output[20];
StaticStringBuilder sb(output, sizeof(output));
template <typename StringBuilder, typename String>
void common_tests(StringBuilder& sb, const String& output) {
SECTION("InitialState") {
REQUIRE(std::string("") == output);
}
SECTION("OverCapacity") {
REQUIRE(19 == sb.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
REQUIRE(0 == sb.print("ABC"));
REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == output);
}
SECTION("EmptyString") {
REQUIRE(0 == sb.print(""));
REQUIRE(std::string("") == output);
@ -40,3 +32,22 @@ TEST_CASE("StringBuilder") {
REQUIRE(std::string("ABCDEFGH") == output);
}
}
TEST_CASE("StaticStringBuilder") {
char output[20];
StaticStringBuilder sb(output, sizeof(output));
common_tests(sb, static_cast<const char*>(output));
SECTION("OverCapacity") {
REQUIRE(19 == sb.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
REQUIRE(0 == sb.print("ABC"));
REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == output);
}
}
TEST_CASE("DynamicStringBuilder") {
std::string output;
DynamicStringBuilder<std::string> sb(output);
common_tests(sb, output);
}