1// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8//     * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10//     * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14//     * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Author: wan@google.com (Zhanyong Wan)
31//
32// The Google C++ Testing Framework (Google Test)
33//
34// This header file defines the public API for Google Test.  It should be
35// included by any test program that uses Google Test.
36//
37// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
38// leave some internal implementation details in this header file.
39// They are clearly marked by comments like this:
40//
41//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
42//
43// Such code is NOT meant to be used by a user directly, and is subject
44// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
45// program!
46//
47// Acknowledgment: Google Test borrowed the idea of automatic test
48// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
49// easyUnit framework.
50
51#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
52#define GTEST_INCLUDE_GTEST_GTEST_H_
53
54#include <limits>
55#include <ostream>
56#include <vector>
57
58// Copyright 2005, Google Inc.
59// All rights reserved.
60//
61// Redistribution and use in source and binary forms, with or without
62// modification, are permitted provided that the following conditions are
63// met:
64//
65//     * Redistributions of source code must retain the above copyright
66// notice, this list of conditions and the following disclaimer.
67//     * Redistributions in binary form must reproduce the above
68// copyright notice, this list of conditions and the following disclaimer
69// in the documentation and/or other materials provided with the
70// distribution.
71//     * Neither the name of Google Inc. nor the names of its
72// contributors may be used to endorse or promote products derived from
73// this software without specific prior written permission.
74//
75// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
76// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
77// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
78// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
79// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
81// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86//
87// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
88//
89// The Google C++ Testing Framework (Google Test)
90//
91// This header file declares functions and macros used internally by
92// Google Test.  They are subject to change without notice.
93
94#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
95#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
96
97// Copyright 2005, Google Inc.
98// All rights reserved.
99//
100// Redistribution and use in source and binary forms, with or without
101// modification, are permitted provided that the following conditions are
102// met:
103//
104//     * Redistributions of source code must retain the above copyright
105// notice, this list of conditions and the following disclaimer.
106//     * Redistributions in binary form must reproduce the above
107// copyright notice, this list of conditions and the following disclaimer
108// in the documentation and/or other materials provided with the
109// distribution.
110//     * Neither the name of Google Inc. nor the names of its
111// contributors may be used to endorse or promote products derived from
112// this software without specific prior written permission.
113//
114// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
115// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
116// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
117// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
118// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
119// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
120// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
121// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
122// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
124// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
125//
126// Authors: wan@google.com (Zhanyong Wan)
127//
128// Low-level types and utilities for porting Google Test to various
129// platforms.  They are subject to change without notice.  DO NOT USE
130// THEM IN USER CODE.
131//
132// This file is fundamental to Google Test.  All other Google Test source
133// files are expected to #include this.  Therefore, it cannot #include
134// any other Google Test header.
135
136#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
137#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
138
139// The user can define the following macros in the build script to
140// control Google Test's behavior.  If the user doesn't define a macro
141// in this list, Google Test will define it.
142//
143//   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)
144//                              is/isn't available.
145//   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions
146//                              are enabled.
147//   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string
148//                              is/isn't available (some systems define
149//                              ::string, which is different to std::string).
150//   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
151//                              is/isn't available (some systems define
152//                              ::wstring, which is different to std::wstring).
153//   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular
154//                              expressions are/aren't available.
155//   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>
156//                              is/isn't available.
157//   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't
158//                              enabled.
159//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
160//                              std::wstring does/doesn't work (Google Test can
161//                              be used where std::wstring is unavailable).
162//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
163//                              is/isn't available.
164//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
165//                              compiler supports Microsoft's "Structured
166//                              Exception Handling".
167//   GTEST_HAS_STREAM_REDIRECTION
168//                            - Define it to 1/0 to indicate whether the
169//                              platform supports I/O stream redirection using
170//                              dup() and dup2().
171//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
172//                              Test's own tr1 tuple implementation should be
173//                              used.  Unused when the user sets
174//                              GTEST_HAS_TR1_TUPLE to 0.
175//   GTEST_LANG_CXX11         - Define it to 1/0 to indicate that Google Test
176//                              is building in C++11/C++98 mode.
177//   GTEST_LINKED_AS_SHARED_LIBRARY
178//                            - Define to 1 when compiling tests that use
179//                              Google Test as a shared library (known as
180//                              DLL on Windows).
181//   GTEST_CREATE_SHARED_LIBRARY
182//                            - Define to 1 when compiling Google Test itself
183//                              as a shared library.
184
185// This header defines the following utilities:
186//
187// Macros indicating the current platform (defined to 1 if compiled on
188// the given platform; otherwise undefined):
189//   GTEST_OS_AIX      - IBM AIX
190//   GTEST_OS_CYGWIN   - Cygwin
191//   GTEST_OS_HPUX     - HP-UX
192//   GTEST_OS_LINUX    - Linux
193//     GTEST_OS_LINUX_ANDROID - Google Android
194//   GTEST_OS_MAC      - Mac OS X
195//     GTEST_OS_IOS    - iOS
196//       GTEST_OS_IOS_SIMULATOR - iOS simulator
197//   GTEST_OS_NACL     - Google Native Client (NaCl)
198//   GTEST_OS_OPENBSD  - OpenBSD
199//   GTEST_OS_QNX      - QNX
200//   GTEST_OS_SOLARIS  - Sun Solaris
201//   GTEST_OS_SYMBIAN  - Symbian
202//   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
203//     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop
204//     GTEST_OS_WINDOWS_MINGW    - MinGW
205//     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile
206//   GTEST_OS_ZOS      - z/OS
207//
208// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
209// most stable support.  Since core members of the Google Test project
210// don't have access to other platforms, support for them may be less
211// stable.  If you notice any problems on your platform, please notify
212// googletestframework@googlegroups.com (patches for fixing them are
213// even more welcome!).
214//
215// Note that it is possible that none of the GTEST_OS_* macros are defined.
216//
217// Macros indicating available Google Test features (defined to 1 if
218// the corresponding feature is supported; otherwise undefined):
219//   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized
220//                            tests)
221//   GTEST_HAS_DEATH_TEST   - death tests
222//   GTEST_HAS_PARAM_TEST   - value-parameterized tests
223//   GTEST_HAS_TYPED_TEST   - typed tests
224//   GTEST_HAS_TYPED_TEST_P - type-parameterized tests
225//   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with
226//                            GTEST_HAS_POSIX_RE (see above) which users can
227//                            define themselves.
228//   GTEST_USES_SIMPLE_RE   - our own simple regex is used;
229//                            the above two are mutually exclusive.
230//   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
231//
232// Macros for basic C++ coding:
233//   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
234//   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a
235//                              variable don't have to be used.
236//   GTEST_DISALLOW_ASSIGN_   - disables operator=.
237//   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
238//   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
239//
240// Synchronization:
241//   Mutex, MutexLock, ThreadLocal, GetThreadCount()
242//                  - synchronization primitives.
243//   GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
244//                         synchronization primitives have real implementations
245//                         and Google Test is thread-safe; or 0 otherwise.
246//
247// Template meta programming:
248//   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.
249//   IteratorTraits - partial implementation of std::iterator_traits, which
250//                    is not available in libCstd when compiled with Sun C++.
251//
252// Smart pointers:
253//   scoped_ptr     - as in TR2.
254//
255// Regular expressions:
256//   RE             - a simple regular expression class using the POSIX
257//                    Extended Regular Expression syntax on UNIX-like
258//                    platforms, or a reduced regular exception syntax on
259//                    other platforms, including Windows.
260//
261// Logging:
262//   GTEST_LOG_()   - logs messages at the specified severity level.
263//   LogToStderr()  - directs all log messages to stderr.
264//   FlushInfoLog() - flushes informational log messages.
265//
266// Stdout and stderr capturing:
267//   CaptureStdout()     - starts capturing stdout.
268//   GetCapturedStdout() - stops capturing stdout and returns the captured
269//                         string.
270//   CaptureStderr()     - starts capturing stderr.
271//   GetCapturedStderr() - stops capturing stderr and returns the captured
272//                         string.
273//
274// Integer types:
275//   TypeWithSize   - maps an integer to a int type.
276//   Int32, UInt32, Int64, UInt64, TimeInMillis
277//                  - integers of known sizes.
278//   BiggestInt     - the biggest signed integer type.
279//
280// Command-line utilities:
281//   GTEST_FLAG()       - references a flag.
282//   GTEST_DECLARE_*()  - declares a flag.
283//   GTEST_DEFINE_*()   - defines a flag.
284//   GetInjectableArgvs() - returns the command line as a vector of strings.
285//
286// Environment variable utilities:
287//   GetEnv()             - gets the value of an environment variable.
288//   BoolFromGTestEnv()   - parses a bool environment variable.
289//   Int32FromGTestEnv()  - parses an Int32 environment variable.
290//   StringFromGTestEnv() - parses a string environment variable.
291
292#include <ctype.h>   // for isspace, etc
293#include <stddef.h>  // for ptrdiff_t
294#include <stdlib.h>
295#include <stdio.h>
296#include <string.h>
297#ifndef _WIN32_WCE
298# include <sys/types.h>
299# include <sys/stat.h>
300#endif  // !_WIN32_WCE
301
302#if defined __APPLE__
303# include <AvailabilityMacros.h>
304# include <TargetConditionals.h>
305#endif
306
307#include <iostream>  // NOLINT
308#include <sstream>  // NOLINT
309#include <string>  // NOLINT
310
311#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
312#define GTEST_FLAG_PREFIX_ "gtest_"
313#define GTEST_FLAG_PREFIX_DASH_ "gtest-"
314#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
315#define GTEST_NAME_ "Google Test"
316#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
317
318// Determines the version of gcc that is used to compile this.
319#ifdef __GNUC__
320// 40302 means version 4.3.2.
321# define GTEST_GCC_VER_ \
322    (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
323#endif  // __GNUC__
324
325// Determines the platform on which Google Test is compiled.
326#ifdef __CYGWIN__
327# define GTEST_OS_CYGWIN 1
328#elif defined __SYMBIAN32__
329# define GTEST_OS_SYMBIAN 1
330#elif defined _WIN32
331# define GTEST_OS_WINDOWS 1
332# ifdef _WIN32_WCE
333#  define GTEST_OS_WINDOWS_MOBILE 1
334# elif defined(__MINGW__) || defined(__MINGW32__)
335#  define GTEST_OS_WINDOWS_MINGW 1
336# else
337#  define GTEST_OS_WINDOWS_DESKTOP 1
338# endif  // _WIN32_WCE
339#elif defined __APPLE__
340# define GTEST_OS_MAC 1
341# if TARGET_OS_IPHONE
342#  define GTEST_OS_IOS 1
343#  if TARGET_IPHONE_SIMULATOR
344#   define GTEST_OS_IOS_SIMULATOR 1
345#  endif
346# endif
347#elif defined __linux__
348# define GTEST_OS_LINUX 1
349# if defined __ANDROID__
350#  define GTEST_OS_LINUX_ANDROID 1
351# endif
352#elif defined __MVS__
353# define GTEST_OS_ZOS 1
354#elif defined(__sun) && defined(__SVR4)
355# define GTEST_OS_SOLARIS 1
356#elif defined(_AIX)
357# define GTEST_OS_AIX 1
358#elif defined(__hpux)
359# define GTEST_OS_HPUX 1
360#elif defined __native_client__
361# define GTEST_OS_NACL 1
362#elif defined __OpenBSD__
363# define GTEST_OS_OPENBSD 1
364#elif defined __QNX__
365# define GTEST_OS_QNX 1
366#endif  // __CYGWIN__
367
368#ifndef GTEST_LANG_CXX11
369// gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when
370// -std={c,gnu}++{0x,11} is passed.  The C++11 standard specifies a
371// value for __cplusplus, and recent versions of clang, gcc, and
372// probably other compilers set that too in C++11 mode.
373# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
374// Compiling in at least C++11 mode.
375#  define GTEST_LANG_CXX11 1
376# else
377#  define GTEST_LANG_CXX11 0
378# endif
379#endif
380
381// Brings in definitions for functions used in the testing::internal::posix
382// namespace (read, write, close, chdir, isatty, stat). We do not currently
383// use them on Windows Mobile.
384#if !GTEST_OS_WINDOWS
385// This assumes that non-Windows OSes provide unistd.h. For OSes where this
386// is not the case, we need to include headers that provide the functions
387// mentioned above.
388# include <unistd.h>
389# include <strings.h>
390#elif !GTEST_OS_WINDOWS_MOBILE
391# include <direct.h>
392# include <io.h>
393#endif
394
395#if GTEST_OS_LINUX_ANDROID
396// Used to define __ANDROID_API__ matching the target NDK API level.
397#  include <android/api-level.h>  // NOLINT
398#endif
399
400// Defines this to true iff Google Test can use POSIX regular expressions.
401#ifndef GTEST_HAS_POSIX_RE
402# if GTEST_OS_LINUX_ANDROID
403// On Android, <regex.h> is only available starting with Gingerbread.
404#  define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
405# else
406#  define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
407# endif
408#endif
409
410#if GTEST_HAS_POSIX_RE
411
412// On some platforms, <regex.h> needs someone to define size_t, and
413// won't compile otherwise.  We can #include it here as we already
414// included <stdlib.h>, which is guaranteed to define size_t through
415// <stddef.h>.
416# include <regex.h>  // NOLINT
417
418# define GTEST_USES_POSIX_RE 1
419
420#elif GTEST_OS_WINDOWS
421
422// <regex.h> is not available on Windows.  Use our own simple regex
423// implementation instead.
424# define GTEST_USES_SIMPLE_RE 1
425
426#else
427
428// <regex.h> may not be available on this platform.  Use our own
429// simple regex implementation instead.
430# define GTEST_USES_SIMPLE_RE 1
431
432#endif  // GTEST_HAS_POSIX_RE
433
434#ifndef GTEST_HAS_EXCEPTIONS
435// The user didn't tell us whether exceptions are enabled, so we need
436// to figure it out.
437# if defined(_MSC_VER) || defined(__BORLANDC__)
438// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
439// macro to enable exceptions, so we'll do the same.
440// Assumes that exceptions are enabled by default.
441#  ifndef _HAS_EXCEPTIONS
442#   define _HAS_EXCEPTIONS 1
443#  endif  // _HAS_EXCEPTIONS
444#  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
445# elif defined(__GNUC__) && __EXCEPTIONS
446// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
447#  define GTEST_HAS_EXCEPTIONS 1
448# elif defined(__SUNPRO_CC)
449// Sun Pro CC supports exceptions.  However, there is no compile-time way of
450// detecting whether they are enabled or not.  Therefore, we assume that
451// they are enabled unless the user tells us otherwise.
452#  define GTEST_HAS_EXCEPTIONS 1
453# elif defined(__IBMCPP__) && __EXCEPTIONS
454// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
455#  define GTEST_HAS_EXCEPTIONS 1
456# elif defined(__HP_aCC)
457// Exception handling is in effect by default in HP aCC compiler. It has to
458// be turned of by +noeh compiler option if desired.
459#  define GTEST_HAS_EXCEPTIONS 1
460# else
461// For other compilers, we assume exceptions are disabled to be
462// conservative.
463#  define GTEST_HAS_EXCEPTIONS 0
464# endif  // defined(_MSC_VER) || defined(__BORLANDC__)
465#endif  // GTEST_HAS_EXCEPTIONS
466
467#if !defined(GTEST_HAS_STD_STRING)
468// Even though we don't use this macro any longer, we keep it in case
469// some clients still depend on it.
470# define GTEST_HAS_STD_STRING 1
471#elif !GTEST_HAS_STD_STRING
472// The user told us that ::std::string isn't available.
473# error "Google Test cannot be used where ::std::string isn't available."
474#endif  // !defined(GTEST_HAS_STD_STRING)
475
476#ifndef GTEST_HAS_GLOBAL_STRING
477// The user didn't tell us whether ::string is available, so we need
478// to figure it out.
479
480# define GTEST_HAS_GLOBAL_STRING 0
481
482#endif  // GTEST_HAS_GLOBAL_STRING
483
484#ifndef GTEST_HAS_STD_WSTRING
485// The user didn't tell us whether ::std::wstring is available, so we need
486// to figure it out.
487// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
488//   is available.
489
490// Cygwin 1.7 and below doesn't support ::std::wstring.
491// Solaris' libc++ doesn't support it either.  Android has
492// no support for it at least as recent as Froyo (2.2).
493# define GTEST_HAS_STD_WSTRING \
494    (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
495
496#endif  // GTEST_HAS_STD_WSTRING
497
498#ifndef GTEST_HAS_GLOBAL_WSTRING
499// The user didn't tell us whether ::wstring is available, so we need
500// to figure it out.
501# define GTEST_HAS_GLOBAL_WSTRING \
502    (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
503#endif  // GTEST_HAS_GLOBAL_WSTRING
504
505// Determines whether RTTI is available.
506#ifndef GTEST_HAS_RTTI
507// The user didn't tell us whether RTTI is enabled, so we need to
508// figure it out.
509
510# ifdef _MSC_VER
511
512#  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.
513#   define GTEST_HAS_RTTI 1
514#  else
515#   define GTEST_HAS_RTTI 0
516#  endif
517
518// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
519# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
520
521#  ifdef __GXX_RTTI
522// When building against STLport with the Android NDK and with
523// -frtti -fno-exceptions, the build fails at link time with undefined
524// references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
525// so disable RTTI when detected.
526#   if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
527       !defined(__EXCEPTIONS)
528#    define GTEST_HAS_RTTI 0
529#   else
530#    define GTEST_HAS_RTTI 1
531#   endif  // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
532#  else
533#   define GTEST_HAS_RTTI 0
534#  endif  // __GXX_RTTI
535
536// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
537// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
538// first version with C++ support.
539# elif defined(__clang__)
540
541#  define GTEST_HAS_RTTI __has_feature(cxx_rtti)
542
543// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
544// both the typeid and dynamic_cast features are present.
545# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
546
547#  ifdef __RTTI_ALL__
548#   define GTEST_HAS_RTTI 1
549#  else
550#   define GTEST_HAS_RTTI 0
551#  endif
552
553# else
554
555// For all other compilers, we assume RTTI is enabled.
556#  define GTEST_HAS_RTTI 1
557
558# endif  // _MSC_VER
559
560#endif  // GTEST_HAS_RTTI
561
562// It's this header's responsibility to #include <typeinfo> when RTTI
563// is enabled.
564#if GTEST_HAS_RTTI
565# include <typeinfo>
566#endif
567
568// Determines whether Google Test can use the pthreads library.
569#ifndef GTEST_HAS_PTHREAD
570// The user didn't tell us explicitly, so we assume pthreads support is
571// available on Linux and Mac.
572//
573// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
574// to your compiler flags.
575# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \
576    || GTEST_OS_QNX)
577#endif  // GTEST_HAS_PTHREAD
578
579#if GTEST_HAS_PTHREAD
580// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
581// true.
582# include <pthread.h>  // NOLINT
583
584// For timespec and nanosleep, used below.
585# include <time.h>  // NOLINT
586#endif
587
588// Determines whether Google Test can use tr1/tuple.  You can define
589// this macro to 0 to prevent Google Test from using tuple (any
590// feature depending on tuple with be disabled in this mode).
591#ifndef GTEST_HAS_TR1_TUPLE
592# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
593// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
594#  define GTEST_HAS_TR1_TUPLE 0
595# else
596// The user didn't tell us not to do it, so we assume it's OK.
597#  define GTEST_HAS_TR1_TUPLE 1
598# endif
599#endif  // GTEST_HAS_TR1_TUPLE
600
601// Determines whether Google Test's own tr1 tuple implementation
602// should be used.
603#ifndef GTEST_USE_OWN_TR1_TUPLE
604// The user didn't tell us, so we need to figure it out.
605
606// We use our own TR1 tuple if we aren't sure the user has an
607// implementation of it already.  At this time, libstdc++ 4.0.0+ and
608// MSVC 2010 are the only mainstream standard libraries that come
609// with a TR1 tuple implementation.  NVIDIA's CUDA NVCC compiler
610// pretends to be GCC by defining __GNUC__ and friends, but cannot
611// compile GCC's tuple implementation.  MSVC 2008 (9.0) provides TR1
612// tuple in a 323 MB Feature Pack download, which we cannot assume the
613// user has.  QNX's QCC compiler is a modified GCC but it doesn't
614// support TR1 tuple.  libc++ only provides std::tuple, in C++11 mode,
615// and it can be used with some compilers that define __GNUC__.
616# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
617      && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600
618#  define GTEST_ENV_HAS_TR1_TUPLE_ 1
619# endif
620
621// C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
622// in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
623// can build with clang but need to use gcc4.2's libstdc++).
624# if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
625#  define GTEST_ENV_HAS_STD_TUPLE_ 1
626# endif
627
628# if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
629#  define GTEST_USE_OWN_TR1_TUPLE 0
630# else
631#  define GTEST_USE_OWN_TR1_TUPLE 1
632# endif
633
634#endif  // GTEST_USE_OWN_TR1_TUPLE
635
636// To avoid conditional compilation everywhere, we make it
637// gtest-port.h's responsibility to #include the header implementing
638// tr1/tuple.
639#if GTEST_HAS_TR1_TUPLE
640
641# if GTEST_USE_OWN_TR1_TUPLE
642// This file was GENERATED by command:
643//     pump.py gtest-tuple.h.pump
644// DO NOT EDIT BY HAND!!!
645
646// Copyright 2009 Google Inc.
647// All Rights Reserved.
648//
649// Redistribution and use in source and binary forms, with or without
650// modification, are permitted provided that the following conditions are
651// met:
652//
653//     * Redistributions of source code must retain the above copyright
654// notice, this list of conditions and the following disclaimer.
655//     * Redistributions in binary form must reproduce the above
656// copyright notice, this list of conditions and the following disclaimer
657// in the documentation and/or other materials provided with the
658// distribution.
659//     * Neither the name of Google Inc. nor the names of its
660// contributors may be used to endorse or promote products derived from
661// this software without specific prior written permission.
662//
663// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
664// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
665// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
666// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
667// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
668// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
669// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
670// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
671// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
672// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
673// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
674//
675// Author: wan@google.com (Zhanyong Wan)
676
677// Implements a subset of TR1 tuple needed by Google Test and Google Mock.
678
679#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
680#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
681
682#include <utility>  // For ::std::pair.
683
684// The compiler used in Symbian has a bug that prevents us from declaring the
685// tuple template as a friend (it complains that tuple is redefined).  This
686// hack bypasses the bug by declaring the members that should otherwise be
687// private as public.
688// Sun Studio versions < 12 also have the above bug.
689#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
690# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
691#else
692# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
693    template <GTEST_10_TYPENAMES_(U)> friend class tuple; \
694   private:
695#endif
696
697// GTEST_n_TUPLE_(T) is the type of an n-tuple.
698#define GTEST_0_TUPLE_(T) tuple<>
699#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
700    void, void, void>
701#define GTEST_2_TUPLE_(T) tuple<T##0, T##1, void, void, void, void, void, \
702    void, void, void>
703#define GTEST_3_TUPLE_(T) tuple<T##0, T##1, T##2, void, void, void, void, \
704    void, void, void>
705#define GTEST_4_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, void, void, void, \
706    void, void, void>
707#define GTEST_5_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, void, void, \
708    void, void, void>
709#define GTEST_6_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, void, \
710    void, void, void>
711#define GTEST_7_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
712    void, void, void>
713#define GTEST_8_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
714    T##7, void, void>
715#define GTEST_9_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
716    T##7, T##8, void>
717#define GTEST_10_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
718    T##7, T##8, T##9>
719
720// GTEST_n_TYPENAMES_(T) declares a list of n typenames.
721#define GTEST_0_TYPENAMES_(T)
722#define GTEST_1_TYPENAMES_(T) typename T##0
723#define GTEST_2_TYPENAMES_(T) typename T##0, typename T##1
724#define GTEST_3_TYPENAMES_(T) typename T##0, typename T##1, typename T##2
725#define GTEST_4_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
726    typename T##3
727#define GTEST_5_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
728    typename T##3, typename T##4
729#define GTEST_6_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
730    typename T##3, typename T##4, typename T##5
731#define GTEST_7_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
732    typename T##3, typename T##4, typename T##5, typename T##6
733#define GTEST_8_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
734    typename T##3, typename T##4, typename T##5, typename T##6, typename T##7
735#define GTEST_9_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
736    typename T##3, typename T##4, typename T##5, typename T##6, \
737    typename T##7, typename T##8
738#define GTEST_10_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
739    typename T##3, typename T##4, typename T##5, typename T##6, \
740    typename T##7, typename T##8, typename T##9
741
742// In theory, defining stuff in the ::std namespace is undefined
743// behavior.  We can do this as we are playing the role of a standard
744// library vendor.
745namespace std {
746namespace tr1 {
747
748template <typename T0 = void, typename T1 = void, typename T2 = void,
749    typename T3 = void, typename T4 = void, typename T5 = void,
750    typename T6 = void, typename T7 = void, typename T8 = void,
751    typename T9 = void>
752class tuple;
753
754// Anything in namespace gtest_internal is Google Test's INTERNAL
755// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
756namespace gtest_internal {
757
758// ByRef<T>::type is T if T is a reference; otherwise it's const T&.
759template <typename T>
760struct ByRef { typedef const T& type; };  // NOLINT
761template <typename T>
762struct ByRef<T&> { typedef T& type; };  // NOLINT
763
764// A handy wrapper for ByRef.
765#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type
766
767// AddRef<T>::type is T if T is a reference; otherwise it's T&.  This
768// is the same as tr1::add_reference<T>::type.
769template <typename T>
770struct AddRef { typedef T& type; };  // NOLINT
771template <typename T>
772struct AddRef<T&> { typedef T& type; };  // NOLINT
773
774// A handy wrapper for AddRef.
775#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type
776
777// A helper for implementing get<k>().
778template <int k> class Get;
779
780// A helper for implementing tuple_element<k, T>.  kIndexValid is true
781// iff k < the number of fields in tuple type T.
782template <bool kIndexValid, int kIndex, class Tuple>
783struct TupleElement;
784
785template <GTEST_10_TYPENAMES_(T)>
786struct TupleElement<true, 0, GTEST_10_TUPLE_(T) > {
787  typedef T0 type;
788};
789
790template <GTEST_10_TYPENAMES_(T)>
791struct TupleElement<true, 1, GTEST_10_TUPLE_(T) > {
792  typedef T1 type;
793};
794
795template <GTEST_10_TYPENAMES_(T)>
796struct TupleElement<true, 2, GTEST_10_TUPLE_(T) > {
797  typedef T2 type;
798};
799
800template <GTEST_10_TYPENAMES_(T)>
801struct TupleElement<true, 3, GTEST_10_TUPLE_(T) > {
802  typedef T3 type;
803};
804
805template <GTEST_10_TYPENAMES_(T)>
806struct TupleElement<true, 4, GTEST_10_TUPLE_(T) > {
807  typedef T4 type;
808};
809
810template <GTEST_10_TYPENAMES_(T)>
811struct TupleElement<true, 5, GTEST_10_TUPLE_(T) > {
812  typedef T5 type;
813};
814
815template <GTEST_10_TYPENAMES_(T)>
816struct TupleElement<true, 6, GTEST_10_TUPLE_(T) > {
817  typedef T6 type;
818};
819
820template <GTEST_10_TYPENAMES_(T)>
821struct TupleElement<true, 7, GTEST_10_TUPLE_(T) > {
822  typedef T7 type;
823};
824
825template <GTEST_10_TYPENAMES_(T)>
826struct TupleElement<true, 8, GTEST_10_TUPLE_(T) > {
827  typedef T8 type;
828};
829
830template <GTEST_10_TYPENAMES_(T)>
831struct TupleElement<true, 9, GTEST_10_TUPLE_(T) > {
832  typedef T9 type;
833};
834
835}  // namespace gtest_internal
836
837template <>
838class tuple<> {
839 public:
840  tuple() {}
841  tuple(const tuple& /* t */)  {}
842  tuple& operator=(const tuple& /* t */) { return *this; }
843};
844
845template <GTEST_1_TYPENAMES_(T)>
846class GTEST_1_TUPLE_(T) {
847 public:
848  template <int k> friend class gtest_internal::Get;
849
850  tuple() : f0_() {}
851
852  explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {}
853
854  tuple(const tuple& t) : f0_(t.f0_) {}
855
856  template <GTEST_1_TYPENAMES_(U)>
857  tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {}
858
859  tuple& operator=(const tuple& t) { return CopyFrom(t); }
860
861  template <GTEST_1_TYPENAMES_(U)>
862  tuple& operator=(const GTEST_1_TUPLE_(U)& t) {
863    return CopyFrom(t);
864  }
865
866  GTEST_DECLARE_TUPLE_AS_FRIEND_
867
868  template <GTEST_1_TYPENAMES_(U)>
869  tuple& CopyFrom(const GTEST_1_TUPLE_(U)& t) {
870    f0_ = t.f0_;
871    return *this;
872  }
873
874  T0 f0_;
875};
876
877template <GTEST_2_TYPENAMES_(T)>
878class GTEST_2_TUPLE_(T) {
879 public:
880  template <int k> friend class gtest_internal::Get;
881
882  tuple() : f0_(), f1_() {}
883
884  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0),
885      f1_(f1) {}
886
887  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {}
888
889  template <GTEST_2_TYPENAMES_(U)>
890  tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {}
891  template <typename U0, typename U1>
892  tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
893
894  tuple& operator=(const tuple& t) { return CopyFrom(t); }
895
896  template <GTEST_2_TYPENAMES_(U)>
897  tuple& operator=(const GTEST_2_TUPLE_(U)& t) {
898    return CopyFrom(t);
899  }
900  template <typename U0, typename U1>
901  tuple& operator=(const ::std::pair<U0, U1>& p) {
902    f0_ = p.first;
903    f1_ = p.second;
904    return *this;
905  }
906
907  GTEST_DECLARE_TUPLE_AS_FRIEND_
908
909  template <GTEST_2_TYPENAMES_(U)>
910  tuple& CopyFrom(const GTEST_2_TUPLE_(U)& t) {
911    f0_ = t.f0_;
912    f1_ = t.f1_;
913    return *this;
914  }
915
916  T0 f0_;
917  T1 f1_;
918};
919
920template <GTEST_3_TYPENAMES_(T)>
921class GTEST_3_TUPLE_(T) {
922 public:
923  template <int k> friend class gtest_internal::Get;
924
925  tuple() : f0_(), f1_(), f2_() {}
926
927  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
928      GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {}
929
930  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
931
932  template <GTEST_3_TYPENAMES_(U)>
933  tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
934
935  tuple& operator=(const tuple& t) { return CopyFrom(t); }
936
937  template <GTEST_3_TYPENAMES_(U)>
938  tuple& operator=(const GTEST_3_TUPLE_(U)& t) {
939    return CopyFrom(t);
940  }
941
942  GTEST_DECLARE_TUPLE_AS_FRIEND_
943
944  template <GTEST_3_TYPENAMES_(U)>
945  tuple& CopyFrom(const GTEST_3_TUPLE_(U)& t) {
946    f0_ = t.f0_;
947    f1_ = t.f1_;
948    f2_ = t.f2_;
949    return *this;
950  }
951
952  T0 f0_;
953  T1 f1_;
954  T2 f2_;
955};
956
957template <GTEST_4_TYPENAMES_(T)>
958class GTEST_4_TUPLE_(T) {
959 public:
960  template <int k> friend class gtest_internal::Get;
961
962  tuple() : f0_(), f1_(), f2_(), f3_() {}
963
964  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
965      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f2),
966      f3_(f3) {}
967
968  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {}
969
970  template <GTEST_4_TYPENAMES_(U)>
971  tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
972      f3_(t.f3_) {}
973
974  tuple& operator=(const tuple& t) { return CopyFrom(t); }
975
976  template <GTEST_4_TYPENAMES_(U)>
977  tuple& operator=(const GTEST_4_TUPLE_(U)& t) {
978    return CopyFrom(t);
979  }
980
981  GTEST_DECLARE_TUPLE_AS_FRIEND_
982
983  template <GTEST_4_TYPENAMES_(U)>
984  tuple& CopyFrom(const GTEST_4_TUPLE_(U)& t) {
985    f0_ = t.f0_;
986    f1_ = t.f1_;
987    f2_ = t.f2_;
988    f3_ = t.f3_;
989    return *this;
990  }
991
992  T0 f0_;
993  T1 f1_;
994  T2 f2_;
995  T3 f3_;
996};
997
998template <GTEST_5_TYPENAMES_(T)>
999class GTEST_5_TUPLE_(T) {
1000 public:
1001  template <int k> friend class gtest_internal::Get;
1002
1003  tuple() : f0_(), f1_(), f2_(), f3_(), f4_() {}
1004
1005  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1006      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3,
1007      GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) {}
1008
1009  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1010      f4_(t.f4_) {}
1011
1012  template <GTEST_5_TYPENAMES_(U)>
1013  tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1014      f3_(t.f3_), f4_(t.f4_) {}
1015
1016  tuple& operator=(const tuple& t) { return CopyFrom(t); }
1017
1018  template <GTEST_5_TYPENAMES_(U)>
1019  tuple& operator=(const GTEST_5_TUPLE_(U)& t) {
1020    return CopyFrom(t);
1021  }
1022
1023  GTEST_DECLARE_TUPLE_AS_FRIEND_
1024
1025  template <GTEST_5_TYPENAMES_(U)>
1026  tuple& CopyFrom(const GTEST_5_TUPLE_(U)& t) {
1027    f0_ = t.f0_;
1028    f1_ = t.f1_;
1029    f2_ = t.f2_;
1030    f3_ = t.f3_;
1031    f4_ = t.f4_;
1032    return *this;
1033  }
1034
1035  T0 f0_;
1036  T1 f1_;
1037  T2 f2_;
1038  T3 f3_;
1039  T4 f4_;
1040};
1041
1042template <GTEST_6_TYPENAMES_(T)>
1043class GTEST_6_TUPLE_(T) {
1044 public:
1045  template <int k> friend class gtest_internal::Get;
1046
1047  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_() {}
1048
1049  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1050      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1051      GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
1052      f5_(f5) {}
1053
1054  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1055      f4_(t.f4_), f5_(t.f5_) {}
1056
1057  template <GTEST_6_TYPENAMES_(U)>
1058  tuple(const GTEST_6_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1059      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_) {}
1060
1061  tuple& operator=(const tuple& t) { return CopyFrom(t); }
1062
1063  template <GTEST_6_TYPENAMES_(U)>
1064  tuple& operator=(const GTEST_6_TUPLE_(U)& t) {
1065    return CopyFrom(t);
1066  }
1067
1068  GTEST_DECLARE_TUPLE_AS_FRIEND_
1069
1070  template <GTEST_6_TYPENAMES_(U)>
1071  tuple& CopyFrom(const GTEST_6_TUPLE_(U)& t) {
1072    f0_ = t.f0_;
1073    f1_ = t.f1_;
1074    f2_ = t.f2_;
1075    f3_ = t.f3_;
1076    f4_ = t.f4_;
1077    f5_ = t.f5_;
1078    return *this;
1079  }
1080
1081  T0 f0_;
1082  T1 f1_;
1083  T2 f2_;
1084  T3 f3_;
1085  T4 f4_;
1086  T5 f5_;
1087};
1088
1089template <GTEST_7_TYPENAMES_(T)>
1090class GTEST_7_TUPLE_(T) {
1091 public:
1092  template <int k> friend class gtest_internal::Get;
1093
1094  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_() {}
1095
1096  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1097      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1098      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f2),
1099      f3_(f3), f4_(f4), f5_(f5), f6_(f6) {}
1100
1101  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1102      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
1103
1104  template <GTEST_7_TYPENAMES_(U)>
1105  tuple(const GTEST_7_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1106      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
1107
1108  tuple& operator=(const tuple& t) { return CopyFrom(t); }
1109
1110  template <GTEST_7_TYPENAMES_(U)>
1111  tuple& operator=(const GTEST_7_TUPLE_(U)& t) {
1112    return CopyFrom(t);
1113  }
1114
1115  GTEST_DECLARE_TUPLE_AS_FRIEND_
1116
1117  template <GTEST_7_TYPENAMES_(U)>
1118  tuple& CopyFrom(const GTEST_7_TUPLE_(U)& t) {
1119    f0_ = t.f0_;
1120    f1_ = t.f1_;
1121    f2_ = t.f2_;
1122    f3_ = t.f3_;
1123    f4_ = t.f4_;
1124    f5_ = t.f5_;
1125    f6_ = t.f6_;
1126    return *this;
1127  }
1128
1129  T0 f0_;
1130  T1 f1_;
1131  T2 f2_;
1132  T3 f3_;
1133  T4 f4_;
1134  T5 f5_;
1135  T6 f6_;
1136};
1137
1138template <GTEST_8_TYPENAMES_(T)>
1139class GTEST_8_TUPLE_(T) {
1140 public:
1141  template <int k> friend class gtest_internal::Get;
1142
1143  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_() {}
1144
1145  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1146      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1147      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6,
1148      GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
1149      f5_(f5), f6_(f6), f7_(f7) {}
1150
1151  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1152      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
1153
1154  template <GTEST_8_TYPENAMES_(U)>
1155  tuple(const GTEST_8_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1156      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
1157
1158  tuple& operator=(const tuple& t) { return CopyFrom(t); }
1159
1160  template <GTEST_8_TYPENAMES_(U)>
1161  tuple& operator=(const GTEST_8_TUPLE_(U)& t) {
1162    return CopyFrom(t);
1163  }
1164
1165  GTEST_DECLARE_TUPLE_AS_FRIEND_
1166
1167  template <GTEST_8_TYPENAMES_(U)>
1168  tuple& CopyFrom(const GTEST_8_TUPLE_(U)& t) {
1169    f0_ = t.f0_;
1170    f1_ = t.f1_;
1171    f2_ = t.f2_;
1172    f3_ = t.f3_;
1173    f4_ = t.f4_;
1174    f5_ = t.f5_;
1175    f6_ = t.f6_;
1176    f7_ = t.f7_;
1177    return *this;
1178  }
1179
1180  T0 f0_;
1181  T1 f1_;
1182  T2 f2_;
1183  T3 f3_;
1184  T4 f4_;
1185  T5 f5_;
1186  T6 f6_;
1187  T7 f7_;
1188};
1189
1190template <GTEST_9_TYPENAMES_(T)>
1191class GTEST_9_TUPLE_(T) {
1192 public:
1193  template <int k> friend class gtest_internal::Get;
1194
1195  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_() {}
1196
1197  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1198      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1199      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
1200      GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
1201      f5_(f5), f6_(f6), f7_(f7), f8_(f8) {}
1202
1203  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1204      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}
1205
1206  template <GTEST_9_TYPENAMES_(U)>
1207  tuple(const GTEST_9_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1208      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}
1209
1210  tuple& operator=(const tuple& t) { return CopyFrom(t); }
1211
1212  template <GTEST_9_TYPENAMES_(U)>
1213  tuple& operator=(const GTEST_9_TUPLE_(U)& t) {
1214    return CopyFrom(t);
1215  }
1216
1217  GTEST_DECLARE_TUPLE_AS_FRIEND_
1218
1219  template <GTEST_9_TYPENAMES_(U)>
1220  tuple& CopyFrom(const GTEST_9_TUPLE_(U)& t) {
1221    f0_ = t.f0_;
1222    f1_ = t.f1_;
1223    f2_ = t.f2_;
1224    f3_ = t.f3_;
1225    f4_ = t.f4_;
1226    f5_ = t.f5_;
1227    f6_ = t.f6_;
1228    f7_ = t.f7_;
1229    f8_ = t.f8_;
1230    return *this;
1231  }
1232
1233  T0 f0_;
1234  T1 f1_;
1235  T2 f2_;
1236  T3 f3_;
1237  T4 f4_;
1238  T5 f5_;
1239  T6 f6_;
1240  T7 f7_;
1241  T8 f8_;
1242};
1243
1244template <GTEST_10_TYPENAMES_(T)>
1245class tuple {
1246 public:
1247  template <int k> friend class gtest_internal::Get;
1248
1249  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_(),
1250      f9_() {}
1251
1252  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1253      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1254      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
1255      GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f2),
1256      f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {}
1257
1258  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1259      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_) {}
1260
1261  template <GTEST_10_TYPENAMES_(U)>
1262  tuple(const GTEST_10_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1263      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_),
1264      f9_(t.f9_) {}
1265
1266  tuple& operator=(const tuple& t) { return CopyFrom(t); }
1267
1268  template <GTEST_10_TYPENAMES_(U)>
1269  tuple& operator=(const GTEST_10_TUPLE_(U)& t) {
1270    return CopyFrom(t);
1271  }
1272
1273  GTEST_DECLARE_TUPLE_AS_FRIEND_
1274
1275  template <GTEST_10_TYPENAMES_(U)>
1276  tuple& CopyFrom(const GTEST_10_TUPLE_(U)& t) {
1277    f0_ = t.f0_;
1278    f1_ = t.f1_;
1279    f2_ = t.f2_;
1280    f3_ = t.f3_;
1281    f4_ = t.f4_;
1282    f5_ = t.f5_;
1283    f6_ = t.f6_;
1284    f7_ = t.f7_;
1285    f8_ = t.f8_;
1286    f9_ = t.f9_;
1287    return *this;
1288  }
1289
1290  T0 f0_;
1291  T1 f1_;
1292  T2 f2_;
1293  T3 f3_;
1294  T4 f4_;
1295  T5 f5_;
1296  T6 f6_;
1297  T7 f7_;
1298  T8 f8_;
1299  T9 f9_;
1300};
1301
1302// 6.1.3.2 Tuple creation functions.
1303
1304// Known limitations: we don't support passing an
1305// std::tr1::reference_wrapper<T> to make_tuple().  And we don't
1306// implement tie().
1307
1308inline tuple<> make_tuple() { return tuple<>(); }
1309
1310template <GTEST_1_TYPENAMES_(T)>
1311inline GTEST_1_TUPLE_(T) make_tuple(const T0& f0) {
1312  return GTEST_1_TUPLE_(T)(f0);
1313}
1314
1315template <GTEST_2_TYPENAMES_(T)>
1316inline GTEST_2_TUPLE_(T) make_tuple(const T0& f0, const T1& f1) {
1317  return GTEST_2_TUPLE_(T)(f0, f1);
1318}
1319
1320template <GTEST_3_TYPENAMES_(T)>
1321inline GTEST_3_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2) {
1322  return GTEST_3_TUPLE_(T)(f0, f1, f2);
1323}
1324
1325template <GTEST_4_TYPENAMES_(T)>
1326inline GTEST_4_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1327    const T3& f3) {
1328  return GTEST_4_TUPLE_(T)(f0, f1, f2, f3);
1329}
1330
1331template <GTEST_5_TYPENAMES_(T)>
1332inline GTEST_5_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1333    const T3& f3, const T4& f4) {
1334  return GTEST_5_TUPLE_(T)(f0, f1, f2, f3, f4);
1335}
1336
1337template <GTEST_6_TYPENAMES_(T)>
1338inline GTEST_6_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1339    const T3& f3, const T4& f4, const T5& f5) {
1340  return GTEST_6_TUPLE_(T)(f0, f1, f2, f3, f4, f5);
1341}
1342
1343template <GTEST_7_TYPENAMES_(T)>
1344inline GTEST_7_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1345    const T3& f3, const T4& f4, const T5& f5, const T6& f6) {
1346  return GTEST_7_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6);
1347}
1348
1349template <GTEST_8_TYPENAMES_(T)>
1350inline GTEST_8_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1351    const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7) {
1352  return GTEST_8_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7);
1353}
1354
1355template <GTEST_9_TYPENAMES_(T)>
1356inline GTEST_9_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1357    const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,
1358    const T8& f8) {
1359  return GTEST_9_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8);
1360}
1361
1362template <GTEST_10_TYPENAMES_(T)>
1363inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1364    const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,
1365    const T8& f8, const T9& f9) {
1366  return GTEST_10_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9);
1367}
1368
1369// 6.1.3.3 Tuple helper classes.
1370
1371template <typename Tuple> struct tuple_size;
1372
1373template <GTEST_0_TYPENAMES_(T)>
1374struct tuple_size<GTEST_0_TUPLE_(T) > {
1375  static const int value = 0;
1376};
1377
1378template <GTEST_1_TYPENAMES_(T)>
1379struct tuple_size<GTEST_1_TUPLE_(T) > {
1380  static const int value = 1;
1381};
1382
1383template <GTEST_2_TYPENAMES_(T)>
1384struct tuple_size<GTEST_2_TUPLE_(T) > {
1385  static const int value = 2;
1386};
1387
1388template <GTEST_3_TYPENAMES_(T)>
1389struct tuple_size<GTEST_3_TUPLE_(T) > {
1390  static const int value = 3;
1391};
1392
1393template <GTEST_4_TYPENAMES_(T)>
1394struct tuple_size<GTEST_4_TUPLE_(T) > {
1395  static const int value = 4;
1396};
1397
1398template <GTEST_5_TYPENAMES_(T)>
1399struct tuple_size<GTEST_5_TUPLE_(T) > {
1400  static const int value = 5;
1401};
1402
1403template <GTEST_6_TYPENAMES_(T)>
1404struct tuple_size<GTEST_6_TUPLE_(T) > {
1405  static const int value = 6;
1406};
1407
1408template <GTEST_7_TYPENAMES_(T)>
1409struct tuple_size<GTEST_7_TUPLE_(T) > {
1410  static const int value = 7;
1411};
1412
1413template <GTEST_8_TYPENAMES_(T)>
1414struct tuple_size<GTEST_8_TUPLE_(T) > {
1415  static const int value = 8;
1416};
1417
1418template <GTEST_9_TYPENAMES_(T)>
1419struct tuple_size<GTEST_9_TUPLE_(T) > {
1420  static const int value = 9;
1421};
1422
1423template <GTEST_10_TYPENAMES_(T)>
1424struct tuple_size<GTEST_10_TUPLE_(T) > {
1425  static const int value = 10;
1426};
1427
1428template <int k, class Tuple>
1429struct tuple_element {
1430  typedef typename gtest_internal::TupleElement<
1431      k < (tuple_size<Tuple>::value), k, Tuple>::type type;
1432};
1433
1434#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type
1435
1436// 6.1.3.4 Element access.
1437
1438namespace gtest_internal {
1439
1440template <>
1441class Get<0> {
1442 public:
1443  template <class Tuple>
1444  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))
1445  Field(Tuple& t) { return t.f0_; }  // NOLINT
1446
1447  template <class Tuple>
1448  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))
1449  ConstField(const Tuple& t) { return t.f0_; }
1450};
1451
1452template <>
1453class Get<1> {
1454 public:
1455  template <class Tuple>
1456  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))
1457  Field(Tuple& t) { return t.f1_; }  // NOLINT
1458
1459  template <class Tuple>
1460  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))
1461  ConstField(const Tuple& t) { return t.f1_; }
1462};
1463
1464template <>
1465class Get<2> {
1466 public:
1467  template <class Tuple>
1468  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))
1469  Field(Tuple& t) { return t.f2_; }  // NOLINT
1470
1471  template <class Tuple>
1472  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))
1473  ConstField(const Tuple& t) { return t.f2_; }
1474};
1475
1476template <>
1477class Get<3> {
1478 public:
1479  template <class Tuple>
1480  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))
1481  Field(Tuple& t) { return t.f3_; }  // NOLINT
1482
1483  template <class Tuple>
1484  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))
1485  ConstField(const Tuple& t) { return t.f3_; }
1486};
1487
1488template <>
1489class Get<4> {
1490 public:
1491  template <class Tuple>
1492  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))
1493  Field(Tuple& t) { return t.f4_; }  // NOLINT
1494
1495  template <class Tuple>
1496  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))
1497  ConstField(const Tuple& t) { return t.f4_; }
1498};
1499
1500template <>
1501class Get<5> {
1502 public:
1503  template <class Tuple>
1504  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))
1505  Field(Tuple& t) { return t.f5_; }  // NOLINT
1506
1507  template <class Tuple>
1508  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))
1509  ConstField(const Tuple& t) { return t.f5_; }
1510};
1511
1512template <>
1513class Get<6> {
1514 public:
1515  template <class Tuple>
1516  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))
1517  Field(Tuple& t) { return t.f6_; }  // NOLINT
1518
1519  template <class Tuple>
1520  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))
1521  ConstField(const Tuple& t) { return t.f6_; }
1522};
1523
1524template <>
1525class Get<7> {
1526 public:
1527  template <class Tuple>
1528  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))
1529  Field(Tuple& t) { return t.f7_; }  // NOLINT
1530
1531  template <class Tuple>
1532  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))
1533  ConstField(const Tuple& t) { return t.f7_; }
1534};
1535
1536template <>
1537class Get<8> {
1538 public:
1539  template <class Tuple>
1540  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))
1541  Field(Tuple& t) { return t.f8_; }  // NOLINT
1542
1543  template <class Tuple>
1544  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))
1545  ConstField(const Tuple& t) { return t.f8_; }
1546};
1547
1548template <>
1549class Get<9> {
1550 public:
1551  template <class Tuple>
1552  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))
1553  Field(Tuple& t) { return t.f9_; }  // NOLINT
1554
1555  template <class Tuple>
1556  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))
1557  ConstField(const Tuple& t) { return t.f9_; }
1558};
1559
1560}  // namespace gtest_internal
1561
1562template <int k, GTEST_10_TYPENAMES_(T)>
1563GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T)))
1564get(GTEST_10_TUPLE_(T)& t) {
1565  return gtest_internal::Get<k>::Field(t);
1566}
1567
1568template <int k, GTEST_10_TYPENAMES_(T)>
1569GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k,  GTEST_10_TUPLE_(T)))
1570get(const GTEST_10_TUPLE_(T)& t) {
1571  return gtest_internal::Get<k>::ConstField(t);
1572}
1573
1574// 6.1.3.5 Relational operators
1575
1576// We only implement == and !=, as we don't have a need for the rest yet.
1577
1578namespace gtest_internal {
1579
1580// SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
1581// first k fields of t1 equals the first k fields of t2.
1582// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
1583// k1 != k2.
1584template <int kSize1, int kSize2>
1585struct SameSizeTuplePrefixComparator;
1586
1587template <>
1588struct SameSizeTuplePrefixComparator<0, 0> {
1589  template <class Tuple1, class Tuple2>
1590  static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {
1591    return true;
1592  }
1593};
1594
1595template <int k>
1596struct SameSizeTuplePrefixComparator<k, k> {
1597  template <class Tuple1, class Tuple2>
1598  static bool Eq(const Tuple1& t1, const Tuple2& t2) {
1599    return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&
1600        ::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);
1601  }
1602};
1603
1604}  // namespace gtest_internal
1605
1606template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
1607inline bool operator==(const GTEST_10_TUPLE_(T)& t,
1608                       const GTEST_10_TUPLE_(U)& u) {
1609  return gtest_internal::SameSizeTuplePrefixComparator<
1610      tuple_size<GTEST_10_TUPLE_(T) >::value,
1611      tuple_size<GTEST_10_TUPLE_(U) >::value>::Eq(t, u);
1612}
1613
1614template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
1615inline bool operator!=(const GTEST_10_TUPLE_(T)& t,
1616                       const GTEST_10_TUPLE_(U)& u) { return !(t == u); }
1617
1618// 6.1.4 Pairs.
1619// Unimplemented.
1620
1621}  // namespace tr1
1622}  // namespace std
1623
1624#undef GTEST_0_TUPLE_
1625#undef GTEST_1_TUPLE_
1626#undef GTEST_2_TUPLE_
1627#undef GTEST_3_TUPLE_
1628#undef GTEST_4_TUPLE_
1629#undef GTEST_5_TUPLE_
1630#undef GTEST_6_TUPLE_
1631#undef GTEST_7_TUPLE_
1632#undef GTEST_8_TUPLE_
1633#undef GTEST_9_TUPLE_
1634#undef GTEST_10_TUPLE_
1635
1636#undef GTEST_0_TYPENAMES_
1637#undef GTEST_1_TYPENAMES_
1638#undef GTEST_2_TYPENAMES_
1639#undef GTEST_3_TYPENAMES_
1640#undef GTEST_4_TYPENAMES_
1641#undef GTEST_5_TYPENAMES_
1642#undef GTEST_6_TYPENAMES_
1643#undef GTEST_7_TYPENAMES_
1644#undef GTEST_8_TYPENAMES_
1645#undef GTEST_9_TYPENAMES_
1646#undef GTEST_10_TYPENAMES_
1647
1648#undef GTEST_DECLARE_TUPLE_AS_FRIEND_
1649#undef GTEST_BY_REF_
1650#undef GTEST_ADD_REF_
1651#undef GTEST_TUPLE_ELEMENT_
1652
1653#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
1654# elif GTEST_ENV_HAS_STD_TUPLE_
1655#  include <tuple>
1656// C++11 puts its tuple into the ::std namespace rather than
1657// ::std::tr1.  gtest expects tuple to live in ::std::tr1, so put it there.
1658// This causes undefined behavior, but supported compilers react in
1659// the way we intend.
1660namespace std {
1661namespace tr1 {
1662using ::std::get;
1663using ::std::make_tuple;
1664using ::std::tuple;
1665using ::std::tuple_element;
1666using ::std::tuple_size;
1667}
1668}
1669
1670# elif GTEST_OS_SYMBIAN
1671
1672// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
1673// use STLport's tuple implementation, which unfortunately doesn't
1674// work as the copy of STLport distributed with Symbian is incomplete.
1675// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
1676// use its own tuple implementation.
1677#  ifdef BOOST_HAS_TR1_TUPLE
1678#   undef BOOST_HAS_TR1_TUPLE
1679#  endif  // BOOST_HAS_TR1_TUPLE
1680
1681// This prevents <boost/tr1/detail/config.hpp>, which defines
1682// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
1683#  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
1684#  include <tuple>
1685
1686# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
1687// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
1688// not conform to the TR1 spec, which requires the header to be <tuple>.
1689
1690#  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
1691// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
1692// which is #included by <tr1/tuple>, to not compile when RTTI is
1693// disabled.  _TR1_FUNCTIONAL is the header guard for
1694// <tr1/functional>.  Hence the following #define is a hack to prevent
1695// <tr1/functional> from being included.
1696#   define _TR1_FUNCTIONAL 1
1697#   include <tr1/tuple>
1698#   undef _TR1_FUNCTIONAL  // Allows the user to #include
1699                        // <tr1/functional> if he chooses to.
1700#  else
1701#   include <tr1/tuple>  // NOLINT
1702#  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
1703
1704# else
1705// If the compiler is not GCC 4.0+, we assume the user is using a
1706// spec-conforming TR1 implementation.
1707#  include <tuple>  // NOLINT
1708# endif  // GTEST_USE_OWN_TR1_TUPLE
1709
1710#endif  // GTEST_HAS_TR1_TUPLE
1711
1712// Determines whether clone(2) is supported.
1713// Usually it will only be available on Linux, excluding
1714// Linux on the Itanium architecture.
1715// Also see http://linux.die.net/man/2/clone.
1716#ifndef GTEST_HAS_CLONE
1717// The user didn't tell us, so we need to figure it out.
1718
1719# if GTEST_OS_LINUX && !defined(__ia64__)
1720#  if GTEST_OS_LINUX_ANDROID
1721// On Android, clone() is only available on ARM starting with Gingerbread.
1722#    if defined(__arm__) && __ANDROID_API__ >= 9
1723#     define GTEST_HAS_CLONE 1
1724#    else
1725#     define GTEST_HAS_CLONE 0
1726#    endif
1727#  else
1728#   define GTEST_HAS_CLONE 1
1729#  endif
1730# else
1731#  define GTEST_HAS_CLONE 0
1732# endif  // GTEST_OS_LINUX && !defined(__ia64__)
1733
1734#endif  // GTEST_HAS_CLONE
1735
1736// Determines whether to support stream redirection. This is used to test
1737// output correctness and to implement death tests.
1738#ifndef GTEST_HAS_STREAM_REDIRECTION
1739// By default, we assume that stream redirection is supported on all
1740// platforms except known mobile ones.
1741# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
1742#  define GTEST_HAS_STREAM_REDIRECTION 0
1743# else
1744#  define GTEST_HAS_STREAM_REDIRECTION 1
1745# endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
1746#endif  // GTEST_HAS_STREAM_REDIRECTION
1747
1748// Determines whether to support death tests.
1749// Google Test does not support death tests for VC 7.1 and earlier as
1750// abort() in a VC 7.1 application compiled as GUI in debug config
1751// pops up a dialog window that cannot be suppressed programmatically.
1752#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
1753     (GTEST_OS_MAC && !GTEST_OS_IOS) || GTEST_OS_IOS_SIMULATOR || \
1754     (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
1755     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
1756     GTEST_OS_OPENBSD || GTEST_OS_QNX)
1757# define GTEST_HAS_DEATH_TEST 1
1758# include <vector>  // NOLINT
1759#endif
1760
1761// We don't support MSVC 7.1 with exceptions disabled now.  Therefore
1762// all the compilers we care about are adequate for supporting
1763// value-parameterized tests.
1764#define GTEST_HAS_PARAM_TEST 1
1765
1766// Determines whether to support type-driven tests.
1767
1768// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
1769// Sun Pro CC, IBM Visual Age, and HP aCC support.
1770#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
1771    defined(__IBMCPP__) || defined(__HP_aCC)
1772# define GTEST_HAS_TYPED_TEST 1
1773# define GTEST_HAS_TYPED_TEST_P 1
1774#endif
1775
1776// Determines whether to support Combine(). This only makes sense when
1777// value-parameterized tests are enabled.  The implementation doesn't
1778// work on Sun Studio since it doesn't understand templated conversion
1779// operators.
1780#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
1781# define GTEST_HAS_COMBINE 1
1782#endif
1783
1784// Determines whether the system compiler uses UTF-16 for encoding wide strings.
1785#define GTEST_WIDE_STRING_USES_UTF16_ \
1786    (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
1787
1788// Determines whether test results can be streamed to a socket.
1789#if GTEST_OS_LINUX
1790# define GTEST_CAN_STREAM_RESULTS_ 1
1791#endif
1792
1793// Defines some utility macros.
1794
1795// The GNU compiler emits a warning if nested "if" statements are followed by
1796// an "else" statement and braces are not used to explicitly disambiguate the
1797// "else" binding.  This leads to problems with code like:
1798//
1799//   if (gate)
1800//     ASSERT_*(condition) << "Some message";
1801//
1802// The "switch (0) case 0:" idiom is used to suppress this.
1803#ifdef __INTEL_COMPILER
1804# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
1805#else
1806# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT
1807#endif
1808
1809// Use this annotation at the end of a struct/class definition to
1810// prevent the compiler from optimizing away instances that are never
1811// used.  This is useful when all interesting logic happens inside the
1812// c'tor and / or d'tor.  Example:
1813//
1814//   struct Foo {
1815//     Foo() { ... }
1816//   } GTEST_ATTRIBUTE_UNUSED_;
1817//
1818// Also use it after a variable or parameter declaration to tell the
1819// compiler the variable/parameter does not have to be used.
1820#if defined(__GNUC__) && !defined(COMPILER_ICC)
1821# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
1822#else
1823# define GTEST_ATTRIBUTE_UNUSED_
1824#endif
1825
1826// A macro to disallow operator=
1827// This should be used in the private: declarations for a class.
1828#define GTEST_DISALLOW_ASSIGN_(type)\
1829  void operator=(type const &)
1830
1831// A macro to disallow copy constructor and operator=
1832// This should be used in the private: declarations for a class.
1833#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
1834  type(type const &);\
1835  GTEST_DISALLOW_ASSIGN_(type)
1836
1837// Tell the compiler to warn about unused return values for functions declared
1838// with this macro.  The macro should be used on function declarations
1839// following the argument list:
1840//
1841//   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
1842#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
1843# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
1844#else
1845# define GTEST_MUST_USE_RESULT_
1846#endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
1847
1848// Determine whether the compiler supports Microsoft's Structured Exception
1849// Handling.  This is supported by several Windows compilers but generally
1850// does not exist on any other system.
1851#ifndef GTEST_HAS_SEH
1852// The user didn't tell us, so we need to figure it out.
1853
1854# if defined(_MSC_VER) || defined(__BORLANDC__)
1855// These two compilers are known to support SEH.
1856#  define GTEST_HAS_SEH 1
1857# else
1858// Assume no SEH.
1859#  define GTEST_HAS_SEH 0
1860# endif
1861
1862#endif  // GTEST_HAS_SEH
1863
1864#ifdef _MSC_VER
1865
1866# if GTEST_LINKED_AS_SHARED_LIBRARY
1867#  define GTEST_API_ __declspec(dllimport)
1868# elif GTEST_CREATE_SHARED_LIBRARY
1869#  define GTEST_API_ __declspec(dllexport)
1870# endif
1871
1872#endif  // _MSC_VER
1873
1874#ifndef GTEST_API_
1875# define GTEST_API_
1876#endif
1877
1878#ifdef __GNUC__
1879// Ask the compiler to never inline a given function.
1880# define GTEST_NO_INLINE_ __attribute__((noinline))
1881#else
1882# define GTEST_NO_INLINE_
1883#endif
1884
1885// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
1886#if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
1887# define GTEST_HAS_CXXABI_H_ 1
1888#else
1889# define GTEST_HAS_CXXABI_H_ 0
1890#endif
1891
1892namespace testing {
1893
1894class Message;
1895
1896namespace internal {
1897
1898// A secret type that Google Test users don't know about.  It has no
1899// definition on purpose.  Therefore it's impossible to create a
1900// Secret object, which is what we want.
1901class Secret;
1902
1903// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
1904// expression is true. For example, you could use it to verify the
1905// size of a static array:
1906//
1907//   GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
1908//                         content_type_names_incorrect_size);
1909//
1910// or to make sure a struct is smaller than a certain size:
1911//
1912//   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
1913//
1914// The second argument to the macro is the name of the variable. If
1915// the expression is false, most compilers will issue a warning/error
1916// containing the name of the variable.
1917
1918template <bool>
1919struct CompileAssert {
1920};
1921
1922#define GTEST_COMPILE_ASSERT_(expr, msg) \
1923  typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
1924      msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
1925
1926// Implementation details of GTEST_COMPILE_ASSERT_:
1927//
1928// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
1929//   elements (and thus is invalid) when the expression is false.
1930//
1931// - The simpler definition
1932//
1933//    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
1934//
1935//   does not work, as gcc supports variable-length arrays whose sizes
1936//   are determined at run-time (this is gcc's extension and not part
1937//   of the C++ standard).  As a result, gcc fails to reject the
1938//   following code with the simple definition:
1939//
1940//     int foo;
1941//     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
1942//                                      // not a compile-time constant.
1943//
1944// - By using the type CompileAssert<(bool(expr))>, we ensures that
1945//   expr is a compile-time constant.  (Template arguments must be
1946//   determined at compile-time.)
1947//
1948// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
1949//   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written
1950//
1951//     CompileAssert<bool(expr)>
1952//
1953//   instead, these compilers will refuse to compile
1954//
1955//     GTEST_COMPILE_ASSERT_(5 > 0, some_message);
1956//
1957//   (They seem to think the ">" in "5 > 0" marks the end of the
1958//   template argument list.)
1959//
1960// - The array size is (bool(expr) ? 1 : -1), instead of simply
1961//
1962//     ((expr) ? 1 : -1).
1963//
1964//   This is to avoid running into a bug in MS VC 7.1, which
1965//   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
1966
1967// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
1968//
1969// This template is declared, but intentionally undefined.
1970template <typename T1, typename T2>
1971struct StaticAssertTypeEqHelper;
1972
1973template <typename T>
1974struct StaticAssertTypeEqHelper<T, T> {};
1975
1976#if GTEST_HAS_GLOBAL_STRING
1977typedef ::string string;
1978#else
1979typedef ::std::string string;
1980#endif  // GTEST_HAS_GLOBAL_STRING
1981
1982#if GTEST_HAS_GLOBAL_WSTRING
1983typedef ::wstring wstring;
1984#elif GTEST_HAS_STD_WSTRING
1985typedef ::std::wstring wstring;
1986#endif  // GTEST_HAS_GLOBAL_WSTRING
1987
1988// A helper for suppressing warnings on constant condition.  It just
1989// returns 'condition'.
1990GTEST_API_ bool IsTrue(bool condition);
1991
1992// Defines scoped_ptr.
1993
1994// This implementation of scoped_ptr is PARTIAL - it only contains
1995// enough stuff to satisfy Google Test's need.
1996template <typename T>
1997class scoped_ptr {
1998 public:
1999  typedef T element_type;
2000
2001  explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
2002  ~scoped_ptr() { reset(); }
2003
2004  T& operator*() const { return *ptr_; }
2005  T* operator->() const { return ptr_; }
2006  T* get() const { return ptr_; }
2007
2008  T* release() {
2009    T* const ptr = ptr_;
2010    ptr_ = NULL;
2011    return ptr;
2012  }
2013
2014  void reset(T* p = NULL) {
2015    if (p != ptr_) {
2016      if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.
2017        delete ptr_;
2018      }
2019      ptr_ = p;
2020    }
2021  }
2022
2023 private:
2024  T* ptr_;
2025
2026  GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
2027};
2028
2029// Defines RE.
2030
2031// A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended
2032// Regular Expression syntax.
2033class GTEST_API_ RE {
2034 public:
2035  // A copy constructor is required by the Standard to initialize object
2036  // references from r-values.
2037  RE(const RE& other) { Init(other.pattern()); }
2038
2039  // Constructs an RE from a string.
2040  RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT
2041
2042#if GTEST_HAS_GLOBAL_STRING
2043
2044  RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT
2045
2046#endif  // GTEST_HAS_GLOBAL_STRING
2047
2048  RE(const char* regex) { Init(regex); }  // NOLINT
2049  ~RE();
2050
2051  // Returns the string representation of the regex.
2052  const char* pattern() const { return pattern_; }
2053
2054  // FullMatch(str, re) returns true iff regular expression re matches
2055  // the entire str.
2056  // PartialMatch(str, re) returns true iff regular expression re
2057  // matches a substring of str (including str itself).
2058  //
2059  // TODO(wan@google.com): make FullMatch() and PartialMatch() work
2060  // when str contains NUL characters.
2061  static bool FullMatch(const ::std::string& str, const RE& re) {
2062    return FullMatch(str.c_str(), re);
2063  }
2064  static bool PartialMatch(const ::std::string& str, const RE& re) {
2065    return PartialMatch(str.c_str(), re);
2066  }
2067
2068#if GTEST_HAS_GLOBAL_STRING
2069
2070  static bool FullMatch(const ::string& str, const RE& re) {
2071    return FullMatch(str.c_str(), re);
2072  }
2073  static bool PartialMatch(const ::string& str, const RE& re) {
2074    return PartialMatch(str.c_str(), re);
2075  }
2076
2077#endif  // GTEST_HAS_GLOBAL_STRING
2078
2079  static bool FullMatch(const char* str, const RE& re);
2080  static bool PartialMatch(const char* str, const RE& re);
2081
2082 private:
2083  void Init(const char* regex);
2084
2085  // We use a const char* instead of an std::string, as Google Test used to be
2086  // used where std::string is not available.  TODO(wan@google.com): change to
2087  // std::string.
2088  const char* pattern_;
2089  bool is_valid_;
2090
2091#if GTEST_USES_POSIX_RE
2092
2093  regex_t full_regex_;     // For FullMatch().
2094  regex_t partial_regex_;  // For PartialMatch().
2095
2096#else  // GTEST_USES_SIMPLE_RE
2097
2098  const char* full_pattern_;  // For FullMatch();
2099
2100#endif
2101
2102  GTEST_DISALLOW_ASSIGN_(RE);
2103};
2104
2105// Formats a source file path and a line number as they would appear
2106// in an error message from the compiler used to compile this code.
2107GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
2108
2109// Formats a file location for compiler-independent XML output.
2110// Although this function is not platform dependent, we put it next to
2111// FormatFileLocation in order to contrast the two functions.
2112GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
2113                                                               int line);
2114
2115// Defines logging utilities:
2116//   GTEST_LOG_(severity) - logs messages at the specified severity level. The
2117//                          message itself is streamed into the macro.
2118//   LogToStderr()  - directs all log messages to stderr.
2119//   FlushInfoLog() - flushes informational log messages.
2120
2121enum GTestLogSeverity {
2122  GTEST_INFO,
2123  GTEST_WARNING,
2124  GTEST_ERROR,
2125  GTEST_FATAL
2126};
2127
2128// Formats log entry severity, provides a stream object for streaming the
2129// log message, and terminates the message with a newline when going out of
2130// scope.
2131class GTEST_API_ GTestLog {
2132 public:
2133  GTestLog(GTestLogSeverity severity, const char* file, int line);
2134
2135  // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
2136  ~GTestLog();
2137
2138  ::std::ostream& GetStream() { return ::std::cerr; }
2139
2140 private:
2141  const GTestLogSeverity severity_;
2142
2143  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
2144};
2145
2146#define GTEST_LOG_(severity) \
2147    ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
2148                                  __FILE__, __LINE__).GetStream()
2149
2150inline void LogToStderr() {}
2151inline void FlushInfoLog() { fflush(NULL); }
2152
2153// INTERNAL IMPLEMENTATION - DO NOT USE.
2154//
2155// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
2156// is not satisfied.
2157//  Synopsys:
2158//    GTEST_CHECK_(boolean_condition);
2159//     or
2160//    GTEST_CHECK_(boolean_condition) << "Additional message";
2161//
2162//    This checks the condition and if the condition is not satisfied
2163//    it prints message about the condition violation, including the
2164//    condition itself, plus additional message streamed into it, if any,
2165//    and then it aborts the program. It aborts the program irrespective of
2166//    whether it is built in the debug mode or not.
2167#define GTEST_CHECK_(condition) \
2168    GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
2169    if (::testing::internal::IsTrue(condition)) \
2170      ; \
2171    else \
2172      GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
2173
2174// An all-mode assert to verify that the given POSIX-style function
2175// call returns 0 (indicating success).  Known limitation: this
2176// doesn't expand to a balanced 'if' statement, so enclose the macro
2177// in {} if you need to use it as the only statement in an 'if'
2178// branch.
2179#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
2180  if (const int gtest_error = (posix_call)) \
2181    GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
2182                      << gtest_error
2183
2184// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
2185//
2186// Use ImplicitCast_ as a safe version of static_cast for upcasting in
2187// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
2188// const Foo*).  When you use ImplicitCast_, the compiler checks that
2189// the cast is safe.  Such explicit ImplicitCast_s are necessary in
2190// surprisingly many situations where C++ demands an exact type match
2191// instead of an argument type convertable to a target type.
2192//
2193// The syntax for using ImplicitCast_ is the same as for static_cast:
2194//
2195//   ImplicitCast_<ToType>(expr)
2196//
2197// ImplicitCast_ would have been part of the C++ standard library,
2198// but the proposal was submitted too late.  It will probably make
2199// its way into the language in the future.
2200//
2201// This relatively ugly name is intentional. It prevents clashes with
2202// similar functions users may have (e.g., implicit_cast). The internal
2203// namespace alone is not enough because the function can be found by ADL.
2204template<typename To>
2205inline To ImplicitCast_(To x) { return x; }
2206
2207// When you upcast (that is, cast a pointer from type Foo to type
2208// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
2209// always succeed.  When you downcast (that is, cast a pointer from
2210// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
2211// how do you know the pointer is really of type SubclassOfFoo?  It
2212// could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
2213// when you downcast, you should use this macro.  In debug mode, we
2214// use dynamic_cast<> to double-check the downcast is legal (we die
2215// if it's not).  In normal mode, we do the efficient static_cast<>
2216// instead.  Thus, it's important to test in debug mode to make sure
2217// the cast is legal!
2218//    This is the only place in the code we should use dynamic_cast<>.
2219// In particular, you SHOULDN'T be using dynamic_cast<> in order to
2220// do RTTI (eg code like this:
2221//    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
2222//    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
2223// You should design the code some other way not to need this.
2224//
2225// This relatively ugly name is intentional. It prevents clashes with
2226// similar functions users may have (e.g., down_cast). The internal
2227// namespace alone is not enough because the function can be found by ADL.
2228template<typename To, typename From>  // use like this: DownCast_<T*>(foo);
2229inline To DownCast_(From* f) {  // so we only accept pointers
2230  // Ensures that To is a sub-type of From *.  This test is here only
2231  // for compile-time type checking, and has no overhead in an
2232  // optimized build at run-time, as it will be optimized away
2233  // completely.
2234  if (false) {
2235    const To to = NULL;
2236    ::testing::internal::ImplicitCast_<From*>(to);
2237  }
2238
2239#if GTEST_HAS_RTTI
2240  // RTTI: debug mode only!
2241  GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
2242#endif
2243  return static_cast<To>(f);
2244}
2245
2246// Downcasts the pointer of type Base to Derived.
2247// Derived must be a subclass of Base. The parameter MUST
2248// point to a class of type Derived, not any subclass of it.
2249// When RTTI is available, the function performs a runtime
2250// check to enforce this.
2251template <class Derived, class Base>
2252Derived* CheckedDowncastToActualType(Base* base) {
2253#if GTEST_HAS_RTTI
2254  GTEST_CHECK_(typeid(*base) == typeid(Derived));
2255  return dynamic_cast<Derived*>(base);  // NOLINT
2256#else
2257  return static_cast<Derived*>(base);  // Poor man's downcast.
2258#endif
2259}
2260
2261#if GTEST_HAS_STREAM_REDIRECTION
2262
2263// Defines the stderr capturer:
2264//   CaptureStdout     - starts capturing stdout.
2265//   GetCapturedStdout - stops capturing stdout and returns the captured string.
2266//   CaptureStderr     - starts capturing stderr.
2267//   GetCapturedStderr - stops capturing stderr and returns the captured string.
2268//
2269GTEST_API_ void CaptureStdout();
2270GTEST_API_ std::string GetCapturedStdout();
2271GTEST_API_ void CaptureStderr();
2272GTEST_API_ std::string GetCapturedStderr();
2273
2274#endif  // GTEST_HAS_STREAM_REDIRECTION
2275
2276
2277#if GTEST_HAS_DEATH_TEST
2278
2279const ::std::vector<testing::internal::string>& GetInjectableArgvs();
2280void SetInjectableArgvs(const ::std::vector<testing::internal::string>*
2281                             new_argvs);
2282
2283// A copy of all command line arguments.  Set by InitGoogleTest().
2284extern ::std::vector<testing::internal::string> g_argvs;
2285
2286#endif  // GTEST_HAS_DEATH_TEST
2287
2288// Defines synchronization primitives.
2289
2290#if GTEST_HAS_PTHREAD
2291
2292// Sleeps for (roughly) n milli-seconds.  This function is only for
2293// testing Google Test's own constructs.  Don't use it in user tests,
2294// either directly or indirectly.
2295inline void SleepMilliseconds(int n) {
2296  const timespec time = {
2297    0,                  // 0 seconds.
2298    n * 1000L * 1000L,  // And n ms.
2299  };
2300  nanosleep(&time, NULL);
2301}
2302
2303// Allows a controller thread to pause execution of newly created
2304// threads until notified.  Instances of this class must be created
2305// and destroyed in the controller thread.
2306//
2307// This class is only for testing Google Test's own constructs. Do not
2308// use it in user tests, either directly or indirectly.
2309class Notification {
2310 public:
2311  Notification() : notified_(false) {
2312    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
2313  }
2314  ~Notification() {
2315    pthread_mutex_destroy(&mutex_);
2316  }
2317
2318  // Notifies all threads created with this notification to start. Must
2319  // be called from the controller thread.
2320  void Notify() {
2321    pthread_mutex_lock(&mutex_);
2322    notified_ = true;
2323    pthread_mutex_unlock(&mutex_);
2324  }
2325
2326  // Blocks until the controller thread notifies. Must be called from a test
2327  // thread.
2328  void WaitForNotification() {
2329    for (;;) {
2330      pthread_mutex_lock(&mutex_);
2331      const bool notified = notified_;
2332      pthread_mutex_unlock(&mutex_);
2333      if (notified)
2334        break;
2335      SleepMilliseconds(10);
2336    }
2337  }
2338
2339 private:
2340  pthread_mutex_t mutex_;
2341  bool notified_;
2342
2343  GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
2344};
2345
2346// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
2347// Consequently, it cannot select a correct instantiation of ThreadWithParam
2348// in order to call its Run(). Introducing ThreadWithParamBase as a
2349// non-templated base class for ThreadWithParam allows us to bypass this
2350// problem.
2351class ThreadWithParamBase {
2352 public:
2353  virtual ~ThreadWithParamBase() {}
2354  virtual void Run() = 0;
2355};
2356
2357// pthread_create() accepts a pointer to a function type with the C linkage.
2358// According to the Standard (7.5/1), function types with different linkages
2359// are different even if they are otherwise identical.  Some compilers (for
2360// example, SunStudio) treat them as different types.  Since class methods
2361// cannot be defined with C-linkage we need to define a free C-function to
2362// pass into pthread_create().
2363extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
2364  static_cast<ThreadWithParamBase*>(thread)->Run();
2365  return NULL;
2366}
2367
2368// Helper class for testing Google Test's multi-threading constructs.
2369// To use it, write:
2370//
2371//   void ThreadFunc(int param) { /* Do things with param */ }
2372//   Notification thread_can_start;
2373//   ...
2374//   // The thread_can_start parameter is optional; you can supply NULL.
2375//   ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
2376//   thread_can_start.Notify();
2377//
2378// These classes are only for testing Google Test's own constructs. Do
2379// not use them in user tests, either directly or indirectly.
2380template <typename T>
2381class ThreadWithParam : public ThreadWithParamBase {
2382 public:
2383  typedef void (*UserThreadFunc)(T);
2384
2385  ThreadWithParam(
2386      UserThreadFunc func, T param, Notification* thread_can_start)
2387      : func_(func),
2388        param_(param),
2389        thread_can_start_(thread_can_start),
2390        finished_(false) {
2391    ThreadWithParamBase* const base = this;
2392    // The thread can be created only after all fields except thread_
2393    // have been initialized.
2394    GTEST_CHECK_POSIX_SUCCESS_(
2395        pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
2396  }
2397  ~ThreadWithParam() { Join(); }
2398
2399  void Join() {
2400    if (!finished_) {
2401      GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
2402      finished_ = true;
2403    }
2404  }
2405
2406  virtual void Run() {
2407    if (thread_can_start_ != NULL)
2408      thread_can_start_->WaitForNotification();
2409    func_(param_);
2410  }
2411
2412 private:
2413  const UserThreadFunc func_;  // User-supplied thread function.
2414  const T param_;  // User-supplied parameter to the thread function.
2415  // When non-NULL, used to block execution until the controller thread
2416  // notifies.
2417  Notification* const thread_can_start_;
2418  bool finished_;  // true iff we know that the thread function has finished.
2419  pthread_t thread_;  // The native thread object.
2420
2421  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
2422};
2423
2424// MutexBase and Mutex implement mutex on pthreads-based platforms. They
2425// are used in conjunction with class MutexLock:
2426//
2427//   Mutex mutex;
2428//   ...
2429//   MutexLock lock(&mutex);  // Acquires the mutex and releases it at the end
2430//                            // of the current scope.
2431//
2432// MutexBase implements behavior for both statically and dynamically
2433// allocated mutexes.  Do not use MutexBase directly.  Instead, write
2434// the following to define a static mutex:
2435//
2436//   GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
2437//
2438// You can forward declare a static mutex like this:
2439//
2440//   GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
2441//
2442// To create a dynamic mutex, just define an object of type Mutex.
2443class MutexBase {
2444 public:
2445  // Acquires this mutex.
2446  void Lock() {
2447    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
2448    owner_ = pthread_self();
2449    has_owner_ = true;
2450  }
2451
2452  // Releases this mutex.
2453  void Unlock() {
2454    // Since the lock is being released the owner_ field should no longer be
2455    // considered valid. We don't protect writing to has_owner_ here, as it's
2456    // the caller's responsibility to ensure that the current thread holds the
2457    // mutex when this is called.
2458    has_owner_ = false;
2459    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
2460  }
2461
2462  // Does nothing if the current thread holds the mutex. Otherwise, crashes
2463  // with high probability.
2464  void AssertHeld() const {
2465    GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
2466        << "The current thread is not holding the mutex @" << this;
2467  }
2468
2469  // A static mutex may be used before main() is entered.  It may even
2470  // be used before the dynamic initialization stage.  Therefore we
2471  // must be able to initialize a static mutex object at link time.
2472  // This means MutexBase has to be a POD and its member variables
2473  // have to be public.
2474 public:
2475  pthread_mutex_t mutex_;  // The underlying pthread mutex.
2476  // has_owner_ indicates whether the owner_ field below contains a valid thread
2477  // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
2478  // accesses to the owner_ field should be protected by a check of this field.
2479  // An alternative might be to memset() owner_ to all zeros, but there's no
2480  // guarantee that a zero'd pthread_t is necessarily invalid or even different
2481  // from pthread_self().
2482  bool has_owner_;
2483  pthread_t owner_;  // The thread holding the mutex.
2484};
2485
2486// Forward-declares a static mutex.
2487# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
2488    extern ::testing::internal::MutexBase mutex
2489
2490// Defines and statically (i.e. at link time) initializes a static mutex.
2491// The initialization list here does not explicitly initialize each field,
2492// instead relying on default initialization for the unspecified fields. In
2493// particular, the owner_ field (a pthread_t) is not explicitly initialized.
2494// This allows initialization to work whether pthread_t is a scalar or struct.
2495// The flag -Wmissing-field-initializers must not be specified for this to work.
2496# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
2497    ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
2498
2499// The Mutex class can only be used for mutexes created at runtime. It
2500// shares its API with MutexBase otherwise.
2501class Mutex : public MutexBase {
2502 public:
2503  Mutex() {
2504    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
2505    has_owner_ = false;
2506  }
2507  ~Mutex() {
2508    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
2509  }
2510
2511 private:
2512  GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
2513};
2514
2515// We cannot name this class MutexLock as the ctor declaration would
2516// conflict with a macro named MutexLock, which is defined on some
2517// platforms.  Hence the typedef trick below.
2518class GTestMutexLock {
2519 public:
2520  explicit GTestMutexLock(MutexBase* mutex)
2521      : mutex_(mutex) { mutex_->Lock(); }
2522
2523  ~GTestMutexLock() { mutex_->Unlock(); }
2524
2525 private:
2526  MutexBase* const mutex_;
2527
2528  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
2529};
2530
2531typedef GTestMutexLock MutexLock;
2532
2533// Helpers for ThreadLocal.
2534
2535// pthread_key_create() requires DeleteThreadLocalValue() to have
2536// C-linkage.  Therefore it cannot be templatized to access
2537// ThreadLocal<T>.  Hence the need for class
2538// ThreadLocalValueHolderBase.
2539class ThreadLocalValueHolderBase {
2540 public:
2541  virtual ~ThreadLocalValueHolderBase() {}
2542};
2543
2544// Called by pthread to delete thread-local data stored by
2545// pthread_setspecific().
2546extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
2547  delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
2548}
2549
2550// Implements thread-local storage on pthreads-based systems.
2551//
2552//   // Thread 1
2553//   ThreadLocal<int> tl(100);  // 100 is the default value for each thread.
2554//
2555//   // Thread 2
2556//   tl.set(150);  // Changes the value for thread 2 only.
2557//   EXPECT_EQ(150, tl.get());
2558//
2559//   // Thread 1
2560//   EXPECT_EQ(100, tl.get());  // In thread 1, tl has the original value.
2561//   tl.set(200);
2562//   EXPECT_EQ(200, tl.get());
2563//
2564// The template type argument T must have a public copy constructor.
2565// In addition, the default ThreadLocal constructor requires T to have
2566// a public default constructor.
2567//
2568// An object managed for a thread by a ThreadLocal instance is deleted
2569// when the thread exits.  Or, if the ThreadLocal instance dies in
2570// that thread, when the ThreadLocal dies.  It's the user's
2571// responsibility to ensure that all other threads using a ThreadLocal
2572// have exited when it dies, or the per-thread objects for those
2573// threads will not be deleted.
2574//
2575// Google Test only uses global ThreadLocal objects.  That means they
2576// will die after main() has returned.  Therefore, no per-thread
2577// object managed by Google Test will be leaked as long as all threads
2578// using Google Test have exited when main() returns.
2579template <typename T>
2580class ThreadLocal {
2581 public:
2582  ThreadLocal() : key_(CreateKey()),
2583                  default_() {}
2584  explicit ThreadLocal(const T& value) : key_(CreateKey()),
2585                                         default_(value) {}
2586
2587  ~ThreadLocal() {
2588    // Destroys the managed object for the current thread, if any.
2589    DeleteThreadLocalValue(pthread_getspecific(key_));
2590
2591    // Releases resources associated with the key.  This will *not*
2592    // delete managed objects for other threads.
2593    GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
2594  }
2595
2596  T* pointer() { return GetOrCreateValue(); }
2597  const T* pointer() const { return GetOrCreateValue(); }
2598  const T& get() const { return *pointer(); }
2599  void set(const T& value) { *pointer() = value; }
2600
2601 private:
2602  // Holds a value of type T.
2603  class ValueHolder : public ThreadLocalValueHolderBase {
2604   public:
2605    explicit ValueHolder(const T& value) : value_(value) {}
2606
2607    T* pointer() { return &value_; }
2608
2609   private:
2610    T value_;
2611    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
2612  };
2613
2614  static pthread_key_t CreateKey() {
2615    pthread_key_t key;
2616    // When a thread exits, DeleteThreadLocalValue() will be called on
2617    // the object managed for that thread.
2618    GTEST_CHECK_POSIX_SUCCESS_(
2619        pthread_key_create(&key, &DeleteThreadLocalValue));
2620    return key;
2621  }
2622
2623  T* GetOrCreateValue() const {
2624    ThreadLocalValueHolderBase* const holder =
2625        static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
2626    if (holder != NULL) {
2627      return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
2628    }
2629
2630    ValueHolder* const new_holder = new ValueHolder(default_);
2631    ThreadLocalValueHolderBase* const holder_base = new_holder;
2632    GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
2633    return new_holder->pointer();
2634  }
2635
2636  // A key pthreads uses for looking up per-thread values.
2637  const pthread_key_t key_;
2638  const T default_;  // The default value for each thread.
2639
2640  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
2641};
2642
2643# define GTEST_IS_THREADSAFE 1
2644
2645#else  // GTEST_HAS_PTHREAD
2646
2647// A dummy implementation of synchronization primitives (mutex, lock,
2648// and thread-local variable).  Necessary for compiling Google Test where
2649// mutex is not supported - using Google Test in multiple threads is not
2650// supported on such platforms.
2651
2652class Mutex {
2653 public:
2654  Mutex() {}
2655  void Lock() {}
2656  void Unlock() {}
2657  void AssertHeld() const {}
2658};
2659
2660# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
2661  extern ::testing::internal::Mutex mutex
2662
2663# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
2664
2665class GTestMutexLock {
2666 public:
2667  explicit GTestMutexLock(Mutex*) {}  // NOLINT
2668};
2669
2670typedef GTestMutexLock MutexLock;
2671
2672template <typename T>
2673class ThreadLocal {
2674 public:
2675  ThreadLocal() : value_() {}
2676  explicit ThreadLocal(const T& value) : value_(value) {}
2677  T* pointer() { return &value_; }
2678  const T* pointer() const { return &value_; }
2679  const T& get() const { return value_; }
2680  void set(const T& value) { value_ = value; }
2681 private:
2682  T value_;
2683};
2684
2685// The above synchronization primitives have dummy implementations.
2686// Therefore Google Test is not thread-safe.
2687# define GTEST_IS_THREADSAFE 0
2688
2689#endif  // GTEST_HAS_PTHREAD
2690
2691// Returns the number of threads running in the process, or 0 to indicate that
2692// we cannot detect it.
2693GTEST_API_ size_t GetThreadCount();
2694
2695// Passing non-POD classes through ellipsis (...) crashes the ARM
2696// compiler and generates a warning in Sun Studio.  The Nokia Symbian
2697// and the IBM XL C/C++ compiler try to instantiate a copy constructor
2698// for objects passed through ellipsis (...), failing for uncopyable
2699// objects.  We define this to ensure that only POD is passed through
2700// ellipsis on these systems.
2701#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
2702// We lose support for NULL detection where the compiler doesn't like
2703// passing non-POD classes through ellipsis (...).
2704# define GTEST_ELLIPSIS_NEEDS_POD_ 1
2705#else
2706# define GTEST_CAN_COMPARE_NULL 1
2707#endif
2708
2709// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
2710// const T& and const T* in a function template.  These compilers
2711// _can_ decide between class template specializations for T and T*,
2712// so a tr1::type_traits-like is_pointer works.
2713#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
2714# define GTEST_NEEDS_IS_POINTER_ 1
2715#endif
2716
2717template <bool bool_value>
2718struct bool_constant {
2719  typedef bool_constant<bool_value> type;
2720  static const bool value = bool_value;
2721};
2722template <bool bool_value> const bool bool_constant<bool_value>::value;
2723
2724typedef bool_constant<false> false_type;
2725typedef bool_constant<true> true_type;
2726
2727template <typename T>
2728struct is_pointer : public false_type {};
2729
2730template <typename T>
2731struct is_pointer<T*> : public true_type {};
2732
2733template <typename Iterator>
2734struct IteratorTraits {
2735  typedef typename Iterator::value_type value_type;
2736};
2737
2738template <typename T>
2739struct IteratorTraits<T*> {
2740  typedef T value_type;
2741};
2742
2743template <typename T>
2744struct IteratorTraits<const T*> {
2745  typedef T value_type;
2746};
2747
2748#if GTEST_OS_WINDOWS
2749# define GTEST_PATH_SEP_ "\\"
2750# define GTEST_HAS_ALT_PATH_SEP_ 1
2751// The biggest signed integer type the compiler supports.
2752typedef __int64 BiggestInt;
2753#else
2754# define GTEST_PATH_SEP_ "/"
2755# define GTEST_HAS_ALT_PATH_SEP_ 0
2756typedef long long BiggestInt;  // NOLINT
2757#endif  // GTEST_OS_WINDOWS
2758
2759// Utilities for char.
2760
2761// isspace(int ch) and friends accept an unsigned char or EOF.  char
2762// may be signed, depending on the compiler (or compiler flags).
2763// Therefore we need to cast a char to unsigned char before calling
2764// isspace(), etc.
2765
2766inline bool IsAlpha(char ch) {
2767  return isalpha(static_cast<unsigned char>(ch)) != 0;
2768}
2769inline bool IsAlNum(char ch) {
2770  return isalnum(static_cast<unsigned char>(ch)) != 0;
2771}
2772inline bool IsDigit(char ch) {
2773  return isdigit(static_cast<unsigned char>(ch)) != 0;
2774}
2775inline bool IsLower(char ch) {
2776  return islower(static_cast<unsigned char>(ch)) != 0;
2777}
2778inline bool IsSpace(char ch) {
2779  return isspace(static_cast<unsigned char>(ch)) != 0;
2780}
2781inline bool IsUpper(char ch) {
2782  return isupper(static_cast<unsigned char>(ch)) != 0;
2783}
2784inline bool IsXDigit(char ch) {
2785  return isxdigit(static_cast<unsigned char>(ch)) != 0;
2786}
2787inline bool IsXDigit(wchar_t ch) {
2788  const unsigned char low_byte = static_cast<unsigned char>(ch);
2789  return ch == low_byte && isxdigit(low_byte) != 0;
2790}
2791
2792inline char ToLower(char ch) {
2793  return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
2794}
2795inline char ToUpper(char ch) {
2796  return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
2797}
2798
2799// The testing::internal::posix namespace holds wrappers for common
2800// POSIX functions.  These wrappers hide the differences between
2801// Windows/MSVC and POSIX systems.  Since some compilers define these
2802// standard functions as macros, the wrapper cannot have the same name
2803// as the wrapped function.
2804
2805namespace posix {
2806
2807// Functions with a different name on Windows.
2808
2809#if GTEST_OS_WINDOWS
2810
2811typedef struct _stat StatStruct;
2812
2813# ifdef __BORLANDC__
2814inline int IsATTY(int fd) { return isatty(fd); }
2815inline int StrCaseCmp(const char* s1, const char* s2) {
2816  return stricmp(s1, s2);
2817}
2818inline char* StrDup(const char* src) { return strdup(src); }
2819# else  // !__BORLANDC__
2820#  if GTEST_OS_WINDOWS_MOBILE
2821inline int IsATTY(int /* fd */) { return 0; }
2822#  else
2823inline int IsATTY(int fd) { return _isatty(fd); }
2824#  endif  // GTEST_OS_WINDOWS_MOBILE
2825inline int StrCaseCmp(const char* s1, const char* s2) {
2826  return _stricmp(s1, s2);
2827}
2828inline char* StrDup(const char* src) { return _strdup(src); }
2829# endif  // __BORLANDC__
2830
2831# if GTEST_OS_WINDOWS_MOBILE
2832inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
2833// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
2834// time and thus not defined there.
2835# else
2836inline int FileNo(FILE* file) { return _fileno(file); }
2837inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
2838inline int RmDir(const char* dir) { return _rmdir(dir); }
2839inline bool IsDir(const StatStruct& st) {
2840  return (_S_IFDIR & st.st_mode) != 0;
2841}
2842# endif  // GTEST_OS_WINDOWS_MOBILE
2843
2844#else
2845
2846typedef struct stat StatStruct;
2847
2848inline int FileNo(FILE* file) { return fileno(file); }
2849inline int IsATTY(int fd) { return isatty(fd); }
2850inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
2851inline int StrCaseCmp(const char* s1, const char* s2) {
2852  return strcasecmp(s1, s2);
2853}
2854inline char* StrDup(const char* src) { return strdup(src); }
2855inline int RmDir(const char* dir) { return rmdir(dir); }
2856inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
2857
2858#endif  // GTEST_OS_WINDOWS
2859
2860// Functions deprecated by MSVC 8.0.
2861
2862#ifdef _MSC_VER
2863// Temporarily disable warning 4996 (deprecated function).
2864# pragma warning(push)
2865# pragma warning(disable:4996)
2866#endif
2867
2868inline const char* StrNCpy(char* dest, const char* src, size_t n) {
2869  return strncpy(dest, src, n);
2870}
2871
2872// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
2873// StrError() aren't needed on Windows CE at this time and thus not
2874// defined there.
2875
2876#if !GTEST_OS_WINDOWS_MOBILE
2877inline int ChDir(const char* dir) { return chdir(dir); }
2878#endif
2879inline FILE* FOpen(const char* path, const char* mode) {
2880  return fopen(path, mode);
2881}
2882#if !GTEST_OS_WINDOWS_MOBILE
2883inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
2884  return freopen(path, mode, stream);
2885}
2886inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
2887#endif
2888inline int FClose(FILE* fp) { return fclose(fp); }
2889#if !GTEST_OS_WINDOWS_MOBILE
2890inline int Read(int fd, void* buf, unsigned int count) {
2891  return static_cast<int>(read(fd, buf, count));
2892}
2893inline int Write(int fd, const void* buf, unsigned int count) {
2894  return static_cast<int>(write(fd, buf, count));
2895}
2896inline int Close(int fd) { return close(fd); }
2897inline const char* StrError(int errnum) { return strerror(errnum); }
2898#endif
2899inline const char* GetEnv(const char* name) {
2900#if GTEST_OS_WINDOWS_MOBILE
2901  // We are on Windows CE, which has no environment variables.
2902  return NULL;
2903#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
2904  // Environment variables which we programmatically clear will be set to the
2905  // empty string rather than unset (NULL).  Handle that case.
2906  const char* const env = getenv(name);
2907  return (env != NULL && env[0] != '\0') ? env : NULL;
2908#else
2909  return getenv(name);
2910#endif
2911}
2912
2913#ifdef _MSC_VER
2914# pragma warning(pop)  // Restores the warning state.
2915#endif
2916
2917#if GTEST_OS_WINDOWS_MOBILE
2918// Windows CE has no C library. The abort() function is used in
2919// several places in Google Test. This implementation provides a reasonable
2920// imitation of standard behaviour.
2921void Abort();
2922#else
2923inline void Abort() { abort(); }
2924#endif  // GTEST_OS_WINDOWS_MOBILE
2925
2926}  // namespace posix
2927
2928// MSVC "deprecates" snprintf and issues warnings wherever it is used.  In
2929// order to avoid these warnings, we need to use _snprintf or _snprintf_s on
2930// MSVC-based platforms.  We map the GTEST_SNPRINTF_ macro to the appropriate
2931// function in order to achieve that.  We use macro definition here because
2932// snprintf is a variadic function.
2933#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
2934// MSVC 2005 and above support variadic macros.
2935# define GTEST_SNPRINTF_(buffer, size, format, ...) \
2936     _snprintf_s(buffer, size, size, format, __VA_ARGS__)
2937#elif defined(_MSC_VER)
2938// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
2939// complain about _snprintf.
2940# define GTEST_SNPRINTF_ _snprintf
2941#else
2942# define GTEST_SNPRINTF_ snprintf
2943#endif
2944
2945// The maximum number a BiggestInt can represent.  This definition
2946// works no matter BiggestInt is represented in one's complement or
2947// two's complement.
2948//
2949// We cannot rely on numeric_limits in STL, as __int64 and long long
2950// are not part of standard C++ and numeric_limits doesn't need to be
2951// defined for them.
2952const BiggestInt kMaxBiggestInt =
2953    ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
2954
2955// This template class serves as a compile-time function from size to
2956// type.  It maps a size in bytes to a primitive type with that
2957// size. e.g.
2958//
2959//   TypeWithSize<4>::UInt
2960//
2961// is typedef-ed to be unsigned int (unsigned integer made up of 4
2962// bytes).
2963//
2964// Such functionality should belong to STL, but I cannot find it
2965// there.
2966//
2967// Google Test uses this class in the implementation of floating-point
2968// comparison.
2969//
2970// For now it only handles UInt (unsigned int) as that's all Google Test
2971// needs.  Other types can be easily added in the future if need
2972// arises.
2973template <size_t size>
2974class TypeWithSize {
2975 public:
2976  // This prevents the user from using TypeWithSize<N> with incorrect
2977  // values of N.
2978  typedef void UInt;
2979};
2980
2981// The specialization for size 4.
2982template <>
2983class TypeWithSize<4> {
2984 public:
2985  // unsigned int has size 4 in both gcc and MSVC.
2986  //
2987  // As base/basictypes.h doesn't compile on Windows, we cannot use
2988  // uint32, uint64, and etc here.
2989  typedef int Int;
2990  typedef unsigned int UInt;
2991};
2992
2993// The specialization for size 8.
2994template <>
2995class TypeWithSize<8> {
2996 public:
2997#if GTEST_OS_WINDOWS
2998  typedef __int64 Int;
2999  typedef unsigned __int64 UInt;
3000#else
3001  typedef long long Int;  // NOLINT
3002  typedef unsigned long long UInt;  // NOLINT
3003#endif  // GTEST_OS_WINDOWS
3004};
3005
3006// Integer types of known sizes.
3007typedef TypeWithSize<4>::Int Int32;
3008typedef TypeWithSize<4>::UInt UInt32;
3009typedef TypeWithSize<8>::Int Int64;
3010typedef TypeWithSize<8>::UInt UInt64;
3011typedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.
3012
3013// Utilities for command line flags and environment variables.
3014
3015// Macro for referencing flags.
3016#define GTEST_FLAG(name) FLAGS_gtest_##name
3017
3018// Macros for declaring flags.
3019#define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
3020#define GTEST_DECLARE_int32_(name) \
3021    GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
3022#define GTEST_DECLARE_string_(name) \
3023    GTEST_API_ extern ::std::string GTEST_FLAG(name)
3024
3025// Macros for defining flags.
3026#define GTEST_DEFINE_bool_(name, default_val, doc) \
3027    GTEST_API_ bool GTEST_FLAG(name) = (default_val)
3028#define GTEST_DEFINE_int32_(name, default_val, doc) \
3029    GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
3030#define GTEST_DEFINE_string_(name, default_val, doc) \
3031    GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
3032
3033// Thread annotations
3034#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
3035#define GTEST_LOCK_EXCLUDED_(locks)
3036
3037// Parses 'str' for a 32-bit signed integer.  If successful, writes the result
3038// to *value and returns true; otherwise leaves *value unchanged and returns
3039// false.
3040// TODO(chandlerc): Find a better way to refactor flag and environment parsing
3041// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
3042// function.
3043bool ParseInt32(const Message& src_text, const char* str, Int32* value);
3044
3045// Parses a bool/Int32/string from the environment variable
3046// corresponding to the given Google Test flag.
3047bool BoolFromGTestEnv(const char* flag, bool default_val);
3048GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
3049const char* StringFromGTestEnv(const char* flag, const char* default_val);
3050
3051}  // namespace internal
3052}  // namespace testing
3053
3054#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
3055
3056#if GTEST_OS_LINUX
3057# include <stdlib.h>
3058# include <sys/types.h>
3059# include <sys/wait.h>
3060# include <unistd.h>
3061#endif  // GTEST_OS_LINUX
3062
3063#if GTEST_HAS_EXCEPTIONS
3064# include <stdexcept>
3065#endif
3066
3067#include <ctype.h>
3068#include <float.h>
3069#include <string.h>
3070#include <iomanip>
3071#include <limits>
3072#include <set>
3073
3074// Copyright 2005, Google Inc.
3075// All rights reserved.
3076//
3077// Redistribution and use in source and binary forms, with or without
3078// modification, are permitted provided that the following conditions are
3079// met:
3080//
3081//     * Redistributions of source code must retain the above copyright
3082// notice, this list of conditions and the following disclaimer.
3083//     * Redistributions in binary form must reproduce the above
3084// copyright notice, this list of conditions and the following disclaimer
3085// in the documentation and/or other materials provided with the
3086// distribution.
3087//     * Neither the name of Google Inc. nor the names of its
3088// contributors may be used to endorse or promote products derived from
3089// this software without specific prior written permission.
3090//
3091// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3092// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3093// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3094// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3095// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3096// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3097// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3098// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3099// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3100// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3101// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3102//
3103// Author: wan@google.com (Zhanyong Wan)
3104//
3105// The Google C++ Testing Framework (Google Test)
3106//
3107// This header file defines the Message class.
3108//
3109// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
3110// leave some internal implementation details in this header file.
3111// They are clearly marked by comments like this:
3112//
3113//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
3114//
3115// Such code is NOT meant to be used by a user directly, and is subject
3116// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
3117// program!
3118
3119#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
3120#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
3121
3122#include <limits>
3123
3124
3125// Ensures that there is at least one operator<< in the global namespace.
3126// See Message& operator<<(...) below for why.
3127void operator<<(const testing::internal::Secret&, int);
3128
3129namespace testing {
3130
3131// The Message class works like an ostream repeater.
3132//
3133// Typical usage:
3134//
3135//   1. You stream a bunch of values to a Message object.
3136//      It will remember the text in a stringstream.
3137//   2. Then you stream the Message object to an ostream.
3138//      This causes the text in the Message to be streamed
3139//      to the ostream.
3140//
3141// For example;
3142//
3143//   testing::Message foo;
3144//   foo << 1 << " != " << 2;
3145//   std::cout << foo;
3146//
3147// will print "1 != 2".
3148//
3149// Message is not intended to be inherited from.  In particular, its
3150// destructor is not virtual.
3151//
3152// Note that stringstream behaves differently in gcc and in MSVC.  You
3153// can stream a NULL char pointer to it in the former, but not in the
3154// latter (it causes an access violation if you do).  The Message
3155// class hides this difference by treating a NULL char pointer as
3156// "(null)".
3157class GTEST_API_ Message {
3158 private:
3159  // The type of basic IO manipulators (endl, ends, and flush) for
3160  // narrow streams.
3161  typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);
3162
3163 public:
3164  // Constructs an empty Message.
3165  Message();
3166
3167  // Copy constructor.
3168  Message(const Message& msg) : ss_(new ::std::stringstream) {  // NOLINT
3169    *ss_ << msg.GetString();
3170  }
3171
3172  // Constructs a Message from a C-string.
3173  explicit Message(const char* str) : ss_(new ::std::stringstream) {
3174    *ss_ << str;
3175  }
3176
3177#if GTEST_OS_SYMBIAN
3178  // Streams a value (either a pointer or not) to this object.
3179  template <typename T>
3180  inline Message& operator <<(const T& value) {
3181    StreamHelper(typename internal::is_pointer<T>::type(), value);
3182    return *this;
3183  }
3184#else
3185  // Streams a non-pointer value to this object.
3186  template <typename T>
3187  inline Message& operator <<(const T& val) {
3188    // Some libraries overload << for STL containers.  These
3189    // overloads are defined in the global namespace instead of ::std.
3190    //
3191    // C++'s symbol lookup rule (i.e. Koenig lookup) says that these
3192    // overloads are visible in either the std namespace or the global
3193    // namespace, but not other namespaces, including the testing
3194    // namespace which Google Test's Message class is in.
3195    //
3196    // To allow STL containers (and other types that has a << operator
3197    // defined in the global namespace) to be used in Google Test
3198    // assertions, testing::Message must access the custom << operator
3199    // from the global namespace.  With this using declaration,
3200    // overloads of << defined in the global namespace and those
3201    // visible via Koenig lookup are both exposed in this function.
3202    using ::operator <<;
3203    *ss_ << val;
3204    return *this;
3205  }
3206
3207  // Streams a pointer value to this object.
3208  //
3209  // This function is an overload of the previous one.  When you
3210  // stream a pointer to a Message, this definition will be used as it
3211  // is more specialized.  (The C++ Standard, section
3212  // [temp.func.order].)  If you stream a non-pointer, then the
3213  // previous definition will be used.
3214  //
3215  // The reason for this overload is that streaming a NULL pointer to
3216  // ostream is undefined behavior.  Depending on the compiler, you
3217  // may get "0", "(nil)", "(null)", or an access violation.  To
3218  // ensure consistent result across compilers, we always treat NULL
3219  // as "(null)".
3220  template <typename T>
3221  inline Message& operator <<(T* const& pointer) {  // NOLINT
3222    if (pointer == NULL) {
3223      *ss_ << "(null)";
3224    } else {
3225      *ss_ << pointer;
3226    }
3227    return *this;
3228  }
3229#endif  // GTEST_OS_SYMBIAN
3230
3231  // Since the basic IO manipulators are overloaded for both narrow
3232  // and wide streams, we have to provide this specialized definition
3233  // of operator <<, even though its body is the same as the
3234  // templatized version above.  Without this definition, streaming
3235  // endl or other basic IO manipulators to Message will confuse the
3236  // compiler.
3237  Message& operator <<(BasicNarrowIoManip val) {
3238    *ss_ << val;
3239    return *this;
3240  }
3241
3242  // Instead of 1/0, we want to see true/false for bool values.
3243  Message& operator <<(bool b) {
3244    return *this << (b ? "true" : "false");
3245  }
3246
3247  // These two overloads allow streaming a wide C string to a Message
3248  // using the UTF-8 encoding.
3249  Message& operator <<(const wchar_t* wide_c_str);
3250  Message& operator <<(wchar_t* wide_c_str);
3251
3252#if GTEST_HAS_STD_WSTRING
3253  // Converts the given wide string to a narrow string using the UTF-8
3254  // encoding, and streams the result to this Message object.
3255  Message& operator <<(const ::std::wstring& wstr);
3256#endif  // GTEST_HAS_STD_WSTRING
3257
3258#if GTEST_HAS_GLOBAL_WSTRING
3259  // Converts the given wide string to a narrow string using the UTF-8
3260  // encoding, and streams the result to this Message object.
3261  Message& operator <<(const ::wstring& wstr);
3262#endif  // GTEST_HAS_GLOBAL_WSTRING
3263
3264  // Gets the text streamed to this object so far as an std::string.
3265  // Each '\0' character in the buffer is replaced with "\\0".
3266  //
3267  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
3268  std::string GetString() const;
3269
3270 private:
3271
3272#if GTEST_OS_SYMBIAN
3273  // These are needed as the Nokia Symbian Compiler cannot decide between
3274  // const T& and const T* in a function template. The Nokia compiler _can_
3275  // decide between class template specializations for T and T*, so a
3276  // tr1::type_traits-like is_pointer works, and we can overload on that.
3277  template <typename T>
3278  inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
3279    if (pointer == NULL) {
3280      *ss_ << "(null)";
3281    } else {
3282      *ss_ << pointer;
3283    }
3284  }
3285  template <typename T>
3286  inline void StreamHelper(internal::false_type /*is_pointer*/,
3287                           const T& value) {
3288    // See the comments in Message& operator <<(const T&) above for why
3289    // we need this using statement.
3290    using ::operator <<;
3291    *ss_ << value;
3292  }
3293#endif  // GTEST_OS_SYMBIAN
3294
3295  // We'll hold the text streamed to this object here.
3296  const internal::scoped_ptr< ::std::stringstream> ss_;
3297
3298  // We declare (but don't implement) this to prevent the compiler
3299  // from implementing the assignment operator.
3300  void operator=(const Message&);
3301};
3302
3303// Streams a Message to an ostream.
3304inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
3305  return os << sb.GetString();
3306}
3307
3308namespace internal {
3309
3310// Converts a streamable value to an std::string.  A NULL pointer is
3311// converted to "(null)".  When the input value is a ::string,
3312// ::std::string, ::wstring, or ::std::wstring object, each NUL
3313// character in it is replaced with "\\0".
3314template <typename T>
3315std::string StreamableToString(const T& streamable) {
3316  return (Message() << streamable).GetString();
3317}
3318
3319}  // namespace internal
3320}  // namespace testing
3321
3322#endif  // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
3323// Copyright 2005, Google Inc.
3324// All rights reserved.
3325//
3326// Redistribution and use in source and binary forms, with or without
3327// modification, are permitted provided that the following conditions are
3328// met:
3329//
3330//     * Redistributions of source code must retain the above copyright
3331// notice, this list of conditions and the following disclaimer.
3332//     * Redistributions in binary form must reproduce the above
3333// copyright notice, this list of conditions and the following disclaimer
3334// in the documentation and/or other materials provided with the
3335// distribution.
3336//     * Neither the name of Google Inc. nor the names of its
3337// contributors may be used to endorse or promote products derived from
3338// this software without specific prior written permission.
3339//
3340// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3341// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3342// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3343// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3344// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3345// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3346// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3347// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3348// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3349// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3350// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3351//
3352// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
3353//
3354// The Google C++ Testing Framework (Google Test)
3355//
3356// This header file declares the String class and functions used internally by
3357// Google Test.  They are subject to change without notice. They should not used
3358// by code external to Google Test.
3359//
3360// This header file is #included by <gtest/internal/gtest-internal.h>.
3361// It should not be #included by other files.
3362
3363#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
3364#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
3365
3366#ifdef __BORLANDC__
3367// string.h is not guaranteed to provide strcpy on C++ Builder.
3368# include <mem.h>
3369#endif
3370
3371#include <string.h>
3372#include <string>
3373
3374
3375namespace testing {
3376namespace internal {
3377
3378// String - an abstract class holding static string utilities.
3379class GTEST_API_ String {
3380 public:
3381  // Static utility methods
3382
3383  // Clones a 0-terminated C string, allocating memory using new.  The
3384  // caller is responsible for deleting the return value using
3385  // delete[].  Returns the cloned string, or NULL if the input is
3386  // NULL.
3387  //
3388  // This is different from strdup() in string.h, which allocates
3389  // memory using malloc().
3390  static const char* CloneCString(const char* c_str);
3391
3392#if GTEST_OS_WINDOWS_MOBILE
3393  // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
3394  // able to pass strings to Win32 APIs on CE we need to convert them
3395  // to 'Unicode', UTF-16.
3396
3397  // Creates a UTF-16 wide string from the given ANSI string, allocating
3398  // memory using new. The caller is responsible for deleting the return
3399  // value using delete[]. Returns the wide string, or NULL if the
3400  // input is NULL.
3401  //
3402  // The wide string is created using the ANSI codepage (CP_ACP) to
3403  // match the behaviour of the ANSI versions of Win32 calls and the
3404  // C runtime.
3405  static LPCWSTR AnsiToUtf16(const char* c_str);
3406
3407  // Creates an ANSI string from the given wide string, allocating
3408  // memory using new. The caller is responsible for deleting the return
3409  // value using delete[]. Returns the ANSI string, or NULL if the
3410  // input is NULL.
3411  //
3412  // The returned string is created using the ANSI codepage (CP_ACP) to
3413  // match the behaviour of the ANSI versions of Win32 calls and the
3414  // C runtime.
3415  static const char* Utf16ToAnsi(LPCWSTR utf16_str);
3416#endif
3417
3418  // Compares two C strings.  Returns true iff they have the same content.
3419  //
3420  // Unlike strcmp(), this function can handle NULL argument(s).  A
3421  // NULL C string is considered different to any non-NULL C string,
3422  // including the empty string.
3423  static bool CStringEquals(const char* lhs, const char* rhs);
3424
3425  // Converts a wide C string to a String using the UTF-8 encoding.
3426  // NULL will be converted to "(null)".  If an error occurred during
3427  // the conversion, "(failed to convert from wide string)" is
3428  // returned.
3429  static std::string ShowWideCString(const wchar_t* wide_c_str);
3430
3431  // Compares two wide C strings.  Returns true iff they have the same
3432  // content.
3433  //
3434  // Unlike wcscmp(), this function can handle NULL argument(s).  A
3435  // NULL C string is considered different to any non-NULL C string,
3436  // including the empty string.
3437  static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs);
3438
3439  // Compares two C strings, ignoring case.  Returns true iff they
3440  // have the same content.
3441  //
3442  // Unlike strcasecmp(), this function can handle NULL argument(s).
3443  // A NULL C string is considered different to any non-NULL C string,
3444  // including the empty string.
3445  static bool CaseInsensitiveCStringEquals(const char* lhs,
3446                                           const char* rhs);
3447
3448  // Compares two wide C strings, ignoring case.  Returns true iff they
3449  // have the same content.
3450  //
3451  // Unlike wcscasecmp(), this function can handle NULL argument(s).
3452  // A NULL C string is considered different to any non-NULL wide C string,
3453  // including the empty string.
3454  // NB: The implementations on different platforms slightly differ.
3455  // On windows, this method uses _wcsicmp which compares according to LC_CTYPE
3456  // environment variable. On GNU platform this method uses wcscasecmp
3457  // which compares according to LC_CTYPE category of the current locale.
3458  // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
3459  // current locale.
3460  static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
3461                                               const wchar_t* rhs);
3462
3463  // Returns true iff the given string ends with the given suffix, ignoring
3464  // case. Any string is considered to end with an empty suffix.
3465  static bool EndsWithCaseInsensitive(
3466      const std::string& str, const std::string& suffix);
3467
3468  // Formats an int value as "%02d".
3469  static std::string FormatIntWidth2(int value);  // "%02d" for width == 2
3470
3471  // Formats an int value as "%X".
3472  static std::string FormatHexInt(int value);
3473
3474  // Formats a byte as "%02X".
3475  static std::string FormatByte(unsigned char value);
3476
3477 private:
3478  String();  // Not meant to be instantiated.
3479};  // class String
3480
3481// Gets the content of the stringstream's buffer as an std::string.  Each '\0'
3482// character in the buffer is replaced with "\\0".
3483GTEST_API_ std::string StringStreamToString(::std::stringstream* stream);
3484
3485}  // namespace internal
3486}  // namespace testing
3487
3488#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
3489// Copyright 2008, Google Inc.
3490// All rights reserved.
3491//
3492// Redistribution and use in source and binary forms, with or without
3493// modification, are permitted provided that the following conditions are
3494// met:
3495//
3496//     * Redistributions of source code must retain the above copyright
3497// notice, this list of conditions and the following disclaimer.
3498//     * Redistributions in binary form must reproduce the above
3499// copyright notice, this list of conditions and the following disclaimer
3500// in the documentation and/or other materials provided with the
3501// distribution.
3502//     * Neither the name of Google Inc. nor the names of its
3503// contributors may be used to endorse or promote products derived from
3504// this software without specific prior written permission.
3505//
3506// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3507// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3508// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3509// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3510// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3511// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3512// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3513// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3514// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3515// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3516// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3517//
3518// Author: keith.ray@gmail.com (Keith Ray)
3519//
3520// Google Test filepath utilities
3521//
3522// This header file declares classes and functions used internally by
3523// Google Test.  They are subject to change without notice.
3524//
3525// This file is #included in <gtest/internal/gtest-internal.h>.
3526// Do not include this header file separately!
3527
3528#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
3529#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
3530
3531
3532namespace testing {
3533namespace internal {
3534
3535// FilePath - a class for file and directory pathname manipulation which
3536// handles platform-specific conventions (like the pathname separator).
3537// Used for helper functions for naming files in a directory for xml output.
3538// Except for Set methods, all methods are const or static, which provides an
3539// "immutable value object" -- useful for peace of mind.
3540// A FilePath with a value ending in a path separator ("like/this/") represents
3541// a directory, otherwise it is assumed to represent a file. In either case,
3542// it may or may not represent an actual file or directory in the file system.
3543// Names are NOT checked for syntax correctness -- no checking for illegal
3544// characters, malformed paths, etc.
3545
3546class GTEST_API_ FilePath {
3547 public:
3548  FilePath() : pathname_("") { }
3549  FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
3550
3551  explicit FilePath(const std::string& pathname) : pathname_(pathname) {
3552    Normalize();
3553  }
3554
3555  FilePath& operator=(const FilePath& rhs) {
3556    Set(rhs);
3557    return *this;
3558  }
3559
3560  void Set(const FilePath& rhs) {
3561    pathname_ = rhs.pathname_;
3562  }
3563
3564  const std::string& string() const { return pathname_; }
3565  const char* c_str() const { return pathname_.c_str(); }
3566
3567  // Returns the current working directory, or "" if unsuccessful.
3568  static FilePath GetCurrentDir();
3569
3570  // Given directory = "dir", base_name = "test", number = 0,
3571  // extension = "xml", returns "dir/test.xml". If number is greater
3572  // than zero (e.g., 12), returns "dir/test_12.xml".
3573  // On Windows platform, uses \ as the separator rather than /.
3574  static FilePath MakeFileName(const FilePath& directory,
3575                               const FilePath& base_name,
3576                               int number,
3577                               const char* extension);
3578
3579  // Given directory = "dir", relative_path = "test.xml",
3580  // returns "dir/test.xml".
3581  // On Windows, uses \ as the separator rather than /.
3582  static FilePath ConcatPaths(const FilePath& directory,
3583                              const FilePath& relative_path);
3584
3585  // Returns a pathname for a file that does not currently exist. The pathname
3586  // will be directory/base_name.extension or
3587  // directory/base_name_<number>.extension if directory/base_name.extension
3588  // already exists. The number will be incremented until a pathname is found
3589  // that does not already exist.
3590  // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
3591  // There could be a race condition if two or more processes are calling this
3592  // function at the same time -- they could both pick the same filename.
3593  static FilePath GenerateUniqueFileName(const FilePath& directory,
3594                                         const FilePath& base_name,
3595                                         const char* extension);
3596
3597  // Returns true iff the path is "".
3598  bool IsEmpty() const { return pathname_.empty(); }
3599
3600  // If input name has a trailing separator character, removes it and returns
3601  // the name, otherwise return the name string unmodified.
3602  // On Windows platform, uses \ as the separator, other platforms use /.
3603  FilePath RemoveTrailingPathSeparator() const;
3604
3605  // Returns a copy of the FilePath with the directory part removed.
3606  // Example: FilePath("path/to/file").RemoveDirectoryName() returns
3607  // FilePath("file"). If there is no directory part ("just_a_file"), it returns
3608  // the FilePath unmodified. If there is no file part ("just_a_dir/") it
3609  // returns an empty FilePath ("").
3610  // On Windows platform, '\' is the path separator, otherwise it is '/'.
3611  FilePath RemoveDirectoryName() const;
3612
3613  // RemoveFileName returns the directory path with the filename removed.
3614  // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
3615  // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
3616  // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
3617  // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
3618  // On Windows platform, '\' is the path separator, otherwise it is '/'.
3619  FilePath RemoveFileName() const;
3620
3621  // Returns a copy of the FilePath with the case-insensitive extension removed.
3622  // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
3623  // FilePath("dir/file"). If a case-insensitive extension is not
3624  // found, returns a copy of the original FilePath.
3625  FilePath RemoveExtension(const char* extension) const;
3626
3627  // Creates directories so that path exists. Returns true if successful or if
3628  // the directories already exist; returns false if unable to create
3629  // directories for any reason. Will also return false if the FilePath does
3630  // not represent a directory (that is, it doesn't end with a path separator).
3631  bool CreateDirectoriesRecursively() const;
3632
3633  // Create the directory so that path exists. Returns true if successful or
3634  // if the directory already exists; returns false if unable to create the
3635  // directory for any reason, including if the parent directory does not
3636  // exist. Not named "CreateDirectory" because that's a macro on Windows.
3637  bool CreateFolder() const;
3638
3639  // Returns true if FilePath describes something in the file-system,
3640  // either a file, directory, or whatever, and that something exists.
3641  bool FileOrDirectoryExists() const;
3642
3643  // Returns true if pathname describes a directory in the file-system
3644  // that exists.
3645  bool DirectoryExists() const;
3646
3647  // Returns true if FilePath ends with a path separator, which indicates that
3648  // it is intended to represent a directory. Returns false otherwise.
3649  // This does NOT check that a directory (or file) actually exists.
3650  bool IsDirectory() const;
3651
3652  // Returns true if pathname describes a root directory. (Windows has one
3653  // root directory per disk drive.)
3654  bool IsRootDirectory() const;
3655
3656  // Returns true if pathname describes an absolute path.
3657  bool IsAbsolutePath() const;
3658
3659 private:
3660  // Replaces multiple consecutive separators with a single separator.
3661  // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
3662  // redundancies that might be in a pathname involving "." or "..".
3663  //
3664  // A pathname with multiple consecutive separators may occur either through
3665  // user error or as a result of some scripts or APIs that generate a pathname
3666  // with a trailing separator. On other platforms the same API or script
3667  // may NOT generate a pathname with a trailing "/". Then elsewhere that
3668  // pathname may have another "/" and pathname components added to it,
3669  // without checking for the separator already being there.
3670  // The script language and operating system may allow paths like "foo//bar"
3671  // but some of the functions in FilePath will not handle that correctly. In
3672  // particular, RemoveTrailingPathSeparator() only removes one separator, and
3673  // it is called in CreateDirectoriesRecursively() assuming that it will change
3674  // a pathname from directory syntax (trailing separator) to filename syntax.
3675  //
3676  // On Windows this method also replaces the alternate path separator '/' with
3677  // the primary path separator '\\', so that for example "bar\\/\\foo" becomes
3678  // "bar\\foo".
3679
3680  void Normalize();
3681
3682  // Returns a pointer to the last occurence of a valid path separator in
3683  // the FilePath. On Windows, for example, both '/' and '\' are valid path
3684  // separators. Returns NULL if no path separator was found.
3685  const char* FindLastPathSeparator() const;
3686
3687  std::string pathname_;
3688};  // class FilePath
3689
3690}  // namespace internal
3691}  // namespace testing
3692
3693#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
3694// This file was GENERATED by command:
3695//     pump.py gtest-type-util.h.pump
3696// DO NOT EDIT BY HAND!!!
3697
3698// Copyright 2008 Google Inc.
3699// All Rights Reserved.
3700//
3701// Redistribution and use in source and binary forms, with or without
3702// modification, are permitted provided that the following conditions are
3703// met:
<