Beispiel #1
0
// MIT License

#include <ArduinoJson.h>
#include <catch.hpp>

static void eraseString(std::string &str) {
  char *p = const_cast<char *>(str.c_str());
  while (*p) *p++ = '*';
}

TEST_CASE("std::string") {
  DynamicJsonBuffer jb;

  SECTION("JsonBuffer_ParseArray") {
    std::string json("[\"hello\"]");
    JsonArray &array = jb.parseArray(json);
    eraseString(json);
    REQUIRE(true == array.success());
    REQUIRE(std::string("hello") == array[0]);
  }

  SECTION("JsonBuffer_ParseObject") {
    std::string json("{\"hello\":\"world\"}");
    JsonObject &object = jb.parseObject(json);
    eraseString(json);
    REQUIRE(true == object.success());
    REQUIRE(std::string("world") == object["hello"]);
  }

  SECTION("JsonObject_Subscript") {
    char json[] = "{\"key\":\"value\"}";
 bool tryParseArray(const char *json) {
   DynamicJsonBuffer buffer;
   char s[256];
   strcpy(s, json);
   return buffer.parseArray(s, _nestingLimit).success();
 }