xref: /freebsd/contrib/googletest/googlemock/include/gmock/internal/gmock-port.h (revision 5ca8c28cd8c725b81781201cfdb5f9969396f934)
1b89a7cc2SEnji Cooper // Copyright 2008, Google Inc.
2b89a7cc2SEnji Cooper // All rights reserved.
3b89a7cc2SEnji Cooper //
4b89a7cc2SEnji Cooper // Redistribution and use in source and binary forms, with or without
5b89a7cc2SEnji Cooper // modification, are permitted provided that the following conditions are
6b89a7cc2SEnji Cooper // met:
7b89a7cc2SEnji Cooper //
8b89a7cc2SEnji Cooper //     * Redistributions of source code must retain the above copyright
9b89a7cc2SEnji Cooper // notice, this list of conditions and the following disclaimer.
10b89a7cc2SEnji Cooper //     * Redistributions in binary form must reproduce the above
11b89a7cc2SEnji Cooper // copyright notice, this list of conditions and the following disclaimer
12b89a7cc2SEnji Cooper // in the documentation and/or other materials provided with the
13b89a7cc2SEnji Cooper // distribution.
14b89a7cc2SEnji Cooper //     * Neither the name of Google Inc. nor the names of its
15b89a7cc2SEnji Cooper // contributors may be used to endorse or promote products derived from
16b89a7cc2SEnji Cooper // this software without specific prior written permission.
17b89a7cc2SEnji Cooper //
18b89a7cc2SEnji Cooper // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19b89a7cc2SEnji Cooper // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20b89a7cc2SEnji Cooper // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21b89a7cc2SEnji Cooper // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22b89a7cc2SEnji Cooper // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23b89a7cc2SEnji Cooper // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24b89a7cc2SEnji Cooper // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25b89a7cc2SEnji Cooper // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26b89a7cc2SEnji Cooper // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27b89a7cc2SEnji Cooper // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28b89a7cc2SEnji Cooper // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29b89a7cc2SEnji Cooper 
30b89a7cc2SEnji Cooper // Low-level types and utilities for porting Google Mock to various
31b89a7cc2SEnji Cooper // platforms.  All macros ending with _ and symbols defined in an
32b89a7cc2SEnji Cooper // internal namespace are subject to change without notice.  Code
33b89a7cc2SEnji Cooper // outside Google Mock MUST NOT USE THEM DIRECTLY.  Macros that don't
34b89a7cc2SEnji Cooper // end with _ are part of Google Mock's public API and can be used by
35b89a7cc2SEnji Cooper // code outside Google Mock.
36b89a7cc2SEnji Cooper 
3728f6c2f2SEnji Cooper // IWYU pragma: private, include "gmock/gmock.h"
3828f6c2f2SEnji Cooper // IWYU pragma: friend gmock/.*
39b89a7cc2SEnji Cooper 
4028f6c2f2SEnji Cooper #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
4128f6c2f2SEnji Cooper #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
42b89a7cc2SEnji Cooper 
43b89a7cc2SEnji Cooper #include <assert.h>
44b89a7cc2SEnji Cooper #include <stdlib.h>
4528f6c2f2SEnji Cooper #include <cstdint>
46b89a7cc2SEnji Cooper #include <iostream>
47b89a7cc2SEnji Cooper 
48b89a7cc2SEnji Cooper // Most of the utilities needed for porting Google Mock are also
49b89a7cc2SEnji Cooper // required for Google Test and are defined in gtest-port.h.
50b89a7cc2SEnji Cooper //
51b89a7cc2SEnji Cooper // Note to maintainers: to reduce code duplication, prefer adding
52b89a7cc2SEnji Cooper // portability utilities to Google Test's gtest-port.h instead of
53b89a7cc2SEnji Cooper // here, as Google Mock depends on Google Test.  Only add a utility
54b89a7cc2SEnji Cooper // here if it's truly specific to Google Mock.
55b89a7cc2SEnji Cooper 
56b89a7cc2SEnji Cooper #include "gmock/internal/custom/gmock-port.h"
5728f6c2f2SEnji Cooper #include "gtest/internal/gtest-port.h"
58b89a7cc2SEnji Cooper 
59*5ca8c28cSEnji Cooper #if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
6028f6c2f2SEnji Cooper #include "absl/flags/declare.h"
6128f6c2f2SEnji Cooper #include "absl/flags/flag.h"
6228f6c2f2SEnji Cooper #endif
6328f6c2f2SEnji Cooper 
6428f6c2f2SEnji Cooper // For MS Visual C++, check the compiler version. At least VS 2015 is
65b89a7cc2SEnji Cooper // required to compile Google Mock.
6628f6c2f2SEnji Cooper #if defined(_MSC_VER) && _MSC_VER < 1900
6728f6c2f2SEnji Cooper #error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
68b89a7cc2SEnji Cooper #endif
69b89a7cc2SEnji Cooper 
70b89a7cc2SEnji Cooper // Macro for referencing flags.  This is public as we want the user to
71b89a7cc2SEnji Cooper // use this syntax to reference Google Mock flags.
7228f6c2f2SEnji Cooper #define GMOCK_FLAG_NAME_(name) gmock_##name
73b89a7cc2SEnji Cooper #define GMOCK_FLAG(name) FLAGS_gmock_##name
74b89a7cc2SEnji Cooper 
7528f6c2f2SEnji Cooper // Pick a command line flags implementation.
76*5ca8c28cSEnji Cooper #if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
77b89a7cc2SEnji Cooper 
78b89a7cc2SEnji Cooper // Macros for defining flags.
79b89a7cc2SEnji Cooper #define GMOCK_DEFINE_bool_(name, default_val, doc) \
8028f6c2f2SEnji Cooper   ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)
81b89a7cc2SEnji Cooper #define GMOCK_DEFINE_int32_(name, default_val, doc) \
8228f6c2f2SEnji Cooper   ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)
83b89a7cc2SEnji Cooper #define GMOCK_DEFINE_string_(name, default_val, doc) \
8428f6c2f2SEnji Cooper   ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)
85b89a7cc2SEnji Cooper 
8628f6c2f2SEnji Cooper // Macros for declaring flags.
8728f6c2f2SEnji Cooper #define GMOCK_DECLARE_bool_(name) \
8828f6c2f2SEnji Cooper   ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))
8928f6c2f2SEnji Cooper #define GMOCK_DECLARE_int32_(name) \
9028f6c2f2SEnji Cooper   ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))
9128f6c2f2SEnji Cooper #define GMOCK_DECLARE_string_(name) \
9228f6c2f2SEnji Cooper   ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))
93b89a7cc2SEnji Cooper 
9428f6c2f2SEnji Cooper #define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))
9528f6c2f2SEnji Cooper #define GMOCK_FLAG_SET(name, value) \
9628f6c2f2SEnji Cooper   (void)(::absl::SetFlag(&GMOCK_FLAG(name), value))
9728f6c2f2SEnji Cooper 
98*5ca8c28cSEnji Cooper #else  // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
9928f6c2f2SEnji Cooper 
10028f6c2f2SEnji Cooper // Macros for defining flags.
10128f6c2f2SEnji Cooper #define GMOCK_DEFINE_bool_(name, default_val, doc)  \
10228f6c2f2SEnji Cooper   namespace testing {                               \
10328f6c2f2SEnji Cooper   GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \
10428f6c2f2SEnji Cooper   }                                                 \
10528f6c2f2SEnji Cooper   static_assert(true, "no-op to require trailing semicolon")
10628f6c2f2SEnji Cooper #define GMOCK_DEFINE_int32_(name, default_val, doc)    \
10728f6c2f2SEnji Cooper   namespace testing {                                  \
10828f6c2f2SEnji Cooper   GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \
10928f6c2f2SEnji Cooper   }                                                    \
11028f6c2f2SEnji Cooper   static_assert(true, "no-op to require trailing semicolon")
11128f6c2f2SEnji Cooper #define GMOCK_DEFINE_string_(name, default_val, doc)         \
11228f6c2f2SEnji Cooper   namespace testing {                                        \
11328f6c2f2SEnji Cooper   GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \
11428f6c2f2SEnji Cooper   }                                                          \
11528f6c2f2SEnji Cooper   static_assert(true, "no-op to require trailing semicolon")
11628f6c2f2SEnji Cooper 
11728f6c2f2SEnji Cooper // Macros for declaring flags.
11828f6c2f2SEnji Cooper #define GMOCK_DECLARE_bool_(name)          \
11928f6c2f2SEnji Cooper   namespace testing {                      \
12028f6c2f2SEnji Cooper   GTEST_API_ extern bool GMOCK_FLAG(name); \
12128f6c2f2SEnji Cooper   }                                        \
12228f6c2f2SEnji Cooper   static_assert(true, "no-op to require trailing semicolon")
12328f6c2f2SEnji Cooper #define GMOCK_DECLARE_int32_(name)            \
12428f6c2f2SEnji Cooper   namespace testing {                         \
12528f6c2f2SEnji Cooper   GTEST_API_ extern int32_t GMOCK_FLAG(name); \
12628f6c2f2SEnji Cooper   }                                           \
12728f6c2f2SEnji Cooper   static_assert(true, "no-op to require trailing semicolon")
12828f6c2f2SEnji Cooper #define GMOCK_DECLARE_string_(name)                 \
12928f6c2f2SEnji Cooper   namespace testing {                               \
13028f6c2f2SEnji Cooper   GTEST_API_ extern ::std::string GMOCK_FLAG(name); \
13128f6c2f2SEnji Cooper   }                                                 \
13228f6c2f2SEnji Cooper   static_assert(true, "no-op to require trailing semicolon")
13328f6c2f2SEnji Cooper 
13428f6c2f2SEnji Cooper #define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)
13528f6c2f2SEnji Cooper #define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)
13628f6c2f2SEnji Cooper 
137*5ca8c28cSEnji Cooper #endif  // defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
13828f6c2f2SEnji Cooper 
13928f6c2f2SEnji Cooper #endif  // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
140