From e772ad38003069d8e13947982f6b7b8ef96d360a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 7 Apr 2013 23:43:34 -0700 Subject: [PATCH] add test using invalid png which leaks fd when it throws - refs #1783 --- tests/cpp_tests/image_io_test.cpp | 41 +++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tests/cpp_tests/image_io_test.cpp b/tests/cpp_tests/image_io_test.cpp index f42718d85e..ea51b1d700 100644 --- a/tests/cpp_tests/image_io_test.cpp +++ b/tests/cpp_tests/image_io_test.cpp @@ -12,17 +12,17 @@ namespace sys = boost::system; int main( int, char*[] ) { - std::string blank; + std::string should_throw; boost::optional type; try { - blank = "./tests/cpp_tests/data/blank.jpg"; - BOOST_TEST( fs::exists( blank ) ); - type = mapnik::type_from_filename(blank); + should_throw = "./tests/cpp_tests/data/blank.jpg"; + BOOST_TEST( fs::exists( should_throw ) ); + type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { - std::auto_ptr reader(mapnik::get_image_reader(blank,*type)); + std::auto_ptr reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) @@ -30,13 +30,13 @@ int main( int, char*[] ) BOOST_TEST( true ); } - blank = "./tests/cpp_tests/data/blank.png"; - BOOST_TEST( fs::exists( blank ) ); - type = mapnik::type_from_filename(blank); + should_throw = "./tests/cpp_tests/data/blank.png"; + BOOST_TEST( fs::exists( should_throw ) ); + type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { - std::auto_ptr reader(mapnik::get_image_reader(blank,*type)); + std::auto_ptr reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) @@ -44,19 +44,34 @@ int main( int, char*[] ) BOOST_TEST( true ); } - blank = "./tests/cpp_tests/data/blank.tiff"; - BOOST_TEST( fs::exists( blank ) ); - type = mapnik::type_from_filename(blank); + should_throw = "./tests/cpp_tests/data/blank.tiff"; + BOOST_TEST( fs::exists( should_throw ) ); + type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { - std::auto_ptr reader(mapnik::get_image_reader(blank,*type)); + std::auto_ptr reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) { BOOST_TEST( true ); } + + should_throw = "./tests/data/images/xcode-CgBI.png"; + BOOST_TEST( fs::exists( should_throw ) ); + type = mapnik::type_from_filename(should_throw); + BOOST_TEST( type ); + try + { + std::auto_ptr reader(mapnik::get_image_reader(should_throw,*type)); + BOOST_TEST( false ); + } + catch (std::exception const&) + { + BOOST_TEST( true ); + } + } catch (std::exception const & ex) {