ADebug.h revision bc7f5b2e56107cfeaeeab13cf8979379e3c2f139
172961230a5890071bcca436eb5630172ce84ec41Andreas Huber/*
272961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Copyright (C) 2010 The Android Open Source Project
372961230a5890071bcca436eb5630172ce84ec41Andreas Huber *
472961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
572961230a5890071bcca436eb5630172ce84ec41Andreas Huber * you may not use this file except in compliance with the License.
672961230a5890071bcca436eb5630172ce84ec41Andreas Huber * You may obtain a copy of the License at
772961230a5890071bcca436eb5630172ce84ec41Andreas Huber *
872961230a5890071bcca436eb5630172ce84ec41Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
972961230a5890071bcca436eb5630172ce84ec41Andreas Huber *
1072961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Unless required by applicable law or agreed to in writing, software
1172961230a5890071bcca436eb5630172ce84ec41Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
1272961230a5890071bcca436eb5630172ce84ec41Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1372961230a5890071bcca436eb5630172ce84ec41Andreas Huber * See the License for the specific language governing permissions and
1472961230a5890071bcca436eb5630172ce84ec41Andreas Huber * limitations under the License.
1572961230a5890071bcca436eb5630172ce84ec41Andreas Huber */
1672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
1772961230a5890071bcca436eb5630172ce84ec41Andreas Huber#ifndef A_DEBUG_H_
1872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
1972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define A_DEBUG_H_
2072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
2172961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <string.h>
2272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
2372961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <media/stagefright/foundation/ABase.h>
2472961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <media/stagefright/foundation/AString.h>
256e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber#include <utils/Log.h>
2672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
2772961230a5890071bcca436eb5630172ce84ec41Andreas Hubernamespace android {
2872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
296e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber#define LITERAL_TO_STRING_INTERNAL(x)    #x
306e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber#define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)
3172961230a5890071bcca436eb5630172ce84ec41Andreas Huber
3272961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK(condition)                                \
336e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber    LOG_ALWAYS_FATAL_IF(                                \
346e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber            !(condition),                               \
35f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            "%s",                                       \
366e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber            __FILE__ ":" LITERAL_TO_STRING(__LINE__)    \
376e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber            " CHECK(" #condition ") failed.")
3872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
3972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define MAKE_COMPARATOR(suffix,op)                          \
4072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    template<class A, class B>                              \
4172961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString Compare_##suffix(const A &a, const B &b) {      \
4272961230a5890071bcca436eb5630172ce84ec41Andreas Huber        AString res;                                        \
4372961230a5890071bcca436eb5630172ce84ec41Andreas Huber        if (!(a op b)) {                                    \
4472961230a5890071bcca436eb5630172ce84ec41Andreas Huber            res.append(a);                                  \
4572961230a5890071bcca436eb5630172ce84ec41Andreas Huber            res.append(" vs. ");                            \
4672961230a5890071bcca436eb5630172ce84ec41Andreas Huber            res.append(b);                                  \
4772961230a5890071bcca436eb5630172ce84ec41Andreas Huber        }                                                   \
4872961230a5890071bcca436eb5630172ce84ec41Andreas Huber        return res;                                         \
4972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    }
5072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
5172961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(EQ,==)
5272961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(NE,!=)
5372961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(LE,<=)
5472961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(GE,>=)
5572961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(LT,<)
5672961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(GT,>)
5772961230a5890071bcca436eb5630172ce84ec41Andreas Huber
5872961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_OP(x,y,suffix,op)                                         \
5972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    do {                                                                \
6072961230a5890071bcca436eb5630172ce84ec41Andreas Huber        AString ___res = Compare_##suffix(x, y);                        \
6172961230a5890071bcca436eb5630172ce84ec41Andreas Huber        if (!___res.empty()) {                                          \
62f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            AString ___full =                                           \
63f933441648ef6a71dee783d733aac17b9508b452Andreas Huber                __FILE__ ":" LITERAL_TO_STRING(__LINE__)                \
64f933441648ef6a71dee783d733aac17b9508b452Andreas Huber                    " CHECK_" #suffix "( " #x "," #y ") failed: ";      \
65f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            ___full.append(___res);                                     \
66f933441648ef6a71dee783d733aac17b9508b452Andreas Huber                                                                        \
67f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            LOG_ALWAYS_FATAL("%s", ___full.c_str());                    \
6872961230a5890071bcca436eb5630172ce84ec41Andreas Huber        }                                                               \
6972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    } while (false)
7072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7172961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_EQ(x,y)   CHECK_OP(x,y,EQ,==)
7272961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_NE(x,y)   CHECK_OP(x,y,NE,!=)
7372961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_LE(x,y)   CHECK_OP(x,y,LE,<=)
7472961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_LT(x,y)   CHECK_OP(x,y,LT,<)
7572961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_GE(x,y)   CHECK_OP(x,y,GE,>=)
7672961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_GT(x,y)   CHECK_OP(x,y,GT,>)
7772961230a5890071bcca436eb5630172ce84ec41Andreas Huber
78bc7f5b2e56107cfeaeeab13cf8979379e3c2f139Andreas Huber#define TRESPASS() \
79bc7f5b2e56107cfeaeeab13cf8979379e3c2f139Andreas Huber        LOG_ALWAYS_FATAL(                                       \
80bc7f5b2e56107cfeaeeab13cf8979379e3c2f139Andreas Huber            __FILE__ ":" LITERAL_TO_STRING(__LINE__)            \
81bc7f5b2e56107cfeaeeab13cf8979379e3c2f139Andreas Huber                " Should not be here.");
8272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
8372961230a5890071bcca436eb5630172ce84ec41Andreas Huber}  // namespace android
8472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
8572961230a5890071bcca436eb5630172ce84ec41Andreas Huber#endif  // A_DEBUG_H_
8672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
87