ljpegtest.cpp

00001 /*
00002  * Copyright (C) 2007 Hubert Figuiere
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00017  */
00018 
00019 
00020 
00021 #include <string>
00022 
00023 #include <boost/test/auto_unit_test.hpp>
00024 #include <boost/crc.hpp>      // for boost::crc_basic, boost::crc_optimal
00025 
00026 #include <libopenraw++/rawdata.h>
00027 
00028 #include "io/file.h"
00029 #include "rawcontainer.h"
00030 #include "jfifcontainer.h"
00031 #include "ljpegdecompressor.h"
00032 #include "ljpegdecompressor_priv.h"
00033 
00034 using boost::unit_test::test_suite;
00035 using OpenRaw::RawData;
00036 using OpenRaw::IO::File;
00037 
00038 std::string g_testfile;
00039 
00040 using namespace OpenRaw::Internals;
00041 
00042 void test_ljpeg()
00043 {
00044     RawData *decompData;
00045     File *s = new File(g_testfile.c_str());
00046     RawContainer *container = new JFIFContainer(s, 0);
00047 
00048     LJpegDecompressor decompressor(s, container);
00049 
00050     decompData = decompressor.decompress();
00051 
00052     boost::crc_optimal<8, 0x1021, 0xFFFF, 0, false, false>  crc_ccitt2;
00053     const uint8_t * data = static_cast<uint8_t *>(decompData->data());
00054     size_t data_len = decompData->size();
00055     crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 );
00056     BOOST_CHECK_EQUAL(crc_ccitt2(), 0x49);
00057 
00058     delete decompData;
00059     delete container;
00060     delete s;
00061 }
00062 
00063 
00064 
00065 test_suite*
00066 init_unit_test_suite( int argc, char * argv[] ) 
00067 {
00068     test_suite* test = BOOST_TEST_SUITE("test ljpeg");
00069     
00070     if (argc == 1) {
00071         // no argument, lets run like we are in "check"
00072         const char * srcdir = getenv("srcdir");
00073         
00074         BOOST_ASSERT(srcdir != NULL);
00075         g_testfile = std::string(srcdir);
00076         g_testfile += "/ljpegtest1.jpg";
00077     }
00078     else {
00079         g_testfile = argv[1];
00080     }
00081     
00082     test->add(BOOST_TEST_CASE(&test_ljpeg));
00083 
00084     return test;
00085 }

Generated on Tue Jun 17 11:47:26 2008 for libopenraw by  doxygen 1.5.6