From a461680a2b5c730ec641c497b02f653a0100666b Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Fri, 27 Aug 2010 15:31:20 +0000 Subject: [PATCH] Removed extraneous headers that were causing problems related to boost serialization and added testSerialization with conditional compiling (--enable-serialization). Currently, the test is all commented out, and it should not affect those not using the flag. --- .cproject | 341 +++++++++++++++----------------- config.h.in | 3 - configure.ac | 29 ++- inference/BayesNet.h | 4 +- inference/BayesTree.h | 4 +- inference/Conditional.h | 6 +- inference/FactorGraph.h | 8 +- inference/ISAM.h | 4 +- inference/ISAM2.h | 4 +- inference/Key.h | 6 +- inference/SymbolicBayesNet.h | 4 +- inference/SymbolicConditional.h | 3 +- linear/GaussianConditional.h | 4 +- linear/GaussianFactor.h | 2 +- linear/VectorBTree.h | 2 +- linear/VectorMap.h | 2 +- nonlinear/LieConfig.h | 2 +- tests/Makefile.am | 13 +- tests/testSerialization.cpp | 223 +++++++++++++++++++++ 19 files changed, 444 insertions(+), 220 deletions(-) create mode 100644 tests/testSerialization.cpp diff --git a/.cproject b/.cproject index a64d177ca..d480c7da0 100644 --- a/.cproject +++ b/.cproject @@ -302,6 +302,7 @@ make + all true true @@ -309,6 +310,7 @@ make + clean true true @@ -316,6 +318,7 @@ make + check true true @@ -323,6 +326,7 @@ make + testGaussianConditional.run true true @@ -330,6 +334,7 @@ make + testGaussianFactor.run true true @@ -337,6 +342,7 @@ make + timeGaussianFactor.run true true @@ -344,6 +350,7 @@ make + timeVectorConfig.run true true @@ -351,6 +358,7 @@ make + testVectorBTree.run true true @@ -358,6 +366,7 @@ make + testVectorMap.run true true @@ -365,6 +374,7 @@ make + testNoiseModel.run true true @@ -372,6 +382,7 @@ make + testBayesNetPreconditioner.run true true @@ -379,6 +390,7 @@ make + testErrors.run true false @@ -386,7 +398,6 @@ make - check true true @@ -394,7 +405,6 @@ make - tests/testSPQRUtil.run true true @@ -402,7 +412,6 @@ make - clean true true @@ -410,6 +419,7 @@ make + check true true @@ -417,6 +427,7 @@ make + tests/testGaussianJunctionTree.run true true @@ -424,7 +435,6 @@ make - check true true @@ -432,7 +442,6 @@ make - clean true true @@ -440,7 +449,6 @@ make - testBTree.run true true @@ -448,7 +456,6 @@ make - testDSF.run true true @@ -456,7 +463,6 @@ make - testDSFVector.run true true @@ -464,7 +470,6 @@ make - testMatrix.run true true @@ -472,7 +477,6 @@ make - testSPQRUtil.run true true @@ -480,7 +484,6 @@ make - testVector.run true true @@ -488,7 +491,6 @@ make - timeMatrix.run true true @@ -496,7 +498,6 @@ make - all true true @@ -504,6 +505,7 @@ make + all true true @@ -511,6 +513,7 @@ make + clean true true @@ -526,6 +529,7 @@ make + testBayesTree.run true false @@ -533,6 +537,7 @@ make + testBinaryBayesNet.run true false @@ -540,6 +545,7 @@ make + testFactorGraph.run true true @@ -547,6 +553,7 @@ make + testISAM.run true true @@ -554,6 +561,7 @@ make + testJunctionTree.run true true @@ -561,6 +569,7 @@ make + testKey.run true true @@ -568,6 +577,7 @@ make + testOrdering.run true true @@ -575,6 +585,7 @@ make + testSymbolicBayesNet.run true false @@ -582,6 +593,7 @@ make + testSymbolicFactor.run true false @@ -589,6 +601,7 @@ make + testSymbolicFactorGraph.run true false @@ -596,6 +609,7 @@ make + timeSymbolMaps.run true true @@ -603,6 +617,7 @@ make + check true true @@ -610,6 +625,7 @@ make + testClusterTree.run true true @@ -617,6 +633,7 @@ make + testJunctionTree.run true true @@ -624,6 +641,7 @@ make + testEliminationTree.run true true @@ -631,7 +649,6 @@ make - check true true @@ -639,7 +656,6 @@ make - testGaussianFactorGraph.run true true @@ -647,7 +663,6 @@ make - testGaussianISAM.run true true @@ -655,7 +670,6 @@ make - testGaussianISAM2.run true true @@ -663,7 +677,6 @@ make - testGraph.run true false @@ -671,7 +684,6 @@ make - testIterative.run true true @@ -679,7 +691,6 @@ make - testNonlinearEquality.run true true @@ -687,7 +698,6 @@ make - testNonlinearFactor.run true true @@ -695,7 +705,6 @@ make - testNonlinearFactorGraph.run true true @@ -703,7 +712,6 @@ make - testNonlinearOptimizer.run true true @@ -711,7 +719,6 @@ make - testSQP.run true true @@ -719,7 +726,6 @@ make - testSubgraphPreconditioner.run true true @@ -727,7 +733,6 @@ make - testTupleConfig.run true true @@ -735,7 +740,6 @@ make - timeGaussianFactorGraph.run true true @@ -743,7 +747,6 @@ make - testBayesNetPreconditioner.run true true @@ -751,7 +754,6 @@ make - testConstraintOptimizer.run true true @@ -759,7 +761,6 @@ make - testInference.run true false @@ -767,7 +768,6 @@ make - testGaussianBayesNet.run true false @@ -775,7 +775,6 @@ make - testGaussianFactor.run true false @@ -783,7 +782,6 @@ make - testJunctionTree.run true false @@ -791,7 +789,6 @@ make - testSymbolicBayesNet.run true false @@ -799,7 +796,6 @@ make - testSymbolicFactorGraph.run true false @@ -807,6 +803,7 @@ make + clean true true @@ -814,6 +811,7 @@ make + all true true @@ -821,6 +819,7 @@ make + testNonlinearConstraint.run true true @@ -828,6 +827,7 @@ make + testLieConfig.run true true @@ -835,6 +835,7 @@ make + testConstraintOptimizer.run true true @@ -842,6 +843,7 @@ make + install true true @@ -849,6 +851,7 @@ make + clean true true @@ -856,7 +859,6 @@ make - all true true @@ -864,7 +866,6 @@ make - clean true true @@ -872,7 +873,6 @@ make - all true true @@ -880,7 +880,6 @@ make - clean true true @@ -888,7 +887,6 @@ make - all true true @@ -896,7 +894,6 @@ make - clean true true @@ -904,6 +901,7 @@ make + all true true @@ -911,6 +909,7 @@ make + clean true true @@ -918,7 +917,6 @@ make - clean all true true @@ -926,7 +924,6 @@ make - all true true @@ -934,7 +931,6 @@ make - check true true @@ -942,7 +938,6 @@ make - clean true true @@ -950,7 +945,6 @@ make - testPlanarSLAM.run true true @@ -958,7 +952,6 @@ make - testPose2Config.run true true @@ -966,7 +959,6 @@ make - testPose2Factor.run true true @@ -974,7 +966,6 @@ make - testPose2Prior.run true true @@ -982,7 +973,6 @@ make - testPose2SLAM.run true true @@ -990,7 +980,6 @@ make - testPose3Config.run true true @@ -998,7 +987,6 @@ make - testPose3SLAM.run true true @@ -1006,7 +994,6 @@ make - testSimulated2DOriented.run true false @@ -1014,7 +1001,6 @@ make - testVSLAMConfig.run true true @@ -1022,7 +1008,6 @@ make - testVSLAMFactor.run true true @@ -1030,7 +1015,6 @@ make - testVSLAMGraph.run true true @@ -1038,7 +1022,6 @@ make - testPose3Factor.run true true @@ -1046,7 +1029,6 @@ make - testSimulated2D.run true false @@ -1054,7 +1036,6 @@ make - testSimulated3D.run true false @@ -1062,7 +1043,6 @@ make - check true true @@ -1070,6 +1050,7 @@ make + timeCalibratedCamera.run true true @@ -1077,6 +1058,7 @@ make + timeRot3.run true true @@ -1084,6 +1066,7 @@ make + clean true true @@ -1091,7 +1074,6 @@ make - SimpleRotation.run true true @@ -1099,7 +1081,6 @@ make - SLAMSelfContained.run true true @@ -1107,7 +1088,6 @@ make - PlanarSLAMExample.run true true @@ -1115,27 +1095,11 @@ make - check true true true - - make - - check - true - true - true - - - make - tests/testLieConfig.run - true - true - true - make -j2 @@ -1154,11 +1118,111 @@ make + clean true true true + + make + check + true + true + true + + + make + + tests/testLieConfig.run + true + true + true + + + make + testRot3.run + true + true + true + + + make + testRot2.run + true + true + true + + + make + testPose3.run + true + true + true + + + make + timeRot3.run + true + true + true + + + make + testPose2.run + true + true + true + + + make + testCal3_S2.run + true + true + true + + + make + testSimpleCamera.run + true + true + true + + + make + testHomography2.run + true + true + true + + + make + testCalibratedCamera.run + true + true + true + + + make + check + true + true + true + + + make + clean + true + true + true + + + make + testPoint2.run + true + true + true + make -j2 @@ -1185,7 +1249,6 @@ make - all true true @@ -1193,110 +1256,14 @@ make - dist true true true - - make - - testRot3.run - true - true - true - - - make - - testRot2.run - true - true - true - - - make - - testPose3.run - true - true - true - - - make - - timeRot3.run - true - true - true - - - make - - testPose2.run - true - true - true - - - make - - testCal3_S2.run - true - true - true - - - make - - testSimpleCamera.run - true - true - true - - - make - - testHomography2.run - true - true - true - - - make - - testCalibratedCamera.run - true - true - true - - - make - - check - true - true - true - - - make - - clean - true - true - true - - - make - - testPoint2.run - true - true - true - make + check true true @@ -1304,6 +1271,7 @@ make + testGaussianJunctionTree.run true true @@ -1311,6 +1279,7 @@ make + testGaussianFactorGraph.run true true @@ -1318,6 +1287,7 @@ make + timeGaussianFactorGraph.run true true @@ -1325,7 +1295,6 @@ make - testTupleConfig.run true true @@ -1333,22 +1302,22 @@ make - testFusionTupleConfig.run true true true - + make - SimpleRotation.run + testSerialization.run true true true make + check true true @@ -1356,6 +1325,7 @@ make + clean true true @@ -1363,6 +1333,7 @@ make + install true true @@ -1370,11 +1341,19 @@ make + all true true true + + make + SimpleRotation.run + true + true + true + diff --git a/config.h.in b/config.h.in index 023e32c2f..b3b1ddf3d 100644 --- a/config.h.in +++ b/config.h.in @@ -1,8 +1,5 @@ /* config.h.in. Generated from configure.ac by autoheader. */ -/* boost serialization flag */ -#undef HAVE_BOOST_SERIALIZATION - /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H diff --git a/configure.ac b/configure.ac index c3afc9148..f8162d76e 100644 --- a/configure.ac +++ b/configure.ac @@ -98,7 +98,7 @@ AC_ARG_ENABLE([ldl], [case "${enableval}" in yes) ldl=true ;; no) ldl=false ;; - *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-ldl]) ;; esac],[ldl=false]) AM_CONDITIONAL([USE_LDL], [test x$ldl = xtrue]) @@ -114,6 +114,17 @@ AC_ARG_ENABLE([profiling], AM_CONDITIONAL([USE_PROFILING], [test x$profiling = xtrue]) +# enable serialization in serialization test +AC_ARG_ENABLE([serialization], + [ --enable-serialization Enable serialization with boost serialization], + [case "${enableval}" in + yes) serialization=true ;; + no) serialization=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-serialization]) ;; + esac],[serialization=false]) + +AM_CONDITIONAL([ENABLE_SERIALIZATION], [test x$serialization = xtrue]) + # Checks for programs. AC_PROG_CXX AC_PROG_CC @@ -160,13 +171,13 @@ AC_ARG_WITH([boost], AC_SUBST([boost]) # ask for boost serialization -AC_ARG_WITH([boost_serialization], - [AS_HELP_STRING([--with-boost-serialization], - [(optional) use the Serialization library from boost - specify the library linking command with the full name of the library - e.g. --with-boost-serialization=-lboost_serialization-gcc-mt-d-1_33_1])], - [AC_DEFINE([HAVE_BOOST_SERIALIZATION], [""], [boost serialization flag]) - - boost_serialization=$withval ]) -AC_SUBST([boost_serialization]) +#AC_ARG_WITH([boost_serialization], +# [AS_HELP_STRING([--with-boost-serialization], +# [(optional) use the Serialization library from boost - specify the library linking command with the full name of the library +# e.g. --with-boost-serialization=-lboost_serialization-gcc-mt-d-1_33_1])], +# [AC_DEFINE([HAVE_BOOST_SERIALIZATION], [""], [boost serialization flag]) +# +#AC_SUBST([boost_serialization]) + AC_OUTPUT diff --git a/inference/BayesNet.h b/inference/BayesNet.h index 647461f31..8f1236414 100644 --- a/inference/BayesNet.h +++ b/inference/BayesNet.h @@ -10,8 +10,8 @@ #include #include -#include -#include +//#include +//#include #include #include diff --git a/inference/BayesTree.h b/inference/BayesTree.h index d89af82f2..948e03654 100644 --- a/inference/BayesTree.h +++ b/inference/BayesTree.h @@ -10,8 +10,8 @@ #include #include -#include -#include +//#include +//#include #include #include diff --git a/inference/Conditional.h b/inference/Conditional.h index d2477b176..62101d79d 100644 --- a/inference/Conditional.h +++ b/inference/Conditional.h @@ -9,9 +9,9 @@ #pragma once #include // for noncopyable -#include -#include -#include +//#include +//#include +//#include #include #include diff --git a/inference/FactorGraph.h b/inference/FactorGraph.h index 2262006c2..f227b19a9 100644 --- a/inference/FactorGraph.h +++ b/inference/FactorGraph.h @@ -11,10 +11,10 @@ #pragma once #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include #include diff --git a/inference/ISAM.h b/inference/ISAM.h index 6e75231cd..563ded450 100644 --- a/inference/ISAM.h +++ b/inference/ISAM.h @@ -11,8 +11,8 @@ #include #include #include -#include -#include +//#include +//#include #include #include diff --git a/inference/ISAM2.h b/inference/ISAM2.h index 81cbe2565..312a0d13f 100644 --- a/inference/ISAM2.h +++ b/inference/ISAM2.h @@ -11,8 +11,8 @@ #include #include #include -#include -#include +//#include +//#include #include #include diff --git a/inference/Key.h b/inference/Key.h index 1c957486d..1a403d8a6 100644 --- a/inference/Key.h +++ b/inference/Key.h @@ -11,7 +11,7 @@ #include #include #include -#include +//#include #include #ifdef GTSAM_MAGIC_KEY #include @@ -273,7 +273,9 @@ namespace gtsam { friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) { - ar & BOOST_SERIALIZATION_NVP(this->j_); + typedef TypedSymbol Base; + ar & boost::serialization::make_nvp("TypedLabeledSymbol", + boost::serialization::base_object(*this)); ar & BOOST_SERIALIZATION_NVP(label_); } }; diff --git a/inference/SymbolicBayesNet.h b/inference/SymbolicBayesNet.h index 043a42192..5a3b4a965 100644 --- a/inference/SymbolicBayesNet.h +++ b/inference/SymbolicBayesNet.h @@ -9,8 +9,8 @@ #pragma once #include -#include -#include +//#include +//#include #include #include diff --git a/inference/SymbolicConditional.h b/inference/SymbolicConditional.h index e737d3f9a..bd2534c84 100644 --- a/inference/SymbolicConditional.h +++ b/inference/SymbolicConditional.h @@ -13,7 +13,8 @@ #include #include #include // TODO: make cpp file -#include +//#include +#include #include #include diff --git a/linear/GaussianConditional.h b/linear/GaussianConditional.h index 9cee2ba9a..29948b797 100644 --- a/linear/GaussianConditional.h +++ b/linear/GaussianConditional.h @@ -12,8 +12,8 @@ #include #include #include -#include -#include +//#include +//#include #include #include diff --git a/linear/GaussianFactor.h b/linear/GaussianFactor.h index 805fd779d..27481269f 100644 --- a/linear/GaussianFactor.h +++ b/linear/GaussianFactor.h @@ -11,7 +11,7 @@ #include #include -#include +//#include #include #include #include diff --git a/linear/VectorBTree.h b/linear/VectorBTree.h index d83e9f1a6..f53aaace1 100644 --- a/linear/VectorBTree.h +++ b/linear/VectorBTree.h @@ -9,7 +9,7 @@ #pragma once #include -#include +//#include #include #include diff --git a/linear/VectorMap.h b/linear/VectorMap.h index f7d422fbf..a2d3bea81 100644 --- a/linear/VectorMap.h +++ b/linear/VectorMap.h @@ -10,7 +10,7 @@ #pragma once #include -#include +//#include #include #include diff --git a/nonlinear/LieConfig.h b/nonlinear/LieConfig.h index 79679c93a..64744e47b 100644 --- a/nonlinear/LieConfig.h +++ b/nonlinear/LieConfig.h @@ -18,7 +18,7 @@ #include #include -#include +//#include #include #include diff --git a/tests/Makefile.am b/tests/Makefile.am index 393db81e5..265a731db 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,6 +17,11 @@ check_PROGRAMS += testSymbolicBayesNet testSymbolicFactorGraph testTupleConfig check_PROGRAMS += testNonlinearEqualityConstraint testBoundingConstraint check_PROGRAMS += testTransformConstraint testLinearApproxFactor +# only if serialization is available +if ENABLE_SERIALIZATION +check_PROGRAMS += testSerialization +endif + # experimental #check_PROGRAMS += testFusionTupleConfig # Doesn't work on Macs @@ -32,7 +37,13 @@ noinst_PROGRAMS = timeGaussianFactorGraph timeFactorOverhead #---------------------------------------------------------------------------------------------------- TESTS = $(check_PROGRAMS) AM_CPPFLAGS = -I$(boost) -I$(BORG_SRCROOT) -AM_LDFLAGS = $(BOOST_LDFLAGS) $(boost_serialization) +AM_LDFLAGS = $(BOOST_LDFLAGS) + +# link to serialization library for test +if ENABLE_SERIALIZATION +AM_LDFLAGS += -lboost_serialization +endif + LDADD = ../libgtsam.la ../CppUnitLite/libCppUnitLite.a AM_DEFAULT_SOURCE_EXT = .cpp diff --git a/tests/testSerialization.cpp b/tests/testSerialization.cpp new file mode 100644 index 000000000..5f4e82ce7 --- /dev/null +++ b/tests/testSerialization.cpp @@ -0,0 +1,223 @@ +/* + * @brief Unit tests for serialization of library classes + * @author Frank Dellaert + * @author Alex Cunningham + */ + +/* ************************************************************************* */ +// Serialization testing code. +/* ************************************************************************* */ + +#include +#include +#include + +// includes for standard serialization types +//#include +//#include +//#include + +#include +#include +#include +#include + +// whether to print the serialized text to stdout +const bool verbose = false; + +// Templated round-trip serialization +template +void roundtrip(const T& input, T& output) { + + // Serialize + std::ostringstream out_archive_stream; + boost::archive::text_oarchive out_archive(out_archive_stream); + out_archive << input; + + // Convert to string + std::string serialized = out_archive_stream.str(); + if (verbose) std::cout << serialized << std::endl << std::endl; + + // De-serialize + std::istringstream in_archive_stream(serialized); + boost::archive::text_iarchive in_archive(in_archive_stream); + in_archive >> output; +} + +// This version requires equality operator +template +bool equality() { + T input; + T output; + roundtrip(input,output); + return input==output; +} + +template +bool equality(const T& input) { + T output; + roundtrip(input,output); + return input==output; +} + +// This version requires equals +template +bool equalsEmpty() { + T input; + T output; + roundtrip(input,output); + return input.equals(output); +} + +template +bool equalsObj(const T& input) { + T output; + roundtrip(input,output); + return input.equals(output); +} + +// De-referenced version for pointers +template +bool equalsDereferenced(const T& input) { + T output; + roundtrip(input,output); + return input->equals(*output); +} + +/* ************************************************************************* */ +// Templated round-trip serialization using XML +template +void roundtripXML(const T& input, T& output) { + + // Serialize + std::ostringstream out_archive_stream; + boost::archive::xml_oarchive out_archive(out_archive_stream); + out_archive << BOOST_SERIALIZATION_NVP(input); + + // Convert to string + std::string serialized = out_archive_stream.str(); + if (verbose) std::cout << serialized << std::endl << std::endl; + + // De-serialize + std::istringstream in_archive_stream(serialized); + boost::archive::xml_iarchive in_archive(in_archive_stream); + in_archive >> BOOST_SERIALIZATION_NVP(output); +} + +// This version requires equality operator +template +bool equalityXML() { + T input; + T output; + roundtripXML(input,output); + return input==output; +} + +template +bool equalityXML(const T& input) { + T output; + roundtripXML(input,output); + return input==output; +} + +// This version requires equals +template +bool equalsXML() { + T input; + T output; + roundtripXML(input,output); + return input.equals(output); +} + +template +bool equalsXML(const T& input) { + T output; + roundtripXML(input,output); + return input.equals(output); +} + +/* ************************************************************************* */ +// Actual Tests +/* ************************************************************************* */ + +#include +//#include +//#include +//#include +//#include +//#include +//#include + +//#include +//#include +//#include +//#include + +#include + +using namespace std; +using namespace gtsam; + +/* ************************************************************************* */ +//TEST( Point2, equalsEmpty) { CHECK(equalsEmpty());} +//TEST( VectorConfig, equalsEmpty) { CHECK(equalsEmpty());} +//TEST( GaussianConditional, equalsEmpty) { CHECK(equalsEmpty());} + + + +/* ************************************************************************* */ +// Testing XML +/* ************************************************************************* */ +//TEST( Point2, equalsXML) { CHECK(equalsXML());} + +//TEST( VectorConfig, equalsXML) { CHECK(equalsXML());} +//TEST( Cal3_S2, equalsXML) { CHECK(equalsXML());} +//TEST( GaussianConditional, equalsXML) { CHECK(equalsXML());} +//TEST( SymbolicConditional, equalsXML) { CHECK(equalsXML());} + + +// The two tests below will not run, however, as CameraMarkerFactor +// is not registered by the serialization code in FactorGraph +//TEST( FactorGraph, equals1) +//{ +// FactorGraph graph; +// graph.push_back(f); +// CHECK(equalsObj(graph)); +//} +//TEST( NonlinearFactorGraph, equals) +//{ +// NonlinearFactorGraph graph; +// graph.push_back(f); +// CHECK(equalsObj(graph)); +//} + +// It *does* work if we explicitly instantiate with the factor type +//TEST( FactorGraph, equals2) +//{ +// FactorGraph graph; +// graph.push_back(f); +// CHECK(equalsObj(graph)); +//} + +// And, as we explicitly registered the three CameraMarkerFactor types in +// the EasySLAMGraph serialize, this will also work :-)) +// see http://www.boost.org/doc/libs/1_35_0/libs/serialization/doc/serialization.html#derivedpointers +//TEST( EasySLAMGraph, equals2) +//{ +// EasySLAMGraph graph = createExampleGraph(); +// CHECK(equalsObj(graph)); +//} +// +//// EasySLAMConfig is no problem either: +//TEST( EasySLAMConfig, equals2) +//{ +// EasySLAMConfig c = createExampleConfig(); +// CHECK(equalsObj(c)); +//} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */