TuttleOFX  1
TuttleOFX/libraries/tuttle/tests/ofx/plugin/main.cpp
Go to the documentation of this file.
00001 #define BOOST_TEST_MODULE imageeffectplugin_tests
00002 #include <tuttle/test/unit_test.hpp>
00003 
00004 #include <tuttle/common/utils/global.hpp>
00005 #include <tuttle/host/Core.hpp>
00006 #include <tuttle/host/ofx/OfxhImageEffectPlugin.hpp>
00007 
00008 #include <boost/archive/xml_oarchive.hpp>
00009 #include <boost/archive/binary_oarchive.hpp>
00010 #include <boost/archive/text_oarchive.hpp>
00011 #include <boost/archive/xml_iarchive.hpp>
00012 #include <boost/archive/binary_iarchive.hpp>
00013 #include <boost/archive/text_iarchive.hpp>
00014 #include <boost/serialization/serialization.hpp>
00015 #include <boost/serialization/export.hpp>
00016 #include <boost/serialization/extended_type_info.hpp>
00017 #include <boost/filesystem/operations.hpp>
00018 
00019 #include <fstream>
00020 #include <iostream>
00021 
00022 using namespace boost::unit_test;
00023 
00024 BOOST_AUTO_TEST_SUITE( plugin_serialization )
00025 
00026 BOOST_AUTO_TEST_CASE( imageeffectplugin_serialization )
00027 {
00028         using namespace std;
00029         using namespace tuttle::host;
00030         using namespace tuttle::host::ofx;
00031         using namespace tuttle::host::ofx::imageEffect;
00032 
00033         core().getPluginCache().addDirectoryToPath( BOOST_PP_STRINGIZE(TUTTLE_PLUGIN_PATH) );
00034         core().preload();
00035 
00036         OfxhImageEffectPlugin* plugin = core().getImageEffectPluginById( "tuttle.invert" );
00037 
00038         //      typedef boost::archive::binary_oarchive OArchive;
00039         //      typedef boost::archive::binary_iarchive IArchive;
00040         //      typedef boost::archive::text_oarchive OArchive;
00041         //      typedef boost::archive::text_iarchive IArchive;
00042         typedef boost::archive::xml_oarchive OArchive;
00043         typedef boost::archive::xml_iarchive IArchive;
00044 
00045         //// Write "tuttle.invert" plugin into a cache file
00046         const std::string testfile = ( core().getPreferences().buildTuttleTestPath() / "test_imageEffectPlugin_serialization.xml" ).string();
00047         TUTTLE_TLOG_VAR( TUTTLE_TRACE, testfile );
00048         BOOST_REQUIRE( testfile.size() );
00049 
00050         {
00051                 std::ofstream ofsb( testfile.c_str() );
00052                 OArchive oArchive( ofsb );
00053                 oArchive << BOOST_SERIALIZATION_NVP( plugin );
00054                 ofsb.close();
00055         }
00056 
00057         BOOST_CHECK( boost::filesystem::exists( testfile ) );
00058 
00059         //// Read "tuttle.invert" plugin from the cache file
00060         OfxhImageEffectPlugin* plugin2 = NULL;
00061 
00062         {
00063                 std::ifstream ifsb( testfile.c_str() );
00064                 IArchive iArchive( ifsb );
00065                 iArchive >> BOOST_SERIALIZATION_NVP( plugin2 );
00066                 ifsb.close();
00067         }
00068         BOOST_CHECK( boost::filesystem::exists( testfile ) );
00069         boost::filesystem::remove( testfile );
00070 
00071         
00072         //// The new plugin re-created from the cache file is the same than the original
00073         BOOST_CHECK( ( *plugin ) == ( *plugin2 ) );
00074 
00075         
00076         // Rewrite "tuttle.invert" plugin into another cache file
00077         const std::string testfile2 = ( core().getPreferences().buildTuttleTestPath() / "test_imageEffectPlugin_serialization2.xml" ).string();
00078         TUTTLE_TLOG_VAR( TUTTLE_TRACE, testfile2 );
00079         BOOST_REQUIRE( testfile2.size() );
00080 
00081         {
00082                 std::ofstream ofsb2( testfile2.c_str() );
00083                 OArchive oArchive2( ofsb2 );
00084                 oArchive2 << BOOST_SERIALIZATION_NVP( plugin2 );
00085                 ofsb2.close();
00086         }
00087 
00088         BOOST_CHECK( boost::filesystem::exists( testfile2 ) );
00089         boost::filesystem::remove( testfile2 );
00090 }
00091 
00092 BOOST_AUTO_TEST_SUITE_END()
00093