Path: blob/main/contrib/googletest/googlemock/include/gmock/internal/gmock-port.h
48525 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>44#include <cstdint>45#include <iostream>4647// Most of the utilities needed for porting Google Mock are also48// required for Google Test and are defined in gtest-port.h.49//50// Note to maintainers: to reduce code duplication, prefer adding51// portability utilities to Google Test's gtest-port.h instead of52// here, as Google Mock depends on Google Test. Only add a utility53// here if it's truly specific to Google Mock.5455#include "gmock/internal/custom/gmock-port.h"56#include "gtest/internal/gtest-port.h"5758#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)59#include "absl/flags/declare.h"60#include "absl/flags/flag.h"61#endif6263// For MS Visual C++, check the compiler version. At least VS 2015 is64// required to compile Google Mock.65#if defined(_MSC_VER) && _MSC_VER < 190066#error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."67#endif6869// Macro for referencing flags. This is public as we want the user to70// use this syntax to reference Google Mock flags.71#define GMOCK_FLAG_NAME_(name) gmock_##name72#define GMOCK_FLAG(name) FLAGS_gmock_##name7374// Pick a command line flags implementation.75#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)7677// Macros for defining flags.78#define GMOCK_DEFINE_bool_(name, default_val, doc) \79ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)80#define GMOCK_DEFINE_int32_(name, default_val, doc) \81ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)82#define GMOCK_DEFINE_string_(name, default_val, doc) \83ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)8485// Macros for declaring flags.86#define GMOCK_DECLARE_bool_(name) \87ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))88#define GMOCK_DECLARE_int32_(name) \89ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))90#define GMOCK_DECLARE_string_(name) \91ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))9293#define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))94#define GMOCK_FLAG_SET(name, value) \95(void)(::absl::SetFlag(&GMOCK_FLAG(name), value))9697#else // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)9899// Macros for defining flags.100#define GMOCK_DEFINE_bool_(name, default_val, doc) \101namespace testing { \102GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \103} \104static_assert(true, "no-op to require trailing semicolon")105#define GMOCK_DEFINE_int32_(name, default_val, doc) \106namespace testing { \107GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \108} \109static_assert(true, "no-op to require trailing semicolon")110#define GMOCK_DEFINE_string_(name, default_val, doc) \111namespace testing { \112GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \113} \114static_assert(true, "no-op to require trailing semicolon")115116// Macros for declaring flags.117#define GMOCK_DECLARE_bool_(name) \118namespace testing { \119GTEST_API_ extern bool GMOCK_FLAG(name); \120} \121static_assert(true, "no-op to require trailing semicolon")122#define GMOCK_DECLARE_int32_(name) \123namespace testing { \124GTEST_API_ extern int32_t GMOCK_FLAG(name); \125} \126static_assert(true, "no-op to require trailing semicolon")127#define GMOCK_DECLARE_string_(name) \128namespace testing { \129GTEST_API_ extern ::std::string GMOCK_FLAG(name); \130} \131static_assert(true, "no-op to require trailing semicolon")132133#define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)134#define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)135136#endif // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)137138#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_139140141