new c++ tiff tests - refs #2491

This commit is contained in:
Dane Springmeyer 2014-12-08 14:52:52 -05:00
parent dc3df99f66
commit bc3f59af12
18 changed files with 9182 additions and 18 deletions

View file

@ -1963,6 +1963,7 @@ if not HELP_REQUESTED:
# build C++ tests
SConscript('tests/cpp_tests/build.py')
SConscript('tests/cxx/build.py')
if env['BENCHMARK']:
SConscript('benchmark/build.py')

View file

@ -5,15 +5,20 @@ failures=0
source ./localize.sh
PYTHON=${PYTHON:-python}
echo "*** Running visual tests..."
$PYTHON tests/visual_tests/test.py -q
echo "*** Running Next Gen C++ tests..."
./tests/cxx/run
failures=$((failures+$?))
echo
echo "*** Running C++ tests..."
echo "*** Running Old C++ tests..."
./tests/cpp_tests/run
failures=$((failures+$?))
echo
echo "*** Running visual tests..."
$PYTHON tests/visual_tests/test.py -q
failures=$((failures+$?))
echo "*** Running python tests..."
$PYTHON tests/run_tests.py -q
failures=$((failures+$?))

View file

@ -135,6 +135,7 @@ private:
unsigned bps_;
unsigned photometric_;
unsigned bands_;
bool is_tiled_;
public:
enum TiffType {
@ -151,6 +152,9 @@ public:
bool premultiplied_alpha() const final;
void read(unsigned x,unsigned y,image_data_rgba8& image) final;
image_data_any read(unsigned x, unsigned y, unsigned width, unsigned height) final;
// methods specific to tiff reader
std::size_t bits_per_sample() const { return bps_; }
bool is_tiled() const { return is_tiled_; }
private:
tiff_reader(const tiff_reader&);
tiff_reader& operator=(const tiff_reader&);
@ -199,7 +203,8 @@ tiff_reader<T>::tiff_reader(std::string const& file_name)
has_alpha_(false),
bps_(0),
photometric_(0),
bands_(1)
bands_(1),
is_tiled_(false)
{
if (!stream_) throw image_reader_exception("TIFF reader: cannot open file "+ file_name);
init();
@ -219,7 +224,8 @@ tiff_reader<T>::tiff_reader(char const* data, std::size_t size)
has_alpha_(false),
bps_(0),
photometric_(0),
bands_(1)
bands_(1),
is_tiled_(false)
{
if (!stream_) throw image_reader_exception("TIFF reader: cannot open image stream ");
stream_.seekg(0, std::ios::beg);
@ -255,10 +261,12 @@ void tiff_reader<T>::init()
}
MAPNIK_LOG_DEBUG(tiff_reader) << "orientation: " << orientation;
is_tiled_ = TIFFIsTiled(tif);
char msg[1024];
if (true)//TIFFRGBAImageOK(tif,msg))
if (TIFFRGBAImageOK(tif,msg))
{
if (TIFFIsTiled(tif))
if (is_tiled_)
{
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width_);
TIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height_);
@ -517,7 +525,7 @@ void tiff_reader<T>::read_generic(unsigned, unsigned, image_data_rgba8& image)
TIFF* tif = open(stream_);
if (tif)
{
MAPNIK_LOG_ERROR(tiff_reader) << "tiff_reader: TODO - tiff is not stripped or tiled";
throw std::runtime_error("tiff_reader: TODO - tiff is not stripped or tiled");
}
}

11
tests/cxx/README.md Normal file
View file

@ -0,0 +1,11 @@
Catch C++ tests
### Building
python scons/scons.py tests/cxx/run
### Running
./tests/cxx/run

32
tests/cxx/build.py Normal file
View file

@ -0,0 +1,32 @@
import os
import glob
from copy import copy
Import ('env')
test_env = env.Clone()
if not env['CPP_TESTS']:
for cpp_test_bin in glob.glob('*-bin'):
os.unlink(cpp_test_bin)
else:
test_env['LIBS'] = [env['MAPNIK_NAME']]
test_env.AppendUnique(LIBS=copy(env['LIBMAPNIK_LIBS']))
test_env.AppendUnique(LIBS='mapnik-wkt')
test_env.AppendUnique(LIBS='mapnik-json')
if env['RUNTIME_LINK'] == 'static' and env['PLATFORM'] == 'Linux':
test_env.AppendUnique(LIBS='dl')
test_env.AppendUnique(CXXFLAGS='-g')
test_env['CXXFLAGS'] = copy(test_env['LIBMAPNIK_CXXFLAGS'])
test_env.Append(CPPDEFINES = env['LIBMAPNIK_DEFINES'])
if test_env['HAS_CAIRO']:
test_env.PrependUnique(CPPPATH=test_env['CAIRO_CPPPATHS'])
test_env.Append(CPPDEFINES = '-DHAVE_CAIRO')
test_env_local = test_env.Clone()
test_program = test_env_local.Program("run", source=glob.glob('*.cpp'))
Depends(test_program, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
Depends(test_program, env.subst('../../src/json/libmapnik-json${LIBSUFFIX}'))
Depends(test_program, env.subst('../../src/wkt/libmapnik-wkt${LIBSUFFIX}'))
# build locally if installing
if 'install' in COMMAND_LINE_TARGETS:
env.Alias('install',test_program)

8997
tests/cxx/catch.hpp Normal file

File diff suppressed because it is too large Load diff

2
tests/cxx/test_main.cpp Normal file
View file

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

76
tests/cxx/tiff_io.cpp Normal file
View file

@ -0,0 +1,76 @@
#include "catch.hpp"
#include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/util/file_io.hpp>
#include <mapnik/tiff_io.hpp>
#include "../../src/tiff_reader.cpp"
std::unique_ptr<mapnik::image_reader> open(std::string const& filename)
{
return std::unique_ptr<mapnik::image_reader>(mapnik::get_image_reader(filename,"tiff"));
}
#define TIFF_ASSERT(filename) \
mapnik::tiff_reader<boost::iostreams::file_source> tiff_reader(filename); \
REQUIRE( tiff_reader.width() == 256 ); \
REQUIRE( tiff_reader.height() == 256 ); \
REQUIRE( tiff_reader.has_alpha() == false ); \
REQUIRE( tiff_reader.premultiplied_alpha() == false ); \
auto reader = open(filename); \
REQUIRE( reader->width() == 256 ); \
REQUIRE( reader->height() == 256 ); \
REQUIRE( reader->has_alpha() == false ); \
REQUIRE( reader->premultiplied_alpha() == false ); \
TEST_CASE("tiff io") {
SECTION("gray8 striped") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray8_striped.tif")
REQUIRE( tiff_reader.bits_per_sample() == 8 );
REQUIRE( tiff_reader.is_tiled() == false );
}
SECTION("gray8 tiled") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray8_tiled.tif")
REQUIRE( tiff_reader.bits_per_sample() == 8 );
REQUIRE( tiff_reader.is_tiled() == true );
}
SECTION("gray16 striped") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray16_striped.tif")
REQUIRE( tiff_reader.bits_per_sample() == 16 );
REQUIRE( tiff_reader.is_tiled() == false );
}
SECTION("gray16 tiled") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray16_tiled.tif")
REQUIRE( tiff_reader.bits_per_sample() == 16 );
REQUIRE( tiff_reader.is_tiled() == true );
}
SECTION("rgba8 striped") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_rgba8_striped.tif")
REQUIRE( tiff_reader.bits_per_sample() == 8 );
REQUIRE( tiff_reader.is_tiled() == false );
}
SECTION("rgba8 tiled") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_rgba8_tiled.tif")
REQUIRE( tiff_reader.bits_per_sample() == 8 );
REQUIRE( tiff_reader.is_tiled() == true );
}
SECTION("gray32f striped") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray32f_striped.tif")
REQUIRE( tiff_reader.bits_per_sample() == 32 );
REQUIRE( tiff_reader.is_tiled() == false );
}
SECTION("gray32f tiled") {
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray32f_tiled.tif")
REQUIRE( tiff_reader.bits_per_sample() == 32 );
REQUIRE( tiff_reader.is_tiled() == true );
}
}

31
tests/cxx/valgrind.supp Normal file
View file

@ -0,0 +1,31 @@
{
dl_error1
Memcheck:Cond
fun:index
fun:expand_dynamic_string_token
fun:fillin_rpath
fun:_dl_init_paths
fun:dl_main
fun:_dl_sysdep_start
fun:_dl_start
}
{
dl_error2
Memcheck:Cond
fun:index
fun:expand_dynamic_string_token
fun:_dl_map_object
fun:map_doit
fun:_dl_catch_error
fun:do_preload
fun:dl_main
fun:_dl_sysdep_start
fun:_dl_start
}
{
tmpfile
Memcheck:Leak
fun:malloc
fun:fdopen@@GLIBC_*
fun:tmpfile@@GLIBC_*
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -13,7 +13,7 @@ def setup():
os.chdir(execution_path('.'))
def test_tiff_rgba8_compare():
filepath1 = '../data/images/24989_rgb_uint8.tif'
filepath1 = '../data/tiff/ndvi_256x256_rgba8_striped.tif'
filepath2 = '/tmp/mapnik-tiff-rgba8.tiff'
im = mapnik.Image.open(filepath1)
im.save(filepath2,'tiff')
@ -23,9 +23,9 @@ def test_tiff_rgba8_compare():
eq_(len(im.tostring()),len(im2.tostring()))
eq_(len(im.tostring('tiff')),len(im2.tostring('tiff')))
def test_tiff_uint8_compare():
filepath1 = '../data/images/24989_ndvi_uint8.tif'
filepath2 = '/tmp/mapnik-tiff-uint8.tiff'
def test_tiff_gray8_compare():
filepath1 = '../data/tiff/ndvi_256x256_gray8_striped.tif'
filepath2 = '/tmp/mapnik-tiff-gray8.tiff'
im = mapnik.Image.open(filepath1)
im.save(filepath2,'tiff')
im2 = mapnik.Image.open(filepath2)
@ -34,9 +34,9 @@ def test_tiff_uint8_compare():
eq_(len(im.tostring()),len(im2.tostring()))
eq_(len(im.tostring('tiff')),len(im2.tostring('tiff')))
def test_tiff_uint16_compare():
filepath1 = '../data/images/24989_ndvi_uint16.tif'
filepath2 = '/tmp/mapnik-tiff-uint16.tiff'
def test_tiff_gray16_compare():
filepath1 = '../data/tiff/ndvi_256x256_gray16_striped.tif'
filepath2 = '/tmp/mapnik-tiff-gray16.tiff'
im = mapnik.Image.open(filepath1)
im.save(filepath2,'tiff')
im2 = mapnik.Image.open(filepath2)
@ -45,9 +45,9 @@ def test_tiff_uint16_compare():
eq_(len(im.tostring()),len(im2.tostring()))
eq_(len(im.tostring('tiff')),len(im2.tostring('tiff')))
def test_tiff_float32_compare():
filepath1 = '../data/images/24989_ndvi_float32.tif'
filepath2 = '/tmp/mapnik-tiff-float32.tiff'
def test_tiff_gray32f_compare():
filepath1 = '../data/tiff/ndvi_256x256_gray32f_striped.tif'
filepath2 = '/tmp/mapnik-tiff-gray32f.tiff'
im = mapnik.Image.open(filepath1)
im.save(filepath2,'tiff')
im2 = mapnik.Image.open(filepath2)
@ -55,6 +55,7 @@ def test_tiff_float32_compare():
eq_(im.height(),im2.height())
eq_(len(im.tostring()),len(im2.tostring()))
eq_(len(im.tostring('tiff')),len(im2.tostring('tiff')))
if __name__ == "__main__":
setup()
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))