Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-04 10:05:12

0001 // Copyright 2008, Google Inc.
0002 // All rights reserved.
0003 //
0004 // Redistribution and use in source and binary forms, with or without
0005 // modification, are permitted provided that the following conditions are
0006 // met:
0007 //
0008 //     * Redistributions of source code must retain the above copyright
0009 // notice, this list of conditions and the following disclaimer.
0010 //     * Redistributions in binary form must reproduce the above
0011 // copyright notice, this list of conditions and the following disclaimer
0012 // in the documentation and/or other materials provided with the
0013 // distribution.
0014 //     * Neither the name of Google Inc. nor the names of its
0015 // contributors may be used to endorse or promote products derived from
0016 // this software without specific prior written permission.
0017 //
0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029 
0030 // Low-level types and utilities for porting Google Mock to various
0031 // platforms.  All macros ending with _ and symbols defined in an
0032 // internal namespace are subject to change without notice.  Code
0033 // outside Google Mock MUST NOT USE THEM DIRECTLY.  Macros that don't
0034 // end with _ are part of Google Mock's public API and can be used by
0035 // code outside Google Mock.
0036 
0037 // IWYU pragma: private, include "gmock/gmock.h"
0038 // IWYU pragma: friend gmock/.*
0039 
0040 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
0041 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
0042 
0043 #include <assert.h>
0044 #include <stdlib.h>
0045 
0046 #include <cstdint>
0047 #include <iostream>
0048 
0049 // Most of the utilities needed for porting Google Mock are also
0050 // required for Google Test and are defined in gtest-port.h.
0051 //
0052 // Note to maintainers: to reduce code duplication, prefer adding
0053 // portability utilities to Google Test's gtest-port.h instead of
0054 // here, as Google Mock depends on Google Test.  Only add a utility
0055 // here if it's truly specific to Google Mock.
0056 
0057 #include "gmock/internal/custom/gmock-port.h"
0058 #include "gtest/internal/gtest-port.h"
0059 
0060 #if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
0061 #include "absl/flags/declare.h"
0062 #include "absl/flags/flag.h"
0063 #endif
0064 
0065 // For MS Visual C++, check the compiler version. At least VS 2015 is
0066 // required to compile Google Mock.
0067 #if defined(_MSC_VER) && _MSC_VER < 1900
0068 #error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
0069 #endif
0070 
0071 // Macro for referencing flags.  This is public as we want the user to
0072 // use this syntax to reference Google Mock flags.
0073 #define GMOCK_FLAG_NAME_(name) gmock_##name
0074 #define GMOCK_FLAG(name) FLAGS_gmock_##name
0075 
0076 // Pick a command line flags implementation.
0077 #if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
0078 
0079 // Macros for defining flags.
0080 #define GMOCK_DEFINE_bool_(name, default_val, doc) \
0081   ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)
0082 #define GMOCK_DEFINE_int32_(name, default_val, doc) \
0083   ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)
0084 #define GMOCK_DEFINE_string_(name, default_val, doc) \
0085   ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)
0086 
0087 // Macros for declaring flags.
0088 #define GMOCK_DECLARE_bool_(name) \
0089   GTEST_API_ ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))
0090 #define GMOCK_DECLARE_int32_(name) \
0091   GTEST_API_ ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))
0092 #define GMOCK_DECLARE_string_(name) \
0093   GTEST_API_ ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))
0094 
0095 #define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))
0096 #define GMOCK_FLAG_SET(name, value) \
0097   (void)(::absl::SetFlag(&GMOCK_FLAG(name), value))
0098 
0099 #else  // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
0100 
0101 // Macros for defining flags.
0102 #define GMOCK_DEFINE_bool_(name, default_val, doc)  \
0103   namespace testing {                               \
0104   GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \
0105   }                                                 \
0106   static_assert(true, "no-op to require trailing semicolon")
0107 #define GMOCK_DEFINE_int32_(name, default_val, doc)    \
0108   namespace testing {                                  \
0109   GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \
0110   }                                                    \
0111   static_assert(true, "no-op to require trailing semicolon")
0112 #define GMOCK_DEFINE_string_(name, default_val, doc)         \
0113   namespace testing {                                        \
0114   GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \
0115   }                                                          \
0116   static_assert(true, "no-op to require trailing semicolon")
0117 
0118 // Macros for declaring flags.
0119 #define GMOCK_DECLARE_bool_(name)          \
0120   namespace testing {                      \
0121   GTEST_API_ extern bool GMOCK_FLAG(name); \
0122   }                                        \
0123   static_assert(true, "no-op to require trailing semicolon")
0124 #define GMOCK_DECLARE_int32_(name)            \
0125   namespace testing {                         \
0126   GTEST_API_ extern int32_t GMOCK_FLAG(name); \
0127   }                                           \
0128   static_assert(true, "no-op to require trailing semicolon")
0129 #define GMOCK_DECLARE_string_(name)                 \
0130   namespace testing {                               \
0131   GTEST_API_ extern ::std::string GMOCK_FLAG(name); \
0132   }                                                 \
0133   static_assert(true, "no-op to require trailing semicolon")
0134 
0135 #define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)
0136 #define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)
0137 
0138 #endif  // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
0139 
0140 #endif  // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_