TuttleOFX  1
parallel_grid.tests.cpp
Go to the documentation of this file.
00001 #include <boost/test/included/unit_test.hpp>
00002 
00003 #include <parallel_grid.hpp>
00004 #include <fill.hpp>
00005 
00006 using boost::unit_test::test_suite;
00007 using namespace boost::gil;
00008 
00009 //g++ parallel_grid.tests.cpp -I /home/scott/project/boost_1_36_0 -I . -ltbb -lpthread
00010 
00011 struct test1
00012 {
00013         void operator()()
00014         {
00015                 int width = 200;
00016                 int height = 200;
00017                 unsigned char* buffer = new unsigned char[width * height * 3];
00018                 memset(buffer, 255, width * height * 3);        
00019                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00020 
00021                 typedef boost::function<void (rgb8_view_t&)> layer_t;
00022                 typedef layer::fill<rgb8_view_t> fill_t;
00023 
00024                 layer_t a[] = 
00025                 {
00026                         fill_t(rgb8_view_t::value_type(255,0,255)),
00027                         fill_t(rgb8_view_t::value_type(255,0,0)),
00028                         fill_t(rgb8_view_t::value_type(0,0,255)),
00029                         fill_t(rgb8_view_t::value_type(255,0,0)),
00030                         fill_t(rgb8_view_t::value_type(100,0,255)),
00031                         fill_t(rgb8_view_t::value_type(100,0,100)),
00032                 };
00033 
00034                 tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);
00035                 init.initialize(1);
00036 
00037                 layer::parallel_grid<rgb8_view_t> grid(a,6,3);
00038                 grid(view);
00039                 
00040                 FILE* fd = fopen("parallel_grid.ppm", "wb");
00041                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00042                 fwrite(buffer, 1, width*height*3, fd);
00043                 fclose(fd);
00044                 delete [] buffer;
00045         }
00046 };
00047 
00048 struct test2
00049 {
00050         void operator()()
00051         {
00052                 sections curr(100,3);
00053 
00054                 double a[] = {34,33,33};
00055 
00056                 int n = 0;
00057                 for(; curr; ++curr, n++)
00058                 {
00059                         BOOST_CHECK(a[n] == *curr);
00060                 }
00061         }
00062 };
00063 
00064 test_suite* init_unit_test_suite( int argc, char** argv)
00065 {
00066         test_suite* test= BOOST_TEST_SUITE( "border tests" );
00067         test->add( BOOST_TEST_CASE(test1()), 0);
00068         test->add( BOOST_TEST_CASE(test2()), 0);
00069         return test;
00070 }