1
// Copyright 2005, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
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
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.
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.
30
// Authors: wan@google.com (Zhanyong Wan)
32
// Low-level types and utilities for porting Google Test to various
33
// platforms. They are subject to change without notice. DO NOT USE
36
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
37
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
39
// The user can define the following macros in the build script to
40
// control Google Test's behavior. If the user doesn't define a macro
41
// in this list, Google Test will define it.
43
// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
44
// is/isn't available.
45
// GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
46
// is/isn't available (some systems define
47
// ::string, which is different to std::string).
48
// GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
49
// is/isn't available (some systems define
50
// ::wstring, which is different to std::wstring).
51
// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
52
// is/isn't available.
53
// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
55
// GTEST_HAS_STD_STRING - Define it to 1/0 to indicate that
56
// std::string does/doesn't work (Google Test can
57
// be used where std::string is unavailable).
58
// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
59
// std::wstring does/doesn't work (Google Test can
60
// be used where std::wstring is unavailable).
61
// GTEST_HAS_TR1_TUPLE 1 - Define it to 1/0 to indicate tr1::tuple
62
// is/isn't available.
64
// This header defines the following utilities:
66
// Macros indicating the name of the Google C++ Testing Framework project:
67
// GTEST_NAME - a string literal of the project name.
68
// GTEST_FLAG_PREFIX - a string literal of the prefix all Google
69
// Test flag names share.
70
// GTEST_FLAG_PREFIX_UPPER - a string literal of the prefix all Google
71
// Test flag names share, in upper case.
73
// Macros indicating the current platform:
74
// GTEST_OS_CYGWIN - defined iff compiled on Cygwin.
75
// GTEST_OS_LINUX - defined iff compiled on Linux.
76
// GTEST_OS_MAC - defined iff compiled on Mac OS X.
77
// GTEST_OS_SOLARIS - defined iff compiled on Sun Solaris.
78
// GTEST_OS_SYMBIAN - defined iff compiled for Symbian.
79
// GTEST_OS_WINDOWS - defined iff compiled on Windows.
80
// GTEST_OS_ZOS - defined iff compiled on IBM z/OS.
82
// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
83
// most stable support. Since core members of the Google Test project
84
// don't have access to other platforms, support for them may be less
85
// stable. If you notice any problems on your platform, please notify
86
// googletestframework@googlegroups.com (patches for fixing them are
87
// even more welcome!).
89
// Note that it is possible that none of the GTEST_OS_ macros are defined.
91
// Macros indicating available Google Test features:
92
// GTEST_HAS_COMBINE - defined iff Combine construct is supported
93
// in value-parameterized tests.
94
// GTEST_HAS_DEATH_TEST - defined iff death tests are supported.
95
// GTEST_HAS_PARAM_TEST - defined iff value-parameterized tests are
97
// GTEST_HAS_TYPED_TEST - defined iff typed tests are supported.
98
// GTEST_HAS_TYPED_TEST_P - defined iff type-parameterized tests are
101
// Macros for basic C++ coding:
102
// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
103
// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances don't have to
105
// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
106
// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
109
// Mutex, MutexLock, ThreadLocal, GetThreadCount()
110
// - synchronization primitives.
111
// GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
112
// synchronization primitives have real implementations
113
// and Google Test is thread-safe; or 0 otherwise.
115
// Template meta programming:
116
// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
119
// scoped_ptr - as in TR2.
121
// Regular expressions:
122
// RE - a simple regular expression class using the POSIX
123
// Extended Regular Expression syntax. Not available on
127
// GTEST_LOG_() - logs messages at the specified severity level.
128
// LogToStderr() - directs all log messages to stderr.
129
// FlushInfoLog() - flushes informational log messages.
132
// CaptureStderr() - starts capturing stderr.
133
// GetCapturedStderr() - stops capturing stderr and returns the captured
137
// TypeWithSize - maps an integer to a int type.
138
// Int32, UInt32, Int64, UInt64, TimeInMillis
139
// - integers of known sizes.
140
// BiggestInt - the biggest signed integer type.
142
// Command-line utilities:
143
// GTEST_FLAG() - references a flag.
144
// GTEST_DECLARE_*() - declares a flag.
145
// GTEST_DEFINE_*() - defines a flag.
146
// GetArgvs() - returns the command line as a vector of strings.
148
// Environment variable utilities:
149
// GetEnv() - gets the value of an environment variable.
150
// BoolFromGTestEnv() - parses a bool environment variable.
151
// Int32FromGTestEnv() - parses an Int32 environment variable.
152
// StringFromGTestEnv() - parses a string environment variable.
156
#include <iostream> // Used for GTEST_CHECK_
158
#define GTEST_NAME "Google Test"
159
#define GTEST_FLAG_PREFIX "gtest_"
160
#define GTEST_FLAG_PREFIX_UPPER "GTEST_"
162
// Determines the version of gcc that is used to compile this.
164
// 40302 means version 4.3.2.
165
#define GTEST_GCC_VER_ \
166
(__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
169
// Determines the platform on which Google Test is compiled.
171
#define GTEST_OS_CYGWIN
173
#define GTEST_OS_SYMBIAN
174
#elif defined _MSC_VER
175
// TODO(kenton@google.com): GTEST_OS_WINDOWS is currently used to mean
176
// both "The OS is Windows" and "The compiler is MSVC". These
177
// meanings really should be separated in order to better support
178
// Windows compilers other than MSVC.
179
#define GTEST_OS_WINDOWS
180
#elif defined __APPLE__
182
#elif defined __linux__
183
#define GTEST_OS_LINUX
184
#elif defined __MVS__
186
#elif defined(__sun) && defined(__SVR4)
187
#define GTEST_OS_SOLARIS
188
#elif defined(__HAIKU__)
189
#define GTEST_OS_HAIKU
192
// Determines whether ::std::string and ::string are available.
194
#ifndef GTEST_HAS_STD_STRING
195
// The user didn't tell us whether ::std::string is available, so we
196
// need to figure it out.
198
#ifdef GTEST_OS_WINDOWS
199
// Assumes that exceptions are enabled by default.
200
#ifndef _HAS_EXCEPTIONS
201
#define _HAS_EXCEPTIONS 1
202
#endif // _HAS_EXCEPTIONS
203
// GTEST_HAS_EXCEPTIONS is non-zero iff exceptions are enabled. It is
204
// always defined, while _HAS_EXCEPTIONS is defined only on Windows.
205
#define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
206
// On Windows, we can use ::std::string if the compiler version is VS
207
// 2005 or above, or if exceptions are enabled.
208
#define GTEST_HAS_STD_STRING ((_MSC_VER >= 1400) || GTEST_HAS_EXCEPTIONS)
209
#else // We are on Linux or Mac OS.
210
#define GTEST_HAS_EXCEPTIONS 0
211
#define GTEST_HAS_STD_STRING 1
212
#endif // GTEST_OS_WINDOWS
214
#endif // GTEST_HAS_STD_STRING
216
#ifndef GTEST_HAS_GLOBAL_STRING
217
// The user didn't tell us whether ::string is available, so we need
220
#define GTEST_HAS_GLOBAL_STRING 0
222
#endif // GTEST_HAS_GLOBAL_STRING
224
#ifndef GTEST_HAS_STD_WSTRING
225
// The user didn't tell us whether ::std::wstring is available, so we need
227
// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
230
#if defined(GTEST_OS_CYGWIN) || defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU)
231
// At least some versions of cygwin don't support ::std::wstring.
232
// Solaris' libc++ doesn't support it either.
233
#define GTEST_HAS_STD_WSTRING 0
235
#define GTEST_HAS_STD_WSTRING GTEST_HAS_STD_STRING
236
#endif // defined(GTEST_OS_CYGWIN) || defined(GTEST_OS_SOLARIS)
238
#endif // GTEST_HAS_STD_WSTRING
240
#ifndef GTEST_HAS_GLOBAL_WSTRING
241
// The user didn't tell us whether ::wstring is available, so we need
243
#define GTEST_HAS_GLOBAL_WSTRING GTEST_HAS_GLOBAL_STRING
244
#endif // GTEST_HAS_GLOBAL_WSTRING
246
#if GTEST_HAS_STD_STRING || GTEST_HAS_GLOBAL_STRING || \
247
GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
248
#include <string> // NOLINT
249
#endif // GTEST_HAS_STD_STRING || GTEST_HAS_GLOBAL_STRING ||
250
// GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
252
#if GTEST_HAS_STD_STRING
253
#include <sstream> // NOLINT
255
#include <strstream> // NOLINT
256
#endif // GTEST_HAS_STD_STRING
258
// Determines whether RTTI is available.
259
#ifndef GTEST_HAS_RTTI
260
// The user didn't tell us whether RTTI is enabled, so we need to
265
#ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
266
#define GTEST_HAS_RTTI 1
268
#define GTEST_HAS_RTTI 0
271
#elif defined(__GNUC__)
273
// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
274
#if GTEST_GCC_VER_ >= 40302
276
#define GTEST_HAS_RTTI 1
278
#define GTEST_HAS_RTTI 0
281
// For gcc versions smaller than 4.3.2, we assume RTTI is enabled.
282
#define GTEST_HAS_RTTI 1
283
#endif // GTEST_GCC_VER >= 40302
287
// Unknown compiler - assume RTTI is enabled.
288
#define GTEST_HAS_RTTI 1
292
#endif // GTEST_HAS_RTTI
294
// Determines whether <pthread.h> is available.
295
#ifndef GTEST_HAS_PTHREAD
296
// The user didn't tell us, so we need to figure it out.
298
#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC)
299
#define GTEST_HAS_PTHREAD 1
301
#define GTEST_HAS_PTHREAD 0
302
#endif // GTEST_OS_LINUX || GTEST_OS_MAC
304
#endif // GTEST_HAS_PTHREAD
306
// Determines whether tr1/tuple is available. If you have tr1/tuple
307
// on your platform, define GTEST_HAS_TR1_TUPLE=1 for both the Google
308
// Test project and your tests. If you would like Google Test to detect
309
// tr1/tuple on your platform automatically, please open an issue
310
// ticket at http://code.google.com/p/googletest.
311
#ifndef GTEST_HAS_TR1_TUPLE
312
// The user didn't tell us, so we need to figure it out.
314
// GCC provides <tr1/tuple> since 4.0.0.
315
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
316
#define GTEST_HAS_TR1_TUPLE 1
318
#define GTEST_HAS_TR1_TUPLE 0
320
#endif // GTEST_HAS_TR1_TUPLE
322
// To avoid conditional compilation everywhere, we make it
323
// gtest-port.h's responsibility to #include the header implementing
325
#if GTEST_HAS_TR1_TUPLE
326
#if defined(__GNUC__)
327
// GCC implements tr1/tuple in the <tr1/tuple> header. This does not
328
// conform to the TR1 spec, which requires the header to be <tuple>.
331
// If the compiler is not GCC, we assume the user is using a
332
// spec-conforming TR1 implementation.
335
#endif // GTEST_HAS_TR1_TUPLE
337
// Determines whether clone(2) is supported.
338
// Usually it will only be available on Linux, excluding
339
// Linux on the Itanium architecture.
340
// Also see http://linux.die.net/man/2/clone.
341
#ifndef GTEST_HAS_CLONE
342
// The user didn't tell us, so we need to figure it out.
344
#if defined(GTEST_OS_LINUX) && !defined(__ia64__)
345
#define GTEST_HAS_CLONE 1
347
#define GTEST_HAS_CLONE 0
348
#endif // defined(GTEST_OS_LINUX) && !defined(__ia64__)
350
#endif // GTEST_HAS_CLONE
352
// Determines whether to support death tests.
353
#if GTEST_HAS_STD_STRING && GTEST_HAS_CLONE
354
#define GTEST_HAS_DEATH_TEST
355
// On some platforms, <regex.h> needs someone to define size_t, and
356
// won't compile otherwise. We can #include it here as we already
357
// included <stdlib.h>, which is guaranteed to define size_t through
362
#include <sys/mman.h>
363
#endif // GTEST_HAS_STD_STRING && GTEST_HAS_CLONE
365
// Determines whether to support value-parameterized tests.
367
#if defined(__GNUC__) || (_MSC_VER >= 1400)
368
// TODO(vladl@google.com): get the implementation rid of vector and list
369
// to compile on MSVC 7.1.
370
#define GTEST_HAS_PARAM_TEST
371
#endif // defined(__GNUC__) || (_MSC_VER >= 1400)
373
// Determines whether to support type-driven tests.
375
// Typed tests need <typeinfo> and variadic macros, which gcc and VC
377
#if defined(__GNUC__) || (_MSC_VER >= 1400)
378
#define GTEST_HAS_TYPED_TEST
379
#define GTEST_HAS_TYPED_TEST_P
380
#endif // defined(__GNUC__) || (_MSC_VER >= 1400)
382
// Determines whether to support Combine(). This only makes sense when
383
// value-parameterized tests are enabled.
384
#if defined(GTEST_HAS_PARAM_TEST) && GTEST_HAS_TR1_TUPLE
385
#define GTEST_HAS_COMBINE
386
#endif // defined(GTEST_HAS_PARAM_TEST) && GTEST_HAS_TR1_TUPLE
388
// Determines whether the system compiler uses UTF-16 for encoding wide strings.
389
#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \
390
defined(GTEST_OS_SYMBIAN)
391
#define GTEST_WIDE_STRING_USES_UTF16_ 1
394
// Defines some utility macros.
396
// The GNU compiler emits a warning if nested "if" statements are followed by
397
// an "else" statement and braces are not used to explicitly disambiguate the
398
// "else" binding. This leads to problems with code like:
401
// ASSERT_*(condition) << "Some message";
403
// The "switch (0) case 0:" idiom is used to suppress this.
404
#ifdef __INTEL_COMPILER
405
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_
407
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: // NOLINT
410
// Use this annotation at the end of a struct / class definition to
411
// prevent the compiler from optimizing away instances that are never
412
// used. This is useful when all interesting logic happens inside the
413
// c'tor and / or d'tor. Example:
417
// } GTEST_ATTRIBUTE_UNUSED_;
418
#if defined(__GNUC__) && !defined(COMPILER_ICC)
419
#define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
421
#define GTEST_ATTRIBUTE_UNUSED_
424
// A macro to disallow the evil copy constructor and operator= functions
425
// This should be used in the private: declarations for a class.
426
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
428
void operator=(const type &)
430
// Tell the compiler to warn about unused return values for functions declared
431
// with this macro. The macro should be used on function declarations
432
// following the argument list:
434
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
435
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
436
#define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
438
#define GTEST_MUST_USE_RESULT_
439
#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
449
// std::strstream is deprecated. However, we have to use it on
450
// Windows as std::stringstream won't compile on Windows when
451
// exceptions are disabled. We use std::stringstream on other
452
// platforms to avoid compiler warnings there.
453
#if GTEST_HAS_STD_STRING
454
typedef ::std::stringstream StrStream;
456
typedef ::std::strstream StrStream;
457
#endif // GTEST_HAS_STD_STRING
459
// Defines scoped_ptr.
461
// This implementation of scoped_ptr is PARTIAL - it only contains
462
// enough stuff to satisfy Google Test's need.
463
template <typename T>
466
explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
467
~scoped_ptr() { reset(); }
469
T& operator*() const { return *ptr_; }
470
T* operator->() const { return ptr_; }
471
T* get() const { return ptr_; }
479
void reset(T* p = NULL) {
481
if (sizeof(T) > 0) { // Makes sure T is a complete type.
490
GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
493
#ifdef GTEST_HAS_DEATH_TEST
497
// A simple C++ wrapper for <regex.h>. It uses the POSIX Enxtended
498
// Regular Expression syntax.
501
// Constructs an RE from a string.
502
#if GTEST_HAS_STD_STRING
503
RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT
504
#endif // GTEST_HAS_STD_STRING
506
#if GTEST_HAS_GLOBAL_STRING
507
RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT
508
#endif // GTEST_HAS_GLOBAL_STRING
510
RE(const char* regex) { Init(regex); } // NOLINT
513
// Returns the string representation of the regex.
514
const char* pattern() const { return pattern_; }
516
// FullMatch(str, re) returns true iff regular expression re matches
518
// PartialMatch(str, re) returns true iff regular expression re
519
// matches a substring of str (including str itself).
521
// TODO(wan@google.com): make FullMatch() and PartialMatch() work
522
// when str contains NUL characters.
523
#if GTEST_HAS_STD_STRING
524
static bool FullMatch(const ::std::string& str, const RE& re) {
525
return FullMatch(str.c_str(), re);
527
static bool PartialMatch(const ::std::string& str, const RE& re) {
528
return PartialMatch(str.c_str(), re);
530
#endif // GTEST_HAS_STD_STRING
532
#if GTEST_HAS_GLOBAL_STRING
533
static bool FullMatch(const ::string& str, const RE& re) {
534
return FullMatch(str.c_str(), re);
536
static bool PartialMatch(const ::string& str, const RE& re) {
537
return PartialMatch(str.c_str(), re);
539
#endif // GTEST_HAS_GLOBAL_STRING
541
static bool FullMatch(const char* str, const RE& re);
542
static bool PartialMatch(const char* str, const RE& re);
545
void Init(const char* regex);
547
// We use a const char* instead of a string, as Google Test may be used
548
// where string is not available. We also do not use Google Test's own
549
// String type here, in order to simplify dependencies between the
551
const char* pattern_;
552
regex_t full_regex_; // For FullMatch().
553
regex_t partial_regex_; // For PartialMatch().
557
#endif // GTEST_HAS_DEATH_TEST
559
// Defines logging utilities:
560
// GTEST_LOG_() - logs messages at the specified severity level.
561
// LogToStderr() - directs all log messages to stderr.
562
// FlushInfoLog() - flushes informational log messages.
564
enum GTestLogSeverity {
571
void GTestLog(GTestLogSeverity severity, const char* file,
572
int line, const char* msg);
574
#define GTEST_LOG_(severity, msg)\
575
::testing::internal::GTestLog(\
576
::testing::internal::GTEST_##severity, __FILE__, __LINE__, \
577
(::testing::Message() << (msg)).GetString().c_str())
579
inline void LogToStderr() {}
580
inline void FlushInfoLog() { fflush(NULL); }
582
// Defines the stderr capturer:
583
// CaptureStderr - starts capturing stderr.
584
// GetCapturedStderr - stops capturing stderr and returns the captured string.
586
#ifdef GTEST_HAS_DEATH_TEST
588
// A copy of all command line arguments. Set by InitGoogleTest().
589
extern ::std::vector<String> g_argvs;
591
void CaptureStderr();
592
// GTEST_HAS_DEATH_TEST implies we have ::std::string.
593
::std::string GetCapturedStderr();
594
const ::std::vector<String>& GetArgvs();
596
#endif // GTEST_HAS_DEATH_TEST
598
// Defines synchronization primitives.
600
// A dummy implementation of synchronization primitives (mutex, lock,
601
// and thread-local variable). Necessary for compiling Google Test where
602
// mutex is not supported - using Google Test in multiple threads is not
603
// supported on such platforms.
608
explicit Mutex(int /*unused*/) {}
609
void AssertHeld() const {}
610
enum { NO_CONSTRUCTOR_NEEDED_FOR_STATIC_MUTEX = 0 };
613
// We cannot call it MutexLock directly as the ctor declaration would
614
// conflict with a macro named MutexLock, which is defined on some
615
// platforms. Hence the typedef trick below.
616
class GTestMutexLock {
618
explicit GTestMutexLock(Mutex*) {} // NOLINT
621
typedef GTestMutexLock MutexLock;
623
template <typename T>
626
ThreadLocal() : value_() {}
627
explicit ThreadLocal(const T& value) : value_(value) {}
628
T* pointer() { return &value_; }
629
const T* pointer() const { return &value_; }
630
const T& get() const { return value_; }
631
void set(const T& value) { value_ = value; }
636
// There's no portable way to detect the number of threads, so we just
637
// return 0 to indicate that we cannot detect it.
638
inline size_t GetThreadCount() { return 0; }
640
// The above synchronization primitives have dummy implementations.
641
// Therefore Google Test is not thread-safe.
642
#define GTEST_IS_THREADSAFE 0
644
#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
646
// Passing non-POD classes through ellipsis (...) crashes the ARM
647
// compiler. The Nokia Symbian and the IBM XL C/C++ compiler try to
648
// instantiate a copy constructor for objects passed through ellipsis
649
// (...), failing for uncopyable objects. We define this to indicate
651
#define GTEST_ELLIPSIS_NEEDS_COPY_ 1
653
// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
654
// const T& and const T* in a function template. These compilers
655
// _can_ decide between class template specializations for T and T*,
656
// so a tr1::type_traits-like is_pointer works.
657
#define GTEST_NEEDS_IS_POINTER_ 1
659
#endif // defined(__SYMBIAN32__) || defined(__IBMCPP__)
661
template <bool bool_value>
662
struct bool_constant {
663
typedef bool_constant<bool_value> type;
664
static const bool value = bool_value;
666
template <bool bool_value> const bool bool_constant<bool_value>::value;
668
typedef bool_constant<false> false_type;
669
typedef bool_constant<true> true_type;
671
template <typename T>
672
struct is_pointer : public false_type {};
674
template <typename T>
675
struct is_pointer<T*> : public true_type {};
677
// Defines BiggestInt as the biggest signed integer type the compiler
680
#ifdef GTEST_OS_WINDOWS
681
typedef __int64 BiggestInt;
683
typedef long long BiggestInt; // NOLINT
684
#endif // GTEST_OS_WINDOWS
686
// The maximum number a BiggestInt can represent. This definition
687
// works no matter BiggestInt is represented in one's complement or
690
// We cannot rely on numeric_limits in STL, as __int64 and long long
691
// are not part of standard C++ and numeric_limits doesn't need to be
693
const BiggestInt kMaxBiggestInt =
694
~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
696
// This template class serves as a compile-time function from size to
697
// type. It maps a size in bytes to a primitive type with that
700
// TypeWithSize<4>::UInt
702
// is typedef-ed to be unsigned int (unsigned integer made up of 4
705
// Such functionality should belong to STL, but I cannot find it
708
// Google Test uses this class in the implementation of floating-point
711
// For now it only handles UInt (unsigned int) as that's all Google Test
712
// needs. Other types can be easily added in the future if need
714
template <size_t size>
717
// This prevents the user from using TypeWithSize<N> with incorrect
722
// The specialization for size 4.
724
class TypeWithSize<4> {
726
// unsigned int has size 4 in both gcc and MSVC.
728
// As base/basictypes.h doesn't compile on Windows, we cannot use
729
// uint32, uint64, and etc here.
731
typedef unsigned int UInt;
734
// The specialization for size 8.
736
class TypeWithSize<8> {
738
#ifdef GTEST_OS_WINDOWS
740
typedef unsigned __int64 UInt;
742
typedef long long Int; // NOLINT
743
typedef unsigned long long UInt; // NOLINT
744
#endif // GTEST_OS_WINDOWS
747
// Integer types of known sizes.
748
typedef TypeWithSize<4>::Int Int32;
749
typedef TypeWithSize<4>::UInt UInt32;
750
typedef TypeWithSize<8>::Int Int64;
751
typedef TypeWithSize<8>::UInt UInt64;
752
typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
754
// Utilities for command line flags and environment variables.
756
// A wrapper for getenv() that works on Linux, Windows, and Mac OS.
757
inline const char* GetEnv(const char* name) {
758
#ifdef _WIN32_WCE // We are on Windows CE.
759
// CE has no environment variables.
761
#elif defined(GTEST_OS_WINDOWS) // We are on Windows proper.
762
// MSVC 8 deprecates getenv(), so we want to suppress warning 4996
763
// (deprecated function) there.
764
#pragma warning(push) // Saves the current warning state.
765
#pragma warning(disable:4996) // Temporarily disables warning 4996.
767
#pragma warning(pop) // Restores the warning state.
768
#else // We are on Linux or Mac OS.
774
// Windows CE has no C library. The abort() function is used in
775
// several places in Google Test. This implementation provides a reasonable
776
// imitation of standard behaviour.
779
inline void abort() { ::abort(); }
782
// INTERNAL IMPLEMENTATION - DO NOT USE.
784
// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
787
// GTEST_CHECK_(boolean_condition);
789
// GTEST_CHECK_(boolean_condition) << "Additional message";
791
// This checks the condition and if the condition is not satisfied
792
// it prints message about the condition violation, including the
793
// condition itself, plus additional message streamed into it, if any,
794
// and then it aborts the program. It aborts the program irrespective of
795
// whether it is built in the debug mode or not.
796
class GTestCheckProvider {
798
GTestCheckProvider(const char* condition, const char* file, int line) {
799
FormatFileLocation(file, line);
800
::std::cerr << " ERROR: Condition " << condition << " failed. ";
802
~GTestCheckProvider() {
803
::std::cerr << ::std::endl;
806
void FormatFileLocation(const char* file, int line) {
808
file = "unknown file";
810
::std::cerr << file << ":";
813
::std::cerr << file << "(" << line << "):";
815
::std::cerr << file << ":" << line << ":";
819
::std::ostream& GetStream() { return ::std::cerr; }
821
#define GTEST_CHECK_(condition) \
822
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
826
::testing::internal::GTestCheckProvider(\
827
#condition, __FILE__, __LINE__).GetStream()
829
// Macro for referencing flags.
830
#define GTEST_FLAG(name) FLAGS_gtest_##name
832
// Macros for declaring flags.
833
#define GTEST_DECLARE_bool_(name) extern bool GTEST_FLAG(name)
834
#define GTEST_DECLARE_int32_(name) \
835
extern ::testing::internal::Int32 GTEST_FLAG(name)
836
#define GTEST_DECLARE_string_(name) \
837
extern ::testing::internal::String GTEST_FLAG(name)
839
// Macros for defining flags.
840
#define GTEST_DEFINE_bool_(name, default_val, doc) \
841
bool GTEST_FLAG(name) = (default_val)
842
#define GTEST_DEFINE_int32_(name, default_val, doc) \
843
::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
844
#define GTEST_DEFINE_string_(name, default_val, doc) \
845
::testing::internal::String GTEST_FLAG(name) = (default_val)
847
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
848
// to *value and returns true; otherwise leaves *value unchanged and returns
850
// TODO(chandlerc): Find a better way to refactor flag and environment parsing
851
// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
853
bool ParseInt32(const Message& src_text, const char* str, Int32* value);
855
// Parses a bool/Int32/string from the environment variable
856
// corresponding to the given Google Test flag.
857
bool BoolFromGTestEnv(const char* flag, bool default_val);
858
Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
859
const char* StringFromGTestEnv(const char* flag, const char* default_val);
861
} // namespace internal
862
} // namespace testing
864
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_