gtest-port.h revision f253efc20ec05216eda902a6fb0628c2f5164757
1d201456903f3ecae1f7794edfab0d5678e64226shiqian// Copyright 2005, Google Inc.
2d201456903f3ecae1f7794edfab0d5678e64226shiqian// All rights reserved.
3d201456903f3ecae1f7794edfab0d5678e64226shiqian//
4d201456903f3ecae1f7794edfab0d5678e64226shiqian// Redistribution and use in source and binary forms, with or without
5d201456903f3ecae1f7794edfab0d5678e64226shiqian// modification, are permitted provided that the following conditions are
6d201456903f3ecae1f7794edfab0d5678e64226shiqian// met:
7d201456903f3ecae1f7794edfab0d5678e64226shiqian//
8d201456903f3ecae1f7794edfab0d5678e64226shiqian//     * Redistributions of source code must retain the above copyright
9d201456903f3ecae1f7794edfab0d5678e64226shiqian// notice, this list of conditions and the following disclaimer.
10d201456903f3ecae1f7794edfab0d5678e64226shiqian//     * Redistributions in binary form must reproduce the above
11d201456903f3ecae1f7794edfab0d5678e64226shiqian// copyright notice, this list of conditions and the following disclaimer
12d201456903f3ecae1f7794edfab0d5678e64226shiqian// in the documentation and/or other materials provided with the
13d201456903f3ecae1f7794edfab0d5678e64226shiqian// distribution.
14d201456903f3ecae1f7794edfab0d5678e64226shiqian//     * Neither the name of Google Inc. nor the names of its
15d201456903f3ecae1f7794edfab0d5678e64226shiqian// contributors may be used to endorse or promote products derived from
16d201456903f3ecae1f7794edfab0d5678e64226shiqian// this software without specific prior written permission.
17d201456903f3ecae1f7794edfab0d5678e64226shiqian//
18d201456903f3ecae1f7794edfab0d5678e64226shiqian// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19d201456903f3ecae1f7794edfab0d5678e64226shiqian// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20d201456903f3ecae1f7794edfab0d5678e64226shiqian// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21d201456903f3ecae1f7794edfab0d5678e64226shiqian// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22d201456903f3ecae1f7794edfab0d5678e64226shiqian// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23d201456903f3ecae1f7794edfab0d5678e64226shiqian// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24d201456903f3ecae1f7794edfab0d5678e64226shiqian// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25d201456903f3ecae1f7794edfab0d5678e64226shiqian// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26d201456903f3ecae1f7794edfab0d5678e64226shiqian// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27d201456903f3ecae1f7794edfab0d5678e64226shiqian// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28d201456903f3ecae1f7794edfab0d5678e64226shiqian// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29d201456903f3ecae1f7794edfab0d5678e64226shiqian//
30d201456903f3ecae1f7794edfab0d5678e64226shiqian// Authors: wan@google.com (Zhanyong Wan)
31d201456903f3ecae1f7794edfab0d5678e64226shiqian//
32d201456903f3ecae1f7794edfab0d5678e64226shiqian// Low-level types and utilities for porting Google Test to various
33d3eb97f32192acf79995983e32a20d8b3afd5872kosak// platforms.  All macros ending with _ and symbols defined in an
34d3eb97f32192acf79995983e32a20d8b3afd5872kosak// internal namespace are subject to change without notice.  Code
35d3eb97f32192acf79995983e32a20d8b3afd5872kosak// outside Google Test MUST NOT USE THEM DIRECTLY.  Macros that don't
36d3eb97f32192acf79995983e32a20d8b3afd5872kosak// end with _ are part of Google Test's public API and can be used by
37d3eb97f32192acf79995983e32a20d8b3afd5872kosak// code outside Google Test.
386a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan//
396a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan// This file is fundamental to Google Test.  All other Google Test source
406a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan// files are expected to #include this.  Therefore, it cannot #include
416a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan// any other Google Test header.
42d201456903f3ecae1f7794edfab0d5678e64226shiqian
43d201456903f3ecae1f7794edfab0d5678e64226shiqian#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
44d201456903f3ecae1f7794edfab0d5678e64226shiqian#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
45d201456903f3ecae1f7794edfab0d5678e64226shiqian
46d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Environment-describing macros
47d3eb97f32192acf79995983e32a20d8b3afd5872kosak// -----------------------------
48d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
49d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Google Test can be used in many different environments.  Macros in
50d3eb97f32192acf79995983e32a20d8b3afd5872kosak// this section tell Google Test what kind of environment it is being
51d3eb97f32192acf79995983e32a20d8b3afd5872kosak// used in, such that Google Test can provide environment-specific
52d3eb97f32192acf79995983e32a20d8b3afd5872kosak// features and implementations.
53d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
54d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Google Test tries to automatically detect the properties of its
55d3eb97f32192acf79995983e32a20d8b3afd5872kosak// environment, so users usually don't need to worry about these
56d3eb97f32192acf79995983e32a20d8b3afd5872kosak// macros.  However, the automatic detection is not perfect.
57d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Sometimes it's necessary for a user to define some of the following
58d3eb97f32192acf79995983e32a20d8b3afd5872kosak// macros in the build script to override Google Test's decisions.
59d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
60d3eb97f32192acf79995983e32a20d8b3afd5872kosak// If the user doesn't define a macro in the list, Google Test will
61d3eb97f32192acf79995983e32a20d8b3afd5872kosak// provide a default definition.  After this header is #included, all
62d3eb97f32192acf79995983e32a20d8b3afd5872kosak// macros in this list will be defined to either 1 or 0.
63d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
64d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Notes to maintainers:
65d3eb97f32192acf79995983e32a20d8b3afd5872kosak//   - Each macro here is a user-tweakable knob; do not grow the list
66d3eb97f32192acf79995983e32a20d8b3afd5872kosak//     lightly.
67d3eb97f32192acf79995983e32a20d8b3afd5872kosak//   - Use #if to key off these macros.  Don't use #ifdef or "#if
68d3eb97f32192acf79995983e32a20d8b3afd5872kosak//     defined(...)", which will not work as these macros are ALWAYS
69d3eb97f32192acf79995983e32a20d8b3afd5872kosak//     defined.
70d201456903f3ecae1f7794edfab0d5678e64226shiqian//
7104f025dd5746fca83c6c32f1729b3449721dd60eshiqian//   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
7204f025dd5746fca83c6c32f1729b3449721dd60eshiqian//                              is/isn't available.
73cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev//   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
74cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev//                              are enabled.
75d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
76d201456903f3ecae1f7794edfab0d5678e64226shiqian//                              is/isn't available (some systems define
77d201456903f3ecae1f7794edfab0d5678e64226shiqian//                              ::string, which is different to std::string).
78d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
79d201456903f3ecae1f7794edfab0d5678e64226shiqian//                              is/isn't available (some systems define
80d201456903f3ecae1f7794edfab0d5678e64226shiqian//                              ::wstring, which is different to std::wstring).
81e96d247b20116646f343b6e2ec37af154f655977vladlosev//   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
82e96d247b20116646f343b6e2ec37af154f655977vladlosev//                              expressions are/aren't available.
83e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
84e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//                              is/isn't available.
8504f025dd5746fca83c6c32f1729b3449721dd60eshiqian//   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
8604f025dd5746fca83c6c32f1729b3449721dd60eshiqian//                              enabled.
8704f025dd5746fca83c6c32f1729b3449721dd60eshiqian//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
8804f025dd5746fca83c6c32f1729b3449721dd60eshiqian//                              std::wstring does/doesn't work (Google Test can
8904f025dd5746fca83c6c32f1729b3449721dd60eshiqian//                              be used where std::wstring is unavailable).
90532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
913d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev//                              is/isn't available.
92f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
93f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan//                              compiler supports Microsoft's "Structured
94f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan//                              Exception Handling".
9535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//   GTEST_HAS_STREAM_REDIRECTION
9635c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//                            - Define it to 1/0 to indicate whether the
9735c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//                              platform supports I/O stream redirection using
9835c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//                              dup() and dup2().
99532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
100532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan//                              Test's own tr1 tuple implementation should be
101532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan//                              used.  Unused when the user sets
102532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan//                              GTEST_HAS_TR1_TUPLE to 0.
1032147489625ea8071ca560462f19b1ceb8940a229vladlosev//   GTEST_LANG_CXX11         - Define it to 1/0 to indicate that Google Test
1042147489625ea8071ca560462f19b1ceb8940a229vladlosev//                              is building in C++11/C++98 mode.
10583589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//   GTEST_LINKED_AS_SHARED_LIBRARY
10683589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//                            - Define to 1 when compiling tests that use
10783589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//                              Google Test as a shared library (known as
10883589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//                              DLL on Windows).
10983589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//   GTEST_CREATE_SHARED_LIBRARY
11083589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//                            - Define to 1 when compiling Google Test itself
11183589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan//                              as a shared library.
112d201456903f3ecae1f7794edfab0d5678e64226shiqian
113d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Platform-indicating macros
114d3eb97f32192acf79995983e32a20d8b3afd5872kosak// --------------------------
115d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
116d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Macros indicating the platform on which Google Test is being used
117d3eb97f32192acf79995983e32a20d8b3afd5872kosak// (a macro is defined to 1 if compiled on the given platform;
118d3eb97f32192acf79995983e32a20d8b3afd5872kosak// otherwise UNDEFINED -- it's never defined to 0.).  Google Test
119d3eb97f32192acf79995983e32a20d8b3afd5872kosak// defines these macros automatically.  Code outside Google Test MUST
120d3eb97f32192acf79995983e32a20d8b3afd5872kosak// NOT define them.
121d201456903f3ecae1f7794edfab0d5678e64226shiqian//
12206d04c0945bf47bae90532552e6e8294802fc9aavladlosev//   GTEST_OS_AIX      - IBM AIX
1230af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_OS_CYGWIN   - Cygwin
124b215e30cadd11db7c9f378b57ffecce92aacce37kosak//   GTEST_OS_FREEBSD  - FreeBSD
125741d6c0d475664fc48790917cefed455a4307227zhanyong.wan//   GTEST_OS_HPUX     - HP-UX
1260af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_OS_LINUX    - Linux
1275017fe0090e8902d028ba38753c00d73f16d83f0zhanyong.wan//     GTEST_OS_LINUX_ANDROID - Google Android
1280af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_OS_MAC      - Mac OS X
129a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm//     GTEST_OS_IOS    - iOS
13042bf979ce7c107bfc214758e4a511232dd9b2e0avladlosev//   GTEST_OS_NACL     - Google Native Client (NaCl)
131814a5e9310bbc8aeb0b985c1dcb66496835bf73avladlosev//   GTEST_OS_OPENBSD  - OpenBSD
132386da2037dc7b1d063ac43bf146889b1edcafe7evladlosev//   GTEST_OS_QNX      - QNX
1330af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_OS_SOLARIS  - Sun Solaris
1340af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_OS_SYMBIAN  - Symbian
135b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan//   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
136b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan//     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
137b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan//     GTEST_OS_WINDOWS_MINGW    - MinGW
13881e1cc73c83265e54b2ec7edc17e77f4d1b89e86zhanyong.wan//     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
1398120f66c3249e253f03fdb48bee7e528bc038d31billydonahue//     GTEST_OS_WINDOWS_PHONE    - Windows Phone
1408120f66c3249e253f03fdb48bee7e528bc038d31billydonahue//     GTEST_OS_WINDOWS_RT       - Windows Store App/WinRT
1410af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_OS_ZOS      - z/OS
142d2849f573052ba8431a887e0034b1be353a0d9b4shiqian//
143b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
144b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian// most stable support.  Since core members of the Google Test project
145b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian// don't have access to other platforms, support for them may be less
146b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian// stable.  If you notice any problems on your platform, please notify
147b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian// googletestframework@googlegroups.com (patches for fixing them are
148b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian// even more welcome!).
149b6a296d0f7caff7140f422e49f5398c9ef17504dshiqian//
150d3eb97f32192acf79995983e32a20d8b3afd5872kosak// It is possible that none of the GTEST_OS_* macros are defined.
151d3eb97f32192acf79995983e32a20d8b3afd5872kosak
152d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Feature-indicating macros
153d3eb97f32192acf79995983e32a20d8b3afd5872kosak// -------------------------
154d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
155d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Macros indicating which Google Test features are available (a macro
156d3eb97f32192acf79995983e32a20d8b3afd5872kosak// is defined to 1 if the corresponding feature is supported;
157d3eb97f32192acf79995983e32a20d8b3afd5872kosak// otherwise UNDEFINED -- it's never defined to 0.).  Google Test
158d3eb97f32192acf79995983e32a20d8b3afd5872kosak// defines these macros automatically.  Code outside Google Test MUST
159d3eb97f32192acf79995983e32a20d8b3afd5872kosak// NOT define them.
160d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
161d3eb97f32192acf79995983e32a20d8b3afd5872kosak// These macros are public so that portable tests can be written.
162d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Such tests typically surround code using a feature with an #if
163d3eb97f32192acf79995983e32a20d8b3afd5872kosak// which controls that code.  For example:
164d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
165d3eb97f32192acf79995983e32a20d8b3afd5872kosak// #if GTEST_HAS_DEATH_TEST
166d3eb97f32192acf79995983e32a20d8b3afd5872kosak//   EXPECT_DEATH(DoSomethingDeadly());
167d3eb97f32192acf79995983e32a20d8b3afd5872kosak// #endif
168d201456903f3ecae1f7794edfab0d5678e64226shiqian//
1690af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
1700af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//                            tests)
1710af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_HAS_DEATH_TEST   - death tests
1720af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_HAS_PARAM_TEST   - value-parameterized tests
1730af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_HAS_TYPED_TEST   - typed tests
1740af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
175d3eb97f32192acf79995983e32a20d8b3afd5872kosak//   GTEST_IS_THREADSAFE    - Google Test is thread-safe.
176e96d247b20116646f343b6e2ec37af154f655977vladlosev//   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
177e96d247b20116646f343b6e2ec37af154f655977vladlosev//                            GTEST_HAS_POSIX_RE (see above) which users can
178e96d247b20116646f343b6e2ec37af154f655977vladlosev//                            define themselves.
1790af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan//   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
180c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan//                            the above two are mutually exclusive.
18106d04c0945bf47bae90532552e6e8294802fc9aavladlosev//   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
182d3eb97f32192acf79995983e32a20d8b3afd5872kosak
183d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Misc public macros
184d3eb97f32192acf79995983e32a20d8b3afd5872kosak// ------------------
185d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
186d3eb97f32192acf79995983e32a20d8b3afd5872kosak//   GTEST_FLAG(flag_name)  - references the variable corresponding to
187d3eb97f32192acf79995983e32a20d8b3afd5872kosak//                            the given Google Test flag.
188d3eb97f32192acf79995983e32a20d8b3afd5872kosak
189d3eb97f32192acf79995983e32a20d8b3afd5872kosak// Internal utilities
190d3eb97f32192acf79995983e32a20d8b3afd5872kosak// ------------------
191d3eb97f32192acf79995983e32a20d8b3afd5872kosak//
192d3eb97f32192acf79995983e32a20d8b3afd5872kosak// The following macros and utilities are for Google Test's INTERNAL
193d3eb97f32192acf79995983e32a20d8b3afd5872kosak// use only.  Code outside Google Test MUST NOT USE THEM DIRECTLY.
194d201456903f3ecae1f7794edfab0d5678e64226shiqian//
195d201456903f3ecae1f7794edfab0d5678e64226shiqian// Macros for basic C++ coding:
196e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
1970da92aaf7f696ebfa2374247ae9010dacbc057fczhanyong.wan//   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
1980da92aaf7f696ebfa2374247ae9010dacbc057fczhanyong.wan//                              variable don't have to be used.
1997b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan//   GTEST_DISALLOW_ASSIGN_   - disables operator=.
200e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
201e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
20241a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak//   GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is
20341a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak//                                        suppressed (constant conditional).
20441a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak//   GTEST_INTENTIONAL_CONST_COND_POP_  - finish code section where MSVC C4127
20541a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak//                                        is suppressed.
206d201456903f3ecae1f7794edfab0d5678e64226shiqian//
20735956659eaaafd4b356acfbabcb48c183d957ff4kosak// C++11 feature wrappers:
20835956659eaaafd4b356acfbabcb48c183d957ff4kosak//
209d3d142ef1cc4956307d3a248e52b9f826f305048kosak//   testing::internal::move  - portability wrapper for std::move.
21035956659eaaafd4b356acfbabcb48c183d957ff4kosak//
211d201456903f3ecae1f7794edfab0d5678e64226shiqian// Synchronization:
212d201456903f3ecae1f7794edfab0d5678e64226shiqian//   Mutex, MutexLock, ThreadLocal, GetThreadCount()
213d3eb97f32192acf79995983e32a20d8b3afd5872kosak//                            - synchronization primitives.
214d201456903f3ecae1f7794edfab0d5678e64226shiqian//
215d201456903f3ecae1f7794edfab0d5678e64226shiqian// Template meta programming:
216d2849f573052ba8431a887e0034b1be353a0d9b4shiqian//   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
217fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan//   IteratorTraits - partial implementation of std::iterator_traits, which
218fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan//                    is not available in libCstd when compiled with Sun C++.
219d201456903f3ecae1f7794edfab0d5678e64226shiqian//
220d201456903f3ecae1f7794edfab0d5678e64226shiqian// Smart pointers:
221d201456903f3ecae1f7794edfab0d5678e64226shiqian//   scoped_ptr     - as in TR2.
222d201456903f3ecae1f7794edfab0d5678e64226shiqian//
223d201456903f3ecae1f7794edfab0d5678e64226shiqian// Regular expressions:
224d201456903f3ecae1f7794edfab0d5678e64226shiqian//   RE             - a simple regular expression class using the POSIX
22535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//                    Extended Regular Expression syntax on UNIX-like
22635c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//                    platforms, or a reduced regular exception syntax on
22735c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan//                    other platforms, including Windows.
228d201456903f3ecae1f7794edfab0d5678e64226shiqian//
229d201456903f3ecae1f7794edfab0d5678e64226shiqian// Logging:
230e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   GTEST_LOG_()   - logs messages at the specified severity level.
231d201456903f3ecae1f7794edfab0d5678e64226shiqian//   LogToStderr()  - directs all log messages to stderr.
232d201456903f3ecae1f7794edfab0d5678e64226shiqian//   FlushInfoLog() - flushes informational log messages.
233d201456903f3ecae1f7794edfab0d5678e64226shiqian//
234fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan// Stdout and stderr capturing:
235fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan//   CaptureStdout()     - starts capturing stdout.
236fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan//   GetCapturedStdout() - stops capturing stdout and returns the captured
237fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan//                         string.
238d201456903f3ecae1f7794edfab0d5678e64226shiqian//   CaptureStderr()     - starts capturing stderr.
239d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GetCapturedStderr() - stops capturing stderr and returns the captured
240d201456903f3ecae1f7794edfab0d5678e64226shiqian//                         string.
241d201456903f3ecae1f7794edfab0d5678e64226shiqian//
242d201456903f3ecae1f7794edfab0d5678e64226shiqian// Integer types:
243d201456903f3ecae1f7794edfab0d5678e64226shiqian//   TypeWithSize   - maps an integer to a int type.
244d201456903f3ecae1f7794edfab0d5678e64226shiqian//   Int32, UInt32, Int64, UInt64, TimeInMillis
245d201456903f3ecae1f7794edfab0d5678e64226shiqian//                  - integers of known sizes.
246d201456903f3ecae1f7794edfab0d5678e64226shiqian//   BiggestInt     - the biggest signed integer type.
247d201456903f3ecae1f7794edfab0d5678e64226shiqian//
248d201456903f3ecae1f7794edfab0d5678e64226shiqian// Command-line utilities:
249d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GTEST_DECLARE_*()  - declares a flag.
250d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GTEST_DEFINE_*()   - defines a flag.
25169a40b7d4ab4171cbe4ef920e7a5171109e2064cvladlosev//   GetInjectableArgvs() - returns the command line as a vector of strings.
252d201456903f3ecae1f7794edfab0d5678e64226shiqian//
253d201456903f3ecae1f7794edfab0d5678e64226shiqian// Environment variable utilities:
254d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GetEnv()             - gets the value of an environment variable.
255d201456903f3ecae1f7794edfab0d5678e64226shiqian//   BoolFromGTestEnv()   - parses a bool environment variable.
256d201456903f3ecae1f7794edfab0d5678e64226shiqian//   Int32FromGTestEnv()  - parses an Int32 environment variable.
257d201456903f3ecae1f7794edfab0d5678e64226shiqian//   StringFromGTestEnv() - parses a string environment variable.
258d201456903f3ecae1f7794edfab0d5678e64226shiqian
25935c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan#include <ctype.h>   // for isspace, etc
26035c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan#include <stddef.h>  // for ptrdiff_t
261d201456903f3ecae1f7794edfab0d5678e64226shiqian#include <stdlib.h>
262d201456903f3ecae1f7794edfab0d5678e64226shiqian#include <stdio.h>
2633c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan#include <string.h>
2644853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan#ifndef _WIN32_WCE
265ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <sys/types.h>
266ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <sys/stat.h>
2674853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan#endif  // !_WIN32_WCE
2683c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
269a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm#if defined __APPLE__
270a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm# include <AvailabilityMacros.h>
271a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm# include <TargetConditionals.h>
272a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm#endif
273a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm
2748120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#include <algorithm>  // NOLINT
2753c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan#include <iostream>  // NOLINT
2767b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan#include <sstream>  // NOLINT
2777b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan#include <string>  // NOLINT
27835956659eaaafd4b356acfbabcb48c183d957ff4kosak#include <utility>
279f972f1680aa5de3230dac197b223336f30210f69kosak#include <vector>  // NOLINT
280d201456903f3ecae1f7794edfab0d5678e64226shiqian
281156d1b513b90deca6287c737e3e6453dc7f64d35kosak#include "gtest/internal/gtest-port-arch.h"
282156d1b513b90deca6287c737e3e6453dc7f64d35kosak#include "gtest/internal/custom/gtest-port.h"
283156d1b513b90deca6287c737e3e6453dc7f64d35kosak
284156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if !defined(GTEST_DEV_EMAIL_)
285156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
286156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_FLAG_PREFIX_ "gtest_"
287156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_FLAG_PREFIX_DASH_ "gtest-"
288156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
289156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_NAME_ "Google Test"
290156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
291156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // !defined(GTEST_DEV_EMAIL_)
292d201456903f3ecae1f7794edfab0d5678e64226shiqian
293f487e9510be94c70f08485887a16b48d756bf38fkosak#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
294f487e9510be94c70f08485887a16b48d756bf38fkosak# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"
295f487e9510be94c70f08485887a16b48d756bf38fkosak#endif  // !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
296f487e9510be94c70f08485887a16b48d756bf38fkosak
29764cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian// Determines the version of gcc that is used to compile this.
29864cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian#ifdef __GNUC__
29964cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian// 40302 means version 4.3.2.
300ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_GCC_VER_ \
30164cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian    (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
30264cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian#endif  // __GNUC__
30364cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
3048120f66c3249e253f03fdb48bee7e528bc038d31billydonahue// Macros for disabling Microsoft Visual C++ warnings.
3058120f66c3249e253f03fdb48bee7e528bc038d31billydonahue//
3068120f66c3249e253f03fdb48bee7e528bc038d31billydonahue//   GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
3078120f66c3249e253f03fdb48bee7e528bc038d31billydonahue//   /* code that triggers warnings C4800 and C4385 */
3088120f66c3249e253f03fdb48bee7e528bc038d31billydonahue//   GTEST_DISABLE_MSC_WARNINGS_POP_()
3098120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#if _MSC_VER >= 1500
3108120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
3118120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    __pragma(warning(push))                        \
3128120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    __pragma(warning(disable: warnings))
3138120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# define GTEST_DISABLE_MSC_WARNINGS_POP_()          \
3148120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    __pragma(warning(pop))
3158120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#else
3168120f66c3249e253f03fdb48bee7e528bc038d31billydonahue// Older versions of MSVC don't have __pragma.
3178120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
3188120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# define GTEST_DISABLE_MSC_WARNINGS_POP_()
3198120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#endif
3208120f66c3249e253f03fdb48bee7e528bc038d31billydonahue
3212147489625ea8071ca560462f19b1ceb8940a229vladlosev#ifndef GTEST_LANG_CXX11
3222147489625ea8071ca560462f19b1ceb8940a229vladlosev// gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when
3232147489625ea8071ca560462f19b1ceb8940a229vladlosev// -std={c,gnu}++{0x,11} is passed.  The C++11 standard specifies a
3242147489625ea8071ca560462f19b1ceb8940a229vladlosev// value for __cplusplus, and recent versions of clang, gcc, and
3252147489625ea8071ca560462f19b1ceb8940a229vladlosev// probably other compilers set that too in C++11 mode.
3262147489625ea8071ca560462f19b1ceb8940a229vladlosev# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
3272147489625ea8071ca560462f19b1ceb8940a229vladlosev// Compiling in at least C++11 mode.
3282147489625ea8071ca560462f19b1ceb8940a229vladlosev#  define GTEST_LANG_CXX11 1
3292147489625ea8071ca560462f19b1ceb8940a229vladlosev# else
3302147489625ea8071ca560462f19b1ceb8940a229vladlosev#  define GTEST_LANG_CXX11 0
3312147489625ea8071ca560462f19b1ceb8940a229vladlosev# endif
3322147489625ea8071ca560462f19b1ceb8940a229vladlosev#endif
3332147489625ea8071ca560462f19b1ceb8940a229vladlosev
3346aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// Distinct from C++11 language support, some environments don't provide
3356aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// proper C++11 library support. Notably, it's possible to build in
3366aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++
3376aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// with no C++11 support.
3386aa0422e8529d76385b64f0a826f5ffd353fd37bkosak//
3396aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__
3406aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// 20110325, but maintenance releases in the 4.4 and 4.5 series followed
3416aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// this date, so check for those versions by their date stamps.
3426aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
3436aa0422e8529d76385b64f0a826f5ffd353fd37bkosak#if GTEST_LANG_CXX11 && \
3446aa0422e8529d76385b64f0a826f5ffd353fd37bkosak    (!defined(__GLIBCXX__) || ( \
3456aa0422e8529d76385b64f0a826f5ffd353fd37bkosak        __GLIBCXX__ >= 20110325ul &&  /* GCC >= 4.6.0 */ \
3466aa0422e8529d76385b64f0a826f5ffd353fd37bkosak        /* Blacklist of patch releases of older branches: */ \
3476aa0422e8529d76385b64f0a826f5ffd353fd37bkosak        __GLIBCXX__ != 20110416ul &&  /* GCC 4.4.6 */ \
3486aa0422e8529d76385b64f0a826f5ffd353fd37bkosak        __GLIBCXX__ != 20120313ul &&  /* GCC 4.4.7 */ \
3496aa0422e8529d76385b64f0a826f5ffd353fd37bkosak        __GLIBCXX__ != 20110428ul &&  /* GCC 4.5.3 */ \
3506aa0422e8529d76385b64f0a826f5ffd353fd37bkosak        __GLIBCXX__ != 20120702ul))   /* GCC 4.5.4 */
3516aa0422e8529d76385b64f0a826f5ffd353fd37bkosak# define GTEST_STDLIB_CXX11 1
3526aa0422e8529d76385b64f0a826f5ffd353fd37bkosak#endif
3536aa0422e8529d76385b64f0a826f5ffd353fd37bkosak
3546aa0422e8529d76385b64f0a826f5ffd353fd37bkosak// Only use C++11 library features if the library provides them.
3556aa0422e8529d76385b64f0a826f5ffd353fd37bkosak#if GTEST_STDLIB_CXX11
3566aa0422e8529d76385b64f0a826f5ffd353fd37bkosak# define GTEST_HAS_STD_BEGIN_AND_END_ 1
3576aa0422e8529d76385b64f0a826f5ffd353fd37bkosak# define GTEST_HAS_STD_FORWARD_LIST_ 1
3586aa0422e8529d76385b64f0a826f5ffd353fd37bkosak# define GTEST_HAS_STD_FUNCTION_ 1
3594f7018ed61966eafae2095ada227075e1ea6377ckosak# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
3606aa0422e8529d76385b64f0a826f5ffd353fd37bkosak# define GTEST_HAS_STD_MOVE_ 1
3616aa0422e8529d76385b64f0a826f5ffd353fd37bkosak# define GTEST_HAS_STD_UNIQUE_PTR_ 1
362f253efc20ec05216eda902a6fb0628c2f5164757kosak# define GTEST_HAS_STD_SHARED_PTR_ 1
3634f7018ed61966eafae2095ada227075e1ea6377ckosak#endif
3644f7018ed61966eafae2095ada227075e1ea6377ckosak
365ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// C++11 specifies that <tuple> provides std::tuple.
366ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// Some platforms still might not have it, however.
367ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#if GTEST_LANG_CXX11
368ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak# define GTEST_HAS_STD_TUPLE_ 1
369ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak# if defined(__clang__)
370ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// Inspired by http://clang.llvm.org/docs/LanguageExtensions.html#__has_include
371ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#  if defined(__has_include) && !__has_include(<tuple>)
372ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#   undef GTEST_HAS_STD_TUPLE_
373ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#  endif
374ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak# elif defined(_MSC_VER)
375ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// Inspired by boost/config/stdlib/dinkumware.hpp
376ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#  if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
377ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#   undef GTEST_HAS_STD_TUPLE_
378ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#  endif
379ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak# elif defined(__GLIBCXX__)
380ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// Inspired by boost/config/stdlib/libstdcpp3.hpp,
381ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// http://gcc.gnu.org/gcc-4.2/changes.html and
382ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak// http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.200x
383ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#  if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
384ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#   undef GTEST_HAS_STD_TUPLE_
385ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#  endif
386ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak# endif
387ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak#endif
388ccf8e33bc59a26745753d494b2535a5f0a97acc5kosak
389e96d247b20116646f343b6e2ec37af154f655977vladlosev// Brings in definitions for functions used in the testing::internal::posix
390e96d247b20116646f343b6e2ec37af154f655977vladlosev// namespace (read, write, close, chdir, isatty, stat). We do not currently
391e96d247b20116646f343b6e2ec37af154f655977vladlosev// use them on Windows Mobile.
392a6340420b9cee27f77c5b91bea807121914a5831kosak#if GTEST_OS_WINDOWS
393a6340420b9cee27f77c5b91bea807121914a5831kosak# if !GTEST_OS_WINDOWS_MOBILE
394a6340420b9cee27f77c5b91bea807121914a5831kosak#  include <direct.h>
395a6340420b9cee27f77c5b91bea807121914a5831kosak#  include <io.h>
396a6340420b9cee27f77c5b91bea807121914a5831kosak# endif
397a6340420b9cee27f77c5b91bea807121914a5831kosak// In order to avoid having to include <windows.h>, use forward declaration
398a6340420b9cee27f77c5b91bea807121914a5831kosak// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
399a6340420b9cee27f77c5b91bea807121914a5831kosak// This assumption is verified by
400a6340420b9cee27f77c5b91bea807121914a5831kosak// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
401a6340420b9cee27f77c5b91bea807121914a5831kosakstruct _RTL_CRITICAL_SECTION;
402a6340420b9cee27f77c5b91bea807121914a5831kosak#else
403e96d247b20116646f343b6e2ec37af154f655977vladlosev// This assumes that non-Windows OSes provide unistd.h. For OSes where this
404e96d247b20116646f343b6e2ec37af154f655977vladlosev// is not the case, we need to include headers that provide the functions
405e96d247b20116646f343b6e2ec37af154f655977vladlosev// mentioned above.
406ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <unistd.h>
4072147489625ea8071ca560462f19b1ceb8940a229vladlosev# include <strings.h>
408a6340420b9cee27f77c5b91bea807121914a5831kosak#endif  // GTEST_OS_WINDOWS
409e96d247b20116646f343b6e2ec37af154f655977vladlosev
41078bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#if GTEST_OS_LINUX_ANDROID
41178bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// Used to define __ANDROID_API__ matching the target NDK API level.
41278bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  include <android/api-level.h>  // NOLINT
41378bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#endif
41478bf6d5724e733cce313228856e18d5c372b4fb3vladlosev
415e96d247b20116646f343b6e2ec37af154f655977vladlosev// Defines this to true iff Google Test can use POSIX regular expressions.
416e96d247b20116646f343b6e2ec37af154f655977vladlosev#ifndef GTEST_HAS_POSIX_RE
41778bf6d5724e733cce313228856e18d5c372b4fb3vladlosev# if GTEST_OS_LINUX_ANDROID
41878bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// On Android, <regex.h> is only available starting with Gingerbread.
41978bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
42078bf6d5724e733cce313228856e18d5c372b4fb3vladlosev# else
42178bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
42278bf6d5724e733cce313228856e18d5c372b4fb3vladlosev# endif
423e96d247b20116646f343b6e2ec37af154f655977vladlosev#endif
424e96d247b20116646f343b6e2ec37af154f655977vladlosev
425156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if GTEST_USES_PCRE
426156d1b513b90deca6287c737e3e6453dc7f64d35kosak// The appropriate headers have already been included.
427156d1b513b90deca6287c737e3e6453dc7f64d35kosak
428156d1b513b90deca6287c737e3e6453dc7f64d35kosak#elif GTEST_HAS_POSIX_RE
429c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan
430c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan// On some platforms, <regex.h> needs someone to define size_t, and
431c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan// won't compile otherwise.  We can #include it here as we already
432c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan// included <stdlib.h>, which is guaranteed to define size_t through
433c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan// <stddef.h>.
434ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <regex.h>  // NOLINT
4353c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
436ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_USES_POSIX_RE 1
437c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan
4383c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan#elif GTEST_OS_WINDOWS
4393c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
4403c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// <regex.h> is not available on Windows.  Use our own simple regex
4413c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// implementation instead.
442ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_USES_SIMPLE_RE 1
4433c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
444c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan#else
445c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan
4464984c93490eeeb7d3d1979b30a39a21cad07cba5zhanyong.wan// <regex.h> may not be available on this platform.  Use our own
4474984c93490eeeb7d3d1979b30a39a21cad07cba5zhanyong.wan// simple regex implementation instead.
448ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_USES_SIMPLE_RE 1
449c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan
450156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // GTEST_USES_PCRE
451c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan
452cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev#ifndef GTEST_HAS_EXCEPTIONS
453cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// The user didn't tell us whether exceptions are enabled, so we need
454cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// to figure it out.
455ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# if defined(_MSC_VER) || defined(__BORLANDC__)
456c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
457c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan// macro to enable exceptions, so we'll do the same.
458d201456903f3ecae1f7794edfab0d5678e64226shiqian// Assumes that exceptions are enabled by default.
459ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  ifndef _HAS_EXCEPTIONS
460ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define _HAS_EXCEPTIONS 1
461ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif  // _HAS_EXCEPTIONS
462ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
4637489581db8ea450d22f64e9a7a824e275fa605a0kosak# elif defined(__clang__)
46483602c834044185eb6ebc67d4c6c474f3593830akosak// clang defines __EXCEPTIONS iff exceptions are enabled before clang 220714,
46583602c834044185eb6ebc67d4c6c474f3593830akosak// but iff cleanups are enabled after that. In Obj-C++ files, there can be
46683602c834044185eb6ebc67d4c6c474f3593830akosak// cleanups for ObjC exceptions which also need cleanups, even if C++ exceptions
46783602c834044185eb6ebc67d4c6c474f3593830akosak// are disabled. clang has __has_feature(cxx_exceptions) which checks for C++
46883602c834044185eb6ebc67d4c6c474f3593830akosak// exceptions starting at clang r206352, but which checked for cleanups prior to
46983602c834044185eb6ebc67d4c6c474f3593830akosak// that. To reliably check for C++ exception availability with clang, check for
47083602c834044185eb6ebc67d4c6c474f3593830akosak// __EXCEPTIONS && __has_feature(cxx_exceptions).
471b215e30cadd11db7c9f378b57ffecce92aacce37kosak#  define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
472ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif defined(__GNUC__) && __EXCEPTIONS
473cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
474ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_EXCEPTIONS 1
475ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif defined(__SUNPRO_CC)
476cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// Sun Pro CC supports exceptions.  However, there is no compile-time way of
477cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// detecting whether they are enabled or not.  Therefore, we assume that
478cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// they are enabled unless the user tells us otherwise.
479ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_EXCEPTIONS 1
480ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif defined(__IBMCPP__) && __EXCEPTIONS
48106d04c0945bf47bae90532552e6e8294802fc9aavladlosev// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
482ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_EXCEPTIONS 1
483741d6c0d475664fc48790917cefed455a4307227zhanyong.wan# elif defined(__HP_aCC)
484741d6c0d475664fc48790917cefed455a4307227zhanyong.wan// Exception handling is in effect by default in HP aCC compiler. It has to
485741d6c0d475664fc48790917cefed455a4307227zhanyong.wan// be turned of by +noeh compiler option if desired.
486741d6c0d475664fc48790917cefed455a4307227zhanyong.wan#  define GTEST_HAS_EXCEPTIONS 1
487ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
488cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// For other compilers, we assume exceptions are disabled to be
489cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev// conservative.
490ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_EXCEPTIONS 0
491ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // defined(_MSC_VER) || defined(__BORLANDC__)
492cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev#endif  // GTEST_HAS_EXCEPTIONS
493d201456903f3ecae1f7794edfab0d5678e64226shiqian
49488e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan#if !defined(GTEST_HAS_STD_STRING)
49588e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan// Even though we don't use this macro any longer, we keep it in case
49688e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan// some clients still depend on it.
497ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_STD_STRING 1
49888e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan#elif !GTEST_HAS_STD_STRING
49988e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan// The user told us that ::std::string isn't available.
500ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# error "Google Test cannot be used where ::std::string isn't available."
50188e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan#endif  // !defined(GTEST_HAS_STD_STRING)
502d201456903f3ecae1f7794edfab0d5678e64226shiqian
503d201456903f3ecae1f7794edfab0d5678e64226shiqian#ifndef GTEST_HAS_GLOBAL_STRING
504d201456903f3ecae1f7794edfab0d5678e64226shiqian// The user didn't tell us whether ::string is available, so we need
505d201456903f3ecae1f7794edfab0d5678e64226shiqian// to figure it out.
506d201456903f3ecae1f7794edfab0d5678e64226shiqian
507ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_GLOBAL_STRING 0
508d201456903f3ecae1f7794edfab0d5678e64226shiqian
509d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_HAS_GLOBAL_STRING
510d201456903f3ecae1f7794edfab0d5678e64226shiqian
511d201456903f3ecae1f7794edfab0d5678e64226shiqian#ifndef GTEST_HAS_STD_WSTRING
512d201456903f3ecae1f7794edfab0d5678e64226shiqian// The user didn't tell us whether ::std::wstring is available, so we need
513d201456903f3ecae1f7794edfab0d5678e64226shiqian// to figure it out.
514d201456903f3ecae1f7794edfab0d5678e64226shiqian// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
515d201456903f3ecae1f7794edfab0d5678e64226shiqian//   is available.
516d201456903f3ecae1f7794edfab0d5678e64226shiqian
517e96d247b20116646f343b6e2ec37af154f655977vladlosev// Cygwin 1.7 and below doesn't support ::std::wstring.
5185017fe0090e8902d028ba38753c00d73f16d83f0zhanyong.wan// Solaris' libc++ doesn't support it either.  Android has
5195017fe0090e8902d028ba38753c00d73f16d83f0zhanyong.wan// no support for it at least as recent as Froyo (2.2).
5205017fe0090e8902d028ba38753c00d73f16d83f0zhanyong.wan# define GTEST_HAS_STD_WSTRING \
5215017fe0090e8902d028ba38753c00d73f16d83f0zhanyong.wan    (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
522d201456903f3ecae1f7794edfab0d5678e64226shiqian
523d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_HAS_STD_WSTRING
524d201456903f3ecae1f7794edfab0d5678e64226shiqian
525d201456903f3ecae1f7794edfab0d5678e64226shiqian#ifndef GTEST_HAS_GLOBAL_WSTRING
526d201456903f3ecae1f7794edfab0d5678e64226shiqian// The user didn't tell us whether ::wstring is available, so we need
527d201456903f3ecae1f7794edfab0d5678e64226shiqian// to figure it out.
528ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_GLOBAL_WSTRING \
529bbab12725025270beb12cb62a73b9cfc33bdec85zhanyong.wan    (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
530d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_HAS_GLOBAL_WSTRING
531d201456903f3ecae1f7794edfab0d5678e64226shiqian
53264cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian// Determines whether RTTI is available.
53364cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian#ifndef GTEST_HAS_RTTI
53464cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian// The user didn't tell us whether RTTI is enabled, so we need to
53564cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian// figure it out.
53664cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
537ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# ifdef _MSC_VER
53864cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
539ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
540ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define GTEST_HAS_RTTI 1
541ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  else
542ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define GTEST_HAS_RTTI 0
543ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif
54464cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
54564cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
546ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
5473569c3c86d520bd04ea806f84c9cb5aad0615fdfzhanyong.wan
548ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  ifdef __GXX_RTTI
54978bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// When building against STLport with the Android NDK and with
55078bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// -frtti -fno-exceptions, the build fails at link time with undefined
55178bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
55278bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// so disable RTTI when detected.
55378bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#   if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
55478bf6d5724e733cce313228856e18d5c372b4fb3vladlosev       !defined(__EXCEPTIONS)
55578bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#    define GTEST_HAS_RTTI 0
55678bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#   else
55778bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#    define GTEST_HAS_RTTI 1
55878bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#   endif  // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
559ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  else
560ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define GTEST_HAS_RTTI 0
561ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif  // __GXX_RTTI
56264cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
563cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
564cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
565cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev// first version with C++ support.
566cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev# elif defined(__clang__)
567cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev
568cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev#  define GTEST_HAS_RTTI __has_feature(cxx_rtti)
569cdb24f86d56e5a3ff84b6f1fa71e0b33f22d9152vladlosev
5703569c3c86d520bd04ea806f84c9cb5aad0615fdfzhanyong.wan// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
5713569c3c86d520bd04ea806f84c9cb5aad0615fdfzhanyong.wan// both the typeid and dynamic_cast features are present.
572ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
5732346d25784279f0eb6dfcd4e9ab28ae572baea07zhanyong.wan
574ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  ifdef __RTTI_ALL__
575ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define GTEST_HAS_RTTI 1
576ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  else
577ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define GTEST_HAS_RTTI 0
578ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif
5792346d25784279f0eb6dfcd4e9ab28ae572baea07zhanyong.wan
580ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
58164cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
5823569c3c86d520bd04ea806f84c9cb5aad0615fdfzhanyong.wan// For all other compilers, we assume RTTI is enabled.
583ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_RTTI 1
58464cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
585ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // _MSC_VER
58664cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
58764cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian#endif  // GTEST_HAS_RTTI
58864cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian
589e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// It's this header's responsibility to #include <typeinfo> when RTTI
590e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// is enabled.
591e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan#if GTEST_HAS_RTTI
592ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <typeinfo>
593e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan#endif
594e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
5953bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// Determines whether Google Test can use the pthreads library.
596e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#ifndef GTEST_HAS_PTHREAD
5971d53731f2c210557caab5660dbe2c578dce6114fkosak// The user didn't tell us explicitly, so we make reasonable assumptions about
5981d53731f2c210557caab5660dbe2c578dce6114fkosak// which platforms have pthreads support.
5993bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
6003bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
6013bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// to your compiler flags.
602386da2037dc7b1d063ac43bf146889b1edcafe7evladlosev# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \
6031d53731f2c210557caab5660dbe2c578dce6114fkosak    || GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NACL)
604e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#endif  // GTEST_HAS_PTHREAD
605e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
6063899557cb8563bb0da8f44d435bb02b2095e07fbvladlosev#if GTEST_HAS_PTHREAD
6073899557cb8563bb0da8f44d435bb02b2095e07fbvladlosev// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
6083899557cb8563bb0da8f44d435bb02b2095e07fbvladlosev// true.
609ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <pthread.h>  // NOLINT
610e96d247b20116646f343b6e2ec37af154f655977vladlosev
611e96d247b20116646f343b6e2ec37af154f655977vladlosev// For timespec and nanosleep, used below.
612ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# include <time.h>  // NOLINT
6133899557cb8563bb0da8f44d435bb02b2095e07fbvladlosev#endif
6143899557cb8563bb0da8f44d435bb02b2095e07fbvladlosev
615fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak// Determines if hash_map/hash_set are available.
616fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak// Only used for testing against those containers.
617fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak#if !defined(GTEST_HAS_HASH_MAP_)
618fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak# if _MSC_VER
619fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak#  define GTEST_HAS_HASH_MAP_ 1  // Indicates that hash_map is available.
620fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak#  define GTEST_HAS_HASH_SET_ 1  // Indicates that hash_set is available.
621fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak# endif  // _MSC_VER
622fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak#endif  // !defined(GTEST_HAS_HASH_MAP_)
623fe95bc332d92c6e3f5c2e07fd681bd3549b77374kosak
624532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan// Determines whether Google Test can use tr1/tuple.  You can define
625532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan// this macro to 0 to prevent Google Test from using tuple (any
626532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan// feature depending on tuple with be disabled in this mode).
6273d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev#ifndef GTEST_HAS_TR1_TUPLE
62878bf6d5724e733cce313228856e18d5c372b4fb3vladlosev# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
62978bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
63078bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  define GTEST_HAS_TR1_TUPLE 0
63178bf6d5724e733cce313228856e18d5c372b4fb3vladlosev# else
632532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan// The user didn't tell us not to do it, so we assume it's OK.
63378bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  define GTEST_HAS_TR1_TUPLE 1
63478bf6d5724e733cce313228856e18d5c372b4fb3vladlosev# endif
635532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan#endif  // GTEST_HAS_TR1_TUPLE
636532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan
637532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan// Determines whether Google Test's own tr1 tuple implementation
638532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan// should be used.
639532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan#ifndef GTEST_USE_OWN_TR1_TUPLE
6403d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev// The user didn't tell us, so we need to figure it out.
6413d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev
642fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan// We use our own TR1 tuple if we aren't sure the user has an
6432147489625ea8071ca560462f19b1ceb8940a229vladlosev// implementation of it already.  At this time, libstdc++ 4.0.0+ and
6442147489625ea8071ca560462f19b1ceb8940a229vladlosev// MSVC 2010 are the only mainstream standard libraries that come
6452147489625ea8071ca560462f19b1ceb8940a229vladlosev// with a TR1 tuple implementation.  NVIDIA's CUDA NVCC compiler
6462147489625ea8071ca560462f19b1ceb8940a229vladlosev// pretends to be GCC by defining __GNUC__ and friends, but cannot
6472147489625ea8071ca560462f19b1ceb8940a229vladlosev// compile GCC's tuple implementation.  MSVC 2008 (9.0) provides TR1
6482147489625ea8071ca560462f19b1ceb8940a229vladlosev// tuple in a 323 MB Feature Pack download, which we cannot assume the
6492147489625ea8071ca560462f19b1ceb8940a229vladlosev// user has.  QNX's QCC compiler is a modified GCC but it doesn't
6502147489625ea8071ca560462f19b1ceb8940a229vladlosev// support TR1 tuple.  libc++ only provides std::tuple, in C++11 mode,
6512147489625ea8071ca560462f19b1ceb8940a229vladlosev// and it can be used with some compilers that define __GNUC__.
652386da2037dc7b1d063ac43bf146889b1edcafe7evladlosev# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
6532147489625ea8071ca560462f19b1ceb8940a229vladlosev      && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600
6542147489625ea8071ca560462f19b1ceb8940a229vladlosev#  define GTEST_ENV_HAS_TR1_TUPLE_ 1
6552147489625ea8071ca560462f19b1ceb8940a229vladlosev# endif
6562147489625ea8071ca560462f19b1ceb8940a229vladlosev
657268ba618154d80648aca80a4e9298dab5cceed75jgm// C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
658268ba618154d80648aca80a4e9298dab5cceed75jgm// in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
659268ba618154d80648aca80a4e9298dab5cceed75jgm// can build with clang but need to use gcc4.2's libstdc++).
660268ba618154d80648aca80a4e9298dab5cceed75jgm# if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
6612147489625ea8071ca560462f19b1ceb8940a229vladlosev#  define GTEST_ENV_HAS_STD_TUPLE_ 1
6622147489625ea8071ca560462f19b1ceb8940a229vladlosev# endif
6632147489625ea8071ca560462f19b1ceb8940a229vladlosev
6642147489625ea8071ca560462f19b1ceb8940a229vladlosev# if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
665ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_USE_OWN_TR1_TUPLE 0
666ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
667ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_USE_OWN_TR1_TUPLE 1
668ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif
669532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan
670532dc2de35f2cef191bc91c3587a9f8f4974756fzhanyong.wan#endif  // GTEST_USE_OWN_TR1_TUPLE
6713d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev
6725145e0fb203071648f4be6b77c68fabf3d92ab8ashiqian// To avoid conditional compilation everywhere, we make it
6735145e0fb203071648f4be6b77c68fabf3d92ab8ashiqian// gtest-port.h's responsibility to #include the header implementing
6745df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak// tuple.
6758120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#if GTEST_HAS_STD_TUPLE_
6768120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# include <tuple>  // IWYU pragma: export
6775df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak# define GTEST_TUPLE_NAMESPACE_ ::std
6788120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#endif  // GTEST_HAS_STD_TUPLE_
6795df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak
6808120f66c3249e253f03fdb48bee7e528bc038d31billydonahue// We include tr1::tuple even if std::tuple is available to define printers for
6818120f66c3249e253f03fdb48bee7e528bc038d31billydonahue// them.
6825145e0fb203071648f4be6b77c68fabf3d92ab8ashiqian#if GTEST_HAS_TR1_TUPLE
6835df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak# ifndef GTEST_TUPLE_NAMESPACE_
6845df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak#  define GTEST_TUPLE_NAMESPACE_ ::std::tr1
6855df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak# endif  // GTEST_TUPLE_NAMESPACE_
686e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan
687ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# if GTEST_USE_OWN_TR1_TUPLE
6888120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#  include "gtest/internal/gtest-tuple.h"  // IWYU pragma: export  // NOLINT
6892147489625ea8071ca560462f19b1ceb8940a229vladlosev# elif GTEST_ENV_HAS_STD_TUPLE_
6902147489625ea8071ca560462f19b1ceb8940a229vladlosev#  include <tuple>
6912147489625ea8071ca560462f19b1ceb8940a229vladlosev// C++11 puts its tuple into the ::std namespace rather than
6922147489625ea8071ca560462f19b1ceb8940a229vladlosev// ::std::tr1.  gtest expects tuple to live in ::std::tr1, so put it there.
6932147489625ea8071ca560462f19b1ceb8940a229vladlosev// This causes undefined behavior, but supported compilers react in
6942147489625ea8071ca560462f19b1ceb8940a229vladlosev// the way we intend.
6952147489625ea8071ca560462f19b1ceb8940a229vladlosevnamespace std {
6962147489625ea8071ca560462f19b1ceb8940a229vladlosevnamespace tr1 {
6972147489625ea8071ca560462f19b1ceb8940a229vladlosevusing ::std::get;
6982147489625ea8071ca560462f19b1ceb8940a229vladlosevusing ::std::make_tuple;
6992147489625ea8071ca560462f19b1ceb8940a229vladlosevusing ::std::tuple;
7002147489625ea8071ca560462f19b1ceb8940a229vladlosevusing ::std::tuple_element;
7012147489625ea8071ca560462f19b1ceb8940a229vladlosevusing ::std::tuple_size;
7022147489625ea8071ca560462f19b1ceb8940a229vladlosev}
7032147489625ea8071ca560462f19b1ceb8940a229vladlosev}
7042147489625ea8071ca560462f19b1ceb8940a229vladlosev
705ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif GTEST_OS_SYMBIAN
706e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan
707e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
708e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// use STLport's tuple implementation, which unfortunately doesn't
709e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// work as the copy of STLport distributed with Symbian is incomplete.
710e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
711e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// use its own tuple implementation.
712ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  ifdef BOOST_HAS_TR1_TUPLE
713ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   undef BOOST_HAS_TR1_TUPLE
714ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif  // BOOST_HAS_TR1_TUPLE
715e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan
716e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// This prevents <boost/tr1/detail/config.hpp>, which defines
717e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
718ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
7198120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#  include <tuple>  // IWYU pragma: export  // NOLINT
720e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan
721ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
7229b23e3cc7677643f6adaf6c327275d0a7cdff02czhanyong.wan// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
7239b23e3cc7677643f6adaf6c327275d0a7cdff02czhanyong.wan// not conform to the TR1 spec, which requires the header to be <tuple>.
724683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan
725ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
726683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
727683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan// which is #included by <tr1/tuple>, to not compile when RTTI is
728683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan// disabled.  _TR1_FUNCTIONAL is the header guard for
729683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan// <tr1/functional>.  Hence the following #define is a hack to prevent
730683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan// <tr1/functional> from being included.
731ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   define _TR1_FUNCTIONAL 1
732ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   include <tr1/tuple>
733ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   undef _TR1_FUNCTIONAL  // Allows the user to #include
734683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan                        // <tr1/functional> if he chooses to.
735ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  else
736ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#   include <tr1/tuple>  // NOLINT
737ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
738683f431d830dea27069e7eef11d355bae2b82b72zhanyong.wan
739ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
7409b23e3cc7677643f6adaf6c327275d0a7cdff02czhanyong.wan// If the compiler is not GCC 4.0+, we assume the user is using a
7415145e0fb203071648f4be6b77c68fabf3d92ab8ashiqian// spec-conforming TR1 implementation.
7428120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#  include <tuple>  // IWYU pragma: export  // NOLINT
743ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // GTEST_USE_OWN_TR1_TUPLE
744e68adf5c9089b4e2b7d527eb398471a7728b2939zhanyong.wan
7455145e0fb203071648f4be6b77c68fabf3d92ab8ashiqian#endif  // GTEST_HAS_TR1_TUPLE
7465145e0fb203071648f4be6b77c68fabf3d92ab8ashiqian
74704f025dd5746fca83c6c32f1729b3449721dd60eshiqian// Determines whether clone(2) is supported.
74804f025dd5746fca83c6c32f1729b3449721dd60eshiqian// Usually it will only be available on Linux, excluding
74904f025dd5746fca83c6c32f1729b3449721dd60eshiqian// Linux on the Itanium architecture.
75004f025dd5746fca83c6c32f1729b3449721dd60eshiqian// Also see http://linux.die.net/man/2/clone.
75104f025dd5746fca83c6c32f1729b3449721dd60eshiqian#ifndef GTEST_HAS_CLONE
75204f025dd5746fca83c6c32f1729b3449721dd60eshiqian// The user didn't tell us, so we need to figure it out.
75304f025dd5746fca83c6c32f1729b3449721dd60eshiqian
754ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# if GTEST_OS_LINUX && !defined(__ia64__)
75578bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  if GTEST_OS_LINUX_ANDROID
75678bf6d5724e733cce313228856e18d5c372b4fb3vladlosev// On Android, clone() is only available on ARM starting with Gingerbread.
75778bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#    if defined(__arm__) && __ANDROID_API__ >= 9
75878bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#     define GTEST_HAS_CLONE 1
75978bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#    else
76078bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#     define GTEST_HAS_CLONE 0
76178bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#    endif
76278bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  else
76378bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#   define GTEST_HAS_CLONE 1
76478bf6d5724e733cce313228856e18d5c372b4fb3vladlosev#  endif
765ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
766ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_CLONE 0
767ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // GTEST_OS_LINUX && !defined(__ia64__)
76804f025dd5746fca83c6c32f1729b3449721dd60eshiqian
76904f025dd5746fca83c6c32f1729b3449721dd60eshiqian#endif  // GTEST_HAS_CLONE
77004f025dd5746fca83c6c32f1729b3449721dd60eshiqian
77181e1cc73c83265e54b2ec7edc17e77f4d1b89e86zhanyong.wan// Determines whether to support stream redirection. This is used to test
77281e1cc73c83265e54b2ec7edc17e77f4d1b89e86zhanyong.wan// output correctness and to implement death tests.
77335c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan#ifndef GTEST_HAS_STREAM_REDIRECTION
77435c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// By default, we assume that stream redirection is supported on all
77535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// platforms except known mobile ones.
7768120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \
7778120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
778ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_STREAM_REDIRECTION 0
779ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
780ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_STREAM_REDIRECTION 1
781ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
78235c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan#endif  // GTEST_HAS_STREAM_REDIRECTION
78381e1cc73c83265e54b2ec7edc17e77f4d1b89e86zhanyong.wan
784d201456903f3ecae1f7794edfab0d5678e64226shiqian// Determines whether to support death tests.
78588e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan// Google Test does not support death tests for VC 7.1 and earlier as
78688e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan// abort() in a VC 7.1 application compiled as GUI in debug config
78788e97c822c988eaa9f8bcbaa1ea5d702ffd7d384zhanyong.wan// pops up a dialog window that cannot be suppressed programmatically.
788a1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0jgm#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
78940be033887b7728d70d47adce581a971371ee705kosak     (GTEST_OS_MAC && !GTEST_OS_IOS) || \
79017e4860871d225bce440a3ca9ef1bdaceaed60d8zhanyong.wan     (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
791814a5e9310bbc8aeb0b985c1dcb66496835bf73avladlosev     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
792b215e30cadd11db7c9f378b57ffecce92aacce37kosak     GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD)
793ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_DEATH_TEST 1
7949623aed82cf3e0dcd2fb2fb7442a5a9507ac55a5zhanyong.wan#endif
795d201456903f3ecae1f7794edfab0d5678e64226shiqian
79612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// We don't support MSVC 7.1 with exceptions disabled now.  Therefore
79712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// all the compilers we care about are adequate for supporting
79812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// value-parameterized tests.
7990af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#define GTEST_HAS_PARAM_TEST 1
8003d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev
801a2b1a8556ea64014606d78b09333d9c522430a25shiqian// Determines whether to support type-driven tests.
802a2b1a8556ea64014606d78b09333d9c522430a25shiqian
80306d04c0945bf47bae90532552e6e8294802fc9aavladlosev// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
804741d6c0d475664fc48790917cefed455a4307227zhanyong.wan// Sun Pro CC, IBM Visual Age, and HP aCC support.
80506d04c0945bf47bae90532552e6e8294802fc9aavladlosev#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
806741d6c0d475664fc48790917cefed455a4307227zhanyong.wan    defined(__IBMCPP__) || defined(__HP_aCC)
807ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_TYPED_TEST 1
808ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_TYPED_TEST_P 1
809cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev#endif
810a2b1a8556ea64014606d78b09333d9c522430a25shiqian
8113d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev// Determines whether to support Combine(). This only makes sense when
812e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// value-parameterized tests are enabled.  The implementation doesn't
813e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// work on Sun Studio since it doesn't understand templated conversion
814e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// operators.
815e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
816ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_COMBINE 1
817e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan#endif
8183d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev
8190c5a66245b8c5939b36b2aad6f4d5ab89b724b1avladlosev// Determines whether the system compiler uses UTF-16 for encoding wide strings.
8200af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#define GTEST_WIDE_STRING_USES_UTF16_ \
82106d04c0945bf47bae90532552e6e8294802fc9aavladlosev    (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
8220c5a66245b8c5939b36b2aad6f4d5ab89b724b1avladlosev
823a9f380f5c7ff75cd715c58e11885dddc54baef02zhanyong.wan// Determines whether test results can be streamed to a socket.
824a9f380f5c7ff75cd715c58e11885dddc54baef02zhanyong.wan#if GTEST_OS_LINUX
825ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_CAN_STREAM_RESULTS_ 1
826a9f380f5c7ff75cd715c58e11885dddc54baef02zhanyong.wan#endif
827a9f380f5c7ff75cd715c58e11885dddc54baef02zhanyong.wan
828d201456903f3ecae1f7794edfab0d5678e64226shiqian// Defines some utility macros.
829d201456903f3ecae1f7794edfab0d5678e64226shiqian
830d201456903f3ecae1f7794edfab0d5678e64226shiqian// The GNU compiler emits a warning if nested "if" statements are followed by
831d201456903f3ecae1f7794edfab0d5678e64226shiqian// an "else" statement and braces are not used to explicitly disambiguate the
832d201456903f3ecae1f7794edfab0d5678e64226shiqian// "else" binding.  This leads to problems with code like:
833d201456903f3ecae1f7794edfab0d5678e64226shiqian//
834d201456903f3ecae1f7794edfab0d5678e64226shiqian//   if (gate)
835d201456903f3ecae1f7794edfab0d5678e64226shiqian//     ASSERT_*(condition) << "Some message";
836d201456903f3ecae1f7794edfab0d5678e64226shiqian//
837d201456903f3ecae1f7794edfab0d5678e64226shiqian// The "switch (0) case 0:" idiom is used to suppress this.
838d201456903f3ecae1f7794edfab0d5678e64226shiqian#ifdef __INTEL_COMPILER
839ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
840d201456903f3ecae1f7794edfab0d5678e64226shiqian#else
841ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
842d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif
843d201456903f3ecae1f7794edfab0d5678e64226shiqian
8440da92aaf7f696ebfa2374247ae9010dacbc057fczhanyong.wan// Use this annotation at the end of a struct/class definition to
845d201456903f3ecae1f7794edfab0d5678e64226shiqian// prevent the compiler from optimizing away instances that are never
846d201456903f3ecae1f7794edfab0d5678e64226shiqian// used.  This is useful when all interesting logic happens inside the
847d201456903f3ecae1f7794edfab0d5678e64226shiqian// c'tor and / or d'tor.  Example:
848d201456903f3ecae1f7794edfab0d5678e64226shiqian//
849d201456903f3ecae1f7794edfab0d5678e64226shiqian//   struct Foo {
850d201456903f3ecae1f7794edfab0d5678e64226shiqian//     Foo() { ... }
851e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   } GTEST_ATTRIBUTE_UNUSED_;
8520da92aaf7f696ebfa2374247ae9010dacbc057fczhanyong.wan//
8530da92aaf7f696ebfa2374247ae9010dacbc057fczhanyong.wan// Also use it after a variable or parameter declaration to tell the
8540da92aaf7f696ebfa2374247ae9010dacbc057fczhanyong.wan// compiler the variable/parameter does not have to be used.
855bcb12fa0f651f7de3a10f4535ed856e52b1c3f62shiqian#if defined(__GNUC__) && !defined(COMPILER_ICC)
856ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
857074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#elif defined(__clang__)
858074ed8c8ea5732a71748e41e95e2d7e17d782302kosak# if __has_attribute(unused)
859074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#  define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
860074ed8c8ea5732a71748e41e95e2d7e17d782302kosak# endif
861074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#endif
862074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#ifndef GTEST_ATTRIBUTE_UNUSED_
863ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_ATTRIBUTE_UNUSED_
864bcb12fa0f651f7de3a10f4535ed856e52b1c3f62shiqian#endif
865d201456903f3ecae1f7794edfab0d5678e64226shiqian
8667b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan// A macro to disallow operator=
8677b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan// This should be used in the private: declarations for a class.
8687b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan#define GTEST_DISALLOW_ASSIGN_(type)\
8697b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan  void operator=(type const &)
8707b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan
8717b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan// A macro to disallow copy constructor and operator=
872d201456903f3ecae1f7794edfab0d5678e64226shiqian// This should be used in the private: declarations for a class.
873e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
8747b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan  type(type const &);\
8757b0c8dd3a94fed17493e2f01dc2fa32bc1eb3a20zhanyong.wan  GTEST_DISALLOW_ASSIGN_(type)
876d201456903f3ecae1f7794edfab0d5678e64226shiqian
877d201456903f3ecae1f7794edfab0d5678e64226shiqian// Tell the compiler to warn about unused return values for functions declared
878d201456903f3ecae1f7794edfab0d5678e64226shiqian// with this macro.  The macro should be used on function declarations
879d201456903f3ecae1f7794edfab0d5678e64226shiqian// following the argument list:
880d201456903f3ecae1f7794edfab0d5678e64226shiqian//
881e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
88264cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
883ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
884d201456903f3ecae1f7794edfab0d5678e64226shiqian#else
885ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_MUST_USE_RESULT_
88664cdcb69b28fc26e78d95c574187f7dd9830c84cshiqian#endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
887d201456903f3ecae1f7794edfab0d5678e64226shiqian
88841a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak// MS C++ compiler emits warning when a conditional expression is compile time
88941a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak// constant. In some contexts this warning is false positive and needs to be
89041a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak// suppressed. Use the following two macros in such cases:
89141a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak//
8928120f66c3249e253f03fdb48bee7e528bc038d31billydonahue// GTEST_INTENTIONAL_CONST_COND_PUSH_()
89341a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak// while (true) {
8948120f66c3249e253f03fdb48bee7e528bc038d31billydonahue// GTEST_INTENTIONAL_CONST_COND_POP_()
89541a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak// }
8968120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
8978120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
8988120f66c3249e253f03fdb48bee7e528bc038d31billydonahue# define GTEST_INTENTIONAL_CONST_COND_POP_() \
8998120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    GTEST_DISABLE_MSC_WARNINGS_POP_()
90041a8bc67ab7e7a81735e9d560f54d8d130dcc3abkosak
901f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan// Determine whether the compiler supports Microsoft's Structured Exception
902f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan// Handling.  This is supported by several Windows compilers but generally
903f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan// does not exist on any other system.
904f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan#ifndef GTEST_HAS_SEH
905f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan// The user didn't tell us, so we need to figure it out.
906f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan
907ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# if defined(_MSC_VER) || defined(__BORLANDC__)
908f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan// These two compilers are known to support SEH.
909ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_SEH 1
910ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
911f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan// Assume no SEH.
912ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_HAS_SEH 0
913ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif
914f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan
915a6340420b9cee27f77c5b91bea807121914a5831kosak#define GTEST_IS_THREADSAFE \
916156d1b513b90deca6287c737e3e6453dc7f64d35kosak    (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ \
917bd263344f9e930ab7d3558c1b7706a55739737cbkosak     || (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) \
918bd263344f9e930ab7d3558c1b7706a55739737cbkosak     || GTEST_HAS_PTHREAD)
919a6340420b9cee27f77c5b91bea807121914a5831kosak
920f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan#endif  // GTEST_HAS_SEH
921f2334aa19555063791ec16fe2b476ec00195bbb8zhanyong.wan
92283589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan#ifdef _MSC_VER
92383589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan
924ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# if GTEST_LINKED_AS_SHARED_LIBRARY
925ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_API_ __declspec(dllimport)
926ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# elif GTEST_CREATE_SHARED_LIBRARY
927ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  define GTEST_API_ __declspec(dllexport)
928ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif
92983589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan
93083589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan#endif  // _MSC_VER
93183589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan
93283589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan#ifndef GTEST_API_
933ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_API_
93483589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan#endif
93583589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan
936c91a353c47ea13244550037918ff8dc423063012zhanyong.wan#ifdef __GNUC__
937c006f8c12bc74131692a2df8fd64dcedeafe6c77zhanyong.wan// Ask the compiler to never inline a given function.
938c91a353c47ea13244550037918ff8dc423063012zhanyong.wan# define GTEST_NO_INLINE_ __attribute__((noinline))
939c006f8c12bc74131692a2df8fd64dcedeafe6c77zhanyong.wan#else
940c91a353c47ea13244550037918ff8dc423063012zhanyong.wan# define GTEST_NO_INLINE_
941c91a353c47ea13244550037918ff8dc423063012zhanyong.wan#endif
942c006f8c12bc74131692a2df8fd64dcedeafe6c77zhanyong.wan
943cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
944cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev#if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
945cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev# define GTEST_HAS_CXXABI_H_ 1
946cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev#else
947cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev# define GTEST_HAS_CXXABI_H_ 0
948cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev#endif
949cf3f92ef93ffc35ec1efe8b3b1d65b2624d84de5vladlosev
95037b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak// A function level attribute to disable checking for use of uninitialized
95137b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak// memory when built with MemorySanitizer.
95237b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak#if defined(__clang__)
95337b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak# if __has_feature(memory_sanitizer)
95437b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak#  define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
95537b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak       __attribute__((no_sanitize_memory))
95637b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak# else
95737b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak#  define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
95835956659eaaafd4b356acfbabcb48c183d957ff4kosak# endif  // __has_feature(memory_sanitizer)
95937b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak#else
96037b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
96135956659eaaafd4b356acfbabcb48c183d957ff4kosak#endif  // __clang__
96235956659eaaafd4b356acfbabcb48c183d957ff4kosak
96335956659eaaafd4b356acfbabcb48c183d957ff4kosak// A function level attribute to disable AddressSanitizer instrumentation.
96435956659eaaafd4b356acfbabcb48c183d957ff4kosak#if defined(__clang__)
96535956659eaaafd4b356acfbabcb48c183d957ff4kosak# if __has_feature(address_sanitizer)
96635956659eaaafd4b356acfbabcb48c183d957ff4kosak#  define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
96735956659eaaafd4b356acfbabcb48c183d957ff4kosak       __attribute__((no_sanitize_address))
96835956659eaaafd4b356acfbabcb48c183d957ff4kosak# else
96935956659eaaafd4b356acfbabcb48c183d957ff4kosak#  define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
97035956659eaaafd4b356acfbabcb48c183d957ff4kosak# endif  // __has_feature(address_sanitizer)
97135956659eaaafd4b356acfbabcb48c183d957ff4kosak#else
97235956659eaaafd4b356acfbabcb48c183d957ff4kosak# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
97335956659eaaafd4b356acfbabcb48c183d957ff4kosak#endif  // __clang__
97437b97d1c93fb8283f8bbf54f5618c1c1e5a4726akosak
975ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak// A function level attribute to disable ThreadSanitizer instrumentation.
976ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak#if defined(__clang__)
977ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak# if __has_feature(thread_sanitizer)
978ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak#  define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
979ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak       __attribute__((no_sanitize_thread))
980ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak# else
981ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak#  define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
982ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak# endif  // __has_feature(thread_sanitizer)
983ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak#else
984ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
985ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak#endif  // __clang__
986ffea2d604031a8c732cec8f8de9d9f9bcfbbcf70kosak
987d201456903f3ecae1f7794edfab0d5678e64226shiqiannamespace testing {
988d201456903f3ecae1f7794edfab0d5678e64226shiqian
989d201456903f3ecae1f7794edfab0d5678e64226shiqianclass Message;
990d201456903f3ecae1f7794edfab0d5678e64226shiqian
9918120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#if defined(GTEST_TUPLE_NAMESPACE_)
9925df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak// Import tuple and friends into the ::testing namespace.
9935df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak// It is part of our interface, having them in ::testing allows us to change
9945df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak// their types as needed.
9955df87d70b64dd8080ab9e3f1b0250e74715e2a60kosakusing GTEST_TUPLE_NAMESPACE_::get;
9965df87d70b64dd8080ab9e3f1b0250e74715e2a60kosakusing GTEST_TUPLE_NAMESPACE_::make_tuple;
9975df87d70b64dd8080ab9e3f1b0250e74715e2a60kosakusing GTEST_TUPLE_NAMESPACE_::tuple;
9985df87d70b64dd8080ab9e3f1b0250e74715e2a60kosakusing GTEST_TUPLE_NAMESPACE_::tuple_size;
9995df87d70b64dd8080ab9e3f1b0250e74715e2a60kosakusing GTEST_TUPLE_NAMESPACE_::tuple_element;
10008120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#endif  // defined(GTEST_TUPLE_NAMESPACE_)
10015df87d70b64dd8080ab9e3f1b0250e74715e2a60kosak
1002d201456903f3ecae1f7794edfab0d5678e64226shiqiannamespace internal {
1003d201456903f3ecae1f7794edfab0d5678e64226shiqian
10046a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan// A secret type that Google Test users don't know about.  It has no
10056a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan// definition on purpose.  Therefore it's impossible to create a
10066a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan// Secret object, which is what we want.
10076a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wanclass Secret;
10086a036a5c8c7613e888fad39d92fc3fd84a96fbc7zhanyong.wan
10092ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
10102ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// expression is true. For example, you could use it to verify the
10112ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// size of a static array:
10122ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10135d83ee08dff5775b3bc59d144bc3ea3d4fe9dfb9kosak//   GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
10145d83ee08dff5775b3bc59d144bc3ea3d4fe9dfb9kosak//                         names_incorrect_size);
10152ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10162ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// or to make sure a struct is smaller than a certain size:
10172ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10182ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
10192ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10202ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// The second argument to the macro is the name of the variable. If
10212ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// the expression is false, most compilers will issue a warning/error
10222ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// containing the name of the variable.
10232ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
1024074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#if GTEST_LANG_CXX11
1025074ed8c8ea5732a71748e41e95e2d7e17d782302kosak# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
1026074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#else  // !GTEST_LANG_CXX11
10272ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantemplate <bool>
1028074ed8c8ea5732a71748e41e95e2d7e17d782302kosak  struct CompileAssert {
10292ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan};
10302ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
1031074ed8c8ea5732a71748e41e95e2d7e17d782302kosak# define GTEST_COMPILE_ASSERT_(expr, msg) \
1032fc01f532a622a7d460a4eff816c56c0e501f20f7zhanyong.wan  typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
1033fc01f532a622a7d460a4eff816c56c0e501f20f7zhanyong.wan      msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
1034074ed8c8ea5732a71748e41e95e2d7e17d782302kosak#endif  // !GTEST_LANG_CXX11
10352ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
10362ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// Implementation details of GTEST_COMPILE_ASSERT_:
10372ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
1038074ed8c8ea5732a71748e41e95e2d7e17d782302kosak// (In C++11, we simply use static_assert instead of the following)
1039074ed8c8ea5732a71748e41e95e2d7e17d782302kosak//
10402ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
10412ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   elements (and thus is invalid) when the expression is false.
10422ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10432ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// - The simpler definition
10442ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10452ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
10462ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10472ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   does not work, as gcc supports variable-length arrays whose sizes
10482ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   are determined at run-time (this is gcc's extension and not part
10492ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   of the C++ standard).  As a result, gcc fails to reject the
10502ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   following code with the simple definition:
10512ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10522ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//     int foo;
10532ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
10542ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//                                      // not a compile-time constant.
10552ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10562ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// - By using the type CompileAssert<(bool(expr))>, we ensures that
10572ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   expr is a compile-time constant.  (Template arguments must be
10582ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   determined at compile-time.)
10592ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10602ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
10612ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
10622ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10632ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//     CompileAssert<bool(expr)>
10642ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10652ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   instead, these compilers will refuse to compile
10662ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10672ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
10682ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10692ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   (They seem to think the ">" in "5 > 0" marks the end of the
10702ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   template argument list.)
10712ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10722ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// - The array size is (bool(expr) ? 1 : -1), instead of simply
10732ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10742ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//     ((expr) ? 1 : -1).
10752ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10762ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   This is to avoid running into a bug in MS VC 7.1, which
10772ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
10782ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
10792ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
10802ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
10812ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// This template is declared, but intentionally undefined.
10822ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantemplate <typename T1, typename T2>
10832ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wanstruct StaticAssertTypeEqHelper;
10842ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
10852ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantemplate <typename T>
10868120f66c3249e253f03fdb48bee7e528bc038d31billydonahuestruct StaticAssertTypeEqHelper<T, T> {
10878120f66c3249e253f03fdb48bee7e528bc038d31billydonahue  enum { value = true };
10888120f66c3249e253f03fdb48bee7e528bc038d31billydonahue};
10892ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
10905d83ee08dff5775b3bc59d144bc3ea3d4fe9dfb9kosak// Evaluates to the number of elements in 'array'.
10915d83ee08dff5775b3bc59d144bc3ea3d4fe9dfb9kosak#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
10925d83ee08dff5775b3bc59d144bc3ea3d4fe9dfb9kosak
10932ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#if GTEST_HAS_GLOBAL_STRING
10942ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantypedef ::string string;
10952ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#else
10962ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantypedef ::std::string string;
10972ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#endif  // GTEST_HAS_GLOBAL_STRING
10982ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
10992ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#if GTEST_HAS_GLOBAL_WSTRING
11002ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantypedef ::wstring wstring;
11012ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#elif GTEST_HAS_STD_WSTRING
11022ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantypedef ::std::wstring wstring;
11032ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#endif  // GTEST_HAS_GLOBAL_WSTRING
11042ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
1105f8b268ee86ca74bba3276352f1e7de53d1336c3ezhanyong.wan// A helper for suppressing warnings on constant condition.  It just
1106f8b268ee86ca74bba3276352f1e7de53d1336c3ezhanyong.wan// returns 'condition'.
110783589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wanGTEST_API_ bool IsTrue(bool condition);
1108f8b268ee86ca74bba3276352f1e7de53d1336c3ezhanyong.wan
1109d201456903f3ecae1f7794edfab0d5678e64226shiqian// Defines scoped_ptr.
1110d201456903f3ecae1f7794edfab0d5678e64226shiqian
1111d201456903f3ecae1f7794edfab0d5678e64226shiqian// This implementation of scoped_ptr is PARTIAL - it only contains
1112d201456903f3ecae1f7794edfab0d5678e64226shiqian// enough stuff to satisfy Google Test's need.
1113d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <typename T>
1114d201456903f3ecae1f7794edfab0d5678e64226shiqianclass scoped_ptr {
1115d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
1116b6fe6899bef6dd90572fc0e7f12912d9ad87a19evladlosev  typedef T element_type;
1117b6fe6899bef6dd90572fc0e7f12912d9ad87a19evladlosev
1118d201456903f3ecae1f7794edfab0d5678e64226shiqian  explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
1119d201456903f3ecae1f7794edfab0d5678e64226shiqian  ~scoped_ptr() { reset(); }
1120d201456903f3ecae1f7794edfab0d5678e64226shiqian
1121d201456903f3ecae1f7794edfab0d5678e64226shiqian  T& operator*() const { return *ptr_; }
1122d201456903f3ecae1f7794edfab0d5678e64226shiqian  T* operator->() const { return ptr_; }
1123d201456903f3ecae1f7794edfab0d5678e64226shiqian  T* get() const { return ptr_; }
1124d201456903f3ecae1f7794edfab0d5678e64226shiqian
1125d201456903f3ecae1f7794edfab0d5678e64226shiqian  T* release() {
1126d201456903f3ecae1f7794edfab0d5678e64226shiqian    T* const ptr = ptr_;
1127d201456903f3ecae1f7794edfab0d5678e64226shiqian    ptr_ = NULL;
1128d201456903f3ecae1f7794edfab0d5678e64226shiqian    return ptr;
1129d201456903f3ecae1f7794edfab0d5678e64226shiqian  }
1130d201456903f3ecae1f7794edfab0d5678e64226shiqian
1131d201456903f3ecae1f7794edfab0d5678e64226shiqian  void reset(T* p = NULL) {
1132d201456903f3ecae1f7794edfab0d5678e64226shiqian    if (p != ptr_) {
1133f8b268ee86ca74bba3276352f1e7de53d1336c3ezhanyong.wan      if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
1134d201456903f3ecae1f7794edfab0d5678e64226shiqian        delete ptr_;
1135d201456903f3ecae1f7794edfab0d5678e64226shiqian      }
1136d201456903f3ecae1f7794edfab0d5678e64226shiqian      ptr_ = p;
1137d201456903f3ecae1f7794edfab0d5678e64226shiqian    }
1138d201456903f3ecae1f7794edfab0d5678e64226shiqian  }
11398965a6a0d2165f32e6413594bba6367f271f51e7vladlosev
11408120f66c3249e253f03fdb48bee7e528bc038d31billydonahue  friend void swap(scoped_ptr& a, scoped_ptr& b) {
11418120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    using std::swap;
11428120f66c3249e253f03fdb48bee7e528bc038d31billydonahue    swap(a.ptr_, b.ptr_);
11438120f66c3249e253f03fdb48bee7e528bc038d31billydonahue  }
11448120f66c3249e253f03fdb48bee7e528bc038d31billydonahue
1145d201456903f3ecae1f7794edfab0d5678e64226shiqian private:
1146d201456903f3ecae1f7794edfab0d5678e64226shiqian  T* ptr_;
1147d201456903f3ecae1f7794edfab0d5678e64226shiqian
1148e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
1149d201456903f3ecae1f7794edfab0d5678e64226shiqian};
1150d201456903f3ecae1f7794edfab0d5678e64226shiqian
11513d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev// Defines RE.
1152d201456903f3ecae1f7794edfab0d5678e64226shiqian
115306d04c0945bf47bae90532552e6e8294802fc9aavladlosev// A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
1154d201456903f3ecae1f7794edfab0d5678e64226shiqian// Regular Expression syntax.
115583589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wanclass GTEST_API_ RE {
1156d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
115706d04c0945bf47bae90532552e6e8294802fc9aavladlosev  // A copy constructor is required by the Standard to initialize object
115806d04c0945bf47bae90532552e6e8294802fc9aavladlosev  // references from r-values.
115906d04c0945bf47bae90532552e6e8294802fc9aavladlosev  RE(const RE& other) { Init(other.pattern()); }
116006d04c0945bf47bae90532552e6e8294802fc9aavladlosev
1161d201456903f3ecae1f7794edfab0d5678e64226shiqian  // Constructs an RE from a string.
1162d201456903f3ecae1f7794edfab0d5678e64226shiqian  RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
1163d201456903f3ecae1f7794edfab0d5678e64226shiqian
1164d201456903f3ecae1f7794edfab0d5678e64226shiqian#if GTEST_HAS_GLOBAL_STRING
1165ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1166d201456903f3ecae1f7794edfab0d5678e64226shiqian  RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
1167ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1168d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_HAS_GLOBAL_STRING
1169d201456903f3ecae1f7794edfab0d5678e64226shiqian
1170d201456903f3ecae1f7794edfab0d5678e64226shiqian  RE(const char* regex) { Init(regex); }  // NOLINT
1171d201456903f3ecae1f7794edfab0d5678e64226shiqian  ~RE();
1172d201456903f3ecae1f7794edfab0d5678e64226shiqian
1173d201456903f3ecae1f7794edfab0d5678e64226shiqian  // Returns the string representation of the regex.
1174d201456903f3ecae1f7794edfab0d5678e64226shiqian  const char* pattern() const { return pattern_; }
1175d201456903f3ecae1f7794edfab0d5678e64226shiqian
11763d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  // FullMatch(str, re) returns true iff regular expression re matches
11773d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  // the entire str.
11783d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  // PartialMatch(str, re) returns true iff regular expression re
11793d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  // matches a substring of str (including str itself).
11803d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  //
11813d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  // TODO(wan@google.com): make FullMatch() and PartialMatch() work
11823d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  // when str contains NUL characters.
11833d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  static bool FullMatch(const ::std::string& str, const RE& re) {
11843d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev    return FullMatch(str.c_str(), re);
11853d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  }
1186d201456903f3ecae1f7794edfab0d5678e64226shiqian  static bool PartialMatch(const ::std::string& str, const RE& re) {
1187d201456903f3ecae1f7794edfab0d5678e64226shiqian    return PartialMatch(str.c_str(), re);
1188d201456903f3ecae1f7794edfab0d5678e64226shiqian  }
1189d201456903f3ecae1f7794edfab0d5678e64226shiqian
1190d201456903f3ecae1f7794edfab0d5678e64226shiqian#if GTEST_HAS_GLOBAL_STRING
1191ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
11923d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  static bool FullMatch(const ::string& str, const RE& re) {
11933d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev    return FullMatch(str.c_str(), re);
11943d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  }
1195d201456903f3ecae1f7794edfab0d5678e64226shiqian  static bool PartialMatch(const ::string& str, const RE& re) {
1196d201456903f3ecae1f7794edfab0d5678e64226shiqian    return PartialMatch(str.c_str(), re);
1197d201456903f3ecae1f7794edfab0d5678e64226shiqian  }
1198ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1199d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_HAS_GLOBAL_STRING
1200d201456903f3ecae1f7794edfab0d5678e64226shiqian
12013d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  static bool FullMatch(const char* str, const RE& re);
1202d201456903f3ecae1f7794edfab0d5678e64226shiqian  static bool PartialMatch(const char* str, const RE& re);
1203d201456903f3ecae1f7794edfab0d5678e64226shiqian
1204d201456903f3ecae1f7794edfab0d5678e64226shiqian private:
1205d201456903f3ecae1f7794edfab0d5678e64226shiqian  void Init(const char* regex);
1206d201456903f3ecae1f7794edfab0d5678e64226shiqian
120787fdda2cf24d953f3cbec1e0c266b2db9928f406jgm  // We use a const char* instead of an std::string, as Google Test used to be
120887fdda2cf24d953f3cbec1e0c266b2db9928f406jgm  // used where std::string is not available.  TODO(wan@google.com): change to
120987fdda2cf24d953f3cbec1e0c266b2db9928f406jgm  // std::string.
1210d201456903f3ecae1f7794edfab0d5678e64226shiqian  const char* pattern_;
1211c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan  bool is_valid_;
1212ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1213c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan#if GTEST_USES_POSIX_RE
1214ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
12153d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  regex_t full_regex_;     // For FullMatch().
12163d7042176307f0d7700a3640f3b3bcc8790b8fcdvladlosev  regex_t partial_regex_;  // For PartialMatch().
1217ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1218c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan#else  // GTEST_USES_SIMPLE_RE
1219ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1220c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan  const char* full_pattern_;  // For FullMatch();
1221ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan
1222c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan#endif
1223d201456903f3ecae1f7794edfab0d5678e64226shiqian
122406d04c0945bf47bae90532552e6e8294802fc9aavladlosev  GTEST_DISALLOW_ASSIGN_(RE);
1225c946ae60194727ede9d3ef44754839f48541a981zhanyong.wan};
1226d201456903f3ecae1f7794edfab0d5678e64226shiqian
12279d7455f9844e293dff8b7902f0c2553094f2f976vladlosev// Formats a source file path and a line number as they would appear
12289d7455f9844e293dff8b7902f0c2553094f2f976vladlosev// in an error message from the compiler used to compile this code.
12299d7455f9844e293dff8b7902f0c2553094f2f976vladlosevGTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
12309d7455f9844e293dff8b7902f0c2553094f2f976vladlosev
12319d7455f9844e293dff8b7902f0c2553094f2f976vladlosev// Formats a file location for compiler-independent XML output.
12329d7455f9844e293dff8b7902f0c2553094f2f976vladlosev// Although this function is not platform dependent, we put it next to
12339d7455f9844e293dff8b7902f0c2553094f2f976vladlosev// FormatFileLocation in order to contrast the two functions.
12349d7455f9844e293dff8b7902f0c2553094f2f976vladlosevGTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
12359d7455f9844e293dff8b7902f0c2553094f2f976vladlosev                                                               int line);
12369d7455f9844e293dff8b7902f0c2553094f2f976vladlosev
1237d201456903f3ecae1f7794edfab0d5678e64226shiqian// Defines logging utilities:
1238866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan//   GTEST_LOG_(severity) - logs messages at the specified severity level. The
1239866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan//                          message itself is streamed into the macro.
1240d201456903f3ecae1f7794edfab0d5678e64226shiqian//   LogToStderr()  - directs all log messages to stderr.
1241d201456903f3ecae1f7794edfab0d5678e64226shiqian//   FlushInfoLog() - flushes informational log messages.
1242d201456903f3ecae1f7794edfab0d5678e64226shiqian
1243d201456903f3ecae1f7794edfab0d5678e64226shiqianenum GTestLogSeverity {
1244d201456903f3ecae1f7794edfab0d5678e64226shiqian  GTEST_INFO,
1245d201456903f3ecae1f7794edfab0d5678e64226shiqian  GTEST_WARNING,
1246d201456903f3ecae1f7794edfab0d5678e64226shiqian  GTEST_ERROR,
1247d201456903f3ecae1f7794edfab0d5678e64226shiqian  GTEST_FATAL
1248d201456903f3ecae1f7794edfab0d5678e64226shiqian};
1249d201456903f3ecae1f7794edfab0d5678e64226shiqian
1250866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan// Formats log entry severity, provides a stream object for streaming the
1251866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan// log message, and terminates the message with a newline when going out of
1252866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan// scope.
125383589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wanclass GTEST_API_ GTestLog {
1254866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan public:
1255866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan  GTestLog(GTestLogSeverity severity, const char* file, int line);
1256866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan
1257866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan  // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
1258866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan  ~GTestLog();
1259866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan
1260866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan  ::std::ostream& GetStream() { return ::std::cerr; }
1261866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan
1262866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan private:
1263866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan  const GTestLogSeverity severity_;
1264866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan
1265866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
1266866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan};
1267d201456903f3ecae1f7794edfab0d5678e64226shiqian
1268156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if !defined(GTEST_LOG_)
1269156d1b513b90deca6287c737e3e6453dc7f64d35kosak
1270156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_LOG_(severity) \
1271866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan    ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
1272866f4a94461d765f7f9514b6cb6e82d7b9ea12d2zhanyong.wan                                  __FILE__, __LINE__).GetStream()
1273d201456903f3ecae1f7794edfab0d5678e64226shiqian
1274d201456903f3ecae1f7794edfab0d5678e64226shiqianinline void LogToStderr() {}
1275d201456903f3ecae1f7794edfab0d5678e64226shiqianinline void FlushInfoLog() { fflush(NULL); }
1276d201456903f3ecae1f7794edfab0d5678e64226shiqian
1277156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // !defined(GTEST_LOG_)
1278156d1b513b90deca6287c737e3e6453dc7f64d35kosak
1279156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if !defined(GTEST_CHECK_)
12803bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// INTERNAL IMPLEMENTATION - DO NOT USE.
12813bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
12823bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
12833bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// is not satisfied.
12843bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//  Synopsys:
12853bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    GTEST_CHECK_(boolean_condition);
12863bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//     or
12873bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    GTEST_CHECK_(boolean_condition) << "Additional message";
12883bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
12893bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    This checks the condition and if the condition is not satisfied
12903bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    it prints message about the condition violation, including the
12913bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    condition itself, plus additional message streamed into it, if any,
12923bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    and then it aborts the program. It aborts the program irrespective of
12933bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//    whether it is built in the debug mode or not.
1294156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_CHECK_(condition) \
12953bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan    GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
12963bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan    if (::testing::internal::IsTrue(condition)) \
12973bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan      ; \
12983bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan    else \
12993bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan      GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
1300156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // !defined(GTEST_CHECK_)
13013bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
13024879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// An all-mode assert to verify that the given POSIX-style function
13034879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// call returns 0 (indicating success).  Known limitation: this
13044879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// doesn't expand to a balanced 'if' statement, so enclose the macro
13054879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// in {} if you need to use it as the only statement in an 'if'
13064879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// branch.
13074879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
13084879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  if (const int gtest_error = (posix_call)) \
13094879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
13104879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan                      << gtest_error
13114879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan
1312d3d142ef1cc4956307d3a248e52b9f826f305048kosak#if GTEST_HAS_STD_MOVE_
1313d3d142ef1cc4956307d3a248e52b9f826f305048kosakusing std::move;
131471271d2c95fdf54a3782edea360dca188f926019kosak#else  // GTEST_HAS_STD_MOVE_
1315d3d142ef1cc4956307d3a248e52b9f826f305048kosaktemplate <typename T>
1316d3d142ef1cc4956307d3a248e52b9f826f305048kosakconst T& move(const T& t) {
1317d3d142ef1cc4956307d3a248e52b9f826f305048kosak  return t;
1318d3d142ef1cc4956307d3a248e52b9f826f305048kosak}
1319d3d142ef1cc4956307d3a248e52b9f826f305048kosak#endif  // GTEST_HAS_STD_MOVE_
1320d3d142ef1cc4956307d3a248e52b9f826f305048kosak
1321e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1322e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan//
1323a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// Use ImplicitCast_ as a safe version of static_cast for upcasting in
13242ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
1325a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// const Foo*).  When you use ImplicitCast_, the compiler checks that
1326a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// the cast is safe.  Such explicit ImplicitCast_s are necessary in
13272ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// surprisingly many situations where C++ demands an exact type match
13282ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// instead of an argument type convertable to a target type.
13292ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
1330a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// The syntax for using ImplicitCast_ is the same as for static_cast:
13312ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
1332a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev//   ImplicitCast_<ToType>(expr)
13332ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//
1334a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// ImplicitCast_ would have been part of the C++ standard library,
13352ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// but the proposal was submitted too late.  It will probably make
13362ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// its way into the language in the future.
1337a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev//
1338a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// This relatively ugly name is intentional. It prevents clashes with
1339a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// similar functions users may have (e.g., implicit_cast). The internal
1340a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// namespace alone is not enough because the function can be found by ADL.
13412ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wantemplate<typename To>
134201e229bacf8643eb47938e2ccf34372c7b177921kosakinline To ImplicitCast_(To x) { return x; }
13432ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
13442ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// When you upcast (that is, cast a pointer from type Foo to type
1345a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
13462ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// always succeed.  When you downcast (that is, cast a pointer from
13472ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
13482ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// how do you know the pointer is really of type SubclassOfFoo?  It
13492ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
13502ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// when you downcast, you should use this macro.  In debug mode, we
13512ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// use dynamic_cast<> to double-check the downcast is legal (we die
13522ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// if it's not).  In normal mode, we do the efficient static_cast<>
13532ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// instead.  Thus, it's important to test in debug mode to make sure
13542ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// the cast is legal!
13552ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//    This is the only place in the code we should use dynamic_cast<>.
13562ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// In particular, you SHOULDN'T be using dynamic_cast<> in order to
13572ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// do RTTI (eg code like this:
13582ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
13592ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan//    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
13602ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan// You should design the code some other way not to need this.
1361a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev//
1362a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// This relatively ugly name is intentional. It prevents clashes with
1363a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// similar functions users may have (e.g., down_cast). The internal
1364a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev// namespace alone is not enough because the function can be found by ADL.
1365a198966dd349f446f0ab065e5576db7ac1e48e63vladlosevtemplate<typename To, typename From>  // use like this: DownCast_<T*>(foo);
1366a198966dd349f446f0ab065e5576db7ac1e48e63vladlosevinline To DownCast_(From* f) {  // so we only accept pointers
13672ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  // Ensures that To is a sub-type of From *.  This test is here only
13682ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  // for compile-time type checking, and has no overhead in an
13692ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  // optimized build at run-time, as it will be optimized away
13702ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  // completely.
13718120f66c3249e253f03fdb48bee7e528bc038d31billydonahue  GTEST_INTENTIONAL_CONST_COND_PUSH_()
13722ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  if (false) {
13738120f66c3249e253f03fdb48bee7e528bc038d31billydonahue  GTEST_INTENTIONAL_CONST_COND_POP_()
13742ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan    const To to = NULL;
1375a198966dd349f446f0ab065e5576db7ac1e48e63vladlosev    ::testing::internal::ImplicitCast_<From*>(to);
13762ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  }
13772ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
13782ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#if GTEST_HAS_RTTI
13792ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  // RTTI: debug mode only!
13802ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
13812ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan#endif
13822ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan  return static_cast<To>(f);
13832ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan}
13842ccea88c99d1ae23383d1b8eb3680a4a4d2edd66zhanyong.wan
1385e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// Downcasts the pointer of type Base to Derived.
1386e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// Derived must be a subclass of Base. The parameter MUST
1387e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// point to a class of type Derived, not any subclass of it.
1388e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// When RTTI is available, the function performs a runtime
1389e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// check to enforce this.
1390e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wantemplate <class Derived, class Base>
1391e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wanDerived* CheckedDowncastToActualType(Base* base) {
1392e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan#if GTEST_HAS_RTTI
1393e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  GTEST_CHECK_(typeid(*base) == typeid(Derived));
1394156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif
1395156d1b513b90deca6287c737e3e6453dc7f64d35kosak
1396156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if GTEST_HAS_DOWNCAST_
1397156d1b513b90deca6287c737e3e6453dc7f64d35kosak  return ::down_cast<Derived*>(base);
1398156d1b513b90deca6287c737e3e6453dc7f64d35kosak#elif GTEST_HAS_RTTI
1399e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  return dynamic_cast<Derived*>(base);  // NOLINT
1400e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan#else
1401e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  return static_cast<Derived*>(base);  // Poor man's downcast.
140292344b762a86bd73d79a0db8999ece92fb5069fazhanyong.wan#endif
1403e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan}
1404e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
140535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan#if GTEST_HAS_STREAM_REDIRECTION
1406fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan
1407d201456903f3ecae1f7794edfab0d5678e64226shiqian// Defines the stderr capturer:
1408fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan//   CaptureStdout     - starts capturing stdout.
1409fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan//   GetCapturedStdout - stops capturing stdout and returns the captured string.
1410d201456903f3ecae1f7794edfab0d5678e64226shiqian//   CaptureStderr     - starts capturing stderr.
1411d201456903f3ecae1f7794edfab0d5678e64226shiqian//   GetCapturedStderr - stops capturing stderr and returns the captured string.
1412fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan//
14139f0824b0a61b50fd40e47da2387cd9b3f872ce47zhanyong.wanGTEST_API_ void CaptureStdout();
141487fdda2cf24d953f3cbec1e0c266b2db9928f406jgmGTEST_API_ std::string GetCapturedStdout();
14159f0824b0a61b50fd40e47da2387cd9b3f872ce47zhanyong.wanGTEST_API_ void CaptureStderr();
141687fdda2cf24d953f3cbec1e0c266b2db9928f406jgmGTEST_API_ std::string GetCapturedStderr();
14174984c93490eeeb7d3d1979b30a39a21cad07cba5zhanyong.wan
141835c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan#endif  // GTEST_HAS_STREAM_REDIRECTION
1419fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan
1420195610d30c2234b76bef70a85426ac8d7dbdf9f3kosak// Returns a path to temporary directory.
1421195610d30c2234b76bef70a85426ac8d7dbdf9f3kosakGTEST_API_ std::string TempDir();
1422195610d30c2234b76bef70a85426ac8d7dbdf9f3kosak
1423195610d30c2234b76bef70a85426ac8d7dbdf9f3kosak// Returns the size (in bytes) of a file.
1424195610d30c2234b76bef70a85426ac8d7dbdf9f3kosakGTEST_API_ size_t GetFileSize(FILE* file);
1425195610d30c2234b76bef70a85426ac8d7dbdf9f3kosak
1426195610d30c2234b76bef70a85426ac8d7dbdf9f3kosak// Reads the entire content of a file as a string.
1427195610d30c2234b76bef70a85426ac8d7dbdf9f3kosakGTEST_API_ std::string ReadEntireFile(FILE* file);
1428fd6f2a8a4b3fe8beb31f26b774b460727c410b66zhanyong.wan
1429f972f1680aa5de3230dac197b223336f30210f69kosak// All command line arguments.
1430f972f1680aa5de3230dac197b223336f30210f69kosakGTEST_API_ const ::std::vector<testing::internal::string>& GetArgvs();
1431f972f1680aa5de3230dac197b223336f30210f69kosak
14320af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#if GTEST_HAS_DEATH_TEST
1433d201456903f3ecae1f7794edfab0d5678e64226shiqian
143469a40b7d4ab4171cbe4ef920e7a5171109e2064cvladlosevconst ::std::vector<testing::internal::string>& GetInjectableArgvs();
143569a40b7d4ab4171cbe4ef920e7a5171109e2064cvladlosevvoid SetInjectableArgvs(const ::std::vector<testing::internal::string>*
143669a40b7d4ab4171cbe4ef920e7a5171109e2064cvladlosev                             new_argvs);
1437d201456903f3ecae1f7794edfab0d5678e64226shiqian
1438d201456903f3ecae1f7794edfab0d5678e64226shiqian
1439d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_HAS_DEATH_TEST
1440d201456903f3ecae1f7794edfab0d5678e64226shiqian
1441d201456903f3ecae1f7794edfab0d5678e64226shiqian// Defines synchronization primitives.
1442a6340420b9cee27f77c5b91bea807121914a5831kosak#if GTEST_IS_THREADSAFE
1443a6340420b9cee27f77c5b91bea807121914a5831kosak# if GTEST_HAS_PTHREAD
1444a6340420b9cee27f77c5b91bea807121914a5831kosak// Sleeps for (roughly) n milliseconds.  This function is only for testing
1445a6340420b9cee27f77c5b91bea807121914a5831kosak// Google Test's own constructs.  Don't use it in user tests, either
1446a6340420b9cee27f77c5b91bea807121914a5831kosak// directly or indirectly.
144712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.waninline void SleepMilliseconds(int n) {
144812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  const timespec time = {
144912a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    0,                  // 0 seconds.
145012a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    n * 1000L * 1000L,  // And n ms.
145112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  };
145212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  nanosleep(&time, NULL);
145312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan}
1454a6340420b9cee27f77c5b91bea807121914a5831kosak# endif  // GTEST_HAS_PTHREAD
145512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
1456156d1b513b90deca6287c737e3e6453dc7f64d35kosak# if GTEST_HAS_NOTIFICATION_
1457156d1b513b90deca6287c737e3e6453dc7f64d35kosak// Notification has already been imported into the namespace.
1458156d1b513b90deca6287c737e3e6453dc7f64d35kosak// Nothing to do here.
1459156d1b513b90deca6287c737e3e6453dc7f64d35kosak
1460a6340420b9cee27f77c5b91bea807121914a5831kosak# elif GTEST_HAS_PTHREAD
146112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// Allows a controller thread to pause execution of newly created
146212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// threads until notified.  Instances of this class must be created
146312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// and destroyed in the controller thread.
146412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//
146512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// This class is only for testing Google Test's own constructs. Do not
146612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// use it in user tests, either directly or indirectly.
146712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wanclass Notification {
146812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan public:
1469cfb40870bc74dc57616e286461a89c9f259b349djgm  Notification() : notified_(false) {
1470cfb40870bc74dc57616e286461a89c9f259b349djgm    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
1471cfb40870bc74dc57616e286461a89c9f259b349djgm  }
1472cfb40870bc74dc57616e286461a89c9f259b349djgm  ~Notification() {
1473cfb40870bc74dc57616e286461a89c9f259b349djgm    pthread_mutex_destroy(&mutex_);
1474cfb40870bc74dc57616e286461a89c9f259b349djgm  }
147512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
147612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  // Notifies all threads created with this notification to start. Must
147712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  // be called from the controller thread.
1478cfb40870bc74dc57616e286461a89c9f259b349djgm  void Notify() {
1479cfb40870bc74dc57616e286461a89c9f259b349djgm    pthread_mutex_lock(&mutex_);
1480cfb40870bc74dc57616e286461a89c9f259b349djgm    notified_ = true;
1481cfb40870bc74dc57616e286461a89c9f259b349djgm    pthread_mutex_unlock(&mutex_);
1482cfb40870bc74dc57616e286461a89c9f259b349djgm  }
148312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
148412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  // Blocks until the controller thread notifies. Must be called from a test
148512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  // thread.
148612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  void WaitForNotification() {
1487cfb40870bc74dc57616e286461a89c9f259b349djgm    for (;;) {
1488cfb40870bc74dc57616e286461a89c9f259b349djgm      pthread_mutex_lock(&mutex_);
1489cfb40870bc74dc57616e286461a89c9f259b349djgm      const bool notified = notified_;
1490cfb40870bc74dc57616e286461a89c9f259b349djgm      pthread_mutex_unlock(&mutex_);
1491cfb40870bc74dc57616e286461a89c9f259b349djgm      if (notified)
1492cfb40870bc74dc57616e286461a89c9f259b349djgm        break;
149312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan      SleepMilliseconds(10);
149412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    }
149512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  }
149612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
149712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan private:
1498cfb40870bc74dc57616e286461a89c9f259b349djgm  pthread_mutex_t mutex_;
1499cfb40870bc74dc57616e286461a89c9f259b349djgm  bool notified_;
150012a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
150112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
150212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan};
150312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
1504bd263344f9e930ab7d3558c1b7706a55739737cbkosak# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
1505a6340420b9cee27f77c5b91bea807121914a5831kosak
1506a6340420b9cee27f77c5b91bea807121914a5831kosakGTEST_API_ void SleepMilliseconds(int n);
1507a6340420b9cee27f77c5b91bea807121914a5831kosak
1508a6340420b9cee27f77c5b91bea807121914a5831kosak// Provides leak-safe Windows kernel handle ownership.
1509a6340420b9cee27f77c5b91bea807121914a5831kosak// Used in death tests and in threading support.
1510a6340420b9cee27f77c5b91bea807121914a5831kosakclass GTEST_API_ AutoHandle {
1511a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1512a6340420b9cee27f77c5b91bea807121914a5831kosak  // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
1513a6340420b9cee27f77c5b91bea807121914a5831kosak  // avoid including <windows.h> in this header file. Including <windows.h> is
1514a6340420b9cee27f77c5b91bea807121914a5831kosak  // undesirable because it defines a lot of symbols and macros that tend to
1515a6340420b9cee27f77c5b91bea807121914a5831kosak  // conflict with client code. This assumption is verified by
1516a6340420b9cee27f77c5b91bea807121914a5831kosak  // WindowsTypesTest.HANDLEIsVoidStar.
1517a6340420b9cee27f77c5b91bea807121914a5831kosak  typedef void* Handle;
1518a6340420b9cee27f77c5b91bea807121914a5831kosak  AutoHandle();
1519a6340420b9cee27f77c5b91bea807121914a5831kosak  explicit AutoHandle(Handle handle);
1520a6340420b9cee27f77c5b91bea807121914a5831kosak
1521a6340420b9cee27f77c5b91bea807121914a5831kosak  ~AutoHandle();
1522a6340420b9cee27f77c5b91bea807121914a5831kosak
1523a6340420b9cee27f77c5b91bea807121914a5831kosak  Handle Get() const;
1524a6340420b9cee27f77c5b91bea807121914a5831kosak  void Reset();
1525a6340420b9cee27f77c5b91bea807121914a5831kosak  void Reset(Handle handle);
1526a6340420b9cee27f77c5b91bea807121914a5831kosak
1527a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1528a6340420b9cee27f77c5b91bea807121914a5831kosak  // Returns true iff the handle is a valid handle object that can be closed.
1529a6340420b9cee27f77c5b91bea807121914a5831kosak  bool IsCloseable() const;
1530a6340420b9cee27f77c5b91bea807121914a5831kosak
1531a6340420b9cee27f77c5b91bea807121914a5831kosak  Handle handle_;
1532a6340420b9cee27f77c5b91bea807121914a5831kosak
1533a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
1534a6340420b9cee27f77c5b91bea807121914a5831kosak};
1535a6340420b9cee27f77c5b91bea807121914a5831kosak
1536a6340420b9cee27f77c5b91bea807121914a5831kosak// Allows a controller thread to pause execution of newly created
1537a6340420b9cee27f77c5b91bea807121914a5831kosak// threads until notified.  Instances of this class must be created
1538a6340420b9cee27f77c5b91bea807121914a5831kosak// and destroyed in the controller thread.
1539a6340420b9cee27f77c5b91bea807121914a5831kosak//
1540a6340420b9cee27f77c5b91bea807121914a5831kosak// This class is only for testing Google Test's own constructs. Do not
1541a6340420b9cee27f77c5b91bea807121914a5831kosak// use it in user tests, either directly or indirectly.
1542a6340420b9cee27f77c5b91bea807121914a5831kosakclass GTEST_API_ Notification {
1543a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1544a6340420b9cee27f77c5b91bea807121914a5831kosak  Notification();
1545a6340420b9cee27f77c5b91bea807121914a5831kosak  void Notify();
1546a6340420b9cee27f77c5b91bea807121914a5831kosak  void WaitForNotification();
1547a6340420b9cee27f77c5b91bea807121914a5831kosak
1548a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1549a6340420b9cee27f77c5b91bea807121914a5831kosak  AutoHandle event_;
1550a6340420b9cee27f77c5b91bea807121914a5831kosak
1551a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
1552a6340420b9cee27f77c5b91bea807121914a5831kosak};
1553156d1b513b90deca6287c737e3e6453dc7f64d35kosak# endif  // GTEST_HAS_NOTIFICATION_
1554a6340420b9cee27f77c5b91bea807121914a5831kosak
1555a6340420b9cee27f77c5b91bea807121914a5831kosak// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
1556a6340420b9cee27f77c5b91bea807121914a5831kosak// defined, but we don't want to use MinGW's pthreads implementation, which
1557a6340420b9cee27f77c5b91bea807121914a5831kosak// has conformance problems with some versions of the POSIX standard.
1558a6340420b9cee27f77c5b91bea807121914a5831kosak# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
1559a6340420b9cee27f77c5b91bea807121914a5831kosak
156006d04c0945bf47bae90532552e6e8294802fc9aavladlosev// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
156106d04c0945bf47bae90532552e6e8294802fc9aavladlosev// Consequently, it cannot select a correct instantiation of ThreadWithParam
156206d04c0945bf47bae90532552e6e8294802fc9aavladlosev// in order to call its Run(). Introducing ThreadWithParamBase as a
156306d04c0945bf47bae90532552e6e8294802fc9aavladlosev// non-templated base class for ThreadWithParam allows us to bypass this
156406d04c0945bf47bae90532552e6e8294802fc9aavladlosev// problem.
156506d04c0945bf47bae90532552e6e8294802fc9aavladlosevclass ThreadWithParamBase {
156606d04c0945bf47bae90532552e6e8294802fc9aavladlosev public:
156706d04c0945bf47bae90532552e6e8294802fc9aavladlosev  virtual ~ThreadWithParamBase() {}
156806d04c0945bf47bae90532552e6e8294802fc9aavladlosev  virtual void Run() = 0;
156906d04c0945bf47bae90532552e6e8294802fc9aavladlosev};
157006d04c0945bf47bae90532552e6e8294802fc9aavladlosev
157106d04c0945bf47bae90532552e6e8294802fc9aavladlosev// pthread_create() accepts a pointer to a function type with the C linkage.
157206d04c0945bf47bae90532552e6e8294802fc9aavladlosev// According to the Standard (7.5/1), function types with different linkages
157306d04c0945bf47bae90532552e6e8294802fc9aavladlosev// are different even if they are otherwise identical.  Some compilers (for
157406d04c0945bf47bae90532552e6e8294802fc9aavladlosev// example, SunStudio) treat them as different types.  Since class methods
157506d04c0945bf47bae90532552e6e8294802fc9aavladlosev// cannot be defined with C-linkage we need to define a free C-function to
157606d04c0945bf47bae90532552e6e8294802fc9aavladlosev// pass into pthread_create().
157706d04c0945bf47bae90532552e6e8294802fc9aavladlosevextern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
157806d04c0945bf47bae90532552e6e8294802fc9aavladlosev  static_cast<ThreadWithParamBase*>(thread)->Run();
157906d04c0945bf47bae90532552e6e8294802fc9aavladlosev  return NULL;
158006d04c0945bf47bae90532552e6e8294802fc9aavladlosev}
158106d04c0945bf47bae90532552e6e8294802fc9aavladlosev
158212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// Helper class for testing Google Test's multi-threading constructs.
1583542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan// To use it, write:
158412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//
158512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//   void ThreadFunc(int param) { /* Do things with param */ }
158612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//   Notification thread_can_start;
158712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//   ...
158812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//   // The thread_can_start parameter is optional; you can supply NULL.
158912a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//   ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
159012a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//   thread_can_start.Notify();
159112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan//
159212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// These classes are only for testing Google Test's own constructs. Do
159312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan// not use them in user tests, either directly or indirectly.
159412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wantemplate <typename T>
159506d04c0945bf47bae90532552e6e8294802fc9aavladlosevclass ThreadWithParam : public ThreadWithParamBase {
159612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan public:
1597a6340420b9cee27f77c5b91bea807121914a5831kosak  typedef void UserThreadFunc(T);
159812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
1599a6340420b9cee27f77c5b91bea807121914a5831kosak  ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
160012a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan      : func_(func),
160112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan        param_(param),
160212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan        thread_can_start_(thread_can_start),
1603542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan        finished_(false) {
1604e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    ThreadWithParamBase* const base = this;
1605542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan    // The thread can be created only after all fields except thread_
1606542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan    // have been initialized.
1607542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(
1608e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan        pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
1609542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan  }
1610542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan  ~ThreadWithParam() { Join(); }
161112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
161212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  void Join() {
161312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    if (!finished_) {
1614542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan      GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
161512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan      finished_ = true;
161612a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    }
161712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  }
161812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
161906d04c0945bf47bae90532552e6e8294802fc9aavladlosev  virtual void Run() {
162012a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    if (thread_can_start_ != NULL)
162112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan      thread_can_start_->WaitForNotification();
162212a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan    func_(param_);
162312a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  }
162412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
162506d04c0945bf47bae90532552e6e8294802fc9aavladlosev private:
1626a6340420b9cee27f77c5b91bea807121914a5831kosak  UserThreadFunc* const func_;  // User-supplied thread function.
162712a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  const T param_;  // User-supplied parameter to the thread function.
162812a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  // When non-NULL, used to block execution until the controller thread
162912a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  // notifies.
163012a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  Notification* const thread_can_start_;
163112a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan  bool finished_;  // true iff we know that the thread function has finished.
1632542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan  pthread_t thread_;  // The native thread object.
1633542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan
1634542b41e5d010cf0a18a37252d5f4b05cfa5408afzhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
163512a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan};
1636156d1b513b90deca6287c737e3e6453dc7f64d35kosak# endif  // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD ||
1637156d1b513b90deca6287c737e3e6453dc7f64d35kosak         // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
1638156d1b513b90deca6287c737e3e6453dc7f64d35kosak
1639156d1b513b90deca6287c737e3e6453dc7f64d35kosak# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
1640156d1b513b90deca6287c737e3e6453dc7f64d35kosak// Mutex and ThreadLocal have already been imported into the namespace.
1641156d1b513b90deca6287c737e3e6453dc7f64d35kosak// Nothing to do here.
1642a6340420b9cee27f77c5b91bea807121914a5831kosak
1643bd263344f9e930ab7d3558c1b7706a55739737cbkosak# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
164412a92c26fc0e0de81f687dbe739a6aa24f37f9ddzhanyong.wan
1645a6340420b9cee27f77c5b91bea807121914a5831kosak// Mutex implements mutex on Windows platforms.  It is used in conjunction
1646a6340420b9cee27f77c5b91bea807121914a5831kosak// with class MutexLock:
16473bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
16484879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan//   Mutex mutex;
16494879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan//   ...
1650a6340420b9cee27f77c5b91bea807121914a5831kosak//   MutexLock lock(&mutex);  // Acquires the mutex and releases it at the
1651a6340420b9cee27f77c5b91bea807121914a5831kosak//                            // end of the current scope.
16523bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
1653a6340420b9cee27f77c5b91bea807121914a5831kosak// A static Mutex *must* be defined or declared using one of the following
1654a6340420b9cee27f77c5b91bea807121914a5831kosak// macros:
16554879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan//   GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
1656a6340420b9cee27f77c5b91bea807121914a5831kosak//   GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
1657a6340420b9cee27f77c5b91bea807121914a5831kosak//
1658a6340420b9cee27f77c5b91bea807121914a5831kosak// (A non-static Mutex is defined/declared in the usual way).
1659a6340420b9cee27f77c5b91bea807121914a5831kosakclass GTEST_API_ Mutex {
1660a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1661a6340420b9cee27f77c5b91bea807121914a5831kosak  enum MutexType { kStatic = 0, kDynamic = 1 };
1662a6340420b9cee27f77c5b91bea807121914a5831kosak  // We rely on kStaticMutex being 0 as it is to what the linker initializes
1663a6340420b9cee27f77c5b91bea807121914a5831kosak  // type_ in static mutexes.  critical_section_ will be initialized lazily
1664a6340420b9cee27f77c5b91bea807121914a5831kosak  // in ThreadSafeLazyInit().
1665a6340420b9cee27f77c5b91bea807121914a5831kosak  enum StaticConstructorSelector { kStaticMutex = 0 };
1666a6340420b9cee27f77c5b91bea807121914a5831kosak
1667a6340420b9cee27f77c5b91bea807121914a5831kosak  // This constructor intentionally does nothing.  It relies on type_ being
1668a6340420b9cee27f77c5b91bea807121914a5831kosak  // statically initialized to 0 (effectively setting it to kStatic) and on
1669a6340420b9cee27f77c5b91bea807121914a5831kosak  // ThreadSafeLazyInit() to lazily initialize the rest of the members.
1670a6340420b9cee27f77c5b91bea807121914a5831kosak  explicit Mutex(StaticConstructorSelector /*dummy*/) {}
1671a6340420b9cee27f77c5b91bea807121914a5831kosak
1672a6340420b9cee27f77c5b91bea807121914a5831kosak  Mutex();
1673a6340420b9cee27f77c5b91bea807121914a5831kosak  ~Mutex();
1674a6340420b9cee27f77c5b91bea807121914a5831kosak
1675a6340420b9cee27f77c5b91bea807121914a5831kosak  void Lock();
1676a6340420b9cee27f77c5b91bea807121914a5831kosak
1677a6340420b9cee27f77c5b91bea807121914a5831kosak  void Unlock();
1678a6340420b9cee27f77c5b91bea807121914a5831kosak
1679a6340420b9cee27f77c5b91bea807121914a5831kosak  // Does nothing if the current thread holds the mutex. Otherwise, crashes
1680a6340420b9cee27f77c5b91bea807121914a5831kosak  // with high probability.
1681a6340420b9cee27f77c5b91bea807121914a5831kosak  void AssertHeld();
1682a6340420b9cee27f77c5b91bea807121914a5831kosak
1683a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1684a6340420b9cee27f77c5b91bea807121914a5831kosak  // Initializes owner_thread_id_ and critical_section_ in static mutexes.
1685a6340420b9cee27f77c5b91bea807121914a5831kosak  void ThreadSafeLazyInit();
1686a6340420b9cee27f77c5b91bea807121914a5831kosak
1687a6340420b9cee27f77c5b91bea807121914a5831kosak  // Per http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx,
1688a6340420b9cee27f77c5b91bea807121914a5831kosak  // we assume that 0 is an invalid value for thread IDs.
1689a6340420b9cee27f77c5b91bea807121914a5831kosak  unsigned int owner_thread_id_;
1690a6340420b9cee27f77c5b91bea807121914a5831kosak
1691a6340420b9cee27f77c5b91bea807121914a5831kosak  // For static mutexes, we rely on these members being initialized to zeros
1692a6340420b9cee27f77c5b91bea807121914a5831kosak  // by the linker.
1693a6340420b9cee27f77c5b91bea807121914a5831kosak  MutexType type_;
1694a6340420b9cee27f77c5b91bea807121914a5831kosak  long critical_section_init_phase_;  // NOLINT
1695a6340420b9cee27f77c5b91bea807121914a5831kosak  _RTL_CRITICAL_SECTION* critical_section_;
1696a6340420b9cee27f77c5b91bea807121914a5831kosak
1697a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
1698a6340420b9cee27f77c5b91bea807121914a5831kosak};
1699a6340420b9cee27f77c5b91bea807121914a5831kosak
1700a6340420b9cee27f77c5b91bea807121914a5831kosak# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1701a6340420b9cee27f77c5b91bea807121914a5831kosak    extern ::testing::internal::Mutex mutex
1702a6340420b9cee27f77c5b91bea807121914a5831kosak
1703a6340420b9cee27f77c5b91bea807121914a5831kosak# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1704a6340420b9cee27f77c5b91bea807121914a5831kosak    ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
1705a6340420b9cee27f77c5b91bea807121914a5831kosak
1706a6340420b9cee27f77c5b91bea807121914a5831kosak// We cannot name this class MutexLock because the ctor declaration would
1707a6340420b9cee27f77c5b91bea807121914a5831kosak// conflict with a macro named MutexLock, which is defined on some
1708a6340420b9cee27f77c5b91bea807121914a5831kosak// platforms. That macro is used as a defensive measure to prevent against
1709a6340420b9cee27f77c5b91bea807121914a5831kosak// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
1710a6340420b9cee27f77c5b91bea807121914a5831kosak// "MutexLock l(&mu)".  Hence the typedef trick below.
1711a6340420b9cee27f77c5b91bea807121914a5831kosakclass GTestMutexLock {
1712a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1713a6340420b9cee27f77c5b91bea807121914a5831kosak  explicit GTestMutexLock(Mutex* mutex)
1714a6340420b9cee27f77c5b91bea807121914a5831kosak      : mutex_(mutex) { mutex_->Lock(); }
1715a6340420b9cee27f77c5b91bea807121914a5831kosak
1716a6340420b9cee27f77c5b91bea807121914a5831kosak  ~GTestMutexLock() { mutex_->Unlock(); }
1717a6340420b9cee27f77c5b91bea807121914a5831kosak
1718a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1719a6340420b9cee27f77c5b91bea807121914a5831kosak  Mutex* const mutex_;
1720a6340420b9cee27f77c5b91bea807121914a5831kosak
1721a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
1722a6340420b9cee27f77c5b91bea807121914a5831kosak};
1723a6340420b9cee27f77c5b91bea807121914a5831kosak
1724a6340420b9cee27f77c5b91bea807121914a5831kosaktypedef GTestMutexLock MutexLock;
1725a6340420b9cee27f77c5b91bea807121914a5831kosak
1726a6340420b9cee27f77c5b91bea807121914a5831kosak// Base class for ValueHolder<T>.  Allows a caller to hold and delete a value
1727a6340420b9cee27f77c5b91bea807121914a5831kosak// without knowing its type.
1728a6340420b9cee27f77c5b91bea807121914a5831kosakclass ThreadLocalValueHolderBase {
1729a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1730a6340420b9cee27f77c5b91bea807121914a5831kosak  virtual ~ThreadLocalValueHolderBase() {}
1731a6340420b9cee27f77c5b91bea807121914a5831kosak};
1732a6340420b9cee27f77c5b91bea807121914a5831kosak
1733a6340420b9cee27f77c5b91bea807121914a5831kosak// Provides a way for a thread to send notifications to a ThreadLocal
1734a6340420b9cee27f77c5b91bea807121914a5831kosak// regardless of its parameter type.
1735a6340420b9cee27f77c5b91bea807121914a5831kosakclass ThreadLocalBase {
1736a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1737a6340420b9cee27f77c5b91bea807121914a5831kosak  // Creates a new ValueHolder<T> object holding a default value passed to
1738a6340420b9cee27f77c5b91bea807121914a5831kosak  // this ThreadLocal<T>'s constructor and returns it.  It is the caller's
1739a6340420b9cee27f77c5b91bea807121914a5831kosak  // responsibility not to call this when the ThreadLocal<T> instance already
1740a6340420b9cee27f77c5b91bea807121914a5831kosak  // has a value on the current thread.
1741a6340420b9cee27f77c5b91bea807121914a5831kosak  virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
1742a6340420b9cee27f77c5b91bea807121914a5831kosak
1743a6340420b9cee27f77c5b91bea807121914a5831kosak protected:
1744a6340420b9cee27f77c5b91bea807121914a5831kosak  ThreadLocalBase() {}
1745a6340420b9cee27f77c5b91bea807121914a5831kosak  virtual ~ThreadLocalBase() {}
1746a6340420b9cee27f77c5b91bea807121914a5831kosak
1747a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1748a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase);
1749a6340420b9cee27f77c5b91bea807121914a5831kosak};
1750a6340420b9cee27f77c5b91bea807121914a5831kosak
1751a6340420b9cee27f77c5b91bea807121914a5831kosak// Maps a thread to a set of ThreadLocals that have values instantiated on that
1752a6340420b9cee27f77c5b91bea807121914a5831kosak// thread and notifies them when the thread exits.  A ThreadLocal instance is
1753a6340420b9cee27f77c5b91bea807121914a5831kosak// expected to persist until all threads it has values on have terminated.
1754a6340420b9cee27f77c5b91bea807121914a5831kosakclass GTEST_API_ ThreadLocalRegistry {
1755a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1756a6340420b9cee27f77c5b91bea807121914a5831kosak  // Registers thread_local_instance as having value on the current thread.
1757a6340420b9cee27f77c5b91bea807121914a5831kosak  // Returns a value that can be used to identify the thread from other threads.
1758a6340420b9cee27f77c5b91bea807121914a5831kosak  static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
1759a6340420b9cee27f77c5b91bea807121914a5831kosak      const ThreadLocalBase* thread_local_instance);
1760a6340420b9cee27f77c5b91bea807121914a5831kosak
1761a6340420b9cee27f77c5b91bea807121914a5831kosak  // Invoked when a ThreadLocal instance is destroyed.
1762a6340420b9cee27f77c5b91bea807121914a5831kosak  static void OnThreadLocalDestroyed(
1763a6340420b9cee27f77c5b91bea807121914a5831kosak      const ThreadLocalBase* thread_local_instance);
1764a6340420b9cee27f77c5b91bea807121914a5831kosak};
1765a6340420b9cee27f77c5b91bea807121914a5831kosak
1766a6340420b9cee27f77c5b91bea807121914a5831kosakclass GTEST_API_ ThreadWithParamBase {
1767a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1768a6340420b9cee27f77c5b91bea807121914a5831kosak  void Join();
1769a6340420b9cee27f77c5b91bea807121914a5831kosak
1770a6340420b9cee27f77c5b91bea807121914a5831kosak protected:
1771a6340420b9cee27f77c5b91bea807121914a5831kosak  class Runnable {
1772a6340420b9cee27f77c5b91bea807121914a5831kosak   public:
1773a6340420b9cee27f77c5b91bea807121914a5831kosak    virtual ~Runnable() {}
1774a6340420b9cee27f77c5b91bea807121914a5831kosak    virtual void Run() = 0;
1775a6340420b9cee27f77c5b91bea807121914a5831kosak  };
1776a6340420b9cee27f77c5b91bea807121914a5831kosak
1777a6340420b9cee27f77c5b91bea807121914a5831kosak  ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
1778a6340420b9cee27f77c5b91bea807121914a5831kosak  virtual ~ThreadWithParamBase();
1779a6340420b9cee27f77c5b91bea807121914a5831kosak
1780a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1781a6340420b9cee27f77c5b91bea807121914a5831kosak  AutoHandle thread_;
1782a6340420b9cee27f77c5b91bea807121914a5831kosak};
1783a6340420b9cee27f77c5b91bea807121914a5831kosak
1784a6340420b9cee27f77c5b91bea807121914a5831kosak// Helper class for testing Google Test's multi-threading constructs.
1785a6340420b9cee27f77c5b91bea807121914a5831kosaktemplate <typename T>
1786a6340420b9cee27f77c5b91bea807121914a5831kosakclass ThreadWithParam : public ThreadWithParamBase {
1787a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1788a6340420b9cee27f77c5b91bea807121914a5831kosak  typedef void UserThreadFunc(T);
1789a6340420b9cee27f77c5b91bea807121914a5831kosak
1790a6340420b9cee27f77c5b91bea807121914a5831kosak  ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
1791a6340420b9cee27f77c5b91bea807121914a5831kosak      : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {
1792a6340420b9cee27f77c5b91bea807121914a5831kosak  }
1793a6340420b9cee27f77c5b91bea807121914a5831kosak  virtual ~ThreadWithParam() {}
1794a6340420b9cee27f77c5b91bea807121914a5831kosak
1795a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1796a6340420b9cee27f77c5b91bea807121914a5831kosak  class RunnableImpl : public Runnable {
1797a6340420b9cee27f77c5b91bea807121914a5831kosak   public:
1798a6340420b9cee27f77c5b91bea807121914a5831kosak    RunnableImpl(UserThreadFunc* func, T param)
1799a6340420b9cee27f77c5b91bea807121914a5831kosak        : func_(func),
1800a6340420b9cee27f77c5b91bea807121914a5831kosak          param_(param) {
1801a6340420b9cee27f77c5b91bea807121914a5831kosak    }
1802a6340420b9cee27f77c5b91bea807121914a5831kosak    virtual ~RunnableImpl() {}
1803a6340420b9cee27f77c5b91bea807121914a5831kosak    virtual void Run() {
1804a6340420b9cee27f77c5b91bea807121914a5831kosak      func_(param_);
1805a6340420b9cee27f77c5b91bea807121914a5831kosak    }
1806a6340420b9cee27f77c5b91bea807121914a5831kosak
1807a6340420b9cee27f77c5b91bea807121914a5831kosak   private:
1808a6340420b9cee27f77c5b91bea807121914a5831kosak    UserThreadFunc* const func_;
1809a6340420b9cee27f77c5b91bea807121914a5831kosak    const T param_;
1810a6340420b9cee27f77c5b91bea807121914a5831kosak
1811a6340420b9cee27f77c5b91bea807121914a5831kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl);
1812a6340420b9cee27f77c5b91bea807121914a5831kosak  };
1813a6340420b9cee27f77c5b91bea807121914a5831kosak
1814a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
1815a6340420b9cee27f77c5b91bea807121914a5831kosak};
1816a6340420b9cee27f77c5b91bea807121914a5831kosak
1817a6340420b9cee27f77c5b91bea807121914a5831kosak// Implements thread-local storage on Windows systems.
1818a6340420b9cee27f77c5b91bea807121914a5831kosak//
1819a6340420b9cee27f77c5b91bea807121914a5831kosak//   // Thread 1
1820a6340420b9cee27f77c5b91bea807121914a5831kosak//   ThreadLocal<int> tl(100);  // 100 is the default value for each thread.
18213bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
1822a6340420b9cee27f77c5b91bea807121914a5831kosak//   // Thread 2
1823a6340420b9cee27f77c5b91bea807121914a5831kosak//   tl.set(150);  // Changes the value for thread 2 only.
1824a6340420b9cee27f77c5b91bea807121914a5831kosak//   EXPECT_EQ(150, tl.get());
18253bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
1826a6340420b9cee27f77c5b91bea807121914a5831kosak//   // Thread 1
1827a6340420b9cee27f77c5b91bea807121914a5831kosak//   EXPECT_EQ(100, tl.get());  // In thread 1, tl has the original value.
1828a6340420b9cee27f77c5b91bea807121914a5831kosak//   tl.set(200);
1829a6340420b9cee27f77c5b91bea807121914a5831kosak//   EXPECT_EQ(200, tl.get());
1830a6340420b9cee27f77c5b91bea807121914a5831kosak//
1831a6340420b9cee27f77c5b91bea807121914a5831kosak// The template type argument T must have a public copy constructor.
1832a6340420b9cee27f77c5b91bea807121914a5831kosak// In addition, the default ThreadLocal constructor requires T to have
1833a6340420b9cee27f77c5b91bea807121914a5831kosak// a public default constructor.
1834a6340420b9cee27f77c5b91bea807121914a5831kosak//
1835a6340420b9cee27f77c5b91bea807121914a5831kosak// The users of a TheadLocal instance have to make sure that all but one
1836a6340420b9cee27f77c5b91bea807121914a5831kosak// threads (including the main one) using that instance have exited before
1837a6340420b9cee27f77c5b91bea807121914a5831kosak// destroying it. Otherwise, the per-thread objects managed for them by the
1838a6340420b9cee27f77c5b91bea807121914a5831kosak// ThreadLocal instance are not guaranteed to be destroyed on all platforms.
18393bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan//
1840a6340420b9cee27f77c5b91bea807121914a5831kosak// Google Test only uses global ThreadLocal objects.  That means they
1841a6340420b9cee27f77c5b91bea807121914a5831kosak// will die after main() has returned.  Therefore, no per-thread
1842a6340420b9cee27f77c5b91bea807121914a5831kosak// object managed by Google Test will be leaked as long as all threads
1843a6340420b9cee27f77c5b91bea807121914a5831kosak// using Google Test have exited when main() returns.
1844a6340420b9cee27f77c5b91bea807121914a5831kosaktemplate <typename T>
1845a6340420b9cee27f77c5b91bea807121914a5831kosakclass ThreadLocal : public ThreadLocalBase {
1846a6340420b9cee27f77c5b91bea807121914a5831kosak public:
1847831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
1848831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  explicit ThreadLocal(const T& value)
1849831b87f2342df0ee2d13c466b400245bdf1c04f3kosak      : default_factory_(new InstanceValueHolderFactory(value)) {}
1850a6340420b9cee27f77c5b91bea807121914a5831kosak
1851a6340420b9cee27f77c5b91bea807121914a5831kosak  ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); }
1852a6340420b9cee27f77c5b91bea807121914a5831kosak
1853a6340420b9cee27f77c5b91bea807121914a5831kosak  T* pointer() { return GetOrCreateValue(); }
1854a6340420b9cee27f77c5b91bea807121914a5831kosak  const T* pointer() const { return GetOrCreateValue(); }
1855a6340420b9cee27f77c5b91bea807121914a5831kosak  const T& get() const { return *pointer(); }
1856a6340420b9cee27f77c5b91bea807121914a5831kosak  void set(const T& value) { *pointer() = value; }
1857a6340420b9cee27f77c5b91bea807121914a5831kosak
1858a6340420b9cee27f77c5b91bea807121914a5831kosak private:
1859a6340420b9cee27f77c5b91bea807121914a5831kosak  // Holds a value of T.  Can be deleted via its base class without the caller
1860a6340420b9cee27f77c5b91bea807121914a5831kosak  // knowing the type of T.
1861a6340420b9cee27f77c5b91bea807121914a5831kosak  class ValueHolder : public ThreadLocalValueHolderBase {
1862a6340420b9cee27f77c5b91bea807121914a5831kosak   public:
1863831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    ValueHolder() : value_() {}
1864a6340420b9cee27f77c5b91bea807121914a5831kosak    explicit ValueHolder(const T& value) : value_(value) {}
1865a6340420b9cee27f77c5b91bea807121914a5831kosak
1866a6340420b9cee27f77c5b91bea807121914a5831kosak    T* pointer() { return &value_; }
1867a6340420b9cee27f77c5b91bea807121914a5831kosak
1868a6340420b9cee27f77c5b91bea807121914a5831kosak   private:
1869a6340420b9cee27f77c5b91bea807121914a5831kosak    T value_;
1870a6340420b9cee27f77c5b91bea807121914a5831kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
1871a6340420b9cee27f77c5b91bea807121914a5831kosak  };
1872a6340420b9cee27f77c5b91bea807121914a5831kosak
1873a6340420b9cee27f77c5b91bea807121914a5831kosak
1874a6340420b9cee27f77c5b91bea807121914a5831kosak  T* GetOrCreateValue() const {
1875a6340420b9cee27f77c5b91bea807121914a5831kosak    return static_cast<ValueHolder*>(
1876a6340420b9cee27f77c5b91bea807121914a5831kosak        ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer();
1877a6340420b9cee27f77c5b91bea807121914a5831kosak  }
1878a6340420b9cee27f77c5b91bea807121914a5831kosak
1879a6340420b9cee27f77c5b91bea807121914a5831kosak  virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const {
1880831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    return default_factory_->MakeNewHolder();
1881a6340420b9cee27f77c5b91bea807121914a5831kosak  }
1882a6340420b9cee27f77c5b91bea807121914a5831kosak
1883831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  class ValueHolderFactory {
1884831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   public:
1885831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    ValueHolderFactory() {}
1886831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ~ValueHolderFactory() {}
1887831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ValueHolder* MakeNewHolder() const = 0;
1888831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1889831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   private:
1890831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory);
1891831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  };
1892831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1893831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  class DefaultValueHolderFactory : public ValueHolderFactory {
1894831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   public:
1895831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    DefaultValueHolderFactory() {}
1896831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); }
1897831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1898831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   private:
1899831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
1900831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  };
1901831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1902831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  class InstanceValueHolderFactory : public ValueHolderFactory {
1903831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   public:
1904831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
1905831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ValueHolder* MakeNewHolder() const {
1906831b87f2342df0ee2d13c466b400245bdf1c04f3kosak      return new ValueHolder(value_);
1907831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    }
1908831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1909831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   private:
1910831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    const T value_;  // The value for each thread.
1911831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1912831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
1913831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  };
1914831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
1915831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  scoped_ptr<ValueHolderFactory> default_factory_;
1916a6340420b9cee27f77c5b91bea807121914a5831kosak
1917a6340420b9cee27f77c5b91bea807121914a5831kosak  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
1918a6340420b9cee27f77c5b91bea807121914a5831kosak};
1919a6340420b9cee27f77c5b91bea807121914a5831kosak
1920a6340420b9cee27f77c5b91bea807121914a5831kosak# elif GTEST_HAS_PTHREAD
1921a6340420b9cee27f77c5b91bea807121914a5831kosak
1922a6340420b9cee27f77c5b91bea807121914a5831kosak// MutexBase and Mutex implement mutex on pthreads-based platforms.
19233bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wanclass MutexBase {
19243bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan public:
19254879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // Acquires this mutex.
19264879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  void Lock() {
19274879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
19284879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    owner_ = pthread_self();
19299a56024c9a5795062492cc15813800378e62e0abjgm    has_owner_ = true;
19304879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  }
19314879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan
19324879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // Releases this mutex.
19334879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  void Unlock() {
19349a56024c9a5795062492cc15813800378e62e0abjgm    // Since the lock is being released the owner_ field should no longer be
19359a56024c9a5795062492cc15813800378e62e0abjgm    // considered valid. We don't protect writing to has_owner_ here, as it's
19369a56024c9a5795062492cc15813800378e62e0abjgm    // the caller's responsibility to ensure that the current thread holds the
19374879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    // mutex when this is called.
19389a56024c9a5795062492cc15813800378e62e0abjgm    has_owner_ = false;
19394879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
19404879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  }
19413bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
19423bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  // Does nothing if the current thread holds the mutex. Otherwise, crashes
19433bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  // with high probability.
19444879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  void AssertHeld() const {
19459a56024c9a5795062492cc15813800378e62e0abjgm    GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
19464879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan        << "The current thread is not holding the mutex @" << this;
19474879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  }
19483bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
19494879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // A static mutex may be used before main() is entered.  It may even
19504879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // be used before the dynamic initialization stage.  Therefore we
19514879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // must be able to initialize a static mutex object at link time.
19524879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // This means MutexBase has to be a POD and its member variables
19534879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  // have to be public.
19543bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan public:
19554879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  pthread_mutex_t mutex_;  // The underlying pthread mutex.
19569a56024c9a5795062492cc15813800378e62e0abjgm  // has_owner_ indicates whether the owner_ field below contains a valid thread
19579a56024c9a5795062492cc15813800378e62e0abjgm  // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
19589a56024c9a5795062492cc15813800378e62e0abjgm  // accesses to the owner_ field should be protected by a check of this field.
19599a56024c9a5795062492cc15813800378e62e0abjgm  // An alternative might be to memset() owner_ to all zeros, but there's no
19609a56024c9a5795062492cc15813800378e62e0abjgm  // guarantee that a zero'd pthread_t is necessarily invalid or even different
19619a56024c9a5795062492cc15813800378e62e0abjgm  // from pthread_self().
19629a56024c9a5795062492cc15813800378e62e0abjgm  bool has_owner_;
19639a56024c9a5795062492cc15813800378e62e0abjgm  pthread_t owner_;  // The thread holding the mutex.
19643bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan};
19653bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
19663bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// Forward-declares a static mutex.
1967a6340420b9cee27f77c5b91bea807121914a5831kosak#  define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1968a6340420b9cee27f77c5b91bea807121914a5831kosak     extern ::testing::internal::MutexBase mutex
19693bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
19704879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// Defines and statically (i.e. at link time) initializes a static mutex.
19719a56024c9a5795062492cc15813800378e62e0abjgm// The initialization list here does not explicitly initialize each field,
19729a56024c9a5795062492cc15813800378e62e0abjgm// instead relying on default initialization for the unspecified fields. In
19739a56024c9a5795062492cc15813800378e62e0abjgm// particular, the owner_ field (a pthread_t) is not explicitly initialized.
19749a56024c9a5795062492cc15813800378e62e0abjgm// This allows initialization to work whether pthread_t is a scalar or struct.
19759a56024c9a5795062492cc15813800378e62e0abjgm// The flag -Wmissing-field-initializers must not be specified for this to work.
1976a6340420b9cee27f77c5b91bea807121914a5831kosak#  define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1977a6340420b9cee27f77c5b91bea807121914a5831kosak     ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
19783bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
19794879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// The Mutex class can only be used for mutexes created at runtime. It
19804879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan// shares its API with MutexBase otherwise.
19813bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wanclass Mutex : public MutexBase {
19823bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan public:
19834879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  Mutex() {
19844879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
19859a56024c9a5795062492cc15813800378e62e0abjgm    has_owner_ = false;
19864879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  }
19874879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  ~Mutex() {
19884879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
19894879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan  }
19903bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
19913bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan private:
19923bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
19933bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan};
19943bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
1995a6340420b9cee27f77c5b91bea807121914a5831kosak// We cannot name this class MutexLock because the ctor declaration would
19963bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// conflict with a macro named MutexLock, which is defined on some
1997a6340420b9cee27f77c5b91bea807121914a5831kosak// platforms. That macro is used as a defensive measure to prevent against
1998a6340420b9cee27f77c5b91bea807121914a5831kosak// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
1999a6340420b9cee27f77c5b91bea807121914a5831kosak// "MutexLock l(&mu)".  Hence the typedef trick below.
20003bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wanclass GTestMutexLock {
20013bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan public:
20023bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  explicit GTestMutexLock(MutexBase* mutex)
20033bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan      : mutex_(mutex) { mutex_->Lock(); }
20043bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20053bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  ~GTestMutexLock() { mutex_->Unlock(); }
20063bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20073bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan private:
20083bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  MutexBase* const mutex_;
20093bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20103bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
20113bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan};
20123bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20133bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wantypedef GTestMutexLock MutexLock;
20143bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2015e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// Helpers for ThreadLocal.
2016e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
2017e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// pthread_key_create() requires DeleteThreadLocalValue() to have
2018e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// C-linkage.  Therefore it cannot be templatized to access
2019e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// ThreadLocal<T>.  Hence the need for class
2020e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// ThreadLocalValueHolderBase.
2021e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wanclass ThreadLocalValueHolderBase {
2022e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan public:
2023e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  virtual ~ThreadLocalValueHolderBase() {}
2024e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan};
2025e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
2026e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// Called by pthread to delete thread-local data stored by
2027e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan// pthread_setspecific().
2028e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wanextern "C" inline void DeleteThreadLocalValue(void* value_holder) {
2029e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
2030e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan}
2031e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
20323bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// Implements thread-local storage on pthreads-based systems.
20333bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wantemplate <typename T>
20343bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wanclass ThreadLocal {
20353bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan public:
2036831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  ThreadLocal()
2037831b87f2342df0ee2d13c466b400245bdf1c04f3kosak      : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
2038831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  explicit ThreadLocal(const T& value)
2039831b87f2342df0ee2d13c466b400245bdf1c04f3kosak      : key_(CreateKey()),
2040831b87f2342df0ee2d13c466b400245bdf1c04f3kosak        default_factory_(new InstanceValueHolderFactory(value)) {}
20413bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20423bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  ~ThreadLocal() {
2043b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan    // Destroys the managed object for the current thread, if any.
2044b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan    DeleteThreadLocalValue(pthread_getspecific(key_));
2045b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan
2046b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan    // Releases resources associated with the key.  This will *not*
2047b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan    // delete managed objects for other threads.
20484879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
20493bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  }
20503bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20513bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  T* pointer() { return GetOrCreateValue(); }
20523bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  const T* pointer() const { return GetOrCreateValue(); }
20533bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  const T& get() const { return *pointer(); }
20543bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  void set(const T& value) { *pointer() = value; }
20553bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20563bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan private:
2057e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  // Holds a value of type T.
2058e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  class ValueHolder : public ThreadLocalValueHolderBase {
2059e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan   public:
2060831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    ValueHolder() : value_() {}
2061e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    explicit ValueHolder(const T& value) : value_(value) {}
2062e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
2063e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    T* pointer() { return &value_; }
2064e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
2065e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan   private:
2066e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    T value_;
2067e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
2068e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan  };
2069e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan
20703bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  static pthread_key_t CreateKey() {
20713bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan    pthread_key_t key;
2072b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan    // When a thread exits, DeleteThreadLocalValue() will be called on
2073b9a7cead1cdf588b9b00ec46f38a727b14681c5bzhanyong.wan    // the object managed for that thread.
2074e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(
2075e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan        pthread_key_create(&key, &DeleteThreadLocalValue));
20763bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan    return key;
20773bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  }
20783bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
20793bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  T* GetOrCreateValue() const {
2080e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    ThreadLocalValueHolderBase* const holder =
2081e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan        static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
2082e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    if (holder != NULL) {
2083e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan      return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
2084e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    }
20854879aac74991ad4552c5ed2ec178af511f3feb5ezhanyong.wan
2086831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    ValueHolder* const new_holder = default_factory_->MakeNewHolder();
2087e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    ThreadLocalValueHolderBase* const holder_base = new_holder;
2088e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
2089e9f093ae15ac232f7ac0a31d64a5873fd1e306c6zhanyong.wan    return new_holder->pointer();
20903bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  }
20913bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2092831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  class ValueHolderFactory {
2093831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   public:
2094831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    ValueHolderFactory() {}
2095831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ~ValueHolderFactory() {}
2096831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ValueHolder* MakeNewHolder() const = 0;
2097831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
2098831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   private:
2099831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory);
2100831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  };
2101831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
2102831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  class DefaultValueHolderFactory : public ValueHolderFactory {
2103831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   public:
2104831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    DefaultValueHolderFactory() {}
2105831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); }
2106831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
2107831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   private:
2108831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
2109831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  };
2110831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
2111831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  class InstanceValueHolderFactory : public ValueHolderFactory {
2112831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   public:
2113831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
2114831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    virtual ValueHolder* MakeNewHolder() const {
2115831b87f2342df0ee2d13c466b400245bdf1c04f3kosak      return new ValueHolder(value_);
2116831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    }
2117831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
2118831b87f2342df0ee2d13c466b400245bdf1c04f3kosak   private:
2119831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    const T value_;  // The value for each thread.
2120831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
2121831b87f2342df0ee2d13c466b400245bdf1c04f3kosak    GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
2122831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  };
2123831b87f2342df0ee2d13c466b400245bdf1c04f3kosak
21243bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  // A key pthreads uses for looking up per-thread values.
21253bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  const pthread_key_t key_;
2126831b87f2342df0ee2d13c466b400245bdf1c04f3kosak  scoped_ptr<ValueHolderFactory> default_factory_;
21273bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
21283bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
21293bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan};
21303bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2131156d1b513b90deca6287c737e3e6453dc7f64d35kosak# endif  // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
21323bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2133a6340420b9cee27f77c5b91bea807121914a5831kosak#else  // GTEST_IS_THREADSAFE
21343bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2135d201456903f3ecae1f7794edfab0d5678e64226shiqian// A dummy implementation of synchronization primitives (mutex, lock,
2136d201456903f3ecae1f7794edfab0d5678e64226shiqian// and thread-local variable).  Necessary for compiling Google Test where
2137d201456903f3ecae1f7794edfab0d5678e64226shiqian// mutex is not supported - using Google Test in multiple threads is not
2138d201456903f3ecae1f7794edfab0d5678e64226shiqian// supported on such platforms.
2139d201456903f3ecae1f7794edfab0d5678e64226shiqian
2140d201456903f3ecae1f7794edfab0d5678e64226shiqianclass Mutex {
2141d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
2142d201456903f3ecae1f7794edfab0d5678e64226shiqian  Mutex() {}
214383fe024fb0fefcd7069d5d4c0611eca6bf66bd1fvladlosev  void Lock() {}
214483fe024fb0fefcd7069d5d4c0611eca6bf66bd1fvladlosev  void Unlock() {}
2145d201456903f3ecae1f7794edfab0d5678e64226shiqian  void AssertHeld() const {}
2146d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2147d201456903f3ecae1f7794edfab0d5678e64226shiqian
2148ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
21493bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan  extern ::testing::internal::Mutex mutex
21503bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2151ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
21523bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2153a6340420b9cee27f77c5b91bea807121914a5831kosak// We cannot name this class MutexLock because the ctor declaration would
2154a6340420b9cee27f77c5b91bea807121914a5831kosak// conflict with a macro named MutexLock, which is defined on some
2155a6340420b9cee27f77c5b91bea807121914a5831kosak// platforms. That macro is used as a defensive measure to prevent against
2156a6340420b9cee27f77c5b91bea807121914a5831kosak// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
2157a6340420b9cee27f77c5b91bea807121914a5831kosak// "MutexLock l(&mu)".  Hence the typedef trick below.
2158d201456903f3ecae1f7794edfab0d5678e64226shiqianclass GTestMutexLock {
2159d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
2160d201456903f3ecae1f7794edfab0d5678e64226shiqian  explicit GTestMutexLock(Mutex*) {}  // NOLINT
2161d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2162d201456903f3ecae1f7794edfab0d5678e64226shiqian
2163d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef GTestMutexLock MutexLock;
2164d201456903f3ecae1f7794edfab0d5678e64226shiqian
2165d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <typename T>
2166d201456903f3ecae1f7794edfab0d5678e64226shiqianclass ThreadLocal {
2167d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
2168e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  ThreadLocal() : value_() {}
2169e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  explicit ThreadLocal(const T& value) : value_(value) {}
2170d201456903f3ecae1f7794edfab0d5678e64226shiqian  T* pointer() { return &value_; }
2171d201456903f3ecae1f7794edfab0d5678e64226shiqian  const T* pointer() const { return &value_; }
2172d201456903f3ecae1f7794edfab0d5678e64226shiqian  const T& get() const { return value_; }
2173d201456903f3ecae1f7794edfab0d5678e64226shiqian  void set(const T& value) { value_ = value; }
2174d201456903f3ecae1f7794edfab0d5678e64226shiqian private:
2175d201456903f3ecae1f7794edfab0d5678e64226shiqian  T value_;
2176d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2177d201456903f3ecae1f7794edfab0d5678e64226shiqian
2178a6340420b9cee27f77c5b91bea807121914a5831kosak#endif  // GTEST_IS_THREADSAFE
21793bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
21803bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// Returns the number of threads running in the process, or 0 to indicate that
21813bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan// we cannot detect it.
21829f0824b0a61b50fd40e47da2387cd9b3f872ce47zhanyong.wanGTEST_API_ size_t GetThreadCount();
21833bef459eac9aa84c579f34249aebc9ff56832054zhanyong.wan
2184d2849f573052ba8431a887e0034b1be353a0d9b4shiqian// Passing non-POD classes through ellipsis (...) crashes the ARM
218544bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan// compiler and generates a warning in Sun Studio.  The Nokia Symbian
218644bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan// and the IBM XL C/C++ compiler try to instantiate a copy constructor
218744bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan// for objects passed through ellipsis (...), failing for uncopyable
218844bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan// objects.  We define this to ensure that only POD is passed through
218944bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan// ellipsis on these systems.
219044bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
219106d04c0945bf47bae90532552e6e8294802fc9aavladlosev// We lose support for NULL detection where the compiler doesn't like
219206d04c0945bf47bae90532552e6e8294802fc9aavladlosev// passing non-POD classes through ellipsis (...).
2193ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_ELLIPSIS_NEEDS_POD_ 1
219406d04c0945bf47bae90532552e6e8294802fc9aavladlosev#else
2195ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_CAN_COMPARE_NULL 1
219644bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan#endif
2197d201456903f3ecae1f7794edfab0d5678e64226shiqian
2198d2849f573052ba8431a887e0034b1be353a0d9b4shiqian// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
2199d2849f573052ba8431a887e0034b1be353a0d9b4shiqian// const T& and const T* in a function template.  These compilers
2200d2849f573052ba8431a887e0034b1be353a0d9b4shiqian// _can_ decide between class template specializations for T and T*,
2201d2849f573052ba8431a887e0034b1be353a0d9b4shiqian// so a tr1::type_traits-like is_pointer works.
220244bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
2203ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_NEEDS_IS_POINTER_ 1
220444bafcb62d0f33fbc9aafb5492b245c949850df8zhanyong.wan#endif
2205d201456903f3ecae1f7794edfab0d5678e64226shiqian
2206d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <bool bool_value>
2207d201456903f3ecae1f7794edfab0d5678e64226shiqianstruct bool_constant {
2208d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef bool_constant<bool_value> type;
2209d201456903f3ecae1f7794edfab0d5678e64226shiqian  static const bool value = bool_value;
2210d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2211d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <bool bool_value> const bool bool_constant<bool_value>::value;
2212d201456903f3ecae1f7794edfab0d5678e64226shiqian
2213d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef bool_constant<false> false_type;
2214d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef bool_constant<true> true_type;
2215d201456903f3ecae1f7794edfab0d5678e64226shiqian
2216d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <typename T>
2217d201456903f3ecae1f7794edfab0d5678e64226shiqianstruct is_pointer : public false_type {};
2218d201456903f3ecae1f7794edfab0d5678e64226shiqian
2219d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <typename T>
2220d201456903f3ecae1f7794edfab0d5678e64226shiqianstruct is_pointer<T*> : public true_type {};
2221d201456903f3ecae1f7794edfab0d5678e64226shiqian
2222fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wantemplate <typename Iterator>
2223fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wanstruct IteratorTraits {
2224fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan  typedef typename Iterator::value_type value_type;
2225fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan};
2226fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan
2227fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wantemplate <typename T>
2228fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wanstruct IteratorTraits<T*> {
2229fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan  typedef T value_type;
2230fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan};
2231fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan
2232fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wantemplate <typename T>
2233fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wanstruct IteratorTraits<const T*> {
2234fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan  typedef T value_type;
2235fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan};
2236fc99b1ad515ccfc92ee92001c409f69385033af5zhanyong.wan
223787d23e45f096c91c9e722b20bf15b733dbab0f80zhanyong.wan#if GTEST_OS_WINDOWS
2238ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_PATH_SEP_ "\\"
2239ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_ALT_PATH_SEP_ 1
22403c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// The biggest signed integer type the compiler supports.
22413c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wantypedef __int64 BiggestInt;
224287d23e45f096c91c9e722b20bf15b733dbab0f80zhanyong.wan#else
2243ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_PATH_SEP_ "/"
2244ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# define GTEST_HAS_ALT_PATH_SEP_ 0
22453c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wantypedef long long BiggestInt;  // NOLINT
224687d23e45f096c91c9e722b20bf15b733dbab0f80zhanyong.wan#endif  // GTEST_OS_WINDOWS
224787d23e45f096c91c9e722b20bf15b733dbab0f80zhanyong.wan
224835c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// Utilities for char.
224935c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan
225035c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// isspace(int ch) and friends accept an unsigned char or EOF.  char
225135c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// may be signed, depending on the compiler (or compiler flags).
225235c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// Therefore we need to cast a char to unsigned char before calling
225335c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan// isspace(), etc.
225435c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan
225535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline bool IsAlpha(char ch) {
225635c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return isalpha(static_cast<unsigned char>(ch)) != 0;
225735c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
225835c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline bool IsAlNum(char ch) {
225935c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return isalnum(static_cast<unsigned char>(ch)) != 0;
226035c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
226135c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline bool IsDigit(char ch) {
226235c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return isdigit(static_cast<unsigned char>(ch)) != 0;
226335c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
226435c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline bool IsLower(char ch) {
226535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return islower(static_cast<unsigned char>(ch)) != 0;
226635c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
226735c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline bool IsSpace(char ch) {
226835c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return isspace(static_cast<unsigned char>(ch)) != 0;
226935c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
227035c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline bool IsUpper(char ch) {
227135c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return isupper(static_cast<unsigned char>(ch)) != 0;
227235c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
2273b5eb6ed9e27b7bf80a406e4a38ffe42db43889cczhanyong.waninline bool IsXDigit(char ch) {
2274b5eb6ed9e27b7bf80a406e4a38ffe42db43889cczhanyong.wan  return isxdigit(static_cast<unsigned char>(ch)) != 0;
2275b5eb6ed9e27b7bf80a406e4a38ffe42db43889cczhanyong.wan}
2276a88c9a88e49e90ec414175543b2b7ff2f70866a7zhanyong.waninline bool IsXDigit(wchar_t ch) {
2277a88c9a88e49e90ec414175543b2b7ff2f70866a7zhanyong.wan  const unsigned char low_byte = static_cast<unsigned char>(ch);
2278a88c9a88e49e90ec414175543b2b7ff2f70866a7zhanyong.wan  return ch == low_byte && isxdigit(low_byte) != 0;
2279a88c9a88e49e90ec414175543b2b7ff2f70866a7zhanyong.wan}
228035c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan
228135c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline char ToLower(char ch) {
228235c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
228335c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
228435c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.waninline char ToUpper(char ch) {
228535c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan  return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
228635c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan}
228735c39756495bea5959de5778aaaf33a94f8c1e2ezhanyong.wan
2288e330b754cbd4b23a160521e05ff1014ed576378bkosakinline std::string StripTrailingSpaces(std::string str) {
2289e330b754cbd4b23a160521e05ff1014ed576378bkosak  std::string::iterator it = str.end();
2290e330b754cbd4b23a160521e05ff1014ed576378bkosak  while (it != str.begin() && IsSpace(*--it))
2291e330b754cbd4b23a160521e05ff1014ed576378bkosak    it = str.erase(it);
2292e330b754cbd4b23a160521e05ff1014ed576378bkosak  return str;
2293e330b754cbd4b23a160521e05ff1014ed576378bkosak}
2294e330b754cbd4b23a160521e05ff1014ed576378bkosak
22953c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// The testing::internal::posix namespace holds wrappers for common
22963c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// POSIX functions.  These wrappers hide the differences between
2297f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan// Windows/MSVC and POSIX systems.  Since some compilers define these
2298f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan// standard functions as macros, the wrapper cannot have the same name
2299f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan// as the wrapped function.
2300f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan
23013c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wannamespace posix {
23023c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
23033c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// Functions with a different name on Windows.
23043c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
23050af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#if GTEST_OS_WINDOWS
23063c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2307f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wantypedef struct _stat StatStruct;
23083c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2309ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# ifdef __BORLANDC__
2310c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.waninline int IsATTY(int fd) { return isatty(fd); }
2311c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.waninline int StrCaseCmp(const char* s1, const char* s2) {
2312c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan  return stricmp(s1, s2);
2313c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan}
2314c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.waninline char* StrDup(const char* src) { return strdup(src); }
2315ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else  // !__BORLANDC__
2316ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  if GTEST_OS_WINDOWS_MOBILE
23174853a503371f39aa22e14adcdecea71c09841e34zhanyong.waninline int IsATTY(int /* fd */) { return 0; }
2318ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  else
2319f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int IsATTY(int fd) { return _isatty(fd); }
2320ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan#  endif  // GTEST_OS_WINDOWS_MOBILE
2321f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int StrCaseCmp(const char* s1, const char* s2) {
2322f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return _stricmp(s1, s2);
23233c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
2324f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline char* StrDup(const char* src) { return _strdup(src); }
2325ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // __BORLANDC__
2326c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan
2327ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# if GTEST_OS_WINDOWS_MOBILE
23284853a503371f39aa22e14adcdecea71c09841e34zhanyong.waninline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
23294853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
23304853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan// time and thus not defined there.
2331ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# else
2332c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.waninline int FileNo(FILE* file) { return _fileno(file); }
2333c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.waninline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
2334f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int RmDir(const char* dir) { return _rmdir(dir); }
2335f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline bool IsDir(const StatStruct& st) {
23363c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan  return (_S_IFDIR & st.st_mode) != 0;
23373c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
2338ffeb11d14a890b902dbb26ff2296cda7bf2d31dfzhanyong.wan# endif  // GTEST_OS_WINDOWS_MOBILE
23393c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2340d201456903f3ecae1f7794edfab0d5678e64226shiqian#else
23413c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2342f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wantypedef struct stat StatStruct;
23433c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2344f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int FileNo(FILE* file) { return fileno(file); }
2345f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int IsATTY(int fd) { return isatty(fd); }
2346f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
2347f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int StrCaseCmp(const char* s1, const char* s2) {
2348f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return strcasecmp(s1, s2);
2349f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan}
2350c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.waninline char* StrDup(const char* src) { return strdup(src); }
2351f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int RmDir(const char* dir) { return rmdir(dir); }
2352f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
23533c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2354d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_OS_WINDOWS
2355d201456903f3ecae1f7794edfab0d5678e64226shiqian
23563c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// Functions deprecated by MSVC 8.0.
23573c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
23588120f66c3249e253f03fdb48bee7e528bc038d31billydonahueGTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
23593c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2360f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline const char* StrNCpy(char* dest, const char* src, size_t n) {
2361f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return strncpy(dest, src, n);
23623c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
23634853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan
23644853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
23654853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan// StrError() aren't needed on Windows CE at this time and thus not
23664853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan// defined there.
23674853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan
23688120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
2369f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int ChDir(const char* dir) { return chdir(dir); }
23704853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan#endif
2371f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline FILE* FOpen(const char* path, const char* mode) {
2372f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return fopen(path, mode);
23733c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
2374b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan#if !GTEST_OS_WINDOWS_MOBILE
2375f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
2376f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return freopen(path, mode, stream);
23773c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
2378f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
23794853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan#endif
2380f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int FClose(FILE* fp) { return fclose(fp); }
2381b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan#if !GTEST_OS_WINDOWS_MOBILE
2382f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int Read(int fd, void* buf, unsigned int count) {
2383f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return static_cast<int>(read(fd, buf, count));
23843c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
2385f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int Write(int fd, const void* buf, unsigned int count) {
2386f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return static_cast<int>(write(fd, buf, count));
23873c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
2388f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline int Close(int fd) { return close(fd); }
2389f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline const char* StrError(int errnum) { return strerror(errnum); }
23904853a503371f39aa22e14adcdecea71c09841e34zhanyong.wan#endif
2391f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline const char* GetEnv(const char* name) {
23928120f66c3249e253f03fdb48bee7e528bc038d31billydonahue#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE | GTEST_OS_WINDOWS_RT
2393b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan  // We are on Windows CE, which has no environment variables.
2394102b50483a4b515a94a5b1c75db468eb071cf172kosak  static_cast<void>(name);  // To prevent 'unused argument' warning.
23953c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan  return NULL;
2396cfcbc298cd91806e0e3417e03fce42bc4f1fa150vladlosev#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
2397c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan  // Environment variables which we programmatically clear will be set to the
2398c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan  // empty string rather than unset (NULL).  Handle that case.
2399c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan  const char* const env = getenv(name);
2400c78ae6196dc9c24380b5cf86f8fd75a4d3edc704zhanyong.wan  return (env != NULL && env[0] != '\0') ? env : NULL;
24013c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan#else
2402f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan  return getenv(name);
24033c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan#endif
24043c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}
24053c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
24068120f66c3249e253f03fdb48bee7e528bc038d31billydonahueGTEST_DISABLE_MSC_WARNINGS_POP_()
24073c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2408b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan#if GTEST_OS_WINDOWS_MOBILE
24093c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// Windows CE has no C library. The abort() function is used in
24103c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// several places in Google Test. This implementation provides a reasonable
24113c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan// imitation of standard behaviour.
2412f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wanvoid Abort();
24133c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan#else
2414f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.waninline void Abort() { abort(); }
2415b50ef44a3527d958270ff1f08cb99e3ac633bd17zhanyong.wan#endif  // GTEST_OS_WINDOWS_MOBILE
24163c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
24173c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan}  // namespace posix
24183c7bbf5b46679aea4e0ac7d3ad241cb036146751zhanyong.wan
2419f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// MSVC "deprecates" snprintf and issues warnings wherever it is used.  In
2420f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// order to avoid these warnings, we need to use _snprintf or _snprintf_s on
2421f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// MSVC-based platforms.  We map the GTEST_SNPRINTF_ macro to the appropriate
2422f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// function in order to achieve that.  We use macro definition here because
2423f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// snprintf is a variadic function.
2424f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
2425f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// MSVC 2005 and above support variadic macros.
2426f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev# define GTEST_SNPRINTF_(buffer, size, format, ...) \
2427f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev     _snprintf_s(buffer, size, size, format, __VA_ARGS__)
2428f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev#elif defined(_MSC_VER)
2429f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
2430f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev// complain about _snprintf.
2431f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev# define GTEST_SNPRINTF_ _snprintf
2432f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev#else
2433f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev# define GTEST_SNPRINTF_ snprintf
2434f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev#endif
2435f7d58e81c35b37851733a7518c9f7260ba1b8a40vladlosev
2436d201456903f3ecae1f7794edfab0d5678e64226shiqian// The maximum number a BiggestInt can represent.  This definition
2437d201456903f3ecae1f7794edfab0d5678e64226shiqian// works no matter BiggestInt is represented in one's complement or
2438d201456903f3ecae1f7794edfab0d5678e64226shiqian// two's complement.
2439d201456903f3ecae1f7794edfab0d5678e64226shiqian//
2440d201456903f3ecae1f7794edfab0d5678e64226shiqian// We cannot rely on numeric_limits in STL, as __int64 and long long
2441d201456903f3ecae1f7794edfab0d5678e64226shiqian// are not part of standard C++ and numeric_limits doesn't need to be
2442d201456903f3ecae1f7794edfab0d5678e64226shiqian// defined for them.
2443d201456903f3ecae1f7794edfab0d5678e64226shiqianconst BiggestInt kMaxBiggestInt =
2444d201456903f3ecae1f7794edfab0d5678e64226shiqian    ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
2445d201456903f3ecae1f7794edfab0d5678e64226shiqian
2446d201456903f3ecae1f7794edfab0d5678e64226shiqian// This template class serves as a compile-time function from size to
2447d201456903f3ecae1f7794edfab0d5678e64226shiqian// type.  It maps a size in bytes to a primitive type with that
2448d201456903f3ecae1f7794edfab0d5678e64226shiqian// size. e.g.
2449d201456903f3ecae1f7794edfab0d5678e64226shiqian//
2450d201456903f3ecae1f7794edfab0d5678e64226shiqian//   TypeWithSize<4>::UInt
2451d201456903f3ecae1f7794edfab0d5678e64226shiqian//
2452d201456903f3ecae1f7794edfab0d5678e64226shiqian// is typedef-ed to be unsigned int (unsigned integer made up of 4
2453d201456903f3ecae1f7794edfab0d5678e64226shiqian// bytes).
2454d201456903f3ecae1f7794edfab0d5678e64226shiqian//
2455d201456903f3ecae1f7794edfab0d5678e64226shiqian// Such functionality should belong to STL, but I cannot find it
2456d201456903f3ecae1f7794edfab0d5678e64226shiqian// there.
2457d201456903f3ecae1f7794edfab0d5678e64226shiqian//
2458d201456903f3ecae1f7794edfab0d5678e64226shiqian// Google Test uses this class in the implementation of floating-point
2459d201456903f3ecae1f7794edfab0d5678e64226shiqian// comparison.
2460d201456903f3ecae1f7794edfab0d5678e64226shiqian//
2461d201456903f3ecae1f7794edfab0d5678e64226shiqian// For now it only handles UInt (unsigned int) as that's all Google Test
2462d201456903f3ecae1f7794edfab0d5678e64226shiqian// needs.  Other types can be easily added in the future if need
2463d201456903f3ecae1f7794edfab0d5678e64226shiqian// arises.
2464d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <size_t size>
2465d201456903f3ecae1f7794edfab0d5678e64226shiqianclass TypeWithSize {
2466d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
2467d201456903f3ecae1f7794edfab0d5678e64226shiqian  // This prevents the user from using TypeWithSize<N> with incorrect
2468d201456903f3ecae1f7794edfab0d5678e64226shiqian  // values of N.
2469d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef void UInt;
2470d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2471d201456903f3ecae1f7794edfab0d5678e64226shiqian
2472d201456903f3ecae1f7794edfab0d5678e64226shiqian// The specialization for size 4.
2473d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <>
2474d201456903f3ecae1f7794edfab0d5678e64226shiqianclass TypeWithSize<4> {
2475d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
2476d201456903f3ecae1f7794edfab0d5678e64226shiqian  // unsigned int has size 4 in both gcc and MSVC.
2477d201456903f3ecae1f7794edfab0d5678e64226shiqian  //
2478d201456903f3ecae1f7794edfab0d5678e64226shiqian  // As base/basictypes.h doesn't compile on Windows, we cannot use
2479d201456903f3ecae1f7794edfab0d5678e64226shiqian  // uint32, uint64, and etc here.
2480d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef int Int;
2481d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef unsigned int UInt;
2482d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2483d201456903f3ecae1f7794edfab0d5678e64226shiqian
2484d201456903f3ecae1f7794edfab0d5678e64226shiqian// The specialization for size 8.
2485d201456903f3ecae1f7794edfab0d5678e64226shiqiantemplate <>
2486d201456903f3ecae1f7794edfab0d5678e64226shiqianclass TypeWithSize<8> {
2487d201456903f3ecae1f7794edfab0d5678e64226shiqian public:
24880af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#if GTEST_OS_WINDOWS
2489d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef __int64 Int;
2490d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef unsigned __int64 UInt;
2491d201456903f3ecae1f7794edfab0d5678e64226shiqian#else
2492d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef long long Int;  // NOLINT
2493d201456903f3ecae1f7794edfab0d5678e64226shiqian  typedef unsigned long long UInt;  // NOLINT
2494d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_OS_WINDOWS
2495d201456903f3ecae1f7794edfab0d5678e64226shiqian};
2496d201456903f3ecae1f7794edfab0d5678e64226shiqian
2497d201456903f3ecae1f7794edfab0d5678e64226shiqian// Integer types of known sizes.
2498d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef TypeWithSize<4>::Int Int32;
2499d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef TypeWithSize<4>::UInt UInt32;
2500d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef TypeWithSize<8>::Int Int64;
2501d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef TypeWithSize<8>::UInt UInt64;
2502d201456903f3ecae1f7794edfab0d5678e64226shiqiantypedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.
2503d201456903f3ecae1f7794edfab0d5678e64226shiqian
2504d201456903f3ecae1f7794edfab0d5678e64226shiqian// Utilities for command line flags and environment variables.
2505d201456903f3ecae1f7794edfab0d5678e64226shiqian
2506d201456903f3ecae1f7794edfab0d5678e64226shiqian// Macro for referencing flags.
2507156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if !defined(GTEST_FLAG)
2508156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_FLAG(name) FLAGS_gtest_##name
2509156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // !defined(GTEST_FLAG)
2510d201456903f3ecae1f7794edfab0d5678e64226shiqian
25114d69b1607a876a77b8719f035b23254677617a47kosak#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
25124d69b1607a876a77b8719f035b23254677617a47kosak# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1
25134d69b1607a876a77b8719f035b23254677617a47kosak#endif  // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
25144d69b1607a876a77b8719f035b23254677617a47kosak
2515156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if !defined(GTEST_DECLARE_bool_)
25160928adbfea9b7645e884bd95fee23cfd669729cdkosak# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
25170928adbfea9b7645e884bd95fee23cfd669729cdkosak
2518d201456903f3ecae1f7794edfab0d5678e64226shiqian// Macros for declaring flags.
2519156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
2520156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_DECLARE_int32_(name) \
252183589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan    GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
2522e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#define GTEST_DECLARE_string_(name) \
252387fdda2cf24d953f3cbec1e0c266b2db9928f406jgm    GTEST_API_ extern ::std::string GTEST_FLAG(name)
2524d201456903f3ecae1f7794edfab0d5678e64226shiqian
2525d201456903f3ecae1f7794edfab0d5678e64226shiqian// Macros for defining flags.
2526e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#define GTEST_DEFINE_bool_(name, default_val, doc) \
252783589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan    GTEST_API_ bool GTEST_FLAG(name) = (default_val)
2528e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#define GTEST_DEFINE_int32_(name, default_val, doc) \
252983589cca345d2f03d93b0555437aa480e0ed6699zhanyong.wan    GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
2530e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#define GTEST_DEFINE_string_(name, default_val, doc) \
253187fdda2cf24d953f3cbec1e0c266b2db9928f406jgm    GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
2532d201456903f3ecae1f7794edfab0d5678e64226shiqian
2533156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // !defined(GTEST_DECLARE_bool_)
2534156d1b513b90deca6287c737e3e6453dc7f64d35kosak
25354c11f25f8c972bc5bed6d92abe2a0a3e41f499d7vladlosev// Thread annotations
2536156d1b513b90deca6287c737e3e6453dc7f64d35kosak#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
2537156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
2538156d1b513b90deca6287c737e3e6453dc7f64d35kosak# define GTEST_LOCK_EXCLUDED_(locks)
2539156d1b513b90deca6287c737e3e6453dc7f64d35kosak#endif  // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
25404c11f25f8c972bc5bed6d92abe2a0a3e41f499d7vladlosev
2541d201456903f3ecae1f7794edfab0d5678e64226shiqian// Parses 'str' for a 32-bit signed integer.  If successful, writes the result
2542d201456903f3ecae1f7794edfab0d5678e64226shiqian// to *value and returns true; otherwise leaves *value unchanged and returns
2543d201456903f3ecae1f7794edfab0d5678e64226shiqian// false.
2544d201456903f3ecae1f7794edfab0d5678e64226shiqian// TODO(chandlerc): Find a better way to refactor flag and environment parsing
2545d201456903f3ecae1f7794edfab0d5678e64226shiqian// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
2546d201456903f3ecae1f7794edfab0d5678e64226shiqian// function.
2547d201456903f3ecae1f7794edfab0d5678e64226shiqianbool ParseInt32(const Message& src_text, const char* str, Int32* value);
2548d201456903f3ecae1f7794edfab0d5678e64226shiqian
2549d201456903f3ecae1f7794edfab0d5678e64226shiqian// Parses a bool/Int32/string from the environment variable
2550d201456903f3ecae1f7794edfab0d5678e64226shiqian// corresponding to the given Google Test flag.
2551d201456903f3ecae1f7794edfab0d5678e64226shiqianbool BoolFromGTestEnv(const char* flag, bool default_val);
25529f0824b0a61b50fd40e47da2387cd9b3f872ce47zhanyong.wanGTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
2553d201456903f3ecae1f7794edfab0d5678e64226shiqianconst char* StringFromGTestEnv(const char* flag, const char* default_val);
2554d201456903f3ecae1f7794edfab0d5678e64226shiqian
2555d201456903f3ecae1f7794edfab0d5678e64226shiqian}  // namespace internal
2556d201456903f3ecae1f7794edfab0d5678e64226shiqian}  // namespace testing
2557d201456903f3ecae1f7794edfab0d5678e64226shiqian
2558d201456903f3ecae1f7794edfab0d5678e64226shiqian#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
25598120f66c3249e253f03fdb48bee7e528bc038d31billydonahue
2560