22#include <gtsam/config.h>
24#if GTSAM_ENABLE_BOOST_SERIALIZATION
34#include <boost/serialization/serialization.hpp>
38const bool verbose =
false;
41namespace serializationTestHelpers {
50inline std::filesystem::path resetFilesystem(
51 std::filesystem::path folder =
"actual") {
52 std::filesystem::remove_all(folder);
53 std::filesystem::create_directory(folder);
59void roundtrip(
const T& input, T& output) {
60 std::string serialized = serialize(input);
61 if (verbose) std::cout << serialized << std::endl << std::endl;
62 deserialize(serialized, output);
67void roundtripFile(
const T& input, T& output) {
68 std::filesystem::path path = resetFilesystem()/
"graph.dat";
69 serializeToFile(input, path.string());
70 deserializeFromFile(path.string(), output);
75bool equality(
const T& input = T()) {
76 T output = create<T>(), outputf = create<T>();
77 roundtrip<T>(input,output);
78 roundtripFile<T>(input,outputf);
79 return (input==output) && (input==outputf);
84bool equalsObj(
const T& input = T()) {
85 T output = create<T>();
86 roundtrip<T>(input,output);
92bool equalsDereferenced(
const T& input) {
93 T output = create<T>();
94 roundtrip<T>(input,output);
95 return input->equals(*output);
100void roundtripXML(
const T& input, T& output) {
101 std::string serialized = serializeXML<T>(input);
102 if (verbose) std::cout << serialized << std::endl << std::endl;
103 deserializeXML(serialized, output);
108void roundtripXMLFile(
const T& input, T& output) {
109 std::filesystem::path path = resetFilesystem()/
"graph.xml";
110 serializeToXMLFile(input, path.string());
111 deserializeFromXMLFile(path.string(), output);
116bool equalityXML(
const T& input = T()) {
117 T output = create<T>(), outputf = create<T>();
118 roundtripXML<T>(input,output);
119 roundtripXMLFile<T>(input,outputf);
120 return (input==output) && (input==outputf);
125bool equalsXML(
const T& input = T()) {
126 T output = create<T>();
127 roundtripXML<T>(input,output);
133bool equalsDereferencedXML(
const T& input = T()) {
134 T output = create<T>();
135 roundtripXML<T>(input,output);
136 return input->equals(*output);
141void roundtripBinary(
const T& input, T& output) {
142 std::string serialized = serializeBinary<T>(input);
143 if (verbose) std::cout << serialized << std::endl << std::endl;
144 deserializeBinary(serialized, output);
149void roundtripBinaryFile(
const T& input, T& output) {
150 std::filesystem::path path = resetFilesystem()/
"graph.bin";
151 serializeToBinaryFile(input, path.string());
152 deserializeFromBinaryFile(path.string(), output);
157bool equalityBinary(
const T& input = T()) {
158 T output = create<T>(), outputf = create<T>();
159 roundtripBinary<T>(input,output);
160 roundtripBinaryFile<T>(input,outputf);
161 return (input==output) && (input==outputf);
166bool equalsBinary(
const T& input = T()) {
167 T output = create<T>();
168 roundtripBinary<T>(input,output);
174bool equalsDereferencedBinary(
const T& input = T()) {
175 T output = create<T>();
176 roundtripBinary<T>(input,output);
177 return input->equals(*output);
Provides additional testing facilities for common data structures.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition Matrix.cpp:39
Convenience functions for serializing data structures via boost.serialization.