2017-01-06 21:07:34 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2017
|
2014-10-23 23:39:22 +02:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
2017-03-25 22:05:06 +01:00
|
|
|
// https://bblanchon.github.io/ArduinoJson/
|
2016-01-07 22:35:12 +01:00
|
|
|
// If you like this project, please add a star!
|
2014-10-23 23:39:22 +02:00
|
|
|
|
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-18 18:22:24 +02:00
|
|
|
TEST_CASE("StringBuilder") {
|
|
|
|
char output[20];
|
|
|
|
StaticStringBuilder sb(output, sizeof(output));
|
2014-10-16 16:23:24 +02:00
|
|
|
|
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("OverCapacity") {
|
|
|
|
REQUIRE(19 == sb.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
|
|
REQUIRE(0 == sb.print("ABC"));
|
|
|
|
REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == 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
|
|
|
}
|