Skip to content
Snippets Groups Projects
Verified Commit 51c5b069 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

More implementation for JsonValue

parent 1c5b0a5b
No related branches found
No related tags found
2 merge requests!42Release 0.2.0,!39F remove boost rdep
Pipeline #24576 failed
......@@ -98,6 +98,12 @@ inline auto get_env_fallback(const std::string &key, const std::string &fallback
*/
class JsonValue {
public:
/**
* Default Constructor.
*
* Creates an empty wrapper where `wrapped` is nullptr.
*/
JsonValue() : JsonValue(nullptr) {}
/**
* Constructor.
*
......@@ -124,14 +130,14 @@ public:
*
* Also copies the `wrapped` object.
*/
auto operator=(const JsonValue &other) -> JsonValue & = default;
auto operator=(const JsonValue &other) -> JsonValue &;
/**
* Move Constructor.
*
* Also moves the `wrapped` object.
*/
JsonValue(JsonValue &&other);
JsonValue(JsonValue &&other) = default;
/**
* Move Assigment.
......
......@@ -153,4 +153,20 @@ auto JsonValue::Reset() -> void {
this->wrapped = nullptr;
}
JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) {
if (!other.IsNull()) {
this->wrapped = new value(*static_cast<value *>(other.wrapped));
}
}
auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
if (this != &other) {
Reset();
if (!other.IsNull()) {
this->wrapped = new value(*static_cast<value *>(other.wrapped));
}
}
return *this;
}
} // namespace caosdb::utility
......@@ -20,10 +20,7 @@
*
*/
#include "gmock/gmock-matchers.h" // for ElementsAre, EXPECT_THAT
#include "boost/beast/core/detail/base64.hpp" // for encoded_size
#include "boost/json/object.hpp" // for object
#include "boost/json/value.hpp" // for value
#include "caosdb/data_type.h" // for atomicdatatype_names
#include "caosdb/entity.h" // for importance_names, role...
#include "caosdb/status_code.h" // for get_status_description
......@@ -38,7 +35,6 @@
#include <utility> // for pair
namespace caosdb::utility {
using ::testing::ElementsAre;
TEST(test_utility, base64_encode) {
auto test_plain = std::string("admin:caosdb");
......@@ -48,17 +44,6 @@ TEST(test_utility, base64_encode) {
EXPECT_EQ(test_encoded, base64_encode(test_plain));
}
TEST(test_utility, test_load_json_file) {
auto json = load_json_file(TEST_DATA_DIR + "/test.json").as_object();
EXPECT_EQ(json["it"], "tests");
EXPECT_EQ(json["null values"], nullptr);
EXPECT_THAT(json["this"].as_array(), ElementsAre("is", "a", "test"));
EXPECT_THAT(json["numbers"].as_array(), ElementsAre(1, 2, 3.3));
auto sub = json["arrays and objects"].as_object();
EXPECT_THAT(sub["see?"].as_array(), ElementsAre(true, false));
}
TEST(test_utility, enum_names) {
// All working enums
for (const auto &entry : caosdb::entity::importance_names) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment