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.  They are subject to change without notice.  DO NOT USE
00034 // THEM IN USER CODE.
00035 
00036 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
00037 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
00038 
00039 // The user can define the following macros in the build script to
00040 // control Google Test's behavior.  If the user doesn't define a macro
00041 // in this list, Google Test will define it.
00042 //
00043 //   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
00044 //                              is/isn't available.
00045 //   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
00046 //                              are enabled.
00047 //   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
00048 //                              is/isn't available (some systems define
00049 //                              ::string, which is different to std::string).
00050 //   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
00051 //                              is/isn't available (some systems define
00052 //                              ::wstring, which is different to std::wstring).
00053 //   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
00054 //                              expressions are/aren't available.
00055 //   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
00056 //                              is/isn't available.
00057 //   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
00058 //                              enabled.
00059 //   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
00060 //                              std::wstring does/doesn't work (Google Test can
00061 //                              be used where std::wstring is unavailable).
00062 //   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
00063 //                              is/isn't available.
00064 //   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
00065 //                              compiler supports Microsoft's "Structured
00066 //                              Exception Handling".
00067 //   GTEST_HAS_STREAM_REDIRECTION
00068 //                            - Define it to 1/0 to indicate whether the
00069 //                              platform supports I/O stream redirection using
00070 //                              dup() and dup2().
00071 //   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
00072 //                              Test's own tr1 tuple implementation should be
00073 //                              used.  Unused when the user sets
00074 //                              GTEST_HAS_TR1_TUPLE to 0.
00075 //   GTEST_LINKED_AS_SHARED_LIBRARY
00076 //                            - Define to 1 when compiling tests that use
00077 //                              Google Test as a shared library (known as
00078 //                              DLL on Windows).
00079 //   GTEST_CREATE_SHARED_LIBRARY
00080 //                            - Define to 1 when compiling Google Test itself
00081 //                              as a shared library.
00082 
00083 // This header defines the following utilities:
00084 //
00085 // Macros indicating the current platform (defined to 1 if compiled on
00086 // the given platform; otherwise undefined):
00087 //   GTEST_OS_AIX      - IBM AIX
00088 //   GTEST_OS_CYGWIN   - Cygwin
00089 //   GTEST_OS_HPUX     - HP-UX
00090 //   GTEST_OS_LINUX    - Linux
00091 //     GTEST_OS_LINUX_ANDROID - Google Android
00092 //   GTEST_OS_MAC      - Mac OS X
00093 //   GTEST_OS_NACL     - Google Native Client (NaCl)
00094 //   GTEST_OS_SOLARIS  - Sun Solaris
00095 //   GTEST_OS_SYMBIAN  - Symbian
00096 //   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
00097 //     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
00098 //     GTEST_OS_WINDOWS_MINGW    - MinGW
00099 //     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
00100 //   GTEST_OS_ZOS      - z/OS
00101 //
00102 // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
00103 // most stable support.  Since core members of the Google Test project
00104 // don't have access to other platforms, support for them may be less
00105 // stable.  If you notice any problems on your platform, please notify
00106 // googletestframework@googlegroups.com (patches for fixing them are
00107 // even more welcome!).
00108 //
00109 // Note that it is possible that none of the GTEST_OS_* macros are defined.
00110 //
00111 // Macros indicating available Google Test features (defined to 1 if
00112 // the corresponding feature is supported; otherwise undefined):
00113 //   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
00114 //                            tests)
00115 //   GTEST_HAS_DEATH_TEST   - death tests
00116 //   GTEST_HAS_PARAM_TEST   - value-parameterized tests
00117 //   GTEST_HAS_TYPED_TEST   - typed tests
00118 //   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
00119 //   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
00120 //                            GTEST_HAS_POSIX_RE (see above) which users can
00121 //                            define themselves.
00122 //   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
00123 //                            the above two are mutually exclusive.
00124 //   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
00125 //
00126 // Macros for basic C++ coding:
00127 //   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
00128 //   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
00129 //                              variable don't have to be used.
00130 //   GTEST_DISALLOW_ASSIGN_   - disables operator=.
00131 //   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
00132 //   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
00133 //
00134 // Synchronization:
00135 //   Mutex, MutexLock, ThreadLocal, GetThreadCount()
00136 //                  - synchronization primitives.
00137 //   GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
00138 //                         synchronization primitives have real implementations
00139 //                         and Google Test is thread-safe; or 0 otherwise.
00140 //
00141 // Template meta programming:
00142 //   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
00143 //   IteratorTraits - partial implementation of std::iterator_traits, which
00144 //                    is not available in libCstd when compiled with Sun C++.
00145 //
00146 // Smart pointers:
00147 //   scoped_ptr     - as in TR2.
00148 //
00149 // Regular expressions:
00150 //   RE             - a simple regular expression class using the POSIX
00151 //                    Extended Regular Expression syntax on UNIX-like
00152 //                    platforms, or a reduced regular exception syntax on
00153 //                    other platforms, including Windows.
00154 //
00155 // Logging:
00156 //   GTEST_LOG_()   - logs messages at the specified severity level.
00157 //   LogToStderr()  - directs all log messages to stderr.
00158 //   FlushInfoLog() - flushes informational log messages.
00159 //
00160 // Stdout and stderr capturing:
00161 //   CaptureStdout()     - starts capturing stdout.
00162 //   GetCapturedStdout() - stops capturing stdout and returns the captured
00163 //                         string.
00164 //   CaptureStderr()     - starts capturing stderr.
00165 //   GetCapturedStderr() - stops capturing stderr and returns the captured
00166 //                         string.
00167 //
00168 // Integer types:
00169 //   TypeWithSize   - maps an integer to a int type.
00170 //   Int32, UInt32, Int64, UInt64, TimeInMillis
00171 //                  - integers of known sizes.
00172 //   BiggestInt     - the biggest signed integer type.
00173 //
00174 // Command-line utilities:
00175 //   GTEST_FLAG()       - references a flag.
00176 //   GTEST_DECLARE_*()  - declares a flag.
00177 //   GTEST_DEFINE_*()   - defines a flag.
00178 //   GetArgvs()         - returns the command line as a vector of strings.
00179 //
00180 // Environment variable utilities:
00181 //   GetEnv()             - gets the value of an environment variable.
00182 //   BoolFromGTestEnv()   - parses a bool environment variable.
00183 //   Int32FromGTestEnv()  - parses an Int32 environment variable.
00184 //   StringFromGTestEnv() - parses a string environment variable.
00185 
00186 #include <ctype.h>   // for isspace, etc
00187 #include <stddef.h>  // for ptrdiff_t
00188 #include <stdlib.h>
00189 #include <stdio.h>
00190 #include <string.h>
00191 #ifndef _WIN32_WCE
00192 # include <sys/types.h>
00193 # include <sys/stat.h>
00194 #endif  // !_WIN32_WCE
00195 
00196 #include <iostream>  // NOLINT
00197 #include <sstream>  // NOLINT
00198 #include <string>  // NOLINT
00199 
00200 #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
00201 #define GTEST_FLAG_PREFIX_ "gtest_"
00202 #define GTEST_FLAG_PREFIX_DASH_ "gtest-"
00203 #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
00204 #define GTEST_NAME_ "Google Test"
00205 #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
00206 
00207 // Determines the version of gcc that is used to compile this.
00208 #ifdef __GNUC__
00209 // 40302 means version 4.3.2.
00210 # define GTEST_GCC_VER_ \
00211     (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
00212 #endif  // __GNUC__
00213 
00214 // Determines the platform on which Google Test is compiled.
00215 #ifdef __CYGWIN__
00216 # define GTEST_OS_CYGWIN 1
00217 #elif defined __SYMBIAN32__
00218 # define GTEST_OS_SYMBIAN 1
00219 #elif defined _WIN32
00220 # define GTEST_OS_WINDOWS 1
00221 # ifdef _WIN32_WCE
00222 #  define GTEST_OS_WINDOWS_MOBILE 1
00223 # elif defined(__MINGW__) || defined(__MINGW32__)
00224 #  define GTEST_OS_WINDOWS_MINGW 1
00225 # else
00226 #  define GTEST_OS_WINDOWS_DESKTOP 1
00227 # endif  // _WIN32_WCE
00228 #elif defined __APPLE__
00229 # define GTEST_OS_MAC 1
00230 #elif defined __linux__
00231 # define GTEST_OS_LINUX 1
00232 # ifdef ANDROID
00233 #  define GTEST_OS_LINUX_ANDROID 1
00234 # endif  // ANDROID
00235 #elif defined __MVS__
00236 # define GTEST_OS_ZOS 1
00237 #elif defined(__sun) && defined(__SVR4)
00238 # define GTEST_OS_SOLARIS 1
00239 #elif defined(_AIX)
00240 # define GTEST_OS_AIX 1
00241 #elif defined(__hpux)
00242 # define GTEST_OS_HPUX 1
00243 #elif defined __native_client__
00244 # define GTEST_OS_NACL 1
00245 #endif  // __CYGWIN__
00246 
00247 // Brings in definitions for functions used in the testing::internal::posix
00248 // namespace (read, write, close, chdir, isatty, stat). We do not currently
00249 // use them on Windows Mobile.
00250 #if !GTEST_OS_WINDOWS
00251 // This assumes that non-Windows OSes provide unistd.h. For OSes where this
00252 // is not the case, we need to include headers that provide the functions
00253 // mentioned above.
00254 # include <unistd.h>
00255 # if !GTEST_OS_NACL
00256 // TODO(vladl@google.com): Remove this condition when Native Client SDK adds
00257 // strings.h (tracked in
00258 // http://code.google.com/p/nativeclient/issues/detail?id=1175).
00259 #  include <strings.h>  // Native Client doesn't provide strings.h.
00260 # endif
00261 #elif !GTEST_OS_WINDOWS_MOBILE
00262 # include <direct.h>
00263 # include <io.h>
00264 #endif
00265 
00266 // Defines this to true iff Google Test can use POSIX regular expressions.
00267 #ifndef GTEST_HAS_POSIX_RE
00268 # define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
00269 #endif
00270 
00271 #if GTEST_HAS_POSIX_RE
00272 
00273 // On some platforms, <regex.h> needs someone to define size_t, and
00274 // won't compile otherwise.  We can #include it here as we already
00275 // included <stdlib.h>, which is guaranteed to define size_t through
00276 // <stddef.h>.
00277 # include <regex.h>  // NOLINT
00278 
00279 # define GTEST_USES_POSIX_RE 1
00280 
00281 #elif GTEST_OS_WINDOWS
00282 
00283 // <regex.h> is not available on Windows.  Use our own simple regex
00284 // implementation instead.
00285 # define GTEST_USES_SIMPLE_RE 1
00286 
00287 #else
00288 
00289 // <regex.h> may not be available on this platform.  Use our own
00290 // simple regex implementation instead.
00291 # define GTEST_USES_SIMPLE_RE 1
00292 
00293 #endif  // GTEST_HAS_POSIX_RE
00294 
00295 #ifndef GTEST_HAS_EXCEPTIONS
00296 // The user didn't tell us whether exceptions are enabled, so we need
00297 // to figure it out.
00298 # if defined(_MSC_VER) || defined(__BORLANDC__)
00299 // MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
00300 // macro to enable exceptions, so we'll do the same.
00301 // Assumes that exceptions are enabled by default.
00302 #  ifndef _HAS_EXCEPTIONS
00303 #   define _HAS_EXCEPTIONS 1
00304 #  endif  // _HAS_EXCEPTIONS
00305 #  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
00306 # elif defined(__GNUC__) && __EXCEPTIONS
00307 // gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
00308 #  define GTEST_HAS_EXCEPTIONS 1
00309 # elif defined(__SUNPRO_CC)
00310 // Sun Pro CC supports exceptions.  However, there is no compile-time way of
00311 // detecting whether they are enabled or not.  Therefore, we assume that
00312 // they are enabled unless the user tells us otherwise.
00313 #  define GTEST_HAS_EXCEPTIONS 1
00314 # elif defined(__IBMCPP__) && __EXCEPTIONS
00315 // xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
00316 #  define GTEST_HAS_EXCEPTIONS 1
00317 # elif defined(__HP_aCC)
00318 // Exception handling is in effect by default in HP aCC compiler. It has to
00319 // be turned of by +noeh compiler option if desired.
00320 #  define GTEST_HAS_EXCEPTIONS 1
00321 # else
00322 // For other compilers, we assume exceptions are disabled to be
00323 // conservative.
00324 #  define GTEST_HAS_EXCEPTIONS 0
00325 # endif  // defined(_MSC_VER) || defined(__BORLANDC__)
00326 #endif  // GTEST_HAS_EXCEPTIONS
00327 
00328 #if !defined(GTEST_HAS_STD_STRING)
00329 // Even though we don't use this macro any longer, we keep it in case
00330 // some clients still depend on it.
00331 # define GTEST_HAS_STD_STRING 1
00332 #elif !GTEST_HAS_STD_STRING
00333 // The user told us that ::std::string isn't available.
00334 # error "Google Test cannot be used where ::std::string isn't available."
00335 #endif  // !defined(GTEST_HAS_STD_STRING)
00336 
00337 #ifndef GTEST_HAS_GLOBAL_STRING
00338 // The user didn't tell us whether ::string is available, so we need
00339 // to figure it out.
00340 
00341 # define GTEST_HAS_GLOBAL_STRING 0
00342 
00343 #endif  // GTEST_HAS_GLOBAL_STRING
00344 
00345 #ifndef GTEST_HAS_STD_WSTRING
00346 // The user didn't tell us whether ::std::wstring is available, so we need
00347 // to figure it out.
00348 // TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
00349 //   is available.
00350 
00351 // Cygwin 1.7 and below doesn't support ::std::wstring.
00352 // Solaris' libc++ doesn't support it either.  Android has
00353 // no support for it at least as recent as Froyo (2.2).
00354 # define GTEST_HAS_STD_WSTRING \
00355     (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
00356 
00357 #endif  // GTEST_HAS_STD_WSTRING
00358 
00359 #ifndef GTEST_HAS_GLOBAL_WSTRING
00360 // The user didn't tell us whether ::wstring is available, so we need
00361 // to figure it out.
00362 # define GTEST_HAS_GLOBAL_WSTRING \
00363     (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
00364 #endif  // GTEST_HAS_GLOBAL_WSTRING
00365 
00366 // Determines whether RTTI is available.
00367 #ifndef GTEST_HAS_RTTI
00368 // The user didn't tell us whether RTTI is enabled, so we need to
00369 // figure it out.
00370 
00371 # ifdef _MSC_VER
00372 
00373 #  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
00374 #   define GTEST_HAS_RTTI 1
00375 #  else
00376 #   define GTEST_HAS_RTTI 0
00377 #  endif
00378 
00379 // Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
00380 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
00381 
00382 #  ifdef __GXX_RTTI
00383 #   define GTEST_HAS_RTTI 1
00384 #  else
00385 #   define GTEST_HAS_RTTI 0
00386 #  endif  // __GXX_RTTI
00387 
00388 // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
00389 // both the typeid and dynamic_cast features are present.
00390 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
00391 
00392 #  ifdef __RTTI_ALL__
00393 #   define GTEST_HAS_RTTI 1
00394 #  else
00395 #   define GTEST_HAS_RTTI 0
00396 #  endif
00397 
00398 # else
00399 
00400 // For all other compilers, we assume RTTI is enabled.
00401 #  define GTEST_HAS_RTTI 1
00402 
00403 # endif  // _MSC_VER
00404 
00405 #endif  // GTEST_HAS_RTTI
00406 
00407 // It's this header's responsibility to #include <typeinfo> when RTTI
00408 // is enabled.
00409 #if GTEST_HAS_RTTI
00410 # include <typeinfo>
00411 #endif
00412 
00413 // Determines whether Google Test can use the pthreads library.
00414 #ifndef GTEST_HAS_PTHREAD
00415 // The user didn't tell us explicitly, so we assume pthreads support is
00416 // available on Linux and Mac.
00417 //
00418 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
00419 // to your compiler flags.
00420 # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX)
00421 #endif  // GTEST_HAS_PTHREAD
00422 
00423 #if GTEST_HAS_PTHREAD
00424 // gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
00425 // true.
00426 # include <pthread.h>  // NOLINT
00427 
00428 // For timespec and nanosleep, used below.
00429 # include <time.h>  // NOLINT
00430 #endif
00431 
00432 // Determines whether Google Test can use tr1/tuple.  You can define
00433 // this macro to 0 to prevent Google Test from using tuple (any
00434 // feature depending on tuple with be disabled in this mode).
00435 #ifndef GTEST_HAS_TR1_TUPLE
00436 // The user didn't tell us not to do it, so we assume it's OK.
00437 # define GTEST_HAS_TR1_TUPLE 1
00438 #endif  // GTEST_HAS_TR1_TUPLE
00439 
00440 // Determines whether Google Test's own tr1 tuple implementation
00441 // should be used.
00442 #ifndef GTEST_USE_OWN_TR1_TUPLE
00443 // The user didn't tell us, so we need to figure it out.
00444 
00445 // We use our own TR1 tuple if we aren't sure the user has an
00446 // implementation of it already.  At this time, GCC 4.0.0+ and MSVC
00447 // 2010 are the only mainstream compilers that come with a TR1 tuple
00448 // implementation.  NVIDIA's CUDA NVCC compiler pretends to be GCC by
00449 // defining __GNUC__ and friends, but cannot compile GCC's tuple
00450 // implementation.  MSVC 2008 (9.0) provides TR1 tuple in a 323 MB
00451 // Feature Pack download, which we cannot assume the user has.
00452 # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \
00453     || _MSC_VER >= 1600
00454 #  define GTEST_USE_OWN_TR1_TUPLE 0
00455 # else
00456 #  define GTEST_USE_OWN_TR1_TUPLE 1
00457 # endif
00458 
00459 #endif  // GTEST_USE_OWN_TR1_TUPLE
00460 
00461 // To avoid conditional compilation everywhere, we make it
00462 // gtest-port.h's responsibility to #include the header implementing
00463 // tr1/tuple.
00464 #if GTEST_HAS_TR1_TUPLE
00465 
00466 # if GTEST_USE_OWN_TR1_TUPLE
00467 #  include "gtest/internal/gtest-tuple.h"
00468 # elif GTEST_OS_SYMBIAN
00469 
00470 // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
00471 // use STLport's tuple implementation, which unfortunately doesn't
00472 // work as the copy of STLport distributed with Symbian is incomplete.
00473 // By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
00474 // use its own tuple implementation.
00475 #  ifdef BOOST_HAS_TR1_TUPLE
00476 #   undef BOOST_HAS_TR1_TUPLE
00477 #  endif  // BOOST_HAS_TR1_TUPLE
00478 
00479 // This prevents <boost/tr1/detail/config.hpp>, which defines
00480 // BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
00481 #  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
00482 #  include <tuple>
00483 
00484 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
00485 // GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
00486 // not conform to the TR1 spec, which requires the header to be <tuple>.
00487 
00488 #  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
00489 // Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
00490 // which is #included by <tr1/tuple>, to not compile when RTTI is
00491 // disabled.  _TR1_FUNCTIONAL is the header guard for
00492 // <tr1/functional>.  Hence the following #define is a hack to prevent
00493 // <tr1/functional> from being included.
00494 #   define _TR1_FUNCTIONAL 1
00495 #   include <tr1/tuple>
00496 #   undef _TR1_FUNCTIONAL  // Allows the user to #include
00497                         // <tr1/functional> if he chooses to.
00498 #  else
00499 #   include <tr1/tuple>  // NOLINT
00500 #  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
00501 
00502 # else
00503 // If the compiler is not GCC 4.0+, we assume the user is using a
00504 // spec-conforming TR1 implementation.
00505 #  include <tuple>  // NOLINT
00506 # endif  // GTEST_USE_OWN_TR1_TUPLE
00507 
00508 #endif  // GTEST_HAS_TR1_TUPLE
00509 
00510 // Determines whether clone(2) is supported.
00511 // Usually it will only be available on Linux, excluding
00512 // Linux on the Itanium architecture.
00513 // Also see http://linux.die.net/man/2/clone.
00514 #ifndef GTEST_HAS_CLONE
00515 // The user didn't tell us, so we need to figure it out.
00516 
00517 # if GTEST_OS_LINUX && !defined(__ia64__)
00518 #  define GTEST_HAS_CLONE 1
00519 # else
00520 #  define GTEST_HAS_CLONE 0
00521 # endif  // GTEST_OS_LINUX && !defined(__ia64__)
00522 
00523 #endif  // GTEST_HAS_CLONE
00524 
00525 // Determines whether to support stream redirection. This is used to test
00526 // output correctness and to implement death tests.
00527 #ifndef GTEST_HAS_STREAM_REDIRECTION
00528 // By default, we assume that stream redirection is supported on all
00529 // platforms except known mobile ones.
00530 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
00531 #  define GTEST_HAS_STREAM_REDIRECTION 0
00532 # else
00533 #  define GTEST_HAS_STREAM_REDIRECTION 1
00534 # endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
00535 #endif  // GTEST_HAS_STREAM_REDIRECTION
00536 
00537 // Determines whether to support death tests.
00538 // Google Test does not support death tests for VC 7.1 and earlier as
00539 // abort() in a VC 7.1 application compiled as GUI in debug config
00540 // pops up a dialog window that cannot be suppressed programmatically.
00541 #if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
00542      (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
00543      GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)
00544 # define GTEST_HAS_DEATH_TEST 1
00545 # include <vector>  // NOLINT
00546 #endif
00547 
00548 // We don't support MSVC 7.1 with exceptions disabled now.  Therefore
00549 // all the compilers we care about are adequate for supporting
00550 // value-parameterized tests.
00551 #define GTEST_HAS_PARAM_TEST 1
00552 
00553 // Determines whether to support type-driven tests.
00554 
00555 // Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
00556 // Sun Pro CC, IBM Visual Age, and HP aCC support.
00557 #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
00558     defined(__IBMCPP__) || defined(__HP_aCC)
00559 # define GTEST_HAS_TYPED_TEST 1
00560 # define GTEST_HAS_TYPED_TEST_P 1
00561 #endif
00562 
00563 // Determines whether to support Combine(). This only makes sense when
00564 // value-parameterized tests are enabled.  The implementation doesn't
00565 // work on Sun Studio since it doesn't understand templated conversion
00566 // operators.
00567 #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
00568 # define GTEST_HAS_COMBINE 1
00569 #endif
00570 
00571 // Determines whether the system compiler uses UTF-16 for encoding wide strings.
00572 #define GTEST_WIDE_STRING_USES_UTF16_ \
00573     (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
00574 
00575 // Determines whether test results can be streamed to a socket.
00576 #if GTEST_OS_LINUX
00577 # define GTEST_CAN_STREAM_RESULTS_ 1
00578 #endif
00579 
00580 // Defines some utility macros.
00581 
00582 // The GNU compiler emits a warning if nested "if" statements are followed by
00583 // an "else" statement and braces are not used to explicitly disambiguate the
00584 // "else" binding.  This leads to problems with code like:
00585 //
00586 //   if (gate)
00587 //     ASSERT_*(condition) << "Some message";
00588 //
00589 // The "switch (0) case 0:" idiom is used to suppress this.
00590 #ifdef __INTEL_COMPILER
00591 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
00592 #else
00593 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
00594 #endif
00595 
00596 // Use this annotation at the end of a struct/class definition to
00597 // prevent the compiler from optimizing away instances that are never
00598 // used.  This is useful when all interesting logic happens inside the
00599 // c'tor and / or d'tor.  Example:
00600 //
00601 //   struct Foo {
00602 //     Foo() { ... }
00603 //   } GTEST_ATTRIBUTE_UNUSED_;
00604 //
00605 // Also use it after a variable or parameter declaration to tell the
00606 // compiler the variable/parameter does not have to be used.
00607 #if defined(__GNUC__) && !defined(COMPILER_ICC)
00608 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
00609 #else
00610 # define GTEST_ATTRIBUTE_UNUSED_
00611 #endif
00612 
00613 // A macro to disallow operator=
00614 // This should be used in the private: declarations for a class.
00615 #define GTEST_DISALLOW_ASSIGN_(type)\
00616   void operator=(type const &)
00617 
00618 // A macro to disallow copy constructor and operator=
00619 // This should be used in the private: declarations for a class.
00620 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
00621   type(type const &);\
00622   GTEST_DISALLOW_ASSIGN_(type)
00623 
00624 // Tell the compiler to warn about unused return values for functions declared
00625 // with this macro.  The macro should be used on function declarations
00626 // following the argument list:
00627 //
00628 //   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
00629 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
00630 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
00631 #else
00632 # define GTEST_MUST_USE_RESULT_
00633 #endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
00634 
00635 // Determine whether the compiler supports Microsoft's Structured Exception
00636 // Handling.  This is supported by several Windows compilers but generally
00637 // does not exist on any other system.
00638 #ifndef GTEST_HAS_SEH
00639 // The user didn't tell us, so we need to figure it out.
00640 
00641 # if defined(_MSC_VER) || defined(__BORLANDC__)
00642 // These two compilers are known to support SEH.
00643 #  define GTEST_HAS_SEH 1
00644 # else
00645 // Assume no SEH.
00646 #  define GTEST_HAS_SEH 0
00647 # endif
00648 
00649 #endif  // GTEST_HAS_SEH
00650 
00651 #ifdef _MSC_VER
00652 
00653 # if GTEST_LINKED_AS_SHARED_LIBRARY
00654 #  define GTEST_API_ __declspec(dllimport)
00655 # elif GTEST_CREATE_SHARED_LIBRARY
00656 #  define GTEST_API_ __declspec(dllexport)
00657 # endif
00658 
00659 #endif  // _MSC_VER
00660 
00661 #ifndef GTEST_API_
00662 # define GTEST_API_
00663 #endif
00664 
00665 #ifdef __GNUC__
00666 // Ask the compiler to never inline a given function.
00667 # define GTEST_NO_INLINE_ __attribute__((noinline))
00668 #else
00669 # define GTEST_NO_INLINE_
00670 #endif
00671 
00672 namespace testing {
00673 
00674 class Message;
00675 
00676 namespace internal {
00677 
00678 class String;
00679 
00680 // The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
00681 // expression is true. For example, you could use it to verify the
00682 // size of a static array:
00683 //
00684 //   GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
00685 //                         content_type_names_incorrect_size);
00686 //
00687 // or to make sure a struct is smaller than a certain size:
00688 //
00689 //   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
00690 //
00691 // The second argument to the macro is the name of the variable. If
00692 // the expression is false, most compilers will issue a warning/error
00693 // containing the name of the variable.
00694 
00695 template <bool>
00696 struct CompileAssert {
00697 };
00698 
00699 #define GTEST_COMPILE_ASSERT_(expr, msg) \
00700   typedef ::testing::internal::CompileAssert<(bool(expr))> \
00701       msg[bool(expr) ? 1 : -1]
00702 
00703 // Implementation details of GTEST_COMPILE_ASSERT_:
00704 //
00705 // - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
00706 //   elements (and thus is invalid) when the expression is false.
00707 //
00708 // - The simpler definition
00709 //
00710 //    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
00711 //
00712 //   does not work, as gcc supports variable-length arrays whose sizes
00713 //   are determined at run-time (this is gcc's extension and not part
00714 //   of the C++ standard).  As a result, gcc fails to reject the
00715 //   following code with the simple definition:
00716 //
00717 //     int foo;
00718 //     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
00719 //                                      // not a compile-time constant.
00720 //
00721 // - By using the type CompileAssert<(bool(expr))>, we ensures that
00722 //   expr is a compile-time constant.  (Template arguments must be
00723 //   determined at compile-time.)
00724 //
00725 // - The outter parentheses in CompileAssert<(bool(expr))> are necessary
00726 //   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
00727 //
00728 //     CompileAssert<bool(expr)>
00729 //
00730 //   instead, these compilers will refuse to compile
00731 //
00732 //     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
00733 //
00734 //   (They seem to think the ">" in "5 > 0" marks the end of the
00735 //   template argument list.)
00736 //
00737 // - The array size is (bool(expr) ? 1 : -1), instead of simply
00738 //
00739 //     ((expr) ? 1 : -1).
00740 //
00741 //   This is to avoid running into a bug in MS VC 7.1, which
00742 //   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
00743 
00744 // StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
00745 //
00746 // This template is declared, but intentionally undefined.
00747 template <typename T1, typename T2>
00748 struct StaticAssertTypeEqHelper;
00749 
00750 template <typename T>
00751 struct StaticAssertTypeEqHelper<T, T> {};
00752 
00753 #if GTEST_HAS_GLOBAL_STRING
00754 typedef ::string string;
00755 #else
00756 typedef ::std::string string;
00757 #endif  // GTEST_HAS_GLOBAL_STRING
00758 
00759 #if GTEST_HAS_GLOBAL_WSTRING
00760 typedef ::wstring wstring;
00761 #elif GTEST_HAS_STD_WSTRING
00762 typedef ::std::wstring wstring;
00763 #endif  // GTEST_HAS_GLOBAL_WSTRING
00764 
00765 // A helper for suppressing warnings on constant condition.  It just
00766 // returns 'condition'.
00767 GTEST_API_ bool IsTrue(bool condition);
00768 
00769 // Defines scoped_ptr.
00770 
00771 // This implementation of scoped_ptr is PARTIAL - it only contains
00772 // enough stuff to satisfy Google Test's need.
00773 template <typename T>
00774 class scoped_ptr {
00775  public:
00776   typedef T element_type;
00777 
00778   explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
00779   ~scoped_ptr() { reset(); }
00780 
00781   T& operator*() const { return *ptr_; }
00782   T* operator->() const { return ptr_; }
00783   T* get() const { return ptr_; }
00784 
00785   T* release() {
00786     T* const ptr = ptr_;
00787     ptr_ = NULL;
00788     return ptr;
00789   }
00790 
00791   void reset(T* p = NULL) {
00792     if (p != ptr_) {
00793       if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
00794         delete ptr_;
00795       }
00796       ptr_ = p;
00797     }
00798   }
00799  private:
00800   T* ptr_;
00801 
00802   GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
00803 };
00804 
00805 // Defines RE.
00806 
00807 // A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
00808 // Regular Expression syntax.
00809 class GTEST_API_ RE {
00810  public:
00811   // A copy constructor is required by the Standard to initialize object
00812   // references from r-values.
00813   RE(const RE& other) { Init(other.pattern()); }
00814 
00815   // Constructs an RE from a string.
00816   RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
00817 
00818 #if GTEST_HAS_GLOBAL_STRING
00819 
00820   RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
00821 
00822 #endif  // GTEST_HAS_GLOBAL_STRING
00823 
00824   RE(const char* regex) { Init(regex); }  // NOLINT
00825   ~RE();
00826 
00827   // Returns the string representation of the regex.
00828   const char* pattern() const { return pattern_; }
00829 
00830   // FullMatch(str, re) returns true iff regular expression re matches
00831   // the entire str.
00832   // PartialMatch(str, re) returns true iff regular expression re
00833   // matches a substring of str (including str itself).
00834   //
00835   // TODO(wan@google.com): make FullMatch() and PartialMatch() work
00836   // when str contains NUL characters.
00837   static bool FullMatch(const ::std::string& str, const RE& re) {
00838     return FullMatch(str.c_str(), re);
00839   }
00840   static bool PartialMatch(const ::std::string& str, const RE& re) {
00841     return PartialMatch(str.c_str(), re);
00842   }
00843 
00844 #if GTEST_HAS_GLOBAL_STRING
00845 
00846   static bool FullMatch(const ::string& str, const RE& re) {
00847     return FullMatch(str.c_str(), re);
00848   }
00849   static bool PartialMatch(const ::string& str, const RE& re) {
00850     return PartialMatch(str.c_str(), re);
00851   }
00852 
00853 #endif  // GTEST_HAS_GLOBAL_STRING
00854 
00855   static bool FullMatch(const char* str, const RE& re);
00856   static bool PartialMatch(const char* str, const RE& re);
00857 
00858  private:
00859   void Init(const char* regex);
00860 
00861   // We use a const char* instead of a string, as Google Test may be used
00862   // where string is not available.  We also do not use Google Test's own
00863   // String type here, in order to simplify dependencies between the
00864   // files.
00865   const char* pattern_;
00866   bool is_valid_;
00867 
00868 #if GTEST_USES_POSIX_RE
00869 
00870   regex_t full_regex_;     // For FullMatch().
00871   regex_t partial_regex_;  // For PartialMatch().
00872 
00873 #else  // GTEST_USES_SIMPLE_RE
00874 
00875   const char* full_pattern_;  // For FullMatch();
00876 
00877 #endif
00878 
00879   GTEST_DISALLOW_ASSIGN_(RE);
00880 };
00881 
00882 // Formats a source file path and a line number as they would appear
00883 // in an error message from the compiler used to compile this code.
00884 GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
00885 
00886 // Formats a file location for compiler-independent XML output.
00887 // Although this function is not platform dependent, we put it next to
00888 // FormatFileLocation in order to contrast the two functions.
00889 GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
00890                                                                int line);
00891 
00892 // Defines logging utilities:
00893 //   GTEST_LOG_(severity) - logs messages at the specified severity level. The
00894 //                          message itself is streamed into the macro.
00895 //   LogToStderr()  - directs all log messages to stderr.
00896 //   FlushInfoLog() - flushes informational log messages.
00897 
00898 enum GTestLogSeverity {
00899   GTEST_INFO,
00900   GTEST_WARNING,
00901   GTEST_ERROR,
00902   GTEST_FATAL
00903 };
00904 
00905 // Formats log entry severity, provides a stream object for streaming the
00906 // log message, and terminates the message with a newline when going out of
00907 // scope.
00908 class GTEST_API_ GTestLog {
00909  public:
00910   GTestLog(GTestLogSeverity severity, const char* file, int line);
00911 
00912   // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
00913   ~GTestLog();
00914 
00915   ::std::ostream& GetStream() { return ::std::cerr; }
00916 
00917  private:
00918   const GTestLogSeverity severity_;
00919 
00920   GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
00921 };
00922 
00923 #define GTEST_LOG_(severity) \
00924     ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
00925                                   __FILE__, __LINE__).GetStream()
00926 
00927 inline void LogToStderr() {}
00928 inline void FlushInfoLog() { fflush(NULL); }
00929 
00930 // INTERNAL IMPLEMENTATION - DO NOT USE.
00931 //
00932 // GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
00933 // is not satisfied.
00934 //  Synopsys:
00935 //    GTEST_CHECK_(boolean_condition);
00936 //     or
00937 //    GTEST_CHECK_(boolean_condition) << "Additional message";
00938 //
00939 //    This checks the condition and if the condition is not satisfied
00940 //    it prints message about the condition violation, including the
00941 //    condition itself, plus additional message streamed into it, if any,
00942 //    and then it aborts the program. It aborts the program irrespective of
00943 //    whether it is built in the debug mode or not.
00944 #define GTEST_CHECK_(condition) \
00945     GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
00946     if (::testing::internal::IsTrue(condition)) \
00947       ; \
00948     else \
00949       GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
00950 
00951 // An all-mode assert to verify that the given POSIX-style function
00952 // call returns 0 (indicating success).  Known limitation: this
00953 // doesn't expand to a balanced 'if' statement, so enclose the macro
00954 // in {} if you need to use it as the only statement in an 'if'
00955 // branch.
00956 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
00957   if (const int gtest_error = (posix_call)) \
00958     GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
00959                       << gtest_error
00960 
00961 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
00962 //
00963 // Use ImplicitCast_ as a safe version of static_cast for upcasting in
00964 // the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
00965 // const Foo*).  When you use ImplicitCast_, the compiler checks that
00966 // the cast is safe.  Such explicit ImplicitCast_s are necessary in
00967 // surprisingly many situations where C++ demands an exact type match
00968 // instead of an argument type convertable to a target type.
00969 //
00970 // The syntax for using ImplicitCast_ is the same as for static_cast:
00971 //
00972 //   ImplicitCast_<ToType>(expr)
00973 //
00974 // ImplicitCast_ would have been part of the C++ standard library,
00975 // but the proposal was submitted too late.  It will probably make
00976 // its way into the language in the future.
00977 //
00978 // This relatively ugly name is intentional. It prevents clashes with
00979 // similar functions users may have (e.g., implicit_cast). The internal
00980 // namespace alone is not enough because the function can be found by ADL.
00981 template<typename To>
00982 inline To ImplicitCast_(To x) { return x; }
00983 
00984 // When you upcast (that is, cast a pointer from type Foo to type
00985 // SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
00986 // always succeed.  When you downcast (that is, cast a pointer from
00987 // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
00988 // how do you know the pointer is really of type SubclassOfFoo?  It
00989 // could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
00990 // when you downcast, you should use this macro.  In debug mode, we
00991 // use dynamic_cast<> to double-check the downcast is legal (we die
00992 // if it's not).  In normal mode, we do the efficient static_cast<>
00993 // instead.  Thus, it's important to test in debug mode to make sure
00994 // the cast is legal!
00995 //    This is the only place in the code we should use dynamic_cast<>.
00996 // In particular, you SHOULDN'T be using dynamic_cast<> in order to
00997 // do RTTI (eg code like this:
00998 //    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
00999 //    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
01000 // You should design the code some other way not to need this.
01001 //
01002 // This relatively ugly name is intentional. It prevents clashes with
01003 // similar functions users may have (e.g., down_cast). The internal
01004 // namespace alone is not enough because the function can be found by ADL.
01005 template<typename To, typename From>  // use like this: DownCast_<T*>(foo);
01006 inline To DownCast_(From* f) {  // so we only accept pointers
01007   // Ensures that To is a sub-type of From *.  This test is here only
01008   // for compile-time type checking, and has no overhead in an
01009   // optimized build at run-time, as it will be optimized away
01010   // completely.
01011   if (false) {
01012     const To to = NULL;
01013     ::testing::internal::ImplicitCast_<From*>(to);
01014   }
01015 
01016 #if GTEST_HAS_RTTI
01017   // RTTI: debug mode only!
01018   GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
01019 #endif
01020   return static_cast<To>(f);
01021 }
01022 
01023 // Downcasts the pointer of type Base to Derived.
01024 // Derived must be a subclass of Base. The parameter MUST
01025 // point to a class of type Derived, not any subclass of it.
01026 // When RTTI is available, the function performs a runtime
01027 // check to enforce this.
01028 template <class Derived, class Base>
01029 Derived* CheckedDowncastToActualType(Base* base) {
01030 #if GTEST_HAS_RTTI
01031   GTEST_CHECK_(typeid(*base) == typeid(Derived));
01032   return dynamic_cast<Derived*>(base);  // NOLINT
01033 #else
01034   return static_cast<Derived*>(base);  // Poor man's downcast.
01035 #endif
01036 }
01037 
01038 #if GTEST_HAS_STREAM_REDIRECTION
01039 
01040 // Defines the stderr capturer:
01041 //   CaptureStdout     - starts capturing stdout.
01042 //   GetCapturedStdout - stops capturing stdout and returns the captured string.
01043 //   CaptureStderr     - starts capturing stderr.
01044 //   GetCapturedStderr - stops capturing stderr and returns the captured string.
01045 //
01046 GTEST_API_ void CaptureStdout();
01047 GTEST_API_ String GetCapturedStdout();
01048 GTEST_API_ void CaptureStderr();
01049 GTEST_API_ String GetCapturedStderr();
01050 
01051 #endif  // GTEST_HAS_STREAM_REDIRECTION
01052 
01053 
01054 #if GTEST_HAS_DEATH_TEST
01055 
01056 // A copy of all command line arguments.  Set by InitGoogleTest().
01057 extern ::std::vector<String> g_argvs;
01058 
01059 // GTEST_HAS_DEATH_TEST implies we have ::std::string.
01060 const ::std::vector<String>& GetArgvs();
01061 
01062 #endif  // GTEST_HAS_DEATH_TEST
01063 
01064 // Defines synchronization primitives.
01065 
01066 #if GTEST_HAS_PTHREAD
01067 
01068 // Sleeps for (roughly) n milli-seconds.  This function is only for
01069 // testing Google Test's own constructs.  Don't use it in user tests,
01070 // either directly or indirectly.
01071 inline void SleepMilliseconds(int n) {
01072   const timespec time = {
01073     0,                  // 0 seconds.
01074     n * 1000L * 1000L,  // And n ms.
01075   };
01076   nanosleep(&time, NULL);
01077 }
01078 
01079 // Allows a controller thread to pause execution of newly created
01080 // threads until notified.  Instances of this class must be created
01081 // and destroyed in the controller thread.
01082 //
01083 // This class is only for testing Google Test's own constructs. Do not
01084 // use it in user tests, either directly or indirectly.
01085 class Notification {
01086  public:
01087   Notification() : notified_(false) {}
01088 
01089   // Notifies all threads created with this notification to start. Must
01090   // be called from the controller thread.
01091   void Notify() { notified_ = true; }
01092 
01093   // Blocks until the controller thread notifies. Must be called from a test
01094   // thread.
01095   void WaitForNotification() {
01096     while(!notified_) {
01097       SleepMilliseconds(10);
01098     }
01099   }
01100 
01101  private:
01102   volatile bool notified_;
01103 
01104   GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
01105 };
01106 
01107 // As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
01108 // Consequently, it cannot select a correct instantiation of ThreadWithParam
01109 // in order to call its Run(). Introducing ThreadWithParamBase as a
01110 // non-templated base class for ThreadWithParam allows us to bypass this
01111 // problem.
01112 class ThreadWithParamBase {
01113  public:
01114   virtual ~ThreadWithParamBase() {}
01115   virtual void Run() = 0;
01116 };
01117 
01118 // pthread_create() accepts a pointer to a function type with the C linkage.
01119 // According to the Standard (7.5/1), function types with different linkages
01120 // are different even if they are otherwise identical.  Some compilers (for
01121 // example, SunStudio) treat them as different types.  Since class methods
01122 // cannot be defined with C-linkage we need to define a free C-function to
01123 // pass into pthread_create().
01124 extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
01125   static_cast<ThreadWithParamBase*>(thread)->Run();
01126   return NULL;
01127 }
01128 
01129 // Helper class for testing Google Test's multi-threading constructs.
01130 // To use it, write:
01131 //
01132 //   void ThreadFunc(int param) { /* Do things with param */ }
01133 //   Notification thread_can_start;
01134 //   ...
01135 //   // The thread_can_start parameter is optional; you can supply NULL.
01136 //   ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
01137 //   thread_can_start.Notify();
01138 //
01139 // These classes are only for testing Google Test's own constructs. Do
01140 // not use them in user tests, either directly or indirectly.
01141 template <typename T>
01142 class ThreadWithParam : public ThreadWithParamBase {
01143  public:
01144   typedef void (*UserThreadFunc)(T);
01145 
01146   ThreadWithParam(
01147       UserThreadFunc func, T param, Notification* thread_can_start)
01148       : func_(func),
01149         param_(param),
01150         thread_can_start_(thread_can_start),
01151         finished_(false) {
01152     ThreadWithParamBase* const base = this;
01153     // The thread can be created only after all fields except thread_
01154     // have been initialized.
01155     GTEST_CHECK_POSIX_SUCCESS_(
01156         pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
01157   }
01158   ~ThreadWithParam() { Join(); }
01159 
01160   void Join() {
01161     if (!finished_) {
01162       GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
01163       finished_ = true;
01164     }
01165   }
01166 
01167   virtual void Run() {
01168     if (thread_can_start_ != NULL)
01169       thread_can_start_->WaitForNotification();
01170     func_(param_);
01171   }
01172 
01173  private:
01174   const UserThreadFunc func_;  // User-supplied thread function.
01175   const T param_;  // User-supplied parameter to the thread function.
01176   // When non-NULL, used to block execution until the controller thread
01177   // notifies.
01178   Notification* const thread_can_start_;
01179   bool finished_;  // true iff we know that the thread function has finished.
01180   pthread_t thread_;  // The native thread object.
01181 
01182   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
01183 };
01184 
01185 // MutexBase and Mutex implement mutex on pthreads-based platforms. They
01186 // are used in conjunction with class MutexLock:
01187 //
01188 //   Mutex mutex;
01189 //   ...
01190 //   MutexLock lock(&mutex);  // Acquires the mutex and releases it at the end
01191 //                            // of the current scope.
01192 //
01193 // MutexBase implements behavior for both statically and dynamically
01194 // allocated mutexes.  Do not use MutexBase directly.  Instead, write
01195 // the following to define a static mutex:
01196 //
01197 //   GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
01198 //
01199 // You can forward declare a static mutex like this:
01200 //
01201 //   GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
01202 //
01203 // To create a dynamic mutex, just define an object of type Mutex.
01204 class MutexBase {
01205  public:
01206   // Acquires this mutex.
01207   void Lock() {
01208     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
01209     owner_ = pthread_self();
01210   }
01211 
01212   // Releases this mutex.
01213   void Unlock() {
01214     // We don't protect writing to owner_ here, as it's the caller's
01215     // responsibility to ensure that the current thread holds the
01216     // mutex when this is called.
01217     owner_ = 0;
01218     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
01219   }
01220 
01221   // Does nothing if the current thread holds the mutex. Otherwise, crashes
01222   // with high probability.
01223   void AssertHeld() const {
01224     GTEST_CHECK_(owner_ == pthread_self())
01225         << "The current thread is not holding the mutex @" << this;
01226   }
01227 
01228   // A static mutex may be used before main() is entered.  It may even
01229   // be used before the dynamic initialization stage.  Therefore we
01230   // must be able to initialize a static mutex object at link time.
01231   // This means MutexBase has to be a POD and its member variables
01232   // have to be public.
01233  public:
01234   pthread_mutex_t mutex_;  // The underlying pthread mutex.
01235   pthread_t owner_;  // The thread holding the mutex; 0 means no one holds it.
01236 };
01237 
01238 // Forward-declares a static mutex.
01239 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
01240     extern ::testing::internal::MutexBase mutex
01241 
01242 // Defines and statically (i.e. at link time) initializes a static mutex.
01243 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
01244     ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 }
01245 
01246 // The Mutex class can only be used for mutexes created at runtime. It
01247 // shares its API with MutexBase otherwise.
01248 class Mutex : public MutexBase {
01249  public:
01250   Mutex() {
01251     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
01252     owner_ = 0;
01253   }
01254   ~Mutex() {
01255     GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
01256   }
01257 
01258  private:
01259   GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
01260 };
01261 
01262 // We cannot name this class MutexLock as the ctor declaration would
01263 // conflict with a macro named MutexLock, which is defined on some
01264 // platforms.  Hence the typedef trick below.
01265 class GTestMutexLock {
01266  public:
01267   explicit GTestMutexLock(MutexBase* mutex)
01268       : mutex_(mutex) { mutex_->Lock(); }
01269 
01270   ~GTestMutexLock() { mutex_->Unlock(); }
01271 
01272  private:
01273   MutexBase* const mutex_;
01274 
01275   GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
01276 };
01277 
01278 typedef GTestMutexLock MutexLock;
01279 
01280 // Helpers for ThreadLocal.
01281 
01282 // pthread_key_create() requires DeleteThreadLocalValue() to have
01283 // C-linkage.  Therefore it cannot be templatized to access
01284 // ThreadLocal<T>.  Hence the need for class
01285 // ThreadLocalValueHolderBase.
01286 class ThreadLocalValueHolderBase {
01287  public:
01288   virtual ~ThreadLocalValueHolderBase() {}
01289 };
01290 
01291 // Called by pthread to delete thread-local data stored by
01292 // pthread_setspecific().
01293 extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
01294   delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
01295 }
01296 
01297 // Implements thread-local storage on pthreads-based systems.
01298 //
01299 //   // Thread 1
01300 //   ThreadLocal<int> tl(100);  // 100 is the default value for each thread.
01301 //
01302 //   // Thread 2
01303 //   tl.set(150);  // Changes the value for thread 2 only.
01304 //   EXPECT_EQ(150, tl.get());
01305 //
01306 //   // Thread 1
01307 //   EXPECT_EQ(100, tl.get());  // In thread 1, tl has the original value.
01308 //   tl.set(200);
01309 //   EXPECT_EQ(200, tl.get());
01310 //
01311 // The template type argument T must have a public copy constructor.
01312 // In addition, the default ThreadLocal constructor requires T to have
01313 // a public default constructor.
01314 //
01315 // An object managed for a thread by a ThreadLocal instance is deleted
01316 // when the thread exits.  Or, if the ThreadLocal instance dies in
01317 // that thread, when the ThreadLocal dies.  It's the user's
01318 // responsibility to ensure that all other threads using a ThreadLocal
01319 // have exited when it dies, or the per-thread objects for those
01320 // threads will not be deleted.
01321 //
01322 // Google Test only uses global ThreadLocal objects.  That means they
01323 // will die after main() has returned.  Therefore, no per-thread
01324 // object managed by Google Test will be leaked as long as all threads
01325 // using Google Test have exited when main() returns.
01326 template <typename T>
01327 class ThreadLocal {
01328  public:
01329   ThreadLocal() : key_(CreateKey()),
01330                   default_() {}
01331   explicit ThreadLocal(const T& value) : key_(CreateKey()),
01332                                          default_(value) {}
01333 
01334   ~ThreadLocal() {
01335     // Destroys the managed object for the current thread, if any.
01336     DeleteThreadLocalValue(pthread_getspecific(key_));
01337 
01338     // Releases resources associated with the key.  This will *not*
01339     // delete managed objects for other threads.
01340     GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
01341   }
01342 
01343   T* pointer() { return GetOrCreateValue(); }
01344   const T* pointer() const { return GetOrCreateValue(); }
01345   const T& get() const { return *pointer(); }
01346   void set(const T& value) { *pointer() = value; }
01347 
01348  private:
01349   // Holds a value of type T.
01350   class ValueHolder : public ThreadLocalValueHolderBase {
01351    public:
01352     explicit ValueHolder(const T& value) : value_(value) {}
01353 
01354     T* pointer() { return &value_; }
01355 
01356    private:
01357     T value_;
01358     GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
01359   };
01360 
01361   static pthread_key_t CreateKey() {
01362     pthread_key_t key;
01363     // When a thread exits, DeleteThreadLocalValue() will be called on
01364     // the object managed for that thread.
01365     GTEST_CHECK_POSIX_SUCCESS_(
01366         pthread_key_create(&key, &DeleteThreadLocalValue));
01367     return key;
01368   }
01369 
01370   T* GetOrCreateValue() const {
01371     ThreadLocalValueHolderBase* const holder =
01372         static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
01373     if (holder != NULL) {
01374       return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
01375     }
01376 
01377     ValueHolder* const new_holder = new ValueHolder(default_);
01378     ThreadLocalValueHolderBase* const holder_base = new_holder;
01379     GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
01380     return new_holder->pointer();
01381   }
01382 
01383   // A key pthreads uses for looking up per-thread values.
01384   const pthread_key_t key_;
01385   const T default_;  // The default value for each thread.
01386 
01387   GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
01388 };
01389 
01390 # define GTEST_IS_THREADSAFE 1
01391 
01392 #else  // GTEST_HAS_PTHREAD
01393 
01394 // A dummy implementation of synchronization primitives (mutex, lock,
01395 // and thread-local variable).  Necessary for compiling Google Test where
01396 // mutex is not supported - using Google Test in multiple threads is not
01397 // supported on such platforms.
01398 
01399 class Mutex {
01400  public:
01401   Mutex() {}
01402   void AssertHeld() const {}
01403 };
01404 
01405 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
01406   extern ::testing::internal::Mutex mutex
01407 
01408 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
01409 
01410 class GTestMutexLock {
01411  public:
01412   explicit GTestMutexLock(Mutex*) {}  // NOLINT
01413 };
01414 
01415 typedef GTestMutexLock MutexLock;
01416 
01417 template <typename T>
01418 class ThreadLocal {
01419  public:
01420   ThreadLocal() : value_() {}
01421   explicit ThreadLocal(const T& value) : value_(value) {}
01422   T* pointer() { return &value_; }
01423   const T* pointer() const { return &value_; }
01424   const T& get() const { return value_; }
01425   void set(const T& value) { value_ = value; }
01426  private:
01427   T value_;
01428 };
01429 
01430 // The above synchronization primitives have dummy implementations.
01431 // Therefore Google Test is not thread-safe.
01432 # define GTEST_IS_THREADSAFE 0
01433 
01434 #endif  // GTEST_HAS_PTHREAD
01435 
01436 // Returns the number of threads running in the process, or 0 to indicate that
01437 // we cannot detect it.
01438 GTEST_API_ size_t GetThreadCount();
01439 
01440 // Passing non-POD classes through ellipsis (...) crashes the ARM
01441 // compiler and generates a warning in Sun Studio.  The Nokia Symbian
01442 // and the IBM XL C/C++ compiler try to instantiate a copy constructor
01443 // for objects passed through ellipsis (...), failing for uncopyable
01444 // objects.  We define this to ensure that only POD is passed through
01445 // ellipsis on these systems.
01446 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
01447 // We lose support for NULL detection where the compiler doesn't like
01448 // passing non-POD classes through ellipsis (...).
01449 # define GTEST_ELLIPSIS_NEEDS_POD_ 1
01450 #else
01451 # define GTEST_CAN_COMPARE_NULL 1
01452 #endif
01453 
01454 // The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
01455 // const T& and const T* in a function template.  These compilers
01456 // _can_ decide between class template specializations for T and T*,
01457 // so a tr1::type_traits-like is_pointer works.
01458 #if defined(__SYMBIAN32__) || defined(__IBMCPP__)
01459 # define GTEST_NEEDS_IS_POINTER_ 1
01460 #endif
01461 
01462 template <bool bool_value>
01463 struct bool_constant {
01464   typedef bool_constant<bool_value> type;
01465   static const bool value = bool_value;
01466 };
01467 template <bool bool_value> const bool bool_constant<bool_value>::value;
01468 
01469 typedef bool_constant<false> false_type;
01470 typedef bool_constant<true> true_type;
01471 
01472 template <typename T>
01473 struct is_pointer : public false_type {};
01474 
01475 template <typename T>
01476 struct is_pointer<T*> : public true_type {};
01477 
01478 template <typename Iterator>
01479 struct IteratorTraits {
01480   typedef typename Iterator::value_type value_type;
01481 };
01482 
01483 template <typename T>
01484 struct IteratorTraits<T*> {
01485   typedef T value_type;
01486 };
01487 
01488 template <typename T>
01489 struct IteratorTraits<const T*> {
01490   typedef T value_type;
01491 };
01492 
01493 #if GTEST_OS_WINDOWS
01494 # define GTEST_PATH_SEP_ "\\"
01495 # define GTEST_HAS_ALT_PATH_SEP_ 1
01496 // The biggest signed integer type the compiler supports.
01497 typedef __int64 BiggestInt;
01498 #else
01499 # define GTEST_PATH_SEP_ "/"
01500 # define GTEST_HAS_ALT_PATH_SEP_ 0
01501 typedef long long BiggestInt;  // NOLINT
01502 #endif  // GTEST_OS_WINDOWS
01503 
01504 // Utilities for char.
01505 
01506 // isspace(int ch) and friends accept an unsigned char or EOF.  char
01507 // may be signed, depending on the compiler (or compiler flags).
01508 // Therefore we need to cast a char to unsigned char before calling
01509 // isspace(), etc.
01510 
01511 inline bool IsAlpha(char ch) {
01512   return isalpha(static_cast<unsigned char>(ch)) != 0;
01513 }
01514 inline bool IsAlNum(char ch) {
01515   return isalnum(static_cast<unsigned char>(ch)) != 0;
01516 }
01517 inline bool IsDigit(char ch) {
01518   return isdigit(static_cast<unsigned char>(ch)) != 0;
01519 }
01520 inline bool IsLower(char ch) {
01521   return islower(static_cast<unsigned char>(ch)) != 0;
01522 }
01523 inline bool IsSpace(char ch) {
01524   return isspace(static_cast<unsigned char>(ch)) != 0;
01525 }
01526 inline bool IsUpper(char ch) {
01527   return isupper(static_cast<unsigned char>(ch)) != 0;
01528 }
01529 inline bool IsXDigit(char ch) {
01530   return isxdigit(static_cast<unsigned char>(ch)) != 0;
01531 }
01532 
01533 inline char ToLower(char ch) {
01534   return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
01535 }
01536 inline char ToUpper(char ch) {
01537   return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
01538 }
01539 
01540 // The testing::internal::posix namespace holds wrappers for common
01541 // POSIX functions.  These wrappers hide the differences between
01542 // Windows/MSVC and POSIX systems.  Since some compilers define these
01543 // standard functions as macros, the wrapper cannot have the same name
01544 // as the wrapped function.
01545 
01546 namespace posix {
01547 
01548 // Functions with a different name on Windows.
01549 
01550 #if GTEST_OS_WINDOWS
01551 
01552 typedef struct _stat StatStruct;
01553 
01554 # ifdef __BORLANDC__
01555 inline int IsATTY(int fd) { return isatty(fd); }
01556 inline int StrCaseCmp(const char* s1, const char* s2) {
01557   return stricmp(s1, s2);
01558 }
01559 inline char* StrDup(const char* src) { return strdup(src); }
01560 # else  // !__BORLANDC__
01561 #  if GTEST_OS_WINDOWS_MOBILE
01562 inline int IsATTY(int /* fd */) { return 0; }
01563 #  else
01564 inline int IsATTY(int fd) { return _isatty(fd); }
01565 #  endif  // GTEST_OS_WINDOWS_MOBILE
01566 inline int StrCaseCmp(const char* s1, const char* s2) {
01567   return _stricmp(s1, s2);
01568 }
01569 inline char* StrDup(const char* src) { return _strdup(src); }
01570 # endif  // __BORLANDC__
01571 
01572 # if GTEST_OS_WINDOWS_MOBILE
01573 inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
01574 // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
01575 // time and thus not defined there.
01576 # else
01577 inline int FileNo(FILE* file) { return _fileno(file); }
01578 inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
01579 inline int RmDir(const char* dir) { return _rmdir(dir); }
01580 inline bool IsDir(const StatStruct& st) {
01581   return (_S_IFDIR & st.st_mode) != 0;
01582 }
01583 # endif  // GTEST_OS_WINDOWS_MOBILE
01584 
01585 #else
01586 
01587 typedef struct stat StatStruct;
01588 
01589 inline int FileNo(FILE* file) { return fileno(file); }
01590 inline int IsATTY(int fd) { return isatty(fd); }
01591 inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
01592 inline int StrCaseCmp(const char* s1, const char* s2) {
01593   return strcasecmp(s1, s2);
01594 }
01595 inline char* StrDup(const char* src) { return strdup(src); }
01596 inline int RmDir(const char* dir) { return rmdir(dir); }
01597 inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
01598 
01599 #endif  // GTEST_OS_WINDOWS
01600 
01601 // Functions deprecated by MSVC 8.0.
01602 
01603 #ifdef _MSC_VER
01604 // Temporarily disable warning 4996 (deprecated function).
01605 # pragma warning(push)
01606 # pragma warning(disable:4996)
01607 #endif
01608 
01609 inline const char* StrNCpy(char* dest, const char* src, size_t n) {
01610   return strncpy(dest, src, n);
01611 }
01612 
01613 // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
01614 // StrError() aren't needed on Windows CE at this time and thus not
01615 // defined there.
01616 
01617 #if !GTEST_OS_WINDOWS_MOBILE
01618 inline int ChDir(const char* dir) { return chdir(dir); }
01619 #endif
01620 inline FILE* FOpen(const char* path, const char* mode) {
01621   return fopen(path, mode);
01622 }
01623 #if !GTEST_OS_WINDOWS_MOBILE
01624 inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
01625   return freopen(path, mode, stream);
01626 }
01627 inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
01628 #endif
01629 inline int FClose(FILE* fp) { return fclose(fp); }
01630 #if !GTEST_OS_WINDOWS_MOBILE
01631 inline int Read(int fd, void* buf, unsigned int count) {
01632   return static_cast<int>(read(fd, buf, count));
01633 }
01634 inline int Write(int fd, const void* buf, unsigned int count) {
01635   return static_cast<int>(write(fd, buf, count));
01636 }
01637 inline int Close(int fd) { return close(fd); }
01638 inline const char* StrError(int errnum) { return strerror(errnum); }
01639 #endif
01640 inline const char* GetEnv(const char* name) {
01641 #if GTEST_OS_WINDOWS_MOBILE
01642   // We are on Windows CE, which has no environment variables.
01643   return NULL;
01644 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
01645   // Environment variables which we programmatically clear will be set to the
01646   // empty string rather than unset (NULL).  Handle that case.
01647   const char* const env = getenv(name);
01648   return (env != NULL && env[0] != '\0') ? env : NULL;
01649 #else
01650   return getenv(name);
01651 #endif
01652 }
01653 
01654 #ifdef _MSC_VER
01655 # pragma warning(pop)  // Restores the warning state.
01656 #endif
01657 
01658 #if GTEST_OS_WINDOWS_MOBILE
01659 // Windows CE has no C library. The abort() function is used in
01660 // several places in Google Test. This implementation provides a reasonable
01661 // imitation of standard behaviour.
01662 void Abort();
01663 #else
01664 inline void Abort() { abort(); }
01665 #endif  // GTEST_OS_WINDOWS_MOBILE
01666 
01667 }  // namespace posix
01668 
01669 // The maximum number a BiggestInt can represent.  This definition
01670 // works no matter BiggestInt is represented in one's complement or
01671 // two's complement.
01672 //
01673 // We cannot rely on numeric_limits in STL, as __int64 and long long
01674 // are not part of standard C++ and numeric_limits doesn't need to be
01675 // defined for them.
01676 const BiggestInt kMaxBiggestInt =
01677     ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
01678 
01679 // This template class serves as a compile-time function from size to
01680 // type.  It maps a size in bytes to a primitive type with that
01681 // size. e.g.
01682 //
01683 //   TypeWithSize<4>::UInt
01684 //
01685 // is typedef-ed to be unsigned int (unsigned integer made up of 4
01686 // bytes).
01687 //
01688 // Such functionality should belong to STL, but I cannot find it
01689 // there.
01690 //
01691 // Google Test uses this class in the implementation of floating-point
01692 // comparison.
01693 //
01694 // For now it only handles UInt (unsigned int) as that's all Google Test
01695 // needs.  Other types can be easily added in the future if need
01696 // arises.
01697 template <size_t size>
01698 class TypeWithSize {
01699  public:
01700   // This prevents the user from using TypeWithSize<N> with incorrect
01701   // values of N.
01702   typedef void UInt;
01703 };
01704 
01705 // The specialization for size 4.
01706 template <>
01707 class TypeWithSize<4> {
01708  public:
01709   // unsigned int has size 4 in both gcc and MSVC.
01710   //
01711   // As base/basictypes.h doesn't compile on Windows, we cannot use
01712   // uint32, uint64, and etc here.
01713   typedef int Int;
01714   typedef unsigned int UInt;
01715 };
01716 
01717 // The specialization for size 8.
01718 template <>
01719 class TypeWithSize<8> {
01720  public:
01721 
01722 #if GTEST_OS_WINDOWS
01723   typedef __int64 Int;
01724   typedef unsigned __int64 UInt;
01725 #else
01726   typedef long long Int;  // NOLINT
01727   typedef unsigned long long UInt;  // NOLINT
01728 #endif  // GTEST_OS_WINDOWS
01729 };
01730 
01731 // Integer types of known sizes.
01732 typedef TypeWithSize<4>::Int Int32;
01733 typedef TypeWithSize<4>::UInt UInt32;
01734 typedef TypeWithSize<8>::Int Int64;
01735 typedef TypeWithSize<8>::UInt UInt64;
01736 typedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.
01737 
01738 // Utilities for command line flags and environment variables.
01739 
01740 // Macro for referencing flags.
01741 #define GTEST_FLAG(name) FLAGS_gtest_##name
01742 
01743 // Macros for declaring flags.
01744 #define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
01745 #define GTEST_DECLARE_int32_(name) \
01746     GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
01747 #define GTEST_DECLARE_string_(name) \
01748     GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name)
01749 
01750 // Macros for defining flags.
01751 #define GTEST_DEFINE_bool_(name, default_val, doc) \
01752     GTEST_API_ bool GTEST_FLAG(name) = (default_val)
01753 #define GTEST_DEFINE_int32_(name, default_val, doc) \
01754     GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
01755 #define GTEST_DEFINE_string_(name, default_val, doc) \
01756     GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
01757 
01758 // Parses 'str' for a 32-bit signed integer.  If successful, writes the result
01759 // to *value and returns true; otherwise leaves *value unchanged and returns
01760 // false.
01761 // TODO(chandlerc): Find a better way to refactor flag and environment parsing
01762 // out of both gtest-port.cc and gtest.cc to avoid exporting this utility
01763 // function.
01764 bool ParseInt32(const Message& src_text, const char* str, Int32* value);
01765 
01766 // Parses a bool/Int32/string from the environment variable
01767 // corresponding to the given Google Test flag.
01768 bool BoolFromGTestEnv(const char* flag, bool default_val);
01769 GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
01770 const char* StringFromGTestEnv(const char* flag, const char* default_val);
01771 
01772 }  // namespace internal
01773 }  // namespace testing
01774 
01775 #endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:24:39