forked from bblanchon/ArduinoJson
Removed Print
class and converted printTo()
to a template method (issue #276)
This commit is contained in:
@ -17,7 +17,7 @@ using namespace ArduinoJson::Internals;
|
||||
void check(const std::string& expected, double input, uint8_t digits = 2) {
|
||||
char output[1024];
|
||||
StaticStringBuilder sb(output, sizeof(output));
|
||||
JsonWriter writer(sb);
|
||||
JsonWriter<StaticStringBuilder> writer(sb);
|
||||
writer.writeFloat(input, digits);
|
||||
REQUIRE(output == expected);
|
||||
REQUIRE(writer.bytesWritten() == expected.size());
|
||||
|
@ -15,7 +15,7 @@ using namespace ArduinoJson::Internals;
|
||||
void check(const char* input, std::string expected) {
|
||||
char output[1024];
|
||||
StaticStringBuilder sb(output, sizeof(output));
|
||||
JsonWriter writer(sb);
|
||||
JsonWriter<StaticStringBuilder> writer(sb);
|
||||
writer.writeString(input);
|
||||
REQUIRE(expected == output);
|
||||
REQUIRE(writer.bytesWritten() == expected.size());
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user