Added support of long long (issue #171)

Moved all build settings to `ArduinoJson/Configuration.hpp`
Added AppVeyor settings in source tree
This commit is contained in:
Benoit Blanchon
2016-02-14 16:18:13 +01:00
parent ce63e9c3c3
commit 8733f95e51
53 changed files with 945 additions and 869 deletions

View File

@ -17,7 +17,11 @@ add_definitions(-DGTEST_HAS_PTHREAD=0)
# Workaround for Visual Studio 2012
if (MSVC AND MSVC_VERSION EQUAL 1700)
add_definitions(-D_VARIADIC_MAX=10)
add_definitions(-D_VARIADIC_MAX=10)
endif()
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
add_executable(ArduinoJsonTests
@ -25,6 +29,7 @@ add_executable(ArduinoJsonTests
${GTEST_DIR}/src/gtest-all.cc
${GTEST_DIR}/src/gtest_main.cc)
target_link_libraries(ArduinoJsonTests ArduinoJson)
add_test(ArduinoJsonTests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ArduinoJsonTests)

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class GbathreeBug : public testing::Test {

View File

@ -7,7 +7,9 @@
#include <gtest/gtest.h>
#include <limits.h> // for LONG_MAX
#define ARDUINOJSON_ENABLE_STD_STREAM
#define ARDUINOJSON_USE_LONG_LONG 0
#define ARDUINOJSON_USE_INT64 0
#include <ArduinoJson.h>
#define SUITE Issue90

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class JsonArray_Add_Tests : public ::testing::Test {

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
#define TEST_(name) TEST(JsonArray_Basic_Tests, name)

View File

@ -64,10 +64,25 @@ TEST_F(JsonArray_PrintTo_Tests, OneDoubleDefaultDigits) {
}
TEST_F(JsonArray_PrintTo_Tests, OneDoubleFourDigits) {
array.add(3.14159265358979323846, 4);
outputMustBe("[3.1416]");
}
TEST_F(JsonArray_PrintTo_Tests, OneDoubleFourDigits_AlternativeSyntax) {
array.add(double_with_n_digits(3.14159265358979323846, 4));
outputMustBe("[3.1416]");
}
TEST_F(JsonArray_PrintTo_Tests, OneFloatDefaultDigits) {
array.add(3.14159f);
outputMustBe("[3.14]");
}
TEST_F(JsonArray_PrintTo_Tests, OneFloatFourDigits) {
array.add(3.14159f, 4);
outputMustBe("[3.1416]");
}
TEST_F(JsonArray_PrintTo_Tests, OneInteger) {
array.add(1);

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class JsonArray_Set_Tests : public ::testing::Test {

View File

@ -5,9 +5,9 @@
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
#include <gtest/gtest.h>
#include <stdint.h>
class JsonArray_Subscript_Tests : public ::testing::Test {
protected:
@ -33,6 +33,15 @@ TEST_(StoreInteger) {
EXPECT_FALSE(_array[0].is<double>());
}
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
TEST_(StoreLongLong) {
_array[0] = 9223372036854775807;
EXPECT_EQ(9223372036854775807, _array[0].as<long long>());
EXPECT_TRUE(_array[0].is<int>());
EXPECT_FALSE(_array[0].is<double>());
}
#endif
TEST_(StoreDouble) {
_array[0] = 123.45;
EXPECT_EQ(123.45, _array[0].as<double>());

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class JsonObject_Iterator_Test : public testing::Test {

View File

@ -5,8 +5,8 @@
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <ArduinoJson.h>
#include <gtest/gtest.h>
using namespace ArduinoJson::Internals;
@ -78,7 +78,8 @@ TEST_F(JsonObject_PrintTo_Tests, TwoIntegers) {
TEST_F(JsonObject_PrintTo_Tests, TwoDoublesFourDigits) {
_object["a"] = double_with_n_digits(3.14159265358979323846, 4);
_object.set("b", 2.71828182845904523536, 4);
outputMustBe("{\"a\":3.1416,\"b\":2.7183}");
_object.set("c", double_with_n_digits(3.14159265358979323846, 3));
outputMustBe("{\"a\":3.1416,\"b\":2.7183,\"c\":3.142}");
}
TEST_F(JsonObject_PrintTo_Tests, TwoDoubleDefaultDigits) {

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class JsonObject_Set_Tests : public ::testing::Test {

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class JsonObject_Subscript_Tests : public ::testing::Test {

View File

@ -5,10 +5,11 @@
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
#include <gtest/gtest.h>
#include <stdint.h>
static const char* null = 0;
TEST(JsonVariant_As_Tests, DoubleAsBool) {
@ -136,6 +137,18 @@ TEST(JsonVariant_As_Tests, NumberStringAsLong) {
ASSERT_EQ(42L, variant.as<long>());
}
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
TEST(JsonVariant_As_Tests, NumberStringAsInt64Negative) {
JsonVariant variant = "-9223372036854775808";
ASSERT_EQ(-9223372036854775807 - 1, variant.as<long long>());
}
TEST(JsonVariant_As_Tests, NumberStringAsInt64Positive) {
JsonVariant variant = "9223372036854775807";
ASSERT_EQ(9223372036854775807, variant.as<long long>());
}
#endif
TEST(JsonVariant_As_Tests, RandomStringAsBool) {
JsonVariant variant = "hello";
ASSERT_FALSE(variant.as<bool>());

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson/JsonVariant.hpp>
using namespace ArduinoJson;

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
#define SUITE JsonVariant_Is_Tests

View File

@ -71,3 +71,15 @@ TEST_F(JsonVariant_PrintTo_Tests, OneFalse) {
variant = false;
outputMustBe("false");
}
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
TEST_F(JsonVariant_PrintTo_Tests, NegativeInt64) {
variant = -9223372036854775807 - 1;
outputMustBe("-9223372036854775808");
}
TEST_F(JsonVariant_PrintTo_Tests, PositiveInt64) {
variant = 9223372036854775807;
outputMustBe("9223372036854775807");
}
#endif

View File

@ -6,40 +6,74 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <stdint.h>
#include <limits>
#include <ArduinoJson.h>
class JsonVariant_Storage_Tests : public ::testing::Test {
protected:
template <typename T>
void testValue(T expected) {
_actual = expected;
EXPECT_EQ(expected, _actual.as<T>());
JsonVariant variant = expected;
EXPECT_EQ(expected, variant.as<T>());
}
template <typename T>
void testReference(T &expected) {
_actual = expected;
EXPECT_EQ(expected, _actual.as<T &>());
JsonVariant variant = expected;
EXPECT_EQ(expected, variant.as<T &>());
}
private:
JsonVariant _actual;
template <typename T>
void testNumericType() {
T min = std::numeric_limits<T>::min();
T max = std::numeric_limits<T>::max();
JsonVariant variantMin(min);
JsonVariant variantMax(max);
EXPECT_EQ(min, variantMin.as<T>());
EXPECT_EQ(max, variantMax.as<T>());
}
};
TEST_F(JsonVariant_Storage_Tests, Double) { testValue<double>(123.45); }
TEST_F(JsonVariant_Storage_Tests, False) { testValue<bool>(false); }
TEST_F(JsonVariant_Storage_Tests, Float) { testValue<float>(123.45f); }
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
TEST_F(JsonVariant_Storage_Tests, SizeOfJsonInteger) {
ASSERT_EQ(8, sizeof(Internals::JsonInteger));
}
#endif
TEST_F(JsonVariant_Storage_Tests, Null) { testValue<const char *>(NULL); }
TEST_F(JsonVariant_Storage_Tests, SChar) { testValue<signed char>(123); }
TEST_F(JsonVariant_Storage_Tests, SInt) { testValue<signed int>(123); }
TEST_F(JsonVariant_Storage_Tests, SLong) { testValue<signed long>(123L); }
TEST_F(JsonVariant_Storage_Tests, SShort) { testValue<signed short>(123); }
TEST_F(JsonVariant_Storage_Tests, String) { testValue<const char *>("hello"); }
TEST_F(JsonVariant_Storage_Tests, False) { testValue<bool>(false); }
TEST_F(JsonVariant_Storage_Tests, True) { testValue<bool>(true); }
TEST_F(JsonVariant_Storage_Tests, UChar) { testValue<unsigned char>(123); }
TEST_F(JsonVariant_Storage_Tests, UInt) { testValue<unsigned int>(123U); }
TEST_F(JsonVariant_Storage_Tests, ULong) { testValue<unsigned long>(123UL); }
TEST_F(JsonVariant_Storage_Tests, UShort) { testValue<unsigned short>(123); }
TEST_F(JsonVariant_Storage_Tests, Double) { testNumericType<double>(); }
TEST_F(JsonVariant_Storage_Tests, Float) { testNumericType<float>(); }
TEST_F(JsonVariant_Storage_Tests, SChar) { testNumericType<signed char>(); }
TEST_F(JsonVariant_Storage_Tests, SInt) { testNumericType<signed int>(); }
TEST_F(JsonVariant_Storage_Tests, SLong) { testNumericType<signed long>(); }
TEST_F(JsonVariant_Storage_Tests, SShort) { testNumericType<signed short>(); }
TEST_F(JsonVariant_Storage_Tests, UChar) { testNumericType<unsigned char>(); }
TEST_F(JsonVariant_Storage_Tests, UInt) { testNumericType<unsigned int>(); }
TEST_F(JsonVariant_Storage_Tests, ULong) { testNumericType<unsigned long>(); }
TEST_F(JsonVariant_Storage_Tests, UShort) { testNumericType<unsigned short>(); }
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
TEST_F(JsonVariant_Storage_Tests, LongLong) { testNumericType<unsigned long long>(); }
TEST_F(JsonVariant_Storage_Tests, ULongLong) { testNumericType<unsigned long long>(); }
#endif
TEST_F(JsonVariant_Storage_Tests, Int8) { testNumericType<int8_t>(); }
TEST_F(JsonVariant_Storage_Tests, Uint8) { testNumericType<uint8_t>(); }
TEST_F(JsonVariant_Storage_Tests, Int16) { testNumericType<int16_t>(); }
TEST_F(JsonVariant_Storage_Tests, Uint16) { testNumericType<uint16_t>(); }
TEST_F(JsonVariant_Storage_Tests, Int32) { testNumericType<int32_t>(); }
TEST_F(JsonVariant_Storage_Tests, Uint32) { testNumericType<uint32_t>(); }
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
TEST_F(JsonVariant_Storage_Tests, Int64) { testNumericType<int64_t>(); }
TEST_F(JsonVariant_Storage_Tests, Uint64) { testNumericType<uint64_t>(); }
#endif
TEST_F(JsonVariant_Storage_Tests, CanStoreObject) {
DynamicJsonBuffer jsonBuffer;

View File

@ -6,7 +6,6 @@
// If you like this project, please add a star!
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
class JsonVariant_Undefined_Tests : public ::testing::Test {

View File

@ -7,7 +7,6 @@
#include <sstream>
#include <gtest/gtest.h>
#define ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson.h>
TEST(StdStream, JsonVariantFalse) {