TuttleOFX  1
lines.tests.cpp
Go to the documentation of this file.
00001 #include <boost/test/included/unit_test.hpp>
00002 
00003 #include <lines.hpp>
00004 
00005 using boost::unit_test::test_suite;
00006 using namespace boost::gil;
00007 
00008 //g++ lines.tests.cpp -I /home/scott/project/boost_1_36_0 -I .
00009 
00010 struct test1
00011 {
00012         void operator()()
00013         {
00014                 int width = 200;
00015                 int height = 200;
00016                 unsigned char* buffer = new unsigned char[width * height * 3];
00017                 memset(buffer, 255, width * height * 3);        
00018                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00019 
00020                 typedef boost::function<void (rgb8_view_t&)> layer_t;
00021 
00022                 layer::uniform_horizontal_lines<rgb8_view_t> lines(rgb8_view_t::value_type(0,0,0),10);
00023                 lines(view);
00024                 
00025                 FILE* fd = fopen("lines1.ppm", "wb");
00026                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00027                 fwrite(buffer, 1, width*height*3, fd);
00028                 fclose(fd);
00029                 delete [] buffer;
00030         }
00031 };
00032 
00033 struct test2
00034 {
00035         void operator()()
00036         {
00037                 int width = 200;
00038                 int height = 200;
00039                 unsigned char* buffer = new unsigned char[width * height * 3];
00040                 memset(buffer, 255, width * height * 3);        
00041                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00042 
00043                 typedef boost::function<void (rgb8_view_t&)> layer_t;
00044 
00045                 layer::uniform_vertical_lines<rgb8_view_t> lines(rgb8_view_t::value_type(0,0,0),10);
00046                 lines(view);
00047                 
00048                 FILE* fd = fopen("lines2.ppm", "wb");
00049                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00050                 fwrite(buffer, 1, width*height*3, fd);
00051                 fclose(fd);
00052                 delete [] buffer;
00053         }
00054 };
00055 
00056 struct test3
00057 {
00058         void operator()()
00059         {
00060                 int width = 200;
00061                 int height = 200;
00062                 unsigned char* buffer = new unsigned char[width * height * 3];
00063                 memset(buffer, 255, width * height * 3);        
00064                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00065 
00066                 typedef boost::function<void (rgb8_view_t&)> layer_t;
00067 
00068                 layer::horizontal_line<rgb8_view_t> line(rgb8_view_t::value_type(0,0,0),30,0,100);
00069                 line(view);
00070                 
00071                 FILE* fd = fopen("lines3.ppm", "wb");
00072                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00073                 fwrite(buffer, 1, width*height*3, fd);
00074                 fclose(fd);
00075                 delete [] buffer;
00076         }
00077 };
00078 
00079 struct test4
00080 {
00081         void operator()()
00082         {
00083                 int width = 200;
00084                 int height = 200;
00085                 unsigned char* buffer = new unsigned char[width * height * 3];
00086                 memset(buffer, 255, width * height * 3);        
00087                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00088 
00089                 typedef boost::function<void (rgb8_view_t&)> layer_t;
00090 
00091                 layer::vertical_lines<rgb8_view_t> line(rgb8_view_t::value_type(0,0,0),10,20);
00092                 line(view);
00093                 
00094                 FILE* fd = fopen("lines4.ppm", "wb");
00095                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00096                 fwrite(buffer, 1, width*height*3, fd);
00097                 fclose(fd);
00098                 delete [] buffer;
00099         }
00100 };
00101 
00102 test_suite* init_unit_test_suite( int argc, char** argv)
00103 {
00104         test_suite* test= BOOST_TEST_SUITE( "lines tests" );
00105         test->add( BOOST_TEST_CASE(test1()), 0);
00106         test->add( BOOST_TEST_CASE(test2()), 0);
00107         test->add( BOOST_TEST_CASE(test3()), 0);
00108         test->add( BOOST_TEST_CASE(test4()), 0);
00109         return test;
00110 }
00111