forked from bblanchon/ArduinoJson
Reorganized writer classes
This commit is contained in:
@ -5,18 +5,29 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
struct CustomWriter {
|
||||
std::string str;
|
||||
class CustomWriter {
|
||||
public:
|
||||
CustomWriter() {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
str.append(1, static_cast<char>(c));
|
||||
_str.append(1, static_cast<char>(c));
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t *s, size_t n) {
|
||||
str.append(reinterpret_cast<const char *>(s), n);
|
||||
_str.append(reinterpret_cast<const char *>(s), n);
|
||||
return n;
|
||||
}
|
||||
|
||||
const std::string &str() const {
|
||||
return _str;
|
||||
}
|
||||
|
||||
private:
|
||||
CustomWriter(const CustomWriter &); // non-copiable
|
||||
CustomWriter &operator=(const CustomWriter &);
|
||||
|
||||
std::string _str;
|
||||
};
|
||||
|
||||
TEST_CASE("CustomWriter") {
|
||||
@ -29,13 +40,13 @@ TEST_CASE("CustomWriter") {
|
||||
CustomWriter writer;
|
||||
serializeJson(array, writer);
|
||||
|
||||
REQUIRE("[4,2]" == writer.str);
|
||||
REQUIRE("[4,2]" == writer.str());
|
||||
}
|
||||
|
||||
SECTION("serializeJsonPretty") {
|
||||
CustomWriter writer;
|
||||
serializeJsonPretty(array, writer);
|
||||
|
||||
REQUIRE("[\r\n 4,\r\n 2\r\n]" == writer.str);
|
||||
REQUIRE("[\r\n 4,\r\n 2\r\n]" == writer.str());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user