forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert.hpp
80 lines (74 loc) · 3.61 KB
/
assert.hpp
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
80
#pragma once
#include "base/base.hpp"
#include "base/internal/message.hpp"
#include "base/src_point.hpp"
#include "std/string.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::Message("CHECK("#X")", ::my::impl::Message msg));} } while(false)
#define CHECK_EQUAL(X, Y, msg) do { if ((X) == (Y)) {} else { \
::my::OnAssertFailed(SRC(), ::my::impl::Message("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::Message("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::Message("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::Message("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::Message("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::Message("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::Message(::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