TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/test/io/writer.hpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <boost/filesystem/path.hpp>
00004 
00005 using namespace boost::unit_test;
00006 using namespace tuttle::host;
00007 namespace bfs = boost::filesystem;
00008 
00009 BOOST_AUTO_TEST_CASE( process_writer )
00010 {
00011         TUTTLE_LOG_INFO( "******** PROCESS WRITER " << pluginName << " ********" );
00012         Graph g;
00013 
00014         TUTTLE_LOG_INFO( "-------- PLUGINS CREATION --------" );
00015         Graph::Node& constant = g.createNode( "tuttle.constant" );
00016         Graph::Node& writer   = g.createNode( pluginName );
00017 
00018         TUTTLE_LOG_INFO( "-------- PLUGINS CONFIGURATION --------" );
00019 
00020         constant.getParam( "width" ).setValue( 500 );
00021         constant.getParam( "height" ).setValue( 500 );
00022         
00023         std::string tuttleOFXData = "TuttleOFX-data";
00024         if( const char* env_test_data = std::getenv("TUTTLE_TEST_DATA") )
00025         {
00026                 tuttleOFXData = env_test_data;
00027         }
00028         
00029         const std::string pluginFilename = ( bfs::path(tuttleOFXData) / "image" / filename ).string();
00030         writer.getParam( "filename" ).setValue( pluginFilename );
00031 
00032         TUTTLE_LOG_INFO( "-------- GRAPH CONNECTION --------" );
00033         g.connect( constant, writer );
00034 
00035         TUTTLE_LOG_INFO( "-------- GRAPH PROCESSING --------" );
00036         boost::posix_time::ptime t1a(boost::posix_time::microsec_clock::local_time());
00037         memory::MemoryCache outputCache;
00038         g.compute( outputCache, writer );
00039         boost::posix_time::ptime t2a(boost::posix_time::microsec_clock::local_time());
00040 
00041         TUTTLE_LOG_INFO( "Process took: " << t2a - t1a );
00042         TUTTLE_LOG_INFO( outputCache );
00043 
00044         memory::CACHE_ELEMENT imgRes = outputCache.get( writer.getName(), 0 );
00045 
00046         TUTTLE_TLOG_VAR( TUTTLE_INFO, imgRes->getROD() );
00047         BOOST_CHECK_EQUAL( imgRes->getROD().x1, 0 );
00048         BOOST_CHECK_EQUAL( imgRes->getROD().y1, 0 );
00049         BOOST_CHECK_EQUAL( imgRes->getROD().x2, 500 );
00050         BOOST_CHECK_EQUAL( imgRes->getROD().y2, 500 );
00051 
00052         TUTTLE_TLOG_VAR( TUTTLE_INFO, imgRes->getBounds() );
00053         BOOST_CHECK_EQUAL( imgRes->getBounds().x1, 0 );
00054         BOOST_CHECK_EQUAL( imgRes->getBounds().y1, 0 );
00055         BOOST_CHECK_EQUAL( imgRes->getBounds().x2, 500 );
00056         BOOST_CHECK_EQUAL( imgRes->getBounds().y2, 500 );
00057 }
00058 
00059 BOOST_AUTO_TEST_CASE( process_unconnected )
00060 {
00061         TUTTLE_LOG_INFO( "******** PROCESS WRITER " << pluginName << " UNCONNECTED ********" );
00062         Graph g;
00063 
00064         TUTTLE_LOG_INFO( "--> PLUGINS CREATION" );
00065         Graph::Node& write = g.createNode( pluginName );
00066 
00067         TUTTLE_LOG_INFO( "--> PLUGINS CONFIGURATION" );
00068         std::string filename = "data/no-such-file";
00069         write.getParam( "filename" ).setValue( filename );
00070 
00071         TUTTLE_LOG_INFO( "---> GRAPH PROCESSING" );
00072         BOOST_REQUIRE_THROW( g.compute( write ), boost::exception );
00073 }