13d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Copyright 2005, Google Inc.
23d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// All rights reserved.
33d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
43d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Redistribution and use in source and binary forms, with or without
53d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// modification, are permitted provided that the following conditions are
63d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// met:
73d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
83d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     * Redistributions of source code must retain the above copyright
93d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// notice, this list of conditions and the following disclaimer.
103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     * Redistributions in binary form must reproduce the above
113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// copyright notice, this list of conditions and the following disclaimer
123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in the documentation and/or other materials provided with the
133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// distribution.
143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     * Neither the name of Google Inc. nor the names of its
153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// contributors may be used to endorse or promote products derived from
163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this software without specific prior written permission.
173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Authors: wan@google.com (Zhanyong Wan)
313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Low-level types and utilities for porting Google Test to various
333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// platforms.  They are subject to change without notice.  DO NOT USE
343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THEM IN USER CODE.
353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user can define the following macros in the build script to
403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// control Google Test's behavior.  If the user doesn't define a macro
413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in this list, Google Test will define it.
423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              is/isn't available.
453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              are enabled.
473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              is/isn't available (some systems define
493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              ::string, which is different to std::string).
503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              is/isn't available (some systems define
523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              ::wstring, which is different to std::wstring).
533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              expressions are/aren't available.
553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              is/isn't available.
573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              enabled.
593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              std::wstring does/doesn't work (Google Test can
613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              be used where std::wstring is unavailable).
623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              is/isn't available.
643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              compiler supports Microsoft's "Structured
663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              Exception Handling".
673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_STREAM_REDIRECTION
683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            - Define it to 1/0 to indicate whether the
693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              platform supports I/O stream redirection using
703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              dup() and dup2().
713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              Test's own tr1 tuple implementation should be
733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              used.  Unused when the user sets
743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              GTEST_HAS_TR1_TUPLE to 0.
753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_LINKED_AS_SHARED_LIBRARY
763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            - Define to 1 when compiling tests that use
773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              Google Test as a shared library (known as
783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              DLL on Windows).
793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_CREATE_SHARED_LIBRARY
803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            - Define to 1 when compiling Google Test itself
813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              as a shared library.
823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This header defines the following utilities:
843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Macros indicating the current platform (defined to 1 if compiled on
863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the given platform; otherwise undefined):
873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_AIX      - IBM AIX
883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_CYGWIN   - Cygwin
893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_HPUX     - HP-UX
903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_LINUX    - Linux
913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     GTEST_OS_LINUX_ANDROID - Google Android
923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_MAC      - Mac OS X
933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_NACL     - Google Native Client (NaCl)
943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_SOLARIS  - Sun Solaris
953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_SYMBIAN  - Symbian
963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     GTEST_OS_WINDOWS_MINGW    - MinGW
993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
1003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_OS_ZOS      - z/OS
1013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
1033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// most stable support.  Since core members of the Google Test project
1043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// don't have access to other platforms, support for them may be less
1053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// stable.  If you notice any problems on your platform, please notify
1063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// googletestframework@googlegroups.com (patches for fixing them are
1073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// even more welcome!).
1083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Note that it is possible that none of the GTEST_OS_* macros are defined.
1103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Macros indicating available Google Test features (defined to 1 if
1123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the corresponding feature is supported; otherwise undefined):
1133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
1143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            tests)
1153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_DEATH_TEST   - death tests
1163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_PARAM_TEST   - value-parameterized tests
1173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_TYPED_TEST   - typed tests
1183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
1193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
1203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            GTEST_HAS_POSIX_RE (see above) which users can
1213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            define themselves.
1223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
1233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                            the above two are mutually exclusive.
1243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
1253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Macros for basic C++ coding:
1273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
1283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
1293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                              variable don't have to be used.
1303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_DISALLOW_ASSIGN_   - disables operator=.
1313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
1323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
1333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Synchronization:
1353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Mutex, MutexLock, ThreadLocal, GetThreadCount()
1363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                  - synchronization primitives.
1373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
1383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                         synchronization primitives have real implementations
1393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                         and Google Test is thread-safe; or 0 otherwise.
1403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Template meta programming:
1423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
1433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   IteratorTraits - partial implementation of std::iterator_traits, which
1443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                    is not available in libCstd when compiled with Sun C++.
1453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Smart pointers:
1473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   scoped_ptr     - as in TR2.
1483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Regular expressions:
1503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   RE             - a simple regular expression class using the POSIX
1513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                    Extended Regular Expression syntax on UNIX-like
1523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                    platforms, or a reduced regular exception syntax on
1533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                    other platforms, including Windows.
1543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Logging:
1563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_LOG_()   - logs messages at the specified severity level.
1573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   LogToStderr()  - directs all log messages to stderr.
1583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   FlushInfoLog() - flushes informational log messages.
1593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Stdout and stderr capturing:
1613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   CaptureStdout()     - starts capturing stdout.
1623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GetCapturedStdout() - stops capturing stdout and returns the captured
1633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                         string.
1643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   CaptureStderr()     - starts capturing stderr.
1653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GetCapturedStderr() - stops capturing stderr and returns the captured
1663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                         string.
1673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Integer types:
1693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   TypeWithSize   - maps an integer to a int type.
1703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Int32, UInt32, Int64, UInt64, TimeInMillis
1713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                  - integers of known sizes.
1723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   BiggestInt     - the biggest signed integer type.
1733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Command-line utilities:
1753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_FLAG()       - references a flag.
1763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_DECLARE_*()  - declares a flag.
1773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_DEFINE_*()   - defines a flag.
1783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GetArgvs()         - returns the command line as a vector of strings.
1793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Environment variable utilities:
1813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GetEnv()             - gets the value of an environment variable.
1823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   BoolFromGTestEnv()   - parses a bool environment variable.
1833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Int32FromGTestEnv()  - parses an Int32 environment variable.
1843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   StringFromGTestEnv() - parses a string environment variable.
1853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <ctype.h>   // for isspace, etc
1873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <stddef.h>  // for ptrdiff_t
1883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <stdlib.h>
1893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <stdio.h>
1903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <string.h>
1913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef _WIN32_WCE
1923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <sys/types.h>
1933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <sys/stat.h>
1943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // !_WIN32_WCE
1953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <iostream>  // NOLINT
1973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <sstream>  // NOLINT
1983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <string>  // NOLINT
1993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
2013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_FLAG_PREFIX_ "gtest_"
2023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_FLAG_PREFIX_DASH_ "gtest-"
2033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
2043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_NAME_ "Google Test"
2053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
2063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines the version of gcc that is used to compile this.
2083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef __GNUC__
2093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 40302 means version 4.3.2.
2103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_GCC_VER_ \
2113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
2123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // __GNUC__
2133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines the platform on which Google Test is compiled.
2153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef __CYGWIN__
2163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_CYGWIN 1
2173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined __SYMBIAN32__
2183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_SYMBIAN 1
2193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined _WIN32
2203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_WINDOWS 1
2213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# ifdef _WIN32_WCE
2223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_OS_WINDOWS_MOBILE 1
2233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__MINGW__) || defined(__MINGW32__)
2243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_OS_WINDOWS_MINGW 1
2253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
2263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_OS_WINDOWS_DESKTOP 1
2273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // _WIN32_WCE
2283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined __APPLE__
2293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_MAC 1
2303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined __linux__
2313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_LINUX 1
2323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# ifdef ANDROID
2333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_OS_LINUX_ANDROID 1
2343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // ANDROID
2353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined __MVS__
2363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_ZOS 1
2373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined(__sun) && defined(__SVR4)
2383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_SOLARIS 1
2393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined(_AIX)
2403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_AIX 1
2413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined(__hpux)
2423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_HPUX 1
2433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined __native_client__
2443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_OS_NACL 1
2453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // __CYGWIN__
2463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Brings in definitions for functions used in the testing::internal::posix
2483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// namespace (read, write, close, chdir, isatty, stat). We do not currently
2493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// use them on Windows Mobile.
2503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if !GTEST_OS_WINDOWS
2513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This assumes that non-Windows OSes provide unistd.h. For OSes where this
2523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// is not the case, we need to include headers that provide the functions
2533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// mentioned above.
2543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <unistd.h>
2553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if !GTEST_OS_NACL
2563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TODO(vladl@google.com): Remove this condition when Native Client SDK adds
2573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// strings.h (tracked in
2583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// http://code.google.com/p/nativeclient/issues/detail?id=1175).
2593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  include <strings.h>  // Native Client doesn't provide strings.h.
2603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif
2613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif !GTEST_OS_WINDOWS_MOBILE
2623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <direct.h>
2633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <io.h>
2643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
2653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Defines this to true iff Google Test can use POSIX regular expressions.
2673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_POSIX_RE
2683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
2693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
2703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_POSIX_RE
2723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// On some platforms, <regex.h> needs someone to define size_t, and
2743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// won't compile otherwise.  We can #include it here as we already
2753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// included <stdlib.h>, which is guaranteed to define size_t through
2763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// <stddef.h>.
2773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <regex.h>  // NOLINT
2783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_USES_POSIX_RE 1
2803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif GTEST_OS_WINDOWS
2823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// <regex.h> is not available on Windows.  Use our own simple regex
2843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// implementation instead.
2853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_USES_SIMPLE_RE 1
2863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else
2883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// <regex.h> may not be available on this platform.  Use our own
2903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// simple regex implementation instead.
2913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_USES_SIMPLE_RE 1
2923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_POSIX_RE
2943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_EXCEPTIONS
2963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us whether exceptions are enabled, so we need
2973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to figure it out.
2983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if defined(_MSC_VER) || defined(__BORLANDC__)
2993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
3003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// macro to enable exceptions, so we'll do the same.
3013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Assumes that exceptions are enabled by default.
3023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  ifndef _HAS_EXCEPTIONS
3033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define _HAS_EXCEPTIONS 1
3043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  endif  // _HAS_EXCEPTIONS
3053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
3063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__GNUC__) && __EXCEPTIONS
3073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
3083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_EXCEPTIONS 1
3093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__SUNPRO_CC)
3103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Sun Pro CC supports exceptions.  However, there is no compile-time way of
3113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// detecting whether they are enabled or not.  Therefore, we assume that
3123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// they are enabled unless the user tells us otherwise.
3133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_EXCEPTIONS 1
3143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__IBMCPP__) && __EXCEPTIONS
3153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
3163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_EXCEPTIONS 1
3173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__HP_aCC)
3183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Exception handling is in effect by default in HP aCC compiler. It has to
3193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// be turned of by +noeh compiler option if desired.
3203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_EXCEPTIONS 1
3213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
3223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For other compilers, we assume exceptions are disabled to be
3233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// conservative.
3243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_EXCEPTIONS 0
3253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // defined(_MSC_VER) || defined(__BORLANDC__)
3263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_EXCEPTIONS
3273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if !defined(GTEST_HAS_STD_STRING)
3293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Even though we don't use this macro any longer, we keep it in case
3303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// some clients still depend on it.
3313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_STD_STRING 1
3323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif !GTEST_HAS_STD_STRING
3333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user told us that ::std::string isn't available.
3343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# error "Google Test cannot be used where ::std::string isn't available."
3353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // !defined(GTEST_HAS_STD_STRING)
3363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_GLOBAL_STRING
3383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us whether ::string is available, so we need
3393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to figure it out.
3403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_GLOBAL_STRING 0
3423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_GLOBAL_STRING
3443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_STD_WSTRING
3463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us whether ::std::wstring is available, so we need
3473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to figure it out.
3483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
3493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   is available.
3503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Cygwin 1.7 and below doesn't support ::std::wstring.
3523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Solaris' libc++ doesn't support it either.  Android has
3533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// no support for it at least as recent as Froyo (2.2).
3543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_STD_WSTRING \
3553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
3563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_STD_WSTRING
3583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_GLOBAL_WSTRING
3603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us whether ::wstring is available, so we need
3613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to figure it out.
3623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_GLOBAL_WSTRING \
3633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
3643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_GLOBAL_WSTRING
3653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether RTTI is available.
3673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_RTTI
3683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us whether RTTI is enabled, so we need to
3693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// figure it out.
3703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# ifdef _MSC_VER
3723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
3743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define GTEST_HAS_RTTI 1
3753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  else
3763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define GTEST_HAS_RTTI 0
3773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  endif
3783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
3803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
3813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  ifdef __GXX_RTTI
3833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define GTEST_HAS_RTTI 1
3843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  else
3853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define GTEST_HAS_RTTI 0
3863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  endif  // __GXX_RTTI
3873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
3893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// both the typeid and dynamic_cast features are present.
3903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
3913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  ifdef __RTTI_ALL__
3933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define GTEST_HAS_RTTI 1
3943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  else
3953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define GTEST_HAS_RTTI 0
3963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  endif
3973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
3993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For all other compilers, we assume RTTI is enabled.
4013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_RTTI 1
4023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // _MSC_VER
4043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_RTTI
4063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// It's this header's responsibility to #include <typeinfo> when RTTI
4083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// is enabled.
4093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_RTTI
4103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <typeinfo>
4113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
4123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether Google Test can use the pthreads library.
4143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_PTHREAD
4153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us explicitly, so we assume pthreads support is
4163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// available on Linux and Mac.
4173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
4183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
4193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to your compiler flags.
4203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX)
4213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_PTHREAD
4223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_PTHREAD
4243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
4253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// true.
4263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <pthread.h>  // NOLINT
4273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For timespec and nanosleep, used below.
4293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <time.h>  // NOLINT
4303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
4313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether Google Test can use tr1/tuple.  You can define
4333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this macro to 0 to prevent Google Test from using tuple (any
4343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// feature depending on tuple with be disabled in this mode).
4353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_TR1_TUPLE
4363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us not to do it, so we assume it's OK.
4373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_TR1_TUPLE 1
4383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_TR1_TUPLE
4393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether Google Test's own tr1 tuple implementation
4413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// should be used.
4423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_USE_OWN_TR1_TUPLE
4433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us, so we need to figure it out.
4443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// We use our own TR1 tuple if we aren't sure the user has an
4463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// implementation of it already.  At this time, GCC 4.0.0+ and MSVC
4473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2010 are the only mainstream compilers that come with a TR1 tuple
4483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// implementation.  NVIDIA's CUDA NVCC compiler pretends to be GCC by
4493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// defining __GNUC__ and friends, but cannot compile GCC's tuple
4503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// implementation.  MSVC 2008 (9.0) provides TR1 tuple in a 323 MB
4513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Feature Pack download, which we cannot assume the user has.
4523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \
4533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    || _MSC_VER >= 1600
4543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_USE_OWN_TR1_TUPLE 0
4553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
4563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_USE_OWN_TR1_TUPLE 1
4573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif
4583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_USE_OWN_TR1_TUPLE
4603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// To avoid conditional compilation everywhere, we make it
4623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// gtest-port.h's responsibility to #include the header implementing
4633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// tr1/tuple.
4643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_TR1_TUPLE
4653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if GTEST_USE_OWN_TR1_TUPLE
4673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  include "gtest/internal/gtest-tuple.h"
4683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif GTEST_OS_SYMBIAN
4693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
4713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// use STLport's tuple implementation, which unfortunately doesn't
4723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// work as the copy of STLport distributed with Symbian is incomplete.
4733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
4743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// use its own tuple implementation.
4753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  ifdef BOOST_HAS_TR1_TUPLE
4763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   undef BOOST_HAS_TR1_TUPLE
4773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  endif  // BOOST_HAS_TR1_TUPLE
4783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This prevents <boost/tr1/detail/config.hpp>, which defines
4803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
4813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
4823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  include <tuple>
4833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
4853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
4863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// not conform to the TR1 spec, which requires the header to be <tuple>.
4873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
4893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
4903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// which is #included by <tr1/tuple>, to not compile when RTTI is
4913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// disabled.  _TR1_FUNCTIONAL is the header guard for
4923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// <tr1/functional>.  Hence the following #define is a hack to prevent
4933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// <tr1/functional> from being included.
4943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   define _TR1_FUNCTIONAL 1
4953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   include <tr1/tuple>
4963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   undef _TR1_FUNCTIONAL  // Allows the user to #include
4973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick                        // <tr1/functional> if he chooses to.
4983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  else
4993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#   include <tr1/tuple>  // NOLINT
5003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
5013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
5033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If the compiler is not GCC 4.0+, we assume the user is using a
5043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// spec-conforming TR1 implementation.
5053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  include <tuple>  // NOLINT
5063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // GTEST_USE_OWN_TR1_TUPLE
5073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_TR1_TUPLE
5093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether clone(2) is supported.
5113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Usually it will only be available on Linux, excluding
5123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Linux on the Itanium architecture.
5133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Also see http://linux.die.net/man/2/clone.
5143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_CLONE
5153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us, so we need to figure it out.
5163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if GTEST_OS_LINUX && !defined(__ia64__)
5183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_CLONE 1
5193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
5203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_CLONE 0
5213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // GTEST_OS_LINUX && !defined(__ia64__)
5223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_CLONE
5243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether to support stream redirection. This is used to test
5263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// output correctness and to implement death tests.
5273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_STREAM_REDIRECTION
5283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// By default, we assume that stream redirection is supported on all
5293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// platforms except known mobile ones.
5303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
5313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_STREAM_REDIRECTION 0
5323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
5333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_STREAM_REDIRECTION 1
5343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
5353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_STREAM_REDIRECTION
5363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether to support death tests.
5383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Google Test does not support death tests for VC 7.1 and earlier as
5393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// abort() in a VC 7.1 application compiled as GUI in debug config
5403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// pops up a dialog window that cannot be suppressed programmatically.
5413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
5423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick     (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
5433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)
5443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_DEATH_TEST 1
5453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <vector>  // NOLINT
5463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
5473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// We don't support MSVC 7.1 with exceptions disabled now.  Therefore
5493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// all the compilers we care about are adequate for supporting
5503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// value-parameterized tests.
5513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_HAS_PARAM_TEST 1
5523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether to support type-driven tests.
5543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
5563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Sun Pro CC, IBM Visual Age, and HP aCC support.
5573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
5583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    defined(__IBMCPP__) || defined(__HP_aCC)
5593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_TYPED_TEST 1
5603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_TYPED_TEST_P 1
5613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
5623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether to support Combine(). This only makes sense when
5643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// value-parameterized tests are enabled.  The implementation doesn't
5653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// work on Sun Studio since it doesn't understand templated conversion
5663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// operators.
5673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
5683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_HAS_COMBINE 1
5693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
5703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether the system compiler uses UTF-16 for encoding wide strings.
5723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_WIDE_STRING_USES_UTF16_ \
5733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
5743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determines whether test results can be streamed to a socket.
5763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_OS_LINUX
5773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_CAN_STREAM_RESULTS_ 1
5783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
5793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Defines some utility macros.
5813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The GNU compiler emits a warning if nested "if" statements are followed by
5833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// an "else" statement and braces are not used to explicitly disambiguate the
5843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "else" binding.  This leads to problems with code like:
5853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
5863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   if (gate)
5873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     ASSERT_*(condition) << "Some message";
5883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
5893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The "switch (0) case 0:" idiom is used to suppress this.
5903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef __INTEL_COMPILER
5913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
5923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else
5933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
5943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
5953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Use this annotation at the end of a struct/class definition to
5973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// prevent the compiler from optimizing away instances that are never
5983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// used.  This is useful when all interesting logic happens inside the
5993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// c'tor and / or d'tor.  Example:
6003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   struct Foo {
6023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     Foo() { ... }
6033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   } GTEST_ATTRIBUTE_UNUSED_;
6043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Also use it after a variable or parameter declaration to tell the
6063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compiler the variable/parameter does not have to be used.
6073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if defined(__GNUC__) && !defined(COMPILER_ICC)
6083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
6093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else
6103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_ATTRIBUTE_UNUSED_
6113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
6123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A macro to disallow operator=
6143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This should be used in the private: declarations for a class.
6153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_DISALLOW_ASSIGN_(type)\
6163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void operator=(type const &)
6173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A macro to disallow copy constructor and operator=
6193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This should be used in the private: declarations for a class.
6203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
6213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  type(type const &);\
6223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  GTEST_DISALLOW_ASSIGN_(type)
6233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Tell the compiler to warn about unused return values for functions declared
6253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// with this macro.  The macro should be used on function declarations
6263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// following the argument list:
6273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
6293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
6303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
6313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else
6323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_MUST_USE_RESULT_
6333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
6343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Determine whether the compiler supports Microsoft's Structured Exception
6363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Handling.  This is supported by several Windows compilers but generally
6373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// does not exist on any other system.
6383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_HAS_SEH
6393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user didn't tell us, so we need to figure it out.
6403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if defined(_MSC_VER) || defined(__BORLANDC__)
6423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// These two compilers are known to support SEH.
6433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_SEH 1
6443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# else
6453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Assume no SEH.
6463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_HAS_SEH 0
6473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif
6483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_SEH
6503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef _MSC_VER
6523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# if GTEST_LINKED_AS_SHARED_LIBRARY
6543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_API_ __declspec(dllimport)
6553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# elif GTEST_CREATE_SHARED_LIBRARY
6563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#  define GTEST_API_ __declspec(dllexport)
6573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# endif
6583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // _MSC_VER
6603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_API_
6623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_API_
6633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
6643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef __GNUC__
6663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Ask the compiler to never inline a given function.
6673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_NO_INLINE_ __attribute__((noinline))
6683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else
6693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_NO_INLINE_
6703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif
6713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace testing {
6733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass Message;
6753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace internal {
6773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass String;
6793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
6813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// expression is true. For example, you could use it to verify the
6823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// size of a static array:
6833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
6853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                         content_type_names_incorrect_size);
6863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// or to make sure a struct is smaller than a certain size:
6883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
6903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The second argument to the macro is the name of the variable. If
6923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the expression is false, most compilers will issue a warning/error
6933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// containing the name of the variable.
6943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <bool>
6963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct CompileAssert {
6973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};
6983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_COMPILE_ASSERT_(expr, msg) \
7003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  typedef ::testing::internal::CompileAssert<(bool(expr))> \
7013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      msg[bool(expr) ? 1 : -1]
7023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Implementation details of GTEST_COMPILE_ASSERT_:
7043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
7063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   elements (and thus is invalid) when the expression is false.
7073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - The simpler definition
7093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
7113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   does not work, as gcc supports variable-length arrays whose sizes
7133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   are determined at run-time (this is gcc's extension and not part
7143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   of the C++ standard).  As a result, gcc fails to reject the
7153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   following code with the simple definition:
7163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     int foo;
7183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
7193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//                                      // not a compile-time constant.
7203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - By using the type CompileAssert<(bool(expr))>, we ensures that
7223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   expr is a compile-time constant.  (Template arguments must be
7233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   determined at compile-time.)
7243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
7263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
7273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     CompileAssert<bool(expr)>
7293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   instead, these compilers will refuse to compile
7313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
7333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   (They seem to think the ">" in "5 > 0" marks the end of the
7353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   template argument list.)
7363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - The array size is (bool(expr) ? 1 : -1), instead of simply
7383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     ((expr) ? 1 : -1).
7403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   This is to avoid running into a bug in MS VC 7.1, which
7423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
7433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
7453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This template is declared, but intentionally undefined.
7473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T1, typename T2>
7483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct StaticAssertTypeEqHelper;
7493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T>
7513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct StaticAssertTypeEqHelper<T, T> {};
7523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_GLOBAL_STRING
7543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef ::string string;
7553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else
7563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef ::std::string string;
7573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_GLOBAL_STRING
7583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_GLOBAL_WSTRING
7603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef ::wstring wstring;
7613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif GTEST_HAS_STD_WSTRING
7623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef ::std::wstring wstring;
7633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_GLOBAL_WSTRING
7643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A helper for suppressing warnings on constant condition.  It just
7663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// returns 'condition'.
7673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ bool IsTrue(bool condition);
7683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Defines scoped_ptr.
7703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This implementation of scoped_ptr is PARTIAL - it only contains
7723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// enough stuff to satisfy Google Test's need.
7733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T>
7743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass scoped_ptr {
7753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
7763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  typedef T element_type;
7773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
7793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  ~scoped_ptr() { reset(); }
7803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  T& operator*() const { return *ptr_; }
7823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  T* operator->() const { return ptr_; }
7833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  T* get() const { return ptr_; }
7843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  T* release() {
7863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    T* const ptr = ptr_;
7873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    ptr_ = NULL;
7883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return ptr;
7893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
7903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void reset(T* p = NULL) {
7923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    if (p != ptr_) {
7933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
7943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick        delete ptr_;
7953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      }
7963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      ptr_ = p;
7973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    }
7983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
7993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
8003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  T* ptr_;
8013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
8033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};
8043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Defines RE.
8063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
8083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Regular Expression syntax.
8093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ RE {
8103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
8113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // A copy constructor is required by the Standard to initialize object
8123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // references from r-values.
8133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  RE(const RE& other) { Init(other.pattern()); }
8143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Constructs an RE from a string.
8163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
8173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_GLOBAL_STRING
8193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
8213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_GLOBAL_STRING
8233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  RE(const char* regex) { Init(regex); }  // NOLINT
8253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  ~RE();
8263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the string representation of the regex.
8283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* pattern() const { return pattern_; }
8293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // FullMatch(str, re) returns true iff regular expression re matches
8313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // the entire str.
8323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // PartialMatch(str, re) returns true iff regular expression re
8333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // matches a substring of str (including str itself).
8343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
8353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // TODO(wan@google.com): make FullMatch() and PartialMatch() work
8363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // when str contains NUL characters.
8373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool FullMatch(const ::std::string& str, const RE& re) {
8383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return FullMatch(str.c_str(), re);
8393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool PartialMatch(const ::std::string& str, const RE& re) {
8413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return PartialMatch(str.c_str(), re);
8423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_GLOBAL_STRING
8453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool FullMatch(const ::string& str, const RE& re) {
8473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return FullMatch(str.c_str(), re);
8483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool PartialMatch(const ::string& str, const RE& re) {
8503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return PartialMatch(str.c_str(), re);
8513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_GLOBAL_STRING
8543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool FullMatch(const char* str, const RE& re);
8563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool PartialMatch(const char* str, const RE& re);
8573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
8593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void Init(const char* regex);
8603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // We use a const char* instead of a string, as Google Test may be used
8623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // where string is not available.  We also do not use Google Test's own
8633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // String type here, in order to simplify dependencies between the
8643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // files.
8653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* pattern_;
8663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool is_valid_;
8673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_USES_POSIX_RE
8693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  regex_t full_regex_;     // For FullMatch().
8713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  regex_t partial_regex_;  // For PartialMatch().
8723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else  // GTEST_USES_SIMPLE_RE
8743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
875