forked from bblanchon/ArduinoJson
Added support for basic_string<char, traits, allocator>
(closes #1045)
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
#include "custom_string.hpp"
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
@ -31,9 +32,9 @@ TEST_CASE("ConstRamStringAdapter") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("StlString") {
|
||||
TEST_CASE("std::string") {
|
||||
std::string str("bravo");
|
||||
StlStringAdapter adapter(str);
|
||||
StlStringAdapter<std::string> adapter = adaptString(str);
|
||||
|
||||
REQUIRE(adapter.compare(NULL) > 0);
|
||||
REQUIRE(adapter.compare("alpha") > 0);
|
||||
@ -43,3 +44,30 @@ TEST_CASE("StlString") {
|
||||
REQUIRE(adapter.equals("bravo"));
|
||||
REQUIRE_FALSE(adapter.equals("charlie"));
|
||||
}
|
||||
|
||||
TEST_CASE("custom_string") {
|
||||
custom_string str("bravo");
|
||||
StlStringAdapter<custom_string> adapter = adaptString(str);
|
||||
|
||||
REQUIRE(adapter.compare(NULL) > 0);
|
||||
REQUIRE(adapter.compare("alpha") > 0);
|
||||
REQUIRE(adapter.compare("bravo") == 0);
|
||||
REQUIRE(adapter.compare("charlie") < 0);
|
||||
|
||||
REQUIRE(adapter.equals("bravo"));
|
||||
REQUIRE_FALSE(adapter.equals("charlie"));
|
||||
}
|
||||
|
||||
TEST_CASE("IsString<T>") {
|
||||
SECTION("std::string") {
|
||||
REQUIRE(IsString<std::string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("basic_string<wchar_t>") {
|
||||
REQUIRE(IsString<std::basic_string<wchar_t> >::value == false);
|
||||
}
|
||||
|
||||
SECTION("custom_string") {
|
||||
REQUIRE(IsString<custom_string>::value == true);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
#include "custom_string.hpp"
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
@ -48,8 +49,30 @@ TEST_CASE("StaticStringWriter") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("DynamicStringWriter") {
|
||||
TEST_CASE("DynamicStringWriter<std::string>") {
|
||||
std::string output;
|
||||
DynamicStringWriter<std::string> sb(output);
|
||||
common_tests(sb, output);
|
||||
}
|
||||
|
||||
TEST_CASE("DynamicStringWriter<custom_string>") {
|
||||
custom_string output;
|
||||
DynamicStringWriter<custom_string> sb(output);
|
||||
|
||||
REQUIRE(4 == print(sb, "ABCD"));
|
||||
REQUIRE("ABCD" == output);
|
||||
}
|
||||
|
||||
TEST_CASE("IsWriteableString") {
|
||||
SECTION("std::string") {
|
||||
REQUIRE(IsWriteableString<std::string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("custom_string") {
|
||||
REQUIRE(IsWriteableString<custom_string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("basic_string<wchar_t>") {
|
||||
REQUIRE(IsWriteableString<std::basic_string<wchar_t> >::value == false);
|
||||
}
|
||||
}
|
||||
|
14
test/Misc/custom_string.hpp
Normal file
14
test/Misc/custom_string.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
struct custom_char_traits : std::char_traits<char> {};
|
||||
struct custom_allocator : std::allocator<char> {};
|
||||
typedef std::basic_string<char, custom_char_traits, custom_allocator>
|
||||
custom_string;
|
Reference in New Issue
Block a user