当前位置: 首页>>代码示例>>C++>>正文


C++ DynamicJsonBuffer::createArray方法代码示例

本文整理汇总了C++中DynamicJsonBuffer::createArray方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicJsonBuffer::createArray方法的具体用法?C++ DynamicJsonBuffer::createArray怎么用?C++ DynamicJsonBuffer::createArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DynamicJsonBuffer的用法示例。


在下文中一共展示了DynamicJsonBuffer::createArray方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TEST(JsonVariant_As_Tests, ArrayAsJsonArray) {
  DynamicJsonBuffer buffer;
  JsonArray& arr = buffer.createArray();

  JsonVariant variant = arr;
  ASSERT_EQ(&arr, &variant.as<JsonArray&>());
  ASSERT_EQ(&arr, &variant.as<JsonArray>());  // <- shorthand
}
开发者ID:FernandoGarcia,项目名称:Ferduino_with_webcontrol_beta,代码行数:8,代码来源:JsonVariant_As_Tests.cpp

示例2:

TEST(StdStream, JsonArraySubscript) {
  std::ostringstream os;
  DynamicJsonBuffer jsonBuffer;
  JsonArray& array = jsonBuffer.createArray();
  array.add("value");
  os << array[0];
  ASSERT_EQ("\"value\"", os.str());
}
开发者ID:chris153002,项目名称:esp8266Switch,代码行数:8,代码来源:StdStream.cpp

示例3:

TEST(DynamicJsonBuffer_Array_Tests, CanAdd1000Values) {
  DynamicJsonBuffer jsonBuffer;

  JsonArray &array = jsonBuffer.createArray();

  for (int i = 1; i <= 1000; i++) {
    array.add("hello");
    ASSERT_EQ(array.size(), i);
  }
}
开发者ID:brettanomyces,项目名称:caduceus,代码行数:10,代码来源:DynamicJsonBuffer_Array_Tests.cpp

示例4:

TEST(JsonVariant_As_Tests, ArrayAsString) {
  DynamicJsonBuffer buffer;

  JsonArray& arr = buffer.createArray();
  arr.add(4);
  arr.add(2);

  JsonVariant variant = arr;
  ASSERT_EQ(String("[4,2]"), variant.as<String>());
}
开发者ID:AugustoPujato,项目名称:ArduinoJson,代码行数:10,代码来源:JsonVariant_As_Tests.cpp

示例5: sizeof

TEST(JsonArray_CopyFrom_Tests, TwoDimensions) {
  DynamicJsonBuffer jsonBuffer;
  JsonArray& array = jsonBuffer.createArray();
  char json[32];
  int source[][3] = {{1, 2, 3}, {4, 5, 6}};

  bool ok = array.copyFrom(source);
  ASSERT_TRUE(ok);

  array.printTo(json, sizeof(json));
  ASSERT_STREQ("[[1,2,3],[4,5,6]]", json);
}
开发者ID:1125384055,项目名称:libraries,代码行数:12,代码来源:JsonArray_CopyFrom_Tests.cpp

示例6: handleGetPlugins

/**
 * Get plugin information
 */
void handleGetPlugins(AsyncWebServerRequest *request)
{
  DEBUG_MSG(SERVER, "%s (%d args)\n", request->url().c_str(), request->params());

  DynamicJsonBuffer jsonBuffer;
  JsonArray& json = jsonBuffer.createArray();

  Plugin::each([&json](Plugin* plugin) {
    JsonObject& obj = json.createNestedObject();
    obj[F("name")] = plugin->getName();
    plugin->getPluginJson(&obj);
  });

  jsonResponse(request, 200, json);
}
开发者ID:andig,项目名称:vzero,代码行数:18,代码来源:webserver.cpp

示例7:

TEST_F(JsonVariant_Comparison_Tests, ArrayInVariant) {
  DynamicJsonBuffer jsonBuffer;
  JsonArray& array1 = jsonBuffer.createArray();
  JsonArray& array2 = jsonBuffer.createArray();

  JsonVariant variant1 = array1;
  JsonVariant variant2 = array1;
  JsonVariant variant3 = array2;

  ASSERT_TRUE(variant1 == variant2);
  ASSERT_FALSE(variant1 != variant2);

  ASSERT_TRUE(variant1 != variant3);
  ASSERT_FALSE(variant1 == variant3);
}
开发者ID:brettanomyces,项目名称:caduceus,代码行数:15,代码来源:JsonVariant_Comparison_Tests.cpp

示例8: sizeof

TEST_F(JsonVariant_Comparison_Tests, VariantsOfDifferentTypes) {
  DynamicJsonBuffer jsonBuffer;
  JsonVariant variants[] = {
      true,
      42,
      666.667,
      "hello",
      jsonBuffer.createArray(),
      jsonBuffer.createObject(),
  };
  size_t n = sizeof(variants) / sizeof(variants[0]);

  for (size_t i = 0; i < n; i++) {
    for (size_t j = i + 1; j < n; j++) {
      ASSERT_TRUE(variants[i] != variants[j]);
      ASSERT_FALSE(variants[i] == variants[j]);
    }
  }
}
开发者ID:brettanomyces,项目名称:caduceus,代码行数:19,代码来源:JsonVariant_Comparison_Tests.cpp

示例9: TEST_CASE

// Copyright Benoit Blanchon 2014-2017
// MIT License
//
// Arduino JSON library
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!

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

TEST_CASE("DynamicJsonBuffer::createArray()") {
  DynamicJsonBuffer jsonBuffer;
  JsonArray &array = jsonBuffer.createArray();

  SECTION("GrowsWithArray") {
    REQUIRE(JSON_ARRAY_SIZE(0) == jsonBuffer.size());

    array.add("hello");
    REQUIRE(JSON_ARRAY_SIZE(1) == jsonBuffer.size());

    array.add("world");
    REQUIRE(JSON_ARRAY_SIZE(2) == jsonBuffer.size());
  }

  SECTION("CanAdd1000Values") {
    for (size_t i = 1; i <= 1000; i++) {
      array.add("hello");
      REQUIRE(array.size() == i);
    }
  }
}
开发者ID:DawesLab,项目名称:arduino,代码行数:31,代码来源:createArray.cpp

示例10: check

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

static void check(JsonArray& array, std::string expected) {
  std::string actual;
  size_t actualLen = array.prettyPrintTo(actual);
  size_t measuredLen = array.measurePrettyLength();
  CHECK(actualLen == expected.size());
  CHECK(measuredLen == expected.size());
  REQUIRE(expected == actual);
}

TEST_CASE("JsonArray::prettyPrintTo()") {
  DynamicJsonBuffer jb;
  JsonArray& array = jb.createArray();

  SECTION("Empty") {
    check(array, "[]");
  }

  SECTION("OneElement") {
    array.add(1);

    check(array,
          "[\r\n"
          "  1\r\n"
          "]");
  }

  SECTION("TwoElements") {
开发者ID:DawesLab,项目名称:arduino,代码行数:30,代码来源:prettyPrintTo.cpp

示例11:

TEST(JsonVariant_Success_Tests, ReturnsTrue_WhenEmptyArray) {
    DynamicJsonBuffer jsonBuffer;

    JsonVariant variant = jsonBuffer.createArray();
    EXPECT_TRUE(variant.success());
}
开发者ID:mirkoflchtt,项目名称:ArduinoJson,代码行数:6,代码来源:JsonVariant_Success_Tests.cpp

示例12: SECTION

// Copyright Benoit Blanchon 2014-2017
// MIT License
//
// Arduino JSON library
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!

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

TEST_CASE("JsonArray::add()") {
  DynamicJsonBuffer _jsonBuffer;
  JsonArray& _array = _jsonBuffer.createArray();

  SECTION("SizeIncreased_WhenValuesAreAdded") {
    _array.add("hello");
    REQUIRE(1U == _array.size());
  }

  SECTION("int") {
    _array.add(123);
    REQUIRE(123 == _array[0].as<int>());
    REQUIRE(_array[0].is<int>());
    REQUIRE(_array[0].is<double>());
  }

  SECTION("double") {
    _array.add(123.45);
    REQUIRE(123.45 == _array[0].as<double>());
    REQUIRE(_array[0].is<double>());
    REQUIRE_FALSE(_array[0].is<bool>());
开发者ID:DawesLab,项目名称:arduino,代码行数:31,代码来源:add.cpp

示例13: REQUIRE

  REQUIRE(var.is<const char*>());

  REQUIRE_FALSE(var.is<bool>());
  REQUIRE_FALSE(var.is<int>());
  REQUIRE_FALSE(var.is<double>());
  REQUIRE_FALSE(var.is<float>());
  REQUIRE_FALSE(var.is<long>());
  REQUIRE_FALSE(var.is<JsonArray>());
  REQUIRE_FALSE(var.is<JsonObject>());
}

TEST_CASE("JsonVariant::is()") {
  DynamicJsonBuffer jsonBuffer;

  SECTION("JsonArray") {
    checkIsArray(jsonBuffer.createArray());
  }

  SECTION("bool") {
    checkIsBool(true);
    checkIsBool(false);
  }

  SECTION("double") {
    checkIsFloat(4.2);
  }

  SECTION("int") {
    checkIsInteger(42);
  }
开发者ID:kosmonout,项目名称:GarageDoor,代码行数:30,代码来源:is.cpp

示例14: defined

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

#if defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning(disable : 4996)
#endif

TEST_CASE("Deprecated functions") {
  DynamicJsonBuffer jsonBuffer;

  SECTION("JsonVariant::asArray()") {
    JsonVariant variant = jsonBuffer.createArray();
    REQUIRE(variant.asArray().success());
  }

  SECTION("JsonVariant::asObject()") {
    JsonVariant variant = jsonBuffer.createObject();
    REQUIRE(variant.asObject().success());
  }

  SECTION("JsonVariant::asString()") {
    JsonVariant variant = "hello";
    REQUIRE(std::string("hello") == variant.asString());
  }

  SECTION("JsonArray::removeAt()") {
    JsonArray& arr = jsonBuffer.createArray();
开发者ID:DawesLab,项目名称:arduino,代码行数:31,代码来源:deprecated.cpp


注:本文中的DynamicJsonBuffer::createArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。