COIN-OR::LEMON - Graph Library

Changes in / [135:6e7aee618f03:134:0775d2ba2afb] in lemon-1.0


Ignore:
Files:
7 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • demo/Makefile.am

    r135 r128  
    55
    66noinst_PROGRAMS += \
    7         demo/arg_parser_demo \
    8         demo/graph_to_eps_demo \
    9         demo/lgf_demo
     7        demo/arg_parser_demo \
     8        demo/graph_to_eps_demo
    109
    1110endif WANT_DEMO
    1211
    1312demo_arg_parser_demo_SOURCES = demo/arg_parser_demo.cc
     13
    1414demo_graph_to_eps_demo_SOURCES = demo/graph_to_eps_demo.cc
    15 demo_lgf_demo_SOURCES = demo/lgf_demo.cc
    1615
  • lemon/Makefile.am

    r135 r128  
    2323        lemon/bin_heap.h \
    2424        lemon/color.h \
    25         lemon/counter.h \
    2625        lemon/dfs.h \
    2726        lemon/dijkstra.h \
     
    3130        lemon/graph_utils.h \
    3231        lemon/kruskal.h \
    33         lemon/lgf_reader.h \
    3432        lemon/list_graph.h \
    3533        lemon/maps.h \
     
    3836        lemon/random.h \
    3937        lemon/smart_graph.h \
    40         lemon/time_measure.h \
    4138        lemon/tolerance.h \
    4239        lemon/unionfind.h
  • lemon/assert.h

    r118 r112  
    2727
    2828namespace lemon {
     29
     30  /// @{
     31
     32  ///\e
     33  class AssertionFailedError : public LogicError {
     34  protected:
     35    const char *_assertion;
     36    const char *_file;
     37    int _line;
     38    const char *_function;
     39    const char *_message;
     40
     41    mutable ExceptionMember<std::string> _message_holder;
     42  public:
     43    ///\e
     44    AssertionFailedError(const char *file, int line, const char *function,
     45                         const char *msg, const char *assertion = 0) :
     46      _assertion(assertion), _file(file), _line(line),
     47      _function(function), _message(msg) {}
     48
     49    ///\e
     50    const char* assertion() const { return _assertion; }
     51    ///\e
     52    const char* message() const { return _message; }
     53    ///\e
     54    const char* file() const { return _file; }
     55    ///\e
     56    const char* function() const { return _function; }
     57    ///\e
     58    int line() const { return _line; }
     59
     60
     61    virtual const char* what() const throw() {
     62      try {
     63        std::ostringstream ostr;
     64        ostr << _file << ":" << _line << ": ";
     65        if (_function)
     66          ostr << _function << ": ";
     67        ostr << _message;
     68        if (_assertion)
     69           ostr << " (assertion '" << _assertion << "' failed)";
     70        _message_holder.set(ostr.str());
     71        return ostr.str().c_str();
     72      }
     73      catch(...) {}
     74      if( _message_holder.valid() ) return _message_holder.get().c_str();
     75      return "lemon::AssertionFailedError";
     76    }
     77    virtual ~AssertionFailedError() throw() {}
     78  };
     79
     80
     81  inline void assert_fail_log(const char *file, int line,
     82                              const char *function,
     83                              const std::exception& exception,
     84                              const char *assertion)
     85  {
     86    std::cerr << file << ":" << line << ": ";
     87    if (function)
     88      std::cerr << function << ": ";
     89    std::cerr << exception.what();
     90    if (assertion)
     91      std::cerr << " (assertion '" << assertion << "' failed)";
     92    std::cerr << std::endl;
     93  }
    2994
    3095  inline void assert_fail_log(const char *file, int line, const char *function,
     
    40105  }
    41106
     107  inline void assert_fail_log(const char *file, int line, const char *function,
     108                              const std::string& message, const char *assertion)
     109  {
     110    assert_fail_log(file, line, function, message.c_str(), assertion);
     111  }
     112
     113  inline void assert_fail_abort(const char *file, int line,
     114                                const char *function,
     115                                const std::exception& exception,
     116                                const char *assertion)
     117  {
     118    assert_fail_log(file, line, function, exception, assertion);
     119    std::abort();
     120  }
     121
    42122  inline void assert_fail_abort(const char *file, int line,
    43123                                const char *function, const char* message,
     
    48128  }
    49129
    50   namespace _assert_bits {
    51    
    52    
    53     inline const char* cstringify(const std::string& str) {
    54       return str.c_str();
    55     }
    56 
    57     inline const char* cstringify(const char* str) {
    58       return str;
    59     }   
    60   }
     130  inline void assert_fail_abort(const char *file, int line,
     131                                const char *function,
     132                                const std::string& message,
     133                                const char *assertion)
     134  {
     135    assert_fail_log(file, line, function, message.c_str(), assertion);
     136    std::abort();
     137  }
     138
     139  inline void assert_fail_error(const char *file, int line,
     140                                  const char *function,
     141                                  const std::exception& exception,
     142                                  const char *assertion)
     143  {
     144    throw AssertionFailedError(file, line, function,
     145                               exception.what(), assertion);
     146  }
     147
     148  inline void assert_fail_error(const char *file, int line,
     149                                  const char *function, const char *message,
     150                                  const char *assertion)
     151  {
     152    throw AssertionFailedError(file, line, function, message, assertion);
     153  }
     154
     155  inline void assert_fail_error(const char *file, int line,
     156                                  const char *function,
     157                                  const std::string& message,
     158                                  const char *assertion)
     159  {
     160    throw AssertionFailedError(file, line, function, message.c_str(), assertion);
     161  }
     162
     163  template <typename Exception>
     164  inline void assert_fail_exception(const char *, int, const char *,
     165                                    const Exception& exception,
     166                                    const char *, const std::exception* =
     167                                    static_cast<const Exception*>(0))
     168  {
     169    throw exception;
     170  }
     171
     172  inline void assert_fail_exception(const char *file, int line,
     173                                    const char *function, const char *message,
     174                                    const char *assertion)
     175  {
     176    throw AssertionFailedError(file, line, function, message, assertion);
     177  }
     178
     179  inline void assert_fail_exception(const char *file, int line,
     180                                    const char *function,
     181                                    const std::string& message,
     182                                    const char *assertion)
     183  {
     184    throw AssertionFailedError(file, line, function, message.c_str(), assertion);
     185  }
     186
     187/// @}
     188
    61189}
    62 
    63190#endif // LEMON_ASSERT_H
    64191
    65192#undef LEMON_ASSERT
    66193#undef LEMON_FIXME
    67 #undef LEMON_DEBUG
    68194
    69195#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) +               \
    70196  (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +               \
     197  (defined(LEMON_ASSERT_ERROR) ? 1 : 0) +               \
     198  (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +           \
    71199  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
    72200#error "LEMON assertion system is not set properly"
     
    75203#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +              \
    76204     (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +            \
     205     (defined(LEMON_ASSERT_ERROR) ? 1 : 0) +            \
     206     (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +        \
    77207     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||     \
    78208     defined(LEMON_ENABLE_ASSERTS)) &&                  \
    79   (defined(LEMON_DISABLE_ASSERTS) ||                    \
    80    defined(NDEBUG))
     209  defined(LEMON_DISABLE_ASSERTS)
    81210#error "LEMON assertion system is not set properly"
    82211#endif
     
    89218#  undef LEMON_ASSERT_HANDLER
    90219#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
     220#elif defined LEMON_ASSERT_ERROR
     221#  undef LEMON_ASSERT_HANDLER
     222#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_error
     223#elif defined LEMON_ASSERT_EXCEPTION
     224#  undef LEMON_ASSERT_HANDLER
     225#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
    91226#elif defined LEMON_ASSERT_CUSTOM
    92227#  undef LEMON_ASSERT_HANDLER
     
    95230#  endif
    96231#  define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER
    97 #elif defined LEMON_DISABLE_ASSERTS
    98 #  undef LEMON_ASSERT_HANDLER
    99 #elif defined NDEBUG
    100 #  undef LEMON_ASSERT_HANDLER
     232#elif defined LEMON_ENABLE_ASSERTS
     233#  undef LEMON_ASSERT_HANDLER
     234#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
    101235#else
    102 #  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
    103 #endif
     236#  undef LEMON_ASSERT_HANDLER
     237#endif
     238
    104239
    105240#ifndef LEMON_FUNCTION_NAME
     
    113248/// \brief Macro for assertion with customizable message
    114249///
    115 /// Macro for assertion with customizable message.  \param exp An
    116 /// expression that must be convertible to \c bool.  If it is \c
    117 /// false, then an assertion is raised. The concrete behaviour depends
    118 /// on the settings of the assertion system.  \param msg A <tt>const
    119 /// char*</tt> parameter, which can be used to provide information
    120 /// about the circumstances of the failed assertion.
    121 ///
    122 /// The assertions are enabled in the default behaviour.
    123 /// You can disable them with the following code:
     250/// Macro for assertion with customizable message. 
     251/// \param exp An expression that must be convertible to \c bool.
     252/// If it is \c false, then an assertion is raised. The concrete
     253/// behaviour depends on the settings of the assertion system.
     254/// \param msg A <tt>const char*</tt>, a <tt>const std::string&</tt> or
     255/// a <tt>const std::exception&</tt> parameter, which can be used to
     256/// provide information about the circumstances of the failed assertion.
     257///
     258/// The assertions are disabled in the default behaviour.
     259/// You can enable them with the following code:
    124260/// \code
    125 /// #define LEMON_DISABLE_ASSERTS
     261/// #define LEMON_ENABLE_ASSERTS
    126262/// \endcode
    127263/// or with compilation parameters:
    128264/// \code
    129 /// g++ -DLEMON_DISABLE_ASSERTS
    130 /// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS'
     265/// g++ -DLEMON_ENABLE_ASSERTS
     266/// make CXXFLAGS='-DLEMON_ENABLE_ASSERTS'
    131267/// \endcode
    132 /// The checking is also disabled when the standard macro \c NDEBUG is defined.
    133268///
    134269/// The LEMON assertion system has a wide range of customization
     
    140275/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
    141276///   message to the standard error and continues the execution.
    142 /// - \c LEMON_ASSERT_ABORT This mode is similar to the \c
    143 ///   LEMON_ASSERT_LOG, but it aborts the program. It is the default
    144 ///   behaviour.
     277/// - \c LEMON_ASSERT_ABORT This mode is similar to the
     278///   \c LEMON_ASSERT_LOG, but it aborts the program. It is the default
     279///   behaviour mode when the assertions are enabled with
     280///   \c LEMON_ENABLE_ASSERTS.
     281/// - \c LEMON_ASSERT_ERROR The assertion throws an
     282///   \ref lemon::AssertionFailedError "AssertionFailedError".
     283///   If the \c msg parameter is an exception, then the result of the
     284///   \ref lemon::Exception::what() "what()" member function is passed
     285///   as error message.
     286/// - \c LEMON_ASSERT_EXCEPTION If the specified \c msg is an
     287///   exception, then it raised directly (solving that the exception
     288///   can not be thrown polymorphically), otherwise an \ref
     289///   lemon::AssertionFailedError "AssertionFailedError" is thrown with
     290///   the given parameters.
    145291/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
    146 ///   function.
     292///   functions. Three overloaded functions should be defined with the
     293///   following parameter lists:
    147294///   \code
    148295///     void custom_assert_handler(const char* file, int line, const char* function,
    149296///                                const char* message, const char* assertion);
     297///     void custom_assert_handler(const char* file, int line, const char* function,
     298///                                const std::string& message, const char* assertion);
     299///     void custom_assert_handler(const char* file, int line, const char* function,
     300///                                const std::exception& message, const char* assertion);
    150301///   \endcode
    151 ///   The name of the function should be defined as the \c
     302///   The name of the functions should be defined as the \c
    152303///   LEMON_CUSTOM_ASSERT_HANDLER macro name.
    153304///   \code
    154305///     #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
    155306///   \endcode
    156 ///   Whenever an assertion is occured, the custom assertion
    157 ///   handler is called with appropiate parameters.
     307///   Whenever an assertion is occured, one of the custom assertion
     308///   handlers is called with appropiate parameters.
    158309///
    159310/// The assertion mode can also be changed within one compilation unit.
     
    165316    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
    166317                         LEMON_FUNCTION_NAME,                           \
    167                          ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
     318                         msg, #exp), 0)))
     319
    168320
    169321/// \ingroup exceptions
     
    176328///   LEMON_ASSERT(false, msg);
    177329/// \endcode
    178 ///
    179 /// \see LEMON_ASSERT
    180330#  define LEMON_FIXME(msg)                                              \
    181   (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,        \
    182                         ::lemon::_assert_bits::cstringify(msg),         \
    183                         static_cast<const char*>(0)))
    184 
    185 /// \ingroup exceptions
    186 ///
    187 /// \brief Macro for internal assertions
    188 ///
    189 /// Macro for internal assertions, it is used in the library to check
    190 /// the consistency of results of algorithms, several pre- and
    191 /// postconditions and invariants. The checking is disabled by
    192 /// default, but it can be turned on with the macro \c
    193 /// LEMON_ENABLE_DEBUG.
    194 /// \code
    195 /// #define LEMON_ENABLE_DEBUG
    196 /// \endcode
    197 /// or with compilation parameters:
    198 /// \code
    199 /// g++ -DLEMON_ENABLE_DEBUG
    200 /// make CXXFLAGS='-DLEMON_ENABLE_DEBUG'
    201 /// \endcode
    202 ///
    203 /// This macro works like the \c LEMON_ASSERT macro, therefore the
    204 /// current behaviour depends on the settings of \c LEMON_ASSERT
    205 /// macro.
    206 ///
    207 /// \see LEMON_ASSERT
    208 #  define LEMON_DEBUG(exp, msg)                                         \
    209   (static_cast<void> (!!(exp) ? 0 : (                                   \
    210     LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
    211                          LEMON_FUNCTION_NAME,                           \
    212                          ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
     331       (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,   \
     332                             "FIXME: " msg, static_cast<const char*>(0)))
    213333
    214334#else
     
    217337#    define LEMON_ASSERT(exp, msg)  (static_cast<void>(0))
    218338#    define LEMON_FIXME(msg) (static_cast<void>(0))
    219 #    define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
    220339#  else
    221 #    define LEMON_ASSERT(exp, msg)                                      \
    222        (static_cast<void> (!!(exp) ? 0 : (                              \
    223         LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                        \
    224                              LEMON_FUNCTION_NAME,                       \
    225                              ::lemon::_assert_bits::cstringify(msg),    \
    226                              #exp), 0)))
    227 #    define LEMON_FIXME(msg)                                            \
     340#    define LEMON_ASSERT(exp, msg)                 \
     341       (static_cast<void> (!!(exp) ? 0 : (         \
     342         LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
     343                              LEMON_FUNCTION_NAME, \
     344                              msg, #exp), 0)))
     345#    define LEMON_FIXME(msg) \
    228346       (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,   \
    229                              ::lemon::_assert_bits::cstringify(msg),    \
    230                              static_cast<const char*>(0)))
    231 
    232 #    if LEMON_ENABLE_DEBUG
    233 #      define LEMON_DEBUG(exp, msg)
    234          (static_cast<void> (!!(exp) ? 0 : (         \
    235            LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
    236                                 LEMON_FUNCTION_NAME, \
    237                                 ::lemon::_assert_bits::cstringify(msg), \
    238                                 #exp), 0)))
    239 #    else
    240 #      define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
    241 #    endif
     347                             "FIXME: " msg,  static_cast<const char*>(0)))
    242348#  endif
    243349
    244350#endif
    245351
    246 #ifdef DOXYGEN
    247 
    248 
    249 #else
    250 
    251 
    252 #endif
    253 
    254 
     352
  • lemon/bits/graph_extender.h

    r125 r107  
    368368
    369369    Node oppositeNode(const Node &n, const Edge &e) const {
    370       if( n == Parent::u(e))
    371         return Parent::v(e);
    372       else if( n == Parent::v(e))
    373         return Parent::u(e);
     370      if( n == Parent::source(e))
     371        return Parent::target(e);
     372      else if( n == Parent::target(e))
     373        return Parent::source(e);
    374374      else
    375375        return INVALID;
     
    382382    using Parent::direct;
    383383    Arc direct(const Edge &edge, const Node &node) const {
    384       return Parent::direct(edge, Parent::u(edge) == node);
     384      return Parent::direct(edge, Parent::source(edge) == node);
    385385    }
    386386
     
    587587    /// Returns the base node of the iterator
    588588    Node baseNode(const IncEdgeIt &edge) const {
    589       return edge._direction ? u(edge) : v(edge);
     589      return edge._direction ? source(edge) : target(edge);
    590590    }
    591591    /// Running node of the iterator
     
    593593    /// Returns the running node of the iterator
    594594    Node runningNode(const IncEdgeIt &edge) const {
    595       return edge._direction ? v(edge) : u(edge);
     595      return edge._direction ? target(edge) : source(edge);
    596596    }
    597597
  • lemon/bits/utility.h

    r117 r39  
    2222// Boost enable_if library
    2323
    24 // Copyright 2003 (c) The Trustees of Indiana University.
     24// Copyright 2003 © The Trustees of Indiana University.
    2525
    2626// Use, modification, and distribution is subject to the Boost Software
     
    2828// http://www.boost.org/LICENSE_1_0.txt)
    2929
    30 //    Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
     30//    Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
    3131//             Jeremiah Willcock (jewillco at osl.iu.edu)
    3232//             Andrew Lumsdaine (lums at osl.iu.edu)
  • lemon/concepts/digraph.h

    r125 r107  
    468468      };
    469469
    470       template <typename _Digraph>
     470      template <typename RDigraph>
    471471      struct Constraints {
    472472        void constraints() {
    473           checkConcept<IterableDigraphComponent<>, _Digraph>();
    474           checkConcept<IDableDigraphComponent<>, _Digraph>();
    475           checkConcept<MappableDigraphComponent<>, _Digraph>();
     473          checkConcept<IterableDigraphComponent<>, Digraph>();
     474          checkConcept<IDableDigraphComponent<>, Digraph>();
     475          checkConcept<MappableDigraphComponent<>, Digraph>();
    476476        }
    477477      };
  • lemon/concepts/graph.h

    r125 r107  
    732732      }
    733733
    734       template <typename _Graph>
     734      template <typename Graph>
    735735      struct Constraints {
    736736        void constraints() {
    737           checkConcept<IterableGraphComponent<>, _Graph>();
    738           checkConcept<IDableGraphComponent<>, _Graph>();
    739           checkConcept<MappableGraphComponent<>, _Graph>();
     737          checkConcept<IterableGraphComponent<>, Graph>();
     738          checkConcept<IDableGraphComponent<>, Graph>();
     739          checkConcept<MappableGraphComponent<>, Graph>();
    740740        }
    741741      };
  • lemon/maps.h

    r123 r104  
    117117
    118118    /// Constructor with specified initial value.
    119     /// \param v The initial value of the map.
     119    /// \param v is the initial value of the map.
    120120    ConstMap(const Value &v) : _value(v) {}
    121121
     
    142142  inline ConstMap<K, V> constMap(const V &v) {
    143143    return ConstMap<K, V>(v);
    144   }
    145 
    146   template<typename K, typename V>
    147   inline ConstMap<K, V> constMap() {
    148     return ConstMap<K, V>();
    149144  }
    150145
     
    619614           typename V = typename F::result_type>
    620615  class FunctorToMap : public MapBase<K, V> {
    621     F _f;
     616    const F &_f;
    622617  public:
    623618    typedef MapBase<K, V> Parent;
  • lemon/random.h

    r116 r110  
    796796          }
    797797      } while(nu>std::pow(xi,delta-1.0)*std::exp(-xi));
    798       return theta*(xi+gamma(int(std::floor(k))));
     798      return theta*(xi-gamma(int(std::floor(k))));
    799799    }
    800800   
     
    820820    double pareto(double k,double x_min)
    821821    {
    822       return exponential(gamma(k,1.0/x_min))+x_min;
     822      return exponential(gamma(k,1.0/x_min));
    823823    } 
    824824     
  • lemon/smart_graph.h

    r125 r109  
    471471    Node target(Arc e) const { return Node(arcs[e._id].target); }
    472472
    473     Node u(Edge e) const { return Node(arcs[2 * e._id].target); }
    474     Node v(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
     473    Node source(Edge e) const { return Node(arcs[2 * e._id].target); }
     474    Node target(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
    475475
    476476    static bool direction(Arc e) {
  • test/Makefile.am

    r119 r108  
    1010check_PROGRAMS += \
    1111        test/bfs_test \
    12         test/counter_test \
    1312        test/dfs_test \
    1413        test/digraph_test \
     
    2221        test/test_tools_fail \
    2322        test/test_tools_pass \
    24         test/time_measure_test \
    2523        test/unionfind_test
    2624
     
    2927
    3028test_bfs_test_SOURCES = test/bfs_test.cc
    31 test_counter_test_SOURCES = test/counter_test.cc
    3229test_dfs_test_SOURCES = test/dfs_test.cc
    3330test_digraph_test_SOURCES = test/digraph_test.cc
     
    4239test_test_tools_fail_SOURCES = test/test_tools_fail.cc
    4340test_test_tools_pass_SOURCES = test/test_tools_pass.cc
    44 test_time_measure_test_SOURCES = test/time_measure_test.cc
    4541test_unionfind_test_SOURCES = test/unionfind_test.cc
  • test/error_test.cc

    r118 r108  
    4040}
    4141
     42void no_assertion_exception_disable() {
     43  LEMON_ASSERT(true, Exception());
     44}
     45
    4246void assertion_text_disable() {
    4347  LEMON_ASSERT(false, "This is a fault message");
     48}
     49
     50void assertion_exception_disable() {
     51  LEMON_ASSERT(false, Exception());
    4452}
    4553
     
    5058void check_assertion_disable() {
    5159  no_assertion_text_disable();
     60  no_assertion_exception_disable();
     61  assertion_exception_disable();
    5262  assertion_text_disable();
    5363  fixme_disable();
    5464}
    5565#undef LEMON_DISABLE_ASSERTS
     66
     67
     68#define LEMON_ASSERT_ERROR
     69#include <lemon/assert.h>
     70
     71void no_assertion_text_error() {
     72  LEMON_ASSERT(true, "This is a fault message");
     73}
     74
     75void no_assertion_exception_error() {
     76  LEMON_ASSERT(true, Exception());
     77}
     78
     79void assertion_text_error() {
     80  LEMON_ASSERT(false, "This is a fault message");
     81}
     82
     83void assertion_exception_error() {
     84  LEMON_ASSERT(false, Exception());
     85}
     86
     87void fixme_error() {
     88  LEMON_FIXME("fixme_error() is fixme!");
     89}
     90
     91void check_assertion_error() {
     92  no_assertion_text_error();
     93  no_assertion_exception_error();
     94  try {
     95    assertion_exception_error();
     96    check(false, "Assertion error");
     97  } catch (const AssertionFailedError& e) {
     98  }
     99
     100  try {
     101    assertion_text_error();
     102    check(false, "Assertion error");
     103  } catch (const AssertionFailedError& e) {
     104  }
     105
     106  try {
     107    fixme_error();
     108    check(false, "Assertion error");
     109  } catch (const AssertionFailedError& e) {
     110  }
     111}
     112#undef LEMON_ASSERT_ERROR
     113
     114#define LEMON_ASSERT_EXCEPTION
     115#include <lemon/assert.h>
     116
     117void no_assertion_text_exception() {
     118  LEMON_ASSERT(true, "This is a fault message");
     119}
     120
     121void no_assertion_exception_exception() {
     122  LEMON_ASSERT(true, Exception());
     123}
     124
     125void assertion_text_exception() {
     126  LEMON_ASSERT(false, "This is a fault message");
     127}
     128
     129void assertion_exception_exception() {
     130  LEMON_ASSERT(false, Exception());
     131}
     132
     133void fixme_exception() {
     134  LEMON_FIXME("fixme_exception() is fixme!");
     135}
     136
     137void check_assertion_exception() {
     138  no_assertion_text_exception();
     139  no_assertion_exception_exception();
     140  try {
     141    assertion_exception_exception();
     142    check(false, "Assertion error");
     143  } catch (const Exception& e) {
     144  }
     145
     146  try {
     147    assertion_text_exception();
     148    check(false, "Assertion error");
     149  } catch (const AssertionFailedError& e) {
     150  }
     151
     152  try {
     153    assertion_text_exception();
     154    check(false, "Assertion error");
     155  } catch (const AssertionFailedError& e) {
     156  }
     157
     158  try {
     159    fixme_exception();
     160    check(false, "Assertion error");
     161  } catch (const AssertionFailedError& e) {
     162  }
     163}
     164#undef LEMON_ASSERT_EXCEPTION
     165
     166#define LEMON_ASSERT_LOG
     167
     168#include <lemon/assert.h>
     169
     170void no_assertion_text_log() {
     171  LEMON_ASSERT(true, "This is a fault message");
     172}
     173
     174void no_assertion_exception_log() {
     175  LEMON_ASSERT(true, Exception());
     176}
     177
     178void assertion_text_log() {
     179  LEMON_ASSERT(false, "This is a fault message");
     180}
     181
     182void assertion_exception_log() {
     183  LEMON_ASSERT(false, Exception());
     184}
     185
     186void fixme_log() {
     187  LEMON_FIXME("fixme_log() is fixme!");
     188}
     189
     190void check_assertion_log() {
     191  no_assertion_text_log();
     192  no_assertion_exception_log();
     193  std::cerr << "The next 3 failure messages are expected: " << std::endl;
     194  assertion_exception_log();
     195  assertion_text_log();
     196  fixme_log();
     197  std::cerr << "End of expected error messages" << std::endl;
     198}
     199#undef LEMON_ASSERT_LOG
    56200
    57201#define LEMON_ASSERT_CUSTOM
     
    63207}
    64208
     209void my_assert_handler(const char*, int, const char*,
     210                       const std::exception&, const char*) {
     211  ++cnt;
     212}
     213
     214void my_assert_handler(const char*, int, const char*,
     215                       const std::string&, const char*) {
     216  ++cnt;
     217}
     218
     219
    65220#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler
    66221#include <lemon/assert.h>
     
    70225}
    71226
     227void no_assertion_exception_custom() {
     228  LEMON_ASSERT(true, Exception());
     229}
     230
    72231void assertion_text_custom() {
    73232  LEMON_ASSERT(false, "This is a fault message");
     233}
     234
     235void assertion_exception_custom() {
     236  LEMON_ASSERT(false, Exception());
    74237}
    75238
     
    80243void check_assertion_custom() {
    81244  no_assertion_text_custom();
     245  no_assertion_exception_custom();
     246  assertion_exception_custom();
    82247  assertion_text_custom();
    83248  fixme_custom();
    84   check(cnt == 2, "The custom assert handler does not work");
     249  check(cnt == 3, "The custom assert handler does not work");
    85250}
    86251
     
    90255int main() {
    91256  check_assertion_disable();
     257  check_assertion_error();
     258  check_assertion_exception();
     259  check_assertion_log();
    92260  check_assertion_custom();
    93261
  • test/maps_test.cc

    r123 r94  
    8484  {
    8585    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    86     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    8786    ConstMap<A,B> map1;
    8887    ConstMap<A,B> map2(B());
    8988    ConstMap<A,B> map3 = map1;
    9089    map1 = constMap<A>(B());
    91     map1 = constMap<A,B>();
    9290    map1.setAll(B());
    93     ConstMap<A,C> map4(C(1));
    94     ConstMap<A,C> map5 = map4;
    95     map4 = constMap<A>(C(2));
    96     map4.setAll(C(3));
    9791
    9892    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
     
    10094
    10195    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
    102     ConstMap<A,Const<int,10> > map6;
    103     ConstMap<A,Const<int,10> > map7 = map6;
    104     map6 = constMap<A,int,10>();
    105     map7 = constMap<A,Const<int,10> >();
    106     check(map6[A()] == 10 && map7[A()] == 10, "Something is wrong with ConstMap");
     96    ConstMap<A,Const<int,10> > map4;
     97    ConstMap<A,Const<int,10> > map5 = map4;
     98    map4 = map5;
     99    check(map4[A()] == 10 && map5[A()] == 10, "Something is wrong with ConstMap");
    107100  }
    108101
Note: See TracChangeset for help on using the changeset viewer.