mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Renamed JsonValue to JsonVariant
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JsonValue.hpp"
|
||||
#include "../JsonVariant.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@ -15,7 +15,7 @@ struct JsonArrayNode {
|
||||
JsonArrayNode() : next(NULL) {}
|
||||
|
||||
JsonArrayNode* next;
|
||||
JsonValue value;
|
||||
JsonVariant value;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,10 @@ class JsonParser {
|
||||
bool skip(const char *wordToSkip);
|
||||
void skipSpaces();
|
||||
|
||||
void parseAnythingTo(JsonValue &destination);
|
||||
inline void parseBooleanTo(JsonValue &destination);
|
||||
inline void parseNullTo(JsonValue &destination);
|
||||
inline void parseNumberTo(JsonValue &destination);
|
||||
void parseAnythingTo(JsonVariant &destination);
|
||||
inline void parseBooleanTo(JsonVariant &destination);
|
||||
inline void parseNullTo(JsonVariant &destination);
|
||||
inline void parseNumberTo(JsonVariant &destination);
|
||||
inline const char *parseString();
|
||||
|
||||
JsonBuffer *_buffer;
|
||||
|
@ -13,7 +13,7 @@ class JsonObject;
|
||||
|
||||
namespace Internals {
|
||||
|
||||
union JsonValueContent {
|
||||
union JsonVariantContent {
|
||||
bool asBoolean;
|
||||
double asDouble;
|
||||
long asLong;
|
@ -9,7 +9,7 @@
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
enum JsonValueType {
|
||||
enum JsonVariantType {
|
||||
JSON_UNDEFINED,
|
||||
JSON_INVALID,
|
||||
JSON_ARRAY,
|
@ -24,7 +24,7 @@ class JsonArray : public JsonPrintable<JsonArray>,
|
||||
friend class JsonBuffer;
|
||||
|
||||
public:
|
||||
typedef JsonValue value_type;
|
||||
typedef JsonVariant value_type;
|
||||
typedef JsonArrayIterator iterator;
|
||||
typedef JsonArrayConstIterator const_iterator;
|
||||
|
||||
|
@ -15,8 +15,8 @@ class JsonArrayConstIterator {
|
||||
explicit JsonArrayConstIterator(Internals::JsonArrayNode *node)
|
||||
: _node(node) {}
|
||||
|
||||
const JsonValue &operator*() const { return _node->value; }
|
||||
const JsonValue *operator->() { return &_node->value; }
|
||||
const JsonVariant &operator*() const { return _node->value; }
|
||||
const JsonVariant *operator->() { return &_node->value; }
|
||||
|
||||
bool operator==(const JsonArrayConstIterator &other) const {
|
||||
return _node == other._node;
|
||||
|
@ -14,8 +14,8 @@ class JsonArrayIterator {
|
||||
public:
|
||||
explicit JsonArrayIterator(Internals::JsonArrayNode *node) : _node(node) {}
|
||||
|
||||
JsonValue &operator*() const { return _node->value; }
|
||||
JsonValue *operator->() { return &_node->value; }
|
||||
JsonVariant &operator*() const { return _node->value; }
|
||||
JsonVariant *operator->() { return &_node->value; }
|
||||
|
||||
bool operator==(const JsonArrayIterator &other) const {
|
||||
return _node == other._node;
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonValue.hpp"
|
||||
#include "JsonVariant.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
class JsonArray;
|
||||
|
@ -33,10 +33,10 @@ class JsonObject : public JsonPrintable<JsonObject>,
|
||||
bool success() const { return _buffer != NULL; }
|
||||
int size() const;
|
||||
|
||||
JsonValue &at(key_type key);
|
||||
const JsonValue &at(key_type key) const;
|
||||
JsonValue &operator[](key_type key);
|
||||
const JsonValue &operator[](key_type key) const { return at(key); }
|
||||
JsonVariant &at(key_type key);
|
||||
const JsonVariant &at(key_type key) const;
|
||||
JsonVariant &operator[](key_type key);
|
||||
const JsonVariant &operator[](key_type key) const { return at(key); }
|
||||
|
||||
void remove(key_type key);
|
||||
|
||||
@ -65,7 +65,7 @@ class JsonObject : public JsonPrintable<JsonObject>,
|
||||
// constructor is private, instance must be created via JsonBuffer
|
||||
JsonObject(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
JsonValue &add(key_type key) { return (*this)[key]; }
|
||||
JsonVariant &add(key_type key) { return (*this)[key]; }
|
||||
Internals::JsonObjectNode *createNode(key_type key);
|
||||
void addNode(Internals::JsonObjectNode *nodeToAdd);
|
||||
void removeNode(Internals::JsonObjectNode *nodeToRemove);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonValue.hpp"
|
||||
#include "JsonVariant.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
@ -14,6 +14,6 @@ struct JsonPair {
|
||||
JsonPair(const char* k) : key(k) {}
|
||||
|
||||
const char* key;
|
||||
JsonValue value;
|
||||
JsonVariant value;
|
||||
};
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h> // for uint8_t
|
||||
|
||||
#include "Internals/JsonValueContent.hpp"
|
||||
#include "Internals/JsonValueType.hpp"
|
||||
#include "Internals/JsonVariantContent.hpp"
|
||||
#include "Internals/JsonVariantType.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
@ -21,9 +21,9 @@ namespace Internals {
|
||||
class JsonWriter;
|
||||
}
|
||||
|
||||
class JsonValue {
|
||||
class JsonVariant {
|
||||
public:
|
||||
JsonValue() : _type(Internals::JSON_UNDEFINED) {}
|
||||
JsonVariant() : _type(Internals::JSON_UNDEFINED) {}
|
||||
|
||||
void set(bool value);
|
||||
void set(double value, uint8_t decimals = 2);
|
||||
@ -40,17 +40,17 @@ class JsonValue {
|
||||
void set(JsonObject &object);
|
||||
|
||||
template <typename T>
|
||||
JsonValue &operator=(T value) {
|
||||
JsonVariant &operator=(T value) {
|
||||
set(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonValue &operator=(JsonArray &array) {
|
||||
JsonVariant &operator=(JsonArray &array) {
|
||||
set(array);
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonValue &operator=(JsonObject &object) {
|
||||
JsonVariant &operator=(JsonObject &object) {
|
||||
set(object);
|
||||
return *this;
|
||||
}
|
||||
@ -84,7 +84,7 @@ class JsonValue {
|
||||
return false;
|
||||
}
|
||||
|
||||
static JsonValue &invalid() { return _invalid; }
|
||||
static JsonVariant &invalid() { return _invalid; }
|
||||
|
||||
bool success() { return _type != Internals::JSON_INVALID; }
|
||||
|
||||
@ -92,80 +92,80 @@ class JsonValue {
|
||||
void writeTo(T &writer) const;
|
||||
|
||||
private:
|
||||
JsonValue(Internals::JsonValueType type) : _type(type) {}
|
||||
JsonVariant(Internals::JsonVariantType type) : _type(type) {}
|
||||
|
||||
Internals::JsonValueType _type;
|
||||
Internals::JsonValueContent _content;
|
||||
static JsonValue _invalid;
|
||||
Internals::JsonVariantType _type;
|
||||
Internals::JsonVariantContent _content;
|
||||
static JsonVariant _invalid;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline bool JsonValue::is<long>() const {
|
||||
inline bool JsonVariant::is<long>() const {
|
||||
return _type == Internals::JSON_LONG;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool JsonValue::is<double>() const {
|
||||
inline bool JsonVariant::is<double>() const {
|
||||
return _type >= Internals::JSON_DOUBLE_0_DECIMALS;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const JsonValue &left, T right) {
|
||||
inline bool operator==(const JsonVariant &left, T right) {
|
||||
return left.as<T>() == right;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(T left, const JsonValue &right) {
|
||||
inline bool operator==(T left, const JsonVariant &right) {
|
||||
return left == right.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(const JsonValue &left, T right) {
|
||||
inline bool operator!=(const JsonVariant &left, T right) {
|
||||
return left.as<T>() != right;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(T left, const JsonValue &right) {
|
||||
inline bool operator!=(T left, const JsonVariant &right) {
|
||||
return left != right.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<=(const JsonValue &left, T right) {
|
||||
inline bool operator<=(const JsonVariant &left, T right) {
|
||||
return left.as<T>() <= right;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<=(T left, const JsonValue &right) {
|
||||
inline bool operator<=(T left, const JsonVariant &right) {
|
||||
return left <= right.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator>=(const JsonValue &left, T right) {
|
||||
inline bool operator>=(const JsonVariant &left, T right) {
|
||||
return left.as<T>() >= right;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator>=(T left, const JsonValue &right) {
|
||||
inline bool operator>=(T left, const JsonVariant &right) {
|
||||
return left >= right.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<(const JsonValue &left, T right) {
|
||||
inline bool operator<(const JsonVariant &left, T right) {
|
||||
return left.as<T>() < right;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<(T left, const JsonValue &right) {
|
||||
inline bool operator<(T left, const JsonVariant &right) {
|
||||
return left < right.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator>(const JsonValue &left, T right) {
|
||||
inline bool operator>(const JsonVariant &left, T right) {
|
||||
return left.as<T>() > right;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator>(T left, const JsonValue &right) {
|
||||
inline bool operator>(T left, const JsonVariant &right) {
|
||||
return left > right.as<T>();
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "../../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../../include/ArduinoJson/JsonBuffer.hpp"
|
||||
#include "../../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../../include/ArduinoJson/JsonObject.hpp"
|
||||
#include "../../include/ArduinoJson/Internals/QuotedString.hpp"
|
||||
|
||||
@ -39,7 +39,7 @@ bool JsonParser::skip(const char *wordToSkip) {
|
||||
return *charToSkip == '\0';
|
||||
}
|
||||
|
||||
void JsonParser::parseAnythingTo(JsonValue &destination) {
|
||||
void JsonParser::parseAnythingTo(JsonVariant &destination) {
|
||||
skipSpaces();
|
||||
|
||||
switch (*_ptr) {
|
||||
@ -91,7 +91,7 @@ JsonArray &JsonParser::parseArray() {
|
||||
if (skip(']')) return array; // empty array
|
||||
|
||||
for (;;) {
|
||||
JsonValue &child = array.add();
|
||||
JsonVariant &child = array.add();
|
||||
|
||||
parseAnythingTo(child);
|
||||
if (!child.success()) return JsonArray::invalid(); // child parsing failed
|
||||
@ -102,16 +102,16 @@ JsonArray &JsonParser::parseArray() {
|
||||
}
|
||||
}
|
||||
|
||||
void JsonParser::parseBooleanTo(JsonValue &destination) {
|
||||
void JsonParser::parseBooleanTo(JsonVariant &destination) {
|
||||
bool value = *_ptr == 't';
|
||||
|
||||
if (skip(value ? "true" : "false"))
|
||||
destination = value;
|
||||
else
|
||||
destination = JsonValue::invalid();
|
||||
destination = JsonVariant::invalid();
|
||||
}
|
||||
|
||||
void JsonParser::parseNumberTo(JsonValue &destination) {
|
||||
void JsonParser::parseNumberTo(JsonVariant &destination) {
|
||||
char *endOfLong;
|
||||
long longValue = strtol(_ptr, &endOfLong, 10);
|
||||
|
||||
@ -126,11 +126,11 @@ void JsonParser::parseNumberTo(JsonValue &destination) {
|
||||
}
|
||||
}
|
||||
|
||||
void JsonParser::parseNullTo(JsonValue &destination) {
|
||||
void JsonParser::parseNullTo(JsonVariant &destination) {
|
||||
if (skip("null"))
|
||||
destination = static_cast<const char *>(NULL);
|
||||
else
|
||||
destination = JsonValue::invalid();
|
||||
destination = JsonVariant::invalid();
|
||||
}
|
||||
|
||||
JsonObject &JsonParser::parseObject() {
|
||||
@ -148,7 +148,7 @@ JsonObject &JsonParser::parseObject() {
|
||||
|
||||
if (!skip(':')) break; // colon is missing
|
||||
|
||||
JsonValue &value = object[key];
|
||||
JsonVariant &value = object[key];
|
||||
|
||||
parseAnythingTo(value);
|
||||
if (!value.success()) break; // value parsing failed
|
||||
|
@ -22,15 +22,15 @@ int JsonArray::size() const {
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
JsonValue &JsonArray::at(int index) const {
|
||||
JsonVariant &JsonArray::at(int index) const {
|
||||
JsonArrayNode *node = _firstNode;
|
||||
while (node && index--) node = node->next;
|
||||
return node ? node->value : JsonValue::invalid();
|
||||
return node ? node->value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
JsonValue &JsonArray::add() {
|
||||
JsonVariant &JsonArray::add() {
|
||||
JsonArrayNode *node = createNode();
|
||||
if (!node) return JsonValue::invalid();
|
||||
if (!node) return JsonVariant::invalid();
|
||||
|
||||
addNode(node);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../include/ArduinoJson/JsonObject.hpp"
|
||||
#include "../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PlacementNew.hpp"
|
||||
#include "../include/ArduinoJson/Internals/JsonParser.hpp"
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "../include/ArduinoJson/JsonBuffer.hpp"
|
||||
#include "../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||
#include "../include/ArduinoJson/Internals/StringBuilder.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PlacementNew.hpp"
|
||||
@ -26,19 +26,19 @@ int JsonObject::size() const {
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
JsonValue &JsonObject::at(const char *key) {
|
||||
JsonVariant &JsonObject::at(const char *key) {
|
||||
JsonObjectNode *node = getNodeAt(key);
|
||||
return node ? node->pair.value : JsonValue::invalid();
|
||||
return node ? node->pair.value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
const JsonValue &JsonObject::at(const char *key) const {
|
||||
const JsonVariant &JsonObject::at(const char *key) const {
|
||||
JsonObjectNode *node = getNodeAt(key);
|
||||
return node ? node->pair.value : JsonValue::invalid();
|
||||
return node ? node->pair.value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
JsonValue &JsonObject::operator[](const char *key) {
|
||||
JsonVariant &JsonObject::operator[](const char *key) {
|
||||
JsonObjectNode *node = getOrCreateNodeAt(key);
|
||||
return node ? node->pair.value : JsonValue::invalid();
|
||||
return node ? node->pair.value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
void JsonObject::remove(char const *key) { removeNode(getNodeAt(key)); }
|
||||
|
@ -4,7 +4,7 @@
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include "../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../include/ArduinoJson/JsonObject.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||
@ -12,70 +12,70 @@
|
||||
using namespace ArduinoJson;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValue JsonValue::_invalid(JSON_INVALID);
|
||||
JsonVariant JsonVariant::_invalid(JSON_INVALID);
|
||||
|
||||
JsonValue::operator JsonArray &() const {
|
||||
JsonVariant::operator JsonArray &() const {
|
||||
return _type == JSON_ARRAY ? *_content.asArray : JsonArray::invalid();
|
||||
}
|
||||
|
||||
JsonValue::operator JsonObject &() const {
|
||||
JsonVariant::operator JsonObject &() const {
|
||||
return _type == JSON_OBJECT ? *_content.asObject : JsonObject::invalid();
|
||||
}
|
||||
|
||||
JsonValue::operator bool() const {
|
||||
JsonVariant::operator bool() const {
|
||||
return _type == JSON_BOOLEAN ? _content.asBoolean : false;
|
||||
}
|
||||
|
||||
JsonValue::operator const char *() const {
|
||||
JsonVariant::operator const char *() const {
|
||||
return _type == JSON_STRING ? _content.asString : NULL;
|
||||
}
|
||||
|
||||
JsonValue::operator double() const {
|
||||
JsonVariant::operator double() const {
|
||||
return _type >= JSON_DOUBLE_0_DECIMALS ? _content.asDouble : 0;
|
||||
}
|
||||
|
||||
JsonValue::operator long() const {
|
||||
JsonVariant::operator long() const {
|
||||
return _type == JSON_LONG ? _content.asLong : 0;
|
||||
}
|
||||
|
||||
void JsonValue::set(bool value) {
|
||||
void JsonVariant::set(bool value) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = Internals::JSON_BOOLEAN;
|
||||
_content.asBoolean = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(const char *value) {
|
||||
void JsonVariant::set(const char *value) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_STRING;
|
||||
_content.asString = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(double value, uint8_t decimals) {
|
||||
void JsonVariant::set(double value, uint8_t decimals) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = static_cast<JsonValueType>(JSON_DOUBLE_0_DECIMALS + decimals);
|
||||
_type = static_cast<JsonVariantType>(JSON_DOUBLE_0_DECIMALS + decimals);
|
||||
_content.asDouble = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(long value) {
|
||||
void JsonVariant::set(long value) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_LONG;
|
||||
_content.asLong = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(JsonArray &array) {
|
||||
void JsonVariant::set(JsonArray &array) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_ARRAY;
|
||||
_content.asArray = &array;
|
||||
}
|
||||
|
||||
void JsonValue::set(JsonObject &object) {
|
||||
void JsonVariant::set(JsonObject &object) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_OBJECT;
|
||||
_content.asObject = &object;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void JsonValue::writeTo(T &writer) const {
|
||||
void JsonVariant::writeTo(T &writer) const {
|
||||
switch (_type) {
|
||||
case JSON_ARRAY:
|
||||
_content.asArray->writeTo(writer);
|
||||
@ -103,5 +103,5 @@ void JsonValue::writeTo(T &writer) const {
|
||||
}
|
||||
}
|
||||
|
||||
template void JsonValue::writeTo(JsonWriter &) const;
|
||||
template void JsonValue::writeTo(PrettyJsonWriter &) const;
|
||||
template void JsonVariant::writeTo(JsonWriter &) const;
|
||||
template void JsonVariant::writeTo(PrettyJsonWriter &) const;
|
@ -7,7 +7,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
// Copyright Benoit Blanchon 2014
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonValue_Storage_Tests : public ::testing::Test {
|
||||
protected:
|
||||
template <typename T>
|
||||
void testValue(T expected) {
|
||||
jsonValue.set(expected);
|
||||
EXPECT_EQ(expected, jsonValue.as<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void testReference(T &expected) {
|
||||
jsonValue.set(expected);
|
||||
EXPECT_EQ(expected, jsonValue.as<T &>());
|
||||
}
|
||||
|
||||
JsonValue jsonValue;
|
||||
};
|
||||
|
||||
TEST_F(JsonValue_Storage_Tests, Double) { testValue<double>(123.45); }
|
||||
TEST_F(JsonValue_Storage_Tests, False) { testValue<bool>(false); }
|
||||
TEST_F(JsonValue_Storage_Tests, Float) { testValue<float>(123.45f); }
|
||||
TEST_F(JsonValue_Storage_Tests, Null) { testValue<const char *>(NULL); }
|
||||
TEST_F(JsonValue_Storage_Tests, SChar) { testValue<signed char>(123); }
|
||||
TEST_F(JsonValue_Storage_Tests, SInt) { testValue<signed int>(123); }
|
||||
TEST_F(JsonValue_Storage_Tests, SLong) { testValue<signed long>(123L); }
|
||||
TEST_F(JsonValue_Storage_Tests, SShort) { testValue<signed short>(123); }
|
||||
TEST_F(JsonValue_Storage_Tests, String) { testValue<const char *>("hello"); }
|
||||
TEST_F(JsonValue_Storage_Tests, True) { testValue<bool>(true); }
|
||||
TEST_F(JsonValue_Storage_Tests, UChar) { testValue<unsigned char>(123); }
|
||||
TEST_F(JsonValue_Storage_Tests, UInt) { testValue<unsigned int>(123U); }
|
||||
TEST_F(JsonValue_Storage_Tests, ULong) { testValue<unsigned long>(123UL); }
|
||||
TEST_F(JsonValue_Storage_Tests, UShort) { testValue<unsigned short>(123); }
|
||||
|
||||
TEST_F(JsonValue_Storage_Tests, CanStoreObject) {
|
||||
StaticJsonBuffer<200> json;
|
||||
JsonObject &object = json.createObject();
|
||||
|
||||
testReference(object);
|
||||
}
|
@ -5,12 +5,12 @@
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include "Printers.hpp"
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonValue_Comparison_Tests : public ::testing::Test {
|
||||
class JsonVariant_Comparison_Tests : public ::testing::Test {
|
||||
protected:
|
||||
template <typename T>
|
||||
void testValue(T low, T mid, T high) {
|
||||
@ -52,45 +52,45 @@ class JsonValue_Comparison_Tests : public ::testing::Test {
|
||||
EXPECT_NE(expected, jsonValue); // operator!=
|
||||
}
|
||||
|
||||
JsonValue jsonValue;
|
||||
JsonVariant jsonValue;
|
||||
};
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, Double) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, Double) {
|
||||
testValue<double>(123.44, 123.45, 123.46);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, Float) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, Float) {
|
||||
testValue<float>(123.44f, 123.45f, 123.46f);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, SChar) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, SChar) {
|
||||
testValue<signed char>(122, 123, 124);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, SInt) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, SInt) {
|
||||
testValue<signed int>(122, 123, 124);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, SLong) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, SLong) {
|
||||
testValue<signed long>(122L, 123L, 124L);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, SShort) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, SShort) {
|
||||
testValue<signed short>(122, 123, 124);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, UChar) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, UChar) {
|
||||
testValue<unsigned char>(122, 123, 124);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, UInt) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, UInt) {
|
||||
testValue<unsigned int>(122, 123, 124);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, ULong) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, ULong) {
|
||||
testValue<unsigned long>(122L, 123L, 124L);
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Comparison_Tests, UShort) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, UShort) {
|
||||
testValue<unsigned short>(122, 123, 124);
|
||||
}
|
@ -8,18 +8,18 @@
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonValue_Copy_Tests : public ::testing::Test {
|
||||
class JsonVariant_Copy_Tests : public ::testing::Test {
|
||||
protected:
|
||||
StaticJsonBuffer<200> json;
|
||||
JsonValue jsonValue1;
|
||||
JsonValue jsonValue2;
|
||||
JsonVariant jsonValue1;
|
||||
JsonVariant jsonValue2;
|
||||
};
|
||||
|
||||
TEST_F(JsonValue_Copy_Tests, IntegersAreCopiedByValue) {
|
||||
TEST_F(JsonVariant_Copy_Tests, IntegersAreCopiedByValue) {
|
||||
jsonValue1 = 123;
|
||||
jsonValue2 = jsonValue1;
|
||||
jsonValue1 = 456;
|
||||
@ -27,7 +27,7 @@ TEST_F(JsonValue_Copy_Tests, IntegersAreCopiedByValue) {
|
||||
EXPECT_EQ(123, jsonValue2.as<int>());
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Copy_Tests, DoublesAreCopiedByValue) {
|
||||
TEST_F(JsonVariant_Copy_Tests, DoublesAreCopiedByValue) {
|
||||
jsonValue1 = 123.45;
|
||||
jsonValue2 = jsonValue1;
|
||||
jsonValue1 = 456.78;
|
||||
@ -35,7 +35,7 @@ TEST_F(JsonValue_Copy_Tests, DoublesAreCopiedByValue) {
|
||||
EXPECT_EQ(123.45, jsonValue2.as<double>());
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Copy_Tests, BooleansAreCopiedByValue) {
|
||||
TEST_F(JsonVariant_Copy_Tests, BooleansAreCopiedByValue) {
|
||||
jsonValue1 = true;
|
||||
jsonValue2 = jsonValue1;
|
||||
jsonValue1 = false;
|
||||
@ -43,7 +43,7 @@ TEST_F(JsonValue_Copy_Tests, BooleansAreCopiedByValue) {
|
||||
EXPECT_TRUE(jsonValue2.as<bool>());
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Copy_Tests, StringsAreCopiedByValue) {
|
||||
TEST_F(JsonVariant_Copy_Tests, StringsAreCopiedByValue) {
|
||||
jsonValue1 = "hello";
|
||||
jsonValue2 = jsonValue1;
|
||||
jsonValue1 = "world";
|
||||
@ -51,7 +51,7 @@ TEST_F(JsonValue_Copy_Tests, StringsAreCopiedByValue) {
|
||||
EXPECT_STREQ("hello", jsonValue2.as<const char *>());
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Copy_Tests, ObjectsAreCopiedByReference) {
|
||||
TEST_F(JsonVariant_Copy_Tests, ObjectsAreCopiedByReference) {
|
||||
JsonObject &object = json.createObject();
|
||||
|
||||
jsonValue1 = object;
|
||||
@ -61,7 +61,7 @@ TEST_F(JsonValue_Copy_Tests, ObjectsAreCopiedByReference) {
|
||||
EXPECT_EQ(1, jsonValue1.asObject().size());
|
||||
}
|
||||
|
||||
TEST_F(JsonValue_Copy_Tests, ArraysAreCopiedByReference) {
|
||||
TEST_F(JsonVariant_Copy_Tests, ArraysAreCopiedByReference) {
|
||||
JsonArray &array = json.createArray();
|
||||
|
||||
jsonValue1 = array;
|
52
test/JsonVariant_Storage_Tests.cpp
Normal file
52
test/JsonVariant_Storage_Tests.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright Benoit Blanchon 2014
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonVariant_Storage_Tests : public ::testing::Test {
|
||||
protected:
|
||||
template <typename T>
|
||||
void testValue(T expected) {
|
||||
jsonValue.set(expected);
|
||||
EXPECT_EQ(expected, jsonValue.as<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void testReference(T &expected) {
|
||||
jsonValue.set(expected);
|
||||
EXPECT_EQ(expected, jsonValue.as<T &>());
|
||||
}
|
||||
|
||||
JsonVariant jsonValue;
|
||||
};
|
||||
|
||||
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); }
|
||||
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, 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, CanStoreObject) {
|
||||
StaticJsonBuffer<200> json;
|
||||
JsonObject &object = json.createObject();
|
||||
|
||||
testReference(object);
|
||||
}
|
@ -7,12 +7,12 @@
|
||||
#include "Printers.hpp"
|
||||
|
||||
std::ostream& ArduinoJson::operator<<(std::ostream& os,
|
||||
const ArduinoJson::JsonValue& v) {
|
||||
const ArduinoJson::JsonVariant& v) {
|
||||
if (v.is<long>())
|
||||
os << v.as<long>();
|
||||
else if (v.is<double>())
|
||||
os << v.as<double>();
|
||||
else
|
||||
os << "JsonValue"; // TODO
|
||||
os << "JsonVariant"; // TODO
|
||||
return os;
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace ArduinoJson {
|
||||
std::ostream& operator<<(std::ostream& os, const ArduinoJson::JsonValue& v);
|
||||
std::ostream& operator<<(std::ostream& os, const ArduinoJson::JsonVariant& v);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonValue.hpp>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
Reference in New Issue
Block a user