TuttleOFX
1
|
00001 #include <boost/test/included/unit_test.hpp> 00002 00003 #include <sections.hpp> 00004 #include <fill.hpp> 00005 00006 using boost::unit_test::test_suite; 00007 using namespace boost::gil; 00008 00009 //g++ section.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 std::pair<double, layer_t> pair_t; 00023 typedef layer::fill<rgb8_view_t> fill_t; 00024 00025 pair_t a[] = 00026 { 00027 pair_t(30,fill_t(rgb8_view_t::value_type(255,0,255))), 00028 pair_t(30,fill_t(rgb8_view_t::value_type(255,0,0))), 00029 pair_t(0,fill_t(rgb8_view_t::value_type(0,0,255))), 00030 pair_t(30,fill_t(rgb8_view_t::value_type(255,0,0))), 00031 pair_t(30,fill_t(rgb8_view_t::value_type(100,0,255))), 00032 pair_t(30,fill_t(rgb8_view_t::value_type(100,0,100))), 00033 }; 00034 00035 layer::rows<rgb8_view_t> rows(a,6,5); 00036 rows(view); 00037 00038 FILE* fd = fopen("sections.test1.ppm", "wb"); 00039 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height); 00040 fwrite(buffer, 1, width*height*3, fd); 00041 fclose(fd); 00042 delete [] buffer; 00043 } 00044 }; 00045 00046 struct test2 00047 { 00048 void operator()() 00049 { 00050 int width = 200; 00051 int height = 200; 00052 unsigned char* buffer = new unsigned char[width * height * 3]; 00053 memset(buffer, 255, width * height * 3); 00054 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3); 00055 00056 typedef boost::function<void (rgb8_view_t&)> layer_t; 00057 typedef std::pair<double, layer_t> pair_t; 00058 typedef layer::fill<rgb8_view_t> fill_t; 00059 00060 pair_t a[] = 00061 { 00062 pair_t(30,fill_t(rgb8_view_t::value_type(255,0,255))), 00063 pair_t(30,fill_t(rgb8_view_t::value_type(255,0,0))), 00064 pair_t(0,fill_t(rgb8_view_t::value_type(0,0,255))), 00065 pair_t(30,fill_t(rgb8_view_t::value_type(255,0,0))), 00066 pair_t(30,fill_t(rgb8_view_t::value_type(100,0,255))), 00067 pair_t(30,fill_t(rgb8_view_t::value_type(100,0,100))), 00068 }; 00069 00070 layer::columns<rgb8_view_t> rows(a,6,5); 00071 rows(view); 00072 00073 FILE* fd = fopen("sections.test2.ppm", "wb"); 00074 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height); 00075 fwrite(buffer, 1, width*height*3, fd); 00076 fclose(fd); 00077 delete [] buffer; 00078 } 00079 }; 00080 00081 test_suite* init_unit_test_suite( int argc, char** argv) 00082 { 00083 test_suite* test= BOOST_TEST_SUITE( "sections tests" ); 00084 test->add( BOOST_TEST_CASE(test1()), 0); 00085 test->add( BOOST_TEST_CASE(test2()), 0); 00086 return test; 00087 }