TuttleOFX
1
|
00001 #include <boost/test/included/unit_test.hpp> 00002 00003 #include <channels.hpp> 00004 #include <fill.hpp> 00005 00006 using boost::unit_test::test_suite; 00007 using namespace boost::gil; 00008 00009 //g++ channels.tests.cpp -I /home/scott/project/boost_1_36_0 -I . 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 layer::horizontal_channels<rgb8_view_t> channels(a,6,3); 00035 channels(view); 00036 00037 FILE* fd = fopen("channels.ppm", "wb"); 00038 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height); 00039 fwrite(buffer, 1, width*height*3, fd); 00040 fclose(fd); 00041 delete [] buffer; 00042 } 00043 }; 00044 00045 struct test2 00046 { 00047 void operator()() 00048 { 00049 channels curr(100,3); 00050 00051 double a[] = {0,49,99}; 00052 00053 int n = 0; 00054 for(; curr; ++curr, n++) 00055 { 00056 BOOST_CHECK(a[n] == *curr); 00057 } 00058 } 00059 }; 00060 00061 test_suite* init_unit_test_suite( int argc, char** argv) 00062 { 00063 test_suite* test= BOOST_TEST_SUITE( "channels tests" ); 00064 test->add( BOOST_TEST_CASE(test1()), 0); 00065 test->add( BOOST_TEST_CASE(test2()), 0); 00066 return test; 00067 }