mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-14 11:06:35 +02:00
73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
![]() |
// Copyright Benoit Blanchon 2014
|
||
|
// MIT License
|
||
|
//
|
||
|
// Arduino JSON library
|
||
|
// https://github.com/bblanchon/ArduinoJson
|
||
|
|
||
|
#include <gtest/gtest.h>
|
||
|
#include <ArduinoJson.h>
|
||
|
|
||
|
class JsonVariant_PrintTo_Tests : public testing::Test {
|
||
|
protected:
|
||
|
JsonVariant variant;
|
||
|
|
||
|
void outputMustBe(const char *expected) {
|
||
|
char buffer[256] = "";
|
||
|
size_t n = variant.printTo(buffer, sizeof(buffer));
|
||
|
EXPECT_STREQ(expected, buffer);
|
||
|
EXPECT_EQ(strlen(expected), n);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, Empty) { outputMustBe(""); }
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, Null) {
|
||
|
variant = static_cast<char *>(0);
|
||
|
outputMustBe("null");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, String) {
|
||
|
variant = "hello";
|
||
|
outputMustBe("\"hello\"");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, DoubleZero) {
|
||
|
variant = 0.0;
|
||
|
outputMustBe("0.0");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, DoubleDefaultDigits) {
|
||
|
variant = 3.14159265358979323846;
|
||
|
outputMustBe("3.14");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, DoubleFourDigits) {
|
||
|
variant.set(3.14159265358979323846, 4);
|
||
|
outputMustBe("3.1416");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, Integer) {
|
||
|
variant = 42;
|
||
|
outputMustBe("42");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, Long) {
|
||
|
variant = 42L;
|
||
|
outputMustBe("42");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, Char) {
|
||
|
variant = '*';
|
||
|
outputMustBe("42");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, True) {
|
||
|
variant = true;
|
||
|
outputMustBe("true");
|
||
|
}
|
||
|
|
||
|
TEST_F(JsonVariant_PrintTo_Tests, OneFalse) {
|
||
|
variant = false;
|
||
|
outputMustBe("false");
|
||
|
}
|