static void GenStat(Stat& stat, const JsonVariant& v) {
    if (v.is<const JsonArray&>()) {
        const JsonArray& a = v.asArray();
        size_t size = 0;
        for (JsonArray::const_iterator itr = a.begin(); itr != a.end(); ++itr)
            GenStat(stat, *itr);
        stat.arrayCount++;
        stat.elementCount += size;
    }
    else if (v.is<const JsonObject&>()) {
        const JsonObject& o = v.asObject();
        for (JsonObject::const_iterator itr = o.begin(); itr != o.end(); ++itr) {
            GenStat(stat, itr->value);
            stat.stringLength += strlen(itr->key);
        }
        stat.objectCount++;
        stat.memberCount += o.size();
        stat.stringCount += o.size();
    }
    else if (v.is<const char*>()) {
        if (v.asString()) {
            stat.stringCount++;
            stat.stringLength += strlen(v.asString());
        }
        else
            stat.nullCount++; // JSON null value is treat as string null pointer
    }
    else if (v.is<long>() || v.is<double>())
        stat.numberCount++;
    else if (v.is<bool>()) {
        if ((bool)v)
            stat.trueCount++;
        else
            stat.falseCount++;
    }
}
Esempio n. 2
0
#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();
    arr.removeAt(0);