Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // (C) Copyright Gennadiy Rozental 2002-2008. |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | // http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | // See http://www.boost.org/libs/test for the library home page. |
| 7 | // |
| 8 | // File : $RCSfile$ |
| 9 | // |
| 10 | // Version : $Revision: 49312 $ |
| 11 | // |
| 12 | // Description : simple minimal testing definitions and implementation |
| 13 | // *************************************************************************** |
| 14 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 15 | #ifndef NDNBOOST_TEST_MINIMAL_HPP_071894GER |
| 16 | #define NDNBOOST_TEST_MINIMAL_HPP_071894GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 18 | #define NDNBOOST_CHECK(exp) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 19 | ( (exp) \ |
| 20 | ? static_cast<void>(0) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 21 | : ndnboost::minimal_test::report_error(#exp,__FILE__,__LINE__, NDNBOOST_CURRENT_FUNCTION) ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 22 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 23 | #define NDNBOOST_REQUIRE(exp) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 24 | ( (exp) \ |
| 25 | ? static_cast<void>(0) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 26 | : ndnboost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,NDNBOOST_CURRENT_FUNCTION)) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 27 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 28 | #define NDNBOOST_ERROR( msg_ ) \ |
| 29 | ndnboost::minimal_test::report_error( (msg_),__FILE__,__LINE__, NDNBOOST_CURRENT_FUNCTION, true ) |
| 30 | #define NDNBOOST_FAIL( msg_ ) \ |
| 31 | ndnboost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, NDNBOOST_CURRENT_FUNCTION, true ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 32 | |
| 33 | //____________________________________________________________________________// |
| 34 | |
| 35 | // Boost.Test |
| 36 | #include <ndnboost/test/detail/global_typedef.hpp> |
| 37 | #include <ndnboost/test/impl/execution_monitor.ipp> |
| 38 | #include <ndnboost/test/impl/debug.ipp> |
| 39 | #include <ndnboost/test/utils/class_properties.hpp> |
| 40 | #include <ndnboost/test/utils/basic_cstring/io.hpp> |
| 41 | |
| 42 | // Boost |
| 43 | #include <ndnboost/cstdlib.hpp> // for exit codes#include <ndnboost/cstdlib.hpp> // for exit codes |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 44 | #include <ndnboost/current_function.hpp> // for NDNBOOST_CURRENT_FUNCTION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 45 | |
| 46 | // STL |
| 47 | #include <iostream> // std::cerr, std::endl |
| 48 | #include <string> // std::string |
| 49 | |
| 50 | #include <ndnboost/test/detail/suppress_warnings.hpp> |
| 51 | |
| 52 | //____________________________________________________________________________// |
| 53 | |
| 54 | int test_main( int argc, char* argv[] ); // prototype for users test_main() |
| 55 | |
| 56 | namespace ndnboost { |
| 57 | namespace minimal_test { |
| 58 | |
| 59 | typedef ndnboost::unit_test::const_string const_string; |
| 60 | |
| 61 | inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; } |
| 62 | |
| 63 | inline void |
| 64 | report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) |
| 65 | { |
| 66 | ++errors_counter(); |
| 67 | std::cerr << file << "(" << line << "): "; |
| 68 | |
| 69 | if( is_msg ) |
| 70 | std::cerr << msg; |
| 71 | else |
| 72 | std::cerr << "test " << msg << " failed"; |
| 73 | |
| 74 | if( func_name != "(unknown)" ) |
| 75 | std::cerr << " in function: '" << func_name << "'"; |
| 76 | |
| 77 | std::cerr << std::endl; |
| 78 | } |
| 79 | |
| 80 | inline void |
| 81 | report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) |
| 82 | { |
| 83 | report_error( msg, file, line, func_name, is_msg ); |
| 84 | |
| 85 | throw ndnboost::execution_aborted(); |
| 86 | } |
| 87 | |
| 88 | class caller { |
| 89 | public: |
| 90 | // constructor |
| 91 | caller( int argc, char** argv ) |
| 92 | : m_argc( argc ), m_argv( argv ) {} |
| 93 | |
| 94 | // execution monitor hook implementation |
| 95 | int operator()() { return test_main( m_argc, m_argv ); } |
| 96 | |
| 97 | private: |
| 98 | // Data members |
| 99 | int m_argc; |
| 100 | char** m_argv; |
| 101 | }; // monitor |
| 102 | |
| 103 | } // namespace minimal_test |
| 104 | |
| 105 | } // namespace ndnboost |
| 106 | |
| 107 | //____________________________________________________________________________// |
| 108 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 109 | int NDNBOOST_TEST_CALL_DECL main( int argc, char* argv[] ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 110 | { |
| 111 | using namespace ndnboost::minimal_test; |
| 112 | |
| 113 | try { |
| 114 | ::ndnboost::execution_monitor ex_mon; |
| 115 | int run_result = ex_mon.execute( caller( argc, argv ) ); |
| 116 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 117 | NDNBOOST_CHECK( run_result == 0 || run_result == ndnboost::exit_success ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 118 | } |
| 119 | catch( ndnboost::execution_exception const& exex ) { |
| 120 | if( exex.code() != ndnboost::execution_exception::no_error ) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 121 | NDNBOOST_ERROR( (std::string( "exception \"" ). |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 122 | append( exex.what().begin(), exex.what().end() ). |
| 123 | append( "\" caught" ) ).c_str() ); |
| 124 | std::cerr << "\n**** Testing aborted."; |
| 125 | } |
| 126 | |
| 127 | if( ndnboost::minimal_test::errors_counter() != 0 ) { |
| 128 | std::cerr << "\n**** " << errors_counter() |
| 129 | << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n"; |
| 130 | |
| 131 | return ndnboost::exit_test_failure; |
| 132 | } |
| 133 | |
| 134 | std::cout << "\n**** no errors detected\n"; |
| 135 | |
| 136 | return ndnboost::exit_success; |
| 137 | } |
| 138 | |
| 139 | //____________________________________________________________________________// |
| 140 | |
| 141 | #include <ndnboost/test/detail/enable_warnings.hpp> |
| 142 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 143 | #endif // NDNBOOST_TEST_MINIMAL_HPP_071894GER |