MRPT  1.9.9
CSchemeArchive_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
11 #include <mrpt/poses/CPose2D.h>
15 #include <sstream>
16 
17 // Check if we have jsoncpp to enable those tests:
18 #include <mrpt/config.h>
19 #if MRPT_HAS_JSONCPP
20 #include <json/json.h>
21 #endif
22 
23 using namespace mrpt::serialization;
24 
25 #if MRPT_HAS_JSONCPP
26 TEST(SchemaSerialization, JSON_archive)
27 {
28  auto arch = archiveJSON();
29  mrpt::poses::CPose2D pt1{1.0, 2.0, 3.0}, pt2;
30  arch = pt1;
31  std::stringstream ss;
32  ss << arch;
33  auto pos = ss.str().find("\"datatype\" : \"mrpt::poses::CPose2D\"");
34  EXPECT_TRUE(pos != std::string::npos);
35 
36  // test deserializing:
37  ss.seekg(0); // rewind for reading
38  auto arch2 = archiveJSON();
39  // Load the plain text representation into the archive:
40  ss >> arch2;
41  // Parse the JSON data into an MRPT object:
42  arch2.readTo(pt2);
43 
44  EXPECT_NEAR(pt1.x(), pt2.x(), 1e-6);
45  EXPECT_NEAR(pt1.y(), pt2.y(), 1e-6);
46  EXPECT_NEAR(pt1.phi(), pt2.phi(), 1e-6);
47 }
48 
49 TEST(SchemaSerialization, JSON_raw)
50 {
51  Json::Value val;
53  std::make_unique<CSchemeArchive<Json::Value>>(val));
54  mrpt::poses::CPose2D pt1{1.0, 2.0, 3.0}, pt2;
55  arch = pt1;
56  std::stringstream ss;
57  ss << val;
58  auto pos = ss.str().find("\"datatype\" : \"mrpt::poses::CPose2D\"");
59  EXPECT_TRUE(pos != std::string::npos);
60 
61  // test deserializing:
62  Json::Value val2;
63  ss.seekg(0); // rewind for reading
64  ss >> val2;
66  std::make_unique<CSchemeArchive<Json::Value>>(val2));
67  arch2.readTo(pt2);
68  EXPECT_NEAR(pt1.x(), pt2.x(), 1e-6);
69  EXPECT_NEAR(pt1.y(), pt2.y(), 1e-6);
70  EXPECT_NEAR(pt1.phi(), pt2.phi(), 1e-6);
71 }
72 
73 #endif
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
Virtual base class for "schematic archives" (JSON, XML,...)
TEST(ICP_SLAM_App, MapFromRawlog_PointMap)
int val
Definition: mrpt_jpeglib.h:957
Base template class for schema-capable "archives", e.g.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)
CSchemeArchiveBase archiveJSON()
Returns an archive for reading/writing in JSON format.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020