1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright 2005, Google Inc.
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// All rights reserved.
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Redistribution and use in source and binary forms, with or without
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// modification, are permitted provided that the following conditions are
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// met:
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     * Redistributions of source code must retain the above copyright
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// notice, this list of conditions and the following disclaimer.
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     * Redistributions in binary form must reproduce the above
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// copyright notice, this list of conditions and the following disclaimer
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in the documentation and/or other materials provided with the
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// distribution.
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     * Neither the name of Google Inc. nor the names of its
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// contributors may be used to endorse or promote products derived from
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// this software without specific prior written permission.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Authors: wan@google.com (Zhanyong Wan)
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Low-level types and utilities for porting Google Test to various
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// platforms.  They are subject to change without notice.  DO NOT USE
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THEM IN USER CODE.
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user can define the following macros in the build script to
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// control Google Test's behavior.  If the user doesn't define a macro
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in this list, Google Test will define it.
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              is/isn't available.
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              are enabled.
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              is/isn't available (some systems define
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              ::string, which is different to std::string).
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              is/isn't available (some systems define
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              ::wstring, which is different to std::wstring).
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              expressions are/aren't available.
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              is/isn't available.
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              enabled.
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              std::wstring does/doesn't work (Google Test can
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              be used where std::wstring is unavailable).
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              is/isn't available.
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              compiler supports Microsoft's "Structured
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              Exception Handling".
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_STREAM_REDIRECTION
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            - Define it to 1/0 to indicate whether the
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              platform supports I/O stream redirection using
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              dup() and dup2().
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              Test's own tr1 tuple implementation should be
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              used.  Unused when the user sets
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              GTEST_HAS_TR1_TUPLE to 0.
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_LINKED_AS_SHARED_LIBRARY
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            - Define to 1 when compiling tests that use
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              Google Test as a shared library (known as
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              DLL on Windows).
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_CREATE_SHARED_LIBRARY
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            - Define to 1 when compiling Google Test itself
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              as a shared library.
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This header defines the following utilities:
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros indicating the current platform (defined to 1 if compiled on
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the given platform; otherwise undefined):
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_AIX      - IBM AIX
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_CYGWIN   - Cygwin
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_HPUX     - HP-UX
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_LINUX    - Linux
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     GTEST_OS_LINUX_ANDROID - Google Android
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_MAC      - Mac OS X
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_NACL     - Google Native Client (NaCl)
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_SOLARIS  - Sun Solaris
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_SYMBIAN  - Symbian
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     GTEST_OS_WINDOWS_MINGW    - MinGW
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_OS_ZOS      - z/OS
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// most stable support.  Since core members of the Google Test project
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// don't have access to other platforms, support for them may be less
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// stable.  If you notice any problems on your platform, please notify
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// googletestframework@googlegroups.com (patches for fixing them are
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// even more welcome!).
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Note that it is possible that none of the GTEST_OS_* macros are defined.
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros indicating available Google Test features (defined to 1 if
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the corresponding feature is supported; otherwise undefined):
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            tests)
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_DEATH_TEST   - death tests
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_PARAM_TEST   - value-parameterized tests
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_TYPED_TEST   - typed tests
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            GTEST_HAS_POSIX_RE (see above) which users can
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            define themselves.
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            the above two are mutually exclusive.
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for basic C++ coding:
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                              variable don't have to be used.
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_DISALLOW_ASSIGN_   - disables operator=.
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Synchronization:
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Mutex, MutexLock, ThreadLocal, GetThreadCount()
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                  - synchronization primitives.
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                         synchronization primitives have real implementations
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                         and Google Test is thread-safe; or 0 otherwise.
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Template meta programming:
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   IteratorTraits - partial implementation of std::iterator_traits, which
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                    is not available in libCstd when compiled with Sun C++.
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Smart pointers:
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   scoped_ptr     - as in TR2.
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Regular expressions:
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   RE             - a simple regular expression class using the POSIX
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                    Extended Regular Expression syntax on UNIX-like
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                    platforms, or a reduced regular exception syntax on
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                    other platforms, including Windows.
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Logging:
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_LOG_()   - logs messages at the specified severity level.
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   LogToStderr()  - directs all log messages to stderr.
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   FlushInfoLog() - flushes informational log messages.
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Stdout and stderr capturing:
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   CaptureStdout()     - starts capturing stdout.
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GetCapturedStdout() - stops capturing stdout and returns the captured
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                         string.
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   CaptureStderr()     - starts capturing stderr.
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GetCapturedStderr() - stops capturing stderr and returns the captured
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                         string.
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Integer types:
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TypeWithSize   - maps an integer to a int type.
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Int32, UInt32, Int64, UInt64, TimeInMillis
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                  - integers of known sizes.
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   BiggestInt     - the biggest signed integer type.
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Command-line utilities:
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_FLAG()       - references a flag.
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_DECLARE_*()  - declares a flag.
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_DEFINE_*()   - defines a flag.
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GetArgvs()         - returns the command line as a vector of strings.
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Environment variable utilities:
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GetEnv()             - gets the value of an environment variable.
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   BoolFromGTestEnv()   - parses a bool environment variable.
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Int32FromGTestEnv()  - parses an Int32 environment variable.
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   StringFromGTestEnv() - parses a string environment variable.
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <ctype.h>   // for isspace, etc
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stddef.h>  // for ptrdiff_t
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdlib.h>
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdio.h>
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string.h>
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef _WIN32_WCE
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <sys/types.h>
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <sys/stat.h>
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // !_WIN32_WCE
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <iostream>  // NOLINT
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <sstream>  // NOLINT
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string>  // NOLINT
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_FLAG_PREFIX_ "gtest_"
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_FLAG_PREFIX_DASH_ "gtest-"
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_NAME_ "Google Test"
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines the version of gcc that is used to compile this.
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __GNUC__
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// 40302 means version 4.3.2.
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_GCC_VER_ \
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // __GNUC__
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines the platform on which Google Test is compiled.
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __CYGWIN__
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_CYGWIN 1
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined __SYMBIAN32__
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_SYMBIAN 1
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined _WIN32
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_WINDOWS 1
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# ifdef _WIN32_WCE
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_OS_WINDOWS_MOBILE 1
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__MINGW__) || defined(__MINGW32__)
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_OS_WINDOWS_MINGW 1
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_OS_WINDOWS_DESKTOP 1
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // _WIN32_WCE
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined __APPLE__
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_MAC 1
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined __linux__
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_LINUX 1
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# ifdef ANDROID
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_OS_LINUX_ANDROID 1
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // ANDROID
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined __MVS__
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_ZOS 1
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(__sun) && defined(__SVR4)
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_SOLARIS 1
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(_AIX)
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_AIX 1
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(__hpux)
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_HPUX 1
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined __native_client__
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_OS_NACL 1
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // __CYGWIN__
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Brings in definitions for functions used in the testing::internal::posix
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// namespace (read, write, close, chdir, isatty, stat). We do not currently
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// use them on Windows Mobile.
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_OS_WINDOWS
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This assumes that non-Windows OSes provide unistd.h. For OSes where this
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is not the case, we need to include headers that provide the functions
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// mentioned above.
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <unistd.h>
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if !GTEST_OS_NACL
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TODO(vladl@google.com): Remove this condition when Native Client SDK adds
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// strings.h (tracked in
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// http://code.google.com/p/nativeclient/issues/detail?id=1175).
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  include <strings.h>  // Native Client doesn't provide strings.h.
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif !GTEST_OS_WINDOWS_MOBILE
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <direct.h>
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <io.h>
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines this to true iff Google Test can use POSIX regular expressions.
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_POSIX_RE
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_POSIX_RE
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// On some platforms, <regex.h> needs someone to define size_t, and
274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// won't compile otherwise.  We can #include it here as we already
275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// included <stdlib.h>, which is guaranteed to define size_t through
276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// <stddef.h>.
277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <regex.h>  // NOLINT
278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_USES_POSIX_RE 1
280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif GTEST_OS_WINDOWS
282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// <regex.h> is not available on Windows.  Use our own simple regex
284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// implementation instead.
285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_USES_SIMPLE_RE 1
286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// <regex.h> may not be available on this platform.  Use our own
290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// simple regex implementation instead.
291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_USES_SIMPLE_RE 1
292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_POSIX_RE
294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_EXCEPTIONS
296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us whether exceptions are enabled, so we need
297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to figure it out.
298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if defined(_MSC_VER) || defined(__BORLANDC__)
299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// macro to enable exceptions, so we'll do the same.
301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Assumes that exceptions are enabled by default.
302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  ifndef _HAS_EXCEPTIONS
303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define _HAS_EXCEPTIONS 1
304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif  // _HAS_EXCEPTIONS
305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__GNUC__) && __EXCEPTIONS
307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_EXCEPTIONS 1
309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__SUNPRO_CC)
310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Sun Pro CC supports exceptions.  However, there is no compile-time way of
311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// detecting whether they are enabled or not.  Therefore, we assume that
312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// they are enabled unless the user tells us otherwise.
313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_EXCEPTIONS 1
314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__IBMCPP__) && __EXCEPTIONS
315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_EXCEPTIONS 1
317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__HP_aCC)
318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Exception handling is in effect by default in HP aCC compiler. It has to
319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// be turned of by +noeh compiler option if desired.
320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_EXCEPTIONS 1
321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For other compilers, we assume exceptions are disabled to be
323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// conservative.
324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_EXCEPTIONS 0
325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // defined(_MSC_VER) || defined(__BORLANDC__)
326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_EXCEPTIONS
327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(GTEST_HAS_STD_STRING)
329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Even though we don't use this macro any longer, we keep it in case
330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// some clients still depend on it.
331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_STD_STRING 1
332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif !GTEST_HAS_STD_STRING
333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user told us that ::std::string isn't available.
334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# error "Google Test cannot be used where ::std::string isn't available."
335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // !defined(GTEST_HAS_STD_STRING)
336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_GLOBAL_STRING
338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us whether ::string is available, so we need
339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to figure it out.
340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_GLOBAL_STRING 0
342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_GLOBAL_STRING
344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_STD_WSTRING
346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us whether ::std::wstring is available, so we need
347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to figure it out.
348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   is available.
350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Cygwin 1.7 and below doesn't support ::std::wstring.
352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Solaris' libc++ doesn't support it either.  Android has
353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// no support for it at least as recent as Froyo (2.2).
354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_STD_WSTRING \
355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_STD_WSTRING
358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_GLOBAL_WSTRING
360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us whether ::wstring is available, so we need
361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to figure it out.
362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_GLOBAL_WSTRING \
363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_GLOBAL_WSTRING
365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether RTTI is available.
367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_RTTI
368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us whether RTTI is enabled, so we need to
369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// figure it out.
370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# ifdef _MSC_VER
372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define GTEST_HAS_RTTI 1
375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  else
376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define GTEST_HAS_RTTI 0
377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif
378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  ifdef __GXX_RTTI
383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define GTEST_HAS_RTTI 1
384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  else
385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define GTEST_HAS_RTTI 0
386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif  // __GXX_RTTI
387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// both the typeid and dynamic_cast features are present.
390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  ifdef __RTTI_ALL__
393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define GTEST_HAS_RTTI 1
394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  else
395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define GTEST_HAS_RTTI 0
396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif
397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For all other compilers, we assume RTTI is enabled.
401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_RTTI 1
402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // _MSC_VER
404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_RTTI
406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// It's this header's responsibility to #include <typeinfo> when RTTI
408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is enabled.
409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_RTTI
410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <typeinfo>
411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether Google Test can use the pthreads library.
414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_PTHREAD
415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us explicitly, so we assume pthreads support is
416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// available on Linux and Mac.
417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to your compiler flags.
420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX)
421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_PTHREAD
422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_PTHREAD
424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// true.
426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <pthread.h>  // NOLINT
427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For timespec and nanosleep, used below.
429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <time.h>  // NOLINT
430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether Google Test can use tr1/tuple.  You can define
433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// this macro to 0 to prevent Google Test from using tuple (any
434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// feature depending on tuple with be disabled in this mode).
435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_TR1_TUPLE
436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us not to do it, so we assume it's OK.
437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_TR1_TUPLE 1
438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_TR1_TUPLE
439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether Google Test's own tr1 tuple implementation
441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// should be used.
442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_USE_OWN_TR1_TUPLE
443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us, so we need to figure it out.
444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// We use our own TR1 tuple if we aren't sure the user has an
446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// implementation of it already.  At this time, GCC 4.0.0+ and MSVC
447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// 2010 are the only mainstream compilers that come with a TR1 tuple
448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// implementation.  NVIDIA's CUDA NVCC compiler pretends to be GCC by
449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// defining __GNUC__ and friends, but cannot compile GCC's tuple
450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// implementation.  MSVC 2008 (9.0) provides TR1 tuple in a 323 MB
451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Feature Pack download, which we cannot assume the user has.
452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \
453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    || _MSC_VER >= 1600
454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_USE_OWN_TR1_TUPLE 0
455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_USE_OWN_TR1_TUPLE 1
457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif
458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_USE_OWN_TR1_TUPLE
460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// To avoid conditional compilation everywhere, we make it
462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// gtest-port.h's responsibility to #include the header implementing
463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// tr1/tuple.
464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_TR1_TUPLE
465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if GTEST_USE_OWN_TR1_TUPLE
467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  include "gtest/internal/gtest-tuple.h"
468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif GTEST_OS_SYMBIAN
469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// use STLport's tuple implementation, which unfortunately doesn't
472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// work as the copy of STLport distributed with Symbian is incomplete.
473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// use its own tuple implementation.
475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  ifdef BOOST_HAS_TR1_TUPLE
476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   undef BOOST_HAS_TR1_TUPLE
477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif  // BOOST_HAS_TR1_TUPLE
478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This prevents <boost/tr1/detail/config.hpp>, which defines
480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  include <tuple>
483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// not conform to the TR1 spec, which requires the header to be <tuple>.
487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// which is #included by <tr1/tuple>, to not compile when RTTI is
491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// disabled.  _TR1_FUNCTIONAL is the header guard for
492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// <tr1/functional>.  Hence the following #define is a hack to prevent
493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// <tr1/functional> from being included.
494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   define _TR1_FUNCTIONAL 1
495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   include <tr1/tuple>
496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   undef _TR1_FUNCTIONAL  // Allows the user to #include
497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        // <tr1/functional> if he chooses to.
498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  else
499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#   include <tr1/tuple>  // NOLINT
500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// If the compiler is not GCC 4.0+, we assume the user is using a
504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// spec-conforming TR1 implementation.
505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  include <tuple>  // NOLINT
506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // GTEST_USE_OWN_TR1_TUPLE
507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_TR1_TUPLE
509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether clone(2) is supported.
511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Usually it will only be available on Linux, excluding
512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Linux on the Itanium architecture.
513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Also see http://linux.die.net/man/2/clone.
514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_CLONE
515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us, so we need to figure it out.
516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if GTEST_OS_LINUX && !defined(__ia64__)
518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_CLONE 1
519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_CLONE 0
521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // GTEST_OS_LINUX && !defined(__ia64__)
522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_CLONE
524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether to support stream redirection. This is used to test
526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// output correctness and to implement death tests.
527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_STREAM_REDIRECTION
528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// By default, we assume that stream redirection is supported on all
529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// platforms except known mobile ones.
530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_STREAM_REDIRECTION 0
532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_STREAM_REDIRECTION 1
534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_STREAM_REDIRECTION
536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether to support death tests.
538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Google Test does not support death tests for VC 7.1 and earlier as
539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// abort() in a VC 7.1 application compiled as GUI in debug config
540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// pops up a dialog window that cannot be suppressed programmatically.
541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)
544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_DEATH_TEST 1
545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <vector>  // NOLINT
546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// We don't support MSVC 7.1 with exceptions disabled now.  Therefore
549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// all the compilers we care about are adequate for supporting
550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// value-parameterized tests.
551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_HAS_PARAM_TEST 1
552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether to support type-driven tests.
554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Sun Pro CC, IBM Visual Age, and HP aCC support.
557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    defined(__IBMCPP__) || defined(__HP_aCC)
559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_TYPED_TEST 1
560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_TYPED_TEST_P 1
561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether to support Combine(). This only makes sense when
564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// value-parameterized tests are enabled.  The implementation doesn't
565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// work on Sun Studio since it doesn't understand templated conversion
566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// operators.
567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_COMBINE 1
569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether the system compiler uses UTF-16 for encoding wide strings.
572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_WIDE_STRING_USES_UTF16_ \
573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determines whether test results can be streamed to a socket.
576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_LINUX
577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_CAN_STREAM_RESULTS_ 1
578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines some utility macros.
581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The GNU compiler emits a warning if nested "if" statements are followed by
583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// an "else" statement and braces are not used to explicitly disambiguate the
584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// "else" binding.  This leads to problems with code like:
585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   if (gate)
587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     ASSERT_*(condition) << "Some message";
588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The "switch (0) case 0:" idiom is used to suppress this.
590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __INTEL_COMPILER
591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use this annotation at the end of a struct/class definition to
597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// prevent the compiler from optimizing away instances that are never
598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// used.  This is useful when all interesting logic happens inside the
599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// c'tor and / or d'tor.  Example:
600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   struct Foo {
602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Foo() { ... }
603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   } GTEST_ATTRIBUTE_UNUSED_;
604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Also use it after a variable or parameter declaration to tell the
606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// compiler the variable/parameter does not have to be used.
607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__GNUC__) && !defined(COMPILER_ICC)
608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_ATTRIBUTE_UNUSED_
611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A macro to disallow operator=
614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This should be used in the private: declarations for a class.
615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DISALLOW_ASSIGN_(type)\
616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void operator=(type const &)
617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A macro to disallow copy constructor and operator=
619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This should be used in the private: declarations for a class.
620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  type(type const &);\
622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_ASSIGN_(type)
623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Tell the compiler to warn about unused return values for functions declared
625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// with this macro.  The macro should be used on function declarations
626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// following the argument list:
627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_MUST_USE_RESULT_
633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Determine whether the compiler supports Microsoft's Structured Exception
636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Handling.  This is supported by several Windows compilers but generally
637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// does not exist on any other system.
638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_HAS_SEH
639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user didn't tell us, so we need to figure it out.
640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if defined(_MSC_VER) || defined(__BORLANDC__)
642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// These two compilers are known to support SEH.
643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_SEH 1
644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Assume no SEH.
646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_HAS_SEH 0
647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif
648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_SEH
650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _MSC_VER
652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if GTEST_LINKED_AS_SHARED_LIBRARY
654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_API_ __declspec(dllimport)
655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif GTEST_CREATE_SHARED_LIBRARY
656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  define GTEST_API_ __declspec(dllexport)
657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif
658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // _MSC_VER
660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_API_
662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_API_
663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __GNUC__
666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Ask the compiler to never inline a given function.
667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_NO_INLINE_ __attribute__((noinline))
668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_NO_INLINE_
670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace testing {
673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Message;
675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace internal {
677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass String;
679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// expression is true. For example, you could use it to verify the
682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// size of a static array:
683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                         content_type_names_incorrect_size);
686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// or to make sure a struct is smaller than a certain size:
688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The second argument to the macro is the name of the variable. If
692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the expression is false, most compilers will issue a warning/error
693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// containing the name of the variable.
694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <bool>
696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct CompileAssert {
697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_COMPILE_ASSERT_(expr, msg) \
700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef ::testing::internal::CompileAssert<(bool(expr))> \
701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      msg[bool(expr) ? 1 : -1]
702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implementation details of GTEST_COMPILE_ASSERT_:
704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   elements (and thus is invalid) when the expression is false.
707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// - The simpler definition
709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   does not work, as gcc supports variable-length arrays whose sizes
713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   are determined at run-time (this is gcc's extension and not part
714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   of the C++ standard).  As a result, gcc fails to reject the
715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   following code with the simple definition:
716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     int foo;
718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                                      // not a compile-time constant.
720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// - By using the type CompileAssert<(bool(expr))>, we ensures that
722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   expr is a compile-time constant.  (Template arguments must be
723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   determined at compile-time.)
724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     CompileAssert<bool(expr)>
729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   instead, these compilers will refuse to compile
731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   (They seem to think the ">" in "5 > 0" marks the end of the
735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   template argument list.)
736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// - The array size is (bool(expr) ? 1 : -1), instead of simply
738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     ((expr) ? 1 : -1).
740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   This is to avoid running into a bug in MS VC 7.1, which
742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This template is declared, but intentionally undefined.
747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T1, typename T2>
748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct StaticAssertTypeEqHelper;
749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct StaticAssertTypeEqHelper<T, T> {};
752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_GLOBAL_STRING
754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef ::string string;
755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef ::std::string string;
757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_GLOBAL_STRING
758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_GLOBAL_WSTRING
760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef ::wstring wstring;
761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif GTEST_HAS_STD_WSTRING
762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef ::std::wstring wstring;
763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_GLOBAL_WSTRING
764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A helper for suppressing warnings on constant condition.  It just
766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// returns 'condition'.
767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ bool IsTrue(bool condition);
768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines scoped_ptr.
770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This implementation of scoped_ptr is PARTIAL - it only contains
772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// enough stuff to satisfy Google Test's need.
773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass scoped_ptr {
775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
776f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef T element_type;
777f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
778f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
779f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~scoped_ptr() { reset(); }
780f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
781f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T& operator*() const { return *ptr_; }
782f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* operator->() const { return ptr_; }
783f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* get() const { return ptr_; }
784f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
785f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* release() {
786f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T* const ptr = ptr_;
787f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ptr_ = NULL;
788f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return ptr;
789f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
790f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
791f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void reset(T* p = NULL) {
792f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (p != ptr_) {
793f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
794f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        delete ptr_;
795f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
796f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ptr_ = p;
797f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
798f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
799f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
800f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* ptr_;
801f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
802f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
803f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
804f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
805f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines RE.
806f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
807f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
808f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Regular Expression syntax.
809f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ RE {
810f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
811f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // A copy constructor is required by the Standard to initialize object
812f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // references from r-values.
813f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  RE(const RE& other) { Init(other.pattern()); }
814f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
815f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Constructs an RE from a string.
816f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
817f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
818f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_GLOBAL_STRING
819f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
820f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
821f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
822f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_GLOBAL_STRING
823f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
824f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  RE(const char* regex) { Init(regex); }  // NOLINT
825f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~RE();
826f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
827f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the string representation of the regex.
828f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* pattern() const { return pattern_; }
829f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
830f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // FullMatch(str, re) returns true iff regular expression re matches
831f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the entire str.
832f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // PartialMatch(str, re) returns true iff regular expression re
833f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // matches a substring of str (including str itself).
834f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
835f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TODO(wan@google.com): make FullMatch() and PartialMatch() work
836f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // when str contains NUL characters.
837f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool FullMatch(const ::std::string& str, const RE& re) {
838f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return FullMatch(str.c_str(), re);
839f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
840f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool PartialMatch(const ::std::string& str, const RE& re) {
841f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return PartialMatch(str.c_str(), re);
842f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
843f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
844f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_GLOBAL_STRING
845f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
846f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool FullMatch(const ::string& str, const RE& re) {
847f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return FullMatch(str.c_str(), re);
848f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
849f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool PartialMatch(const ::string& str, const RE& re) {
850f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return PartialMatch(str.c_str(), re);
851f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
852f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
853f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_GLOBAL_STRING
854f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
855f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool FullMatch(const char* str, const RE& re);
856f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool PartialMatch(const char* str, const RE& re);
857f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
858f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
859f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Init(const char* regex);
860f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
861f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We use a const char* instead of a string, as Google Test may be used
862f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // where string is not available.  We also do not use Google Test's own
863f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // String type here, in order to simplify dependencies between the
864f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // files.
865f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* pattern_;
866f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool is_valid_;
867f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
868f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_USES_POSIX_RE
869f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
870f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  regex_t full_regex_;     // For FullMatch().
871f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  regex_t partial_regex_;  // For PartialMatch().
872f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
873f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else  // GTEST_USES_SIMPLE_RE
874f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
875f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* full_pattern_;  // For FullMatch();
876f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
877f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
878f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
879f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_ASSIGN_(RE);
880f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
881f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
882f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Formats a source file path and a line number as they would appear
883f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in an error message from the compiler used to compile this code.
884f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
885f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
886f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Formats a file location for compiler-independent XML output.
887f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Although this function is not platform dependent, we put it next to
888f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// FormatFileLocation in order to contrast the two functions.
889f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
890f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                               int line);
891f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
892f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines logging utilities:
893f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_LOG_(severity) - logs messages at the specified severity level. The
894f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                          message itself is streamed into the macro.
895f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   LogToStderr()  - directs all log messages to stderr.
896f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   FlushInfoLog() - flushes informational log messages.
897f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
898f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum GTestLogSeverity {
899f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_INFO,
900f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_WARNING,
901f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_ERROR,
902f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_FATAL
903f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
904f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
905f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Formats log entry severity, provides a stream object for streaming the
906f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// log message, and terminates the message with a newline when going out of
907f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// scope.
908f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ GTestLog {
909f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
910f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTestLog(GTestLogSeverity severity, const char* file, int line);
911f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
912f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
913f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~GTestLog();
914f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
915f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ::std::ostream& GetStream() { return ::std::cerr; }
916f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
917f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
918f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const GTestLogSeverity severity_;
919f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
920f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
921f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
922f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
923f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_LOG_(severity) \
924f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
925f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  __FILE__, __LINE__).GetStream()
926f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
927f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline void LogToStderr() {}
928f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline void FlushInfoLog() { fflush(NULL); }
929f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
930f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE.
931f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
932f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
933f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is not satisfied.
934f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//  Synopsys:
935f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    GTEST_CHECK_(boolean_condition);
936f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     or
937f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    GTEST_CHECK_(boolean_condition) << "Additional message";
938f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
939f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    This checks the condition and if the condition is not satisfied
940f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    it prints message about the condition violation, including the
941f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    condition itself, plus additional message streamed into it, if any,
942f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    and then it aborts the program. It aborts the program irrespective of
943f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    whether it is built in the debug mode or not.
944f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_CHECK_(condition) \
945f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
946f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (::testing::internal::IsTrue(condition)) \
947f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ; \
948f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    else \
949f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
950f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
951f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// An all-mode assert to verify that the given POSIX-style function
952f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// call returns 0 (indicating success).  Known limitation: this
953f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// doesn't expand to a balanced 'if' statement, so enclose the macro
954f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in {} if you need to use it as the only statement in an 'if'
955f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// branch.
956f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
957f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (const int gtest_error = (posix_call)) \
958f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
959f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      << gtest_error
960f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
961f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
962f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
963f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use ImplicitCast_ as a safe version of static_cast for upcasting in
964f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
965f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// const Foo*).  When you use ImplicitCast_, the compiler checks that
966f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the cast is safe.  Such explicit ImplicitCast_s are necessary in
967f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// surprisingly many situations where C++ demands an exact type match
968f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// instead of an argument type convertable to a target type.
969f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
970f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The syntax for using ImplicitCast_ is the same as for static_cast:
971f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
972f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ImplicitCast_<ToType>(expr)
973f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
974f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ImplicitCast_ would have been part of the C++ standard library,
975f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// but the proposal was submitted too late.  It will probably make
976f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// its way into the language in the future.
977f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
978f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This relatively ugly name is intentional. It prevents clashes with
979f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// similar functions users may have (e.g., implicit_cast). The internal
980f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// namespace alone is not enough because the function can be found by ADL.
981f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate<typename To>
982f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline To ImplicitCast_(To x) { return x; }
983f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
984f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When you upcast (that is, cast a pointer from type Foo to type
985f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
986f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// always succeed.  When you downcast (that is, cast a pointer from
987f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
988f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// how do you know the pointer is really of type SubclassOfFoo?  It
989f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
990f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// when you downcast, you should use this macro.  In debug mode, we
991f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// use dynamic_cast<> to double-check the downcast is legal (we die
992f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// if it's not).  In normal mode, we do the efficient static_cast<>
993f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// instead.  Thus, it's important to test in debug mode to make sure
994f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the cast is legal!
995f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    This is the only place in the code we should use dynamic_cast<>.
996f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// In particular, you SHOULDN'T be using dynamic_cast<> in order to
997f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// do RTTI (eg code like this:
998f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
999f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
1000f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// You should design the code some other way not to need this.
1001f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1002f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This relatively ugly name is intentional. It prevents clashes with
1003f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// similar functions users may have (e.g., down_cast). The internal
1004f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// namespace alone is not enough because the function can be found by ADL.
1005f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate<typename To, typename From>  // use like this: DownCast_<T*>(foo);
1006f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline To DownCast_(From* f) {  // so we only accept pointers
1007f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Ensures that To is a sub-type of From *.  This test is here only
1008f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // for compile-time type checking, and has no overhead in an
1009f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // optimized build at run-time, as it will be optimized away
1010f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // completely.
1011f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (false) {
1012f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const To to = NULL;
1013f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::testing::internal::ImplicitCast_<From*>(to);
1014f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1015f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1016f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_RTTI
1017f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // RTTI: debug mode only!
1018f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
1019f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1020f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return static_cast<To>(f);
1021f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1022f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1023f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Downcasts the pointer of type Base to Derived.
1024f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Derived must be a subclass of Base. The parameter MUST
1025f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// point to a class of type Derived, not any subclass of it.
1026f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When RTTI is available, the function performs a runtime
1027f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// check to enforce this.
1028f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <class Derived, class Base>
1029f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDerived* CheckedDowncastToActualType(Base* base) {
1030f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_RTTI
1031f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_CHECK_(typeid(*base) == typeid(Derived));
1032f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return dynamic_cast<Derived*>(base);  // NOLINT
1033f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1034f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return static_cast<Derived*>(base);  // Poor man's downcast.
1035f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1036f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1037f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1038f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_STREAM_REDIRECTION
1039f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1040f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines the stderr capturer:
1041f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   CaptureStdout     - starts capturing stdout.
1042f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GetCapturedStdout - stops capturing stdout and returns the captured string.
1043f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   CaptureStderr     - starts capturing stderr.
1044f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GetCapturedStderr - stops capturing stderr and returns the captured string.
1045f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1046f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ void CaptureStdout();
1047f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ String GetCapturedStdout();
1048f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ void CaptureStderr();
1049f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ String GetCapturedStderr();
1050f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1051f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_STREAM_REDIRECTION
1052f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1053f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1054f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_DEATH_TEST
1055f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1056f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A copy of all command line arguments.  Set by InitGoogleTest().
1057f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern ::std::vector<String> g_argvs;
1058f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1059f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// GTEST_HAS_DEATH_TEST implies we have ::std::string.
1060f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst ::std::vector<String>& GetArgvs();
1061f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1062f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_DEATH_TEST
1063f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1064f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines synchronization primitives.
1065f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1066f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_PTHREAD
1067f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1068f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Sleeps for (roughly) n milli-seconds.  This function is only for
1069f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// testing Google Test's own constructs.  Don't use it in user tests,
1070f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// either directly or indirectly.
1071f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline void SleepMilliseconds(int n) {
1072f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const timespec time = {
1073f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    0,                  // 0 seconds.
1074f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    n * 1000L * 1000L,  // And n ms.
1075f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  };
1076f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  nanosleep(&time, NULL);
1077f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1078f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1079f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Allows a controller thread to pause execution of newly created
1080f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// threads until notified.  Instances of this class must be created
1081f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and destroyed in the controller thread.
1082f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1083f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This class is only for testing Google Test's own constructs. Do not
1084f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// use it in user tests, either directly or indirectly.
1085f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Notification {
1086f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1087f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Notification() : notified_(false) {}
1088f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1089f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Notifies all threads created with this notification to start. Must
1090f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // be called from the controller thread.
1091f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Notify() { notified_ = true; }
1092f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1093f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Blocks until the controller thread notifies. Must be called from a test
1094f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // thread.
1095f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void WaitForNotification() {
1096f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    while(!notified_) {
1097f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      SleepMilliseconds(10);
1098f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1099f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  volatile bool notified_;
1103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
1105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
1108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Consequently, it cannot select a correct instantiation of ThreadWithParam
1109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in order to call its Run(). Introducing ThreadWithParamBase as a
1110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// non-templated base class for ThreadWithParam allows us to bypass this
1111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// problem.
1112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass ThreadWithParamBase {
1113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~ThreadWithParamBase() {}
1115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void Run() = 0;
1116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// pthread_create() accepts a pointer to a function type with the C linkage.
1119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// According to the Standard (7.5/1), function types with different linkages
1120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// are different even if they are otherwise identical.  Some compilers (for
1121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// example, SunStudio) treat them as different types.  Since class methods
1122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// cannot be defined with C-linkage we need to define a free C-function to
1123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// pass into pthread_create().
1124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
1125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static_cast<ThreadWithParamBase*>(thread)->Run();
1126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return NULL;
1127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Helper class for testing Google Test's multi-threading constructs.
1130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// To use it, write:
1131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   void ThreadFunc(int param) { /* Do things with param */ }
1133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Notification thread_can_start;
1134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ...
1135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // The thread_can_start parameter is optional; you can supply NULL.
1136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
1137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   thread_can_start.Notify();
1138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// These classes are only for testing Google Test's own constructs. Do
1140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// not use them in user tests, either directly or indirectly.
1141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass ThreadWithParam : public ThreadWithParamBase {
1143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef void (*UserThreadFunc)(T);
1145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ThreadWithParam(
1147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      UserThreadFunc func, T param, Notification* thread_can_start)
1148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      : func_(func),
1149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        param_(param),
1150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        thread_can_start_(thread_can_start),
1151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        finished_(false) {
1152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ThreadWithParamBase* const base = this;
1153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // The thread can be created only after all fields except thread_
1154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // have been initialized.
1155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(
1156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
1157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~ThreadWithParam() { Join(); }
1159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Join() {
1161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (!finished_) {
1162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
1163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      finished_ = true;
1164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void Run() {
1168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (thread_can_start_ != NULL)
1169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      thread_can_start_->WaitForNotification();
1170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    func_(param_);
1171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const UserThreadFunc func_;  // User-supplied thread function.
1175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const T param_;  // User-supplied parameter to the thread function.
1176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // When non-NULL, used to block execution until the controller thread
1177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // notifies.
1178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Notification* const thread_can_start_;
1179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool finished_;  // true iff we know that the thread function has finished.
1180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  pthread_t thread_;  // The native thread object.
1181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
1183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// MutexBase and Mutex implement mutex on pthreads-based platforms. They
1186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// are used in conjunction with class MutexLock:
1187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Mutex mutex;
1189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ...
1190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   MutexLock lock(&mutex);  // Acquires the mutex and releases it at the end
1191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//                            // of the current scope.
1192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// MutexBase implements behavior for both statically and dynamically
1194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// allocated mutexes.  Do not use MutexBase directly.  Instead, write
1195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the following to define a static mutex:
1196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
1198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// You can forward declare a static mutex like this:
1200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
1202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// To create a dynamic mutex, just define an object of type Mutex.
1204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass MutexBase {
1205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Acquires this mutex.
1207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Lock() {
1208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
1209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    owner_ = pthread_self();
1210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Releases this mutex.
1213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Unlock() {
1214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // We don't protect writing to owner_ here, as it's the caller's
1215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // responsibility to ensure that the current thread holds the
1216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // mutex when this is called.
1217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    owner_ = 0;
1218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
1219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Does nothing if the current thread holds the mutex. Otherwise, crashes
1222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // with high probability.
1223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void AssertHeld() const {
1224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_(owner_ == pthread_self())
1225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        << "The current thread is not holding the mutex @" << this;
1226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // A static mutex may be used before main() is entered.  It may even
1229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // be used before the dynamic initialization stage.  Therefore we
1230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // must be able to initialize a static mutex object at link time.
1231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This means MutexBase has to be a POD and its member variables
1232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // have to be public.
1233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  pthread_mutex_t mutex_;  // The underlying pthread mutex.
1235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  pthread_t owner_;  // The thread holding the mutex; 0 means no one holds it.
1236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Forward-declares a static mutex.
1239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    extern ::testing::internal::MutexBase mutex
1241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines and statically (i.e. at link time) initializes a static mutex.
1243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 }
1245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The Mutex class can only be used for mutexes created at runtime. It
1247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// shares its API with MutexBase otherwise.
1248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Mutex : public MutexBase {
1249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Mutex() {
1251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
1252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    owner_ = 0;
1253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~Mutex() {
1255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
1256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
1260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// We cannot name this class MutexLock as the ctor declaration would
1263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// conflict with a macro named MutexLock, which is defined on some
1264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// platforms.  Hence the typedef trick below.
1265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTestMutexLock {
1266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  explicit GTestMutexLock(MutexBase* mutex)
1268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      : mutex_(mutex) { mutex_->Lock(); }
1269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~GTestMutexLock() { mutex_->Unlock(); }
1271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  MutexBase* const mutex_;
1274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
1276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef GTestMutexLock MutexLock;
1279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Helpers for ThreadLocal.
1281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// pthread_key_create() requires DeleteThreadLocalValue() to have
1283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// C-linkage.  Therefore it cannot be templatized to access
1284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ThreadLocal<T>.  Hence the need for class
1285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ThreadLocalValueHolderBase.
1286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass ThreadLocalValueHolderBase {
1287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~ThreadLocalValueHolderBase() {}
1289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Called by pthread to delete thread-local data stored by
1292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// pthread_setspecific().
1293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" inline void DeleteThreadLocalValue(void* value_holder) {
1294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
1295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implements thread-local storage on pthreads-based systems.
1298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // Thread 1
1300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ThreadLocal<int> tl(100);  // 100 is the default value for each thread.
1301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // Thread 2
1303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   tl.set(150);  // Changes the value for thread 2 only.
1304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_EQ(150, tl.get());
1305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // Thread 1
1307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_EQ(100, tl.get());  // In thread 1, tl has the original value.
1308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   tl.set(200);
1309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_EQ(200, tl.get());
1310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The template type argument T must have a public copy constructor.
1312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// In addition, the default ThreadLocal constructor requires T to have
1313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// a public default constructor.
1314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// An object managed for a thread by a ThreadLocal instance is deleted
1316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// when the thread exits.  Or, if the ThreadLocal instance dies in
1317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// that thread, when the ThreadLocal dies.  It's the user's
1318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// responsibility to ensure that all other threads using a ThreadLocal
1319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// have exited when it dies, or the per-thread objects for those
1320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// threads will not be deleted.
1321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Google Test only uses global ThreadLocal objects.  That means they
1323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// will die after main() has returned.  Therefore, no per-thread
1324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// object managed by Google Test will be leaked as long as all threads
1325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// using Google Test have exited when main() returns.
1326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass ThreadLocal {
1328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ThreadLocal() : key_(CreateKey()),
1330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                  default_() {}
1331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  explicit ThreadLocal(const T& value) : key_(CreateKey()),
1332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                         default_(value) {}
1333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~ThreadLocal() {
1335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // Destroys the managed object for the current thread, if any.
1336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    DeleteThreadLocalValue(pthread_getspecific(key_));
1337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // Releases resources associated with the key.  This will *not*
1339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // delete managed objects for other threads.
1340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
1341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* pointer() { return GetOrCreateValue(); }
1344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const T* pointer() const { return GetOrCreateValue(); }
1345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const T& get() const { return *pointer(); }
1346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void set(const T& value) { *pointer() = value; }
1347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Holds a value of type T.
1350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  class ValueHolder : public ThreadLocalValueHolderBase {
1351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   public:
1352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    explicit ValueHolder(const T& value) : value_(value) {}
1353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T* pointer() { return &value_; }
1355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   private:
1357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T value_;
1358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
1359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  };
1360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static pthread_key_t CreateKey() {
1362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    pthread_key_t key;
1363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // When a thread exits, DeleteThreadLocalValue() will be called on
1364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // the object managed for that thread.
1365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(
1366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        pthread_key_create(&key, &DeleteThreadLocalValue));
1367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return key;
1368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* GetOrCreateValue() const {
1371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ThreadLocalValueHolderBase* const holder =
1372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
1373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (holder != NULL) {
1374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
1375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ValueHolder* const new_holder = new ValueHolder(default_);
1378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ThreadLocalValueHolderBase* const holder_base = new_holder;
1379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
1380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return new_holder->pointer();
1381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // A key pthreads uses for looking up per-thread values.
1384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const pthread_key_t key_;
1385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const T default_;  // The default value for each thread.
1386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
1388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_IS_THREADSAFE 1
1391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else  // GTEST_HAS_PTHREAD
1393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A dummy implementation of synchronization primitives (mutex, lock,
1395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and thread-local variable).  Necessary for compiling Google Test where
1396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// mutex is not supported - using Google Test in multiple threads is not
1397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// supported on such platforms.
1398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Mutex {
1400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Mutex() {}
1402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void AssertHeld() const {}
1403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  extern ::testing::internal::Mutex mutex
1407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
1409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTestMutexLock {
1411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  explicit GTestMutexLock(Mutex*) {}  // NOLINT
1413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef GTestMutexLock MutexLock;
1416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass ThreadLocal {
1419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ThreadLocal() : value_() {}
1421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  explicit ThreadLocal(const T& value) : value_(value) {}
1422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T* pointer() { return &value_; }
1423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const T* pointer() const { return &value_; }
1424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const T& get() const { return value_; }
1425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void set(const T& value) { value_ = value; }
1426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  T value_;
1428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The above synchronization primitives have dummy implementations.
1431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Therefore Google Test is not thread-safe.
1432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_IS_THREADSAFE 0
1433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_PTHREAD
1435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Returns the number of threads running in the process, or 0 to indicate that
1437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// we cannot detect it.
1438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ size_t GetThreadCount();
1439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Passing non-POD classes through ellipsis (...) crashes the ARM
1441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// compiler and generates a warning in Sun Studio.  The Nokia Symbian
1442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and the IBM XL C/C++ compiler try to instantiate a copy constructor
1443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// for objects passed through ellipsis (...), failing for uncopyable
1444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// objects.  We define this to ensure that only POD is passed through
1445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ellipsis on these systems.
1446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
1447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// We lose support for NULL detection where the compiler doesn't like
1448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// passing non-POD classes through ellipsis (...).
1449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_ELLIPSIS_NEEDS_POD_ 1
1450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_CAN_COMPARE_NULL 1
1452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
1455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// const T& and const T* in a function template.  These compilers
1456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// _can_ decide between class template specializations for T and T*,
1457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// so a tr1::type_traits-like is_pointer works.
1458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
1459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_NEEDS_IS_POINTER_ 1
1460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <bool bool_value>
1463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct bool_constant {
1464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef bool_constant<bool_value> type;
1465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static const bool value = bool_value;
1466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <bool bool_value> const bool bool_constant<bool_value>::value;
1468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef bool_constant<false> false_type;
1470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef bool_constant<true> true_type;
1471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct is_pointer : public false_type {};
1474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct is_pointer<T*> : public true_type {};
1477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Iterator>
1479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct IteratorTraits {
1480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef typename Iterator::value_type value_type;
1481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct IteratorTraits<T*> {
1485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef T value_type;
1486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct IteratorTraits<const T*> {
1490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef T value_type;
1491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_WINDOWS
1494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_PATH_SEP_ "\\"
1495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_ALT_PATH_SEP_ 1
1496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The biggest signed integer type the compiler supports.
1497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef __int64 BiggestInt;
1498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_PATH_SEP_ "/"
1500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define GTEST_HAS_ALT_PATH_SEP_ 0
1501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef long long BiggestInt;  // NOLINT
1502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_OS_WINDOWS
1503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Utilities for char.
1505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// isspace(int ch) and friends accept an unsigned char or EOF.  char
1507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// may be signed, depending on the compiler (or compiler flags).
1508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Therefore we need to cast a char to unsigned char before calling
1509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// isspace(), etc.
1510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsAlpha(char ch) {
1512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return isalpha(static_cast<unsigned char>(ch)) != 0;
1513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsAlNum(char ch) {
1515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return isalnum(static_cast<unsigned char>(ch)) != 0;
1516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsDigit(char ch) {
1518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return isdigit(static_cast<unsigned char>(ch)) != 0;
1519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsLower(char ch) {
1521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return islower(static_cast<unsigned char>(ch)) != 0;
1522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsSpace(char ch) {
1524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return isspace(static_cast<unsigned char>(ch)) != 0;
1525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsUpper(char ch) {
1527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return isupper(static_cast<unsigned char>(ch)) != 0;
1528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsXDigit(char ch) {
1530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return isxdigit(static_cast<unsigned char>(ch)) != 0;
1531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline char ToLower(char ch) {
1534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
1535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline char ToUpper(char ch) {
1537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
1538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The testing::internal::posix namespace holds wrappers for common
1541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// POSIX functions.  These wrappers hide the differences between
1542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Windows/MSVC and POSIX systems.  Since some compilers define these
1543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// standard functions as macros, the wrapper cannot have the same name
1544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// as the wrapped function.
1545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace posix {
1547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Functions with a different name on Windows.
1549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_WINDOWS
1551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef struct _stat StatStruct;
1553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# ifdef __BORLANDC__
1555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int IsATTY(int fd) { return isatty(fd); }
1556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int StrCaseCmp(const char* s1, const char* s2) {
1557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return stricmp(s1, s2);
1558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline char* StrDup(const char* src) { return strdup(src); }
1560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else  // !__BORLANDC__
1561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  if GTEST_OS_WINDOWS_MOBILE
1562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int IsATTY(int /* fd */) { return 0; }
1563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  else
1564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int IsATTY(int fd) { return _isatty(fd); }
1565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#  endif  // GTEST_OS_WINDOWS_MOBILE
1566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int StrCaseCmp(const char* s1, const char* s2) {
1567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return _stricmp(s1, s2);
1568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline char* StrDup(const char* src) { return _strdup(src); }
1570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // __BORLANDC__
1571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if GTEST_OS_WINDOWS_MOBILE
1573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
1574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
1575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// time and thus not defined there.
1576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else
1577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int FileNo(FILE* file) { return _fileno(file); }
1578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
1579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int RmDir(const char* dir) { return _rmdir(dir); }
1580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsDir(const StatStruct& st) {
1581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return (_S_IFDIR & st.st_mode) != 0;
1582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif  // GTEST_OS_WINDOWS_MOBILE
1584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef struct stat StatStruct;
1588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int FileNo(FILE* file) { return fileno(file); }
1590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int IsATTY(int fd) { return isatty(fd); }
1591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
1592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int StrCaseCmp(const char* s1, const char* s2) {
1593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return strcasecmp(s1, s2);
1594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline char* StrDup(const char* src) { return strdup(src); }
1596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int RmDir(const char* dir) { return rmdir(dir); }
1597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
1598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_OS_WINDOWS
1600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Functions deprecated by MSVC 8.0.
1602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _MSC_VER
1604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Temporarily disable warning 4996 (deprecated function).
1605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# pragma warning(push)
1606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# pragma warning(disable:4996)
1607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline const char* StrNCpy(char* dest, const char* src, size_t n) {
1610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return strncpy(dest, src, n);
1611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
1614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// StrError() aren't needed on Windows CE at this time and thus not
1615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// defined there.
1616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_OS_WINDOWS_MOBILE
1618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int ChDir(const char* dir) { return chdir(dir); }
1619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline FILE* FOpen(const char* path, const char* mode) {
1621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return fopen(path, mode);
1622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_OS_WINDOWS_MOBILE
1624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
1625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return freopen(path, mode, stream);
1626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
1628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int FClose(FILE* fp) { return fclose(fp); }
1630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_OS_WINDOWS_MOBILE
1631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int Read(int fd, void* buf, unsigned int count) {
1632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return static_cast<int>(read(fd, buf, count));
1633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int Write(int fd, const void* buf, unsigned int count) {
1635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return static_cast<int>(write(fd, buf, count));
1636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline int Close(int fd) { return close(fd); }
1638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline const char* StrError(int errnum) { return strerror(errnum); }
1639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline const char* GetEnv(const char* name) {
1641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_WINDOWS_MOBILE
1642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We are on Windows CE, which has no environment variables.
1643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return NULL;
1644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Environment variables which we programmatically clear will be set to the
1646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // empty string rather than unset (NULL).  Handle that case.
1647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* const env = getenv(name);
1648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return (env != NULL && env[0] != '\0') ? env : NULL;
1649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return getenv(name);
1651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _MSC_VER
1655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# pragma warning(pop)  // Restores the warning state.
1656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_WINDOWS_MOBILE
1659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Windows CE has no C library. The abort() function is used in
1660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// several places in Google Test. This implementation provides a reasonable
1661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// imitation of standard behaviour.
1662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid Abort();
1663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline void Abort() { abort(); }
1665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_OS_WINDOWS_MOBILE
1666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace posix
1668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The maximum number a BiggestInt can represent.  This definition
1670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// works no matter BiggestInt is represented in one's complement or
1671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// two's complement.
1672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// We cannot rely on numeric_limits in STL, as __int64 and long long
1674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// are not part of standard C++ and numeric_limits doesn't need to be
1675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// defined for them.
1676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst BiggestInt kMaxBiggestInt =
1677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
1678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This template class serves as a compile-time function from size to
1680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// type.  It maps a size in bytes to a primitive type with that
1681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// size. e.g.
1682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TypeWithSize<4>::UInt
1684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is typedef-ed to be unsigned int (unsigned integer made up of 4
1686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// bytes).
1687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Such functionality should belong to STL, but I cannot find it
1689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// there.
1690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Google Test uses this class in the implementation of floating-point
1692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// comparison.
1693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For now it only handles UInt (unsigned int) as that's all Google Test
1695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// needs.  Other types can be easily added in the future if need
1696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// arises.
1697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <size_t size>
1698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TypeWithSize {
1699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This prevents the user from using TypeWithSize<N> with incorrect
1701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // values of N.
1702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef void UInt;
1703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The specialization for size 4.
1706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TypeWithSize<4> {
1708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // unsigned int has size 4 in both gcc and MSVC.
1710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // As base/basictypes.h doesn't compile on Windows, we cannot use
1712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // uint32, uint64, and etc here.
1713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef int Int;
1714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef unsigned int UInt;
1715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The specialization for size 8.
1718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TypeWithSize<8> {
1720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_WINDOWS
1723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef __int64 Int;
1724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef unsigned __int64 UInt;
1725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef long long Int;  // NOLINT
1727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef unsigned long long UInt;  // NOLINT
1728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_OS_WINDOWS
1729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Integer types of known sizes.
1732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef TypeWithSize<4>::Int Int32;
1733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef TypeWithSize<4>::UInt UInt32;
1734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef TypeWithSize<8>::Int Int64;
1735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef TypeWithSize<8>::UInt UInt64;
1736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.
1737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Utilities for command line flags and environment variables.
1739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macro for referencing flags.
1741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_FLAG(name) FLAGS_gtest_##name
1742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for declaring flags.
1744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
1745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DECLARE_int32_(name) \
1746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
1747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DECLARE_string_(name) \
1748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name)
1749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for defining flags.
1751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DEFINE_bool_(name, default_val, doc) \
1752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_API_ bool GTEST_FLAG(name) = (default_val)
1753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DEFINE_int32_(name, default_val, doc) \
1754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
1755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_DEFINE_string_(name, default_val, doc) \
1756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
1757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Parses 'str' for a 32-bit signed integer.  If successful, writes the result
1759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to *value and returns true; otherwise leaves *value unchanged and returns
1760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// false.
1761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TODO(chandlerc): Find a better way to refactor flag and environment parsing
1762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
1763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// function.
1764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgbool ParseInt32(const Message& src_text, const char* str, Int32* value);
1765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Parses a bool/Int32/string from the environment variable
1767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// corresponding to the given Google Test flag.
1768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgbool BoolFromGTestEnv(const char* flag, bool default_val);
1769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
1770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst char* StringFromGTestEnv(const char* flag, const char* default_val);
1771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace internal
1773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace testing
1774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
1776