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;
64 void roundtripFile(
const T& input,
T& 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;
105 void roundtripXMLFile(
const T& input,
T& 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;
146 void roundtripBinaryFile(
const T& input,
T& 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);
bool deserializeFromFile(const std::string &filename, T &output)
deserializes from a file
Provides additional testing facilities for common data structures.
std::string serialize(const T &input)
serializes to a string
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
bool serializeToFile(const T &input, const std::string &filename)
serializes to a file
void deserializeXML(const std::string &serialized, T &output, const std::string &name="data")
deserializes from a string in XML
bool serializeToBinaryFile(const T &input, const std::string &filename, const std::string &name="data")
serializes to a binary file
Eigen::Triplet< double > T
void deserializeBinary(const std::string &serialized, T &output, const std::string &name="data")
deserializes from a string in binary
bool deserializeFromXMLFile(const std::string &filename, T &output, const std::string &name="data")
deserializes from an XML file
void deserialize(const std::string &serialized, T &output)
deserializes from a string
ADT create(const Signature &signature)
bool serializeToXMLFile(const T &input, const std::string &filename, const std::string &name="data")
serializes to an XML file
bool equality(const Errors &actual, const Errors &expected, double tol)
bool deserializeFromBinaryFile(const std::string &filename, T &output, const std::string &name="data")
deserializes from a binary file