ADebug.h revision 6e4c5c499999c04c2477b987f9e64f3ff2bf1a06
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),                               \
356e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber            __FILE__ ":" LITERAL_TO_STRING(__LINE__)    \
366e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber            " CHECK(" #condition ") failed.")
3772961230a5890071bcca436eb5630172ce84ec41Andreas Huber
3872961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define MAKE_COMPARATOR(suffix,op)                          \
3972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    template<class A, class B>                              \
4072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString Compare_##suffix(const A &a, const B &b) {      \
4172961230a5890071bcca436eb5630172ce84ec41Andreas Huber        AString res;                                        \
4272961230a5890071bcca436eb5630172ce84ec41Andreas Huber        if (!(a op b)) {                                    \
4372961230a5890071bcca436eb5630172ce84ec41Andreas Huber            res.append(a);                                  \
4472961230a5890071bcca436eb5630172ce84ec41Andreas Huber            res.append(" vs. ");                            \
4572961230a5890071bcca436eb5630172ce84ec41Andreas Huber            res.append(b);                                  \
4672961230a5890071bcca436eb5630172ce84ec41Andreas Huber        }                                                   \
4772961230a5890071bcca436eb5630172ce84ec41Andreas Huber        return res;                                         \
4872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    }
4972961230a5890071bcca436eb5630172ce84ec41Andreas Huber
5072961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(EQ,==)
5172961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(NE,!=)
5272961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(LE,<=)
5372961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(GE,>=)
5472961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(LT,<)
5572961230a5890071bcca436eb5630172ce84ec41Andreas HuberMAKE_COMPARATOR(GT,>)
5672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
5772961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_OP(x,y,suffix,op)                                         \
5872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    do {                                                                \
5972961230a5890071bcca436eb5630172ce84ec41Andreas Huber        AString ___res = Compare_##suffix(x, y);                        \
6072961230a5890071bcca436eb5630172ce84ec41Andreas Huber        if (!___res.empty()) {                                          \
616e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber            LOG_ALWAYS_FATAL(                                           \
626e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber                    __FILE__ ":" LITERAL_TO_STRING(__LINE__)            \
636e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber                    " CHECK_" #suffix "( " #x "," #y ") failed: %s",    \
646e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber                    ___res.c_str());                                    \
6572961230a5890071bcca436eb5630172ce84ec41Andreas Huber        }                                                               \
6672961230a5890071bcca436eb5630172ce84ec41Andreas Huber    } while (false)
6772961230a5890071bcca436eb5630172ce84ec41Andreas Huber
6872961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_EQ(x,y)   CHECK_OP(x,y,EQ,==)
6972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_NE(x,y)   CHECK_OP(x,y,NE,!=)
7072961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_LE(x,y)   CHECK_OP(x,y,LE,<=)
7172961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_LT(x,y)   CHECK_OP(x,y,LT,<)
7272961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_GE(x,y)   CHECK_OP(x,y,GE,>=)
7372961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define CHECK_GT(x,y)   CHECK_OP(x,y,GT,>)
7472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
756e4c5c499999c04c2477b987f9e64f3ff2bf1a06Andreas Huber#define TRESPASS()      LOG_ALWAYS_FATAL("Should not be here.")
7672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7772961230a5890071bcca436eb5630172ce84ec41Andreas Huber}  // namespace android
7872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#endif  // A_DEBUG_H_
8072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
81