28#include <boost/serialization/serialization.hpp>
29#include <boost/filesystem.hpp>
33const bool verbose =
false;
36namespace serializationTestHelpers {
45boost::filesystem::path resetFilesystem(
46 boost::filesystem::path folder =
"actual") {
47 boost::filesystem::remove_all(folder);
48 boost::filesystem::create_directory(folder);
54void roundtrip(
const T& input, T& output) {
55 std::string serialized =
serialize(input);
56 if (verbose) std::cout << serialized << std::endl << std::endl;
62void roundtripFile(
const T& input, T& output) {
63 boost::filesystem::path path = resetFilesystem()/
"graph.dat";
70bool equality(
const T& input = T()) {
71 T output = create<T>(), outputf = create<T>();
72 roundtrip<T>(input,output);
73 roundtripFile<T>(input,outputf);
74 return (input==output) && (input==outputf);
79bool equalsObj(
const T& input = T()) {
80 T output = create<T>();
81 roundtrip<T>(input,output);
87bool equalsDereferenced(
const T& input) {
88 T output = create<T>();
89 roundtrip<T>(input,output);
90 return input->equals(*output);
95void roundtripXML(
const T& input, T& output) {
96 std::string serialized = serializeXML<T>(input);
97 if (verbose) std::cout << serialized << std::endl << std::endl;
103void roundtripXMLFile(
const T& input, T& output) {
104 boost::filesystem::path path = resetFilesystem()/
"graph.xml";
111bool equalityXML(
const T& input = T()) {
112 T output = create<T>(), outputf = create<T>();
113 roundtripXML<T>(input,output);
114 roundtripXMLFile<T>(input,outputf);
115 return (input==output) && (input==outputf);
120bool equalsXML(
const T& input = T()) {
121 T output = create<T>();
122 roundtripXML<T>(input,output);
128bool equalsDereferencedXML(
const T& input = T()) {
129 T output = create<T>();
130 roundtripXML<T>(input,output);
131 return input->equals(*output);
136void roundtripBinary(
const T& input, T& output) {
137 std::string serialized = serializeBinary<T>(input);
138 if (verbose) std::cout << serialized << std::endl << std::endl;
144void roundtripBinaryFile(
const T& input, T& output) {
145 boost::filesystem::path path = resetFilesystem()/
"graph.bin";
152bool equalityBinary(
const T& input = T()) {
153 T output = create<T>(), outputf = create<T>();
154 roundtripBinary<T>(input,output);
155 roundtripBinaryFile<T>(input,outputf);
156 return (input==output) && (input==outputf);
161bool equalsBinary(
const T& input = T()) {
162 T output = create<T>();
163 roundtripBinary<T>(input,output);
169bool equalsDereferencedBinary(
const T& input = T()) {
170 T output = create<T>();
171 roundtripBinary<T>(input,output);
172 return input->equals(*output);
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
bool deserializeFromXMLFile(const std::string &filename, T &output, const std::string &name="data")
deserializes from an XML file
Definition: serialization.h:173
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition: Matrix.cpp:42
void deserializeBinary(const std::string &serialized, T &output, const std::string &name="data")
deserializes from a string in binary
Definition: serialization.h:265
void deserializeXML(const std::string &serialized, T &output, const std::string &name="data")
deserializes from a string in XML
Definition: serialization.h:191
bool serializeToXMLFile(const T &input, const std::string &filename, const std::string &name="data")
serializes to an XML file
Definition: serialization.h:162
bool serializeToFile(const T &input, const std::string &filename)
serializes to a file
Definition: serialization.h:92
void deserialize(const std::string &serialized, T &output)
deserializes from a string
Definition: serialization.h:118
bool serializeToBinaryFile(const T &input, const std::string &filename, const std::string &name="data")
serializes to a binary file
Definition: serialization.h:236
bool deserializeFromFile(const std::string &filename, T &output)
deserializes from a file
Definition: serialization.h:102
bool deserializeFromBinaryFile(const std::string &filename, T &output, const std::string &name="data")
deserializes from a binary file
Definition: serialization.h:247
Convenience functions for serializing data structures via boost.serialization.