Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Merge requests
  • !1070

Add test for `const __FlashStringHelper*` keys and values

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Simon Arlott requested to merge github/fork/nomis/test-FlashStringHelper into 6.x 5 years ago
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 1

Issues #441 (closed) and #783 (closed) fixed support for const __FlashStringHelper* but it's broken again.

"100% code coverage" is meaningless if it doesn't cover all of the features, so here are some tests for it.

Compare
  • 6.x (base)

and
  • latest version
    09c2b26f
    1 commit, 2 years ago

1 file
+ 30
- 1

    Preferences

    File browser
    Compare changes
test/JsonVariant/subscript.cpp
+ 30
- 1
  • View file @ 09c2b26f


@@ -5,6 +5,8 @@
@@ -5,6 +5,8 @@
#include <ArduinoJson.h>
#include <ArduinoJson.h>
#include <catch.hpp>
#include <catch.hpp>
 
class __FlashStringHelper;
 
TEST_CASE("JsonVariant::operator[]") {
TEST_CASE("JsonVariant::operator[]") {
DynamicJsonDocument doc(4096);
DynamicJsonDocument doc(4096);
JsonVariant var = doc.to<JsonVariant>();
JsonVariant var = doc.to<JsonVariant>();
@@ -22,6 +24,14 @@ TEST_CASE("JsonVariant::operator[]") {
@@ -22,6 +24,14 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(var[0].isNull());
REQUIRE(var[0].isNull());
}
}
 
SECTION("The JsonVariant is a const __FlashStringHelper*") {
 
const __FlashStringHelper *value = reinterpret_cast<const __FlashStringHelper *>("hello world");
 
var.set(value);
 
REQUIRE(0 == var.size());
 
REQUIRE(var["0"].isNull());
 
REQUIRE(var[0].isNull());
 
}
 
SECTION("The JsonVariant is a JsonArray") {
SECTION("The JsonVariant is a JsonArray") {
JsonArray array = var.to<JsonArray>();
JsonArray array = var.to<JsonArray>();
@@ -40,7 +50,7 @@ TEST_CASE("JsonVariant::operator[]") {
@@ -40,7 +50,7 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(var["0"].isNull());
REQUIRE(var["0"].isNull());
}
}
SECTION("set value") {
SECTION("set value as a string") {
array.add("hello");
array.add("hello");
var[0] = "world";
var[0] = "world";
@@ -49,6 +59,17 @@ TEST_CASE("JsonVariant::operator[]") {
@@ -49,6 +59,17 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(std::string("world") == var[0]);
REQUIRE(std::string("world") == var[0]);
}
}
 
SECTION("set value as a const __FlashStringHelper*") {
 
const __FlashStringHelper *value = reinterpret_cast<const __FlashStringHelper *>("world");
 
 
array.add("hello");
 
 
var[0] = value;
 
 
REQUIRE(1 == var.size());
 
REQUIRE(std::string("world") == var[0]);
 
}
 
SECTION("set value in a nested object") {
SECTION("set value in a nested object") {
array.createNestedObject();
array.createNestedObject();
@@ -90,6 +111,14 @@ TEST_CASE("JsonVariant::operator[]") {
@@ -90,6 +111,14 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(std::string("world") == var["hello"]);
REQUIRE(std::string("world") == var["hello"]);
}
}
 
SECTION("set value, key is a const __FlashStringHelper*") {
 
const __FlashStringHelper *key = reinterpret_cast<const __FlashStringHelper *>("hello");
 
var[key] = "world";
 
 
REQUIRE(1 == var.size());
 
REQUIRE(std::string("world") == var[key]);
 
}
 
SECTION("var[key].to<JsonArray>()") {
SECTION("var[key].to<JsonArray>()") {
JsonArray arr = var["hello"].to<JsonArray>();
JsonArray arr = var["hello"].to<JsonArray>();
REQUIRE(arr.isNull() == false);
REQUIRE(arr.isNull() == false);
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Simon Arlott
Reference: bblanchon/ArduinoJson!1070
Source branch: github/fork/nomis/test-FlashStringHelper

Menu

Explore Projects Groups Snippets