1 | // Copyright Benoit Blanchon 2014-2016
|
---|
2 | // MIT License
|
---|
3 | //
|
---|
4 | // Arduino JSON library
|
---|
5 | // https://github.com/bblanchon/ArduinoJson
|
---|
6 | // If you like this project, please add a star!
|
---|
7 |
|
---|
8 | #include <gtest/gtest.h>
|
---|
9 | #include <ArduinoJson.h>
|
---|
10 |
|
---|
11 | class JsonVariant_PrintTo_Tests : public testing::Test {
|
---|
12 | protected:
|
---|
13 | JsonVariant variant;
|
---|
14 |
|
---|
15 | void outputMustBe(const char *expected) {
|
---|
16 | char buffer[256] = "";
|
---|
17 | size_t n = variant.printTo(buffer, sizeof(buffer));
|
---|
18 | EXPECT_STREQ(expected, buffer);
|
---|
19 | EXPECT_EQ(strlen(expected), n);
|
---|
20 | }
|
---|
21 | };
|
---|
22 |
|
---|
23 | TEST_F(JsonVariant_PrintTo_Tests, Empty) { outputMustBe(""); }
|
---|
24 |
|
---|
25 | TEST_F(JsonVariant_PrintTo_Tests, Null) {
|
---|
26 | variant = static_cast<char *>(0);
|
---|
27 | outputMustBe("null");
|
---|
28 | }
|
---|
29 |
|
---|
30 | TEST_F(JsonVariant_PrintTo_Tests, String) {
|
---|
31 | variant = "hello";
|
---|
32 | outputMustBe("\"hello\"");
|
---|
33 | }
|
---|
34 |
|
---|
35 | TEST_F(JsonVariant_PrintTo_Tests, DoubleZero) {
|
---|
36 | variant = 0.0;
|
---|
37 | outputMustBe("0.00");
|
---|
38 | }
|
---|
39 |
|
---|
40 | TEST_F(JsonVariant_PrintTo_Tests, DoubleDefaultDigits) {
|
---|
41 | variant = 3.14159265358979323846;
|
---|
42 | outputMustBe("3.14");
|
---|
43 | }
|
---|
44 |
|
---|
45 | TEST_F(JsonVariant_PrintTo_Tests, DoubleFourDigits) {
|
---|
46 | variant = JsonVariant(3.14159265358979323846, 4);
|
---|
47 | outputMustBe("3.1416");
|
---|
48 | }
|
---|
49 |
|
---|
50 | TEST_F(JsonVariant_PrintTo_Tests, Integer) {
|
---|
51 | variant = 42;
|
---|
52 | outputMustBe("42");
|
---|
53 | }
|
---|
54 |
|
---|
55 | TEST_F(JsonVariant_PrintTo_Tests, Long) {
|
---|
56 | variant = 42L;
|
---|
57 | outputMustBe("42");
|
---|
58 | }
|
---|
59 |
|
---|
60 | TEST_F(JsonVariant_PrintTo_Tests, Char) {
|
---|
61 | variant = '*';
|
---|
62 | outputMustBe("42");
|
---|
63 | }
|
---|
64 |
|
---|
65 | TEST_F(JsonVariant_PrintTo_Tests, True) {
|
---|
66 | variant = true;
|
---|
67 | outputMustBe("true");
|
---|
68 | }
|
---|
69 |
|
---|
70 | TEST_F(JsonVariant_PrintTo_Tests, OneFalse) {
|
---|
71 | variant = false;
|
---|
72 | outputMustBe("false");
|
---|
73 | }
|
---|
74 |
|
---|
75 | #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
---|
76 | TEST_F(JsonVariant_PrintTo_Tests, NegativeInt64) {
|
---|
77 | variant = -9223372036854775807 - 1;
|
---|
78 | outputMustBe("-9223372036854775808");
|
---|
79 | }
|
---|
80 |
|
---|
81 | TEST_F(JsonVariant_PrintTo_Tests, PositiveInt64) {
|
---|
82 | variant = 9223372036854775807;
|
---|
83 | outputMustBe("9223372036854775807");
|
---|
84 | }
|
---|
85 | #endif
|
---|