22 #include <gtsam/config.h>
24 #if GTSAM_ENABLE_BOOST_SERIALIZATION
33 #include <boost/serialization/serialization.hpp>
34 #include <boost/filesystem.hpp>
38 const bool verbose =
false;
41 namespace serializationTestHelpers {
52 boost::filesystem::remove_all(folder);
53 boost::filesystem::create_directory(folder);
59 void 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);
67 void roundtripFile(
const T& input,
T& output) {
69 serializeToFile(input,
path.string());
70 deserializeFromFile(
path.string(), output);
76 T output = create<T>(), outputf = create<T>();
77 roundtrip<T>(input,output);
78 roundtripFile<T>(input,outputf);
79 return (input==output) && (input==outputf);
84 bool equalsObj(
const T& input =
T()) {
85 T output = create<T>();
86 roundtrip<T>(input,output);
92 bool equalsDereferenced(
const T& input) {
93 T output = create<T>();
94 roundtrip<T>(input,output);
95 return input->equals(*output);
100 void 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);
108 void roundtripXMLFile(
const T& input,
T& output) {
110 serializeToXMLFile(input,
path.string());
111 deserializeFromXMLFile(
path.string(), output);
116 bool 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);
125 bool equalsXML(
const T& input =
T()) {
126 T output = create<T>();
127 roundtripXML<T>(input,output);
133 bool equalsDereferencedXML(
const T& input =
T()) {
134 T output = create<T>();
135 roundtripXML<T>(input,output);
136 return input->equals(*output);
141 void 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);
149 void roundtripBinaryFile(
const T& input,
T& output) {
151 serializeToBinaryFile(input,
path.string());
152 deserializeFromBinaryFile(
path.string(), output);
157 bool 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);
166 bool equalsBinary(
const T& input =
T()) {
167 T output = create<T>();
168 roundtripBinary<T>(input,output);
174 bool equalsDereferencedBinary(
const T& input =
T()) {
175 T output = create<T>();
176 roundtripBinary<T>(input,output);
177 return input->equals(*output);