Skip to content

Commit

Permalink
add test using invalid png which leaks fd when it throws - refs mapni…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer authored and PetrDlouhy committed Aug 21, 2013
1 parent 99f7595 commit e772ad3
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions tests/cpp_tests/image_io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,66 @@ namespace sys = boost::system;

int main( int, char*[] )
{
std::string blank;
std::string should_throw;
boost::optional<std::string> 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<mapnik::image_reader> reader(mapnik::get_image_reader(blank,*type));
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
{
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<mapnik::image_reader> reader(mapnik::get_image_reader(blank,*type));
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
{
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<mapnik::image_reader> reader(mapnik::get_image_reader(blank,*type));
std::auto_ptr<mapnik::image_reader> 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<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
{
BOOST_TEST( true );
}

}
catch (std::exception const & ex)
{
Expand Down

0 comments on commit e772ad3

Please sign in to comment.