diff --git a/JsonGenerator/EscapedString.cpp b/JsonGenerator/EscapedString.cpp deleted file mode 100644 index 4253d323..00000000 --- a/JsonGenerator/EscapedString.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#include "EscapedString.h" - -using namespace ArduinoJson::Internals; - -static inline char getSpecialChar(char c) -{ - // Optimized for code size on a 8-bit AVR - - const char* p = "\"\"\\\\\bb\ff\nn\rr\tt\0"; - - while (p[0] && p[0] != c) - { - p += 2; - } - - return p[1]; -} - -static inline size_t printCharTo(char c, Print& p) -{ - char specialChar = getSpecialChar(c); - - return specialChar != 0 - ? p.write('\\') + p.write(specialChar) - : p.write(c); -} - -size_t EscapedString::printTo(const char* s, Print& p) -{ - if (!s) return p.print("null"); - - size_t n = p.write('\"'); - - while (*s) - { - n += printCharTo(*s++, p); - } - - return n + p.write('\"'); -} \ No newline at end of file diff --git a/JsonGenerator/EscapedString.h b/JsonGenerator/EscapedString.h deleted file mode 100644 index 22db62c7..00000000 --- a/JsonGenerator/EscapedString.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "Print.h" - -namespace ArduinoJson -{ - namespace Internals - { - class EscapedString - { - public: - static size_t printTo(const char*, Print&); - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/IndentedPrint.cpp b/JsonGenerator/IndentedPrint.cpp deleted file mode 100644 index 75032831..00000000 --- a/JsonGenerator/IndentedPrint.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "IndentedPrint.h" - -using namespace ArduinoJson::Generator; - -void IndentedPrint::indent() -{ - if (level < MAX_LEVEL) - level++; -} - -void IndentedPrint::unindent() -{ - if (level > 0) - level--; -} - -void IndentedPrint::setTabSize(uint8_t n) -{ - if (n < MAX_TAB_SIZE) - tabSize = n; -} - -size_t IndentedPrint::write(uint8_t c) -{ - size_t n = 0; - - if (isNewLine) - n += writeTabs(); - - n += sink.write(c); - - isNewLine = c == '\n'; - - return n; -} - -inline size_t IndentedPrint::writeTabs() -{ - size_t n = 0; - - for (int i = 0; i < level*tabSize; i++) - n += sink.write(' '); - - return n; -} \ No newline at end of file diff --git a/JsonGenerator/IndentedPrint.h b/JsonGenerator/IndentedPrint.h deleted file mode 100644 index ace14144..00000000 --- a/JsonGenerator/IndentedPrint.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#pragma once - -#include "Print.h" - -namespace ArduinoJson -{ - namespace Generator - { - // Decorator on top of Print to allow indented output. - // This class is used by JsonPrintable::prettyPrintTo() but can also be used - // for your own purpose, like logging. - class IndentedPrint : public Print - { - public: - - IndentedPrint(Print& p) - : sink(p) - { - level = 0; - tabSize = 2; - isNewLine = true; - } - - virtual size_t write(uint8_t); - - // Adds one level of indentation - void indent(); - - // Removes one level of indentation - void unindent(); - - // Set the number of space printed for each level of indentation - void setTabSize(uint8_t n); - - private: - Print& sink; - uint8_t level : 4; - uint8_t tabSize : 3; - bool isNewLine : 1; - - size_t writeTabs(); - - static const int MAX_LEVEL = 15; // because it's only 4 bits - static const int MAX_TAB_SIZE = 7; // because it's only 3 bits - }; - } -} - diff --git a/JsonGenerator/JsonArray.h b/JsonGenerator/JsonArray.h deleted file mode 100644 index f0251fcf..00000000 --- a/JsonGenerator/JsonArray.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "JsonArrayBase.h" - -namespace ArduinoJson -{ - namespace Generator - { - template - class JsonArray : public JsonArrayBase - { - public: - JsonArray() - : JsonArrayBase(items, N) - { - - } - - private: - JsonValue items[N]; - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonArrayBase.cpp b/JsonGenerator/JsonArrayBase.cpp deleted file mode 100644 index 2c620b00..00000000 --- a/JsonGenerator/JsonArrayBase.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "JsonArrayBase.h" - -using namespace ArduinoJson::Generator; -using namespace ArduinoJson::Internals; - -size_t JsonArrayBase::printTo(Print& p) const -{ - size_t n = 0; - - n += p.write('['); - - // NB: the code has been optimized for a small size on a 8-bit AVR - - const JsonValue* current = items; - for (int i = count; i > 0; i--) - { - n += current->printTo(p); - current++; - - if (i > 1) - { - n += p.write(','); - } - } - - n += p.write(']'); - - return n; -} \ No newline at end of file diff --git a/JsonGenerator/JsonArrayBase.h b/JsonGenerator/JsonArrayBase.h deleted file mode 100644 index 359fd137..00000000 --- a/JsonGenerator/JsonArrayBase.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#pragma once - -#include "JsonPrintable.h" -#include "JsonValue.h" - -namespace ArduinoJson -{ - namespace Generator - { - class JsonArrayBase : public JsonPrintable - { - public: - JsonArrayBase(JsonValue* items, int capacity) - : items(items), capacity(capacity), count(0) - { - - } - - void add(const Printable& value) - { - addIfPossible(value); - } - - void add(bool value) - { - addIfPossible(value); - } - - void add(int value) - { - addIfPossible(value); - } - - void add(long value) - { - addIfPossible(value); - } - - void add(double value) - { - addIfPossible(value); - } - - void add(const char* value) - { - addIfPossible(value); - } - - template - void add(double value) - { - if (count >= capacity) return; - - JsonValue& v = items[count++]; - v.set(value); - } - - virtual size_t printTo(Print& p) const; - - using JsonPrintable::printTo; - - private: - JsonValue* items; - int capacity, count; - - template - void addIfPossible(T value) - { - if (count < capacity) - items[count++] = value; - } - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonGenerator.vcxproj b/JsonGenerator/JsonGenerator.vcxproj deleted file mode 100644 index b24261ba..00000000 --- a/JsonGenerator/JsonGenerator.vcxproj +++ /dev/null @@ -1,101 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {C6536D27-738D-4CEB-A2BC-E13C8897D894} - Win32Proj - JsonGenerator - - - - StaticLibrary - true - v120 - Unicode - - - StaticLibrary - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - Level3 - Disabled - _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - - - Windows - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - - - Windows - true - true - true - - - - - - \ No newline at end of file diff --git a/JsonGenerator/JsonGenerator.vcxproj.filters b/JsonGenerator/JsonGenerator.vcxproj.filters deleted file mode 100644 index 70143357..00000000 --- a/JsonGenerator/JsonGenerator.vcxproj.filters +++ /dev/null @@ -1,84 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/JsonGenerator/JsonObject.h b/JsonGenerator/JsonObject.h deleted file mode 100644 index 76048c43..00000000 --- a/JsonGenerator/JsonObject.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "JsonObjectBase.h" - -#ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING -#ifdef __GNUC__ -#define DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) -#define DEPRECATED __declspec(deprecated) -#endif -#else -#define DEPRECATED -#endif - -namespace ArduinoJson -{ - namespace Generator - { - template - class JsonObject : public JsonObjectBase - { - public: - JsonObject() - : JsonObjectBase(items, N) - { - } - - private: - KeyValuePair items[N]; - }; - - - // Obsolete: use JsonObject instead - template - class DEPRECATED JsonHashTable : public JsonObject - { - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonObjectBase.cpp b/JsonGenerator/JsonObjectBase.cpp deleted file mode 100644 index 45fdb6bf..00000000 --- a/JsonGenerator/JsonObjectBase.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "JsonObjectBase.h" -#include // for strcmp - -using namespace ArduinoJson::Generator; -using namespace ArduinoJson::Internals; - -JsonValue JsonObjectBase::nullValue; - -size_t JsonObjectBase::printTo(Print& p) const -{ - size_t n = 0; - - n += p.write('{'); - - // NB: the code has been optimized for a small size on a 8-bit AVR - - const KeyValuePair* current = items; - for (int i = count; i > 0; i--) - { - n += EscapedString::printTo(current->key, p); - n += p.write(':'); - n += current->value.printTo(p); - - current++; - - if (i > 1) - { - n += p.write(','); - } - } - - n += p.write('}'); - - return n; -} - -JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(JsonKey key) const -{ - KeyValuePair* p = items; - - for (int i = count; i > 0; --i) - { - if (!strcmp(p->key, key)) - return p; - - p++; - } - - return 0; -} - -JsonValue& JsonObjectBase::operator[](JsonKey key) -{ - KeyValuePair* match = getMatchingPair(key); - - if (match) - return match->value; - - JsonValue* value; - - if (count < capacity) - { - items[count].key = key; - value = &items[count].value; - count++; - } - else - { - value = &nullValue; - } - - value->reset(); - return *value; -} - -bool JsonObjectBase::containsKey(JsonKey key) const -{ - return getMatchingPair(key) != 0; -} - -void JsonObjectBase::remove(JsonKey key) -{ - KeyValuePair* match = getMatchingPair(key); - if (match == 0) return; - - *match = items[--count]; -} \ No newline at end of file diff --git a/JsonGenerator/JsonObjectBase.h b/JsonGenerator/JsonObjectBase.h deleted file mode 100644 index 5e27d34f..00000000 --- a/JsonGenerator/JsonObjectBase.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#pragma once - -#include "JsonPrintable.h" -#include "JsonValue.h" -#include "EscapedString.h" - -namespace ArduinoJson -{ - namespace Generator - { - typedef const char* JsonKey; - - class JsonObjectBase : public JsonPrintable - { - public: - JsonValue& operator[](JsonKey); - bool containsKey(JsonKey) const; - void remove(JsonKey key); - - template - void add(JsonKey key, T value) - { - operator[](key) = value; - } - - template - void add(JsonKey key, double value) - { - operator[](key).set(value); - } - - using JsonPrintable::printTo; - - virtual size_t printTo(Print& p) const; - - protected: - - struct KeyValuePair - { - JsonKey key; - JsonValue value; - }; - - JsonObjectBase(KeyValuePair* items, int capacity) - : items(items), capacity(capacity), count(0) - { - } - - private: - KeyValuePair* items; - int capacity, count; - static JsonValue nullValue; - - KeyValuePair* getMatchingPair(JsonKey key) const; - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonPrettyPrint.cpp b/JsonGenerator/JsonPrettyPrint.cpp deleted file mode 100644 index a6992497..00000000 --- a/JsonGenerator/JsonPrettyPrint.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "JsonPrettyPrint.h" - -using namespace ArduinoJson::Generator; - -size_t JsonPrettyPrint::write(uint8_t c) -{ - size_t n = inString ? handleStringChar(c) : handleMarkupChar(c); - previousChar = c; - return n; -} - -inline size_t JsonPrettyPrint::handleStringChar(uint8_t c) -{ - bool isQuote = c == '"' && previousChar != '\\'; - - if (isQuote) inString = false; - - return sink.write(c); -} - -inline size_t JsonPrettyPrint::handleMarkupChar(uint8_t c) -{ - switch (c) - { - case '{': - case '[': - return handleBlockOpen(c); - - case '}': - case ']': - return handleBlockClose(c); - - case ':': - return handleColumn(); - - case ',': - return handleComma(); - - case '"': - return handleQuoteOpen(); - - default: - return handleNormalChar(c); - } -} - -inline size_t JsonPrettyPrint::handleBlockOpen(uint8_t c) -{ - return indentIfNeeded() + sink.write(c); -} - -inline size_t JsonPrettyPrint::handleBlockClose(uint8_t c) -{ - return unindentIfNeeded() + sink.write(c); -} - -inline size_t JsonPrettyPrint::handleColumn() -{ - return sink.write(':') + sink.write(' '); -} - -inline size_t JsonPrettyPrint::handleComma() -{ - return sink.write(',') + sink.println(); -} - -inline size_t JsonPrettyPrint::handleQuoteOpen() -{ - inString = true; - return indentIfNeeded() + sink.write('"'); -} - -inline size_t JsonPrettyPrint::handleNormalChar(uint8_t c) -{ - return indentIfNeeded() + sink.write(c); -} - -size_t JsonPrettyPrint::indentIfNeeded() -{ - if (!inEmptyBlock()) return 0; - - sink.indent(); - return sink.println(); -} - -size_t JsonPrettyPrint::unindentIfNeeded() -{ - if (inEmptyBlock()) return 0; - - sink.unindent(); - return sink.println(); -} \ No newline at end of file diff --git a/JsonGenerator/JsonPrettyPrint.h b/JsonGenerator/JsonPrettyPrint.h deleted file mode 100644 index decff82d..00000000 --- a/JsonGenerator/JsonPrettyPrint.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#pragma once - -#include "Print.h" -#include "IndentedPrint.h" - -namespace ArduinoJson -{ - namespace Generator - { - // Converts a compact JSON string into an indented one. - class JsonPrettyPrint : public Print - { - public: - - JsonPrettyPrint(IndentedPrint& p) - : sink(p) - { - previousChar = 0; - inString = false; - } - - virtual size_t write(uint8_t); - - private: - uint8_t previousChar; - IndentedPrint& sink; - bool inString; - - bool inEmptyBlock() - { - return previousChar == '{' || previousChar == '['; - } - - size_t handleStringChar(uint8_t); - size_t handleMarkupChar(uint8_t); - - size_t handleBlockClose(uint8_t); - size_t handleBlockOpen(uint8_t); - size_t handleColumn(); - size_t handleComma(); - size_t handleQuoteOpen(); - size_t handleNormalChar(uint8_t); - size_t indentIfNeeded(); - size_t unindentIfNeeded(); - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonPrintable.cpp b/JsonGenerator/JsonPrintable.cpp deleted file mode 100644 index 5d6cfa03..00000000 --- a/JsonGenerator/JsonPrintable.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "JsonPrintable.h" -#include "JsonPrettyPrint.h" -#include "StringBuilder.h" - -using namespace ArduinoJson::Generator; -using namespace ArduinoJson::Internals; - -size_t JsonPrintable::printTo(char* buffer, size_t bufferSize) const -{ - StringBuilder sb(buffer, bufferSize); - return printTo(sb); -} - -size_t JsonPrintable::prettyPrintTo(char* buffer, size_t bufferSize) const -{ - StringBuilder sb(buffer, bufferSize); - return prettyPrintTo(sb); -} - -size_t JsonPrintable::prettyPrintTo(IndentedPrint& p) const -{ - JsonPrettyPrint prettyPrint(p); - return printTo(prettyPrint); -} - -size_t JsonPrintable::prettyPrintTo(Print& p) const -{ - IndentedPrint indentedPrint(p); - return prettyPrintTo(indentedPrint); -} \ No newline at end of file diff --git a/JsonGenerator/JsonPrintable.h b/JsonGenerator/JsonPrintable.h deleted file mode 100644 index 3eec80e2..00000000 --- a/JsonGenerator/JsonPrintable.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "Print.h" -#include "Printable.h" -#include "IndentedPrint.h" - -namespace ArduinoJson -{ - namespace Generator - { - // Contains methods to generate a JSON string. - // Implemented by both JsonObject and JsonArray - class JsonPrintable : public Printable - { - public: - - // Generates the compact JSON string and sends it to a Print stream - virtual size_t printTo(Print& p) const = 0; - - // Generates the compact JSON string and writes it in a buffer - size_t printTo(char* buffer, size_t bufferSize) const; - - // Generates the indented JSON string and sends it to a Print stream - size_t prettyPrintTo(Print& p) const; - - // Generates the indented JSON string and sends it to a IndentedPrint stream - // This overload allows a finer control of the output because you can customize - // the IndentedPrint. - size_t prettyPrintTo(IndentedPrint& p) const; - - // Generates the indented JSON string and writes it in a buffer - size_t prettyPrintTo(char* buffer, size_t bufferSize) const; - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonValue.cpp b/JsonGenerator/JsonValue.cpp deleted file mode 100644 index d7de4673..00000000 --- a/JsonGenerator/JsonValue.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#include "EscapedString.h" -#include "JsonValue.h" - -using namespace ArduinoJson::Generator; -using namespace ArduinoJson::Internals; - -size_t JsonValue::printBoolTo(const Content& c, Print& p) -{ - return p.print(c.asBool ? "true" : "false"); -} - -size_t JsonValue::printLongTo(const Content& c, Print& p) -{ - return p.print(c.asLong); -} - -size_t JsonValue::printPrintableTo(const Content& c, Print& p) -{ - if (c.asPrintable) - return c.asPrintable->printTo(p); - else - return p.print("null"); -} - -size_t JsonValue::printStringTo(const Content& c, Print& p) -{ - return EscapedString::printTo(c.asString, p); -} \ No newline at end of file diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h deleted file mode 100644 index 5c080818..00000000 --- a/JsonGenerator/JsonValue.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "EscapedString.h" -#include "Printable.h" -#include "StringBuilder.h" - -namespace ArduinoJson -{ - namespace Generator - { - class JsonValue - { - public: - - void operator=(bool value) - { - printToImpl = &printBoolTo; - content.asBool = value; - } - - void operator=(long value) - { - printToImpl = &printLongTo; - content.asLong = value; - } - - void operator=(int value) - { - printToImpl = &printLongTo; - content.asLong = value; - } - - void operator=(const Printable& value) - { - printToImpl = &printPrintableTo; - content.asPrintable = &value; - } - - void operator=(const char* value) - { - printToImpl = &printStringTo; - content.asString = value; - } - - void operator=(double value) - { - set<2>(value); - } - - template - void set(double value) - { - printToImpl = &printDoubleTo < DIGITS > ; - content.asDouble = value; - } - - operator bool() - { - return content.asBool; - } - - operator const char*() - { - return content.asString; - } - - operator double() - { - return content.asDouble; - } - - operator float() - { - return (float)content.asDouble; - } - - operator int() - { - return content.asLong; - } - - operator long() - { - return content.asLong; - } - - operator const Printable&() - { - return *content.asPrintable; - } - - size_t printTo(Print& p) const - { - // handmade polymorphism - return printToImpl(content, p); - } - - void reset() - { - content.asDouble = 0; - printToImpl = printStringTo; - } - - private: - union Content - { - bool asBool; - double asDouble; - long asLong; - const Printable* asPrintable; - const char* asString; - }; - - Content content; - - size_t(*printToImpl)(const Content&, Print&); - - static size_t printBoolTo(const Content&, Print&); - static size_t printLongTo(const Content&, Print&); - static size_t printPrintableTo(const Content&, Print&); - static size_t printStringTo(const Content&, Print&); - - template - static size_t printDoubleTo(const Content& c, Print& p) - { - return p.print(c.asDouble, DIGITS); - } - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/Print.cpp b/JsonGenerator/Print.cpp deleted file mode 100644 index daa26b43..00000000 --- a/JsonGenerator/Print.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#ifndef ARDUINO - -#include "Print.h" -#include - -size_t Print::print(const char s[]) -{ - size_t n = 0; - while (*s) - { - n += write(*s++); - } - return n; -} - -size_t Print::print(double value, int digits) -{ - char tmp[32]; - sprintf(tmp, "%.*lg", digits+1, value); - return print(tmp); -} - -size_t Print::print(long value) -{ - char tmp[32]; - sprintf(tmp, "%ld", value); - return print(tmp); -} - -size_t Print::println() -{ - return write('\r') + write('\n'); -} - -#endif \ No newline at end of file diff --git a/JsonGenerator/Print.h b/JsonGenerator/Print.h deleted file mode 100644 index e5b3381d..00000000 --- a/JsonGenerator/Print.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#ifndef ARDUINO - -#include -#include - -// This class reproduces Arduino's Print -class Print -{ -public: - - virtual size_t write(uint8_t) = 0; - - size_t print(const char[]); - size_t print(double, int = 2); - size_t print(long); - size_t println(); -}; - -#else - -#include - -#endif diff --git a/JsonGenerator/Printable.h b/JsonGenerator/Printable.h deleted file mode 100644 index c953b1e5..00000000 --- a/JsonGenerator/Printable.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#ifndef ARDUINO - -class Print; - -class Printable -{ -public: - - virtual size_t printTo(Print& p) const = 0; -}; - -#else - -#include - -#endif - diff --git a/JsonGenerator/README.md b/JsonGenerator/README.md deleted file mode 100644 index 52d2b70e..00000000 --- a/JsonGenerator/README.md +++ /dev/null @@ -1,247 +0,0 @@ -Arduino JSON library - Generator -================================ - -*An elegant and efficient JSON encoder for embedded systems.* - -It's design to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc). - -It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project. - - -Features --------- - -* Elegant API, very easy to use -* Fixed memory allocation (no malloc) -* Small footprint -* Supports nested objects -* Supports indented output -* Implements Arduino's `Printable interface -* MIT License - - -Example -------- - - JsonArray<2> array; - array.add<6>(48.756080); // <6> specifies the number of digits in the output - array.add<6>(2.302038); // (the default is 2) - - JsonObject<3> root; - root["sensor"] = "gps"; - root["time"] = 1351824120; - root["data"] = array; - - Serial.print(root); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} - - -How to use? ------------- - -### 1. Install the library - -Download the library and extract it to: - - /libraries/ArduinoJson - -### 2. Import in your sketch - -Just add the following lines at the top of your `.ino` file: - - #include - - using namespace ArduinoJson::Generator; - -> ##### Having a namespace conflict? -> To be able to use both `ArduinoJson::Generator` and `ArduinoJson::Parser` in the same file, you need to do one of the followings: -> -> * Put the `using` statements into different functions -> * `using namespace ArduinoJson`, then prefix the type names by `Generator::` or `Parser::` -> * Create aliases for the namespaces or the types (C++11 only) - -### 3. Create object tree - -In order to generate a JSON string, you need to build the equivalent object tree. You usually start by the root which can be either a JSON Array or a JSON Object. - -#### JSON Array - -You create an array with the following line: - - JsonArray<8> array; - -See the little `<8>`? It's a template parameter that gives the capacity of the array, it's the maximum number of elements you can put in it. - -> ##### About the capacity -> As stated in the feature list, this library works with a fixed memory allocation. -> This means that the size of the object must be know at the compilation time, therefore you can **not** use a variable to set the capacity of the array. - -Then you can add strings, integer, booleans, etc: - - array.add("bazinga!"); - array.add(42); - array.add(true); - -There are two syntaxes for floating point values: - - array.add<4>(3.1415); // 4 digits: "3.1415" - array.add(3.14); // 2 digits: "3.14" - -> ##### About floating point precision -> The overload of `add()` with 2 parameters allows you to specify the number of decimals to save in the JSON string. -> When you use the overload with one parameter, you use the default number of decimals which is two. -> Note that this behavior is the exact same as Arduino's `Print::print(double,int);` which is implemented by `Serial`. -> So you may already be familiar with it. - -Finally you can add nested object to the array: - - JsonArray<8> nestedArray; - array.add(nestedArray); - -or - - JsonObject<8> nestedObject; - array.add(nestedObject); - -> ##### CAUTION! Nested objects must be in memory -> Calling `add()` makes the `JsonArray` store a pointer to the nested object. -> This is designed to avoid memory duplication. -> But it can only work if the object is in memory when `printTo()` is executed. -> For instance, don't do this: -> -> void addNestedObject() -> { -> JsonObject<2> nestedObject; -> // ... -> array.add(nestedObject); // <- DON'T !! -> -> // array now contains a pointer to a local variable that will be -> // discarded as soon as the function exits -> } -> -> For the same reason, don't do this either: -> -> for( int i=0; i<100; i++) -> { -> JsonObject<2> nestedObject; -> // ... -> array.add(nestedObject); // <- DON'T !! -> } -> // array now contains 100 pointers to the same a local variable -> // that is out of the scope anyway - -#### JSON Object - -You create a JSON object (ie hash-table/dictionary) with the following line: - - JsonObject<8> object; - -Like with the array class, there is a template parameter that gives the capacity of the object. - -Then you can add strings, integer, booleans, etc: - - object["key1"] = "bazinga!"; - object["key2"] = 42; - object["key3"] = true; - -As for the arrays, there are two syntaxes for the floating point values: - - object["key4"].set<4>(3.1415); // 4 digits "3.1415" - object["key5"] = 3.1415; // default: 2 digits "3.14" - -Finally you can add nested objects: - - JsonArray<8> nestedArray; - object["key6"] = nestedArray; - -or - - JsonObject<8> nestedObject; - object["key7"] = nestedObject; - -> ##### Other JsonObject functions -> * `object.add(key, value)` is a synonym for `object[key] = value` -> * `object.containsKey(key)` returns `true` is the `key` is present in `object` -> * `object.remove(key)` removes the `value` associated with `key` - -### 4. Get the JSON string - -There are two ways tho get the resulting JSON string. - -Depending on your project, you may need to dump the string in a classic `char[]` or send it to a stream like `Serial` or `EthernetClient `. - -Both ways are the easy way :-) - -#### Use a classic `char[]` - -Whether you have a `JsonArray` or a `JsonObject`, simply call `printTo()` with the destination buffer, like so: - - char buffer[256]; - array.printTo(buffer, sizeof(buffer)); - -> ##### Want an indented output? -> By default the generated JSON is as small as possible. It contains no extra space, nor line break. -> But if you want an indented, more readable output, you can. -> Simply call `prettyPrintTo` instead of `printTo()`: -> -> array.prettyPrintTo(buffer, sizeof(buffer)); - -#### Send to a stream - -It's very likely that the generated JSON will end up in a stream like `Serial` or `EthernetClient `, so you can save some time and memory by doing this: - - Serial.print(array); - -or - - array.printTo(Serial); - -> ##### About the Printable interface -> `JsonArray` and `JsonObject` implement Arduino's `Printable` interface. -> This is why you can call `Serial.print()` like in the example above. -> You can do the same with any other implementation of `Print`: `HardwareSerial`, `SoftwareSerial`, `LiquidCrystal`, `EthernetClient`, `WiFiClient`, `Wire`... - - -Memory usage ------------- - -Here are the size of the main classes of the library. - -This table is for an 8-bit Arduino, types would be bigger on a 32-bit processor. - -| Type | Size in bytes | -| --------------------| ------------- | -| JsonArray<N> | 8 + 6 x N | -| JsonObject<N> | 8 + 8 x N | - - -Code size ---------- - -The following values has been obtained with Arduino IDE 1.0.5, targeting an Arduino Duelmilanove with an ATmega 328. - -### Minimum setup - -| Function | Size | -| ----------------------------------- | ---- | -| `JsonObjectBase::printTo()` | 234 | -| `EscapedString::printTo()` | 196 | -| `JsonArrayBase::printTo()` | 164 | -| `Print::print(char const*)` | 146 | -| `JsonObjectBase::operator[]` | 114 | -| `JsonObjectBase::getMatchingPair()` | 72 | -| `JsonValue::printPrintableTo()` | 40 | -| `JsonValue::printStringTo()` | 12 | - -### Additional space for integers - -| Function | Size | -| ---------------------------- | ---- | -| `Print::print(long, int)` | 328 | -| `JsonValue::printLongTo()` | 22 | - -### Additional space for floating point - -| Function | Size | -| ------------------------------ | ---- | -| `Print::print(double, int)` | 1548 | -| `JsonValue::printDouleTo<2>()` | 22 | \ No newline at end of file diff --git a/JsonGenerator/StringBuilder.cpp b/JsonGenerator/StringBuilder.cpp deleted file mode 100644 index debf4fd7..00000000 --- a/JsonGenerator/StringBuilder.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#include "StringBuilder.h" - -using namespace ArduinoJson::Internals; - -size_t StringBuilder::write(uint8_t c) -{ - if (length >= capacity) return 0; - - buffer[length++] = c; - buffer[length] = 0; - return 1; -} \ No newline at end of file diff --git a/JsonGenerator/StringBuilder.h b/JsonGenerator/StringBuilder.h deleted file mode 100644 index 3e0bc96f..00000000 --- a/JsonGenerator/StringBuilder.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "Print.h" - -namespace ArduinoJson -{ - namespace Internals - { - class StringBuilder : public Print - { - public: - StringBuilder(char* buf, int size) - : buffer(buf), capacity(size - 1), length(0) - { - buffer[0] = 0; - } - - virtual size_t write(uint8_t c); - - private: - char* buffer; - int capacity; - int length; - }; - } -} \ No newline at end of file diff --git a/JsonGeneratorTests/EscapedStringTests.cpp b/JsonGeneratorTests/EscapedStringTests.cpp deleted file mode 100644 index ea0c7980..00000000 --- a/JsonGeneratorTests/EscapedStringTests.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "EscapedString.h" -#include "StringBuilder.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Internals; - -namespace JsonGeneratorTests -{ - TEST_CLASS(EscapedStringTests) - { - char buffer[1024]; - size_t returnValue; - - public: - - TEST_METHOD(Null) - { - whenInputIs(0); - outputMustBe("null"); - } - - TEST_METHOD(EmptyString) - { - whenInputIs(""); - outputMustBe("\"\""); - } - - TEST_METHOD(QuotationMark) - { - whenInputIs("\""); - outputMustBe("\"\\\"\""); - } - - TEST_METHOD(ReverseSolidus) - { - whenInputIs("\\"); - outputMustBe("\"\\\\\""); - } - - TEST_METHOD(Solidus) - { - whenInputIs("/"); - outputMustBe("\"/\""); // but the JSON format allows \/ - } - - TEST_METHOD(Backspace) - { - whenInputIs("\b"); - outputMustBe("\"\\b\""); - } - - TEST_METHOD(Formfeed) - { - whenInputIs("\f"); - outputMustBe("\"\\f\""); - } - - TEST_METHOD(Newline) - { - whenInputIs("\n"); - outputMustBe("\"\\n\""); - } - - TEST_METHOD(CarriageReturn) - { - whenInputIs("\r"); - outputMustBe("\"\\r\""); - } - - TEST_METHOD(HorizontalTab) - { - whenInputIs("\t"); - outputMustBe("\"\\t\""); - } - - private: - void whenInputIs(const char* input) - { - StringBuilder sb(buffer, sizeof(buffer)); - returnValue = EscapedString::printTo(input, sb); - } - - void outputMustBe(const char* expected) - { - Assert::AreEqual(expected, buffer); - Assert::AreEqual(strlen(expected), returnValue); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/Issue10.cpp b/JsonGeneratorTests/Issue10.cpp deleted file mode 100644 index 5ecfcc49..00000000 --- a/JsonGeneratorTests/Issue10.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "CppUnitTest.h" -#include "JsonArray.h" -#include "JsonObject.h" - -using namespace ArduinoJson::Generator; -using namespace Microsoft::VisualStudio::CppUnitTestFramework; - -namespace JsonGeneratorTests -{ - TEST_CLASS(Issue10) - { - struct Person { - int id; - char name[32]; - }; - - Person persons[2]; - - public: - - TEST_METHOD_INITIALIZE(Initialize) - { - Person boss; - boss.id = 1; - strcpy(boss.name, "Jeff"); - Person employee; - employee.id = 2; - strcpy(employee.name, "John"); - persons[0] = boss; - persons[1] = employee; - } - - TEST_METHOD(WrongWayToAddObjectInAnArray) - { - JsonArray<2> json; - - for (int i = 0; i < 2; i++) - { - JsonObject<2> object; - - object["id"] = persons[i].id; - object["name"] = persons[i].name; - - json.add(object); // <- Adding a reference to a temporary variable - } - - char buffer[256]; - json.printTo(buffer, sizeof(buffer)); - - // the same values are repeated, that's normal - Assert::AreEqual("[{\"id\":2,\"name\":\"John\"},{\"id\":2,\"name\":\"John\"}]", buffer); - } - - TEST_METHOD(RightWayToAddObjectInAnArray) - { - JsonArray<2> json; - JsonObject<2> object[2]; - - for (int i = 0; i < 2; i++) - { - object[i]["id"] = persons[i].id; - object[i]["name"] = persons[i].name; - - json.add(object[i]); - } - - char buffer[256]; - json.printTo(buffer, sizeof(buffer)); - - Assert::AreEqual("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonArrayTests.cpp b/JsonGeneratorTests/JsonArrayTests.cpp deleted file mode 100644 index 5dcdd96a..00000000 --- a/JsonGeneratorTests/JsonArrayTests.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "JsonArray.h" -#include "JsonObject.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Generator; - -namespace JsonGeneratorTests -{ - TEST_CLASS(JsonArrayTests) - { - JsonArray<2> array; - char buffer[256]; - - public: - - TEST_METHOD(Empty) - { - outputMustBe("[]"); - } - - TEST_METHOD(Null) - { - array.add((char*) 0); - - outputMustBe("[null]"); - } - - TEST_METHOD(OneString) - { - array.add("hello"); - - outputMustBe("[\"hello\"]"); - } - - TEST_METHOD(TwoStrings) - { - array.add("hello"); - array.add("world"); - - outputMustBe("[\"hello\",\"world\"]"); - } - - TEST_METHOD(OneStringOverCapacity) - { - array.add("hello"); - array.add("world"); - array.add("lost"); - - outputMustBe("[\"hello\",\"world\"]"); - } - - TEST_METHOD(OneDoubleDefaultDigits) - { - array.add(3.14159265358979323846); - outputMustBe("[3.14]"); - } - - TEST_METHOD(OneDoubleFourDigits) - { - array.add<4>(3.14159265358979323846); - outputMustBe("[3.1416]"); - } - - TEST_METHOD(OneInteger) - { - array.add(1); - - outputMustBe("[1]"); - } - - TEST_METHOD(TwoIntegers) - { - array.add(1); - array.add(2); - - outputMustBe("[1,2]"); - } - - TEST_METHOD(OneIntegerOverCapacity) - { - array.add(1); - array.add(2); - array.add(3); - - outputMustBe("[1,2]"); - } - - TEST_METHOD(OneTrue) - { - array.add(true); - - outputMustBe("[true]"); - } - - TEST_METHOD(OneFalse) - { - array.add(false); - - outputMustBe("[false]"); - } - - TEST_METHOD(TwoBooleans) - { - array.add(false); - array.add(true); - - outputMustBe("[false,true]"); - } - - TEST_METHOD(OneBooleanOverCapacity) - { - array.add(false); - array.add(true); - array.add(false); - - outputMustBe("[false,true]"); - } - - TEST_METHOD(OneEmptyNestedArray) - { - JsonArray<1> nestedArray; - - array.add(nestedArray); - - outputMustBe("[[]]"); - } - - TEST_METHOD(OneEmptyNestedHash) - { - JsonObject<1> nestedObject; - - array.add(nestedObject); - - outputMustBe("[{}]"); - } - - TEST_METHOD(OneNestedArrayWithOneInteger) - { - JsonArray<1> nestedArray; - nestedArray.add(1); - - array.add(nestedArray); - - outputMustBe("[[1]]"); - } - - private: - - void outputMustBe(const char* expected) - { - size_t n = array.printTo(buffer, sizeof(buffer)); - Assert::AreEqual(expected, buffer); - Assert::AreEqual(strlen(expected), n); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj b/JsonGeneratorTests/JsonGeneratorTests.vcxproj deleted file mode 100644 index 1b31c03b..00000000 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj +++ /dev/null @@ -1,107 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {B9545D97-E084-4A19-8E48-929157064360} - Win32Proj - JsonGeneratorTests - - - - DynamicLibrary - true - v120 - Unicode - false - - - DynamicLibrary - false - v120 - true - Unicode - false - - - - - - - - - - - - - true - $(ProjectDir)/../JsonGenerator;$(IncludePath) - - - true - $(ProjectDir)/../JsonGenerator;$(IncludePath) - - - - NotUsing - Level3 - Disabled - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - ARDUINO_JSON_NO_DEPRECATION_WARNING;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - - - Windows - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - Level3 - Use - MaxSpeed - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - - - - - - - - - - - - - - {c6536d27-738d-4ceb-a2bc-e13c8897d894} - - - - - - \ No newline at end of file diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters deleted file mode 100644 index 8028fec2..00000000 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters +++ /dev/null @@ -1,52 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/JsonGeneratorTests/JsonObject_Indexer_Tests.cpp b/JsonGeneratorTests/JsonObject_Indexer_Tests.cpp deleted file mode 100644 index f3138331..00000000 --- a/JsonGeneratorTests/JsonObject_Indexer_Tests.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "JsonArray.h" -#include "JsonObject.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Generator; - -namespace JsonGeneratorTests -{ - TEST_CLASS(JsonObject_Indexer_Tests) - { - JsonObject<2> object; - - public: - - TEST_METHOD(Empty) - { - mustNotContain("key"); - } - - TEST_METHOD(TwoStrings) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - - mustContain("key1", "value1"); - mustContain("key2", "value2"); - } - - TEST_METHOD(RemoveFirst) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key1"); - - mustNotContain("key1"); - mustContain("key2", "value2"); - } - - TEST_METHOD(RemoveLast) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key2"); - - mustContain("key1", "value1"); - mustNotContain("key2"); - } - - private: - - void mustContain(const char* key, const char* expected) - { - Assert::IsTrue(object.containsKey(key)); - - const char* actual = object[key]; - Assert::AreEqual(expected, actual); - } - - void mustNotContain(const char* key) - { - Assert::IsFalse(object.containsKey(key)); - - const char* actual = object[key]; - Assert::IsNull(actual); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonObject_PrintTo_Tests.cpp b/JsonGeneratorTests/JsonObject_PrintTo_Tests.cpp deleted file mode 100644 index 277ab2f0..00000000 --- a/JsonGeneratorTests/JsonObject_PrintTo_Tests.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "JsonArray.h" -#include "JsonObject.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Generator; - -namespace JsonGeneratorTests -{ - TEST_CLASS(JsonObject_PrintTo_Tests) - { - JsonObject<2> object; - - public: - - TEST_METHOD(Empty) - { - outputMustBe("{}"); - } - - TEST_METHOD(OneString) - { - object["key"] = "value"; - - outputMustBe("{\"key\":\"value\"}"); - } - - TEST_METHOD(TwoStrings) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - - outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); - } - - TEST_METHOD(RemoveFirst) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key1"); - - outputMustBe("{\"key2\":\"value2\"}"); - } - - TEST_METHOD(RemoveLast) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key2"); - - outputMustBe("{\"key1\":\"value1\"}"); - } - - TEST_METHOD(RemoveUnexistingKey) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key3"); - - outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); - } - - TEST_METHOD(ReplaceExistingKey) - { - object["key"] = "value1"; - object["key"] = "value2"; - - outputMustBe("{\"key\":\"value2\"}"); - } - - TEST_METHOD(OneStringOverCapacity) - { - object["key1"] = "value1"; - object["key2"] = "value2"; - object["key3"] = "value3"; - - outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); - } - - TEST_METHOD(OneInteger) - { - object["key"] = 1; - outputMustBe("{\"key\":1}"); - } - - TEST_METHOD(OneDoubleFourDigits) - { - object["key"].set<4>(3.14159265358979323846); - outputMustBe("{\"key\":3.1416}"); - } - - TEST_METHOD(OneDoubleDefaultDigits) - { - object["key"] = 3.14159265358979323846; - outputMustBe("{\"key\":3.14}"); - } - - TEST_METHOD(OneNull) - { - object["key"] = (char*) 0; - outputMustBe("{\"key\":null}"); - } - - TEST_METHOD(OneTrue) - { - object["key"] = true; - outputMustBe("{\"key\":true}"); - } - - TEST_METHOD(OneFalse) - { - object["key"] = false; - outputMustBe("{\"key\":false}"); - } - - TEST_METHOD(OneEmptyNestedArray) - { - auto nestedArray = JsonArray<1>(); - - object["key"] = nestedArray; - - outputMustBe("{\"key\":[]}"); - } - - TEST_METHOD(OneEmptyNestedObject) - { - auto nestedObject = JsonObject<1>(); - - object["key"] = nestedObject; - - outputMustBe("{\"key\":{}}"); - } - - private: - - void outputMustBe(const char* expected) - { - char buffer[256]; - size_t result; - - result = object.printTo(buffer, sizeof(buffer)); - - Assert::AreEqual(strlen(expected), result); - Assert::AreEqual(expected, buffer); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp deleted file mode 100644 index a863f9a5..00000000 --- a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "StringBuilder.h" -#include "JsonValue.h" -#include "JsonArray.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Generator; -using namespace ArduinoJson::Internals; - -namespace JsonGeneratorTests -{ - TEST_CLASS(JsonValue_Cast_Tests) - { - JsonValue value; - - public: - - TEST_METHOD(Bool) - { - setValueAndCheckCast(true); - setValueAndCheckCast(false); - } - - TEST_METHOD(Double) - { - setValueAndCheckCast(3.14156); - } - - TEST_METHOD(Float) - { - setValueAndCheckCast(3.14f); - } - - TEST_METHOD(Integer) - { - setValueAndCheckCast(42); - } - - TEST_METHOD(Long) - { - setValueAndCheckCast(42L); - } - - TEST_METHOD(Array) - { - JsonArray<2> array; - setValueAndCheckCast(array); - } - - TEST_METHOD(String) - { - setValueAndCheckCast("hello"); - } - - private: - - template - void setValueAndCheckCast(T expected) - { - value = expected; - T actual = value; - Assert::AreEqual(expected, actual); - } - - template - void setValueAndCheckCast(JsonArray& expected) - { - value = expected; - const Printable& actual = value; - Assert::AreEqual((void*) &expected, (void*) &actual); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonValue_PrintTo_Tests.cpp b/JsonGeneratorTests/JsonValue_PrintTo_Tests.cpp deleted file mode 100644 index 19d62a29..00000000 --- a/JsonGeneratorTests/JsonValue_PrintTo_Tests.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "StringBuilder.h" -#include "JsonValue.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Generator; -using namespace ArduinoJson::Internals; - -namespace JsonGeneratorTests -{ - TEST_CLASS(JsonValue_PrintTo_Tests) - { - char buffer[1024]; - size_t returnValue; - - public: - - TEST_METHOD(String) - { - setValueTo("hello"); - outputMustBe("\"hello\""); - } - - TEST_METHOD(Float) - { - setValueTo(3.1415f); - outputMustBe("3.14"); - } - - TEST_METHOD(DoubleZeroDigits) - { - setValueTo<0>(3.14159265358979323846); - outputMustBe("3"); - } - - TEST_METHOD(DoubleOneDigit) - { - setValueTo<1>(3.14159265358979323846); - outputMustBe("3.1"); - } - - TEST_METHOD(DoubleTwoDigits) - { - setValueTo<2>(3.14159265358979323846); - outputMustBe("3.14"); - } - - TEST_METHOD(Integer) - { - setValueTo(314); - outputMustBe("314"); - } - - TEST_METHOD(Char) - { - setValueTo('A'); - outputMustBe("65"); - } - - TEST_METHOD(Short) - { - setValueTo((short)314); - outputMustBe("314"); - } - - TEST_METHOD(Long) - { - setValueTo(314159265L); - outputMustBe("314159265"); - } - - private: - - template - void setValueTo(double value) - { - StringBuilder sb(buffer, sizeof(buffer)); - JsonValue jsonValue; - jsonValue.set(value); - returnValue = jsonValue.printTo(sb); - } - - template - void setValueTo(T value) - { - StringBuilder sb(buffer, sizeof(buffer)); - JsonValue jsonValue; - jsonValue = value; - returnValue = jsonValue.printTo(sb); - } - - void outputMustBe(const char* expected) - { - Assert::AreEqual(expected, buffer); - Assert::AreEqual(strlen(expected), returnValue); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/PrettyPrint_Array_Tests.cpp b/JsonGeneratorTests/PrettyPrint_Array_Tests.cpp deleted file mode 100644 index 82d1760a..00000000 --- a/JsonGeneratorTests/PrettyPrint_Array_Tests.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "JsonPrettyPrint.h" -#include "StringBuilder.h" - -using namespace ArduinoJson::Internals; -using namespace ArduinoJson::Generator; -using namespace Microsoft::VisualStudio::CppUnitTestFramework; - -namespace JsonGeneratorTests -{ - TEST_CLASS(PrettyPrint_Array_Tests) - { - char buffer[1024]; - size_t returnValue; - - public: - - TEST_METHOD(EmptyArray) - { - whenInputIs("[]"); - outputMustBe("[]"); - } - - TEST_METHOD(OneElement) - { - whenInputIs("[1]"); - outputMustBe( - "[\r\n" - " 1\r\n" - "]"); - } - - TEST_METHOD(TwoElements) - { - whenInputIs("[1,2]"); - outputMustBe( - "[\r\n" - " 1,\r\n" - " 2\r\n" - "]"); - } - - TEST_METHOD(EmptyNestedArrays) - { - whenInputIs("[[],[]]"); - outputMustBe( - "[\r\n" - " [],\r\n" - " []\r\n" - "]"); - } - - TEST_METHOD(NestedArrays) - { - whenInputIs("[[1,2],[3,4]]"); - outputMustBe( - "[\r\n" - " [\r\n" - " 1,\r\n" - " 2\r\n" - " ],\r\n" - " [\r\n" - " 3,\r\n" - " 4\r\n" - " ]\r\n" - "]"); - } - - private: - - void whenInputIs(const char input[]) - { - StringBuilder sb(buffer, sizeof(buffer)); - IndentedPrint indentedPrint(sb); - JsonPrettyPrint decorator(indentedPrint); - - returnValue = decorator.print(input); - } - - void outputMustBe(const char* expected) - { - Assert::AreEqual(expected, buffer); - Assert::AreEqual(strlen(expected), returnValue); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/PrettyPrint_Object_Tests.cpp b/JsonGeneratorTests/PrettyPrint_Object_Tests.cpp deleted file mode 100644 index 99c96cb9..00000000 --- a/JsonGeneratorTests/PrettyPrint_Object_Tests.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "JsonPrettyPrint.h" -#include "StringBuilder.h" - -using namespace ArduinoJson::Internals; -using namespace ArduinoJson::Generator; -using namespace Microsoft::VisualStudio::CppUnitTestFramework; - -namespace JsonGeneratorTests -{ - TEST_CLASS(PrettyPrint_Object_Tests) - { - char buffer[1024]; - size_t returnValue; - - public: - - TEST_METHOD(EmptyObject) - { - whenInputIs("{}"); - outputMustBe("{}"); - } - - TEST_METHOD(OneMember) - { - whenInputIs("{\"key\":\"value\"}"); - outputMustBe( - "{\r\n" - " \"key\": \"value\"\r\n" - "}"); - } - - TEST_METHOD(TwoMembers) - { - whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}"); - outputMustBe( - "{\r\n" - " \"key1\": \"value1\",\r\n" - " \"key2\": \"value2\"\r\n" - "}"); - } - - TEST_METHOD(EmptyNestedObjects) - { - whenInputIs("{\"key1\":{},\"key2\":{}}"); - outputMustBe( - "{\r\n" - " \"key1\": {},\r\n" - " \"key2\": {}\r\n" - "}"); - } - - TEST_METHOD(NestedObjects) - { - whenInputIs("{\"key1\":{\"a\":1},\"key2\":{\"b\":2}}"); - outputMustBe( - "{\r\n" - " \"key1\": {\r\n" - " \"a\": 1\r\n" - " },\r\n" - " \"key2\": {\r\n" - " \"b\": 2\r\n" - " }\r\n" - "}"); - } - - private: - - void whenInputIs(const char input[]) - { - StringBuilder sb(buffer, sizeof(buffer)); - IndentedPrint indentedPrint(sb); - JsonPrettyPrint decorator(indentedPrint); - - returnValue = decorator.print(input); - } - - void outputMustBe(const char* expected) - { - Assert::AreEqual(expected, buffer); - Assert::AreEqual(strlen(expected), returnValue); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/PrettyPrint_String_Tests.cpp b/JsonGeneratorTests/PrettyPrint_String_Tests.cpp deleted file mode 100644 index a6660973..00000000 --- a/JsonGeneratorTests/PrettyPrint_String_Tests.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "JsonPrettyPrint.h" -#include "StringBuilder.h" - -using namespace ArduinoJson::Internals; -using namespace ArduinoJson::Generator; -using namespace Microsoft::VisualStudio::CppUnitTestFramework; - -namespace JsonGeneratorTests -{ - TEST_CLASS(PrettyPrint_String_Tests) - { - char buffer[1024]; - size_t returnValue; - - public: - - TEST_METHOD(EmptyString) - { - whenInputIs(""); - outputMustBe(""); - } - - TEST_METHOD(TrickyCharacters) - { - whenInputIs ("\":\\\"',\""); - outputMustBe("\":\\\"',\""); - } - - TEST_METHOD(OpeningCurlyBrace) - { - whenInputIs ("\"{\""); - outputMustBe("\"{\""); - } - - TEST_METHOD(OpeningSquareBrace) - { - whenInputIs("\"[\""); - outputMustBe("\"[\""); - } - - TEST_METHOD(ClosingCurlyBrace) - { - whenInputIs("\"}\""); - outputMustBe("\"}\""); - } - - TEST_METHOD(ClosingSquareBrace) - { - whenInputIs("\"]\""); - outputMustBe("\"]\""); - } - - private: - - void whenInputIs(const char input[]) - { - StringBuilder sb(buffer, sizeof(buffer)); - IndentedPrint indentedPrint(sb); - JsonPrettyPrint decorator(indentedPrint); - - returnValue = decorator.print(input); - } - - void outputMustBe(const char* expected) - { - Assert::AreEqual(expected, buffer); - Assert::AreEqual(strlen(expected), returnValue); - } - }; -} \ No newline at end of file diff --git a/JsonGeneratorTests/StringBuilderTests.cpp b/JsonGeneratorTests/StringBuilderTests.cpp deleted file mode 100644 index fcbd9abb..00000000 --- a/JsonGeneratorTests/StringBuilderTests.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include "CppUnitTest.h" -#include "StringBuilder.h" - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; -using namespace ArduinoJson::Internals; - -namespace JsonGeneratorTests -{ - TEST_CLASS(StringBuilderTests) - { - char buffer[20]; - Print* sb; - size_t returnValue; - - public: - - TEST_METHOD_INITIALIZE(Initialize) - { - sb = new StringBuilder(buffer, sizeof(buffer)); - } - - TEST_METHOD(InitialState) - { - outputMustBe(""); - } - - TEST_METHOD(OverCapacity) - { - print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - resultMustBe(19); - - print("ABC"); - resultMustBe(0); - - outputMustBe("ABCDEFGHIJKLMNOPQRS"); - } - - TEST_METHOD(EmptyString) - { - print(""); - resultMustBe(0); - outputMustBe(""); - } - - TEST_METHOD(OneString) - { - print("ABCD"); - resultMustBe(4); - outputMustBe("ABCD"); - } - - TEST_METHOD(TwoStrings) - { - print("ABCD"); - resultMustBe(4); - - print("EFGH"); - resultMustBe(4); - - outputMustBe("ABCDEFGH"); - } - - private: - - void print(const char* value) - { - returnValue = sb->print(value); - } - - void outputMustBe(const char* expected) - { - Assert::AreEqual(expected, buffer); - } - - void resultMustBe(size_t expected) - { - Assert::AreEqual(expected, returnValue); - } - }; -} \ No newline at end of file