Go to the documentation of this file. 1 #include <gtest/gtest.h>
55 add_field(
"pos", &v.pos);
56 add_field(
"rot", &v.rot);
62 j[
"stamp"] = double(t.
sec) + 1e-9 * double(t.
nsec);
67 double sec = j[
"stamp"];
102 std::cout <<
json.
dump(2) << std::endl;
104 ASSERT_EQ(
json[
"int"], 69);
105 ASSERT_EQ(
json[
"real"], 3.14);
107 ASSERT_EQ(
json[
"pose"][
"__type"],
"Pose3D");
108 ASSERT_EQ(
json[
"pose"][
"pos"][
"x"], 1);
109 ASSERT_EQ(
json[
"pose"][
"pos"][
"y"], 2);
110 ASSERT_EQ(
json[
"pose"][
"pos"][
"z"], 3);
112 ASSERT_EQ(
json[
"pose"][
"rot"][
"w"], 4);
113 ASSERT_EQ(
json[
"pose"][
"rot"][
"x"], 5);
114 ASSERT_EQ(
json[
"pose"][
"rot"][
"y"], 6);
115 ASSERT_EQ(
json[
"pose"][
"rot"][
"z"], 7);
120 ASSERT_EQ(pose.
pos.
x, pose2.pos.x);
121 ASSERT_EQ(pose.
pos.
y, pose2.pos.y);
122 ASSERT_EQ(pose.
pos.
z, pose2.pos.z);
124 ASSERT_EQ(pose.
rot.
w, pose2.rot.w);
125 ASSERT_EQ(pose.
rot.
x, pose2.rot.x);
126 ASSERT_EQ(pose.
rot.
y, pose2.rot.y);
127 ASSERT_EQ(pose.
rot.
z, pose2.rot.z);
129 auto num = exporter.
fromJson(
json[
"int"])->first.cast<
int>();
131 auto real = exporter.
fromJson(
json[
"real"])->first.cast<
double>();
132 ASSERT_EQ(real, 3.14);
142 std::cout <<
json.
dump() << std::endl;
148 ASSERT_EQ(stamp.
sec, stamp_out.sec);
149 ASSERT_EQ(stamp.
nsec, stamp_out.nsec);
155 ASSERT_EQ(stamp.
sec, stamp_out.sec);
156 ASSERT_EQ(stamp.
nsec, stamp_out.nsec);
160 ASSERT_TRUE(stamp_out);
161 ASSERT_EQ(stamp.
sec, stamp_out->sec);
162 ASSERT_EQ(stamp.
nsec, stamp_out->nsec);
169 auto const test_json = R
"(json:{"x":2.1, "y":4.2, "z":6.3})";
170 ASSERT_NO_THROW(vect = BT::convertFromString<TestTypes::Vector3D>(test_json));
172 ASSERT_EQ(vect.x, 2.1);
173 ASSERT_EQ(vect.y, 4.2);
174 ASSERT_EQ(vect.z, 6.3);
180 bb_in->set(
"int", 42);
181 bb_in->set(
"real", 3.14);
185 std::cout <<
json.
dump(2) << std::endl;
190 ASSERT_EQ(bb_out->get<
int>(
"int"), 42);
191 ASSERT_EQ(bb_out->get<
double>(
"real"), 3.14);
194 ASSERT_EQ(vect_out.x, 1.1);
195 ASSERT_EQ(vect_out.y, 2.2);
196 ASSERT_EQ(vect_out.z, 3.3);
bool toJson(const BT::Any &any, nlohmann::json &destination) const
toJson adds the content of "any" to the JSON "destination".
BT_JSON_CONVERTER(Vector3D, v)
void ImportBlackboardFromJSON(const nlohmann::json &json, Blackboard &blackboard)
ImportBlackboardFromJSON will append elements to the blackboard, using the values parsed from the JSO...
namespace for Niels Lohmann
nlohmann::json ExportBlackboardToJSON(const Blackboard &blackboard)
ExportBlackboardToJSON will create a JSON that contains the current values of the blackboard....
TEST_F(JsonTest, TwoWaysConversion)
static JsonExporter & get()
void jsonFromTime(const Time &t, nlohmann::json &j)
static Blackboard::Ptr create(Blackboard::Ptr parent={})
basic_json<> json
default specialization
void jsonToTime(const nlohmann::json &j, Time &t)
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
ExpectedEntry fromJson(const nlohmann::json &source) const
fromJson will return an Entry (value wrappedn in Any + TypeInfo) from a json source....