2017-11-07 20:42:50 +01:00
|
|
|
// ArduinoJson - arduinojson.org
|
2018-01-05 09:20:01 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2018
|
2014-10-23 23:39:22 +02:00
|
|
|
// MIT License
|
|
|
|
|
2016-05-06 08:44:31 +02:00
|
|
|
#include <ArduinoJson.h>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
2014-10-16 16:23:24 +02:00
|
|
|
|
|
|
|
using namespace ArduinoJson::Internals;
|
|
|
|
|
2017-04-22 11:33:40 +02:00
|
|
|
template <typename StringBuilder, typename String>
|
|
|
|
void common_tests(StringBuilder& sb, const String& output) {
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("InitialState") {
|
|
|
|
REQUIRE(std::string("") == output);
|
2017-01-06 21:07:34 +01:00
|
|
|
}
|
2014-10-16 16:23:24 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("EmptyString") {
|
|
|
|
REQUIRE(0 == sb.print(""));
|
|
|
|
REQUIRE(std::string("") == output);
|
2017-01-06 21:07:34 +01:00
|
|
|
}
|
2014-12-20 19:19:48 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("OneString") {
|
|
|
|
REQUIRE(4 == sb.print("ABCD"));
|
|
|
|
REQUIRE(std::string("ABCD") == output);
|
2017-01-06 21:07:34 +01:00
|
|
|
}
|
2014-10-16 16:23:24 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("TwoStrings") {
|
|
|
|
REQUIRE(4 == sb.print("ABCD"));
|
|
|
|
REQUIRE(4 == sb.print("EFGH"));
|
|
|
|
REQUIRE(std::string("ABCDEFGH") == output);
|
|
|
|
}
|
2014-10-23 23:45:36 +02:00
|
|
|
}
|
2017-04-22 11:33:40 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|