forked from bblanchon/ArduinoJson
@ -1,48 +0,0 @@
|
||||
// Copyright Benoit Blanchon 2014-2016
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class Issue67 : public testing::Test {
|
||||
public:
|
||||
void whenInputIs(double value) { _variant = value; }
|
||||
|
||||
void outputMustBe(const char* expected) {
|
||||
char buffer[1024];
|
||||
_variant.printTo(buffer, sizeof(buffer));
|
||||
ASSERT_STREQ(expected, buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
JsonVariant _variant;
|
||||
};
|
||||
|
||||
TEST_F(Issue67, BigPositiveDouble) {
|
||||
whenInputIs(1e100);
|
||||
outputMustBe("1e+100");
|
||||
}
|
||||
|
||||
TEST_F(Issue67, BigNegativeDouble) {
|
||||
whenInputIs(-1e100);
|
||||
outputMustBe("-1e+100");
|
||||
}
|
||||
|
||||
TEST_F(Issue67, Zero) {
|
||||
whenInputIs(0.0);
|
||||
outputMustBe("0.00");
|
||||
}
|
||||
|
||||
TEST_F(Issue67, SmallPositiveDouble) {
|
||||
whenInputIs(111.111);
|
||||
outputMustBe("111.11");
|
||||
}
|
||||
|
||||
TEST_F(Issue67, SmallNegativeDouble) {
|
||||
whenInputIs(-111.111);
|
||||
outputMustBe("-111.11");
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <limits>
|
||||
|
||||
class JsonVariant_PrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
@ -15,8 +16,8 @@ class JsonVariant_PrintTo_Tests : public testing::Test {
|
||||
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);
|
||||
ASSERT_STREQ(expected, buffer);
|
||||
ASSERT_EQ(strlen(expected), n);
|
||||
}
|
||||
};
|
||||
|
||||
@ -47,6 +48,46 @@ TEST_F(JsonVariant_PrintTo_Tests, DoubleFourDigits) {
|
||||
outputMustBe("3.1416");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Infinity) {
|
||||
variant = std::numeric_limits<double>::infinity();
|
||||
outputMustBe("Infinity");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, MinusInfinity) {
|
||||
variant = -std::numeric_limits<double>::infinity();
|
||||
outputMustBe("-Infinity");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, SignalingNaN) {
|
||||
variant = std::numeric_limits<double>::signaling_NaN();
|
||||
outputMustBe("NaN");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, QuietNaN) {
|
||||
variant = std::numeric_limits<double>::quiet_NaN();
|
||||
outputMustBe("NaN");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VeryBigPositiveDouble) {
|
||||
variant = JsonVariant(3.14159265358979323846e42, 4);
|
||||
outputMustBe("3.1416e42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VeryBigNegativeDouble) {
|
||||
variant = JsonVariant(-3.14159265358979323846e42, 4);
|
||||
outputMustBe("-3.1416e42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VerySmallPositiveDouble) {
|
||||
variant = JsonVariant(3.14159265358979323846e-42, 4);
|
||||
outputMustBe("3.1416e-42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VerySmallNegativeDouble) {
|
||||
variant = JsonVariant(-3.14159265358979323846e-42, 4);
|
||||
outputMustBe("-3.1416e-42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Integer) {
|
||||
variant = 42;
|
||||
outputMustBe("42");
|
||||
@ -62,11 +103,6 @@ TEST_F(JsonVariant_PrintTo_Tests, UnsignedLong) {
|
||||
outputMustBe("4294967295");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Char) {
|
||||
variant = '*';
|
||||
outputMustBe("42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, True) {
|
||||
variant = true;
|
||||
outputMustBe("true");
|
||||
|
Reference in New Issue
Block a user