20 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
30 #include <boost/serialization/serialization.hpp>
31 #include <boost/filesystem.hpp>
35 const bool verbose =
false;
38 namespace serializationTestHelpers {
49 boost::filesystem::remove_all(folder);
50 boost::filesystem::create_directory(folder);
56 void roundtrip(
const T& input,
T& output) {
57 std::string serialized = serialize(input);
58 if (verbose) std::cout << serialized << std::endl << std::endl;
59 deserialize(serialized, output);
64 void roundtripFile(
const T& input,
T& output) {
66 serializeToFile(input,
path.string());
67 deserializeFromFile(
path.string(), output);
73 T output = create<T>(), outputf = create<T>();
74 roundtrip<T>(input,output);
75 roundtripFile<T>(input,outputf);
76 return (input==output) && (input==outputf);
81 bool equalsObj(
const T& input =
T()) {
82 T output = create<T>();
83 roundtrip<T>(input,output);
89 bool equalsDereferenced(
const T& input) {
90 T output = create<T>();
91 roundtrip<T>(input,output);
92 return input->equals(*output);
97 void roundtripXML(
const T& input,
T& output) {
98 std::string serialized = serializeXML<T>(input);
99 if (verbose) std::cout << serialized << std::endl << std::endl;
100 deserializeXML(serialized, output);
105 void roundtripXMLFile(
const T& input,
T& output) {
107 serializeToXMLFile(input,
path.string());
108 deserializeFromXMLFile(
path.string(), output);
113 bool equalityXML(
const T& input =
T()) {
114 T output = create<T>(), outputf = create<T>();
115 roundtripXML<T>(input,output);
116 roundtripXMLFile<T>(input,outputf);
117 return (input==output) && (input==outputf);
122 bool equalsXML(
const T& input =
T()) {
123 T output = create<T>();
124 roundtripXML<T>(input,output);
130 bool equalsDereferencedXML(
const T& input =
T()) {
131 T output = create<T>();
132 roundtripXML<T>(input,output);
133 return input->equals(*output);
138 void roundtripBinary(
const T& input,
T& output) {
139 std::string serialized = serializeBinary<T>(input);
140 if (verbose) std::cout << serialized << std::endl << std::endl;
141 deserializeBinary(serialized, output);
146 void roundtripBinaryFile(
const T& input,
T& output) {
148 serializeToBinaryFile(input,
path.string());
149 deserializeFromBinaryFile(
path.string(), output);
154 bool equalityBinary(
const T& input =
T()) {
155 T output = create<T>(), outputf = create<T>();
156 roundtripBinary<T>(input,output);
157 roundtripBinaryFile<T>(input,outputf);
158 return (input==output) && (input==outputf);
163 bool equalsBinary(
const T& input =
T()) {
164 T output = create<T>();
165 roundtripBinary<T>(input,output);
171 bool equalsDereferencedBinary(
const T& input =
T()) {
172 T output = create<T>();
173 roundtripBinary<T>(input,output);
174 return input->equals(*output);