source: rtos_arduino/trunk/arduino_lib/libraries/ArduinoJson/test/JsonVariant_Storage_Tests.cpp@ 209

Last change on this file since 209 was 209, checked in by ertl-honda, 8 years ago

BlueMix用のフィアルを追加

File size: 3.1 KB
Line 
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 <stdint.h>
10#include <limits>
11#include <ArduinoJson.h>
12
13class JsonVariant_Storage_Tests : public ::testing::Test {
14 protected:
15 template <typename T>
16 void testValue(T expected) {
17 JsonVariant variant = expected;
18 EXPECT_EQ(expected, variant.as<T>());
19 }
20
21 template <typename T>
22 void testReference(T &expected) {
23 JsonVariant variant = expected;
24 EXPECT_EQ(expected, variant.as<T &>());
25 }
26
27 template <typename T>
28 void testNumericType() {
29 T min = std::numeric_limits<T>::min();
30 T max = std::numeric_limits<T>::max();
31
32 JsonVariant variantMin(min);
33 JsonVariant variantMax(max);
34
35 EXPECT_EQ(min, variantMin.as<T>());
36 EXPECT_EQ(max, variantMax.as<T>());
37 }
38};
39
40#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
41TEST_F(JsonVariant_Storage_Tests, SizeOfJsonInteger) {
42 ASSERT_EQ(8, sizeof(Internals::JsonInteger));
43}
44#endif
45
46TEST_F(JsonVariant_Storage_Tests, Null) { testValue<const char *>(NULL); }
47TEST_F(JsonVariant_Storage_Tests, String) { testValue<const char *>("hello"); }
48
49TEST_F(JsonVariant_Storage_Tests, False) { testValue<bool>(false); }
50TEST_F(JsonVariant_Storage_Tests, True) { testValue<bool>(true); }
51
52TEST_F(JsonVariant_Storage_Tests, Double) { testNumericType<double>(); }
53TEST_F(JsonVariant_Storage_Tests, Float) { testNumericType<float>(); }
54TEST_F(JsonVariant_Storage_Tests, SChar) { testNumericType<signed char>(); }
55TEST_F(JsonVariant_Storage_Tests, SInt) { testNumericType<signed int>(); }
56TEST_F(JsonVariant_Storage_Tests, SLong) { testNumericType<signed long>(); }
57TEST_F(JsonVariant_Storage_Tests, SShort) { testNumericType<signed short>(); }
58TEST_F(JsonVariant_Storage_Tests, UChar) { testNumericType<unsigned char>(); }
59TEST_F(JsonVariant_Storage_Tests, UInt) { testNumericType<unsigned int>(); }
60TEST_F(JsonVariant_Storage_Tests, ULong) { testNumericType<unsigned long>(); }
61TEST_F(JsonVariant_Storage_Tests, UShort) { testNumericType<unsigned short>(); }
62#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
63TEST_F(JsonVariant_Storage_Tests, LongLong) { testNumericType<unsigned long long>(); }
64TEST_F(JsonVariant_Storage_Tests, ULongLong) { testNumericType<unsigned long long>(); }
65#endif
66
67TEST_F(JsonVariant_Storage_Tests, Int8) { testNumericType<int8_t>(); }
68TEST_F(JsonVariant_Storage_Tests, Uint8) { testNumericType<uint8_t>(); }
69TEST_F(JsonVariant_Storage_Tests, Int16) { testNumericType<int16_t>(); }
70TEST_F(JsonVariant_Storage_Tests, Uint16) { testNumericType<uint16_t>(); }
71TEST_F(JsonVariant_Storage_Tests, Int32) { testNumericType<int32_t>(); }
72TEST_F(JsonVariant_Storage_Tests, Uint32) { testNumericType<uint32_t>(); }
73#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
74TEST_F(JsonVariant_Storage_Tests, Int64) { testNumericType<int64_t>(); }
75TEST_F(JsonVariant_Storage_Tests, Uint64) { testNumericType<uint64_t>(); }
76#endif
77
78TEST_F(JsonVariant_Storage_Tests, CanStoreObject) {
79 DynamicJsonBuffer jsonBuffer;
80 JsonObject &object = jsonBuffer.createObject();
81
82 testReference(object);
83}
Note: See TracBrowser for help on using the repository browser.