40 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ 41 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ 202 # include <sys/types.h> 203 # include <sys/stat.h> 204 #endif // !_WIN32_WCE 206 #if defined __APPLE__ 207 # include <AvailabilityMacros.h> 208 # include <TargetConditionals.h> 215 #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" 216 #define GTEST_FLAG_PREFIX_ "gtest_" 217 #define GTEST_FLAG_PREFIX_DASH_ "gtest-" 218 #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" 219 #define GTEST_NAME_ "Google Test" 220 #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/" 225 # define GTEST_GCC_VER_ \ 226 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) 231 # define GTEST_OS_CYGWIN 1 232 #elif defined __SYMBIAN32__ 233 # define GTEST_OS_SYMBIAN 1 235 # define GTEST_OS_WINDOWS 1 237 # define GTEST_OS_WINDOWS_MOBILE 1 238 # elif defined(__MINGW__) || defined(__MINGW32__) 239 # define GTEST_OS_WINDOWS_MINGW 1 241 # define GTEST_OS_WINDOWS_DESKTOP 1 242 # endif // _WIN32_WCE 243 #elif defined __APPLE__ 244 # define GTEST_OS_MAC 1 245 # if TARGET_OS_IPHONE 246 # define GTEST_OS_IOS 1 247 # if TARGET_IPHONE_SIMULATOR 248 # define GTEST_OS_IOS_SIMULATOR 1 251 #elif defined __linux__ 252 # define GTEST_OS_LINUX 1 253 # if defined __ANDROID__ 254 # define GTEST_OS_LINUX_ANDROID 1 256 #elif defined __MVS__ 257 # define GTEST_OS_ZOS 1 258 #elif defined(__sun) && defined(__SVR4) 259 # define GTEST_OS_SOLARIS 1 261 # define GTEST_OS_AIX 1 262 #elif defined(__hpux) 263 # define GTEST_OS_HPUX 1 264 #elif defined __native_client__ 265 # define GTEST_OS_NACL 1 266 #elif defined __OpenBSD__ 267 # define GTEST_OS_OPENBSD 1 268 #elif defined __QNX__ 269 # define GTEST_OS_QNX 1 272 #ifndef GTEST_LANG_CXX11 277 # if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L 279 # define GTEST_LANG_CXX11 1 281 # define GTEST_LANG_CXX11 0 288 #if !GTEST_OS_WINDOWS 293 # include <strings.h> 294 #elif !GTEST_OS_WINDOWS_MOBILE 299 #if GTEST_OS_LINUX_ANDROID 301 # include <android/api-level.h> 305 #ifndef GTEST_HAS_POSIX_RE 306 # if GTEST_OS_LINUX_ANDROID 308 # define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) 310 # define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS) 314 #if GTEST_HAS_POSIX_RE 322 # define GTEST_USES_POSIX_RE 1 324 #elif GTEST_OS_WINDOWS 328 # define GTEST_USES_SIMPLE_RE 1 334 # define GTEST_USES_SIMPLE_RE 1 336 #endif // GTEST_HAS_POSIX_RE 338 #ifndef GTEST_HAS_EXCEPTIONS 341 # if defined(_MSC_VER) || defined(__BORLANDC__) 345 # ifndef _HAS_EXCEPTIONS 346 # define _HAS_EXCEPTIONS 1 347 # endif // _HAS_EXCEPTIONS 348 # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS 349 # elif defined(__GNUC__) && __EXCEPTIONS 351 # define GTEST_HAS_EXCEPTIONS 1 352 # elif defined(__SUNPRO_CC) 356 # define GTEST_HAS_EXCEPTIONS 1 357 # elif defined(__IBMCPP__) && __EXCEPTIONS 359 # define GTEST_HAS_EXCEPTIONS 1 360 # elif defined(__HP_aCC) 363 # define GTEST_HAS_EXCEPTIONS 1 367 # define GTEST_HAS_EXCEPTIONS 0 368 # endif // defined(_MSC_VER) || defined(__BORLANDC__) 369 #endif // GTEST_HAS_EXCEPTIONS 371 #if !defined(GTEST_HAS_STD_STRING) 374 # define GTEST_HAS_STD_STRING 1 375 #elif !GTEST_HAS_STD_STRING 377 # error "Google Test cannot be used where ::std::string isn't available." 378 #endif // !defined(GTEST_HAS_STD_STRING) 380 #ifndef GTEST_HAS_GLOBAL_STRING 384 # define GTEST_HAS_GLOBAL_STRING 0 386 #endif // GTEST_HAS_GLOBAL_STRING 388 #ifndef GTEST_HAS_STD_WSTRING 397 # define GTEST_HAS_STD_WSTRING \ 398 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS)) 400 #endif // GTEST_HAS_STD_WSTRING 402 #ifndef GTEST_HAS_GLOBAL_WSTRING 405 # define GTEST_HAS_GLOBAL_WSTRING \ 406 (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING) 407 #endif // GTEST_HAS_GLOBAL_WSTRING 410 #ifndef GTEST_HAS_RTTI 416 # ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. 417 # define GTEST_HAS_RTTI 1 419 # define GTEST_HAS_RTTI 0 423 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302) 430 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \ 431 !defined(__EXCEPTIONS) 432 # define GTEST_HAS_RTTI 0 434 # define GTEST_HAS_RTTI 1 435 # endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS 437 # define GTEST_HAS_RTTI 0 438 # endif // __GXX_RTTI 443 # elif defined(__clang__) 445 # define GTEST_HAS_RTTI __has_feature(cxx_rtti) 449 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) 452 # define GTEST_HAS_RTTI 1 454 # define GTEST_HAS_RTTI 0 460 # define GTEST_HAS_RTTI 1 464 #endif // GTEST_HAS_RTTI 473 #ifndef GTEST_HAS_PTHREAD 479 # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \ 481 #endif // GTEST_HAS_PTHREAD 483 #if GTEST_HAS_PTHREAD 486 # include <pthread.h> 495 #ifndef GTEST_HAS_TR1_TUPLE 496 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) 498 # define GTEST_HAS_TR1_TUPLE 0 501 # define GTEST_HAS_TR1_TUPLE 1 503 #endif // GTEST_HAS_TR1_TUPLE 507 #ifndef GTEST_USE_OWN_TR1_TUPLE 520 # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \ 521 && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600 522 # define GTEST_ENV_HAS_TR1_TUPLE_ 1 528 # if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325) 529 # define GTEST_ENV_HAS_STD_TUPLE_ 1 532 # if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_ 533 # define GTEST_USE_OWN_TR1_TUPLE 0 535 # define GTEST_USE_OWN_TR1_TUPLE 1 538 #endif // GTEST_USE_OWN_TR1_TUPLE 543 #if GTEST_HAS_TR1_TUPLE 545 # if GTEST_USE_OWN_TR1_TUPLE 546 # include "gtest/internal/gtest-tuple.h" 547 # elif GTEST_ENV_HAS_STD_TUPLE_ 556 using ::std::make_tuple;
558 using ::std::tuple_element;
559 using ::std::tuple_size;
563 # elif GTEST_OS_SYMBIAN 570 # ifdef BOOST_HAS_TR1_TUPLE 571 # undef BOOST_HAS_TR1_TUPLE 572 # endif // BOOST_HAS_TR1_TUPLE 576 # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED 579 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) 583 # if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 589 # define _TR1_FUNCTIONAL 1 590 # include <tr1/tuple> 591 # undef _TR1_FUNCTIONAL // Allows the user to #include 594 # include <tr1/tuple> 595 # endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 601 # endif // GTEST_USE_OWN_TR1_TUPLE 603 #endif // GTEST_HAS_TR1_TUPLE 609 #ifndef GTEST_HAS_CLONE 612 # if GTEST_OS_LINUX && !defined(__ia64__) 613 # if GTEST_OS_LINUX_ANDROID 615 # if defined(__arm__) && __ANDROID_API__ >= 9 616 # define GTEST_HAS_CLONE 1 618 # define GTEST_HAS_CLONE 0 621 # define GTEST_HAS_CLONE 1 624 # define GTEST_HAS_CLONE 0 625 # endif // GTEST_OS_LINUX && !defined(__ia64__) 627 #endif // GTEST_HAS_CLONE 631 #ifndef GTEST_HAS_STREAM_REDIRECTION 634 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN 635 # define GTEST_HAS_STREAM_REDIRECTION 0 637 # define GTEST_HAS_STREAM_REDIRECTION 1 638 # endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN 639 #endif // GTEST_HAS_STREAM_REDIRECTION 645 #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ 646 (GTEST_OS_MAC && !GTEST_OS_IOS) || GTEST_OS_IOS_SIMULATOR || \ 647 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ 648 GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \ 649 GTEST_OS_OPENBSD || GTEST_OS_QNX) 650 # define GTEST_HAS_DEATH_TEST 1 657 #define GTEST_HAS_PARAM_TEST 1 663 #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \ 664 defined(__IBMCPP__) || defined(__HP_aCC) 665 # define GTEST_HAS_TYPED_TEST 1 666 # define GTEST_HAS_TYPED_TEST_P 1 673 #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC) 674 # define GTEST_HAS_COMBINE 1 678 #define GTEST_WIDE_STRING_USES_UTF16_ \ 679 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX) 683 # define GTEST_CAN_STREAM_RESULTS_ 1 696 #ifdef __INTEL_COMPILER 697 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ 699 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT 713 #if defined(__GNUC__) && !defined(COMPILER_ICC) 714 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) 716 # define GTEST_ATTRIBUTE_UNUSED_ 721 #define GTEST_DISALLOW_ASSIGN_(type)\ 722 void operator=(type const &) 726 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\ 728 GTEST_DISALLOW_ASSIGN_(type) 735 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC) 736 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) 738 # define GTEST_MUST_USE_RESULT_ 739 #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC 744 #ifndef GTEST_HAS_SEH 747 # if defined(_MSC_VER) || defined(__BORLANDC__) 749 # define GTEST_HAS_SEH 1 752 # define GTEST_HAS_SEH 0 755 #endif // GTEST_HAS_SEH 759 # if GTEST_LINKED_AS_SHARED_LIBRARY 760 # define GTEST_API_ __declspec(dllimport) 761 # elif GTEST_CREATE_SHARED_LIBRARY 762 # define GTEST_API_ __declspec(dllexport) 773 # define GTEST_NO_INLINE_ __attribute__((noinline)) 775 # define GTEST_NO_INLINE_ 779 #if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) 780 # define GTEST_HAS_CXXABI_H_ 1 782 # define GTEST_HAS_CXXABI_H_ 0 812 struct CompileAssert {
815 #define GTEST_COMPILE_ASSERT_(expr, msg) \ 816 typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \ 817 msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_ 863 template <
typename T1,
typename T2>
864 struct StaticAssertTypeEqHelper;
866 template <
typename T>
867 struct StaticAssertTypeEqHelper<
T,
T> {};
869 #if GTEST_HAS_GLOBAL_STRING 870 typedef ::string string;
872 typedef ::std::string string;
873 #endif // GTEST_HAS_GLOBAL_STRING 875 #if GTEST_HAS_GLOBAL_WSTRING 876 typedef ::wstring wstring;
877 #elif GTEST_HAS_STD_WSTRING 878 typedef ::std::wstring wstring;
879 #endif // GTEST_HAS_GLOBAL_WSTRING 883 GTEST_API_
bool IsTrue(
bool condition);
889 template <
typename T>
892 typedef T element_type;
894 explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
895 ~scoped_ptr() { reset(); }
898 T* operator->()
const {
return ptr_; }
899 T*
get()
const {
return ptr_; }
907 void reset(T* p = NULL) {
909 if (IsTrue(
sizeof(T) > 0)) {
919 GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
926 class GTEST_API_ RE {
930 RE(
const RE& other) { Init(other.pattern()); }
933 RE(const ::std::string& regex) { Init(regex.c_str()); }
935 #if GTEST_HAS_GLOBAL_STRING 937 RE(const ::string& regex) { Init(regex.c_str()); }
939 #endif // GTEST_HAS_GLOBAL_STRING 941 RE(
const char* regex) { Init(regex); }
945 const char* pattern()
const {
return pattern_; }
954 static bool FullMatch(const ::std::string& str,
const RE& re) {
955 return FullMatch(str.c_str(), re);
957 static bool PartialMatch(const ::std::string& str,
const RE& re) {
958 return PartialMatch(str.c_str(), re);
961 #if GTEST_HAS_GLOBAL_STRING 963 static bool FullMatch(const ::string& str,
const RE& re) {
964 return FullMatch(str.c_str(), re);
966 static bool PartialMatch(const ::string& str,
const RE& re) {
967 return PartialMatch(str.c_str(), re);
970 #endif // GTEST_HAS_GLOBAL_STRING 972 static bool FullMatch(
const char* str,
const RE& re);
973 static bool PartialMatch(
const char* str,
const RE& re);
976 void Init(
const char* regex);
981 const char* pattern_;
984 #if GTEST_USES_POSIX_RE 987 regex_t partial_regex_;
989 #else // GTEST_USES_SIMPLE_RE 991 const char* full_pattern_;
995 GTEST_DISALLOW_ASSIGN_(RE);
1000 GTEST_API_ ::std::string FormatFileLocation(
const char* file,
int line);
1005 GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
const char* file,
1014 enum GTestLogSeverity {
1024 class GTEST_API_ GTestLog {
1026 GTestLog(GTestLogSeverity severity,
const char* file,
int line);
1031 ::std::ostream& GetStream() { return ::std::cerr; }
1034 const GTestLogSeverity severity_;
1036 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
1039 #define GTEST_LOG_(severity) \ 1040 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ 1041 __FILE__, __LINE__).GetStream() 1043 inline void LogToStderr() {}
1044 inline void FlushInfoLog() { fflush(NULL); }
1060 #define GTEST_CHECK_(condition) \ 1061 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1062 if (::testing::internal::IsTrue(condition)) \ 1065 GTEST_LOG_(FATAL) << "Condition " #condition " failed. " 1072 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ 1073 if (const int gtest_error = (posix_call)) \ 1074 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ 1097 template<
typename To>
1098 inline To ImplicitCast_(To x) {
return x; }
1121 template<
typename To,
typename From>
1122 inline To DownCast_(From* f) {
1129 ::testing::internal::ImplicitCast_<From*>(to);
1134 GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
1136 return static_cast<To
>(f);
1144 template <
class Derived,
class Base>
1145 Derived* CheckedDowncastToActualType(
Base* base) {
1147 GTEST_CHECK_(
typeid(*base) ==
typeid(Derived));
1148 return dynamic_cast<Derived*
>(base);
1150 return static_cast<Derived*
>(base);
1154 #if GTEST_HAS_STREAM_REDIRECTION 1162 GTEST_API_
void CaptureStdout();
1163 GTEST_API_ std::string GetCapturedStdout();
1164 GTEST_API_
void CaptureStderr();
1165 GTEST_API_ std::string GetCapturedStderr();
1167 #endif // GTEST_HAS_STREAM_REDIRECTION 1170 #if GTEST_HAS_DEATH_TEST 1172 const ::std::vector<testing::internal::string>& GetInjectableArgvs();
1173 void SetInjectableArgvs(const ::std::vector<testing::internal::string>*
1177 extern ::std::vector<testing::internal::string> g_argvs;
1179 #endif // GTEST_HAS_DEATH_TEST 1183 #if GTEST_HAS_PTHREAD 1188 inline void SleepMilliseconds(
int n) {
1189 const timespec time = {
1193 nanosleep(&time, NULL);
1202 class Notification {
1204 Notification() : notified_(false) {
1205 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
1208 pthread_mutex_destroy(&mutex_);
1214 pthread_mutex_lock(&mutex_);
1216 pthread_mutex_unlock(&mutex_);
1221 void WaitForNotification() {
1223 pthread_mutex_lock(&mutex_);
1224 const bool notified = notified_;
1225 pthread_mutex_unlock(&mutex_);
1228 SleepMilliseconds(10);
1233 pthread_mutex_t mutex_;
1236 GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
1244 class ThreadWithParamBase {
1246 virtual ~ThreadWithParamBase() {}
1247 virtual void Run() = 0;
1256 extern "C" inline void* ThreadFuncWithCLinkage(
void* thread) {
1257 static_cast<ThreadWithParamBase*
>(thread)->Run();
1273 template <
typename T>
1274 class ThreadWithParam :
public ThreadWithParamBase {
1276 typedef void (*UserThreadFunc)(T);
1279 UserThreadFunc
func, T param, Notification* thread_can_start)
1282 thread_can_start_(thread_can_start),
1284 ThreadWithParamBase*
const base =
this;
1287 GTEST_CHECK_POSIX_SUCCESS_(
1288 pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
1290 ~ThreadWithParam() { Join(); }
1294 GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
1299 virtual void Run() {
1300 if (thread_can_start_ != NULL)
1301 thread_can_start_->WaitForNotification();
1306 const UserThreadFunc func_;
1310 Notification*
const thread_can_start_;
1314 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
1340 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
1341 owner_ = pthread_self();
1352 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
1357 void AssertHeld()
const {
1358 GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
1359 <<
"The current thread is not holding the mutex @" <<
this;
1368 pthread_mutex_t mutex_;
1380 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ 1381 extern ::testing::internal::MutexBase mutex 1389 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ 1390 ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false } 1394 class Mutex :
public MutexBase {
1397 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
1401 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
1405 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
1411 class GTestMutexLock {
1413 explicit GTestMutexLock(MutexBase* mutex)
1414 : mutex_(mutex) { mutex_->Lock(); }
1416 ~GTestMutexLock() { mutex_->Unlock(); }
1419 MutexBase*
const mutex_;
1421 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
1424 typedef GTestMutexLock MutexLock;
1432 class ThreadLocalValueHolderBase {
1434 virtual ~ThreadLocalValueHolderBase() {}
1439 extern "C" inline void DeleteThreadLocalValue(
void* value_holder) {
1440 delete static_cast<ThreadLocalValueHolderBase*
>(value_holder);
1472 template <
typename T>
1475 ThreadLocal() : key_(CreateKey()),
1477 explicit ThreadLocal(
const T& value) : key_(CreateKey()),
1482 DeleteThreadLocalValue(pthread_getspecific(key_));
1486 GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
1489 T* pointer() {
return GetOrCreateValue(); }
1490 const T* pointer()
const {
return GetOrCreateValue(); }
1491 const T&
get()
const {
return *pointer(); }
1492 void set(
const T& value) { *pointer() = value; }
1496 class ValueHolder :
public ThreadLocalValueHolderBase {
1498 explicit ValueHolder(
const T& value) : value_(value) {}
1500 T* pointer() {
return &value_; }
1504 GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
1507 static pthread_key_t CreateKey() {
1511 GTEST_CHECK_POSIX_SUCCESS_(
1512 pthread_key_create(&key, &DeleteThreadLocalValue));
1516 T* GetOrCreateValue()
const {
1517 ThreadLocalValueHolderBase*
const holder =
1518 static_cast<ThreadLocalValueHolderBase*
>(pthread_getspecific(key_));
1519 if (holder != NULL) {
1520 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
1523 ValueHolder*
const new_holder =
new ValueHolder(default_);
1524 ThreadLocalValueHolderBase*
const holder_base = new_holder;
1525 GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
1526 return new_holder->pointer();
1530 const pthread_key_t key_;
1533 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
1536 # define GTEST_IS_THREADSAFE 1 1538 #else // GTEST_HAS_PTHREAD 1550 void AssertHeld()
const {}
1553 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ 1554 extern ::testing::internal::Mutex mutex 1556 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex 1558 class GTestMutexLock {
1560 explicit GTestMutexLock(Mutex*) {}
1563 typedef GTestMutexLock MutexLock;
1565 template <
typename T>
1568 ThreadLocal() : value_() {}
1569 explicit ThreadLocal(
const T& value) : value_(value) {}
1570 T* pointer() {
return &value_; }
1571 const T* pointer()
const {
return &value_; }
1572 const T&
get()
const {
return value_; }
1573 void set(
const T& value) { value_ = value; }
1580 # define GTEST_IS_THREADSAFE 0 1582 #endif // GTEST_HAS_PTHREAD 1586 GTEST_API_
size_t GetThreadCount();
1594 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) 1597 # define GTEST_ELLIPSIS_NEEDS_POD_ 1 1599 # define GTEST_CAN_COMPARE_NULL 1 1606 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) 1607 # define GTEST_NEEDS_IS_POINTER_ 1 1610 template <
bool bool_value>
1611 struct bool_constant {
1612 typedef bool_constant<bool_value> type;
1613 static const bool value = bool_value;
1615 template <
bool bool_value>
const bool bool_constant<bool_value>::value;
1617 typedef bool_constant<false> false_type;
1618 typedef bool_constant<true> true_type;
1620 template <
typename T>
1621 struct is_pointer :
public false_type {};
1623 template <
typename T>
1624 struct is_pointer<T*> :
public true_type {};
1626 template <
typename Iterator>
1627 struct IteratorTraits {
1628 typedef typename Iterator::value_type value_type;
1631 template <
typename T>
1632 struct IteratorTraits<T*> {
1633 typedef T value_type;
1636 template <
typename T>
1637 struct IteratorTraits<const T*> {
1638 typedef T value_type;
1641 #if GTEST_OS_WINDOWS 1642 # define GTEST_PATH_SEP_ "\\" 1643 # define GTEST_HAS_ALT_PATH_SEP_ 1 1645 typedef __int64 BiggestInt;
1647 # define GTEST_PATH_SEP_ "/" 1648 # define GTEST_HAS_ALT_PATH_SEP_ 0 1649 typedef long long BiggestInt;
1650 #endif // GTEST_OS_WINDOWS 1659 inline bool IsAlpha(
char ch) {
1660 return isalpha(static_cast<unsigned char>(ch)) != 0;
1662 inline bool IsAlNum(
char ch) {
1663 return isalnum(static_cast<unsigned char>(ch)) != 0;
1665 inline bool IsDigit(
char ch) {
1666 return isdigit(static_cast<unsigned char>(ch)) != 0;
1668 inline bool IsLower(
char ch) {
1669 return islower(static_cast<unsigned char>(ch)) != 0;
1671 inline bool IsSpace(
char ch) {
1672 return isspace(static_cast<unsigned char>(ch)) != 0;
1674 inline bool IsUpper(
char ch) {
1675 return isupper(static_cast<unsigned char>(ch)) != 0;
1677 inline bool IsXDigit(
char ch) {
1678 return isxdigit(static_cast<unsigned char>(ch)) != 0;
1680 inline bool IsXDigit(
wchar_t ch) {
1681 const unsigned char low_byte =
static_cast<unsigned char>(ch);
1682 return ch == low_byte && isxdigit(low_byte) != 0;
1685 inline char ToLower(
char ch) {
1686 return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
1688 inline char ToUpper(
char ch) {
1689 return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
1702 #if GTEST_OS_WINDOWS 1704 typedef struct _stat StatStruct;
1706 # ifdef __BORLANDC__ 1707 inline int IsATTY(
int fd) {
return isatty(fd); }
1708 inline int StrCaseCmp(
const char* s1,
const char* s2) {
1709 return stricmp(s1, s2);
1711 inline char* StrDup(
const char* src) {
return strdup(src); }
1712 # else // !__BORLANDC__ 1713 # if GTEST_OS_WINDOWS_MOBILE 1714 inline int IsATTY(
int ) {
return 0; }
1716 inline int IsATTY(
int fd) {
return _isatty(fd); }
1717 # endif // GTEST_OS_WINDOWS_MOBILE 1718 inline int StrCaseCmp(
const char* s1,
const char* s2) {
1719 return _stricmp(s1, s2);
1721 inline char* StrDup(
const char* src) {
return _strdup(src); }
1722 # endif // __BORLANDC__ 1724 # if GTEST_OS_WINDOWS_MOBILE 1725 inline int FileNo(FILE* file) {
return reinterpret_cast<int>(_fileno(file)); }
1729 inline int FileNo(FILE* file) {
return _fileno(file); }
1730 inline int Stat(
const char* path, StatStruct* buf) {
return _stat(path, buf); }
1731 inline int RmDir(
const char* dir) {
return _rmdir(dir); }
1732 inline bool IsDir(
const StatStruct& st) {
1733 return (_S_IFDIR & st.st_mode) != 0;
1735 # endif // GTEST_OS_WINDOWS_MOBILE 1739 typedef struct stat StatStruct;
1741 inline int FileNo(FILE* file) {
return fileno(file); }
1742 inline int IsATTY(
int fd) {
return isatty(fd); }
1743 inline int Stat(
const char* path, StatStruct* buf) {
return stat(path, buf); }
1744 inline int StrCaseCmp(
const char* s1,
const char* s2) {
1745 return strcasecmp(s1, s2);
1747 inline char* StrDup(
const char* src) {
return strdup(src); }
1748 inline int RmDir(
const char* dir) {
return rmdir(dir); }
1749 inline bool IsDir(
const StatStruct& st) {
return S_ISDIR(st.st_mode); }
1751 #endif // GTEST_OS_WINDOWS 1757 # pragma warning(push) 1758 # pragma warning(disable:4996) 1761 inline const char* StrNCpy(
char* dest,
const char* src,
size_t n) {
1762 return strncpy(dest, src, n);
1769 #if !GTEST_OS_WINDOWS_MOBILE 1770 inline int ChDir(
const char* dir) {
return chdir(dir); }
1772 inline FILE* FOpen(
const char* path,
const char* mode) {
1773 return fopen(path, mode);
1775 #if !GTEST_OS_WINDOWS_MOBILE 1776 inline FILE *FReopen(
const char* path,
const char* mode, FILE* stream) {
1777 return freopen(path, mode, stream);
1779 inline FILE* FDOpen(
int fd,
const char* mode) {
return fdopen(fd, mode); }
1781 inline int FClose(FILE* fp) {
return fclose(fp); }
1782 #if !GTEST_OS_WINDOWS_MOBILE 1783 inline int Read(
int fd,
void* buf,
unsigned int count) {
1784 return static_cast<int>(read(fd, buf, count));
1786 inline int Write(
int fd,
const void* buf,
unsigned int count) {
1787 return static_cast<int>(write(fd, buf, count));
1789 inline int Close(
int fd) {
return close(fd); }
1790 inline const char* StrError(
int errnum) {
return strerror(errnum); }
1792 inline const char* GetEnv(
const char* name) {
1793 #if GTEST_OS_WINDOWS_MOBILE 1796 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) 1799 const char*
const env = getenv(name);
1800 return (env != NULL && env[0] !=
'\0') ? env : NULL;
1802 return getenv(name);
1807 # pragma warning(pop) // Restores the warning state. 1810 #if GTEST_OS_WINDOWS_MOBILE 1816 inline void Abort() { abort(); }
1817 #endif // GTEST_OS_WINDOWS_MOBILE 1826 #if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE 1828 # define GTEST_SNPRINTF_(buffer, size, format, ...) \ 1829 _snprintf_s(buffer, size, size, format, __VA_ARGS__) 1830 #elif defined(_MSC_VER) 1833 # define GTEST_SNPRINTF_ _snprintf 1835 # define GTEST_SNPRINTF_ snprintf 1845 const BiggestInt kMaxBiggestInt =
1846 ~(
static_cast<BiggestInt
>(1) << (8*
sizeof(BiggestInt) - 1));
1866 template <
size_t size>
1867 class TypeWithSize {
1876 class TypeWithSize<4> {
1883 typedef unsigned int UInt;
1888 class TypeWithSize<8> {
1890 #if GTEST_OS_WINDOWS 1891 typedef __int64 Int;
1892 typedef unsigned __int64 UInt;
1894 typedef long long Int;
1895 typedef unsigned long long UInt;
1896 #endif // GTEST_OS_WINDOWS 1900 typedef TypeWithSize<4>::Int Int32;
1901 typedef TypeWithSize<4>::UInt UInt32;
1902 typedef TypeWithSize<8>::Int Int64;
1903 typedef TypeWithSize<8>::UInt UInt64;
1904 typedef TypeWithSize<8>::Int TimeInMillis;
1909 #define GTEST_FLAG(name) FLAGS_gtest_##name 1912 #define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) 1913 #define GTEST_DECLARE_int32_(name) \ 1914 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name) 1915 #define GTEST_DECLARE_string_(name) \ 1916 GTEST_API_ extern ::std::string GTEST_FLAG(name) 1919 #define GTEST_DEFINE_bool_(name, default_val, doc) \ 1920 GTEST_API_ bool GTEST_FLAG(name) = (default_val) 1921 #define GTEST_DEFINE_int32_(name, default_val, doc) \ 1922 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) 1923 #define GTEST_DEFINE_string_(name, default_val, doc) \ 1924 GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) 1927 #define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) 1928 #define GTEST_LOCK_EXCLUDED_(locks) 1936 bool ParseInt32(
const Message& src_text,
const char* str, Int32* value);
1940 bool BoolFromGTestEnv(
const char* flag,
bool default_val);
1941 GTEST_API_ Int32 Int32FromGTestEnv(
const char* flag, Int32 default_val);
1942 const char* StringFromGTestEnv(
const char* flag,
const char* default_val);
1947 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ Definition: gtest_unittest.cc:5031
Definition: gtest-all.cc:113
Definition: TypeSafeIdHash.h:44
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:539
Definition: benchGeometry.cpp:23
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:148
Definition: BandTriangularSolver.h:13