/* -*- mona-c++ -*-
*
* Copyright (c) Leipzig, Madrid 2004 - 2009
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 PUcRPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdexcept>
#include <climits>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/path.hpp>
#include <mia/core/cmdlineparser.hh>
#include <mia/core/msgstream.hh>
#include <mia/core/file.hh>
NS_MIA_USE
using namespace std;
using namespace boost::unit_test;
namespace bfs = ::boost::filesystem;
extern void add_attribute_tests(test_suite* test);
extern void add_concurrence_tests(test_suite* test);
extern void add_optparam_tests(test_suite* test);
extern void add_optionparser_tests(test_suite* test);
extern void add_param_tests(test_suite* test);
extern void add_filter_tests(test_suite* test);
extern void add_handler_tests(test_suite* test);
extern void add_iohandler_tests(test_suite* test);
extern void add_spacial_kernel__tests(test_suite* test);
extern void add_pixeltype_tests(test_suite* test);
extern void add_histogram_tests(test_suite* test);
extern void add_streamredir_tests(test_suite* test);
extern void add_sqmin_tests(test_suite* test);
//extern void add_cstplan_tests(test_suite* test);
extern void add_register_tests(test_suite* test);
void test_file()
{
try {
COutputFile f("testfile");
unlink("testfile");
}
catch (...) {
BOOST_FAIL("unable to create a file for writing in current directory");
}
try {
#ifdef WIN32
CInputFile f("test-core.exe");
#else
CInputFile f("test-core");
#endif
}
catch (...) {
BOOST_FAIL("unable to open 'test-core' for reading in current directory");
}
try {
CInputFile f("this-file-should-not-exist.11111");
BOOST_FAIL("'this-file-should-not-exist.11111' was opened for reading");
}
catch (runtime_error& x) {
BOOST_MESSAGE(string("caught an expected exception:") + x.what());
}
try {
CInputFile f("/nnananan5676281/7828/1ttgfthis-file-should-not-exist.11111");
BOOST_FAIL("'/nnananan5676281/7828/1ttgf/this-file-should-not-be-created.11111' was opened for writing");
}
catch (runtime_error& x) {
BOOST_MESSAGE(string("caught an expected exception:") + x.what());
}
}
bool init_unit_test_suite()
{
cvdebug() << "init_unit_test_suite \n";
if (bfs::path::default_name_check_writable())
#if WIN32
bfs::path::default_name_check(bfs::windows_name);
#else
bfs::path::default_name_check(bfs::portable_posix_name);
#endif
#ifdef WIN32
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif
test_suite *suite = &framework::master_test_suite();
add_pixeltype_tests(suite);
add_concurrence_tests(suite);
add_attribute_tests(suite);
add_optionparser_tests(suite);
add_optparam_tests(suite);
add_param_tests(suite);
add_filter_tests(suite);
add_handler_tests(suite);
add_iohandler_tests(suite);
add_spacial_kernel__tests(suite);
add_histogram_tests(suite);
add_sqmin_tests(suite);
add_streamredir_tests(suite);
// add_cstplan_tests(suite);
add_register_tests(suite);
suite->add( BOOST_TEST_CASE( &test_file ));
return true;
}
int BOOST_TEST_CALL_DECL
main( int argc, char* argv[] )
{
CCmdOptionList().parse(argc, argv);
return ::boost::unit_test::unit_test_main( &init_unit_test_suite, argc, argv );
}