blob: 3143bd67996e96e0172dc341162915ee04b983c5 [file] [log] [blame]
Leon Romanovsky51940842015-11-08 14:39:44 +02001// 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 <vector>
56
57// Copyright 2005, Google Inc.
58// All rights reserved.
59//
60// Redistribution and use in source and binary forms, with or without
61// modification, are permitted provided that the following conditions are
62// met:
63//
64// * Redistributions of source code must retain the above copyright
65// notice, this list of conditions and the following disclaimer.
66// * Redistributions in binary form must reproduce the above
67// copyright notice, this list of conditions and the following disclaimer
68// in the documentation and/or other materials provided with the
69// distribution.
70// * Neither the name of Google Inc. nor the names of its
71// contributors may be used to endorse or promote products derived from
72// this software without specific prior written permission.
73//
74// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
75// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
76// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
77// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
78// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
79// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
80// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
81// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
82// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
83// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
84// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85//
86// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
87//
88// The Google C++ Testing Framework (Google Test)
89//
90// This header file declares functions and macros used internally by
91// Google Test. They are subject to change without notice.
92
93#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
94#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
95
96// Copyright 2005, Google Inc.
97// All rights reserved.
98//
99// Redistribution and use in source and binary forms, with or without
100// modification, are permitted provided that the following conditions are
101// met:
102//
103// * Redistributions of source code must retain the above copyright
104// notice, this list of conditions and the following disclaimer.
105// * Redistributions in binary form must reproduce the above
106// copyright notice, this list of conditions and the following disclaimer
107// in the documentation and/or other materials provided with the
108// distribution.
109// * Neither the name of Google Inc. nor the names of its
110// contributors may be used to endorse or promote products derived from
111// this software without specific prior written permission.
112//
113// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
114// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
115// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
116// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
117// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
118// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
119// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
120// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
121// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
123// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124//
125// Authors: wan@google.com (Zhanyong Wan)
126//
127// Low-level types and utilities for porting Google Test to various
128// platforms. They are subject to change without notice. DO NOT USE
129// THEM IN USER CODE.
130
131#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
132#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
133
134// The user can define the following macros in the build script to
135// control Google Test's behavior. If the user doesn't define a macro
136// in this list, Google Test will define it.
137//
138// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
139// is/isn't available.
140// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions
141// are enabled.
142// GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
143// is/isn't available (some systems define
144// ::string, which is different to std::string).
145// GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
146// is/isn't available (some systems define
147// ::wstring, which is different to std::wstring).
148// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular
149// expressions are/aren't available.
150// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
151// is/isn't available.
152// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
153// enabled.
154// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
155// std::wstring does/doesn't work (Google Test can
156// be used where std::wstring is unavailable).
157// GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple
158// is/isn't available.
159// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
160// compiler supports Microsoft's "Structured
161// Exception Handling".
162// GTEST_HAS_STREAM_REDIRECTION
163// - Define it to 1/0 to indicate whether the
164// platform supports I/O stream redirection using
165// dup() and dup2().
166// GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google
167// Test's own tr1 tuple implementation should be
168// used. Unused when the user sets
169// GTEST_HAS_TR1_TUPLE to 0.
170// GTEST_LINKED_AS_SHARED_LIBRARY
171// - Define to 1 when compiling tests that use
172// Google Test as a shared library (known as
173// DLL on Windows).
174// GTEST_CREATE_SHARED_LIBRARY
175// - Define to 1 when compiling Google Test itself
176// as a shared library.
177
178// This header defines the following utilities:
179//
180// Macros indicating the current platform (defined to 1 if compiled on
181// the given platform; otherwise undefined):
182// GTEST_OS_AIX - IBM AIX
183// GTEST_OS_CYGWIN - Cygwin
184// GTEST_OS_HPUX - HP-UX
185// GTEST_OS_LINUX - Linux
186// GTEST_OS_LINUX_ANDROID - Google Android
187// GTEST_OS_MAC - Mac OS X
188// GTEST_OS_NACL - Google Native Client (NaCl)
189// GTEST_OS_SOLARIS - Sun Solaris
190// GTEST_OS_SYMBIAN - Symbian
191// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
192// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
193// GTEST_OS_WINDOWS_MINGW - MinGW
194// GTEST_OS_WINDOWS_MOBILE - Windows Mobile
195// GTEST_OS_ZOS - z/OS
196//
197// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
198// most stable support. Since core members of the Google Test project
199// don't have access to other platforms, support for them may be less
200// stable. If you notice any problems on your platform, please notify
201// googletestframework@googlegroups.com (patches for fixing them are
202// even more welcome!).
203//
204// Note that it is possible that none of the GTEST_OS_* macros are defined.
205//
206// Macros indicating available Google Test features (defined to 1 if
207// the corresponding feature is supported; otherwise undefined):
208// GTEST_HAS_COMBINE - the Combine() function (for value-parameterized
209// tests)
210// GTEST_HAS_DEATH_TEST - death tests
211// GTEST_HAS_PARAM_TEST - value-parameterized tests
212// GTEST_HAS_TYPED_TEST - typed tests
213// GTEST_HAS_TYPED_TEST_P - type-parameterized tests
214// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with
215// GTEST_HAS_POSIX_RE (see above) which users can
216// define themselves.
217// GTEST_USES_SIMPLE_RE - our own simple regex is used;
218// the above two are mutually exclusive.
219// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
220//
221// Macros for basic C++ coding:
222// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
223// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a
224// variable don't have to be used.
225// GTEST_DISALLOW_ASSIGN_ - disables operator=.
226// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
227// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
228//
229// Synchronization:
230// Mutex, MutexLock, ThreadLocal, GetThreadCount()
231// - synchronization primitives.
232// GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
233// synchronization primitives have real implementations
234// and Google Test is thread-safe; or 0 otherwise.
235//
236// Template meta programming:
237// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
238// IteratorTraits - partial implementation of std::iterator_traits, which
239// is not available in libCstd when compiled with Sun C++.
240//
241// Smart pointers:
242// scoped_ptr - as in TR2.
243//
244// Regular expressions:
245// RE - a simple regular expression class using the POSIX
246// Extended Regular Expression syntax on UNIX-like
247// platforms, or a reduced regular exception syntax on
248// other platforms, including Windows.
249//
250// Logging:
251// GTEST_LOG_() - logs messages at the specified severity level.
252// LogToStderr() - directs all log messages to stderr.
253// FlushInfoLog() - flushes informational log messages.
254//
255// Stdout and stderr capturing:
256// CaptureStdout() - starts capturing stdout.
257// GetCapturedStdout() - stops capturing stdout and returns the captured
258// string.
259// CaptureStderr() - starts capturing stderr.
260// GetCapturedStderr() - stops capturing stderr and returns the captured
261// string.
262//
263// Integer types:
264// TypeWithSize - maps an integer to a int type.
265// Int32, UInt32, Int64, UInt64, TimeInMillis
266// - integers of known sizes.
267// BiggestInt - the biggest signed integer type.
268//
269// Command-line utilities:
270// GTEST_FLAG() - references a flag.
271// GTEST_DECLARE_*() - declares a flag.
272// GTEST_DEFINE_*() - defines a flag.
273// GetArgvs() - returns the command line as a vector of strings.
274//
275// Environment variable utilities:
276// GetEnv() - gets the value of an environment variable.
277// BoolFromGTestEnv() - parses a bool environment variable.
278// Int32FromGTestEnv() - parses an Int32 environment variable.
279// StringFromGTestEnv() - parses a string environment variable.
280
281#include <ctype.h> // for isspace, etc
282#include <stddef.h> // for ptrdiff_t
283#include <stdlib.h>
284#include <stdio.h>
285#include <string.h>
286#ifndef _WIN32_WCE
287# include <sys/types.h>
288# include <sys/stat.h>
289#endif // !_WIN32_WCE
290
291#include <iostream> // NOLINT
292#include <sstream> // NOLINT
293#include <string> // NOLINT
294
295#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
296#define GTEST_FLAG_PREFIX_ "gtest_"
297#define GTEST_FLAG_PREFIX_DASH_ "gtest-"
298#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
299#define GTEST_NAME_ "Google Test"
300#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
301
302// Determines the version of gcc that is used to compile this.
303#ifdef __GNUC__
304// 40302 means version 4.3.2.
305# define GTEST_GCC_VER_ \
306 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
307#endif // __GNUC__
308
309// Determines the platform on which Google Test is compiled.
310#ifdef __CYGWIN__
311# define GTEST_OS_CYGWIN 1
312#elif defined __SYMBIAN32__
313# define GTEST_OS_SYMBIAN 1
314#elif defined _WIN32
315# define GTEST_OS_WINDOWS 1
316# ifdef _WIN32_WCE
317# define GTEST_OS_WINDOWS_MOBILE 1
318# elif defined(__MINGW__) || defined(__MINGW32__)
319# define GTEST_OS_WINDOWS_MINGW 1
320# else
321# define GTEST_OS_WINDOWS_DESKTOP 1
322# endif // _WIN32_WCE
323#elif defined __APPLE__
324# define GTEST_OS_MAC 1
325#elif defined __linux__
326# define GTEST_OS_LINUX 1
327# ifdef ANDROID
328# define GTEST_OS_LINUX_ANDROID 1
329# endif // ANDROID
330#elif defined __MVS__
331# define GTEST_OS_ZOS 1
332#elif defined(__sun) && defined(__SVR4)
333# define GTEST_OS_SOLARIS 1
334#elif defined(_AIX)
335# define GTEST_OS_AIX 1
336#elif defined(__hpux)
337# define GTEST_OS_HPUX 1
338#elif defined __native_client__
339# define GTEST_OS_NACL 1
340#endif // __CYGWIN__
341
342// Brings in definitions for functions used in the testing::internal::posix
343// namespace (read, write, close, chdir, isatty, stat). We do not currently
344// use them on Windows Mobile.
345#if !GTEST_OS_WINDOWS
346// This assumes that non-Windows OSes provide unistd.h. For OSes where this
347// is not the case, we need to include headers that provide the functions
348// mentioned above.
349# include <unistd.h>
350# if !GTEST_OS_NACL
351// TODO(vladl@google.com): Remove this condition when Native Client SDK adds
352// strings.h (tracked in
353// http://code.google.com/p/nativeclient/issues/detail?id=1175).
354# include <strings.h> // Native Client doesn't provide strings.h.
355# endif
356#elif !GTEST_OS_WINDOWS_MOBILE
357# include <direct.h>
358# include <io.h>
359#endif
360
361// Defines this to true iff Google Test can use POSIX regular expressions.
362#ifndef GTEST_HAS_POSIX_RE
363# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
364#endif
365
366#if GTEST_HAS_POSIX_RE
367
368// On some platforms, <regex.h> needs someone to define size_t, and
369// won't compile otherwise. We can #include it here as we already
370// included <stdlib.h>, which is guaranteed to define size_t through
371// <stddef.h>.
372# include <regex.h> // NOLINT
373
374# define GTEST_USES_POSIX_RE 1
375
376#elif GTEST_OS_WINDOWS
377
378// <regex.h> is not available on Windows. Use our own simple regex
379// implementation instead.
380# define GTEST_USES_SIMPLE_RE 1
381
382#else
383
384// <regex.h> may not be available on this platform. Use our own
385// simple regex implementation instead.
386# define GTEST_USES_SIMPLE_RE 1
387
388#endif // GTEST_HAS_POSIX_RE
389
390#ifndef GTEST_HAS_EXCEPTIONS
391// The user didn't tell us whether exceptions are enabled, so we need
392// to figure it out.
393# if defined(_MSC_VER) || defined(__BORLANDC__)
394// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
395// macro to enable exceptions, so we'll do the same.
396// Assumes that exceptions are enabled by default.
397# ifndef _HAS_EXCEPTIONS
398# define _HAS_EXCEPTIONS 1
399# endif // _HAS_EXCEPTIONS
400# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
401# elif defined(__GNUC__) && __EXCEPTIONS
402// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
403# define GTEST_HAS_EXCEPTIONS 1
404# elif defined(__SUNPRO_CC)
405// Sun Pro CC supports exceptions. However, there is no compile-time way of
406// detecting whether they are enabled or not. Therefore, we assume that
407// they are enabled unless the user tells us otherwise.
408# define GTEST_HAS_EXCEPTIONS 1
409# elif defined(__IBMCPP__) && __EXCEPTIONS
410// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
411# define GTEST_HAS_EXCEPTIONS 1
412# elif defined(__HP_aCC)
413// Exception handling is in effect by default in HP aCC compiler. It has to
414// be turned of by +noeh compiler option if desired.
415# define GTEST_HAS_EXCEPTIONS 1
416# else
417// For other compilers, we assume exceptions are disabled to be
418// conservative.
419# define GTEST_HAS_EXCEPTIONS 0
420# endif // defined(_MSC_VER) || defined(__BORLANDC__)
421#endif // GTEST_HAS_EXCEPTIONS
422
423#if !defined(GTEST_HAS_STD_STRING)
424// Even though we don't use this macro any longer, we keep it in case
425// some clients still depend on it.
426# define GTEST_HAS_STD_STRING 1
427#elif !GTEST_HAS_STD_STRING
428// The user told us that ::std::string isn't available.
429# error "Google Test cannot be used where ::std::string isn't available."
430#endif // !defined(GTEST_HAS_STD_STRING)
431
432#ifndef GTEST_HAS_GLOBAL_STRING
433// The user didn't tell us whether ::string is available, so we need
434// to figure it out.
435
436# define GTEST_HAS_GLOBAL_STRING 0
437
438#endif // GTEST_HAS_GLOBAL_STRING
439
440#ifndef GTEST_HAS_STD_WSTRING
441// The user didn't tell us whether ::std::wstring is available, so we need
442// to figure it out.
443// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
444// is available.
445
446// Cygwin 1.7 and below doesn't support ::std::wstring.
447// Solaris' libc++ doesn't support it either. Android has
448// no support for it at least as recent as Froyo (2.2).
449# define GTEST_HAS_STD_WSTRING \
450 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
451
452#endif // GTEST_HAS_STD_WSTRING
453
454#ifndef GTEST_HAS_GLOBAL_WSTRING
455// The user didn't tell us whether ::wstring is available, so we need
456// to figure it out.
457# define GTEST_HAS_GLOBAL_WSTRING \
458 (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
459#endif // GTEST_HAS_GLOBAL_WSTRING
460
461// Determines whether RTTI is available.
462#ifndef GTEST_HAS_RTTI
463// The user didn't tell us whether RTTI is enabled, so we need to
464// figure it out.
465
466# ifdef _MSC_VER
467
468# ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
469# define GTEST_HAS_RTTI 1
470# else
471# define GTEST_HAS_RTTI 0
472# endif
473
474// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
475# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
476
477# ifdef __GXX_RTTI
478# define GTEST_HAS_RTTI 1
479# else
480# define GTEST_HAS_RTTI 0
481# endif // __GXX_RTTI
482
483// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
484// both the typeid and dynamic_cast features are present.
485# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
486
487# ifdef __RTTI_ALL__
488# define GTEST_HAS_RTTI 1
489# else
490# define GTEST_HAS_RTTI 0
491# endif
492
493# else
494
495// For all other compilers, we assume RTTI is enabled.
496# define GTEST_HAS_RTTI 1
497
498# endif // _MSC_VER
499
500#endif // GTEST_HAS_RTTI
501
502// It's this header's responsibility to #include <typeinfo> when RTTI
503// is enabled.
504#if GTEST_HAS_RTTI
505# include <typeinfo>
506#endif
507
508// Determines whether Google Test can use the pthreads library.
509#ifndef GTEST_HAS_PTHREAD
510// The user didn't tell us explicitly, so we assume pthreads support is
511// available on Linux and Mac.
512//
513// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
514// to your compiler flags.
515# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX)
516#endif // GTEST_HAS_PTHREAD
517
518#if GTEST_HAS_PTHREAD
519// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
520// true.
521# include <pthread.h> // NOLINT
522
523// For timespec and nanosleep, used below.
524# include <time.h> // NOLINT
525#endif
526
527// Determines whether Google Test can use tr1/tuple. You can define
528// this macro to 0 to prevent Google Test from using tuple (any
529// feature depending on tuple with be disabled in this mode).
530#ifndef GTEST_HAS_TR1_TUPLE
531// The user didn't tell us not to do it, so we assume it's OK.
532# define GTEST_HAS_TR1_TUPLE 1
533#endif // GTEST_HAS_TR1_TUPLE
534
535// Determines whether Google Test's own tr1 tuple implementation
536// should be used.
537#ifndef GTEST_USE_OWN_TR1_TUPLE
538// The user didn't tell us, so we need to figure it out.
539
540// We use our own TR1 tuple if we aren't sure the user has an
541// implementation of it already. At this time, GCC 4.0.0+ and MSVC
542// 2010 are the only mainstream compilers that come with a TR1 tuple
543// implementation. NVIDIA's CUDA NVCC compiler pretends to be GCC by
544// defining __GNUC__ and friends, but cannot compile GCC's tuple
545// implementation. MSVC 2008 (9.0) provides TR1 tuple in a 323 MB
546// Feature Pack download, which we cannot assume the user has.
547# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \
548 || _MSC_VER >= 1600
549# define GTEST_USE_OWN_TR1_TUPLE 0
550# else
551# define GTEST_USE_OWN_TR1_TUPLE 1
552# endif
553
554#endif // GTEST_USE_OWN_TR1_TUPLE
555
556// To avoid conditional compilation everywhere, we make it
557// gtest-port.h's responsibility to #include the header implementing
558// tr1/tuple.
559#if GTEST_HAS_TR1_TUPLE
560
561# if GTEST_USE_OWN_TR1_TUPLE
562// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
563
564// Copyright 2009 Google Inc.
565// All Rights Reserved.
566//
567// Redistribution and use in source and binary forms, with or without
568// modification, are permitted provided that the following conditions are
569// met:
570//
571// * Redistributions of source code must retain the above copyright
572// notice, this list of conditions and the following disclaimer.
573// * Redistributions in binary form must reproduce the above
574// copyright notice, this list of conditions and the following disclaimer
575// in the documentation and/or other materials provided with the
576// distribution.
577// * Neither the name of Google Inc. nor the names of its
578// contributors may be used to endorse or promote products derived from
579// this software without specific prior written permission.
580//
581// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
582// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
583// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
584// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
585// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
586// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
587// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
588// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
589// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
590// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
591// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
592//
593// Author: wan@google.com (Zhanyong Wan)
594
595// Implements a subset of TR1 tuple needed by Google Test and Google Mock.
596
597#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
598#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
599
600#include <utility> // For ::std::pair.
601
602// The compiler used in Symbian has a bug that prevents us from declaring the
603// tuple template as a friend (it complains that tuple is redefined). This
604// hack bypasses the bug by declaring the members that should otherwise be
605// private as public.
606// Sun Studio versions < 12 also have the above bug.
607#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
608# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
609#else
610# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
611 template <GTEST_10_TYPENAMES_(U)> friend class tuple; \
612 private:
613#endif
614
615// GTEST_n_TUPLE_(T) is the type of an n-tuple.
616#define GTEST_0_TUPLE_(T) tuple<>
617#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
618 void, void, void>
619#define GTEST_2_TUPLE_(T) tuple<T##0, T##1, void, void, void, void, void, \
620 void, void, void>
621#define GTEST_3_TUPLE_(T) tuple<T##0, T##1, T##2, void, void, void, void, \
622 void, void, void>
623#define GTEST_4_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, void, void, void, \
624 void, void, void>
625#define GTEST_5_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, void, void, \
626 void, void, void>
627#define GTEST_6_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, void, \
628 void, void, void>
629#define GTEST_7_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
630 void, void, void>
631#define GTEST_8_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
632 T##7, void, void>
633#define GTEST_9_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
634 T##7, T##8, void>
635#define GTEST_10_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
636 T##7, T##8, T##9>
637
638// GTEST_n_TYPENAMES_(T) declares a list of n typenames.
639#define GTEST_0_TYPENAMES_(T)
640#define GTEST_1_TYPENAMES_(T) typename T##0
641#define GTEST_2_TYPENAMES_(T) typename T##0, typename T##1
642#define GTEST_3_TYPENAMES_(T) typename T##0, typename T##1, typename T##2
643#define GTEST_4_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
644 typename T##3
645#define GTEST_5_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
646 typename T##3, typename T##4
647#define GTEST_6_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
648 typename T##3, typename T##4, typename T##5
649#define GTEST_7_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
650 typename T##3, typename T##4, typename T##5, typename T##6
651#define GTEST_8_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
652 typename T##3, typename T##4, typename T##5, typename T##6, typename T##7
653#define GTEST_9_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
654 typename T##3, typename T##4, typename T##5, typename T##6, \
655 typename T##7, typename T##8
656#define GTEST_10_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
657 typename T##3, typename T##4, typename T##5, typename T##6, \
658 typename T##7, typename T##8, typename T##9
659
660// In theory, defining stuff in the ::std namespace is undefined
661// behavior. We can do this as we are playing the role of a standard
662// library vendor.
663namespace std {
664namespace tr1 {
665
666template <typename T0 = void, typename T1 = void, typename T2 = void,
667 typename T3 = void, typename T4 = void, typename T5 = void,
668 typename T6 = void, typename T7 = void, typename T8 = void,
669 typename T9 = void>
670class tuple;
671
672// Anything in namespace gtest_internal is Google Test's INTERNAL
673// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
674namespace gtest_internal {
675
676// ByRef<T>::type is T if T is a reference; otherwise it's const T&.
677template <typename T>
678struct ByRef { typedef const T& type; }; // NOLINT
679template <typename T>
680struct ByRef<T&> { typedef T& type; }; // NOLINT
681
682// A handy wrapper for ByRef.
683#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type
684
685// AddRef<T>::type is T if T is a reference; otherwise it's T&. This
686// is the same as tr1::add_reference<T>::type.
687template <typename T>
688struct AddRef { typedef T& type; }; // NOLINT
689template <typename T>
690struct AddRef<T&> { typedef T& type; }; // NOLINT
691
692// A handy wrapper for AddRef.
693#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type
694
695// A helper for implementing get<k>().
696template <int k> class Get;
697
698// A helper for implementing tuple_element<k, T>. kIndexValid is true
699// iff k < the number of fields in tuple type T.
700template <bool kIndexValid, int kIndex, class Tuple>
701struct TupleElement;
702
703template <GTEST_10_TYPENAMES_(T)>
704struct TupleElement<true, 0, GTEST_10_TUPLE_(T)> { typedef T0 type; };
705
706template <GTEST_10_TYPENAMES_(T)>
707struct TupleElement<true, 1, GTEST_10_TUPLE_(T)> { typedef T1 type; };
708
709template <GTEST_10_TYPENAMES_(T)>
710struct TupleElement<true, 2, GTEST_10_TUPLE_(T)> { typedef T2 type; };
711
712template <GTEST_10_TYPENAMES_(T)>
713struct TupleElement<true, 3, GTEST_10_TUPLE_(T)> { typedef T3 type; };
714
715template <GTEST_10_TYPENAMES_(T)>
716struct TupleElement<true, 4, GTEST_10_TUPLE_(T)> { typedef T4 type; };
717
718template <GTEST_10_TYPENAMES_(T)>
719struct TupleElement<true, 5, GTEST_10_TUPLE_(T)> { typedef T5 type; };
720
721template <GTEST_10_TYPENAMES_(T)>
722struct TupleElement<true, 6, GTEST_10_TUPLE_(T)> { typedef T6 type; };
723
724template <GTEST_10_TYPENAMES_(T)>
725struct TupleElement<true, 7, GTEST_10_TUPLE_(T)> { typedef T7 type; };
726
727template <GTEST_10_TYPENAMES_(T)>
728struct TupleElement<true, 8, GTEST_10_TUPLE_(T)> { typedef T8 type; };
729
730template <GTEST_10_TYPENAMES_(T)>
731struct TupleElement<true, 9, GTEST_10_TUPLE_(T)> { typedef T9 type; };
732
733} // namespace gtest_internal
734
735template <>
736class tuple<> {
737 public:
738 tuple() {}
739 tuple(const tuple& /* t */) {}
740 tuple& operator=(const tuple& /* t */) { return *this; }
741};
742
743template <GTEST_1_TYPENAMES_(T)>
744class GTEST_1_TUPLE_(T) {
745 public:
746 template <int k> friend class gtest_internal::Get;
747
748 tuple() : f0_() {}
749
750 explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {}
751
752 tuple(const tuple& t) : f0_(t.f0_) {}
753
754 template <GTEST_1_TYPENAMES_(U)>
755 tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {}
756
757 tuple& operator=(const tuple& t) { return CopyFrom(t); }
758
759 template <GTEST_1_TYPENAMES_(U)>
760 tuple& operator=(const GTEST_1_TUPLE_(U)& t) {
761 return CopyFrom(t);
762 }
763
764 GTEST_DECLARE_TUPLE_AS_FRIEND_
765
766 template <GTEST_1_TYPENAMES_(U)>
767 tuple& CopyFrom(const GTEST_1_TUPLE_(U)& t) {
768 f0_ = t.f0_;
769 return *this;
770 }
771
772 T0 f0_;
773};
774
775template <GTEST_2_TYPENAMES_(T)>
776class GTEST_2_TUPLE_(T) {
777 public:
778 template <int k> friend class gtest_internal::Get;
779
780 tuple() : f0_(), f1_() {}
781
782 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0),
783 f1_(f1) {}
784
785 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {}
786
787 template <GTEST_2_TYPENAMES_(U)>
788 tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {}
789 template <typename U0, typename U1>
790 tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
791
792 tuple& operator=(const tuple& t) { return CopyFrom(t); }
793
794 template <GTEST_2_TYPENAMES_(U)>
795 tuple& operator=(const GTEST_2_TUPLE_(U)& t) {
796 return CopyFrom(t);
797 }
798 template <typename U0, typename U1>
799 tuple& operator=(const ::std::pair<U0, U1>& p) {
800 f0_ = p.first;
801 f1_ = p.second;
802 return *this;
803 }
804
805 GTEST_DECLARE_TUPLE_AS_FRIEND_
806
807 template <GTEST_2_TYPENAMES_(U)>
808 tuple& CopyFrom(const GTEST_2_TUPLE_(U)& t) {
809 f0_ = t.f0_;
810 f1_ = t.f1_;
811 return *this;
812 }
813
814 T0 f0_;
815 T1 f1_;
816};
817
818template <GTEST_3_TYPENAMES_(T)>
819class GTEST_3_TUPLE_(T) {
820 public:
821 template <int k> friend class gtest_internal::Get;
822
823 tuple() : f0_(), f1_(), f2_() {}
824
825 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
826 GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {}
827
828 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
829
830 template <GTEST_3_TYPENAMES_(U)>
831 tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
832
833 tuple& operator=(const tuple& t) { return CopyFrom(t); }
834
835 template <GTEST_3_TYPENAMES_(U)>
836 tuple& operator=(const GTEST_3_TUPLE_(U)& t) {
837 return CopyFrom(t);
838 }
839
840 GTEST_DECLARE_TUPLE_AS_FRIEND_
841
842 template <GTEST_3_TYPENAMES_(U)>
843 tuple& CopyFrom(const GTEST_3_TUPLE_(U)& t) {
844 f0_ = t.f0_;
845 f1_ = t.f1_;
846 f2_ = t.f2_;
847 return *this;
848 }
849
850 T0 f0_;
851 T1 f1_;
852 T2 f2_;
853};
854
855template <GTEST_4_TYPENAMES_(T)>
856class GTEST_4_TUPLE_(T) {
857 public:
858 template <int k> friend class gtest_internal::Get;
859
860 tuple() : f0_(), f1_(), f2_(), f3_() {}
861
862 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
863 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f2),
864 f3_(f3) {}
865
866 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {}
867
868 template <GTEST_4_TYPENAMES_(U)>
869 tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
870 f3_(t.f3_) {}
871
872 tuple& operator=(const tuple& t) { return CopyFrom(t); }
873
874 template <GTEST_4_TYPENAMES_(U)>
875 tuple& operator=(const GTEST_4_TUPLE_(U)& t) {
876 return CopyFrom(t);
877 }
878
879 GTEST_DECLARE_TUPLE_AS_FRIEND_
880
881 template <GTEST_4_TYPENAMES_(U)>
882 tuple& CopyFrom(const GTEST_4_TUPLE_(U)& t) {
883 f0_ = t.f0_;
884 f1_ = t.f1_;
885 f2_ = t.f2_;
886 f3_ = t.f3_;
887 return *this;
888 }
889
890 T0 f0_;
891 T1 f1_;
892 T2 f2_;
893 T3 f3_;
894};
895
896template <GTEST_5_TYPENAMES_(T)>
897class GTEST_5_TUPLE_(T) {
898 public:
899 template <int k> friend class gtest_internal::Get;
900
901 tuple() : f0_(), f1_(), f2_(), f3_(), f4_() {}
902
903 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
904 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3,
905 GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) {}
906
907 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
908 f4_(t.f4_) {}
909
910 template <GTEST_5_TYPENAMES_(U)>
911 tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
912 f3_(t.f3_), f4_(t.f4_) {}
913
914 tuple& operator=(const tuple& t) { return CopyFrom(t); }
915
916 template <GTEST_5_TYPENAMES_(U)>
917 tuple& operator=(const GTEST_5_TUPLE_(U)& t) {
918 return CopyFrom(t);
919 }
920
921 GTEST_DECLARE_TUPLE_AS_FRIEND_
922
923 template <GTEST_5_TYPENAMES_(U)>
924 tuple& CopyFrom(const GTEST_5_TUPLE_(U)& t) {
925 f0_ = t.f0_;
926 f1_ = t.f1_;
927 f2_ = t.f2_;
928 f3_ = t.f3_;
929 f4_ = t.f4_;
930 return *this;
931 }
932
933 T0 f0_;
934 T1 f1_;
935 T2 f2_;
936 T3 f3_;
937 T4 f4_;
938};
939
940template <GTEST_6_TYPENAMES_(T)>
941class GTEST_6_TUPLE_(T) {
942 public:
943 template <int k> friend class gtest_internal::Get;
944
945 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_() {}
946
947 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
948 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
949 GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
950 f5_(f5) {}
951
952 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
953 f4_(t.f4_), f5_(t.f5_) {}
954
955 template <GTEST_6_TYPENAMES_(U)>
956 tuple(const GTEST_6_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
957 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_) {}
958
959 tuple& operator=(const tuple& t) { return CopyFrom(t); }
960
961 template <GTEST_6_TYPENAMES_(U)>
962 tuple& operator=(const GTEST_6_TUPLE_(U)& t) {
963 return CopyFrom(t);
964 }
965
966 GTEST_DECLARE_TUPLE_AS_FRIEND_
967
968 template <GTEST_6_TYPENAMES_(U)>
969 tuple& CopyFrom(const GTEST_6_TUPLE_(U)& t) {
970 f0_ = t.f0_;
971 f1_ = t.f1_;
972 f2_ = t.f2_;
973 f3_ = t.f3_;
974 f4_ = t.f4_;
975 f5_ = t.f5_;
976 return *this;
977 }
978
979 T0 f0_;
980 T1 f1_;
981 T2 f2_;
982 T3 f3_;
983 T4 f4_;
984 T5 f5_;
985};
986
987template <GTEST_7_TYPENAMES_(T)>
988class GTEST_7_TUPLE_(T) {
989 public:
990 template <int k> friend class gtest_internal::Get;
991
992 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_() {}
993
994 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
995 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
996 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f2),
997 f3_(f3), f4_(f4), f5_(f5), f6_(f6) {}
998
999 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1000 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
1001
1002 template <GTEST_7_TYPENAMES_(U)>
1003 tuple(const GTEST_7_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1004 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
1005
1006 tuple& operator=(const tuple& t) { return CopyFrom(t); }
1007
1008 template <GTEST_7_TYPENAMES_(U)>
1009 tuple& operator=(const GTEST_7_TUPLE_(U)& t) {
1010 return CopyFrom(t);
1011 }
1012
1013 GTEST_DECLARE_TUPLE_AS_FRIEND_
1014
1015 template <GTEST_7_TYPENAMES_(U)>
1016 tuple& CopyFrom(const GTEST_7_TUPLE_(U)& t) {
1017 f0_ = t.f0_;
1018 f1_ = t.f1_;
1019 f2_ = t.f2_;
1020 f3_ = t.f3_;
1021 f4_ = t.f4_;
1022 f5_ = t.f5_;
1023 f6_ = t.f6_;
1024 return *this;
1025 }
1026
1027 T0 f0_;
1028 T1 f1_;
1029 T2 f2_;
1030 T3 f3_;
1031 T4 f4_;
1032 T5 f5_;
1033 T6 f6_;
1034};
1035
1036template <GTEST_8_TYPENAMES_(T)>
1037class GTEST_8_TUPLE_(T) {
1038 public:
1039 template <int k> friend class gtest_internal::Get;
1040
1041 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_() {}
1042
1043 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1044 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1045 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6,
1046 GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
1047 f5_(f5), f6_(f6), f7_(f7) {}
1048
1049 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1050 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
1051
1052 template <GTEST_8_TYPENAMES_(U)>
1053 tuple(const GTEST_8_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1054 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
1055
1056 tuple& operator=(const tuple& t) { return CopyFrom(t); }
1057
1058 template <GTEST_8_TYPENAMES_(U)>
1059 tuple& operator=(const GTEST_8_TUPLE_(U)& t) {
1060 return CopyFrom(t);
1061 }
1062
1063 GTEST_DECLARE_TUPLE_AS_FRIEND_
1064
1065 template <GTEST_8_TYPENAMES_(U)>
1066 tuple& CopyFrom(const GTEST_8_TUPLE_(U)& t) {
1067 f0_ = t.f0_;
1068 f1_ = t.f1_;
1069 f2_ = t.f2_;
1070 f3_ = t.f3_;
1071 f4_ = t.f4_;
1072 f5_ = t.f5_;
1073 f6_ = t.f6_;
1074 f7_ = t.f7_;
1075 return *this;
1076 }
1077
1078 T0 f0_;
1079 T1 f1_;
1080 T2 f2_;
1081 T3 f3_;
1082 T4 f4_;
1083 T5 f5_;
1084 T6 f6_;
1085 T7 f7_;
1086};
1087
1088template <GTEST_9_TYPENAMES_(T)>
1089class GTEST_9_TUPLE_(T) {
1090 public:
1091 template <int k> friend class gtest_internal::Get;
1092
1093 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_() {}
1094
1095 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1096 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1097 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
1098 GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
1099 f5_(f5), f6_(f6), f7_(f7), f8_(f8) {}
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_), f7_(t.f7_), f8_(t.f8_) {}
1103
1104 template <GTEST_9_TYPENAMES_(U)>
1105 tuple(const GTEST_9_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_), f7_(t.f7_), f8_(t.f8_) {}
1107
1108 tuple& operator=(const tuple& t) { return CopyFrom(t); }
1109
1110 template <GTEST_9_TYPENAMES_(U)>
1111 tuple& operator=(const GTEST_9_TUPLE_(U)& t) {
1112 return CopyFrom(t);
1113 }
1114
1115 GTEST_DECLARE_TUPLE_AS_FRIEND_
1116
1117 template <GTEST_9_TYPENAMES_(U)>
1118 tuple& CopyFrom(const GTEST_9_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 f7_ = t.f7_;
1127 f8_ = t.f8_;
1128 return *this;
1129 }
1130
1131 T0 f0_;
1132 T1 f1_;
1133 T2 f2_;
1134 T3 f3_;
1135 T4 f4_;
1136 T5 f5_;
1137 T6 f6_;
1138 T7 f7_;
1139 T8 f8_;
1140};
1141
1142template <GTEST_10_TYPENAMES_(T)>
1143class tuple {
1144 public:
1145 template <int k> friend class gtest_internal::Get;
1146
1147 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_(),
1148 f9_() {}
1149
1150 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
1151 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
1152 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
1153 GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f2),
1154 f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {}
1155
1156 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
1157 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_) {}
1158
1159 template <GTEST_10_TYPENAMES_(U)>
1160 tuple(const GTEST_10_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
1161 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_),
1162 f9_(t.f9_) {}
1163
1164 tuple& operator=(const tuple& t) { return CopyFrom(t); }
1165
1166 template <GTEST_10_TYPENAMES_(U)>
1167 tuple& operator=(const GTEST_10_TUPLE_(U)& t) {
1168 return CopyFrom(t);
1169 }
1170
1171 GTEST_DECLARE_TUPLE_AS_FRIEND_
1172
1173 template <GTEST_10_TYPENAMES_(U)>
1174 tuple& CopyFrom(const GTEST_10_TUPLE_(U)& t) {
1175 f0_ = t.f0_;
1176 f1_ = t.f1_;
1177 f2_ = t.f2_;
1178 f3_ = t.f3_;
1179 f4_ = t.f4_;
1180 f5_ = t.f5_;
1181 f6_ = t.f6_;
1182 f7_ = t.f7_;
1183 f8_ = t.f8_;
1184 f9_ = t.f9_;
1185 return *this;
1186 }
1187
1188 T0 f0_;
1189 T1 f1_;
1190 T2 f2_;
1191 T3 f3_;
1192 T4 f4_;
1193 T5 f5_;
1194 T6 f6_;
1195 T7 f7_;
1196 T8 f8_;
1197 T9 f9_;
1198};
1199
1200// 6.1.3.2 Tuple creation functions.
1201
1202// Known limitations: we don't support passing an
1203// std::tr1::reference_wrapper<T> to make_tuple(). And we don't
1204// implement tie().
1205
1206inline tuple<> make_tuple() { return tuple<>(); }
1207
1208template <GTEST_1_TYPENAMES_(T)>
1209inline GTEST_1_TUPLE_(T) make_tuple(const T0& f0) {
1210 return GTEST_1_TUPLE_(T)(f0);
1211}
1212
1213template <GTEST_2_TYPENAMES_(T)>
1214inline GTEST_2_TUPLE_(T) make_tuple(const T0& f0, const T1& f1) {
1215 return GTEST_2_TUPLE_(T)(f0, f1);
1216}
1217
1218template <GTEST_3_TYPENAMES_(T)>
1219inline GTEST_3_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2) {
1220 return GTEST_3_TUPLE_(T)(f0, f1, f2);
1221}
1222
1223template <GTEST_4_TYPENAMES_(T)>
1224inline GTEST_4_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1225 const T3& f3) {
1226 return GTEST_4_TUPLE_(T)(f0, f1, f2, f3);
1227}
1228
1229template <GTEST_5_TYPENAMES_(T)>
1230inline GTEST_5_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1231 const T3& f3, const T4& f4) {
1232 return GTEST_5_TUPLE_(T)(f0, f1, f2, f3, f4);
1233}
1234
1235template <GTEST_6_TYPENAMES_(T)>
1236inline GTEST_6_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1237 const T3& f3, const T4& f4, const T5& f5) {
1238 return GTEST_6_TUPLE_(T)(f0, f1, f2, f3, f4, f5);
1239}
1240
1241template <GTEST_7_TYPENAMES_(T)>
1242inline GTEST_7_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1243 const T3& f3, const T4& f4, const T5& f5, const T6& f6) {
1244 return GTEST_7_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6);
1245}
1246
1247template <GTEST_8_TYPENAMES_(T)>
1248inline GTEST_8_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1249 const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7) {
1250 return GTEST_8_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7);
1251}
1252
1253template <GTEST_9_TYPENAMES_(T)>
1254inline GTEST_9_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1255 const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,
1256 const T8& f8) {
1257 return GTEST_9_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8);
1258}
1259
1260template <GTEST_10_TYPENAMES_(T)>
1261inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
1262 const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,
1263 const T8& f8, const T9& f9) {
1264 return GTEST_10_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9);
1265}
1266
1267// 6.1.3.3 Tuple helper classes.
1268
1269template <typename Tuple> struct tuple_size;
1270
1271template <GTEST_0_TYPENAMES_(T)>
1272struct tuple_size<GTEST_0_TUPLE_(T)> { static const int value = 0; };
1273
1274template <GTEST_1_TYPENAMES_(T)>
1275struct tuple_size<GTEST_1_TUPLE_(T)> { static const int value = 1; };
1276
1277template <GTEST_2_TYPENAMES_(T)>
1278struct tuple_size<GTEST_2_TUPLE_(T)> { static const int value = 2; };
1279
1280template <GTEST_3_TYPENAMES_(T)>
1281struct tuple_size<GTEST_3_TUPLE_(T)> { static const int value = 3; };
1282
1283template <GTEST_4_TYPENAMES_(T)>
1284struct tuple_size<GTEST_4_TUPLE_(T)> { static const int value = 4; };
1285
1286template <GTEST_5_TYPENAMES_(T)>
1287struct tuple_size<GTEST_5_TUPLE_(T)> { static const int value = 5; };
1288
1289template <GTEST_6_TYPENAMES_(T)>
1290struct tuple_size<GTEST_6_TUPLE_(T)> { static const int value = 6; };
1291
1292template <GTEST_7_TYPENAMES_(T)>
1293struct tuple_size<GTEST_7_TUPLE_(T)> { static const int value = 7; };
1294
1295template <GTEST_8_TYPENAMES_(T)>
1296struct tuple_size<GTEST_8_TUPLE_(T)> { static const int value = 8; };
1297
1298template <GTEST_9_TYPENAMES_(T)>
1299struct tuple_size<GTEST_9_TUPLE_(T)> { static const int value = 9; };
1300
1301template <GTEST_10_TYPENAMES_(T)>
1302struct tuple_size<GTEST_10_TUPLE_(T)> { static const int value = 10; };
1303
1304template <int k, class Tuple>
1305struct tuple_element {
1306 typedef typename gtest_internal::TupleElement<
1307 k < (tuple_size<Tuple>::value), k, Tuple>::type type;
1308};
1309
1310#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type
1311
1312// 6.1.3.4 Element access.
1313
1314namespace gtest_internal {
1315
1316template <>
1317class Get<0> {
1318 public:
1319 template <class Tuple>
1320 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))
1321 Field(Tuple& t) { return t.f0_; } // NOLINT
1322
1323 template <class Tuple>
1324 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))
1325 ConstField(const Tuple& t) { return t.f0_; }
1326};
1327
1328template <>
1329class Get<1> {
1330 public:
1331 template <class Tuple>
1332 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))
1333 Field(Tuple& t) { return t.f1_; } // NOLINT
1334
1335 template <class Tuple>
1336 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))
1337 ConstField(const Tuple& t) { return t.f1_; }
1338};
1339
1340template <>
1341class Get<2> {
1342 public:
1343 template <class Tuple>
1344 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))
1345 Field(Tuple& t) { return t.f2_; } // NOLINT
1346
1347 template <class Tuple>
1348 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))
1349 ConstField(const Tuple& t) { return t.f2_; }
1350};
1351
1352template <>
1353class Get<3> {
1354 public:
1355 template <class Tuple>
1356 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))
1357 Field(Tuple& t) { return t.f3_; } // NOLINT
1358
1359 template <class Tuple>
1360 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))
1361 ConstField(const Tuple& t) { return t.f3_; }
1362};
1363
1364template <>
1365class Get<4> {
1366 public:
1367 template <class Tuple>
1368 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))
1369 Field(Tuple& t) { return t.f4_; } // NOLINT
1370
1371 template <class Tuple>
1372 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))
1373 ConstField(const Tuple& t) { return t.f4_; }
1374};
1375
1376template <>
1377class Get<5> {
1378 public:
1379 template <class Tuple>
1380 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))
1381 Field(Tuple& t) { return t.f5_; } // NOLINT
1382
1383 template <class Tuple>
1384 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))
1385 ConstField(const Tuple& t) { return t.f5_; }
1386};
1387
1388template <>
1389class Get<6> {
1390 public:
1391 template <class Tuple>
1392 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))
1393 Field(Tuple& t) { return t.f6_; } // NOLINT
1394
1395 template <class Tuple>
1396 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))
1397 ConstField(const Tuple& t) { return t.f6_; }
1398};
1399
1400template <>
1401class Get<7> {
1402 public:
1403 template <class Tuple>
1404 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))
1405 Field(Tuple& t) { return t.f7_; } // NOLINT
1406
1407 template <class Tuple>
1408 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))
1409 ConstField(const Tuple& t) { return t.f7_; }
1410};
1411
1412template <>
1413class Get<8> {
1414 public:
1415 template <class Tuple>
1416 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))
1417 Field(Tuple& t) { return t.f8_; } // NOLINT
1418
1419 template <class Tuple>
1420 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))
1421 ConstField(const Tuple& t) { return t.f8_; }
1422};
1423
1424template <>
1425class Get<9> {
1426 public:
1427 template <class Tuple>
1428 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))
1429 Field(Tuple& t) { return t.f9_; } // NOLINT
1430
1431 template <class Tuple>
1432 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))
1433 ConstField(const Tuple& t) { return t.f9_; }
1434};
1435
1436} // namespace gtest_internal
1437
1438template <int k, GTEST_10_TYPENAMES_(T)>
1439GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T)))
1440get(GTEST_10_TUPLE_(T)& t) {
1441 return gtest_internal::Get<k>::Field(t);
1442}
1443
1444template <int k, GTEST_10_TYPENAMES_(T)>
1445GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T)))
1446get(const GTEST_10_TUPLE_(T)& t) {
1447 return gtest_internal::Get<k>::ConstField(t);
1448}
1449
1450// 6.1.3.5 Relational operators
1451
1452// We only implement == and !=, as we don't have a need for the rest yet.
1453
1454namespace gtest_internal {
1455
1456// SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
1457// first k fields of t1 equals the first k fields of t2.
1458// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
1459// k1 != k2.
1460template <int kSize1, int kSize2>
1461struct SameSizeTuplePrefixComparator;
1462
1463template <>
1464struct SameSizeTuplePrefixComparator<0, 0> {
1465 template <class Tuple1, class Tuple2>
1466 static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {
1467 return true;
1468 }
1469};
1470
1471template <int k>
1472struct SameSizeTuplePrefixComparator<k, k> {
1473 template <class Tuple1, class Tuple2>
1474 static bool Eq(const Tuple1& t1, const Tuple2& t2) {
1475 return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&
1476 ::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);
1477 }
1478};
1479
1480} // namespace gtest_internal
1481
1482template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
1483inline bool operator==(const GTEST_10_TUPLE_(T)& t,
1484 const GTEST_10_TUPLE_(U)& u) {
1485 return gtest_internal::SameSizeTuplePrefixComparator<
1486 tuple_size<GTEST_10_TUPLE_(T)>::value,
1487 tuple_size<GTEST_10_TUPLE_(U)>::value>::Eq(t, u);
1488}
1489
1490template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
1491inline bool operator!=(const GTEST_10_TUPLE_(T)& t,
1492 const GTEST_10_TUPLE_(U)& u) { return !(t == u); }
1493
1494// 6.1.4 Pairs.
1495// Unimplemented.
1496
1497} // namespace tr1
1498} // namespace std
1499
1500#undef GTEST_0_TUPLE_
1501#undef GTEST_1_TUPLE_
1502#undef GTEST_2_TUPLE_
1503#undef GTEST_3_TUPLE_
1504#undef GTEST_4_TUPLE_
1505#undef GTEST_5_TUPLE_
1506#undef GTEST_6_TUPLE_
1507#undef GTEST_7_TUPLE_
1508#undef GTEST_8_TUPLE_
1509#undef GTEST_9_TUPLE_
1510#undef GTEST_10_TUPLE_
1511
1512#undef GTEST_0_TYPENAMES_
1513#undef GTEST_1_TYPENAMES_
1514#undef GTEST_2_TYPENAMES_
1515#undef GTEST_3_TYPENAMES_
1516#undef GTEST_4_TYPENAMES_
1517#undef GTEST_5_TYPENAMES_
1518#undef GTEST_6_TYPENAMES_
1519#undef GTEST_7_TYPENAMES_
1520#undef GTEST_8_TYPENAMES_
1521#undef GTEST_9_TYPENAMES_
1522#undef GTEST_10_TYPENAMES_
1523
1524#undef GTEST_DECLARE_TUPLE_AS_FRIEND_
1525#undef GTEST_BY_REF_
1526#undef GTEST_ADD_REF_
1527#undef GTEST_TUPLE_ELEMENT_
1528
1529#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
1530# elif GTEST_OS_SYMBIAN
1531
1532// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
1533// use STLport's tuple implementation, which unfortunately doesn't
1534// work as the copy of STLport distributed with Symbian is incomplete.
1535// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
1536// use its own tuple implementation.
1537# ifdef BOOST_HAS_TR1_TUPLE
1538# undef BOOST_HAS_TR1_TUPLE
1539# endif // BOOST_HAS_TR1_TUPLE
1540
1541// This prevents <boost/tr1/detail/config.hpp>, which defines
1542// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
1543# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
1544# include <tuple>
1545
1546# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
1547// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
1548// not conform to the TR1 spec, which requires the header to be <tuple>.
1549
1550# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
1551// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
1552// which is #included by <tr1/tuple>, to not compile when RTTI is
1553// disabled. _TR1_FUNCTIONAL is the header guard for
1554// <tr1/functional>. Hence the following #define is a hack to prevent
1555// <tr1/functional> from being included.
1556# define _TR1_FUNCTIONAL 1
1557# include <tr1/tuple>
1558# undef _TR1_FUNCTIONAL // Allows the user to #include
1559 // <tr1/functional> if he chooses to.
1560# else
1561# include <tr1/tuple> // NOLINT
1562# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
1563
1564# else
1565// If the compiler is not GCC 4.0+, we assume the user is using a
1566// spec-conforming TR1 implementation.
1567# include <tuple> // NOLINT
1568# endif // GTEST_USE_OWN_TR1_TUPLE
1569
1570#endif // GTEST_HAS_TR1_TUPLE
1571
1572// Determines whether clone(2) is supported.
1573// Usually it will only be available on Linux, excluding
1574// Linux on the Itanium architecture.
1575// Also see http://linux.die.net/man/2/clone.
1576#ifndef GTEST_HAS_CLONE
1577// The user didn't tell us, so we need to figure it out.
1578
1579# if GTEST_OS_LINUX && !defined(__ia64__)
1580# define GTEST_HAS_CLONE 1
1581# else
1582# define GTEST_HAS_CLONE 0
1583# endif // GTEST_OS_LINUX && !defined(__ia64__)
1584
1585#endif // GTEST_HAS_CLONE
1586
1587// Determines whether to support stream redirection. This is used to test
1588// output correctness and to implement death tests.
1589#ifndef GTEST_HAS_STREAM_REDIRECTION
1590// By default, we assume that stream redirection is supported on all
1591// platforms except known mobile ones.
1592# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
1593# define GTEST_HAS_STREAM_REDIRECTION 0
1594# else
1595# define GTEST_HAS_STREAM_REDIRECTION 1
1596# endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
1597#endif // GTEST_HAS_STREAM_REDIRECTION
1598
1599// Determines whether to support death tests.
1600// Google Test does not support death tests for VC 7.1 and earlier as
1601// abort() in a VC 7.1 application compiled as GUI in debug config
1602// pops up a dialog window that cannot be suppressed programmatically.
1603#if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
1604 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
1605 GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)
1606# define GTEST_HAS_DEATH_TEST 1
1607# include <vector> // NOLINT
1608#endif
1609
1610// We don't support MSVC 7.1 with exceptions disabled now. Therefore
1611// all the compilers we care about are adequate for supporting
1612// value-parameterized tests.
1613#define GTEST_HAS_PARAM_TEST 1
1614
1615// Determines whether to support type-driven tests.
1616
1617// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
1618// Sun Pro CC, IBM Visual Age, and HP aCC support.
1619#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
1620 defined(__IBMCPP__) || defined(__HP_aCC)
1621# define GTEST_HAS_TYPED_TEST 1
1622# define GTEST_HAS_TYPED_TEST_P 1
1623#endif
1624
1625// Determines whether to support Combine(). This only makes sense when
1626// value-parameterized tests are enabled. The implementation doesn't
1627// work on Sun Studio since it doesn't understand templated conversion
1628// operators.
1629#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
1630# define GTEST_HAS_COMBINE 1
1631#endif
1632
1633// Determines whether the system compiler uses UTF-16 for encoding wide strings.
1634#define GTEST_WIDE_STRING_USES_UTF16_ \
1635 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
1636
1637// Determines whether test results can be streamed to a socket.
1638#if GTEST_OS_LINUX
1639# define GTEST_CAN_STREAM_RESULTS_ 1
1640#endif
1641
1642// Defines some utility macros.
1643
1644// The GNU compiler emits a warning if nested "if" statements are followed by
1645// an "else" statement and braces are not used to explicitly disambiguate the
1646// "else" binding. This leads to problems with code like:
1647//
1648// if (gate)
1649// ASSERT_*(condition) << "Some message";
1650//
1651// The "switch (0) case 0:" idiom is used to suppress this.
1652#ifdef __INTEL_COMPILER
1653# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
1654#else
1655# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT
1656#endif
1657
1658// Use this annotation at the end of a struct/class definition to
1659// prevent the compiler from optimizing away instances that are never
1660// used. This is useful when all interesting logic happens inside the
1661// c'tor and / or d'tor. Example:
1662//
1663// struct Foo {
1664// Foo() { ... }
1665// } GTEST_ATTRIBUTE_UNUSED_;
1666//
1667// Also use it after a variable or parameter declaration to tell the
1668// compiler the variable/parameter does not have to be used.
1669#if defined(__GNUC__) && !defined(COMPILER_ICC)
1670# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
1671#else
1672# define GTEST_ATTRIBUTE_UNUSED_
1673#endif
1674
1675// A macro to disallow operator=
1676// This should be used in the private: declarations for a class.
1677#define GTEST_DISALLOW_ASSIGN_(type)\
1678 void operator=(type const &)
1679
1680// A macro to disallow copy constructor and operator=
1681// This should be used in the private: declarations for a class.
1682#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
1683 type(type const &);\
1684 GTEST_DISALLOW_ASSIGN_(type)
1685
1686// Tell the compiler to warn about unused return values for functions declared
1687// with this macro. The macro should be used on function declarations
1688// following the argument list:
1689//
1690// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
1691#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
1692# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
1693#else
1694# define GTEST_MUST_USE_RESULT_
1695#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
1696
1697// Determine whether the compiler supports Microsoft's Structured Exception
1698// Handling. This is supported by several Windows compilers but generally
1699// does not exist on any other system.
1700#ifndef GTEST_HAS_SEH
1701// The user didn't tell us, so we need to figure it out.
1702
1703# if defined(_MSC_VER) || defined(__BORLANDC__)
1704// These two compilers are known to support SEH.
1705# define GTEST_HAS_SEH 1
1706# else
1707// Assume no SEH.
1708# define GTEST_HAS_SEH 0
1709# endif
1710
1711#endif // GTEST_HAS_SEH
1712
1713#ifdef _MSC_VER
1714
1715# if GTEST_LINKED_AS_SHARED_LIBRARY
1716# define GTEST_API_ __declspec(dllimport)
1717# elif GTEST_CREATE_SHARED_LIBRARY
1718# define GTEST_API_ __declspec(dllexport)
1719# endif
1720
1721#endif // _MSC_VER
1722
1723#ifndef GTEST_API_
1724# define GTEST_API_
1725#endif
1726
1727#ifdef __GNUC__
1728// Ask the compiler to never inline a given function.
1729# define GTEST_NO_INLINE_ __attribute__((noinline))
1730#else
1731# define GTEST_NO_INLINE_
1732#endif
1733
1734namespace testing {
1735
1736class Message;
1737
1738namespace internal {
1739
1740class String;
1741
1742// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
1743// expression is true. For example, you could use it to verify the
1744// size of a static array:
1745//
1746// GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
1747// content_type_names_incorrect_size);
1748//
1749// or to make sure a struct is smaller than a certain size:
1750//
1751// GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
1752//
1753// The second argument to the macro is the name of the variable. If
1754// the expression is false, most compilers will issue a warning/error
1755// containing the name of the variable.
1756
1757template <bool>
1758struct CompileAssert {
1759};
1760
1761#define GTEST_COMPILE_ASSERT_(expr, msg) \
1762 typedef ::testing::internal::CompileAssert<(bool(expr))> \
1763 msg[bool(expr) ? 1 : -1]
1764
1765// Implementation details of GTEST_COMPILE_ASSERT_:
1766//
1767// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
1768// elements (and thus is invalid) when the expression is false.
1769//
1770// - The simpler definition
1771//
1772// #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
1773//
1774// does not work, as gcc supports variable-length arrays whose sizes
1775// are determined at run-time (this is gcc's extension and not part
1776// of the C++ standard). As a result, gcc fails to reject the
1777// following code with the simple definition:
1778//
1779// int foo;
1780// GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
1781// // not a compile-time constant.
1782//
1783// - By using the type CompileAssert<(bool(expr))>, we ensures that
1784// expr is a compile-time constant. (Template arguments must be
1785// determined at compile-time.)
1786//
1787// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
1788// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
1789//
1790// CompileAssert<bool(expr)>
1791//
1792// instead, these compilers will refuse to compile
1793//
1794// GTEST_COMPILE_ASSERT_(5 > 0, some_message);
1795//
1796// (They seem to think the ">" in "5 > 0" marks the end of the
1797// template argument list.)
1798//
1799// - The array size is (bool(expr) ? 1 : -1), instead of simply
1800//
1801// ((expr) ? 1 : -1).
1802//
1803// This is to avoid running into a bug in MS VC 7.1, which
1804// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
1805
1806// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
1807//
1808// This template is declared, but intentionally undefined.
1809template <typename T1, typename T2>
1810struct StaticAssertTypeEqHelper;
1811
1812template <typename T>
1813struct StaticAssertTypeEqHelper<T, T> {};
1814
1815#if GTEST_HAS_GLOBAL_STRING
1816typedef ::string string;
1817#else
1818typedef ::std::string string;
1819#endif // GTEST_HAS_GLOBAL_STRING
1820
1821#if GTEST_HAS_GLOBAL_WSTRING
1822typedef ::wstring wstring;
1823#elif GTEST_HAS_STD_WSTRING
1824typedef ::std::wstring wstring;
1825#endif // GTEST_HAS_GLOBAL_WSTRING
1826
1827// A helper for suppressing warnings on constant condition. It just
1828// returns 'condition'.
1829GTEST_API_ bool IsTrue(bool condition);
1830
1831// Defines scoped_ptr.
1832
1833// This implementation of scoped_ptr is PARTIAL - it only contains
1834// enough stuff to satisfy Google Test's need.
1835template <typename T>
1836class scoped_ptr {
1837 public:
1838 typedef T element_type;
1839
1840 explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
1841 ~scoped_ptr() { reset(); }
1842
1843 T& operator*() const { return *ptr_; }
1844 T* operator->() const { return ptr_; }
1845 T* get() const { return ptr_; }
1846
1847 T* release() {
1848 T* const ptr = ptr_;
1849 ptr_ = NULL;
1850 return ptr;
1851 }
1852
1853 void reset(T* p = NULL) {
1854 if (p != ptr_) {
1855 if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type.
1856 delete ptr_;
1857 }
1858 ptr_ = p;
1859 }
1860 }
1861 private:
1862 T* ptr_;
1863
1864 GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
1865};
1866
1867// Defines RE.
1868
1869// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
1870// Regular Expression syntax.
1871class GTEST_API_ RE {
1872 public:
1873 // A copy constructor is required by the Standard to initialize object
1874 // references from r-values.
1875 RE(const RE& other) { Init(other.pattern()); }
1876
1877 // Constructs an RE from a string.
1878 RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT
1879
1880#if GTEST_HAS_GLOBAL_STRING
1881
1882 RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT
1883
1884#endif // GTEST_HAS_GLOBAL_STRING
1885
1886 RE(const char* regex) { Init(regex); } // NOLINT
1887 ~RE();
1888
1889 // Returns the string representation of the regex.
1890 const char* pattern() const { return pattern_; }
1891
1892 // FullMatch(str, re) returns true iff regular expression re matches
1893 // the entire str.
1894 // PartialMatch(str, re) returns true iff regular expression re
1895 // matches a substring of str (including str itself).
1896 //
1897 // TODO(wan@google.com): make FullMatch() and PartialMatch() work
1898 // when str contains NUL characters.
1899 static bool FullMatch(const ::std::string& str, const RE& re) {
1900 return FullMatch(str.c_str(), re);
1901 }
1902 static bool PartialMatch(const ::std::string& str, const RE& re) {
1903 return PartialMatch(str.c_str(), re);
1904 }
1905
1906#if GTEST_HAS_GLOBAL_STRING
1907
1908 static bool FullMatch(const ::string& str, const RE& re) {
1909 return FullMatch(str.c_str(), re);
1910 }
1911 static bool PartialMatch(const ::string& str, const RE& re) {
1912 return PartialMatch(str.c_str(), re);
1913 }
1914
1915#endif // GTEST_HAS_GLOBAL_STRING
1916
1917 static bool FullMatch(const char* str, const RE& re);
1918 static bool PartialMatch(const char* str, const RE& re);
1919
1920 private:
1921 void Init(const char* regex);
1922
1923 // We use a const char* instead of a string, as Google Test may be used
1924 // where string is not available. We also do not use Google Test's own
1925 // String type here, in order to simplify dependencies between the
1926 // files.
1927 const char* pattern_;
1928 bool is_valid_;
1929
1930#if GTEST_USES_POSIX_RE
1931
1932 regex_t full_regex_; // For FullMatch().
1933 regex_t partial_regex_; // For PartialMatch().
1934
1935#else // GTEST_USES_SIMPLE_RE
1936
1937 const char* full_pattern_; // For FullMatch();
1938
1939#endif
1940
1941 GTEST_DISALLOW_ASSIGN_(RE);
1942};
1943
1944// Formats a source file path and a line number as they would appear
1945// in an error message from the compiler used to compile this code.
1946GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
1947
1948// Formats a file location for compiler-independent XML output.
1949// Although this function is not platform dependent, we put it next to
1950// FormatFileLocation in order to contrast the two functions.
1951GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
1952 int line);
1953
1954// Defines logging utilities:
1955// GTEST_LOG_(severity) - logs messages at the specified severity level. The
1956// message itself is streamed into the macro.
1957// LogToStderr() - directs all log messages to stderr.
1958// FlushInfoLog() - flushes informational log messages.
1959
1960enum GTestLogSeverity {
1961 GTEST_INFO,
1962 GTEST_WARNING,
1963 GTEST_ERROR,
1964 GTEST_FATAL
1965};
1966
1967// Formats log entry severity, provides a stream object for streaming the
1968// log message, and terminates the message with a newline when going out of
1969// scope.
1970class GTEST_API_ GTestLog {
1971 public:
1972 GTestLog(GTestLogSeverity severity, const char* file, int line);
1973
1974 // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
1975 ~GTestLog();
1976
1977 ::std::ostream& GetStream() { return ::std::cerr; }
1978
1979 private:
1980 const GTestLogSeverity severity_;
1981
1982 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
1983};
1984
1985#define GTEST_LOG_(severity) \
1986 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
1987 __FILE__, __LINE__).GetStream()
1988
1989inline void LogToStderr() {}
1990inline void FlushInfoLog() { fflush(NULL); }
1991
1992// INTERNAL IMPLEMENTATION - DO NOT USE.
1993//
1994// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
1995// is not satisfied.
1996// Synopsys:
1997// GTEST_CHECK_(boolean_condition);
1998// or
1999// GTEST_CHECK_(boolean_condition) << "Additional message";
2000//
2001// This checks the condition and if the condition is not satisfied
2002// it prints message about the condition violation, including the
2003// condition itself, plus additional message streamed into it, if any,
2004// and then it aborts the program. It aborts the program irrespective of
2005// whether it is built in the debug mode or not.
2006#define GTEST_CHECK_(condition) \
2007 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
2008 if (::testing::internal::IsTrue(condition)) \
2009 ; \
2010 else \
2011 GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
2012
2013// An all-mode assert to verify that the given POSIX-style function
2014// call returns 0 (indicating success). Known limitation: this
2015// doesn't expand to a balanced 'if' statement, so enclose the macro
2016// in {} if you need to use it as the only statement in an 'if'
2017// branch.
2018#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
2019 if (const int gtest_error = (posix_call)) \
2020 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
2021 << gtest_error
2022
2023// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
2024//
2025// Use ImplicitCast_ as a safe version of static_cast for upcasting in
2026// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
2027// const Foo*). When you use ImplicitCast_, the compiler checks that
2028// the cast is safe. Such explicit ImplicitCast_s are necessary in
2029// surprisingly many situations where C++ demands an exact type match
2030// instead of an argument type convertable to a target type.
2031//
2032// The syntax for using ImplicitCast_ is the same as for static_cast:
2033//
2034// ImplicitCast_<ToType>(expr)
2035//
2036// ImplicitCast_ would have been part of the C++ standard library,
2037// but the proposal was submitted too late. It will probably make
2038// its way into the language in the future.
2039//
2040// This relatively ugly name is intentional. It prevents clashes with
2041// similar functions users may have (e.g., implicit_cast). The internal
2042// namespace alone is not enough because the function can be found by ADL.
2043template<typename To>
2044inline To ImplicitCast_(To x) { return x; }
2045
2046// When you upcast (that is, cast a pointer from type Foo to type
2047// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
2048// always succeed. When you downcast (that is, cast a pointer from
2049// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
2050// how do you know the pointer is really of type SubclassOfFoo? It
2051// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
2052// when you downcast, you should use this macro. In debug mode, we
2053// use dynamic_cast<> to double-check the downcast is legal (we die
2054// if it's not). In normal mode, we do the efficient static_cast<>
2055// instead. Thus, it's important to test in debug mode to make sure
2056// the cast is legal!
2057// This is the only place in the code we should use dynamic_cast<>.
2058// In particular, you SHOULDN'T be using dynamic_cast<> in order to
2059// do RTTI (eg code like this:
2060// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
2061// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
2062// You should design the code some other way not to need this.
2063//
2064// This relatively ugly name is intentional. It prevents clashes with
2065// similar functions users may have (e.g., down_cast). The internal
2066// namespace alone is not enough because the function can be found by ADL.
2067template<typename To, typename From> // use like this: DownCast_<T*>(foo);
2068inline To DownCast_(From* f) { // so we only accept pointers
2069 // Ensures that To is a sub-type of From *. This test is here only
2070 // for compile-time type checking, and has no overhead in an
2071 // optimized build at run-time, as it will be optimized away
2072 // completely.
2073 if (false) {
2074 const To to = NULL;
2075 ::testing::internal::ImplicitCast_<From*>(to);
2076 }
2077
2078#if GTEST_HAS_RTTI
2079 // RTTI: debug mode only!
2080 GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
2081#endif
2082 return static_cast<To>(f);
2083}
2084
2085// Downcasts the pointer of type Base to Derived.
2086// Derived must be a subclass of Base. The parameter MUST
2087// point to a class of type Derived, not any subclass of it.
2088// When RTTI is available, the function performs a runtime
2089// check to enforce this.
2090template <class Derived, class Base>
2091Derived* CheckedDowncastToActualType(Base* base) {
2092#if GTEST_HAS_RTTI
2093 GTEST_CHECK_(typeid(*base) == typeid(Derived));
2094 return dynamic_cast<Derived*>(base); // NOLINT
2095#else
2096 return static_cast<Derived*>(base); // Poor man's downcast.
2097#endif
2098}
2099
2100#if GTEST_HAS_STREAM_REDIRECTION
2101
2102// Defines the stderr capturer:
2103// CaptureStdout - starts capturing stdout.
2104// GetCapturedStdout - stops capturing stdout and returns the captured string.
2105// CaptureStderr - starts capturing stderr.
2106// GetCapturedStderr - stops capturing stderr and returns the captured string.
2107//
2108GTEST_API_ void CaptureStdout();
2109GTEST_API_ String GetCapturedStdout();
2110GTEST_API_ void CaptureStderr();
2111GTEST_API_ String GetCapturedStderr();
2112
2113#endif // GTEST_HAS_STREAM_REDIRECTION
2114
2115
2116#if GTEST_HAS_DEATH_TEST
2117
2118// A copy of all command line arguments. Set by InitGoogleTest().
2119extern ::std::vector<String> g_argvs;
2120
2121// GTEST_HAS_DEATH_TEST implies we have ::std::string.
2122const ::std::vector<String>& GetArgvs();
2123
2124#endif // GTEST_HAS_DEATH_TEST
2125
2126// Defines synchronization primitives.
2127
2128#if GTEST_HAS_PTHREAD
2129
2130// Sleeps for (roughly) n milli-seconds. This function is only for
2131// testing Google Test's own constructs. Don't use it in user tests,
2132// either directly or indirectly.
2133inline void SleepMilliseconds(int n) {
2134 const timespec time = {
2135 0, // 0 seconds.
2136 n * 1000L * 1000L, // And n ms.
2137 };
2138 nanosleep(&time, NULL);
2139}
2140
2141// Allows a controller thread to pause execution of newly created
2142// threads until notified. Instances of this class must be created
2143// and destroyed in the controller thread.
2144//
2145// This class is only for testing Google Test's own constructs. Do not
2146// use it in user tests, either directly or indirectly.
2147class Notification {
2148 public:
2149 Notification() : notified_(false) {}
2150
2151 // Notifies all threads created with this notification to start. Must
2152 // be called from the controller thread.
2153 void Notify() { notified_ = true; }
2154
2155 // Blocks until the controller thread notifies. Must be called from a test
2156 // thread.
2157 void WaitForNotification() {
2158 while(!notified_) {
2159 SleepMilliseconds(10);
2160 }
2161 }
2162
2163 private:
2164 volatile bool notified_;
2165
2166 GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
2167};
2168
2169// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
2170// Consequently, it cannot select a correct instantiation of ThreadWithParam
2171// in order to call its Run(). Introducing ThreadWithParamBase as a
2172// non-templated base class for ThreadWithParam allows us to bypass this
2173// problem.
2174class ThreadWithParamBase {
2175 public:
2176 virtual ~ThreadWithParamBase() {}
2177 virtual void Run() = 0;
2178};
2179
2180// pthread_create() accepts a pointer to a function type with the C linkage.
2181// According to the Standard (7.5/1), function types with different linkages
2182// are different even if they are otherwise identical. Some compilers (for
2183// example, SunStudio) treat them as different types. Since class methods
2184// cannot be defined with C-linkage we need to define a free C-function to
2185// pass into pthread_create().
2186extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
2187 static_cast<ThreadWithParamBase*>(thread)->Run();
2188 return NULL;
2189}
2190
2191// Helper class for testing Google Test's multi-threading constructs.
2192// To use it, write:
2193//
2194// void ThreadFunc(int param) { /* Do things with param */ }
2195// Notification thread_can_start;
2196// ...
2197// // The thread_can_start parameter is optional; you can supply NULL.
2198// ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
2199// thread_can_start.Notify();
2200//
2201// These classes are only for testing Google Test's own constructs. Do
2202// not use them in user tests, either directly or indirectly.
2203template <typename T>
2204class ThreadWithParam : public ThreadWithParamBase {
2205 public:
2206 typedef void (*UserThreadFunc)(T);
2207
2208 ThreadWithParam(
2209 UserThreadFunc func, T param, Notification* thread_can_start)
2210 : func_(func),
2211 param_(param),
2212 thread_can_start_(thread_can_start),
2213 finished_(false) {
2214 ThreadWithParamBase* const base = this;
2215 // The thread can be created only after all fields except thread_
2216 // have been initialized.
2217 GTEST_CHECK_POSIX_SUCCESS_(
2218 pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
2219 }
2220 ~ThreadWithParam() { Join(); }
2221
2222 void Join() {
2223 if (!finished_) {
2224 GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
2225 finished_ = true;
2226 }
2227 }
2228
2229 virtual void Run() {
2230 if (thread_can_start_ != NULL)
2231 thread_can_start_->WaitForNotification();
2232 func_(param_);
2233 }
2234
2235 private:
2236 const UserThreadFunc func_; // User-supplied thread function.
2237 const T param_; // User-supplied parameter to the thread function.
2238 // When non-NULL, used to block execution until the controller thread
2239 // notifies.
2240 Notification* const thread_can_start_;
2241 bool finished_; // true iff we know that the thread function has finished.
2242 pthread_t thread_; // The native thread object.
2243
2244 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
2245};
2246
2247// MutexBase and Mutex implement mutex on pthreads-based platforms. They
2248// are used in conjunction with class MutexLock:
2249//
2250// Mutex mutex;
2251// ...
2252// MutexLock lock(&mutex); // Acquires the mutex and releases it at the end
2253// // of the current scope.
2254//
2255// MutexBase implements behavior for both statically and dynamically
2256// allocated mutexes. Do not use MutexBase directly. Instead, write
2257// the following to define a static mutex:
2258//
2259// GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
2260//
2261// You can forward declare a static mutex like this:
2262//
2263// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
2264//
2265// To create a dynamic mutex, just define an object of type Mutex.
2266class MutexBase {
2267 public:
2268 // Acquires this mutex.
2269 void Lock() {
2270 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
2271 owner_ = pthread_self();
2272 }
2273
2274 // Releases this mutex.
2275 void Unlock() {
2276 // We don't protect writing to owner_ here, as it's the caller's
2277 // responsibility to ensure that the current thread holds the
2278 // mutex when this is called.
2279 owner_ = 0;
2280 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
2281 }
2282
2283 // Does nothing if the current thread holds the mutex. Otherwise, crashes
2284 // with high probability.
2285 void AssertHeld() const {
2286 GTEST_CHECK_(owner_ == pthread_self())
2287 << "The current thread is not holding the mutex @" << this;
2288 }
2289
2290 // A static mutex may be used before main() is entered. It may even
2291 // be used before the dynamic initialization stage. Therefore we
2292 // must be able to initialize a static mutex object at link time.
2293 // This means MutexBase has to be a POD and its member variables
2294 // have to be public.
2295 public:
2296 pthread_mutex_t mutex_; // The underlying pthread mutex.
2297 pthread_t owner_; // The thread holding the mutex; 0 means no one holds it.
2298};
2299
2300// Forward-declares a static mutex.
2301# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
2302 extern ::testing::internal::MutexBase mutex
2303
2304// Defines and statically (i.e. at link time) initializes a static mutex.
2305# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
2306 ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 }
2307
2308// The Mutex class can only be used for mutexes created at runtime. It
2309// shares its API with MutexBase otherwise.
2310class Mutex : public MutexBase {
2311 public:
2312 Mutex() {
2313 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
2314 owner_ = 0;
2315 }
2316 ~Mutex() {
2317 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
2318 }
2319
2320 private:
2321 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
2322};
2323
2324// We cannot name this class MutexLock as the ctor declaration would
2325// conflict with a macro named MutexLock, which is defined on some
2326// platforms. Hence the typedef trick below.
2327class GTestMutexLock {
2328 public:
2329 explicit GTestMutexLock(MutexBase* mutex)
2330 : mutex_(mutex) { mutex_->Lock(); }
2331
2332 ~GTestMutexLock() { mutex_->Unlock(); }
2333
2334 private:
2335 MutexBase* const mutex_;
2336
2337 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
2338};
2339
2340typedef GTestMutexLock MutexLock;
2341
2342// Helpers for ThreadLocal.
2343
2344// pthread_key_create() requires DeleteThreadLocalValue() to have
2345// C-linkage. Therefore it cannot be templatized to access
2346// ThreadLocal<T>. Hence the need for class
2347// ThreadLocalValueHolderBase.
2348class ThreadLocalValueHolderBase {
2349 public:
2350 virtual ~ThreadLocalValueHolderBase() {}
2351};
2352
2353// Called by pthread to delete thread-local data stored by
2354// pthread_setspecific().
2355extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
2356 delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
2357}
2358
2359// Implements thread-local storage on pthreads-based systems.
2360//
2361// // Thread 1
2362// ThreadLocal<int> tl(100); // 100 is the default value for each thread.
2363//
2364// // Thread 2
2365// tl.set(150); // Changes the value for thread 2 only.
2366// EXPECT_EQ(150, tl.get());
2367//
2368// // Thread 1
2369// EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value.
2370// tl.set(200);
2371// EXPECT_EQ(200, tl.get());
2372//
2373// The template type argument T must have a public copy constructor.
2374// In addition, the default ThreadLocal constructor requires T to have
2375// a public default constructor.
2376//
2377// An object managed for a thread by a ThreadLocal instance is deleted
2378// when the thread exits. Or, if the ThreadLocal instance dies in
2379// that thread, when the ThreadLocal dies. It's the user's
2380// responsibility to ensure that all other threads using a ThreadLocal
2381// have exited when it dies, or the per-thread objects for those
2382// threads will not be deleted.
2383//
2384// Google Test only uses global ThreadLocal objects. That means they
2385// will die after main() has returned. Therefore, no per-thread
2386// object managed by Google Test will be leaked as long as all threads
2387// using Google Test have exited when main() returns.
2388template <typename T>
2389class ThreadLocal {
2390 public:
2391 ThreadLocal() : key_(CreateKey()),
2392 default_() {}
2393 explicit ThreadLocal(const T& value) : key_(CreateKey()),
2394 default_(value) {}
2395
2396 ~ThreadLocal() {
2397 // Destroys the managed object for the current thread, if any.
2398 DeleteThreadLocalValue(pthread_getspecific(key_));
2399
2400 // Releases resources associated with the key. This will *not*
2401 // delete managed objects for other threads.
2402 GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
2403 }
2404
2405 T* pointer() { return GetOrCreateValue(); }
2406 const T* pointer() const { return GetOrCreateValue(); }
2407 const T& get() const { return *pointer(); }
2408 void set(const T& value) { *pointer() = value; }
2409
2410 private:
2411 // Holds a value of type T.
2412 class ValueHolder : public ThreadLocalValueHolderBase {
2413 public:
2414 explicit ValueHolder(const T& value) : value_(value) {}
2415
2416 T* pointer() { return &value_; }
2417
2418 private:
2419 T value_;
2420 GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
2421 };
2422
2423 static pthread_key_t CreateKey() {
2424 pthread_key_t key;
2425 // When a thread exits, DeleteThreadLocalValue() will be called on
2426 // the object managed for that thread.
2427 GTEST_CHECK_POSIX_SUCCESS_(
2428 pthread_key_create(&key, &DeleteThreadLocalValue));
2429 return key;
2430 }
2431
2432 T* GetOrCreateValue() const {
2433 ThreadLocalValueHolderBase* const holder =
2434 static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
2435 if (holder != NULL) {
2436 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
2437 }
2438
2439 ValueHolder* const new_holder = new ValueHolder(default_);
2440 ThreadLocalValueHolderBase* const holder_base = new_holder;
2441 GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
2442 return new_holder->pointer();
2443 }
2444
2445 // A key pthreads uses for looking up per-thread values.
2446 const pthread_key_t key_;
2447 const T default_; // The default value for each thread.
2448
2449 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
2450};
2451
2452# define GTEST_IS_THREADSAFE 1
2453
2454#else // GTEST_HAS_PTHREAD
2455
2456// A dummy implementation of synchronization primitives (mutex, lock,
2457// and thread-local variable). Necessary for compiling Google Test where
2458// mutex is not supported - using Google Test in multiple threads is not
2459// supported on such platforms.
2460
2461class Mutex {
2462 public:
2463 Mutex() {}
2464 void AssertHeld() const {}
2465};
2466
2467# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
2468 extern ::testing::internal::Mutex mutex
2469
2470# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
2471
2472class GTestMutexLock {
2473 public:
2474 explicit GTestMutexLock(Mutex*) {} // NOLINT
2475};
2476
2477typedef GTestMutexLock MutexLock;
2478
2479template <typename T>
2480class ThreadLocal {
2481 public:
2482 ThreadLocal() : value_() {}
2483 explicit ThreadLocal(const T& value) : value_(value) {}
2484 T* pointer() { return &value_; }
2485 const T* pointer() const { return &value_; }
2486 const T& get() const { return value_; }
2487 void set(const T& value) { value_ = value; }
2488 private:
2489 T value_;
2490};
2491
2492// The above synchronization primitives have dummy implementations.
2493// Therefore Google Test is not thread-safe.
2494# define GTEST_IS_THREADSAFE 0
2495
2496#endif // GTEST_HAS_PTHREAD
2497
2498// Returns the number of threads running in the process, or 0 to indicate that
2499// we cannot detect it.
2500GTEST_API_ size_t GetThreadCount();
2501
2502// Passing non-POD classes through ellipsis (...) crashes the ARM
2503// compiler and generates a warning in Sun Studio. The Nokia Symbian
2504// and the IBM XL C/C++ compiler try to instantiate a copy constructor
2505// for objects passed through ellipsis (...), failing for uncopyable
2506// objects. We define this to ensure that only POD is passed through
2507// ellipsis on these systems.
2508#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
2509// We lose support for NULL detection where the compiler doesn't like
2510// passing non-POD classes through ellipsis (...).
2511# define GTEST_ELLIPSIS_NEEDS_POD_ 1
2512#else
2513# define GTEST_CAN_COMPARE_NULL 1
2514#endif
2515
2516// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
2517// const T& and const T* in a function template. These compilers
2518// _can_ decide between class template specializations for T and T*,
2519// so a tr1::type_traits-like is_pointer works.
2520#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
2521# define GTEST_NEEDS_IS_POINTER_ 1
2522#endif
2523
2524template <bool bool_value>
2525struct bool_constant {
2526 typedef bool_constant<bool_value> type;
2527 static const bool value = bool_value;
2528};
2529template <bool bool_value> const bool bool_constant<bool_value>::value;
2530
2531typedef bool_constant<false> false_type;
2532typedef bool_constant<true> true_type;
2533
2534template <typename T>
2535struct is_pointer : public false_type {};
2536
2537template <typename T>
2538struct is_pointer<T*> : public true_type {};
2539
2540template <typename Iterator>
2541struct IteratorTraits {
2542 typedef typename Iterator::value_type value_type;
2543};
2544
2545template <typename T>
2546struct IteratorTraits<T*> {
2547 typedef T value_type;
2548};
2549
2550template <typename T>
2551struct IteratorTraits<const T*> {
2552 typedef T value_type;
2553};
2554
2555#if GTEST_OS_WINDOWS
2556# define GTEST_PATH_SEP_ "\\"
2557# define GTEST_HAS_ALT_PATH_SEP_ 1
2558// The biggest signed integer type the compiler supports.
2559typedef __int64 BiggestInt;
2560#else
2561# define GTEST_PATH_SEP_ "/"
2562# define GTEST_HAS_ALT_PATH_SEP_ 0
2563typedef long long BiggestInt; // NOLINT
2564#endif // GTEST_OS_WINDOWS
2565
2566// Utilities for char.
2567
2568// isspace(int ch) and friends accept an unsigned char or EOF. char
2569// may be signed, depending on the compiler (or compiler flags).
2570// Therefore we need to cast a char to unsigned char before calling
2571// isspace(), etc.
2572
2573inline bool IsAlpha(char ch) {
2574 return isalpha(static_cast<unsigned char>(ch)) != 0;
2575}
2576inline bool IsAlNum(char ch) {
2577 return isalnum(static_cast<unsigned char>(ch)) != 0;
2578}
2579inline bool IsDigit(char ch) {
2580 return isdigit(static_cast<unsigned char>(ch)) != 0;
2581}
2582inline bool IsLower(char ch) {
2583 return islower(static_cast<unsigned char>(ch)) != 0;
2584}
2585inline bool IsSpace(char ch) {
2586 return isspace(static_cast<unsigned char>(ch)) != 0;
2587}
2588inline bool IsUpper(char ch) {
2589 return isupper(static_cast<unsigned char>(ch)) != 0;
2590}
2591inline bool IsXDigit(char ch) {
2592 return isxdigit(static_cast<unsigned char>(ch)) != 0;
2593}
2594
2595inline char ToLower(char ch) {
2596 return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
2597}
2598inline char ToUpper(char ch) {
2599 return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
2600}
2601
2602// The testing::internal::posix namespace holds wrappers for common
2603// POSIX functions. These wrappers hide the differences between
2604// Windows/MSVC and POSIX systems. Since some compilers define these
2605// standard functions as macros, the wrapper cannot have the same name
2606// as the wrapped function.
2607
2608namespace posix {
2609
2610// Functions with a different name on Windows.
2611
2612#if GTEST_OS_WINDOWS
2613
2614typedef struct _stat StatStruct;
2615
2616# ifdef __BORLANDC__
2617inline int IsATTY(int fd) { return isatty(fd); }
2618inline int StrCaseCmp(const char* s1, const char* s2) {
2619 return stricmp(s1, s2);
2620}
2621inline char* StrDup(const char* src) { return strdup(src); }
2622# else // !__BORLANDC__
2623# if GTEST_OS_WINDOWS_MOBILE
2624inline int IsATTY(int /* fd */) { return 0; }
2625# else
2626inline int IsATTY(int fd) { return _isatty(fd); }
2627# endif // GTEST_OS_WINDOWS_MOBILE
2628inline int StrCaseCmp(const char* s1, const char* s2) {
2629 return _stricmp(s1, s2);
2630}
2631inline char* StrDup(const char* src) { return _strdup(src); }
2632# endif // __BORLANDC__
2633
2634# if GTEST_OS_WINDOWS_MOBILE
2635inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
2636// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
2637// time and thus not defined there.
2638# else
2639inline int FileNo(FILE* file) { return _fileno(file); }
2640inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
2641inline int RmDir(const char* dir) { return _rmdir(dir); }
2642inline bool IsDir(const StatStruct& st) {
2643 return (_S_IFDIR & st.st_mode) != 0;
2644}
2645# endif // GTEST_OS_WINDOWS_MOBILE
2646
2647#else
2648
2649typedef struct stat StatStruct;
2650
2651inline int FileNo(FILE* file) { return fileno(file); }
2652inline int IsATTY(int fd) { return isatty(fd); }
2653inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
2654inline int StrCaseCmp(const char* s1, const char* s2) {
2655 return strcasecmp(s1, s2);
2656}
2657inline char* StrDup(const char* src) { return strdup(src); }
2658inline int RmDir(const char* dir) { return rmdir(dir); }
2659inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
2660
2661#endif // GTEST_OS_WINDOWS
2662
2663// Functions deprecated by MSVC 8.0.
2664
2665#ifdef _MSC_VER
2666// Temporarily disable warning 4996 (deprecated function).
2667# pragma warning(push)
2668# pragma warning(disable:4996)
2669#endif
2670
2671inline const char* StrNCpy(char* dest, const char* src, size_t n) {
2672 return strncpy(dest, src, n);
2673}
2674
2675// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
2676// StrError() aren't needed on Windows CE at this time and thus not
2677// defined there.
2678
2679#if !GTEST_OS_WINDOWS_MOBILE
2680inline int ChDir(const char* dir) { return chdir(dir); }
2681#endif
2682inline FILE* FOpen(const char* path, const char* mode) {
2683 return fopen(path, mode);
2684}
2685#if !GTEST_OS_WINDOWS_MOBILE
2686inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
2687 return freopen(path, mode, stream);
2688}
2689inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
2690#endif
2691inline int FClose(FILE* fp) { return fclose(fp); }
2692#if !GTEST_OS_WINDOWS_MOBILE
2693inline int Read(int fd, void* buf, unsigned int count) {
2694 return static_cast<int>(read(fd, buf, count));
2695}
2696inline int Write(int fd, const void* buf, unsigned int count) {
2697 return static_cast<int>(write(fd, buf, count));
2698}
2699inline int Close(int fd) { return close(fd); }
2700inline const char* StrError(int errnum) { return strerror(errnum); }
2701#endif
2702inline const char* GetEnv(const char* name) {
2703#if GTEST_OS_WINDOWS_MOBILE
2704 // We are on Windows CE, which has no environment variables.
2705 return NULL;
2706#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
2707 // Environment variables which we programmatically clear will be set to the
2708 // empty string rather than unset (NULL). Handle that case.
2709 const char* const env = getenv(name);
2710 return (env != NULL && env[0] != '\0') ? env : NULL;
2711#else
2712 return getenv(name);
2713#endif
2714}
2715
2716#ifdef _MSC_VER
2717# pragma warning(pop) // Restores the warning state.
2718#endif
2719
2720#if GTEST_OS_WINDOWS_MOBILE
2721// Windows CE has no C library. The abort() function is used in
2722// several places in Google Test. This implementation provides a reasonable
2723// imitation of standard behaviour.
2724void Abort();
2725#else
2726inline void Abort() { abort(); }
2727#endif // GTEST_OS_WINDOWS_MOBILE
2728
2729} // namespace posix
2730
2731// The maximum number a BiggestInt can represent. This definition
2732// works no matter BiggestInt is represented in one's complement or
2733// two's complement.
2734//
2735// We cannot rely on numeric_limits in STL, as __int64 and long long
2736// are not part of standard C++ and numeric_limits doesn't need to be
2737// defined for them.
2738const BiggestInt kMaxBiggestInt =
2739 ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
2740
2741// This template class serves as a compile-time function from size to
2742// type. It maps a size in bytes to a primitive type with that
2743// size. e.g.
2744//
2745// TypeWithSize<4>::UInt
2746//
2747// is typedef-ed to be unsigned int (unsigned integer made up of 4
2748// bytes).
2749//
2750// Such functionality should belong to STL, but I cannot find it
2751// there.
2752//
2753// Google Test uses this class in the implementation of floating-point
2754// comparison.
2755//
2756// For now it only handles UInt (unsigned int) as that's all Google Test
2757// needs. Other types can be easily added in the future if need
2758// arises.
2759template <size_t size>
2760class TypeWithSize {
2761 public:
2762 // This prevents the user from using TypeWithSize<N> with incorrect
2763 // values of N.
2764 typedef void UInt;
2765};
2766
2767// The specialization for size 4.
2768template <>
2769class TypeWithSize<4> {
2770 public:
2771 // unsigned int has size 4 in both gcc and MSVC.
2772 //
2773 // As base/basictypes.h doesn't compile on Windows, we cannot use
2774 // uint32, uint64, and etc here.
2775 typedef int Int;
2776 typedef unsigned int UInt;
2777};
2778
2779// The specialization for size 8.
2780template <>
2781class TypeWithSize<8> {
2782 public:
2783
2784#if GTEST_OS_WINDOWS
2785 typedef __int64 Int;
2786 typedef unsigned __int64 UInt;
2787#else
2788 typedef long long Int; // NOLINT
2789 typedef unsigned long long UInt; // NOLINT
2790#endif // GTEST_OS_WINDOWS
2791};
2792
2793// Integer types of known sizes.
2794typedef TypeWithSize<4>::Int Int32;
2795typedef TypeWithSize<4>::UInt UInt32;
2796typedef TypeWithSize<8>::Int Int64;
2797typedef TypeWithSize<8>::UInt UInt64;
2798typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
2799
2800// Utilities for command line flags and environment variables.
2801
2802// Macro for referencing flags.
2803#define GTEST_FLAG(name) FLAGS_gtest_##name
2804
2805// Macros for declaring flags.
2806#define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
2807#define GTEST_DECLARE_int32_(name) \
2808 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
2809#define GTEST_DECLARE_string_(name) \
2810 GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name)
2811
2812// Macros for defining flags.
2813#define GTEST_DEFINE_bool_(name, default_val, doc) \
2814 GTEST_API_ bool GTEST_FLAG(name) = (default_val)
2815#define GTEST_DEFINE_int32_(name, default_val, doc) \
2816 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
2817#define GTEST_DEFINE_string_(name, default_val, doc) \
2818 GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
2819
2820// Parses 'str' for a 32-bit signed integer. If successful, writes the result
2821// to *value and returns true; otherwise leaves *value unchanged and returns
2822// false.
2823// TODO(chandlerc): Find a better way to refactor flag and environment parsing
2824// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
2825// function.
2826bool ParseInt32(const Message& src_text, const char* str, Int32* value);
2827
2828// Parses a bool/Int32/string from the environment variable
2829// corresponding to the given Google Test flag.
2830bool BoolFromGTestEnv(const char* flag, bool default_val);
2831GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
2832const char* StringFromGTestEnv(const char* flag, const char* default_val);
2833
2834} // namespace internal
2835} // namespace testing
2836
2837#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
2838
2839#if GTEST_OS_LINUX
2840# include <stdlib.h>
2841# include <sys/types.h>
2842# include <sys/wait.h>
2843# include <unistd.h>
2844#endif // GTEST_OS_LINUX
2845
2846#include <ctype.h>
2847#include <string.h>
2848#include <iomanip>
2849#include <limits>
2850#include <set>
2851
2852// Copyright 2005, Google Inc.
2853// All rights reserved.
2854//
2855// Redistribution and use in source and binary forms, with or without
2856// modification, are permitted provided that the following conditions are
2857// met:
2858//
2859// * Redistributions of source code must retain the above copyright
2860// notice, this list of conditions and the following disclaimer.
2861// * Redistributions in binary form must reproduce the above
2862// copyright notice, this list of conditions and the following disclaimer
2863// in the documentation and/or other materials provided with the
2864// distribution.
2865// * Neither the name of Google Inc. nor the names of its
2866// contributors may be used to endorse or promote products derived from
2867// this software without specific prior written permission.
2868//
2869// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2870// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2871// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2872// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2873// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2874// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2875// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2876// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2877// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2878// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2879// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2880//
2881// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
2882//
2883// The Google C++ Testing Framework (Google Test)
2884//
2885// This header file declares the String class and functions used internally by
2886// Google Test. They are subject to change without notice. They should not used
2887// by code external to Google Test.
2888//
2889// This header file is #included by <gtest/internal/gtest-internal.h>.
2890// It should not be #included by other files.
2891
2892#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
2893#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
2894
2895#ifdef __BORLANDC__
2896// string.h is not guaranteed to provide strcpy on C++ Builder.
2897# include <mem.h>
2898#endif
2899
2900#include <string.h>
2901
2902#include <string>
2903
2904namespace testing {
2905namespace internal {
2906
2907// String - a UTF-8 string class.
2908//
2909// For historic reasons, we don't use std::string.
2910//
2911// TODO(wan@google.com): replace this class with std::string or
2912// implement it in terms of the latter.
2913//
2914// Note that String can represent both NULL and the empty string,
2915// while std::string cannot represent NULL.
2916//
2917// NULL and the empty string are considered different. NULL is less
2918// than anything (including the empty string) except itself.
2919//
2920// This class only provides minimum functionality necessary for
2921// implementing Google Test. We do not intend to implement a full-fledged
2922// string class here.
2923//
2924// Since the purpose of this class is to provide a substitute for
2925// std::string on platforms where it cannot be used, we define a copy