// Copyright (c) 2005-2006 Hartmut Kaiser (hartmut.kaiser@gmail.com) // Copyright (c) 2005-2006 Andre Merzky (andre@merzky.net) // Copyright (c) 2005-2006 Chris Miceli (cmicel1@cct.lsu.edu) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include "test_tempfile_helpers.hpp" #include "test_saga.hpp" #include #include #if !defined(SAGA_TEST_API_HPP) #define SAGA_TEST_API_HPP #define SAGA_REQUIRE_THROW(M, E) { \ try { \ M; } \ catch (const saga::exception &e) { \ BOOST_CHECK_EQUAL(E, e.get_error()); \ } } \ struct PlainSync {}; typedef boost::mpl::vector apitypes; namespace test_api { // call_test that is instantiated with the test to be run and // a specific error code: (normal result expected, Success) template struct call_test; template struct call_test > { call_test(saga::session s, saga::test::test_helper_utils *utils) : s_(s), utils_(utils) {} template void operator()(Tag) { //Call test with first file from vector, //Should run normally w/ no exceptions thrown. std::string file(utils_->create_temp_file_for_exception(saga::Success)); Functor().test(s_, file, Tag()); } saga::session s_; saga::test::test_helper_utils *utils_; }; // call_test that is instantiated with the test to be run and // a generic error code template struct call_test { call_test(saga::session s, saga::test::test_helper_utils *utils) : s_(s), utils_(utils) {} template void operator()(Tag) { //Call test with appropriate file from vector //to throw appropriate exception std::string file(utils_->create_temp_file_for_exception(static_cast(E::value))); typedef int (*ftype)(saga::session, std::string, Tag); SAGA_REQUIRE_THROW(Functor().test(s_, file, Tag()), E::value) std::cout << "Tests: " << Functor::name << " with file " << file << std::endl; } saga::session s_; saga::test::test_helper_utils *utils_; }; // api_test gets instantiated with test to be run as TestFunctor and // and error code as Error template struct api_test { api_test(saga::session s, saga::test::test_helper_utils *utils) : s_(s), utils_(utils) {} template void operator()(Error) { boost::mpl::for_each(call_test(s_, utils_)); } saga::session s_; saga::test::test_helper_utils *utils_; }; // run_test gets instantiated with test to be run template struct run_test { static void execute(saga::test::test_helper_utils *utils_) { saga::session s_; boost::mpl::for_each(api_test(s_, utils_)); } }; } // test_api #endif // !SAGA_TEST_FILE_HPP