From 9fc8c0aa0dc469e177065c80f4333da27797ecf8 Mon Sep 17 00:00:00 2001 From: Andreas Schenk <andreas_schenk@hms.harvard.edu> Date: Tue, 10 Jul 2012 13:42:16 -0400 Subject: [PATCH] added tests for io exceptions --- modules/io/tests/CMakeLists.txt | 1 + modules/io/tests/test_exceptions.cc | 54 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 modules/io/tests/test_exceptions.cc diff --git a/modules/io/tests/CMakeLists.txt b/modules/io/tests/CMakeLists.txt index 9ac4ba134..64a310415 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 000000000..2ed51ce3e --- /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(); -- GitLab