diff --git a/modules/io/tests/CMakeLists.txt b/modules/io/tests/CMakeLists.txt index 9ac4ba1342db1995749b5cce02a1c89fa278b536..64a31041525e12f4c1c0bc2ba906284b1a424a5e 100644 --- a/modules/io/tests/CMakeLists.txt +++ b/modules/io/tests/CMakeLists.txt @@ -15,6 +15,7 @@ set(OST_IO_UNIT_TESTS ) if (ENABLE_IMG) list(APPEND OST_IO_UNIT_TESTS test_io_img.cc) + list(APPEND OST_IO_UNIT_TESTS test_exceptions.cc) endif() ost_unittest(MODULE io SOURCES "${OST_IO_UNIT_TESTS}" diff --git a/modules/io/tests/test_exceptions.cc b/modules/io/tests/test_exceptions.cc new file mode 100644 index 0000000000000000000000000000000000000000..2ed51ce3e61239424f4d3ce8b9ce2f77a3825b24 --- /dev/null +++ b/modules/io/tests/test_exceptions.cc @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ + +/* + Author: Andreas Schenk + */ + +#define BOOST_TEST_DYN_LINK +#include <boost/test/unit_test.hpp> +#include <boost/test/auto_unit_test.hpp> + +#include <ost/io/load_map.hh> +#include <ost/img/image.hh> +#include <ost/io/io_exception.hh> + +using namespace ost; +using namespace ost::io; + + +BOOST_AUTO_TEST_SUITE( io ); + + +BOOST_AUTO_TEST_CASE(exception) +{ + try { + BOOST_CHECK_THROW(ost::img::ImageHandle loadedimage=LoadImage("nonexistent.mrc"),IOException); + }catch(...){ + BOOST_ERROR( "Failed to catch IOException." ); + } + ost::img::ImageHandle ih=ost::img::CreateImage(); + try { + BOOST_CHECK_THROW(SaveImage(ih,"nonexistent.ABC"),IOUnknownFormatException); + }catch(...){ + BOOST_ERROR( "Failed to catch IOUnknownFormatException." ); + } +} + +BOOST_AUTO_TEST_SUITE_END();