17ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Copyright 2005, Google Inc.
27ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// All rights reserved.
37ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
47ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Redistribution and use in source and binary forms, with or without
57ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// modification, are permitted provided that the following conditions are
67ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// met:
77ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
87ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     * Redistributions of source code must retain the above copyright
97ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// notice, this list of conditions and the following disclaimer.
107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     * Redistributions in binary form must reproduce the above
117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// copyright notice, this list of conditions and the following disclaimer
127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// in the documentation and/or other materials provided with the
137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// distribution.
147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     * Neither the name of Google Inc. nor the names of its
157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// contributors may be used to endorse or promote products derived from
167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// this software without specific prior written permission.
177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
207ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Authors: wan@google.com (Zhanyong Wan)
317ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
327ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Low-level types and utilities for porting Google Test to various
337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// platforms.  They are subject to change without notice.  DO NOT USE
347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// THEM IN USER CODE.
357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user can define the following macros in the build script to
407ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// control Google Test's behavior.  If the user doesn't define a macro
417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// in this list, Google Test will define it.
427ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              is/isn't available.
4557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
4657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                              are enabled.
477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              is/isn't available (some systems define
497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              ::string, which is different to std::string).
507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              is/isn't available (some systems define
527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              ::wstring, which is different to std::wstring).
53b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
54b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                              expressions are/aren't available.
557ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
567ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              is/isn't available.
577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
587ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              enabled.
597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              std::wstring does/doesn't work (Google Test can
617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              be used where std::wstring is unavailable).
62190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                              is/isn't available.
64190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
65190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                              compiler supports Microsoft's "Structured
66190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                              Exception Handling".
67b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_HAS_STREAM_REDIRECTION
68b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                            - Define it to 1/0 to indicate whether the
69b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                              platform supports I/O stream redirection using
70b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                              dup() and dup2().
71190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
72190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                              Test's own tr1 tuple implementation should be
73190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                              used.  Unused when the user sets
74190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                              GTEST_HAS_TR1_TUPLE to 0.
7557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GTEST_LINKED_AS_SHARED_LIBRARY
7657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                            - Define to 1 when compiling tests that use
7757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                              Google Test as a shared library (known as
7857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                              DLL on Windows).
7957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GTEST_CREATE_SHARED_LIBRARY
8057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                            - Define to 1 when compiling Google Test itself
8157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                              as a shared library.
827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// This header defines the following utilities:
847ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
85e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// Macros indicating the current platform (defined to 1 if compiled on
86e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// the given platform; otherwise undefined):
8757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GTEST_OS_AIX      - IBM AIX
88e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_OS_CYGWIN   - Cygwin
8936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//   GTEST_OS_FREEBSD  - FreeBSD
90ec4c02d252b4f2b3dda053c9c7c894832c91dfcaNick Lewycky//   GTEST_OS_HAIKU    - Haiku
91b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_OS_HPUX     - HP-UX
92e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_OS_LINUX    - Linux
93b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//     GTEST_OS_LINUX_ANDROID - Google Android
94e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_OS_MAC      - Mac OS X
95b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_OS_NACL     - Google Native Client (NaCl)
96e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_OS_SOLARIS  - Sun Solaris
97e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_OS_SYMBIAN  - Symbian
98190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
99190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
100190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//     GTEST_OS_WINDOWS_MINGW    - MinGW
10157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
102e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_OS_ZOS      - z/OS
1037ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
1057ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// most stable support.  Since core members of the Google Test project
1067ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// don't have access to other platforms, support for them may be less
1077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// stable.  If you notice any problems on your platform, please notify
1087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// googletestframework@googlegroups.com (patches for fixing them are
1097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// even more welcome!).
1107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
111e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// Note that it is possible that none of the GTEST_OS_* macros are defined.
1127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
113e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// Macros indicating available Google Test features (defined to 1 if
114e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// the corresponding feature is supported; otherwise undefined):
115e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
116e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//                            tests)
117e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_HAS_DEATH_TEST   - death tests
118e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_HAS_PARAM_TEST   - value-parameterized tests
119e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_HAS_TYPED_TEST   - typed tests
120e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
121b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
122b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                            GTEST_HAS_POSIX_RE (see above) which users can
123b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                            define themselves.
124e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
125e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer//                            the above two are mutually exclusive.
12657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
1277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Macros for basic C++ coding:
1297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
130190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
131190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                              variable don't have to be used.
13257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GTEST_DISALLOW_ASSIGN_   - disables operator=.
1337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
1347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
1357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Synchronization:
1377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Mutex, MutexLock, ThreadLocal, GetThreadCount()
1387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                  - synchronization primitives.
1397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
1407ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                         synchronization primitives have real implementations
1417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                         and Google Test is thread-safe; or 0 otherwise.
1427ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Template meta programming:
1447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
145b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   IteratorTraits - partial implementation of std::iterator_traits, which
146b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                    is not available in libCstd when compiled with Sun C++.
1477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Smart pointers:
1497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   scoped_ptr     - as in TR2.
1507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Regular expressions:
1527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   RE             - a simple regular expression class using the POSIX
153b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                    Extended Regular Expression syntax on UNIX-like
154b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                    platforms, or a reduced regular exception syntax on
155b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                    other platforms, including Windows.
1567ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Logging:
1587ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_LOG_()   - logs messages at the specified severity level.
1597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   LogToStderr()  - directs all log messages to stderr.
1607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   FlushInfoLog() - flushes informational log messages.
1617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
16257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Stdout and stderr capturing:
16357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   CaptureStdout()     - starts capturing stdout.
16457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   GetCapturedStdout() - stops capturing stdout and returns the captured
16557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//                         string.
1667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   CaptureStderr()     - starts capturing stderr.
1677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GetCapturedStderr() - stops capturing stderr and returns the captured
1687ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                         string.
1697ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1707ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Integer types:
1717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   TypeWithSize   - maps an integer to a int type.
1727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Int32, UInt32, Int64, UInt64, TimeInMillis
1737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//                  - integers of known sizes.
1747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   BiggestInt     - the biggest signed integer type.
1757ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1767ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Command-line utilities:
1777ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_FLAG()       - references a flag.
1787ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_DECLARE_*()  - declares a flag.
1797ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GTEST_DEFINE_*()   - defines a flag.
1807ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GetArgvs()         - returns the command line as a vector of strings.
1817ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
1827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Environment variable utilities:
1837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   GetEnv()             - gets the value of an environment variable.
1847ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   BoolFromGTestEnv()   - parses a bool environment variable.
1857ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Int32FromGTestEnv()  - parses an Int32 environment variable.
1867ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   StringFromGTestEnv() - parses a string environment variable.
1877ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
188b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include <ctype.h>   // for isspace, etc
189b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include <stddef.h>  // for ptrdiff_t
1907ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#include <stdlib.h>
1917ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#include <stdio.h>
192190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#include <string.h>
193190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#ifndef _WIN32_WCE
194b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <sys/types.h>
195b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <sys/stat.h>
196190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#endif  // !_WIN32_WCE
197190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
198190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#include <iostream>  // NOLINT
19957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#include <sstream>  // NOLINT
20057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#include <string>  // NOLINT
2017ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
202e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
203e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_FLAG_PREFIX_ "gtest_"
20457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#define GTEST_FLAG_PREFIX_DASH_ "gtest-"
205e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
206e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_NAME_ "Google Test"
207e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
2087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
2097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines the version of gcc that is used to compile this.
2107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifdef __GNUC__
2117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// 40302 means version 4.3.2.
212b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_GCC_VER_ \
2137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
2147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // __GNUC__
2157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
2167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines the platform on which Google Test is compiled.
2177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifdef __CYGWIN__
218b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_CYGWIN 1
219190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#elif defined __SYMBIAN32__
220b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_SYMBIAN 1
221190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#elif defined _WIN32
222b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_WINDOWS 1
223b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# ifdef _WIN32_WCE
224b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_OS_WINDOWS_MOBILE 1
225b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__MINGW__) || defined(__MINGW32__)
226b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_OS_WINDOWS_MINGW 1
227b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
228b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_OS_WINDOWS_DESKTOP 1
229b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // _WIN32_WCE
2307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#elif defined __APPLE__
231b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_MAC 1
23236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#elif defined __FreeBSD__
23336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines# define GTEST_OS_FREEBSD 1
2347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#elif defined __linux__
235b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_LINUX 1
23668d92bdcc99e647546f40cfce5cfbeb904be2985Evgeniy Stepanov# if defined(ANDROID) || defined(__ANDROID__)
237b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_OS_LINUX_ANDROID 1
238b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // ANDROID
2397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#elif defined __MVS__
240b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_ZOS 1
2417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#elif defined(__sun) && defined(__SVR4)
242b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_SOLARIS 1
24357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#elif defined(_AIX)
244b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_AIX 1
245b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#elif defined(__hpux)
246b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_HPUX 1
247b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#elif defined __native_client__
248b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_NACL 1
249df40664a63a91a1ab4b40c7f2d356cf255071d56Edward O'Callaghan#elif defined(__HAIKU__)
250b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_OS_HAIKU 1
251190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#endif  // __CYGWIN__
2527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
253b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Brings in definitions for functions used in the testing::internal::posix
254b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// namespace (read, write, close, chdir, isatty, stat). We do not currently
255b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// use them on Windows Mobile.
256b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if !GTEST_OS_WINDOWS
257b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// This assumes that non-Windows OSes provide unistd.h. For OSes where this
258b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// is not the case, we need to include headers that provide the functions
259b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// mentioned above.
260b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <unistd.h>
261b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if !GTEST_OS_NACL
262b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// TODO(vladl@google.com): Remove this condition when Native Client SDK adds
263b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// strings.h (tracked in
264b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// http://code.google.com/p/nativeclient/issues/detail?id=1175).
265b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  include <strings.h>  // Native Client doesn't provide strings.h.
266b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif
267b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#elif !GTEST_OS_WINDOWS_MOBILE
268b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <direct.h>
269b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <io.h>
270b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif
271b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
27294c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru// Defines this to true iff Google Test can use POSIX regular expressions.
273b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#ifndef GTEST_HAS_POSIX_RE
274b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
275b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif
276b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
277b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if GTEST_HAS_POSIX_RE
2787ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
279e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// On some platforms, <regex.h> needs someone to define size_t, and
280e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// won't compile otherwise.  We can #include it here as we already
281e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// included <stdlib.h>, which is guaranteed to define size_t through
282e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// <stddef.h>.
283b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <regex.h>  // NOLINT
284190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
285b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_USES_POSIX_RE 1
286e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
287190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#elif GTEST_OS_WINDOWS
288190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
289190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// <regex.h> is not available on Windows.  Use our own simple regex
290190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// implementation instead.
291b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_USES_SIMPLE_RE 1
292190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
293e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#else
294e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
295e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// <regex.h> may not be available on this platform.  Use our own
296e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// simple regex implementation instead.
297b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_USES_SIMPLE_RE 1
298e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
299b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif  // GTEST_HAS_POSIX_RE
3007ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
30157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#ifndef GTEST_HAS_EXCEPTIONS
30257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// The user didn't tell us whether exceptions are enabled, so we need
30357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// to figure it out.
304b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if defined(_MSC_VER) || defined(__BORLANDC__)
305190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
306190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// macro to enable exceptions, so we'll do the same.
3077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Assumes that exceptions are enabled by default.
308b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  ifndef _HAS_EXCEPTIONS
309b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define _HAS_EXCEPTIONS 1
310b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  endif  // _HAS_EXCEPTIONS
311b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
312b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__GNUC__) && __EXCEPTIONS
31394c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
314b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_EXCEPTIONS 1
315b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__SUNPRO_CC)
31657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Sun Pro CC supports exceptions.  However, there is no compile-time way of
31757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// detecting whether they are enabled or not.  Therefore, we assume that
31857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// they are enabled unless the user tells us otherwise.
319b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_EXCEPTIONS 1
320b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__IBMCPP__) && __EXCEPTIONS
32194c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
322b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_EXCEPTIONS 1
323b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__HP_aCC)
324b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Exception handling is in effect by default in HP aCC compiler. It has to
325b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// be turned of by +noeh compiler option if desired.
326b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_EXCEPTIONS 1
327b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
32857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// For other compilers, we assume exceptions are disabled to be
32957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// conservative.
330b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_EXCEPTIONS 0
331b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // defined(_MSC_VER) || defined(__BORLANDC__)
33257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif  // GTEST_HAS_EXCEPTIONS
333e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
33457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#if !defined(GTEST_HAS_STD_STRING)
33557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Even though we don't use this macro any longer, we keep it in case
33657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// some clients still depend on it.
337b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_STD_STRING 1
33857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#elif !GTEST_HAS_STD_STRING
33957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// The user told us that ::std::string isn't available.
340b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# error "Google Test cannot be used where ::std::string isn't available."
34157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif  // !defined(GTEST_HAS_STD_STRING)
3427ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_GLOBAL_STRING
3447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user didn't tell us whether ::string is available, so we need
3457ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// to figure it out.
3467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
347b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_GLOBAL_STRING 0
3487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_GLOBAL_STRING
3507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_STD_WSTRING
3527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user didn't tell us whether ::std::wstring is available, so we need
3537ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// to figure it out.
3547ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
3557ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   is available.
3567ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
357b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Cygwin 1.7 and below doesn't support ::std::wstring.
358b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Solaris' libc++ doesn't support it either.  Android has
359b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// no support for it at least as recent as Froyo (2.2).
36021aa347c2816aa8fc635ad05c5ab786234b32c7eChris Lattner// Minix currently doesn't support it either.
361b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_STD_WSTRING \
362b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || GTEST_OS_HAIKU || defined(_MINIX)))
3637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_STD_WSTRING
3657ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_GLOBAL_WSTRING
3677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user didn't tell us whether ::wstring is available, so we need
3687ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// to figure it out.
369b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_GLOBAL_WSTRING \
370e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer    (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
3717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_GLOBAL_WSTRING
3727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines whether RTTI is available.
3747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_RTTI
3757ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user didn't tell us whether RTTI is enabled, so we need to
3767ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// figure it out.
3777ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
378b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# ifdef _MSC_VER
3797ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
38094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru#  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
381b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define GTEST_HAS_RTTI 1
382b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  else
383b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define GTEST_HAS_RTTI 0
384b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  endif
3857ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
38694c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
387b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
38857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
389b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  ifdef __GXX_RTTI
390b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define GTEST_HAS_RTTI 1
391b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  else
392b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define GTEST_HAS_RTTI 0
393b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  endif  // __GXX_RTTI
39457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
39557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
39657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// both the typeid and dynamic_cast features are present.
397b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
39857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
399b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  ifdef __RTTI_ALL__
400b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define GTEST_HAS_RTTI 1
401b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  else
402b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define GTEST_HAS_RTTI 0
403b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  endif
4047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
405b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
4067ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
40757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// For all other compilers, we assume RTTI is enabled.
408b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_RTTI 1
4097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
410b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // _MSC_VER
4117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_RTTI
4137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
41457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// It's this header's responsibility to #include <typeinfo> when RTTI
41557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// is enabled.
41657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#if GTEST_HAS_RTTI
417b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <typeinfo>
41857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif
41957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
42057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Determines whether Google Test can use the pthreads library.
4217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_PTHREAD
42257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// The user didn't tell us explicitly, so we assume pthreads support is
42357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// available on Linux and Mac.
42457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
42557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
42657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// to your compiler flags.
42736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || \
42836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          GTEST_OS_HPUX || GTEST_OS_FREEBSD)
4297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_PTHREAD
4307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
431b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if GTEST_HAS_PTHREAD
432b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
433b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// true.
434b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <pthread.h>  // NOLINT
435b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
436b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// For timespec and nanosleep, used below.
437b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <time.h>  // NOLINT
438b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif
439b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
440190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Determines whether Google Test can use tr1/tuple.  You can define
441190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// this macro to 0 to prevent Google Test from using tuple (any
442190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// feature depending on tuple with be disabled in this mode).
4437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_TR1_TUPLE
444190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// The user didn't tell us not to do it, so we assume it's OK.
445b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_TR1_TUPLE 1
446190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#endif  // GTEST_HAS_TR1_TUPLE
447190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
448190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Determines whether Google Test's own tr1 tuple implementation
449190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// should be used.
450190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#ifndef GTEST_USE_OWN_TR1_TUPLE
4517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user didn't tell us, so we need to figure it out.
4527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
45357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// We use our own TR1 tuple if we aren't sure the user has an
45457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// implementation of it already.  At this time, GCC 4.0.0+ and MSVC
45557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// 2010 are the only mainstream compilers that come with a TR1 tuple
45657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// implementation.  NVIDIA's CUDA NVCC compiler pretends to be GCC by
45757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// defining __GNUC__ and friends, but cannot compile GCC's tuple
45857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// implementation.  MSVC 2008 (9.0) provides TR1 tuple in a 323 MB
45957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Feature Pack download, which we cannot assume the user has.
460b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if (defined(__GNUC__) && !(defined(__CUDACC__) || defined(__clang__)) \
461b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad                        && (GTEST_GCC_VER_ >= 40000)) \
46257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    || _MSC_VER >= 1600
463b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_USE_OWN_TR1_TUPLE 0
464b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
465b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_USE_OWN_TR1_TUPLE 1
466b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif
467190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
468190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#endif  // GTEST_USE_OWN_TR1_TUPLE
4697ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4707ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// To avoid conditional compilation everywhere, we make it
4717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// gtest-port.h's responsibility to #include the header implementing
4727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// tr1/tuple.
4737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#if GTEST_HAS_TR1_TUPLE
474190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
475b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if GTEST_USE_OWN_TR1_TUPLE
476b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  include "gtest/internal/gtest-tuple.h"
477b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif GTEST_OS_SYMBIAN
478190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
479190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
480190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// use STLport's tuple implementation, which unfortunately doesn't
481190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// work as the copy of STLport distributed with Symbian is incomplete.
482190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
483190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// use its own tuple implementation.
484b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  ifdef BOOST_HAS_TR1_TUPLE
485b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   undef BOOST_HAS_TR1_TUPLE
486b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  endif  // BOOST_HAS_TR1_TUPLE
487190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
488190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// This prevents <boost/tr1/detail/config.hpp>, which defines
489190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
490b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
491b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  include <tuple>
492190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
493b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
494190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
495190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// not conform to the TR1 spec, which requires the header to be <tuple>.
496190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
497b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
498190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
499190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// which is #included by <tr1/tuple>, to not compile when RTTI is
500190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// disabled.  _TR1_FUNCTIONAL is the header guard for
501190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// <tr1/functional>.  Hence the following #define is a hack to prevent
502190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// <tr1/functional> from being included.
503b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   define _TR1_FUNCTIONAL 1
504b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   include <tr1/tuple>
505b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   undef _TR1_FUNCTIONAL  // Allows the user to #include
506190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                        // <tr1/functional> if he chooses to.
507b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  else
508b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#   include <tr1/tuple>  // NOLINT
509b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
510190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
511b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
512190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// If the compiler is not GCC 4.0+, we assume the user is using a
5137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// spec-conforming TR1 implementation.
514b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  include <tuple>  // NOLINT
515b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // GTEST_USE_OWN_TR1_TUPLE
516190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
5177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_TR1_TUPLE
5187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
5197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines whether clone(2) is supported.
5207ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Usually it will only be available on Linux, excluding
5217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Linux on the Itanium architecture.
5227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Also see http://linux.die.net/man/2/clone.
5237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_HAS_CLONE
5247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The user didn't tell us, so we need to figure it out.
5257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
526b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if GTEST_OS_LINUX && !defined(__ia64__)
527b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_CLONE 1
528b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
529b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_CLONE 0
530b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // GTEST_OS_LINUX && !defined(__ia64__)
5317ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
5327ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_CLONE
5337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
53457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Determines whether to support stream redirection. This is used to test
53557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// output correctness and to implement death tests.
536b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#ifndef GTEST_HAS_STREAM_REDIRECTION
537b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// By default, we assume that stream redirection is supported on all
538b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// platforms except known mobile ones.
539b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
540b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_STREAM_REDIRECTION 0
541b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
542b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_STREAM_REDIRECTION 1
543b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
544b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif  // GTEST_HAS_STREAM_REDIRECTION
54557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
5467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines whether to support death tests.
54757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Google Test does not support death tests for VC 7.1 and earlier as
54857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// abort() in a VC 7.1 application compiled as GUI in debug config
54957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// pops up a dialog window that cannot be suppressed programmatically.
55057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
55157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer     (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
55236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || \
55336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines     GTEST_OS_HPUX || GTEST_OS_FREEBSD)
554b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_DEATH_TEST 1
555b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# include <vector>  // NOLINT
556e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#endif
5577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
55857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// We don't support MSVC 7.1 with exceptions disabled now.  Therefore
55957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// all the compilers we care about are adequate for supporting
56057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// value-parameterized tests.
561e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_HAS_PARAM_TEST 1
5627ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
5637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines whether to support type-driven tests.
5647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
56557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
566b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Sun Pro CC, IBM Visual Age, and HP aCC support.
56757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
568b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    defined(__IBMCPP__) || defined(__HP_aCC)
569b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_TYPED_TEST 1
570b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_TYPED_TEST_P 1
57157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif
5727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
5737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines whether to support Combine(). This only makes sense when
57457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// value-parameterized tests are enabled.  The implementation doesn't
57557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// work on Sun Studio since it doesn't understand templated conversion
57657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// operators.
57757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
578b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_HAS_COMBINE 1
57957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif
5807ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
5817ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Determines whether the system compiler uses UTF-16 for encoding wide strings.
582e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#define GTEST_WIDE_STRING_USES_UTF16_ \
58357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
5847ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
585b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Determines whether test results can be streamed to a socket.
586b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if GTEST_OS_LINUX
587b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_CAN_STREAM_RESULTS_ 1
588b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif
589b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
5907ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Defines some utility macros.
5917ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
5927ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The GNU compiler emits a warning if nested "if" statements are followed by
5937ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// an "else" statement and braces are not used to explicitly disambiguate the
5947ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// "else" binding.  This leads to problems with code like:
5957ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
5967ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   if (gate)
5977ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     ASSERT_*(condition) << "Some message";
5987ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
5997ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The "switch (0) case 0:" idiom is used to suppress this.
6007ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifdef __INTEL_COMPILER
601b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
6027ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#else
603b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
6047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif
6057ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
606190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Use this annotation at the end of a struct/class definition to
6077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// prevent the compiler from optimizing away instances that are never
6087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// used.  This is useful when all interesting logic happens inside the
6097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// c'tor and / or d'tor.  Example:
6107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
6117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   struct Foo {
6127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     Foo() { ... }
6137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   } GTEST_ATTRIBUTE_UNUSED_;
614190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//
615190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Also use it after a variable or parameter declaration to tell the
616190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// compiler the variable/parameter does not have to be used.
6177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#if defined(__GNUC__) && !defined(COMPILER_ICC)
618b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
6197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#else
620b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_ATTRIBUTE_UNUSED_
6217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif
6227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
62357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// A macro to disallow operator=
62457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// This should be used in the private: declarations for a class.
62557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#define GTEST_DISALLOW_ASSIGN_(type)\
6268c8b9ee8c8646aa1a79c782d4da9abdf3eb4eefeArgyrios Kyrtzidis  void operator=(type const &)
62757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
62857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// A macro to disallow copy constructor and operator=
6297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// This should be used in the private: declarations for a class.
6307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
6318c8b9ee8c8646aa1a79c782d4da9abdf3eb4eefeArgyrios Kyrtzidis  type(type const &);\
63257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  GTEST_DISALLOW_ASSIGN_(type)
6337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Tell the compiler to warn about unused return values for functions declared
6357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// with this macro.  The macro should be used on function declarations
6367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// following the argument list:
6377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
6387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
6397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
640b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
6417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#else
642b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_MUST_USE_RESULT_
6437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
6447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
645190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Determine whether the compiler supports Microsoft's Structured Exception
646190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Handling.  This is supported by several Windows compilers but generally
647190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// does not exist on any other system.
648190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#ifndef GTEST_HAS_SEH
649190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// The user didn't tell us, so we need to figure it out.
650190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
651b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if defined(_MSC_VER) || defined(__BORLANDC__)
652190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// These two compilers are known to support SEH.
653b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_SEH 1
654b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# else
655190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Assume no SEH.
656b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_HAS_SEH 0
657b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif
658190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
659190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#endif  // GTEST_HAS_SEH
660190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
66157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#ifdef _MSC_VER
66257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
663b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# if GTEST_LINKED_AS_SHARED_LIBRARY
664b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_API_ __declspec(dllimport)
665b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# elif GTEST_CREATE_SHARED_LIBRARY
666b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#  define GTEST_API_ __declspec(dllexport)
667b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# endif
66857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
66957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif  // _MSC_VER
67057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
67157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#ifndef GTEST_API_
672b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_API_
673b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif
674b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
675b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#ifdef __GNUC__
676b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Ask the compiler to never inline a given function.
677b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_NO_INLINE_ __attribute__((noinline))
678b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#else
679b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad# define GTEST_NO_INLINE_
68057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#endif
68157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
6827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmannamespace testing {
6837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6847ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmanclass Message;
6857ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6867ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmannamespace internal {
6877ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6887ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmanclass String;
6897ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
690b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
691b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// expression is true. For example, you could use it to verify the
692b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// size of a static array:
693b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
694b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
695b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                         content_type_names_incorrect_size);
696b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
697b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// or to make sure a struct is smaller than a certain size:
698b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
699b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
700b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
701b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// The second argument to the macro is the name of the variable. If
702b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// the expression is false, most compilers will issue a warning/error
703b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// containing the name of the variable.
704b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
705b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtemplate <bool>
706b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadstruct CompileAssert {
707b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad};
708b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
709b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#define GTEST_COMPILE_ASSERT_(expr, msg) \
710b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  typedef ::testing::internal::CompileAssert<(bool(expr))> \
711b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      msg[bool(expr) ? 1 : -1]
712b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
713b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Implementation details of GTEST_COMPILE_ASSERT_:
714b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
715b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
716b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   elements (and thus is invalid) when the expression is false.
717b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
718b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// - The simpler definition
719b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
720b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
721b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
722b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   does not work, as gcc supports variable-length arrays whose sizes
723b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   are determined at run-time (this is gcc's extension and not part
724b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   of the C++ standard).  As a result, gcc fails to reject the
725b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   following code with the simple definition:
726b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
727b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//     int foo;
728b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
729b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//                                      // not a compile-time constant.
730b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
731b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// - By using the type CompileAssert<(bool(expr))>, we ensures that
732b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   expr is a compile-time constant.  (Template arguments must be
733b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   determined at compile-time.)
734b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
735b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
736b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
737b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
738b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//     CompileAssert<bool(expr)>
739b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
740b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   instead, these compilers will refuse to compile
741b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
742b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
743b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
744b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   (They seem to think the ">" in "5 > 0" marks the end of the
745b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   template argument list.)
746b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
747b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// - The array size is (bool(expr) ? 1 : -1), instead of simply
748b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
749b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//     ((expr) ? 1 : -1).
750b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
751b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   This is to avoid running into a bug in MS VC 7.1, which
752b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
753b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
754b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
755b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
756b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// This template is declared, but intentionally undefined.
757b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtemplate <typename T1, typename T2>
758b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadstruct StaticAssertTypeEqHelper;
759b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
760b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtemplate <typename T>
761b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadstruct StaticAssertTypeEqHelper<T, T> {};
762b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
763b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if GTEST_HAS_GLOBAL_STRING
764b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtypedef ::string string;
765b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#else
766b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtypedef ::std::string string;
767b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif  // GTEST_HAS_GLOBAL_STRING
768b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
769b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if GTEST_HAS_GLOBAL_WSTRING
770b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtypedef ::wstring wstring;
771b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#elif GTEST_HAS_STD_WSTRING
772b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtypedef ::std::wstring wstring;
773b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif  // GTEST_HAS_GLOBAL_WSTRING
7747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
775190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// A helper for suppressing warnings on constant condition.  It just
776190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// returns 'condition'.
77757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin KramerGTEST_API_ bool IsTrue(bool condition);
778190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
7797ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Defines scoped_ptr.
7807ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
7817ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// This implementation of scoped_ptr is PARTIAL - it only contains
7827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// enough stuff to satisfy Google Test's need.
7837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmantemplate <typename T>
7847ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmanclass scoped_ptr {
7857ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman public:
78657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  typedef T element_type;
78757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
7887ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
7897ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  ~scoped_ptr() { reset(); }
7907ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
7917ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  T& operator*() const { return *ptr_; }
7927ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  T* operator->() const { return ptr_; }
7937ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  T* get() const { return ptr_; }
7947ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
7957ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  T* release() {
7967ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    T* const ptr = ptr_;
7977ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    ptr_ = NULL;
7987ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    return ptr;
7997ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  }
8007ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8017ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  void reset(T* p = NULL) {
8027ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    if (p != ptr_) {
803190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer      if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
8047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman        delete ptr_;
8057ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      }
8067ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      ptr_ = p;
8077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    }
8087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  }
8097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman private:
8107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  T* ptr_;
8117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
8137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman};
8147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Defines RE.
8167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
81757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
8187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Regular Expression syntax.
81957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ RE {
8207ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman public:
82157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // A copy constructor is required by the Standard to initialize object
82257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // references from r-values.
82357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  RE(const RE& other) { Init(other.pattern()); }
82457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
8257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Constructs an RE from a string.
8267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
8277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#if GTEST_HAS_GLOBAL_STRING
829b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
8307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
831b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
8327ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_GLOBAL_STRING
8337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  RE(const char* regex) { Init(regex); }  // NOLINT
8357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  ~RE();
8367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Returns the string representation of the regex.
8387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  const char* pattern() const { return pattern_; }
8397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
84094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // FullMatch(str, re) returns true iff regular expression re matches
8417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // the entire str.
84294c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // PartialMatch(str, re) returns true iff regular expression re
8437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // matches a substring of str (including str itself).
8447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
8457ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // TODO(wan@google.com): make FullMatch() and PartialMatch() work
8467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // when str contains NUL characters.
8477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool FullMatch(const ::std::string& str, const RE& re) {
8487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    return FullMatch(str.c_str(), re);
8497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  }
8507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool PartialMatch(const ::std::string& str, const RE& re) {
8517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    return PartialMatch(str.c_str(), re);
8527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  }
8537ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8547ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#if GTEST_HAS_GLOBAL_STRING
855b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
8567ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool FullMatch(const ::string& str, const RE& re) {
8577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    return FullMatch(str.c_str(), re);
8587ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  }
8597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool PartialMatch(const ::string& str, const RE& re) {
8607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman    return PartialMatch(str.c_str(), re);
8617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  }
862b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
8637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_GLOBAL_STRING
8647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8657ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool FullMatch(const char* str, const RE& re);
8667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool PartialMatch(const char* str, const RE& re);
8677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8687ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman private:
8697ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  void Init(const char* regex);
8707ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
8717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // We use a const char* instead of a string, as Google Test may be used
8727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // where string is not available.  We also do not use Google Test's own
8737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // String type here, in order to simplify dependencies between the
8747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // files.
8757ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  const char* pattern_;
876e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer  bool is_valid_;
877b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
878e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#if GTEST_USES_POSIX_RE
879b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
8807ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  regex_t full_regex_;     // For FullMatch().
8817ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  regex_t partial_regex_;  // For PartialMatch().
882b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
883e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#else  // GTEST_USES_SIMPLE_RE
884b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
885e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer  const char* full_pattern_;  // For FullMatch();
886b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
887e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#endif
8887ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
88957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  GTEST_DISALLOW_ASSIGN_(RE);
890e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer};
8917ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
892b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Formats a source file path and a line number as they would appear
893b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// in an error message from the compiler used to compile this code.
894b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay FoadGTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
895b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
896b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Formats a file location for compiler-independent XML output.
897b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Although this function is not platform dependent, we put it next to
898b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// FormatFileLocation in order to contrast the two functions.
899b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay FoadGTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
900b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad                                                               int line);
901b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
9027ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Defines logging utilities:
903190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//   GTEST_LOG_(severity) - logs messages at the specified severity level. The
904190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//                          message itself is streamed into the macro.
9057ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   LogToStderr()  - directs all log messages to stderr.
9067ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   FlushInfoLog() - flushes informational log messages.
9077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
9087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmanenum GTestLogSeverity {
9097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_INFO,
9107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_WARNING,
9117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_ERROR,
9127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_FATAL
9137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman};
9147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
915190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Formats log entry severity, provides a stream object for streaming the
916190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// log message, and terminates the message with a newline when going out of
917190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// scope.
91857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ GTestLog {
919190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
920190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  GTestLog(GTestLogSeverity severity, const char* file, int line);
9217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
922190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
923190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  ~GTestLog();
924190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
925190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  ::std::ostream& GetStream() { return ::std::cerr; }
926190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
927190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer private:
928190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const GTestLogSeverity severity_;
929190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
930190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
931190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer};
932190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
933190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer#define GTEST_LOG_(severity) \
934190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
935190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                                  __FILE__, __LINE__).GetStream()
9367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
9377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmaninline void LogToStderr() {}
9387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmaninline void FlushInfoLog() { fflush(NULL); }
9397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
94057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// INTERNAL IMPLEMENTATION - DO NOT USE.
94157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
94257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
94357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// is not satisfied.
94457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//  Synopsys:
94557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    GTEST_CHECK_(boolean_condition);
94657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     or
94757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    GTEST_CHECK_(boolean_condition) << "Additional message";
94857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
94957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    This checks the condition and if the condition is not satisfied
95057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    it prints message about the condition violation, including the
95157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    condition itself, plus additional message streamed into it, if any,
95257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    and then it aborts the program. It aborts the program irrespective of
95357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//    whether it is built in the debug mode or not.
95457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#define GTEST_CHECK_(condition) \
95557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
95657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    if (::testing::internal::IsTrue(condition)) \
95757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer      ; \
95857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    else \
95957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer      GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
96057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
96157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// An all-mode assert to verify that the given POSIX-style function
96257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// call returns 0 (indicating success).  Known limitation: this
96357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// doesn't expand to a balanced 'if' statement, so enclose the macro
96457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// in {} if you need to use it as the only statement in an 'if'
96557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// branch.
96657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
96757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  if (const int gtest_error = (posix_call)) \
96857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
96957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer                      << gtest_error
97057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
97157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
97257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
973b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// Use ImplicitCast_ as a safe version of static_cast for upcasting in
974b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
975b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// const Foo*).  When you use ImplicitCast_, the compiler checks that
976b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// the cast is safe.  Such explicit ImplicitCast_s are necessary in
977b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// surprisingly many situations where C++ demands an exact type match
978b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// instead of an argument type convertable to a target type.
979b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
980b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// The syntax for using ImplicitCast_ is the same as for static_cast:
981b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
982b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//   ImplicitCast_<ToType>(expr)
983b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
984b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// ImplicitCast_ would have been part of the C++ standard library,
985b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// but the proposal was submitted too late.  It will probably make
986b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// its way into the language in the future.
987b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
988b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// This relatively ugly name is intentional. It prevents clashes with
989b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// similar functions users may have (e.g., implicit_cast). The internal
990b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// namespace alone is not enough because the function can be found by ADL.
991b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtemplate<typename To>
992b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadinline To ImplicitCast_(To x) { return x; }
993b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
994b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// When you upcast (that is, cast a pointer from type Foo to type
995b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
996b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// always succeed.  When you downcast (that is, cast a pointer from
997b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
998b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// how do you know the pointer is really of type SubclassOfFoo?  It
999b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
1000b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// when you downcast, you should use this macro.  In debug mode, we
1001b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// use dynamic_cast<> to double-check the downcast is legal (we die
1002b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// if it's not).  In normal mode, we do the efficient static_cast<>
1003b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// instead.  Thus, it's important to test in debug mode to make sure
1004b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// the cast is legal!
1005b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//    This is the only place in the code we should use dynamic_cast<>.
1006b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// In particular, you SHOULDN'T be using dynamic_cast<> in order to
1007b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// do RTTI (eg code like this:
1008b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
1009b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
1010b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// You should design the code some other way not to need this.
1011b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad//
1012b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// This relatively ugly name is intentional. It prevents clashes with
1013b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// similar functions users may have (e.g., down_cast). The internal
1014b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// namespace alone is not enough because the function can be found by ADL.
1015b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadtemplate<typename To, typename From>  // use like this: DownCast_<T*>(foo);
1016b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadinline To DownCast_(From* f) {  // so we only accept pointers
1017b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Ensures that To is a sub-type of From *.  This test is here only
1018b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // for compile-time type checking, and has no overhead in an
1019b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // optimized build at run-time, as it will be optimized away
1020b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // completely.
1021b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  if (false) {
1022b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    const To to = NULL;
1023b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    ::testing::internal::ImplicitCast_<From*>(to);
1024b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
1025b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
1026b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#if GTEST_HAS_RTTI
1027b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // RTTI: debug mode only!
1028b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
1029b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#endif
1030b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  return static_cast<To>(f);
1031b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad}
1032b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
103357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Downcasts the pointer of type Base to Derived.
103457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Derived must be a subclass of Base. The parameter MUST
103557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// point to a class of type Derived, not any subclass of it.
103657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// When RTTI is available, the function performs a runtime
103757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// check to enforce this.
103857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramertemplate <class Derived, class Base>
103957240ff6e2252f8986f6e47e4010bc52fbae25d1