Welcome to mirror list, hosted at ThFree Co, Russian Federation.

assert.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9146c2fcf796bfd2ba19ceacb0ca873568584606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include "base.hpp"
#include "internal/message.hpp"
#include "src_point.hpp"
#include "../std/string.hpp"
#include "../std/vector.hpp"

namespace my
{
  // Called when ASSERT, CHECK or VERIFY failed.
  typedef void (*AssertFailedFn)(SrcPoint const &, string const &);
  extern AssertFailedFn OnAssertFailed;

  /// @return Pointer to previous message function.
  AssertFailedFn SetAssertFunction(AssertFailedFn fn);
}

// TODO: Evaluate X only once in CHECK().
#define CHECK(X, msg) do { if (X) {} else { \
    ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X")", ::my::impl::Message msg));} } while(false)
#define CHECK_EQUAL(X, Y, msg) do { if ((X) == (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X" == "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_NOT_EQUAL(X, Y, msg) do { if ((X) != (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X" != "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_LESS(X, Y, msg) do { if ((X) < (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X" < "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_LESS_OR_EQUAL(X, Y, msg) do { if ((X) <= (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X" <= "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_GREATER(X, Y, msg) do { if ((X) > (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X" > "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_GREATER_OR_EQUAL(X, Y, msg) do { if ((X) >= (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X" >= "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_OR_CALL(fail, call, X, msg) do { if (X) {} else { \
  if (fail) {\
    ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg(::my::impl::Message("CHECK("#X")"), \
                                                     ::my::impl::Message msg)); \
  } else { \
    call(); \
  } } } while (false)

#ifdef DEBUG
// for Symbian compatibility
#ifdef ASSERT
#undef ASSERT
#endif
#define ASSERT(X, msg) CHECK(X, msg)
#define VERIFY(X, msg) CHECK(X, msg)
#define ASSERT_EQUAL(X, Y, msg) CHECK_EQUAL(X, Y, msg)
#define ASSERT_NOT_EQUAL(X, Y, msg) CHECK_NOT_EQUAL(X, Y, msg)
#define ASSERT_LESS(X, Y, msg) CHECK_LESS(X, Y, msg)
#define ASSERT_LESS_OR_EQUAL(X, Y, msg) CHECK_LESS_OR_EQUAL(X, Y, msg)
#define ASSERT_GREATER(X, Y, msg) CHECK_GREATER(X, Y, msg)
#define ASSERT_GREATER_OR_EQUAL(X, Y, msg) CHECK_GREATER_OR_EQUAL(X, Y, msg)
#else
// for Symbian compatibility
#ifdef ASSERT
#undef ASSERT
#endif
#define ASSERT(X, msg)
#define VERIFY(X, msg) (void)(X)
#define ASSERT_EQUAL(X, Y, msg)
#define ASSERT_NOT_EQUAL(X, Y, msg)
#define ASSERT_LESS(X, Y, msg)
#define ASSERT_LESS_OR_EQUAL(X, Y, msg)
#define ASSERT_GREATER(X, Y, msg)
#define ASSERT_GREATER_OR_EQUAL(X, Y, msg)
#endif