15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Macros specific to the RLZ library.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef RLZ_LIB_ASSERT_H_
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_LIB_ASSERT_H_
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An assertion macro.
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Can mute expected assertions in debug mode.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASSERT_STRING
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  #ifndef MUTE_EXPECTED_ASSERTS
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    #define ASSERT_STRING(expr) LOG_IF(FATAL, false) << (expr)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  #else
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    #define ASSERT_STRING(expr) \
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      do { \
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        std::string expr_string(expr); \
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (rlz_lib::expected_assertion_ != expr_string) { \
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          LOG_IF(FATAL, false) << (expr); \
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        } \
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      } while (0)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  #endif
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef VERIFY
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  #ifdef _DEBUG
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    #define VERIFY(expr) LOG_IF(FATAL, !(expr)) << #expr
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  #else
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    #define VERIFY(expr) (void)(expr)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  #endif
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace rlz_lib {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef MUTE_EXPECTED_ASSERTS
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern std::string expected_assertion_;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)inline void SetExpectedAssertion(const char* s) {
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef MUTE_EXPECTED_ASSERTS
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  expected_assertion_ = s;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // rlz_lib
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // RLZ_LIB_ASSERT_H_
54