Line data Source code
1 : /*
2 : * Copyright (C) 2010 The Android Open Source Project
3 : *
4 : * Licensed under the Apache License, Version 2.0 (the "License");
5 : * you may not use this file except in compliance with the License.
6 : * You may obtain a copy of the License at
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
10 : * Unless required by applicable law or agreed to in writing, software
11 : * distributed under the License is distributed on an "AS IS" BASIS,
12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : * See the License for the specific language governing permissions and
14 : * limitations under the License.
15 : */
16 :
17 : #ifndef A_DEBUG_H_
18 :
19 : #define A_DEBUG_H_
20 :
21 : #include <string.h>
22 :
23 : #include <media/stagefright/foundation/ABase.h>
24 : #include <media/stagefright/foundation/AString.h>
25 : #include <utils/Log.h>
26 :
27 : namespace stagefright {
28 :
29 : #define LITERAL_TO_STRING_INTERNAL(x) #x
30 : #define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)
31 :
32 : #define CHECK(condition) \
33 : LOG_ALWAYS_FATAL_IF( \
34 : !(condition), \
35 : "%s", \
36 : __FILE__ ":" LITERAL_TO_STRING(__LINE__) \
37 : " CHECK(" #condition ") failed.")
38 :
39 : #define MAKE_COMPARATOR(suffix,op) \
40 : template<class A, class B> \
41 : AString Compare_##suffix(const A &a, const B &b) { \
42 : AString res; \
43 : if (!(a op b)) { \
44 : res.append(a); \
45 : res.append(" vs. "); \
46 : res.append(b); \
47 : } \
48 : return res; \
49 : }
50 :
51 0 : MAKE_COMPARATOR(EQ,==)
52 0 : MAKE_COMPARATOR(NE,!=)
53 0 : MAKE_COMPARATOR(LE,<=)
54 0 : MAKE_COMPARATOR(GE,>=)
55 0 : MAKE_COMPARATOR(LT,<)
56 0 : MAKE_COMPARATOR(GT,>)
57 :
58 : #define CHECK_OP(x,y,suffix,op) \
59 : do { \
60 : AString ___res = Compare_##suffix(x, y); \
61 : if (!___res.empty()) { \
62 : AString ___full = \
63 : __FILE__ ":" LITERAL_TO_STRING(__LINE__) \
64 : " CHECK_" #suffix "( " #x "," #y ") failed: "; \
65 : ___full.append(___res); \
66 : \
67 : LOG_ALWAYS_FATAL("%s", ___full.c_str()); \
68 : } \
69 : } while (false)
70 :
71 : #define CHECK_EQ(x,y) CHECK_OP(x,y,EQ,==)
72 : #define CHECK_NE(x,y) CHECK_OP(x,y,NE,!=)
73 : #define CHECK_LE(x,y) CHECK_OP(x,y,LE,<=)
74 : #define CHECK_LT(x,y) CHECK_OP(x,y,LT,<)
75 : #define CHECK_GE(x,y) CHECK_OP(x,y,GE,>=)
76 : #define CHECK_GT(x,y) CHECK_OP(x,y,GT,>)
77 :
78 : #define TRESPASS() \
79 : LOG_ALWAYS_FATAL( \
80 : __FILE__ ":" LITERAL_TO_STRING(__LINE__) \
81 : " Should not be here.");
82 :
83 : } // namespace stagefright
84 :
85 : #endif // A_DEBUG_H_
86 :
|