gtest-port.h
Go to the documentation of this file.
00001 // Copyright 2005, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Authors: wan@google.com (Zhanyong Wan)
00031 //
00032 // Low-level types and utilities for porting Google Test to various
00033 // platforms.  All macros ending with _ and symbols defined in an
00034 // internal namespace are subject to change without notice.  Code
00035 // outside Google Test MUST NOT USE THEM DIRECTLY.  Macros that don't
00036 // end with _ are part of Google Test's public API and can be used by
00037 // code outside Google Test.
00038 //
00039 // This file is fundamental to Google Test.  All other Google Test source
00040 // files are expected to #include this.  Therefore, it cannot #include
00041 // any other Google Test header.
00042 
00043 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
00044 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
00045 
00046 // Environment-describing macros
00047 // -----------------------------
00048 //
00049 // Google Test can be used in many different environments.  Macros in
00050 // this section tell Google Test what kind of environment it is being
00051 // used in, such that Google Test can provide environment-specific
00052 // features and implementations.
00053 //
00054 // Google Test tries to automatically detect the properties of its
00055 // environment, so users usually don't need to worry about these
00056 // macros.  However, the automatic detection is not perfect.
00057 // Sometimes it's necessary for a user to define some of the following
00058 // macros in the build script to override Google Test's decisions.
00059 //
00060 // If the user doesn't define a macro in the list, Google Test will
00061 // provide a default definition.  After this header is #included, all
00062 // macros in this list will be defined to either 1 or 0.
00063 //
00064 // Notes to maintainers:
00065 //   - Each macro here is a user-tweakable knob; do not grow the list
00066 //     lightly.
00067 //   - Use #if to key off these macros.  Don't use #ifdef or "#if
00068 //     defined(...)", which will not work as these macros are ALWAYS
00069 //     defined.
00070 //
00071 //   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
00072 //                              is/isn't available.
00073 //   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
00074 //                              are enabled.
00075 //   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
00076 //                              is/isn't available (some systems define
00077 //                              ::string, which is different to std::string).
00078 //   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
00079 //                              is/isn't available (some systems define
00080 //                              ::wstring, which is different to std::wstring).
00081 //   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
00082 //                              expressions are/aren't available.
00083 //   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
00084 //                              is/isn't available.
00085 //   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
00086 //                              enabled.
00087 //   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
00088 //                              std::wstring does/doesn't work (Google Test can
00089 //                              be used where std::wstring is unavailable).
00090 //   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
00091 //                              is/isn't available.
00092 //   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
00093 //                              compiler supports Microsoft's "Structured
00094 //                              Exception Handling".
00095 //   GTEST_HAS_STREAM_REDIRECTION
00096 //                            - Define it to 1/0 to indicate whether the
00097 //                              platform supports I/O stream redirection using
00098 //                              dup() and dup2().
00099 //   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
00100 //                              Test's own tr1 tuple implementation should be
00101 //                              used.  Unused when the user sets
00102 //                              GTEST_HAS_TR1_TUPLE to 0.
00103 //   GTEST_LANG_CXX11         - Define it to 1/0 to indicate that Google Test
00104 //                              is building in C++11/C++98 mode.
00105 //   GTEST_LINKED_AS_SHARED_LIBRARY
00106 //                            - Define to 1 when compiling tests that use
00107 //                              Google Test as a shared library (known as
00108 //                              DLL on Windows).
00109 //   GTEST_CREATE_SHARED_LIBRARY
00110 //                            - Define to 1 when compiling Google Test itself
00111 //                              as a shared library.
00112 
00113 // Platform-indicating macros
00114 // --------------------------
00115 //
00116 // Macros indicating the platform on which Google Test is being used
00117 // (a macro is defined to 1 if compiled on the given platform;
00118 // otherwise UNDEFINED -- it's never defined to 0.).  Google Test
00119 // defines these macros automatically.  Code outside Google Test MUST
00120 // NOT define them.
00121 //
00122 //   GTEST_OS_AIX      - IBM AIX
00123 //   GTEST_OS_CYGWIN   - Cygwin
00124 //   GTEST_OS_FREEBSD  - FreeBSD
00125 //   GTEST_OS_HPUX     - HP-UX
00126 //   GTEST_OS_LINUX    - Linux
00127 //     GTEST_OS_LINUX_ANDROID - Google Android
00128 //   GTEST_OS_MAC      - Mac OS X
00129 //     GTEST_OS_IOS    - iOS
00130 //   GTEST_OS_NACL     - Google Native Client (NaCl)
00131 //   GTEST_OS_OPENBSD  - OpenBSD
00132 //   GTEST_OS_QNX      - QNX
00133 //   GTEST_OS_SOLARIS  - Sun Solaris
00134 //   GTEST_OS_SYMBIAN  - Symbian
00135 //   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
00136 //     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
00137 //     GTEST_OS_WINDOWS_MINGW    - MinGW
00138 //     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
00139 //     GTEST_OS_WINDOWS_PHONE    - Windows Phone
00140 //     GTEST_OS_WINDOWS_RT       - Windows Store App/WinRT
00141 //   GTEST_OS_ZOS      - z/OS
00142 //
00143 // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
00144 // most stable support.  Since core members of the Google Test project
00145 // don't have access to other platforms, support for them may be less
00146 // stable.  If you notice any problems on your platform, please notify
00147 // googletestframework@googlegroups.com (patches for fixing them are
00148 // even more welcome!).
00149 //
00150 // It is possible that none of the GTEST_OS_* macros are defined.
00151 
00152 // Feature-indicating macros
00153 // -------------------------
00154 //
00155 // Macros indicating which Google Test features are available (a macro
00156 // is defined to 1 if the corresponding feature is supported;
00157 // otherwise UNDEFINED -- it's never defined to 0.).  Google Test
00158 // defines these macros automatically.  Code outside Google Test MUST
00159 // NOT define them.
00160 //
00161 // These macros are public so that portable tests can be written.
00162 // Such tests typically surround code using a feature with an #if
00163 // which controls that code.  For example:
00164 //
00165 // #if GTEST_HAS_DEATH_TEST
00166 //   EXPECT_DEATH(DoSomethingDeadly());
00167 // #endif
00168 //
00169 //   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
00170 //                            tests)
00171 //   GTEST_HAS_DEATH_TEST   - death tests
00172 //   GTEST_HAS_PARAM_TEST   - value-parameterized tests
00173 //   GTEST_HAS_TYPED_TEST   - typed tests
00174 //   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
00175 //   GTEST_IS_THREADSAFE    - Google Test is thread-safe.
00176 //   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
00177 //                            GTEST_HAS_POSIX_RE (see above) which users can
00178 //                            define themselves.
00179 //   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
00180 //                            the above two are mutually exclusive.
00181 //   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
00182 
00183 // Misc public macros
00184 // ------------------
00185 //
00186 //   GTEST_FLAG(flag_name)  - references the variable corresponding to
00187 //                            the given Google Test flag.
00188 
00189 // Internal utilities
00190 // ------------------
00191 //
00192 // The following macros and utilities are for Google Test's INTERNAL
00193 // use only.  Code outside Google Test MUST NOT USE THEM DIRECTLY.
00194 //
00195 // Macros for basic C++ coding:
00196 //   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
00197 //   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
00198 //                              variable don't have to be used.
00199 //   GTEST_DISALLOW_ASSIGN_   - disables operator=.
00200 //   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
00201 //   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
00202 //   GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is
00203 //                                        suppressed (constant conditional).
00204 //   GTEST_INTENTIONAL_CONST_COND_POP_  - finish code section where MSVC C4127
00205 //                                        is suppressed.
00206 //
00207 // C++11 feature wrappers:
00208 //
00209 //   testing::internal::move  - portability wrapper for std::move.
00210 //
00211 // Synchronization:
00212 //   Mutex, MutexLock, ThreadLocal, GetThreadCount()
00213 //                            - synchronization primitives.
00214 //
00215 // Template meta programming:
00216 //   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
00217 //   IteratorTraits - partial implementation of std::iterator_traits, which
00218 //                    is not available in libCstd when compiled with Sun C++.
00219 //
00220 // Smart pointers:
00221 //   scoped_ptr     - as in TR2.
00222 //
00223 // Regular expressions:
00224 //   RE             - a simple regular expression class using the POSIX
00225 //                    Extended Regular Expression syntax on UNIX-like
00226 //                    platforms, or a reduced regular exception syntax on
00227 //                    other platforms, including Windows.
00228 //
00229 // Logging:
00230 //   GTEST_LOG_()   - logs messages at the specified severity level.
00231 //   LogToStderr()  - directs all log messages to stderr.
00232 //   FlushInfoLog() - flushes informational log messages.
00233 //
00234 // Stdout and stderr capturing:
00235 //   CaptureStdout()     - starts capturing stdout.
00236 //   GetCapturedStdout() - stops capturing stdout and returns the captured
00237 //                         string.
00238 //   CaptureStderr()     - starts capturing stderr.
00239 //   GetCapturedStderr() - stops capturing stderr and returns the captured
00240 //                         string.
00241 //
00242 // Integer types:
00243 //   TypeWithSize   - maps an integer to a int type.
00244 //   Int32, UInt32, Int64, UInt64, TimeInMillis
00245 //                  - integers of known sizes.
00246 //   BiggestInt     - the biggest signed integer type.
00247 //
00248 // Command-line utilities:
00249 //   GTEST_DECLARE_*()  - declares a flag.
00250 //   GTEST_DEFINE_*()   - defines a flag.
00251 //   GetInjectableArgvs() - returns the command line as a vector of strings.
00252 //
00253 // Environment variable utilities:
00254 //   GetEnv()             - gets the value of an environment variable.
00255 //   BoolFromGTestEnv()   - parses a bool environment variable.
00256 //   Int32FromGTestEnv()  - parses an Int32 environment variable.
00257 //   StringFromGTestEnv() - parses a string environment variable.
00258 
00259 #include <ctype.h>   // for isspace, etc
00260 #include <stddef.h>  // for ptrdiff_t
00261 #include <stdlib.h>
00262 #include <stdio.h>
00263 #include <string.h>
00264 #ifndef _WIN32_WCE
00265 # include <sys/types.h>
00266 # include <sys/stat.h>
00267 #endif  // !_WIN32_WCE
00268 
00269 #if defined __APPLE__
00270 # include <AvailabilityMacros.h>
00271 # include <TargetConditionals.h>
00272 #endif
00273 
00274 #include <algorithm>  // NOLINT
00275 #include <iostream>  // NOLINT
00276 #include <sstream>  // NOLINT
00277 #include <string>  // NOLINT
00278 #include <utility>
00279 
00280 #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
00281 #define GTEST_FLAG_PREFIX_ "gtest_"
00282 #define GTEST_FLAG_PREFIX_DASH_ "gtest-"
00283 #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
00284 #define GTEST_NAME_ "Google Test"
00285 #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
00286 
00287 // Determines the version of gcc that is used to compile this.
00288 #ifdef __GNUC__
00289 // 40302 means version 4.3.2.
00290 # define GTEST_GCC_VER_ \
00291     (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
00292 #endif  // __GNUC__
00293 
00294 // Determines the platform on which Google Test is compiled.
00295 #ifdef __CYGWIN__
00296 # define GTEST_OS_CYGWIN 1
00297 #elif defined __SYMBIAN32__
00298 # define GTEST_OS_SYMBIAN 1
00299 #elif defined _WIN32
00300 # define GTEST_OS_WINDOWS 1
00301 # ifdef _WIN32_WCE
00302 #  define GTEST_OS_WINDOWS_MOBILE 1
00303 # elif defined(__MINGW__) || defined(__MINGW32__)
00304 #  define GTEST_OS_WINDOWS_MINGW 1
00305 # elif defined(WINAPI_FAMILY)
00306 #  include <winapifamily.h>
00307 #  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
00308 #   define GTEST_OS_WINDOWS_DESKTOP 1
00309 #  elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
00310 #   define GTEST_OS_WINDOWS_PHONE 1
00311 #  elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
00312 #   define GTEST_OS_WINDOWS_RT 1
00313 #  else
00314     // WINAPI_FAMILY defined but no known partition matched.
00315     // Default to desktop.
00316 #   define GTEST_OS_WINDOWS_DESKTOP 1
00317 #  endif
00318 # else
00319 #  define GTEST_OS_WINDOWS_DESKTOP 1
00320 # endif  // _WIN32_WCE
00321 #elif defined __APPLE__
00322 # define GTEST_OS_MAC 1
00323 # if TARGET_OS_IPHONE
00324 #  define GTEST_OS_IOS 1
00325 # endif
00326 #elif defined __FreeBSD__
00327 # define GTEST_OS_FREEBSD 1
00328 #elif defined __linux__
00329 # define GTEST_OS_LINUX 1
00330 # if defined __ANDROID__
00331 #  define GTEST_OS_LINUX_ANDROID 1
00332 # endif
00333 #elif defined __MVS__
00334 # define GTEST_OS_ZOS 1
00335 #elif defined(__sun) && defined(__SVR4)
00336 # define GTEST_OS_SOLARIS 1
00337 #elif defined(_AIX)
00338 # define GTEST_OS_AIX 1
00339 #elif defined(__hpux)
00340 # define GTEST_OS_HPUX 1
00341 #elif defined __native_client__
00342 # define GTEST_OS_NACL 1
00343 #elif defined __OpenBSD__
00344 # define GTEST_OS_OPENBSD 1
00345 #elif defined __QNX__
00346 # define GTEST_OS_QNX 1
00347 #endif  // __CYGWIN__
00348 
00349 // Macros for disabling Microsoft Visual C++ warnings.
00350 //
00351 //   GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
00352 //   /* code that triggers warnings C4800 and C4385 */
00353 //   GTEST_DISABLE_MSC_WARNINGS_POP_()
00354 #if _MSC_VER >= 1500
00355 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
00356     __pragma(warning(push))                        \
00357     __pragma(warning(disable: warnings))
00358 # define GTEST_DISABLE_MSC_WARNINGS_POP_()          \
00359     __pragma(warning(pop))
00360 #else
00361 // Older versions of MSVC don't have __pragma.
00362 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
00363 # define GTEST_DISABLE_MSC_WARNINGS_POP_()
00364 #endif
00365 
00366 #ifndef GTEST_LANG_CXX11
00367 // gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when
00368 // -std={c,gnu}++{0x,11} is passed.  The C++11 standard specifies a
00369 // value for __cplusplus, and recent versions of clang, gcc, and
00370 // probably other compilers set that too in C++11 mode.
00371 # if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
00372 // Compiling in at least C++11 mode.
00373 #  define GTEST_LANG_CXX11 1
00374 # else
00375 #  define GTEST_LANG_CXX11 0
00376 # endif
00377 #endif
00378 
00379 // Distinct from C++11 language support, some environments don't provide
00380 // proper C++11 library support. Notably, it's possible to build in
00381 // C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++
00382 // with no C++11 support.
00383 //
00384 // libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__
00385 // 20110325, but maintenance releases in the 4.4 and 4.5 series followed
00386 // this date, so check for those versions by their date stamps.
00387 // https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
00388 #if GTEST_LANG_CXX11 && \
00389     (!defined(__GLIBCXX__) || ( \
00390         __GLIBCXX__ >= 20110325ul &&  /* GCC >= 4.6.0 */ \
00391         /* Blacklist of patch releases of older branches: */ \
00392         __GLIBCXX__ != 20110416ul &&  /* GCC 4.4.6 */ \
00393         __GLIBCXX__ != 20120313ul &&  /* GCC 4.4.7 */ \
00394         __GLIBCXX__ != 20110428ul &&  /* GCC 4.5.3 */ \
00395         __GLIBCXX__ != 20120702ul))   /* GCC 4.5.4 */
00396 # define GTEST_STDLIB_CXX11 1
00397 #endif
00398 
00399 // Only use C++11 library features if the library provides them.
00400 #if GTEST_STDLIB_CXX11
00401 # define GTEST_HAS_STD_BEGIN_AND_END_ 1
00402 # define GTEST_HAS_STD_FORWARD_LIST_ 1
00403 # define GTEST_HAS_STD_FUNCTION_ 1
00404 # define GTEST_HAS_STD_INITIALIZER_LIST_ 1
00405 # define GTEST_HAS_STD_MOVE_ 1
00406 # define GTEST_HAS_STD_UNIQUE_PTR_ 1
00407 #endif
00408 
00409 // C++11 specifies that <tuple> provides std::tuple.
00410 // Some platforms still might not have it, however.
00411 #if GTEST_LANG_CXX11
00412 # define GTEST_HAS_STD_TUPLE_ 1
00413 # if defined(__clang__)
00414 // Inspired by http://clang.llvm.org/docs/LanguageExtensions.html#__has_include
00415 #  if defined(__has_include) && !__has_include(<tuple>)
00416 #   undef GTEST_HAS_STD_TUPLE_
00417 #  endif
00418 # elif defined(_MSC_VER)
00419 // Inspired by boost/config/stdlib/dinkumware.hpp
00420 #  if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
00421 #   undef GTEST_HAS_STD_TUPLE_
00422 #  endif
00423 # elif defined(__GLIBCXX__)
00424 // Inspired by boost/config/stdlib/libstdcpp3.hpp,
00425 // http://gcc.gnu.org/gcc-4.2/changes.html and
00426 // http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.200x
00427 #  if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
00428 #   undef GTEST_HAS_STD_TUPLE_
00429 #  endif
00430 # endif
00431 #endif
00432 
00433 // Brings in definitions for functions used in the testing::internal::posix
00434 // namespace (read, write, close, chdir, isatty, stat). We do not currently
00435 // use them on Windows Mobile.
00436 #if GTEST_OS_WINDOWS
00437 # if !GTEST_OS_WINDOWS_MOBILE
00438 #  include <direct.h>
00439 #  include <io.h>
00440 # endif
00441 // In order to avoid having to include <windows.h>, use forward declaration
00442 // assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
00443 // This assumption is verified by
00444 // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
00445 struct _RTL_CRITICAL_SECTION;
00446 #else
00447 // This assumes that non-Windows OSes provide unistd.h. For OSes where this
00448 // is not the case, we need to include headers that provide the functions
00449 // mentioned above.
00450 # include <unistd.h>
00451 # include <strings.h>
00452 #endif  // GTEST_OS_WINDOWS
00453 
00454 #if GTEST_OS_LINUX_ANDROID
00455 // Used to define __ANDROID_API__ matching the target NDK API level.
00456 #  include <android/api-level.h>  // NOLINT
00457 #endif
00458 
00459 // Defines this to true iff Google Test can use POSIX regular expressions.
00460 #ifndef GTEST_HAS_POSIX_RE
00461 # if GTEST_OS_LINUX_ANDROID
00462 // On Android, <regex.h> is only available starting with Gingerbread.
00463 #  define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
00464 # else
00465 #  define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
00466 # endif
00467 #endif
00468 
00469 #if GTEST_HAS_POSIX_RE
00470 
00471 // On some platforms, <regex.h> needs someone to define size_t, and
00472 // won't compile otherwise.  We can #include it here as we already
00473 // included <stdlib.h>, which is guaranteed to define size_t through
00474 // <stddef.h>.
00475 # include <regex.h>  // NOLINT
00476 
00477 # define GTEST_USES_POSIX_RE 1
00478 
00479 #elif GTEST_OS_WINDOWS
00480 
00481 // <regex.h> is not available on Windows.  Use our own simple regex
00482 // implementation instead.
00483 # define GTEST_USES_SIMPLE_RE 1
00484 
00485 #else
00486 
00487 // <regex.h> may not be available on this platform.  Use our own
00488 // simple regex implementation instead.
00489 # define GTEST_USES_SIMPLE_RE 1
00490 
00491 #endif  // GTEST_HAS_POSIX_RE
00492 
00493 #ifndef GTEST_HAS_EXCEPTIONS
00494 // The user didn't tell us whether exceptions are enabled, so we need
00495 // to figure it out.
00496 # if defined(_MSC_VER) || defined(__BORLANDC__)
00497 // MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
00498 // macro to enable exceptions, so we'll do the same.
00499 // Assumes that exceptions are enabled by default.
00500 #  ifndef _HAS_EXCEPTIONS
00501 #   define _HAS_EXCEPTIONS 1
00502 #  endif  // _HAS_EXCEPTIONS
00503 #  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
00504 # elif defined(__clang__)
00505 // clang defines __EXCEPTIONS iff exceptions are enabled before clang 220714,
00506 // but iff cleanups are enabled after that. In Obj-C++ files, there can be
00507 // cleanups for ObjC exceptions which also need cleanups, even if C++ exceptions
00508 // are disabled. clang has __has_feature(cxx_exceptions) which checks for C++
00509 // exceptions starting at clang r206352, but which checked for cleanups prior to
00510 // that. To reliably check for C++ exception availability with clang, check for
00511 // __EXCEPTIONS && __has_feature(cxx_exceptions).
00512 #  define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
00513 # elif defined(__GNUC__) && __EXCEPTIONS
00514 // gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
00515 #  define GTEST_HAS_EXCEPTIONS 1
00516 # elif defined(__SUNPRO_CC)
00517 // Sun Pro CC supports exceptions.  However, there is no compile-time way of
00518 // detecting whether they are enabled or not.  Therefore, we assume that
00519 // they are enabled unless the user tells us otherwise.
00520 #  define GTEST_HAS_EXCEPTIONS 1
00521 # elif defined(__IBMCPP__) && __EXCEPTIONS
00522 // xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
00523 #  define GTEST_HAS_EXCEPTIONS 1
00524 # elif defined(__HP_aCC)
00525 // Exception handling is in effect by default in HP aCC compiler. It has to
00526 // be turned of by +noeh compiler option if desired.
00527 #  define GTEST_HAS_EXCEPTIONS 1
00528 # else
00529 // For other compilers, we assume exceptions are disabled to be
00530 // conservative.
00531 #  define GTEST_HAS_EXCEPTIONS 0
00532 # endif  // defined(_MSC_VER) || defined(__BORLANDC__)
00533 #endif  // GTEST_HAS_EXCEPTIONS
00534 
00535 #if !defined(GTEST_HAS_STD_STRING)
00536 // Even though we don't use this macro any longer, we keep it in case
00537 // some clients still depend on it.
00538 # define GTEST_HAS_STD_STRING 1
00539 #elif !GTEST_HAS_STD_STRING
00540 // The user told us that ::std::string isn't available.
00541 # error "Google Test cannot be used where ::std::string isn't available."
00542 #endif  // !defined(GTEST_HAS_STD_STRING)
00543 
00544 #ifndef GTEST_HAS_GLOBAL_STRING
00545 // The user didn't tell us whether ::string is available, so we need
00546 // to figure it out.
00547 
00548 # define GTEST_HAS_GLOBAL_STRING 0
00549 
00550 #endif  // GTEST_HAS_GLOBAL_STRING
00551 
00552 #ifndef GTEST_HAS_STD_WSTRING
00553 // The user didn't tell us whether ::std::wstring is available, so we need
00554 // to figure it out.
00555 // TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
00556 //   is available.
00557 
00558 // Cygwin 1.7 and below doesn't support ::std::wstring.
00559 // Solaris' libc++ doesn't support it either.  Android has
00560 // no support for it at least as recent as Froyo (2.2).
00561 # define GTEST_HAS_STD_WSTRING \
00562     (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
00563 
00564 #endif  // GTEST_HAS_STD_WSTRING
00565 
00566 #ifndef GTEST_HAS_GLOBAL_WSTRING
00567 // The user didn't tell us whether ::wstring is available, so we need
00568 // to figure it out.
00569 # define GTEST_HAS_GLOBAL_WSTRING \
00570     (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
00571 #endif  // GTEST_HAS_GLOBAL_WSTRING
00572 
00573 // Determines whether RTTI is available.
00574 #ifndef GTEST_HAS_RTTI
00575 // The user didn't tell us whether RTTI is enabled, so we need to
00576 // figure it out.
00577 
00578 # ifdef _MSC_VER
00579 
00580 #  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
00581 #   define GTEST_HAS_RTTI 1
00582 #  else
00583 #   define GTEST_HAS_RTTI 0
00584 #  endif
00585 
00586 // Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
00587 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
00588 
00589 #  ifdef __GXX_RTTI
00590 // When building against STLport with the Android NDK and with
00591 // -frtti -fno-exceptions, the build fails at link time with undefined
00592 // references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
00593 // so disable RTTI when detected.
00594 #   if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
00595        !defined(__EXCEPTIONS)
00596 #    define GTEST_HAS_RTTI 0
00597 #   else
00598 #    define GTEST_HAS_RTTI 1
00599 #   endif  // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
00600 #  else
00601 #   define GTEST_HAS_RTTI 0
00602 #  endif  // __GXX_RTTI
00603 
00604 // Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
00605 // using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
00606 // first version with C++ support.
00607 # elif defined(__clang__)
00608 
00609 #  define GTEST_HAS_RTTI __has_feature(cxx_rtti)
00610 
00611 // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
00612 // both the typeid and dynamic_cast features are present.
00613 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
00614 
00615 #  ifdef __RTTI_ALL__
00616 #   define GTEST_HAS_RTTI 1
00617 #  else
00618 #   define GTEST_HAS_RTTI 0
00619 #  endif
00620 
00621 # else
00622 
00623 // For all other compilers, we assume RTTI is enabled.
00624 #  define GTEST_HAS_RTTI 1
00625 
00626 # endif  // _MSC_VER
00627 
00628 #endif  // GTEST_HAS_RTTI
00629 
00630 // It's this header's responsibility to #include <typeinfo> when RTTI
00631 // is enabled.
00632 #if GTEST_HAS_RTTI
00633 # include <typeinfo>
00634 #endif
00635 
00636 // Determines whether Google Test can use the pthreads library.
00637 #ifndef GTEST_HAS_PTHREAD
00638 // The user didn't tell us explicitly, so we make reasonable assumptions about
00639 // which platforms have pthreads support.
00640 //
00641 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
00642 // to your compiler flags.
00643 # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \
00644     || GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NACL)
00645 #endif  // GTEST_HAS_PTHREAD
00646 
00647 #if GTEST_HAS_PTHREAD
00648 // gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
00649 // true.
00650 # include <pthread.h>  // NOLINT
00651 
00652 // For timespec and nanosleep, used below.
00653 # include <time.h>  // NOLINT
00654 #endif
00655 
00656 // Determines whether Google Test can use tr1/tuple.  You can define
00657 // this macro to 0 to prevent Google Test from using tuple (any
00658 // feature depending on tuple with be disabled in this mode).
00659 #ifndef GTEST_HAS_TR1_TUPLE
00660 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
00661 // STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
00662 #  define GTEST_HAS_TR1_TUPLE 0
00663 # else
00664 // The user didn't tell us not to do it, so we assume it's OK.
00665 #  define GTEST_HAS_TR1_TUPLE 1
00666 # endif
00667 #endif  // GTEST_HAS_TR1_TUPLE
00668 
00669 // Determines whether Google Test's own tr1 tuple implementation
00670 // should be used.
00671 #ifndef GTEST_USE_OWN_TR1_TUPLE
00672 // The user didn't tell us, so we need to figure it out.
00673 
00674 // We use our own TR1 tuple if we aren't sure the user has an
00675 // implementation of it already.  At this time, libstdc++ 4.0.0+ and
00676 // MSVC 2010 are the only mainstream standard libraries that come
00677 // with a TR1 tuple implementation.  NVIDIA's CUDA NVCC compiler
00678 // pretends to be GCC by defining __GNUC__ and friends, but cannot
00679 // compile GCC's tuple implementation.  MSVC 2008 (9.0) provides TR1
00680 // tuple in a 323 MB Feature Pack download, which we cannot assume the
00681 // user has.  QNX's QCC compiler is a modified GCC but it doesn't
00682 // support TR1 tuple.  libc++ only provides std::tuple, in C++11 mode,
00683 // and it can be used with some compilers that define __GNUC__.
00684 # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
00685       && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600
00686 #  define GTEST_ENV_HAS_TR1_TUPLE_ 1
00687 # endif
00688 
00689 // C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
00690 // in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
00691 // can build with clang but need to use gcc4.2's libstdc++).
00692 # if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
00693 #  define GTEST_ENV_HAS_STD_TUPLE_ 1
00694 # endif
00695 
00696 # if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
00697 #  define GTEST_USE_OWN_TR1_TUPLE 0
00698 # else
00699 #  define GTEST_USE_OWN_TR1_TUPLE 1
00700 # endif
00701 
00702 #endif  // GTEST_USE_OWN_TR1_TUPLE
00703 
00704 // To avoid conditional compilation everywhere, we make it
00705 // gtest-port.h's responsibility to #include the header implementing
00706 // tuple.
00707 #if GTEST_HAS_STD_TUPLE_
00708 # include <tuple>  // IWYU pragma: export
00709 # define GTEST_TUPLE_NAMESPACE_ ::std
00710 #endif  // GTEST_HAS_STD_TUPLE_
00711 
00712 // We include tr1::tuple even if std::tuple is available to define printers for
00713 // them.
00714 #if GTEST_HAS_TR1_TUPLE
00715 # ifndef GTEST_TUPLE_NAMESPACE_
00716 #  define GTEST_TUPLE_NAMESPACE_ ::std::tr1
00717 # endif  // GTEST_TUPLE_NAMESPACE_
00718 
00719 # if GTEST_USE_OWN_TR1_TUPLE
00720 #  include "gtest/internal/gtest-tuple.h"  // IWYU pragma: export  // NOLINT
00721 # elif GTEST_ENV_HAS_STD_TUPLE_
00722 #  include <tuple>
00723 // C++11 puts its tuple into the ::std namespace rather than
00724 // ::std::tr1.  gtest expects tuple to live in ::std::tr1, so put it there.
00725 // This causes undefined behavior, but supported compilers react in
00726 // the way we intend.
00727 namespace std {
00728 namespace tr1 {
00729 using ::std::get;
00730 using ::std::make_tuple;
00731 using ::std::tuple;
00732 using ::std::tuple_element;
00733 using ::std::tuple_size;
00734 }
00735 }
00736 
00737 # elif GTEST_OS_SYMBIAN
00738 
00739 // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
00740 // use STLport's tuple implementation, which unfortunately doesn't
00741 // work as the copy of STLport distributed with Symbian is incomplete.
00742 // By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
00743 // use its own tuple implementation.
00744 #  ifdef BOOST_HAS_TR1_TUPLE
00745 #   undef BOOST_HAS_TR1_TUPLE
00746 #  endif  // BOOST_HAS_TR1_TUPLE
00747 
00748 // This prevents <boost/tr1/detail/config.hpp>, which defines
00749 // BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
00750 #  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
00751 #  include <tuple>  // IWYU pragma: export  // NOLINT
00752 
00753 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
00754 // GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
00755 // not conform to the TR1 spec, which requires the header to be <tuple>.
00756 
00757 #  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
00758 // Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
00759 // which is #included by <tr1/tuple>, to not compile when RTTI is
00760 // disabled.  _TR1_FUNCTIONAL is the header guard for
00761 // <tr1/functional>.  Hence the following #define is a hack to prevent
00762 // <tr1/functional> from being included.
00763 #   define _TR1_FUNCTIONAL 1
00764 #   include <tr1/tuple>
00765 #   undef _TR1_FUNCTIONAL  // Allows the user to #include
00766                         // <tr1/functional> if he chooses to.
00767 #  else
00768 #   include <tr1/tuple>  // NOLINT
00769 #  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
00770 
00771 # else
00772 // If the compiler is not GCC 4.0+, we assume the user is using a
00773 // spec-conforming TR1 implementation.
00774 #  include <tuple>  // IWYU pragma: export  // NOLINT
00775 # endif  // GTEST_USE_OWN_TR1_TUPLE
00776 
00777 #endif  // GTEST_HAS_TR1_TUPLE
00778 
00779 // Determines whether clone(2) is supported.
00780 // Usually it will only be available on Linux, excluding
00781 // Linux on the Itanium architecture.
00782 // Also see http://linux.die.net/man/2/clone.
00783 #ifndef GTEST_HAS_CLONE
00784 // The user didn't tell us, so we need to figure it out.
00785 
00786 # if GTEST_OS_LINUX && !defined(__ia64__)
00787 #  if GTEST_OS_LINUX_ANDROID
00788 // On Android, clone() is only available on ARM starting with Gingerbread.
00789 #    if defined(__arm__) && __ANDROID_API__ >= 9
00790 #     define GTEST_HAS_CLONE 1
00791 #    else
00792 #     define GTEST_HAS_CLONE 0
00793 #    endif
00794 #  else
00795 #   define GTEST_HAS_CLONE 1
00796 #  endif
00797 # else
00798 #  define GTEST_HAS_CLONE 0
00799 # endif  // GTEST_OS_LINUX && !defined(__ia64__)
00800 
00801 #endif  // GTEST_HAS_CLONE
00802 
00803 // Determines whether to support stream redirection. This is used to test
00804 // output correctness and to implement death tests.
00805 #ifndef GTEST_HAS_STREAM_REDIRECTION
00806 // By default, we assume that stream redirection is supported on all
00807 // platforms except known mobile ones.
00808 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \
00809     GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
00810 #  define GTEST_HAS_STREAM_REDIRECTION 0
00811 # else
00812 #  define GTEST_HAS_STREAM_REDIRECTION 1
00813 # endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
00814 #endif  // GTEST_HAS_STREAM_REDIRECTION
00815 
00816 // Determines whether to support death tests.
00817 // Google Test does not support death tests for VC 7.1 and earlier as
00818 // abort() in a VC 7.1 application compiled as GUI in debug config
00819 // pops up a dialog window that cannot be suppressed programmatically.
00820 #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
00821      (GTEST_OS_MAC && !GTEST_OS_IOS) || \
00822      (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
00823      GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
00824      GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD)
00825 # define GTEST_HAS_DEATH_TEST 1
00826 # include <vector>  // NOLINT
00827 #endif
00828 
00829 // We don't support MSVC 7.1 with exceptions disabled now.  Therefore
00830 // all the compilers we care about are adequate for supporting
00831 // value-parameterized tests.
00832 #define GTEST_HAS_PARAM_TEST 1
00833 
00834 // Determines whether to support type-driven tests.
00835 
00836 // Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
00837 // Sun Pro CC, IBM Visual Age, and HP aCC support.
00838 #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
00839     defined(__IBMCPP__) || defined(__HP_aCC)
00840 # define GTEST_HAS_TYPED_TEST 1
00841 # define GTEST_HAS_TYPED_TEST_P 1
00842 #endif
00843 
00844 // Determines whether to support Combine(). This only makes sense when
00845 // value-parameterized tests are enabled.  The implementation doesn't
00846 // work on Sun Studio since it doesn't understand templated conversion
00847 // operators.
00848 #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
00849 # define GTEST_HAS_COMBINE 1
00850 #endif
00851 
00852 // Determines whether the system compiler uses UTF-16 for encoding wide strings.
00853 #define GTEST_WIDE_STRING_USES_UTF16_ \
00854     (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
00855 
00856 // Determines whether test results can be streamed to a socket.
00857 #if GTEST_OS_LINUX
00858 # define GTEST_CAN_STREAM_RESULTS_ 1
00859 #endif
00860 
00861 // Defines some utility macros.
00862 
00863 // The GNU compiler emits a warning if nested "if" statements are followed by
00864 // an "else" statement and braces are not used to explicitly disambiguate the
00865 // "else" binding.  This leads to problems with code like:
00866 //
00867 //   if (gate)
00868 //     ASSERT_*(condition) << "Some message";
00869 //
00870 // The "switch (0) case 0:" idiom is used to suppress this.
00871 #ifdef __INTEL_COMPILER
00872 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
00873 #else
00874 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
00875 #endif
00876 
00877 // Use this annotation at the end of a struct/class definition to
00878 // prevent the compiler from optimizing away instances that are never
00879 // used.  This is useful when all interesting logic happens inside the
00880 // c'tor and / or d'tor.  Example:
00881 //
00882 //   struct Foo {
00883 //     Foo() { ... }
00884 //   } GTEST_ATTRIBUTE_UNUSED_;
00885 //
00886 // Also use it after a variable or parameter declaration to tell the
00887 // compiler the variable/parameter does not have to be used.
00888 #if defined(__GNUC__) && !defined(COMPILER_ICC)
00889 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
00890 #elif defined(__clang__)
00891 # if __has_attribute(unused)
00892 #  define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
00893 # endif
00894 #endif
00895 #ifndef GTEST_ATTRIBUTE_UNUSED_
00896 # define GTEST_ATTRIBUTE_UNUSED_
00897 #endif
00898 
00899 // A macro to disallow operator=
00900 // This should be used in the private: declarations for a class.
00901 #define GTEST_DISALLOW_ASSIGN_(type)\
00902   void operator=(type const &)
00903 
00904 // A macro to disallow copy constructor and operator=
00905 // This should be used in the private: declarations for a class.
00906 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
00907   type(type const &);\
00908   GTEST_DISALLOW_ASSIGN_(type)
00909 
00910 // Tell the compiler to warn about unused return values for functions declared
00911 // with this macro.  The macro should be used on function declarations
00912 // following the argument list:
00913 //
00914 //   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
00915 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
00916 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
00917 #else
00918 # define GTEST_MUST_USE_RESULT_
00919 #endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
00920 
00921 // MS C++ compiler emits warning when a conditional expression is compile time
00922 // constant. In some contexts this warning is false positive and needs to be
00923 // suppressed. Use the following two macros in such cases:
00924 //
00925 // GTEST_INTENTIONAL_CONST_COND_PUSH_()
00926 // while (true) {
00927 // GTEST_INTENTIONAL_CONST_COND_POP_()
00928 // }
00929 # define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
00930     GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
00931 # define GTEST_INTENTIONAL_CONST_COND_POP_() \
00932     GTEST_DISABLE_MSC_WARNINGS_POP_()
00933 
00934 // Determine whether the compiler supports Microsoft's Structured Exception
00935 // Handling.  This is supported by several Windows compilers but generally
00936 // does not exist on any other system.
00937 #ifndef GTEST_HAS_SEH
00938 // The user didn't tell us, so we need to figure it out.
00939 
00940 # if defined(_MSC_VER) || defined(__BORLANDC__)
00941 // These two compilers are known to support SEH.
00942 #  define GTEST_HAS_SEH 1
00943 # else
00944 // Assume no SEH.
00945 #  define GTEST_HAS_SEH 0
00946 # endif
00947 
00948 #define GTEST_IS_THREADSAFE \
00949     (0 \
00950      || (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) \
00951      || GTEST_HAS_PTHREAD)
00952 
00953 #endif  // GTEST_HAS_SEH
00954 
00955 #ifdef _MSC_VER
00956 
00957 # if GTEST_LINKED_AS_SHARED_LIBRARY
00958 #  define GTEST_API_ __declspec(dllimport)
00959 # elif GTEST_CREATE_SHARED_LIBRARY
00960 #  define GTEST_API_ __declspec(dllexport)
00961 # endif
00962 
00963 #endif  // _MSC_VER
00964 
00965 #ifndef GTEST_API_
00966 # define GTEST_API_
00967 #endif
00968 
00969 #ifdef __GNUC__
00970 // Ask the compiler to never inline a given function.
00971 # define GTEST_NO_INLINE_ __attribute__((noinline))
00972 #else
00973 # define GTEST_NO_INLINE_
00974 #endif
00975 
00976 // _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
00977 #if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
00978 # define GTEST_HAS_CXXABI_H_ 1
00979 #else
00980 # define GTEST_HAS_CXXABI_H_ 0
00981 #endif
00982 
00983 // A function level attribute to disable checking for use of uninitialized
00984 // memory when built with MemorySanitizer.
00985 #if defined(__clang__)
00986 # if __has_feature(memory_sanitizer)
00987 #  define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
00988        __attribute__((no_sanitize_memory))
00989 # else
00990 #  define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
00991 # endif  // __has_feature(memory_sanitizer)
00992 #else
00993 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
00994 #endif  // __clang__
00995 
00996 // A function level attribute to disable AddressSanitizer instrumentation.
00997 #if defined(__clang__)
00998 # if __has_feature(address_sanitizer)
00999 #  define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
01000        __attribute__((no_sanitize_address))
01001 # else
01002 #  define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
01003 # endif  // __has_feature(address_sanitizer)
01004 #else
01005 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
01006 #endif  // __clang__
01007 
01008 // A function level attribute to disable ThreadSanitizer instrumentation.
01009 #if defined(__clang__)
01010 # if __has_feature(thread_sanitizer)
01011 #  define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
01012        __attribute__((no_sanitize_thread))
01013 # else
01014 #  define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
01015 # endif  // __has_feature(thread_sanitizer)
01016 #else
01017 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
01018 #endif  // __clang__
01019 
01020 namespace testing {
01021 
01022 class Message;
01023 
01024 #if defined(GTEST_TUPLE_NAMESPACE_)
01025 // Import tuple and friends into the ::testing namespace.
01026 // It is part of our interface, having them in ::testing allows us to change
01027 // their types as needed.
01028 using GTEST_TUPLE_NAMESPACE_::get;
01029 using GTEST_TUPLE_NAMESPACE_::make_tuple;
01030 using GTEST_TUPLE_NAMESPACE_::tuple;
01031 using GTEST_TUPLE_NAMESPACE_::tuple_size;
01032 using GTEST_TUPLE_NAMESPACE_::tuple_element;
01033 #endif  // defined(GTEST_TUPLE_NAMESPACE_)
01034 
01035 namespace internal {
01036 
01037 // A secret type that Google Test users don't know about.  It has no
01038 // definition on purpose.  Therefore it's impossible to create a
01039 // Secret object, which is what we want.
01040 class Secret;
01041 
01042 // The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
01043 // expression is true. For example, you could use it to verify the
01044 // size of a static array:
01045 //
01046 //   GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
01047 //                         names_incorrect_size);
01048 //
01049 // or to make sure a struct is smaller than a certain size:
01050 //
01051 //   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
01052 //
01053 // The second argument to the macro is the name of the variable. If
01054 // the expression is false, most compilers will issue a warning/error
01055 // containing the name of the variable.
01056 
01057 #if GTEST_LANG_CXX11
01058 # define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
01059 #else  // !GTEST_LANG_CXX11
01060 template <bool>
01061   struct CompileAssert {
01062 };
01063 
01064 # define GTEST_COMPILE_ASSERT_(expr, msg) \
01065   typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
01066       msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
01067 #endif  // !GTEST_LANG_CXX11
01068 
01069 // Implementation details of GTEST_COMPILE_ASSERT_:
01070 //
01071 // (In C++11, we simply use static_assert instead of the following)
01072 //
01073 // - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
01074 //   elements (and thus is invalid) when the expression is false.
01075 //
01076 // - The simpler definition
01077 //
01078 //    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
01079 //
01080 //   does not work, as gcc supports variable-length arrays whose sizes
01081 //   are determined at run-time (this is gcc's extension and not part
01082 //   of the C++ standard).  As a result, gcc fails to reject the
01083 //   following code with the simple definition:
01084 //
01085 //     int foo;
01086 //     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
01087 //                                      // not a compile-time constant.
01088 //
01089 // - By using the type CompileAssert<(bool(expr))>, we ensures that
01090 //   expr is a compile-time constant.  (Template arguments must be
01091 //   determined at compile-time.)
01092 //
01093 // - The outter parentheses in CompileAssert<(bool(expr))> are necessary
01094 //   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
01095 //
01096 //     CompileAssert<bool(expr)>
01097 //
01098 //   instead, these compilers will refuse to compile
01099 //
01100 //     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
01101 //
01102 //   (They seem to think the ">" in "5 > 0" marks the end of the
01103 //   template argument list.)
01104 //
01105 // - The array size is (bool(expr) ? 1 : -1), instead of simply
01106 //
01107 //     ((expr) ? 1 : -1).
01108 //
01109 //   This is to avoid running into a bug in MS VC 7.1, which
01110 //   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
01111 
01112 // StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
01113 //
01114 // This template is declared, but intentionally undefined.
01115 template <typename T1, typename T2>
01116 struct StaticAssertTypeEqHelper;
01117 
01118 template <typename T>
01119 struct StaticAssertTypeEqHelper<T, T> {
01120   enum { value = true };
01121 };
01122 
01123 // Evaluates to the number of elements in 'array'.
01124 #define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
01125 
01126 #if GTEST_HAS_GLOBAL_STRING
01127 typedef ::string string;
01128 #else
01129 typedef ::std::string string;
01130 #endif  // GTEST_HAS_GLOBAL_STRING
01131 
01132 #if GTEST_HAS_GLOBAL_WSTRING
01133 typedef ::wstring wstring;
01134 #elif GTEST_HAS_STD_WSTRING
01135 typedef ::std::wstring wstring;
01136 #endif  // GTEST_HAS_GLOBAL_WSTRING
01137 
01138 // A helper for suppressing warnings on constant condition.  It just
01139 // returns 'condition'.
01140 GTEST_API_ bool IsTrue(bool condition);
01141 
01142 // Defines scoped_ptr.
01143 
01144 // This implementation of scoped_ptr is PARTIAL - it only contains
01145 // enough stuff to satisfy Google Test's need.
01146 template <typename T>
01147 class scoped_ptr {
01148  public:
01149   typedef T element_type;
01150 
01151   explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
01152   ~scoped_ptr() { reset(); }
01153 
01154   T& operator*() const { return *ptr_; }
01155   T* operator->() const { return ptr_; }
01156   T* get() const { return ptr_; }
01157 
01158   T* release() {
01159     T* const ptr = ptr_;
01160     ptr_ = NULL;
01161     return ptr;
01162   }
01163 
01164   void reset(T* p = NULL) {
01165     if (p != ptr_) {
01166       if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
01167         delete ptr_;
01168       }
01169       ptr_ = p;
01170     }
01171   }
01172 
01173   friend void swap(scoped_ptr& a, scoped_ptr& b) {
01174     using std::swap;
01175     swap(a.ptr_, b.ptr_);
01176   }
01177 
01178  private:
01179   T* ptr_;
01180 
01181   GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
01182 };
01183 
01184 // Defines RE.
01185 
01186 // A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
01187 // Regular Expression syntax.
01188 class GTEST_API_ RE {
01189  public:
01190   // A copy constructor is required by the Standard to initialize object
01191   // references from r-values.
01192   RE(const RE& other) { Init(other.pattern()); }
01193 
01194   // Constructs an RE from a string.
01195   RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
01196 
01197 #if GTEST_HAS_GLOBAL_STRING
01198 
01199   RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
01200 
01201 #endif  // GTEST_HAS_GLOBAL_STRING
01202 
01203   RE(const char* regex) { Init(regex); }  // NOLINT
01204   ~RE();
01205 
01206   // Returns the string representation of the regex.
01207   const char* pattern() const { return pattern_; }
01208 
01209   // FullMatch(str, re) returns true iff regular expression re matches
01210   // the entire str.
01211   // PartialMatch(str, re) returns true iff regular expression re
01212   // matches a substring of str (including str itself).
01213   //
01214   // TODO(wan@google.com): make FullMatch() and PartialMatch() work
01215   // when str contains NUL characters.
01216   static bool FullMatch(const ::std::string& str, const RE& re) {
01217     return FullMatch(str.c_str(), re);
01218   }
01219   static bool PartialMatch(const ::std::string& str, const RE& re) {
01220     return PartialMatch(str.c_str(), re);
01221   }
01222 
01223 #if GTEST_HAS_GLOBAL_STRING
01224 
01225   static bool FullMatch(const ::string& str, const RE& re) {
01226     return FullMatch(str.c_str(), re);
01227   }
01228   static bool PartialMatch(const ::string& str, const RE& re) {
01229     return PartialMatch(str.c_str(), re);
01230   }
01231 
01232 #endif  // GTEST_HAS_GLOBAL_STRING
01233 
01234   static bool FullMatch(const char* str, const RE& re);
01235   static bool PartialMatch(const char* str, const RE& re);
01236 
01237  private:
01238   void Init(const char* regex);
01239 
01240   // We use a const char* instead of an std::string, as Google Test used to be
01241   // used where std::string is not available.  TODO(wan@google.com): change to
01242   // std::string.
01243   const char* pattern_;
01244   bool is_valid_;
01245 
01246 #if GTEST_USES_POSIX_RE
01247 
01248   regex_t full_regex_;     // For FullMatch().
01249   regex_t partial_regex_;  // For PartialMatch().
01250 
01251 #else  // GTEST_USES_SIMPLE_RE
01252 
01253   const char* full_pattern_;  // For FullMatch();
01254 
01255 #endif
01256 
01257   GTEST_DISALLOW_ASSIGN_(RE);
01258 };
01259 
01260 // Formats a source file path and a line number as they would appear
01261 // in an error message from the compiler used to compile this code.
01262 GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
01263 
01264 // Formats a file location for compiler-independent XML output.
01265 // Although this function is not platform dependent, we put it next to
01266 // FormatFileLocation in order to contrast the two functions.
01267 GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
01268                                                                int line);
01269 
01270 // Defines logging utilities:
01271 //   GTEST_LOG_(severity) - logs messages at the specified severity level. The
01272 //                          message itself is streamed into the macro.
01273 //   LogToStderr()  - directs all log messages to stderr.
01274 //   FlushInfoLog() - flushes informational log messages.
01275 
01276 enum GTestLogSeverity {
01277   GTEST_INFO,
01278   GTEST_WARNING,
01279   GTEST_ERROR,
01280   GTEST_FATAL
01281 };
01282 
01283 // Formats log entry severity, provides a stream object for streaming the
01284 // log message, and terminates the message with a newline when going out of
01285 // scope.
01286 class GTEST_API_ GTestLog {
01287  public:
01288   GTestLog(GTestLogSeverity severity, const char* file, int line);
01289 
01290   // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
01291   ~GTestLog();
01292 
01293   ::std::ostream& GetStream() { return ::std::cerr; }
01294 
01295  private:
01296   const GTestLogSeverity severity_;
01297 
01298   GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
01299 };
01300 
01301 #define GTEST_LOG_(severity) \
01302     ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
01303                                   __FILE__, __LINE__).GetStream()
01304 
01305 inline void LogToStderr() {}
01306 inline void FlushInfoLog() { fflush(NULL); }
01307 
01308 // INTERNAL IMPLEMENTATION - DO NOT USE.
01309 //
01310 // GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
01311 // is not satisfied.
01312 //  Synopsys:
01313 //    GTEST_CHECK_(boolean_condition);
01314 //     or
01315 //    GTEST_CHECK_(boolean_condition) << "Additional message";
01316 //
01317 //    This checks the condition and if the condition is not satisfied
01318 //    it prints message about the condition violation, including the
01319 //    condition itself, plus additional message streamed into it, if any,
01320 //    and then it aborts the program. It aborts the program irrespective of
01321 //    whether it is built in the debug mode or not.
01322 #define GTEST_CHECK_(condition) \
01323     GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01324     if (::testing::internal::IsTrue(condition)) \
01325       ; \
01326     else \
01327       GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
01328 
01329 // An all-mode assert to verify that the given POSIX-style function
01330 // call returns 0 (indicating success).  Known limitation: this
01331 // doesn't expand to a balanced 'if' statement, so enclose the macro
01332 // in {} if you need to use it as the only statement in an 'if'
01333 // branch.
01334 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
01335   if (const int gtest_error = (posix_call)) \
01336     GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
01337                       << gtest_error
01338 
01339 #if GTEST_HAS_STD_MOVE_
01340 using std::move;
01341 #else  // GTEST_HAS_STD_MOVE_
01342 template <typename T>
01343 const T& move(const T& t) {
01344   return t;
01345 }
01346 #endif  // GTEST_HAS_STD_MOVE_
01347 
01348 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
01349 //
01350 // Use ImplicitCast_ as a safe version of static_cast for upcasting in
01351 // the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
01352 // const Foo*).  When you use ImplicitCast_, the compiler checks that
01353 // the cast is safe.  Such explicit ImplicitCast_s are necessary in
01354 // surprisingly many situations where C++ demands an exact type match
01355 // instead of an argument type convertable to a target type.
01356 //
01357 // The syntax for using ImplicitCast_ is the same as for static_cast:
01358 //
01359 //   ImplicitCast_<ToType>(expr)
01360 //
01361 // ImplicitCast_ would have been part of the C++ standard library,
01362 // but the proposal was submitted too late.  It will probably make
01363 // its way into the language in the future.
01364 //
01365 // This relatively ugly name is intentional. It prevents clashes with
01366 // similar functions users may have (e.g., implicit_cast). The internal
01367 // namespace alone is not enough because the function can be found by ADL.
01368 template<typename To>
01369 inline To ImplicitCast_(To x) { return ::testing::internal::move(x); }
01370 
01371 // When you upcast (that is, cast a pointer from type Foo to type
01372 // SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
01373 // always succeed.  When you downcast (that is, cast a pointer from
01374 // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
01375 // how do you know the pointer is really of type SubclassOfFoo?  It
01376 // could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
01377 // when you downcast, you should use this macro.  In debug mode, we
01378 // use dynamic_cast<> to double-check the downcast is legal (we die
01379 // if it's not).  In normal mode, we do the efficient static_cast<>
01380 // instead.  Thus, it's important to test in debug mode to make sure
01381 // the cast is legal!
01382 //    This is the only place in the code we should use dynamic_cast<>.
01383 // In particular, you SHOULDN'T be using dynamic_cast<> in order to
01384 // do RTTI (eg code like this:
01385 //    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
01386 //    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
01387 // You should design the code some other way not to need this.
01388 //
01389 // This relatively ugly name is intentional. It prevents clashes with
01390 // similar functions users may have (e.g., down_cast). The internal
01391 // namespace alone is not enough because the function can be found by ADL.
01392 template<typename To, typename From>  // use like this: DownCast_<T*>(foo);
01393 inline To DownCast_(From* f) {  // so we only accept pointers
01394   // Ensures that To is a sub-type of From *.  This test is here only
01395   // for compile-time type checking, and has no overhead in an
01396   // optimized build at run-time, as it will be optimized away
01397   // completely.
01398   GTEST_INTENTIONAL_CONST_COND_PUSH_()
01399   if (false) {
01400   GTEST_INTENTIONAL_CONST_COND_POP_()
01401     const To to = NULL;
01402     ::testing::internal::ImplicitCast_<From*>(to);
01403   }
01404 
01405 #if GTEST_HAS_RTTI
01406   // RTTI: debug mode only!
01407   GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
01408 #endif
01409   return static_cast<To>(f);
01410 }
01411 
01412 // Downcasts the pointer of type Base to Derived.
01413 // Derived must be a subclass of Base. The parameter MUST
01414 // point to a class of type Derived, not any subclass of it.
01415 // When RTTI is available, the function performs a runtime
01416 // check to enforce this.
01417 template <class Derived, class Base>
01418 Derived* CheckedDowncastToActualType(Base* base) {
01419 #if GTEST_HAS_RTTI
01420   GTEST_CHECK_(typeid(*base) == typeid(Derived));
01421   return dynamic_cast<Derived*>(base);  // NOLINT
01422 #else
01423   return static_cast<Derived*>(base);  // Poor man's downcast.
01424 #endif
01425 }
01426 
01427 #if GTEST_HAS_STREAM_REDIRECTION
01428 
01429 // Defines the stderr capturer:
01430 //   CaptureStdout     - starts capturing stdout.
01431 //   GetCapturedStdout - stops capturing stdout and returns the captured string.
01432 //   CaptureStderr     - starts capturing stderr.
01433 //   GetCapturedStderr - stops capturing stderr and returns the captured string.
01434 //
01435 GTEST_API_ void CaptureStdout();
01436 GTEST_API_ std::string GetCapturedStdout();
01437 GTEST_API_ void CaptureStderr();
01438 GTEST_API_ std::string GetCapturedStderr();
01439 
01440 #endif  // GTEST_HAS_STREAM_REDIRECTION
01441 
01442 
01443 #if GTEST_HAS_DEATH_TEST
01444 
01445 const ::std::vector<testing::internal::string>& GetInjectableArgvs();
01446 void SetInjectableArgvs(const ::std::vector<testing::internal::string>*
01447                              new_argvs);
01448 
01449 // A copy of all command line arguments.  Set by InitGoogleTest().
01450 extern ::std::vector<testing::internal::string> g_argvs;
01451 
01452 #endif  // GTEST_HAS_DEATH_TEST
01453 
01454 // Defines synchronization primitives.
01455 #if GTEST_IS_THREADSAFE
01456 # if GTEST_HAS_PTHREAD
01457 // Sleeps for (roughly) n milliseconds.  This function is only for testing
01458 // Google Test's own constructs.  Don't use it in user tests, either
01459 // directly or indirectly.
01460 inline void SleepMilliseconds(int n) {
01461   const timespec time = {
01462     0,                  // 0 seconds.
01463     n * 1000L * 1000L,  // And n ms.
01464   };
01465   nanosleep(&time, NULL);
01466 }
01467 # endif  // GTEST_HAS_PTHREAD
01468 
01469 # if 0  // OS detection
01470 # elif GTEST_HAS_PTHREAD
01471 // Allows a controller thread to pause execution of newly created
01472 // threads until notified.  Instances of this class must be created
01473 // and destroyed in the controller thread.
01474 //
01475 // This class is only for testing Google Test's own constructs. Do not
01476 // use it in user tests, either directly or indirectly.
01477 class Notification {
01478  public:
01479   Notification() : notified_(false) {
01480     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
01481   }
01482   ~Notification() {
01483     pthread_mutex_destroy(&mutex_);
01484   }
01485 
01486   // Notifies all threads created with this notification to start. Must
01487   // be called from the controller thread.
01488   void Notify() {
01489     pthread_mutex_lock(&mutex_);
01490     notified_ = true;
01491     pthread_mutex_unlock(&mutex_);
01492   }
01493 
01494   // Blocks until the controller thread notifies. Must be called from a test
01495   // thread.
01496   void WaitForNotification() {
01497     for (;;) {
01498       pthread_mutex_lock(&mutex_);
01499       const bool notified = notified_;
01500       pthread_mutex_unlock(&mutex_);
01501       if (notified)
01502         break;
01503       SleepMilliseconds(10);
01504     }
01505   }
01506 
01507  private:
01508   pthread_mutex_t mutex_;
01509   bool notified_;
01510 
01511   GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
01512 };
01513 
01514 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
01515 
01516 GTEST_API_ void SleepMilliseconds(int n);
01517 
01518 // Provides leak-safe Windows kernel handle ownership.
01519 // Used in death tests and in threading support.
01520 class GTEST_API_ AutoHandle {
01521  public:
01522   // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
01523   // avoid including <windows.h> in this header file. Including <windows.h> is
01524   // undesirable because it defines a lot of symbols and macros that tend to
01525   // conflict with client code. This assumption is verified by
01526   // WindowsTypesTest.HANDLEIsVoidStar.
01527   typedef void* Handle;
01528   AutoHandle();
01529   explicit AutoHandle(Handle handle);
01530 
01531   ~AutoHandle();
01532 
01533   Handle Get() const;
01534   void Reset();
01535   void Reset(Handle handle);
01536 
01537  private:
01538   // Returns true iff the handle is a valid handle object that can be closed.
01539   bool IsCloseable() const;
01540 
01541   Handle handle_;
01542 
01543   GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
01544 };
01545 
01546 // Allows a controller thread to pause execution of newly created
01547 // threads until notified.  Instances of this class must be created
01548 // and destroyed in the controller thread.
01549 //
01550 // This class is only for testing Google Test's own constructs. Do not
01551 // use it in user tests, either directly or indirectly.
01552 class GTEST_API_ Notification {
01553  public:
01554   Notification();
01555   void Notify();
01556   void WaitForNotification();
01557 
01558  private:
01559   AutoHandle event_;
01560 
01561   GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
01562 };
01563 # endif  // OS detection
01564 
01565 // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
01566 // defined, but we don't want to use MinGW's pthreads implementation, which
01567 // has conformance problems with some versions of the POSIX standard.
01568 # if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
01569 
01570 // As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
01571 // Consequently, it cannot select a correct instantiation of ThreadWithParam
01572 // in order to call its Run(). Introducing ThreadWithParamBase as a
01573 // non-templated base class for ThreadWithParam allows us to bypass this
01574 // problem.
01575 class ThreadWithParamBase {
01576  public:
01577   virtual ~ThreadWithParamBase() {}
01578   virtual void Run() = 0;
01579 };
01580 
01581 // pthread_create() accepts a pointer to a function type with the C linkage.
01582 // According to the Standard (7.5/1), function types with different linkages
01583 // are different even if they are otherwise identical.  Some compilers (for
01584 // example, SunStudio) treat them as different types.  Since class methods
01585 // cannot be defined with C-linkage we need to define a free C-function to
01586 // pass into pthread_create().
01587 extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
01588   static_cast<ThreadWithParamBase*>(thread)->Run();
01589   return NULL;
01590 }
01591 
01592 // Helper class for testing Google Test's multi-threading constructs.
01593 // To use it, write:
01594 //
01595 //   void ThreadFunc(int param) { /* Do things with param */ }
01596 //   Notification thread_can_start;
01597 //   ...
01598 //   // The thread_can_start parameter is optional; you can supply NULL.
01599 //   ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
01600 //   thread_can_start.Notify();
01601 //
01602 // These classes are only for testing Google Test's own constructs. Do
01603 // not use them in user tests, either directly or indirectly.
01604 template <typename T>
01605 class ThreadWithParam : public ThreadWithParamBase {
01606  public:
01607   typedef void UserThreadFunc(T);
01608 
01609   ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
01610       : func_(func),
01611         param_(param),
01612         thread_can_start_(thread_can_start),
01613         finished_(false) {
01614     ThreadWithParamBase* const base = this;
01615     // The thread can be created only after all fields except thread_
01616     // have been initialized.
01617     GTEST_CHECK_POSIX_SUCCESS_(
01618         pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
01619   }
01620   ~ThreadWithParam() { Join(); }
01621 
01622   void Join() {
01623     if (!finished_) {
01624       GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
01625       finished_ = true;
01626     }
01627   }
01628 
01629   virtual void Run() {
01630     if (thread_can_start_ != NULL)
01631       thread_can_start_->WaitForNotification();
01632     func_(param_);
01633   }
01634 
01635  private:
01636   UserThreadFunc* const func_;  // User-supplied thread function.
01637   const T param_;  // User-supplied parameter to the thread function.
01638   // When non-NULL, used to block execution until the controller thread
01639   // notifies.
01640   Notification* const thread_can_start_;
01641   bool finished_;  // true iff we know that the thread function has finished.
01642   pthread_t thread_;  // The native thread object.
01643 
01644   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
01645 };
01646 # endif  // GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
01647 
01648 # if 0  // OS detection
01649 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
01650 
01651 // Mutex implements mutex on Windows platforms.  It is used in conjunction
01652 // with class MutexLock:
01653 //
01654 //   Mutex mutex;
01655 //   ...
01656 //   MutexLock lock(&mutex);  // Acquires the mutex and releases it at the
01657 //                            // end of the current scope.
01658 //
01659 // A static Mutex *must* be defined or declared using one of the following
01660 // macros:
01661 //   GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
01662 //   GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
01663 //
01664 // (A non-static Mutex is defined/declared in the usual way).
01665 class GTEST_API_ Mutex {
01666  public:
01667   enum MutexType { kStatic = 0, kDynamic = 1 };
01668   // We rely on kStaticMutex being 0 as it is to what the linker initializes
01669   // type_ in static mutexes.  critical_section_ will be initialized lazily
01670   // in ThreadSafeLazyInit().
01671   enum StaticConstructorSelector { kStaticMutex = 0 };
01672 
01673   // This constructor intentionally does nothing.  It relies on type_ being
01674   // statically initialized to 0 (effectively setting it to kStatic) and on
01675   // ThreadSafeLazyInit() to lazily initialize the rest of the members.
01676   explicit Mutex(StaticConstructorSelector /*dummy*/) {}
01677 
01678   Mutex();
01679   ~Mutex();
01680 
01681   void Lock();
01682 
01683   void Unlock();
01684 
01685   // Does nothing if the current thread holds the mutex. Otherwise, crashes
01686   // with high probability.
01687   void AssertHeld();
01688 
01689  private:
01690   // Initializes owner_thread_id_ and critical_section_ in static mutexes.
01691   void ThreadSafeLazyInit();
01692 
01693   // Per http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx,
01694   // we assume that 0 is an invalid value for thread IDs.
01695   unsigned int owner_thread_id_;
01696 
01697   // For static mutexes, we rely on these members being initialized to zeros
01698   // by the linker.
01699   MutexType type_;
01700   long critical_section_init_phase_;  // NOLINT
01701   _RTL_CRITICAL_SECTION* critical_section_;
01702 
01703   GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
01704 };
01705 
01706 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
01707     extern ::testing::internal::Mutex mutex
01708 
01709 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
01710     ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
01711 
01712 // We cannot name this class MutexLock because the ctor declaration would
01713 // conflict with a macro named MutexLock, which is defined on some
01714 // platforms. That macro is used as a defensive measure to prevent against
01715 // inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
01716 // "MutexLock l(&mu)".  Hence the typedef trick below.
01717 class GTestMutexLock {
01718  public:
01719   explicit GTestMutexLock(Mutex* mutex)
01720       : mutex_(mutex) { mutex_->Lock(); }
01721 
01722   ~GTestMutexLock() { mutex_->Unlock(); }
01723 
01724  private:
01725   Mutex* const mutex_;
01726 
01727   GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
01728 };
01729 
01730 typedef GTestMutexLock MutexLock;
01731 
01732 // Base class for ValueHolder<T>.  Allows a caller to hold and delete a value
01733 // without knowing its type.
01734 class ThreadLocalValueHolderBase {
01735  public:
01736   virtual ~ThreadLocalValueHolderBase() {}
01737 };
01738 
01739 // Provides a way for a thread to send notifications to a ThreadLocal
01740 // regardless of its parameter type.
01741 class ThreadLocalBase {
01742  public:
01743   // Creates a new ValueHolder<T> object holding a default value passed to
01744   // this ThreadLocal<T>'s constructor and returns it.  It is the caller's
01745   // responsibility not to call this when the ThreadLocal<T> instance already
01746   // has a value on the current thread.
01747   virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
01748 
01749  protected:
01750   ThreadLocalBase() {}
01751   virtual ~ThreadLocalBase() {}
01752 
01753  private:
01754   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase);
01755 };
01756 
01757 // Maps a thread to a set of ThreadLocals that have values instantiated on that
01758 // thread and notifies them when the thread exits.  A ThreadLocal instance is
01759 // expected to persist until all threads it has values on have terminated.
01760 class GTEST_API_ ThreadLocalRegistry {
01761  public:
01762   // Registers thread_local_instance as having value on the current thread.
01763   // Returns a value that can be used to identify the thread from other threads.
01764   static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
01765       const ThreadLocalBase* thread_local_instance);
01766 
01767   // Invoked when a ThreadLocal instance is destroyed.
01768   static void OnThreadLocalDestroyed(
01769       const ThreadLocalBase* thread_local_instance);
01770 };
01771 
01772 class GTEST_API_ ThreadWithParamBase {
01773  public:
01774   void Join();
01775 
01776  protected:
01777   class Runnable {
01778    public:
01779     virtual ~Runnable() {}
01780     virtual void Run() = 0;
01781   };
01782 
01783   ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
01784   virtual ~ThreadWithParamBase();
01785 
01786  private:
01787   AutoHandle thread_;
01788 };
01789 
01790 // Helper class for testing Google Test's multi-threading constructs.
01791 template <typename T>
01792 class ThreadWithParam : public ThreadWithParamBase {
01793  public:
01794   typedef void UserThreadFunc(T);
01795 
01796   ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
01797       : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {
01798   }
01799   virtual ~ThreadWithParam() {}
01800 
01801  private:
01802   class RunnableImpl : public Runnable {
01803    public:
01804     RunnableImpl(UserThreadFunc* func, T param)
01805         : func_(func),
01806           param_(param) {
01807     }
01808     virtual ~RunnableImpl() {}
01809     virtual void Run() {
01810       func_(param_);
01811     }
01812 
01813    private:
01814     UserThreadFunc* const func_;
01815     const T param_;
01816 
01817     GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl);
01818   };
01819 
01820   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
01821 };
01822 
01823 // Implements thread-local storage on Windows systems.
01824 //
01825 //   // Thread 1
01826 //   ThreadLocal<int> tl(100);  // 100 is the default value for each thread.
01827 //
01828 //   // Thread 2
01829 //   tl.set(150);  // Changes the value for thread 2 only.
01830 //   EXPECT_EQ(150, tl.get());
01831 //
01832 //   // Thread 1
01833 //   EXPECT_EQ(100, tl.get());  // In thread 1, tl has the original value.
01834 //   tl.set(200);
01835 //   EXPECT_EQ(200, tl.get());
01836 //
01837 // The template type argument T must have a public copy constructor.
01838 // In addition, the default ThreadLocal constructor requires T to have
01839 // a public default constructor.
01840 //
01841 // The users of a TheadLocal instance have to make sure that all but one
01842 // threads (including the main one) using that instance have exited before
01843 // destroying it. Otherwise, the per-thread objects managed for them by the
01844 // ThreadLocal instance are not guaranteed to be destroyed on all platforms.
01845 //
01846 // Google Test only uses global ThreadLocal objects.  That means they
01847 // will die after main() has returned.  Therefore, no per-thread
01848 // object managed by Google Test will be leaked as long as all threads
01849 // using Google Test have exited when main() returns.
01850 template <typename T>
01851 class ThreadLocal : public ThreadLocalBase {
01852  public:
01853   ThreadLocal() : default_() {}
01854   explicit ThreadLocal(const T& value) : default_(value) {}
01855 
01856   ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); }
01857 
01858   T* pointer() { return GetOrCreateValue(); }
01859   const T* pointer() const { return GetOrCreateValue(); }
01860   const T& get() const { return *pointer(); }
01861   void set(const T& value) { *pointer() = value; }
01862 
01863  private:
01864   // Holds a value of T.  Can be deleted via its base class without the caller
01865   // knowing the type of T.
01866   class ValueHolder : public ThreadLocalValueHolderBase {
01867    public:
01868     explicit ValueHolder(const T& value) : value_(value) {}
01869 
01870     T* pointer() { return &value_; }
01871 
01872    private:
01873     T value_;
01874     GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
01875   };
01876 
01877 
01878   T* GetOrCreateValue() const {
01879     return static_cast<ValueHolder*>(
01880         ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer();
01881   }
01882 
01883   virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const {
01884     return new ValueHolder(default_);
01885   }
01886 
01887   const T default_;  // The default value for each thread.
01888 
01889   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
01890 };
01891 
01892 # elif GTEST_HAS_PTHREAD
01893 
01894 // MutexBase and Mutex implement mutex on pthreads-based platforms.
01895 class MutexBase {
01896  public:
01897   // Acquires this mutex.
01898   void Lock() {
01899     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
01900     owner_ = pthread_self();
01901     has_owner_ = true;
01902   }
01903 
01904   // Releases this mutex.
01905   void Unlock() {
01906     // Since the lock is being released the owner_ field should no longer be
01907     // considered valid. We don't protect writing to has_owner_ here, as it's
01908     // the caller's responsibility to ensure that the current thread holds the
01909     // mutex when this is called.
01910     has_owner_ = false;
01911     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
01912   }
01913 
01914   // Does nothing if the current thread holds the mutex. Otherwise, crashes
01915   // with high probability.
01916   void AssertHeld() const {
01917     GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
01918         << "The current thread is not holding the mutex @" << this;
01919   }
01920 
01921   // A static mutex may be used before main() is entered.  It may even
01922   // be used before the dynamic initialization stage.  Therefore we
01923   // must be able to initialize a static mutex object at link time.
01924   // This means MutexBase has to be a POD and its member variables
01925   // have to be public.
01926  public:
01927   pthread_mutex_t mutex_;  // The underlying pthread mutex.
01928   // has_owner_ indicates whether the owner_ field below contains a valid thread
01929   // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
01930   // accesses to the owner_ field should be protected by a check of this field.
01931   // An alternative might be to memset() owner_ to all zeros, but there's no
01932   // guarantee that a zero'd pthread_t is necessarily invalid or even different
01933   // from pthread_self().
01934   bool has_owner_;
01935   pthread_t owner_;  // The thread holding the mutex.
01936 };
01937 
01938 // Forward-declares a static mutex.
01939 #  define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
01940      extern ::testing::internal::MutexBase mutex
01941 
01942 // Defines and statically (i.e. at link time) initializes a static mutex.
01943 // The initialization list here does not explicitly initialize each field,
01944 // instead relying on default initialization for the unspecified fields. In
01945 // particular, the owner_ field (a pthread_t) is not explicitly initialized.
01946 // This allows initialization to work whether pthread_t is a scalar or struct.
01947 // The flag -Wmissing-field-initializers must not be specified for this to work.
01948 #  define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
01949      ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
01950 
01951 // The Mutex class can only be used for mutexes created at runtime. It
01952 // shares its API with MutexBase otherwise.
01953 class Mutex : public MutexBase {
01954  public:
01955   Mutex() {
01956     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
01957     has_owner_ = false;
01958   }
01959   ~Mutex() {
01960     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
01961   }
01962 
01963  private:
01964   GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
01965 };
01966 
01967 // We cannot name this class MutexLock because the ctor declaration would
01968 // conflict with a macro named MutexLock, which is defined on some
01969 // platforms. That macro is used as a defensive measure to prevent against
01970 // inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
01971 // "MutexLock l(&mu)".  Hence the typedef trick below.
01972 class GTestMutexLock {
01973  public:
01974   explicit GTestMutexLock(MutexBase* mutex)
01975       : mutex_(mutex) { mutex_->Lock(); }
01976 
01977   ~GTestMutexLock() { mutex_->Unlock(); }
01978 
01979  private:
01980   MutexBase* const mutex_;
01981 
01982   GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
01983 };
01984 
01985 typedef GTestMutexLock MutexLock;
01986 
01987 // Helpers for ThreadLocal.
01988 
01989 // pthread_key_create() requires DeleteThreadLocalValue() to have
01990 // C-linkage.  Therefore it cannot be templatized to access
01991 // ThreadLocal<T>.  Hence the need for class
01992 // ThreadLocalValueHolderBase.
01993 class ThreadLocalValueHolderBase {
01994  public:
01995   virtual ~ThreadLocalValueHolderBase() {}
01996 };
01997 
01998 // Called by pthread to delete thread-local data stored by
01999 // pthread_setspecific().
02000 extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
02001   delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
02002 }
02003 
02004 // Implements thread-local storage on pthreads-based systems.
02005 template <typename T>
02006 class ThreadLocal {
02007  public:
02008   ThreadLocal() : key_(CreateKey()),
02009                   default_() {}
02010   explicit ThreadLocal(const T& value) : key_(CreateKey()),
02011                                          default_(value) {}
02012 
02013   ~ThreadLocal() {
02014     // Destroys the managed object for the current thread, if any.
02015     DeleteThreadLocalValue(pthread_getspecific(key_));
02016 
02017     // Releases resources associated with the key.  This will *not*
02018     // delete managed objects for other threads.
02019     GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
02020   }
02021 
02022   T* pointer() { return GetOrCreateValue(); }
02023   const T* pointer() const { return GetOrCreateValue(); }
02024   const T& get() const { return *pointer(); }
02025   void set(const T& value) { *pointer() = value; }
02026 
02027  private:
02028   // Holds a value of type T.
02029   class ValueHolder : public ThreadLocalValueHolderBase {
02030    public:
02031     explicit ValueHolder(const T& value) : value_(value) {}
02032 
02033     T* pointer() { return &value_; }
02034 
02035    private:
02036     T value_;
02037     GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
02038   };
02039 
02040   static pthread_key_t CreateKey() {
02041     pthread_key_t key;
02042     // When a thread exits, DeleteThreadLocalValue() will be called on
02043     // the object managed for that thread.
02044     GTEST_CHECK_POSIX_SUCCESS_(
02045         pthread_key_create(&key, &DeleteThreadLocalValue));
02046     return key;
02047   }
02048 
02049   T* GetOrCreateValue() const {
02050     ThreadLocalValueHolderBase* const holder =
02051         static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
02052     if (holder != NULL) {
02053       return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
02054     }
02055 
02056     ValueHolder* const new_holder = new ValueHolder(default_);
02057     ThreadLocalValueHolderBase* const holder_base = new_holder;
02058     GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
02059     return new_holder->pointer();
02060   }
02061 
02062   // A key pthreads uses for looking up per-thread values.
02063   const pthread_key_t key_;
02064   const T default_;  // The default value for each thread.
02065 
02066   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
02067 };
02068 
02069 # endif  // OS detection
02070 
02071 #else  // GTEST_IS_THREADSAFE
02072 
02073 // A dummy implementation of synchronization primitives (mutex, lock,
02074 // and thread-local variable).  Necessary for compiling Google Test where
02075 // mutex is not supported - using Google Test in multiple threads is not
02076 // supported on such platforms.
02077 
02078 class Mutex {
02079  public:
02080   Mutex() {}
02081   void Lock() {}
02082   void Unlock() {}
02083   void AssertHeld() const {}
02084 };
02085 
02086 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
02087   extern ::testing::internal::Mutex mutex
02088 
02089 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
02090 
02091 // We cannot name this class MutexLock because the ctor declaration would
02092 // conflict with a macro named MutexLock, which is defined on some
02093 // platforms. That macro is used as a defensive measure to prevent against
02094 // inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
02095 // "MutexLock l(&mu)".  Hence the typedef trick below.
02096 class GTestMutexLock {
02097  public:
02098   explicit GTestMutexLock(Mutex*) {}  // NOLINT
02099 };
02100 
02101 typedef GTestMutexLock MutexLock;
02102 
02103 template <typename T>
02104 class ThreadLocal {
02105  public:
02106   ThreadLocal() : value_() {}
02107   explicit ThreadLocal(const T& value) : value_(value) {}
02108   T* pointer() { return &value_; }
02109   const T* pointer() const { return &value_; }
02110   const T& get() const { return value_; }
02111   void set(const T& value) { value_ = value; }
02112  private:
02113   T value_;
02114 };
02115 
02116 #endif  // GTEST_IS_THREADSAFE
02117 
02118 // Returns the number of threads running in the process, or 0 to indicate that
02119 // we cannot detect it.
02120 GTEST_API_ size_t GetThreadCount();
02121 
02122 // Passing non-POD classes through ellipsis (...) crashes the ARM
02123 // compiler and generates a warning in Sun Studio.  The Nokia Symbian
02124 // and the IBM XL C/C++ compiler try to instantiate a copy constructor
02125 // for objects passed through ellipsis (...), failing for uncopyable
02126 // objects.  We define this to ensure that only POD is passed through
02127 // ellipsis on these systems.
02128 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
02129 // We lose support for NULL detection where the compiler doesn't like
02130 // passing non-POD classes through ellipsis (...).
02131 # define GTEST_ELLIPSIS_NEEDS_POD_ 1
02132 #else
02133 # define GTEST_CAN_COMPARE_NULL 1
02134 #endif
02135 
02136 // The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
02137 // const T& and const T* in a function template.  These compilers
02138 // _can_ decide between class template specializations for T and T*,
02139 // so a tr1::type_traits-like is_pointer works.
02140 #if defined(__SYMBIAN32__) || defined(__IBMCPP__)
02141 # define GTEST_NEEDS_IS_POINTER_ 1
02142 #endif
02143 
02144 template <bool bool_value>
02145 struct bool_constant {
02146   typedef bool_constant<bool_value> type;
02147   static const bool value = bool_value;
02148 };
02149 template <bool bool_value> const bool bool_constant<bool_value>::value;
02150 
02151 typedef bool_constant<false> false_type;
02152 typedef bool_constant<true> true_type;
02153 
02154 template <typename T>
02155 struct is_pointer : public false_type {};
02156 
02157 template <typename T>
02158 struct is_pointer<T*> : public true_type {};
02159 
02160 template <typename Iterator>
02161 struct IteratorTraits {
02162   typedef typename Iterator::value_type value_type;
02163 };
02164 
02165 template <typename T>
02166 struct IteratorTraits<T*> {
02167   typedef T value_type;
02168 };
02169 
02170 template <typename T>
02171 struct IteratorTraits<const T*> {
02172   typedef T value_type;
02173 };
02174 
02175 #if GTEST_OS_WINDOWS
02176 # define GTEST_PATH_SEP_ "\\"
02177 # define GTEST_HAS_ALT_PATH_SEP_ 1
02178 // The biggest signed integer type the compiler supports.
02179 typedef __int64 BiggestInt;
02180 #else
02181 # define GTEST_PATH_SEP_ "/"
02182 # define GTEST_HAS_ALT_PATH_SEP_ 0
02183 typedef long long BiggestInt;  // NOLINT
02184 #endif  // GTEST_OS_WINDOWS
02185 
02186 // Utilities for char.
02187 
02188 // isspace(int ch) and friends accept an unsigned char or EOF.  char
02189 // may be signed, depending on the compiler (or compiler flags).
02190 // Therefore we need to cast a char to unsigned char before calling
02191 // isspace(), etc.
02192 
02193 inline bool IsAlpha(char ch) {
02194   return isalpha(static_cast<unsigned char>(ch)) != 0;
02195 }
02196 inline bool IsAlNum(char ch) {
02197   return isalnum(static_cast<unsigned char>(ch)) != 0;
02198 }
02199 inline bool IsDigit(char ch) {
02200   return isdigit(static_cast<unsigned char>(ch)) != 0;
02201 }
02202 inline bool IsLower(char ch) {
02203   return islower(static_cast<unsigned char>(ch)) != 0;
02204 }
02205 inline bool IsSpace(char ch) {
02206   return isspace(static_cast<unsigned char>(ch)) != 0;
02207 }
02208 inline bool IsUpper(char ch) {
02209   return isupper(static_cast<unsigned char>(ch)) != 0;
02210 }
02211 inline bool IsXDigit(char ch) {
02212   return isxdigit(static_cast<unsigned char>(ch)) != 0;
02213 }
02214 inline bool IsXDigit(wchar_t ch) {
02215   const unsigned char low_byte = static_cast<unsigned char>(ch);
02216   return ch == low_byte && isxdigit(low_byte) != 0;
02217 }
02218 
02219 inline char ToLower(char ch) {
02220   return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
02221 }
02222 inline char ToUpper(char ch) {
02223   return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
02224 }
02225 
02226 inline std::string StripTrailingSpaces(std::string str) {
02227   std::string::iterator it = str.end();
02228   while (it != str.begin() && IsSpace(*--it))
02229     it = str.erase(it);
02230   return str;
02231 }
02232 
02233 // The testing::internal::posix namespace holds wrappers for common
02234 // POSIX functions.  These wrappers hide the differences between
02235 // Windows/MSVC and POSIX systems.  Since some compilers define these
02236 // standard functions as macros, the wrapper cannot have the same name
02237 // as the wrapped function.
02238 
02239 namespace posix {
02240 
02241 // Functions with a different name on Windows.
02242 
02243 #if GTEST_OS_WINDOWS
02244 
02245 typedef struct _stat StatStruct;
02246 
02247 # ifdef __BORLANDC__
02248 inline int IsATTY(int fd) { return isatty(fd); }
02249 inline int StrCaseCmp(const char* s1, const char* s2) {
02250   return stricmp(s1, s2);
02251 }
02252 inline char* StrDup(const char* src) { return strdup(src); }
02253 # else  // !__BORLANDC__
02254 #  if GTEST_OS_WINDOWS_MOBILE
02255 inline int IsATTY(int /* fd */) { return 0; }
02256 #  else
02257 inline int IsATTY(int fd) { return _isatty(fd); }
02258 #  endif  // GTEST_OS_WINDOWS_MOBILE
02259 inline int StrCaseCmp(const char* s1, const char* s2) {
02260   return _stricmp(s1, s2);
02261 }
02262 inline char* StrDup(const char* src) { return _strdup(src); }
02263 # endif  // __BORLANDC__
02264 
02265 # if GTEST_OS_WINDOWS_MOBILE
02266 inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
02267 // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
02268 // time and thus not defined there.
02269 # else
02270 inline int FileNo(FILE* file) { return _fileno(file); }
02271 inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
02272 inline int RmDir(const char* dir) { return _rmdir(dir); }
02273 inline bool IsDir(const StatStruct& st) {
02274   return (_S_IFDIR & st.st_mode) != 0;
02275 }
02276 # endif  // GTEST_OS_WINDOWS_MOBILE
02277 
02278 #else
02279 
02280 typedef struct stat StatStruct;
02281 
02282 inline int FileNo(FILE* file) { return fileno(file); }
02283 inline int IsATTY(int fd) { return isatty(fd); }
02284 inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
02285 inline int StrCaseCmp(const char* s1, const char* s2) {
02286   return strcasecmp(s1, s2);
02287 }
02288 inline char* StrDup(const char* src) { return strdup(src); }
02289 inline int RmDir(const char* dir) { return rmdir(dir); }
02290 inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
02291 
02292 #endif  // GTEST_OS_WINDOWS
02293 
02294 // Functions deprecated by MSVC 8.0.
02295 
02296 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
02297 
02298 inline const char* StrNCpy(char* dest, const char* src, size_t n) {
02299   return strncpy(dest, src, n);
02300 }
02301 
02302 // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
02303 // StrError() aren't needed on Windows CE at this time and thus not
02304 // defined there.
02305 
02306 #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
02307 inline int ChDir(const char* dir) { return chdir(dir); }
02308 #endif
02309 inline FILE* FOpen(const char* path, const char* mode) {
02310   return fopen(path, mode);
02311 }
02312 #if !GTEST_OS_WINDOWS_MOBILE
02313 inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
02314   return freopen(path, mode, stream);
02315 }
02316 inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
02317 #endif
02318 inline int FClose(FILE* fp) { return fclose(fp); }
02319 #if !GTEST_OS_WINDOWS_MOBILE
02320 inline int Read(int fd, void* buf, unsigned int count) {
02321   return static_cast<int>(read(fd, buf, count));
02322 }
02323 inline int Write(int fd, const void* buf, unsigned int count) {
02324   return static_cast<int>(write(fd, buf, count));
02325 }
02326 inline int Close(int fd) { return close(fd); }
02327 inline const char* StrError(int errnum) { return strerror(errnum); }
02328 #endif
02329 inline const char* GetEnv(const char* name) {
02330 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE | GTEST_OS_WINDOWS_RT
02331   // We are on Windows CE, which has no environment variables.
02332   static_cast<void>(name);  // To prevent 'unused argument' warning.
02333   return NULL;
02334 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
02335   // Environment variables which we programmatically clear will be set to the
02336   // empty string rather than unset (NULL).  Handle that case.
02337   const char* const env = getenv(name);
02338   return (env != NULL && env[0] != '\0') ? env : NULL;
02339 #else
02340   return getenv(name);
02341 #endif
02342 }
02343 
02344 GTEST_DISABLE_MSC_WARNINGS_POP_()
02345 
02346 #if GTEST_OS_WINDOWS_MOBILE
02347 // Windows CE has no C library. The abort() function is used in
02348 // several places in Google Test. This implementation provides a reasonable
02349 // imitation of standard behaviour.
02350 void Abort();
02351 #else
02352 inline void Abort() { abort(); }
02353 #endif  // GTEST_OS_WINDOWS_MOBILE
02354 
02355 }  // namespace posix
02356 
02357 // MSVC "deprecates" snprintf and issues warnings wherever it is used.  In
02358 // order to avoid these warnings, we need to use _snprintf or _snprintf_s on
02359 // MSVC-based platforms.  We map the GTEST_SNPRINTF_ macro to the appropriate
02360 // function in order to achieve that.  We use macro definition here because
02361 // snprintf is a variadic function.
02362 #if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
02363 // MSVC 2005 and above support variadic macros.
02364 # define GTEST_SNPRINTF_(buffer, size, format, ...) \
02365      _snprintf_s(buffer, size, size, format, __VA_ARGS__)
02366 #elif defined(_MSC_VER)
02367 // Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
02368 // complain about _snprintf.
02369 # define GTEST_SNPRINTF_ _snprintf
02370 #else
02371 # define GTEST_SNPRINTF_ snprintf
02372 #endif
02373 
02374 // The maximum number a BiggestInt can represent.  This definition
02375 // works no matter BiggestInt is represented in one's complement or
02376 // two's complement.
02377 //
02378 // We cannot rely on numeric_limits in STL, as __int64 and long long
02379 // are not part of standard C++ and numeric_limits doesn't need to be
02380 // defined for them.
02381 const BiggestInt kMaxBiggestInt =
02382     ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
02383 
02384 // This template class serves as a compile-time function from size to
02385 // type.  It maps a size in bytes to a primitive type with that
02386 // size. e.g.
02387 //
02388 //   TypeWithSize<4>::UInt
02389 //
02390 // is typedef-ed to be unsigned int (unsigned integer made up of 4
02391 // bytes).
02392 //
02393 // Such functionality should belong to STL, but I cannot find it
02394 // there.
02395 //
02396 // Google Test uses this class in the implementation of floating-point
02397 // comparison.
02398 //
02399 // For now it only handles UInt (unsigned int) as that's all Google Test
02400 // needs.  Other types can be easily added in the future if need
02401 // arises.
02402 template <size_t size>
02403 class TypeWithSize {
02404  public:
02405   // This prevents the user from using TypeWithSize<N> with incorrect
02406   // values of N.
02407   typedef void UInt;
02408 };
02409 
02410 // The specialization for size 4.
02411 template <>
02412 class TypeWithSize<4> {
02413  public:
02414   // unsigned int has size 4 in both gcc and MSVC.
02415   //
02416   // As base/basictypes.h doesn't compile on Windows, we cannot use
02417   // uint32, uint64, and etc here.
02418   typedef int Int;
02419   typedef unsigned int UInt;
02420 };
02421 
02422 // The specialization for size 8.
02423 template <>
02424 class TypeWithSize<8> {
02425  public:
02426 #if GTEST_OS_WINDOWS
02427   typedef __int64 Int;
02428   typedef unsigned __int64 UInt;
02429 #else
02430   typedef long long Int;  // NOLINT
02431   typedef unsigned long long UInt;  // NOLINT
02432 #endif  // GTEST_OS_WINDOWS
02433 };
02434 
02435 // Integer types of known sizes.
02436 typedef TypeWithSize<4>::Int Int32;
02437 typedef TypeWithSize<4>::UInt UInt32;
02438 typedef TypeWithSize<8>::Int Int64;
02439 typedef TypeWithSize<8>::UInt UInt64;
02440 typedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.
02441 
02442 // Utilities for command line flags and environment variables.
02443 
02444 // Macro for referencing flags.
02445 #define GTEST_FLAG(name) FLAGS_gtest_##name
02446 
02447 // Macros for declaring flags.
02448 #define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
02449 #define GTEST_DECLARE_int32_(name) \
02450     GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
02451 #define GTEST_DECLARE_string_(name) \
02452     GTEST_API_ extern ::std::string GTEST_FLAG(name)
02453 
02454 // Macros for defining flags.
02455 #define GTEST_DEFINE_bool_(name, default_val, doc) \
02456     GTEST_API_ bool GTEST_FLAG(name) = (default_val)
02457 #define GTEST_DEFINE_int32_(name, default_val, doc) \
02458     GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
02459 #define GTEST_DEFINE_string_(name, default_val, doc) \
02460     GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
02461 
02462 // Thread annotations
02463 #define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
02464 #define GTEST_LOCK_EXCLUDED_(locks)
02465 
02466 // Parses 'str' for a 32-bit signed integer.  If successful, writes the result
02467 // to *value and returns true; otherwise leaves *value unchanged and returns
02468 // false.
02469 // TODO(chandlerc): Find a better way to refactor flag and environment parsing
02470 // out of both gtest-port.cc and gtest.cc to avoid exporting this utility
02471 // function.
02472 bool ParseInt32(const Message& src_text, const char* str, Int32* value);
02473 
02474 // Parses a bool/Int32/string from the environment variable
02475 // corresponding to the given Google Test flag.
02476 bool BoolFromGTestEnv(const char* flag, bool default_val);
02477 GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
02478 const char* StringFromGTestEnv(const char* flag, const char* default_val);
02479 
02480 }  // namespace internal
02481 }  // namespace testing
02482 
02483 #endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
02484 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:03