Path: blob/main/contrib/googletest/googlemock/include/gmock/internal/gmock-port.h
111877 views
// Copyright 2008, Google Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above10// copyright notice, this list of conditions and the following disclaimer11// in the documentation and/or other materials provided with the12// distribution.13// * Neither the name of Google Inc. nor the names of its14// contributors may be used to endorse or promote products derived from15// this software without specific prior written permission.16//17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2829// Low-level types and utilities for porting Google Mock to various30// platforms. All macros ending with _ and symbols defined in an31// internal namespace are subject to change without notice. Code32// outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't33// end with _ are part of Google Mock's public API and can be used by34// code outside Google Mock.3536// IWYU pragma: private, include "gmock/gmock.h"37// IWYU pragma: friend gmock/.*3839#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_40#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_4142#include <assert.h>43#include <stdlib.h>4445#include <cstdint>46#include <iostream>4748// Most of the utilities needed for porting Google Mock are also49// required for Google Test and are defined in gtest-port.h.50//51// Note to maintainers: to reduce code duplication, prefer adding52// portability utilities to Google Test's gtest-port.h instead of53// here, as Google Mock depends on Google Test. Only add a utility54// here if it's truly specific to Google Mock.5556#include "gmock/internal/custom/gmock-port.h"57#include "gtest/internal/gtest-port.h"5859#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)60#include "absl/flags/declare.h"61#include "absl/flags/flag.h"62#endif6364// For MS Visual C++, check the compiler version. At least VS 2015 is65// required to compile Google Mock.66#if defined(_MSC_VER) && _MSC_VER < 190067#error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."68#endif6970// Macro for referencing flags. This is public as we want the user to71// use this syntax to reference Google Mock flags.72#define GMOCK_FLAG_NAME_(name) gmock_##name73#define GMOCK_FLAG(name) FLAGS_gmock_##name7475// Pick a command line flags implementation.76#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)7778// Macros for defining flags.79#define GMOCK_DEFINE_bool_(name, default_val, doc) \80ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)81#define GMOCK_DEFINE_int32_(name, default_val, doc) \82ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)83#define GMOCK_DEFINE_string_(name, default_val, doc) \84ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)8586// Macros for declaring flags.87#define GMOCK_DECLARE_bool_(name) \88ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))89#define GMOCK_DECLARE_int32_(name) \90ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))91#define GMOCK_DECLARE_string_(name) \92ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))9394#define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))95#define GMOCK_FLAG_SET(name, value) \96(void)(::absl::SetFlag(&GMOCK_FLAG(name), value))9798#else // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)99100// Macros for defining flags.101#define GMOCK_DEFINE_bool_(name, default_val, doc) \102namespace testing { \103GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \104} \105static_assert(true, "no-op to require trailing semicolon")106#define GMOCK_DEFINE_int32_(name, default_val, doc) \107namespace testing { \108GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \109} \110static_assert(true, "no-op to require trailing semicolon")111#define GMOCK_DEFINE_string_(name, default_val, doc) \112namespace testing { \113GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \114} \115static_assert(true, "no-op to require trailing semicolon")116117// Macros for declaring flags.118#define GMOCK_DECLARE_bool_(name) \119namespace testing { \120GTEST_API_ extern bool GMOCK_FLAG(name); \121} \122static_assert(true, "no-op to require trailing semicolon")123#define GMOCK_DECLARE_int32_(name) \124namespace testing { \125GTEST_API_ extern int32_t GMOCK_FLAG(name); \126} \127static_assert(true, "no-op to require trailing semicolon")128#define GMOCK_DECLARE_string_(name) \129namespace testing { \130GTEST_API_ extern ::std::string GMOCK_FLAG(name); \131} \132static_assert(true, "no-op to require trailing semicolon")133134#define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)135#define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)136137#endif // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)138139#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_140141142