Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:39:26

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 #include <cstdint>
0046 #include <iostream>
0047 
0048 // Most of the utilities needed for porting Google Mock are also
0049 // required for Google Test and are defined in gtest-port.h.
0050 //
0051 // Note to maintainers: to reduce code duplication, prefer adding
0052 // portability utilities to Google Test's gtest-port.h instead of
0053 // here, as Google Mock depends on Google Test.  Only add a utility
0054 // here if it's truly specific to Google Mock.
0055 
0056 #include "gmock/internal/custom/gmock-port.h"
0057 #include "gtest/internal/gtest-port.h"
0058 
0059 #if GTEST_HAS_ABSL
0060 #include "absl/flags/declare.h"
0061 #include "absl/flags/flag.h"
0062 #endif
0063 
0064 // For MS Visual C++, check the compiler version. At least VS 2015 is
0065 // required to compile Google Mock.
0066 #if defined(_MSC_VER) && _MSC_VER < 1900
0067 #error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
0068 #endif
0069 
0070 // Macro for referencing flags.  This is public as we want the user to
0071 // use this syntax to reference Google Mock flags.
0072 #define GMOCK_FLAG_NAME_(name) gmock_##name
0073 #define GMOCK_FLAG(name) FLAGS_gmock_##name
0074 
0075 // Pick a command line flags implementation.
0076 #if GTEST_HAS_ABSL
0077 
0078 // Macros for defining flags.
0079 #define GMOCK_DEFINE_bool_(name, default_val, doc) \
0080   ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)
0081 #define GMOCK_DEFINE_int32_(name, default_val, doc) \
0082   ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)
0083 #define GMOCK_DEFINE_string_(name, default_val, doc) \
0084   ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)
0085 
0086 // Macros for declaring flags.
0087 #define GMOCK_DECLARE_bool_(name) \
0088   ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))
0089 #define GMOCK_DECLARE_int32_(name) \
0090   ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))
0091 #define GMOCK_DECLARE_string_(name) \
0092   ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))
0093 
0094 #define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))
0095 #define GMOCK_FLAG_SET(name, value) \
0096   (void)(::absl::SetFlag(&GMOCK_FLAG(name), value))
0097 
0098 #else  // GTEST_HAS_ABSL
0099 
0100 // Macros for defining flags.
0101 #define GMOCK_DEFINE_bool_(name, default_val, doc)  \
0102   namespace testing {                               \
0103   GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \
0104   }                                                 \
0105   static_assert(true, "no-op to require trailing semicolon")
0106 #define GMOCK_DEFINE_int32_(name, default_val, doc)    \
0107   namespace testing {                                  \
0108   GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \
0109   }                                                    \
0110   static_assert(true, "no-op to require trailing semicolon")
0111 #define GMOCK_DEFINE_string_(name, default_val, doc)         \
0112   namespace testing {                                        \
0113   GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \
0114   }                                                          \
0115   static_assert(true, "no-op to require trailing semicolon")
0116 
0117 // Macros for declaring flags.
0118 #define GMOCK_DECLARE_bool_(name)          \
0119   namespace testing {                      \
0120   GTEST_API_ extern bool GMOCK_FLAG(name); \
0121   }                                        \
0122   static_assert(true, "no-op to require trailing semicolon")
0123 #define GMOCK_DECLARE_int32_(name)            \
0124   namespace testing {                         \
0125   GTEST_API_ extern int32_t GMOCK_FLAG(name); \
0126   }                                           \
0127   static_assert(true, "no-op to require trailing semicolon")
0128 #define GMOCK_DECLARE_string_(name)                 \
0129   namespace testing {                               \
0130   GTEST_API_ extern ::std::string GMOCK_FLAG(name); \
0131   }                                                 \
0132   static_assert(true, "no-op to require trailing semicolon")
0133 
0134 #define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)
0135 #define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)
0136 
0137 #endif  // GTEST_HAS_ABSL
0138 
0139 #endif  // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_