1f92157deSopenharmony_ci// Copyright 2008, Google Inc. 2f92157deSopenharmony_ci// All rights reserved. 3f92157deSopenharmony_ci// 4f92157deSopenharmony_ci// Redistribution and use in source and binary forms, with or without 5f92157deSopenharmony_ci// modification, are permitted provided that the following conditions are 6f92157deSopenharmony_ci// met: 7f92157deSopenharmony_ci// 8f92157deSopenharmony_ci// * Redistributions of source code must retain the above copyright 9f92157deSopenharmony_ci// notice, this list of conditions and the following disclaimer. 10f92157deSopenharmony_ci// * Redistributions in binary form must reproduce the above 11f92157deSopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 12f92157deSopenharmony_ci// in the documentation and/or other materials provided with the 13f92157deSopenharmony_ci// distribution. 14f92157deSopenharmony_ci// * Neither the name of Google Inc. nor the names of its 15f92157deSopenharmony_ci// contributors may be used to endorse or promote products derived from 16f92157deSopenharmony_ci// this software without specific prior written permission. 17f92157deSopenharmony_ci// 18f92157deSopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19f92157deSopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20f92157deSopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21f92157deSopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22f92157deSopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23f92157deSopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24f92157deSopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25f92157deSopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26f92157deSopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27f92157deSopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28f92157deSopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29f92157deSopenharmony_ci 30f92157deSopenharmony_ci// Low-level types and utilities for porting Google Mock to various 31f92157deSopenharmony_ci// platforms. All macros ending with _ and symbols defined in an 32f92157deSopenharmony_ci// internal namespace are subject to change without notice. Code 33f92157deSopenharmony_ci// outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't 34f92157deSopenharmony_ci// end with _ are part of Google Mock's public API and can be used by 35f92157deSopenharmony_ci// code outside Google Mock. 36f92157deSopenharmony_ci 37f92157deSopenharmony_ci// IWYU pragma: private, include "gmock/gmock.h" 38f92157deSopenharmony_ci// IWYU pragma: friend gmock/.* 39f92157deSopenharmony_ci 40f92157deSopenharmony_ci#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 41f92157deSopenharmony_ci#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 42f92157deSopenharmony_ci 43f92157deSopenharmony_ci#include <assert.h> 44f92157deSopenharmony_ci#include <stdlib.h> 45f92157deSopenharmony_ci#include <cstdint> 46f92157deSopenharmony_ci#include <iostream> 47f92157deSopenharmony_ci 48f92157deSopenharmony_ci// Most of the utilities needed for porting Google Mock are also 49f92157deSopenharmony_ci// required for Google Test and are defined in gtest-port.h. 50f92157deSopenharmony_ci// 51f92157deSopenharmony_ci// Note to maintainers: to reduce code duplication, prefer adding 52f92157deSopenharmony_ci// portability utilities to Google Test's gtest-port.h instead of 53f92157deSopenharmony_ci// here, as Google Mock depends on Google Test. Only add a utility 54f92157deSopenharmony_ci// here if it's truly specific to Google Mock. 55f92157deSopenharmony_ci 56f92157deSopenharmony_ci#include "gmock/internal/custom/gmock-port.h" 57f92157deSopenharmony_ci#include "gtest/internal/gtest-port.h" 58f92157deSopenharmony_ci 59f92157deSopenharmony_ci#if GTEST_HAS_ABSL 60f92157deSopenharmony_ci#include "absl/flags/declare.h" 61f92157deSopenharmony_ci#include "absl/flags/flag.h" 62f92157deSopenharmony_ci#endif 63f92157deSopenharmony_ci 64f92157deSopenharmony_ci// For MS Visual C++, check the compiler version. At least VS 2015 is 65f92157deSopenharmony_ci// required to compile Google Mock. 66f92157deSopenharmony_ci#if defined(_MSC_VER) && _MSC_VER < 1900 67f92157deSopenharmony_ci#error "At least Visual C++ 2015 (14.0) is required to compile Google Mock." 68f92157deSopenharmony_ci#endif 69f92157deSopenharmony_ci 70f92157deSopenharmony_ci// Macro for referencing flags. This is public as we want the user to 71f92157deSopenharmony_ci// use this syntax to reference Google Mock flags. 72f92157deSopenharmony_ci#define GMOCK_FLAG_NAME_(name) gmock_##name 73f92157deSopenharmony_ci#define GMOCK_FLAG(name) FLAGS_gmock_##name 74f92157deSopenharmony_ci 75f92157deSopenharmony_ci// Pick a command line flags implementation. 76f92157deSopenharmony_ci#if GTEST_HAS_ABSL 77f92157deSopenharmony_ci 78f92157deSopenharmony_ci// Macros for defining flags. 79f92157deSopenharmony_ci#define GMOCK_DEFINE_bool_(name, default_val, doc) \ 80f92157deSopenharmony_ci ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc) 81f92157deSopenharmony_ci#define GMOCK_DEFINE_int32_(name, default_val, doc) \ 82f92157deSopenharmony_ci ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc) 83f92157deSopenharmony_ci#define GMOCK_DEFINE_string_(name, default_val, doc) \ 84f92157deSopenharmony_ci ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc) 85f92157deSopenharmony_ci 86f92157deSopenharmony_ci// Macros for declaring flags. 87f92157deSopenharmony_ci#define GMOCK_DECLARE_bool_(name) \ 88f92157deSopenharmony_ci ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name)) 89f92157deSopenharmony_ci#define GMOCK_DECLARE_int32_(name) \ 90f92157deSopenharmony_ci ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name)) 91f92157deSopenharmony_ci#define GMOCK_DECLARE_string_(name) \ 92f92157deSopenharmony_ci ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name)) 93f92157deSopenharmony_ci 94f92157deSopenharmony_ci#define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name)) 95f92157deSopenharmony_ci#define GMOCK_FLAG_SET(name, value) \ 96f92157deSopenharmony_ci (void)(::absl::SetFlag(&GMOCK_FLAG(name), value)) 97f92157deSopenharmony_ci 98f92157deSopenharmony_ci#else // GTEST_HAS_ABSL 99f92157deSopenharmony_ci 100f92157deSopenharmony_ci// Macros for defining flags. 101f92157deSopenharmony_ci#define GMOCK_DEFINE_bool_(name, default_val, doc) \ 102f92157deSopenharmony_ci namespace testing { \ 103f92157deSopenharmony_ci GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \ 104f92157deSopenharmony_ci } \ 105f92157deSopenharmony_ci static_assert(true, "no-op to require trailing semicolon") 106f92157deSopenharmony_ci#define GMOCK_DEFINE_int32_(name, default_val, doc) \ 107f92157deSopenharmony_ci namespace testing { \ 108f92157deSopenharmony_ci GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \ 109f92157deSopenharmony_ci } \ 110f92157deSopenharmony_ci static_assert(true, "no-op to require trailing semicolon") 111f92157deSopenharmony_ci#define GMOCK_DEFINE_string_(name, default_val, doc) \ 112f92157deSopenharmony_ci namespace testing { \ 113f92157deSopenharmony_ci GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \ 114f92157deSopenharmony_ci } \ 115f92157deSopenharmony_ci static_assert(true, "no-op to require trailing semicolon") 116f92157deSopenharmony_ci 117f92157deSopenharmony_ci// Macros for declaring flags. 118f92157deSopenharmony_ci#define GMOCK_DECLARE_bool_(name) \ 119f92157deSopenharmony_ci namespace testing { \ 120f92157deSopenharmony_ci GTEST_API_ extern bool GMOCK_FLAG(name); \ 121f92157deSopenharmony_ci } \ 122f92157deSopenharmony_ci static_assert(true, "no-op to require trailing semicolon") 123f92157deSopenharmony_ci#define GMOCK_DECLARE_int32_(name) \ 124f92157deSopenharmony_ci namespace testing { \ 125f92157deSopenharmony_ci GTEST_API_ extern int32_t GMOCK_FLAG(name); \ 126f92157deSopenharmony_ci } \ 127f92157deSopenharmony_ci static_assert(true, "no-op to require trailing semicolon") 128f92157deSopenharmony_ci#define GMOCK_DECLARE_string_(name) \ 129f92157deSopenharmony_ci namespace testing { \ 130f92157deSopenharmony_ci GTEST_API_ extern ::std::string GMOCK_FLAG(name); \ 131f92157deSopenharmony_ci } \ 132f92157deSopenharmony_ci static_assert(true, "no-op to require trailing semicolon") 133f92157deSopenharmony_ci 134f92157deSopenharmony_ci#define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name) 135f92157deSopenharmony_ci#define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value) 136f92157deSopenharmony_ci 137f92157deSopenharmony_ci#endif // GTEST_HAS_ABSL 138f92157deSopenharmony_ci 139f92157deSopenharmony_ci#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 140