TuttleOFX  1
main.cpp
Go to the documentation of this file.
00001 #define BOOST_TEST_MODULE imageeffectplugin_tests
00002 #include <boost/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         OfxhImageEffectPlugin* plugin = core().getImageEffectPluginById( "tuttle.invert" );
00036 
00037         //      typedef boost::archive::binary_oarchive OArchive;
00038         //      typedef boost::archive::binary_iarchive IArchive;
00039         //      typedef boost::archive::text_oarchive OArchive;
00040         //      typedef boost::archive::text_iarchive IArchive;
00041         typedef boost::archive::xml_oarchive OArchive;
00042         typedef boost::archive::xml_iarchive IArchive;
00043 
00044         //// Write "tuttle.invert" plugin into a cache file
00045         const std::string testfile = ( core().getPreferences().buildTuttleTestPath() / "test_imageEffectPlugin_serialization.xml" ).string();
00046         TUTTLE_TLOG_VAR( TUTTLE_TRACE, testfile );
00047         BOOST_REQUIRE( testfile.size() );
00048 
00049         {
00050                 std::ofstream ofsb( testfile.c_str() );
00051                 OArchive oArchive( ofsb );
00052                 oArchive << BOOST_SERIALIZATION_NVP( plugin );
00053                 ofsb.close();
00054         }
00055 
00056         BOOST_CHECK( boost::filesystem::exists( testfile ) );
00057 
00058         //// Read "tuttle.invert" plugin from the cache file
00059         OfxhImageEffectPlugin* plugin2 = NULL;
00060 
00061         {
00062                 std::ifstream ifsb( testfile.c_str() );
00063                 IArchive iArchive( ifsb );
00064                 iArchive >> BOOST_SERIALIZATION_NVP( plugin2 );
00065                 ifsb.close();
00066         }
00067         BOOST_CHECK( boost::filesystem::exists( testfile ) );
00068         boost::filesystem::remove( testfile );
00069 
00070         
00071         //// The new plugin re-created from the cache file is the same than the original
00072         BOOST_CHECK( ( *plugin ) == ( *plugin2 ) );
00073 
00074         
00075         // Rewrite "tuttle.invert" plugin into another cache file
00076         const std::string testfile2 = ( core().getPreferences().buildTuttleTestPath() / "test_imageEffectPlugin_serialization2.xml" ).string();
00077         TUTTLE_TLOG_VAR( TUTTLE_TRACE, testfile2 );
00078         BOOST_REQUIRE( testfile2.size() );
00079 
00080         {
00081                 std::ofstream ofsb2( testfile2.c_str() );
00082                 OArchive oArchive2( ofsb2 );
00083                 oArchive2 << BOOST_SERIALIZATION_NVP( plugin2 );
00084                 ofsb2.close();
00085         }
00086 
00087         BOOST_CHECK( boost::filesystem::exists( testfile2 ) );
00088         boost::filesystem::remove( testfile2 );
00089 }
00090 
00091 BOOST_AUTO_TEST_SUITE_END()
00092