43 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ 44 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ 257 #include <type_traits> 260 # include <sys/types.h> 261 # include <sys/stat.h> 262 #endif // !_WIN32_WCE 264 #if defined __APPLE__ 265 # include <AvailabilityMacros.h> 266 # include <TargetConditionals.h> 280 #if !defined(GTEST_DEV_EMAIL_) 281 # define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" 282 # define GTEST_FLAG_PREFIX_ "gtest_" 283 # define GTEST_FLAG_PREFIX_DASH_ "gtest-" 284 # define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" 285 # define GTEST_NAME_ "Google Test" 286 # define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" 287 #endif // !defined(GTEST_DEV_EMAIL_) 289 #if !defined(GTEST_INIT_GOOGLE_TEST_NAME_) 290 # define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest" 291 #endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_) 296 # define GTEST_GCC_VER_ \ 297 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) 305 #if defined(_MSC_VER) 306 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \ 307 __pragma(warning(push)) \ 308 __pragma(warning(disable: warnings)) 309 # define GTEST_DISABLE_MSC_WARNINGS_POP_() \ 310 __pragma(warning(pop)) 313 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) 314 # define GTEST_DISABLE_MSC_WARNINGS_POP_() 320 # define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ 321 _Pragma("clang diagnostic push") \ 322 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ 323 _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") 324 #define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ 325 _Pragma("clang diagnostic pop") 327 # define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ 328 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) 329 # define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ 330 GTEST_DISABLE_MSC_WARNINGS_POP_() 337 # if !GTEST_OS_WINDOWS_MOBILE 342 #if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) 345 typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
350 typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
357 # include <strings.h> 358 #endif // GTEST_OS_WINDOWS 360 #if GTEST_OS_LINUX_ANDROID 362 # include <android/api-level.h> 366 #ifndef GTEST_HAS_POSIX_RE 367 # if GTEST_OS_LINUX_ANDROID 369 # define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) 371 # define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS) 378 #elif GTEST_HAS_POSIX_RE 386 # define GTEST_USES_POSIX_RE 1 388 #elif GTEST_OS_WINDOWS 392 # define GTEST_USES_SIMPLE_RE 1 398 # define GTEST_USES_SIMPLE_RE 1 400 #endif // GTEST_USES_PCRE 402 #ifndef GTEST_HAS_EXCEPTIONS 405 # if defined(_MSC_VER) && defined(_CPPUNWIND) 407 # define GTEST_HAS_EXCEPTIONS 1 408 # elif defined(__BORLANDC__) 412 # ifndef _HAS_EXCEPTIONS 413 # define _HAS_EXCEPTIONS 1 414 # endif // _HAS_EXCEPTIONS 415 # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS 416 # elif defined(__clang__) 424 # define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) 425 # elif defined(__GNUC__) && __EXCEPTIONS 427 # define GTEST_HAS_EXCEPTIONS 1 428 # elif defined(__SUNPRO_CC) 432 # define GTEST_HAS_EXCEPTIONS 1 433 # elif defined(__IBMCPP__) && __EXCEPTIONS 435 # define GTEST_HAS_EXCEPTIONS 1 436 # elif defined(__HP_aCC) 439 # define GTEST_HAS_EXCEPTIONS 1 443 # define GTEST_HAS_EXCEPTIONS 0 444 # endif // defined(_MSC_VER) || defined(__BORLANDC__) 445 #endif // GTEST_HAS_EXCEPTIONS 447 #if !defined(GTEST_HAS_STD_STRING) 450 # define GTEST_HAS_STD_STRING 1 451 #elif !GTEST_HAS_STD_STRING 453 # error "::std::string isn't available." 454 #endif // !defined(GTEST_HAS_STD_STRING) 456 #ifndef GTEST_HAS_STD_WSTRING 462 #define GTEST_HAS_STD_WSTRING \ 463 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ 466 #endif // GTEST_HAS_STD_WSTRING 469 #ifndef GTEST_HAS_RTTI 475 # ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. 476 # define GTEST_HAS_RTTI 1 478 # define GTEST_HAS_RTTI 0 482 # elif defined(__GNUC__) 489 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \ 490 !defined(__EXCEPTIONS) 491 # define GTEST_HAS_RTTI 0 493 # define GTEST_HAS_RTTI 1 494 # endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS 496 # define GTEST_HAS_RTTI 0 497 # endif // __GXX_RTTI 502 # elif defined(__clang__) 504 # define GTEST_HAS_RTTI __has_feature(cxx_rtti) 508 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) 511 # define GTEST_HAS_RTTI 1 513 # define GTEST_HAS_RTTI 0 519 # define GTEST_HAS_RTTI 1 523 #endif // GTEST_HAS_RTTI 532 #ifndef GTEST_HAS_PTHREAD 538 #define GTEST_HAS_PTHREAD \ 539 (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \ 540 GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ 541 GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \ 543 #endif // GTEST_HAS_PTHREAD 545 #if GTEST_HAS_PTHREAD 548 # include <pthread.h> 558 #ifndef GTEST_HAS_CLONE 561 # if GTEST_OS_LINUX && !defined(__ia64__) 562 # if GTEST_OS_LINUX_ANDROID 565 # if defined(__LP64__) || \ 566 (defined(__arm__) && __ANDROID_API__ >= 9) || \ 567 (defined(__mips__) && __ANDROID_API__ >= 12) || \ 568 (defined(__i386__) && __ANDROID_API__ >= 17) 569 # define GTEST_HAS_CLONE 1 571 # define GTEST_HAS_CLONE 0 574 # define GTEST_HAS_CLONE 1 577 # define GTEST_HAS_CLONE 0 578 # endif // GTEST_OS_LINUX && !defined(__ia64__) 580 #endif // GTEST_HAS_CLONE 584 #ifndef GTEST_HAS_STREAM_REDIRECTION 587 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT 588 # define GTEST_HAS_STREAM_REDIRECTION 0 590 # define GTEST_HAS_STREAM_REDIRECTION 1 591 # endif // !GTEST_OS_WINDOWS_MOBILE 592 #endif // GTEST_HAS_STREAM_REDIRECTION 596 #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ 597 (GTEST_OS_MAC && !GTEST_OS_IOS) || \ 598 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \ 599 GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \ 600 GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ 601 GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU) 602 # define GTEST_HAS_DEATH_TEST 1 609 #if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \ 610 defined(__IBMCPP__) || defined(__HP_aCC) 611 # define GTEST_HAS_TYPED_TEST 1 612 # define GTEST_HAS_TYPED_TEST_P 1 616 #define GTEST_WIDE_STRING_USES_UTF16_ \ 617 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2) 620 #if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ 621 GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD 622 # define GTEST_CAN_STREAM_RESULTS_ 1 635 #ifdef __INTEL_COMPILER 636 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ 638 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT 652 #if defined(__GNUC__) && !defined(COMPILER_ICC) 653 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) 654 #elif defined(__clang__) 655 # if __has_attribute(unused) 656 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) 659 #ifndef GTEST_ATTRIBUTE_UNUSED_ 660 # define GTEST_ATTRIBUTE_UNUSED_ 664 #if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) 665 # if defined(__MINGW_PRINTF_FORMAT) 669 # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ 670 __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \ 673 # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ 674 __attribute__((__format__(__printf__, string_index, first_to_check))) 677 # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) 683 #define GTEST_DISALLOW_ASSIGN_(type) \ 684 void operator=(type const &) = delete 688 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ 689 type(type const &) = delete; \ 690 GTEST_DISALLOW_ASSIGN_(type) 697 #if defined(__GNUC__) && !defined(COMPILER_ICC) 698 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) 700 # define GTEST_MUST_USE_RESULT_ 701 #endif // __GNUC__ && !COMPILER_ICC 711 # define GTEST_INTENTIONAL_CONST_COND_PUSH_() \ 712 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127) 713 # define GTEST_INTENTIONAL_CONST_COND_POP_() \ 714 GTEST_DISABLE_MSC_WARNINGS_POP_() 719 #ifndef GTEST_HAS_SEH 722 # if defined(_MSC_VER) || defined(__BORLANDC__) 724 # define GTEST_HAS_SEH 1 727 # define GTEST_HAS_SEH 0 730 #endif // GTEST_HAS_SEH 732 #ifndef GTEST_IS_THREADSAFE 734 #define GTEST_IS_THREADSAFE \ 735 (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ 736 (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \ 739 #endif // GTEST_IS_THREADSAFE 747 # if GTEST_LINKED_AS_SHARED_LIBRARY 748 # define GTEST_API_ __declspec(dllimport) 749 # elif GTEST_CREATE_SHARED_LIBRARY 750 # define GTEST_API_ __declspec(dllexport) 752 #elif __GNUC__ >= 4 || defined(__clang__) 753 # define GTEST_API_ __attribute__((visibility ("default"))) 762 #ifndef GTEST_DEFAULT_DEATH_TEST_STYLE 763 # define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" 764 #endif // GTEST_DEFAULT_DEATH_TEST_STYLE 768 # define GTEST_NO_INLINE_ __attribute__((noinline)) 770 # define GTEST_NO_INLINE_ 774 #if !defined(GTEST_HAS_CXXABI_H_) 775 # if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) 776 # define GTEST_HAS_CXXABI_H_ 1 778 # define GTEST_HAS_CXXABI_H_ 0 784 #if defined(__clang__) 785 # if __has_feature(memory_sanitizer) 786 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \ 787 __attribute__((no_sanitize_memory)) 789 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ 790 # endif // __has_feature(memory_sanitizer) 792 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ 796 #if defined(__clang__) 797 # if __has_feature(address_sanitizer) 798 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ 799 __attribute__((no_sanitize_address)) 801 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ 802 # endif // __has_feature(address_sanitizer) 804 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ 808 #if defined(__clang__) 809 # if __has_feature(hwaddress_sanitizer) 810 # define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ 811 __attribute__((no_sanitize("hwaddress"))) 813 # define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ 814 # endif // __has_feature(hwaddress_sanitizer) 816 # define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ 820 #if defined(__clang__) 821 # if __has_feature(thread_sanitizer) 822 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \ 823 __attribute__((no_sanitize_thread)) 825 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ 826 # endif // __has_feature(thread_sanitizer) 828 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ 838 using std::make_tuple;
840 using std::tuple_element;
841 using std::tuple_size;
859 #define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) 864 template <
typename T1,
typename T2>
867 template <
typename T>
873 template <
typename T,
typename U>
877 template <
typename T>
883 #define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0])) 893 #elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE 904 RE(const ::std::string& regex) { Init(regex.c_str()); }
906 RE(
const char* regex) { Init(regex); }
910 const char*
pattern()
const {
return pattern_; }
917 return FullMatch(str.c_str(), re);
920 return PartialMatch(str.c_str(), re);
923 static bool FullMatch(
const char* str,
const RE& re);
924 static bool PartialMatch(
const char* str,
const RE& re);
927 void Init(
const char* regex);
928 const char* pattern_;
931 # if GTEST_USES_POSIX_RE 934 regex_t partial_regex_;
936 # else // GTEST_USES_SIMPLE_RE 938 const char* full_pattern_;
945 #endif // GTEST_USES_PCRE 988 #if !defined(GTEST_LOG_) 990 # define GTEST_LOG_(severity) \ 991 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ 992 __FILE__, __LINE__).GetStream() 997 #endif // !defined(GTEST_LOG_) 999 #if !defined(GTEST_CHECK_) 1014 # define GTEST_CHECK_(condition) \ 1015 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1016 if (::testing::internal::IsTrue(condition)) \ 1019 GTEST_LOG_(FATAL) << "Condition " #condition " failed. " 1020 #endif // !defined(GTEST_CHECK_) 1027 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ 1028 if (const int gtest_error = (posix_call)) \ 1029 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ 1035 template <
typename T>
1037 template <
typename T>
1042 #define GTEST_ADD_REFERENCE_(T) \ 1043 typename ::testing::internal::AddReference<T>::type 1056 template <
typename T>
1058 template <
typename T>
1062 #define GTEST_REFERENCE_TO_CONST_(T) \ 1063 typename ::testing::internal::ConstRef<T>::type 1085 template<
typename To>
1109 template<
typename To,
typename From>
1118 const To to =
nullptr;
1119 ::testing::internal::ImplicitCast_<From*>(to);
1124 GTEST_CHECK_(f ==
nullptr || dynamic_cast<To>(f) !=
nullptr);
1126 return static_cast<To>(f);
1134 template <
class Derived,
class Base>
1140 #if GTEST_HAS_DOWNCAST_ 1141 return ::down_cast<Derived*>(base);
1142 #elif GTEST_HAS_RTTI 1143 return dynamic_cast<Derived*
>(base);
1145 return static_cast<Derived*
>(base);
1149 #if GTEST_HAS_STREAM_REDIRECTION 1162 #endif // GTEST_HAS_STREAM_REDIRECTION 1172 #if GTEST_HAS_DEATH_TEST 1174 std::vector<std::string> GetInjectableArgvs();
1176 void SetInjectableArgvs(
const std::vector<std::string>* new_argvs);
1177 void SetInjectableArgvs(
const std::vector<std::string>& new_argvs);
1178 void ClearInjectableArgvs();
1180 #endif // GTEST_HAS_DEATH_TEST 1183 #if GTEST_IS_THREADSAFE 1184 # if GTEST_HAS_PTHREAD 1188 inline void SleepMilliseconds(
int n) {
1189 const timespec time = {
1193 nanosleep(&time,
nullptr);
1195 # endif // GTEST_HAS_PTHREAD 1197 # if GTEST_HAS_NOTIFICATION_ 1201 # elif GTEST_HAS_PTHREAD 1208 class Notification {
1210 Notification() : notified_(
false) {
1214 pthread_mutex_destroy(&mutex_);
1220 pthread_mutex_lock(&mutex_);
1222 pthread_mutex_unlock(&mutex_);
1227 void WaitForNotification() {
1229 pthread_mutex_lock(&mutex_);
1230 const bool notified = notified_;
1231 pthread_mutex_unlock(&mutex_);
1234 SleepMilliseconds(10);
1239 pthread_mutex_t mutex_;
1245 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 1258 typedef void* Handle;
1260 explicit AutoHandle(Handle handle);
1266 void Reset(Handle handle);
1270 bool IsCloseable()
const;
1287 void WaitForNotification();
1294 # endif // GTEST_HAS_NOTIFICATION_ 1299 # if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW 1306 class ThreadWithParamBase {
1308 virtual ~ThreadWithParamBase() {}
1309 virtual void Run() = 0;
1318 extern "C" inline void* ThreadFuncWithCLinkage(
void* thread) {
1319 static_cast<ThreadWithParamBase*
>(thread)->
Run();
1335 template <
typename T>
1336 class ThreadWithParam :
public ThreadWithParamBase {
1338 typedef void UserThreadFunc(T);
1340 ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
1343 thread_can_start_(thread_can_start),
1345 ThreadWithParamBase*
const base =
this;
1349 pthread_create(&thread_,
nullptr, &ThreadFuncWithCLinkage, base));
1351 ~ThreadWithParam()
override { Join(); }
1360 void Run()
override {
1361 if (thread_can_start_ !=
nullptr) thread_can_start_->WaitForNotification();
1366 UserThreadFunc*
const func_;
1370 Notification*
const thread_can_start_;
1376 # endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD || 1379 # if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 1383 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 1401 enum MutexType { kStatic = 0, kDynamic = 1 };
1405 enum StaticConstructorSelector { kStaticMutex = 0 };
1410 explicit Mutex(StaticConstructorSelector ) {}
1425 void ThreadSafeLazyInit();
1429 unsigned int owner_thread_id_;
1434 long critical_section_init_phase_;
1435 GTEST_CRITICAL_SECTION* critical_section_;
1440 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ 1441 extern ::testing::internal::Mutex mutex 1443 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ 1444 ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex) 1454 : mutex_(mutex) { mutex_->Lock(); }
1459 Mutex*
const mutex_;
1468 class ThreadLocalValueHolderBase {
1470 virtual ~ThreadLocalValueHolderBase() {}
1475 class ThreadLocalBase {
1481 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread()
const = 0;
1484 ThreadLocalBase() {}
1485 virtual ~ThreadLocalBase() {}
1498 static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
1499 const ThreadLocalBase* thread_local_instance);
1502 static void OnThreadLocalDestroyed(
1503 const ThreadLocalBase* thread_local_instance);
1513 virtual ~Runnable() {}
1514 virtual void Run() = 0;
1517 ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
1518 virtual ~ThreadWithParamBase();
1525 template <
typename T>
1526 class ThreadWithParam :
public ThreadWithParamBase {
1528 typedef void UserThreadFunc(T);
1530 ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
1531 : ThreadWithParamBase(
new RunnableImpl(func, param), thread_can_start) {
1533 virtual ~ThreadWithParam() {}
1536 class RunnableImpl :
public Runnable {
1538 RunnableImpl(UserThreadFunc* func, T param)
1542 virtual ~RunnableImpl() {}
1543 virtual void Run() {
1548 UserThreadFunc*
const func_;
1584 template <
typename T>
1587 ThreadLocal() : default_factory_(
new DefaultValueHolderFactory()) {}
1589 : default_factory_(
new InstanceValueHolderFactory(value)) {}
1591 ~
ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(
this); }
1593 T* pointer() {
return GetOrCreateValue(); }
1594 const T* pointer()
const {
return GetOrCreateValue(); }
1595 const T&
get()
const {
return *pointer(); }
1596 void set(
const T&
value) { *pointer() =
value; }
1601 class ValueHolder :
public ThreadLocalValueHolderBase {
1603 ValueHolder() : value_() {}
1604 explicit ValueHolder(
const T& value) : value_(value) {}
1606 T* pointer() {
return &value_; }
1614 T* GetOrCreateValue()
const {
1615 return static_cast<ValueHolder*
>(
1616 ThreadLocalRegistry::GetValueOnCurrentThread(
this))->pointer();
1619 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread()
const {
1620 return default_factory_->MakeNewHolder();
1623 class ValueHolderFactory {
1625 ValueHolderFactory() {}
1626 virtual ~ValueHolderFactory() {}
1627 virtual ValueHolder* MakeNewHolder()
const = 0;
1633 class DefaultValueHolderFactory :
public ValueHolderFactory {
1635 DefaultValueHolderFactory() {}
1636 virtual ValueHolder* MakeNewHolder()
const {
return new ValueHolder(); }
1642 class InstanceValueHolderFactory :
public ValueHolderFactory {
1644 explicit InstanceValueHolderFactory(
const T& value) : value_(value) {}
1645 virtual ValueHolder* MakeNewHolder()
const {
1646 return new ValueHolder(value_);
1655 std::unique_ptr<ValueHolderFactory> default_factory_;
1660 # elif GTEST_HAS_PTHREAD 1668 owner_ = pthread_self();
1684 void AssertHeld()
const {
1685 GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
1686 <<
"The current thread is not holding the mutex @" <<
this;
1695 pthread_mutex_t mutex_;
1707 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ 1708 extern ::testing::internal::MutexBase mutex 1716 #define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ 1717 ::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0} 1721 class Mutex :
public MutexBase {
1743 : mutex_(mutex) { mutex_->Lock(); }
1748 MutexBase*
const mutex_;
1761 class ThreadLocalValueHolderBase {
1763 virtual ~ThreadLocalValueHolderBase() {}
1768 extern "C" inline void DeleteThreadLocalValue(
void* value_holder) {
1769 delete static_cast<ThreadLocalValueHolderBase*
>(value_holder);
1773 template <
typename T>
1777 : key_(CreateKey()), default_factory_(
new DefaultValueHolderFactory()) {}
1778 explicit ThreadLocal(
const T&
value)
1779 : key_(CreateKey()),
1780 default_factory_(
new InstanceValueHolderFactory(value)) {}
1784 DeleteThreadLocalValue(pthread_getspecific(key_));
1791 T* pointer() {
return GetOrCreateValue(); }
1792 const T* pointer()
const {
return GetOrCreateValue(); }
1793 const T&
get()
const {
return *pointer(); }
1794 void set(
const T&
value) { *pointer() =
value; }
1798 class ValueHolder :
public ThreadLocalValueHolderBase {
1800 ValueHolder() : value_() {}
1801 explicit ValueHolder(
const T& value) : value_(value) {}
1803 T* pointer() {
return &value_; }
1810 static pthread_key_t CreateKey() {
1815 pthread_key_create(&key, &DeleteThreadLocalValue));
1819 T* GetOrCreateValue()
const {
1820 ThreadLocalValueHolderBase*
const holder =
1821 static_cast<ThreadLocalValueHolderBase*
>(pthread_getspecific(key_));
1822 if (holder !=
nullptr) {
1823 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
1826 ValueHolder*
const new_holder = default_factory_->MakeNewHolder();
1827 ThreadLocalValueHolderBase*
const holder_base = new_holder;
1829 return new_holder->pointer();
1832 class ValueHolderFactory {
1834 ValueHolderFactory() {}
1835 virtual ~ValueHolderFactory() {}
1836 virtual ValueHolder* MakeNewHolder()
const = 0;
1842 class DefaultValueHolderFactory :
public ValueHolderFactory {
1844 DefaultValueHolderFactory() {}
1845 virtual ValueHolder* MakeNewHolder()
const {
return new ValueHolder(); }
1851 class InstanceValueHolderFactory :
public ValueHolderFactory {
1853 explicit InstanceValueHolderFactory(
const T& value) : value_(value) {}
1854 virtual ValueHolder* MakeNewHolder()
const {
1855 return new ValueHolder(value_);
1865 const pthread_key_t key_;
1866 std::unique_ptr<ValueHolderFactory> default_factory_;
1871 # endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 1873 #else // GTEST_IS_THREADSAFE 1888 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ 1889 extern ::testing::internal::Mutex mutex 1891 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex 1905 template <
typename T>
1912 const T&
get()
const {
return value_; }
1918 #endif // GTEST_IS_THREADSAFE 1924 template <
bool bool_value>
1934 template <
typename T,
typename U>
1937 template <
typename T>
1940 template <
typename Iterator>
1946 template <
typename T>
1951 template <
typename T>
1956 #if GTEST_OS_WINDOWS 1957 # define GTEST_PATH_SEP_ "\\" 1958 # define GTEST_HAS_ALT_PATH_SEP_ 1 1962 # define GTEST_PATH_SEP_ "/" 1963 # define GTEST_HAS_ALT_PATH_SEP_ 0 1965 #endif // GTEST_OS_WINDOWS 1975 return isalpha(static_cast<unsigned char>(ch)) != 0;
1978 return isalnum(static_cast<unsigned char>(ch)) != 0;
1981 return isdigit(static_cast<unsigned char>(ch)) != 0;
1984 return islower(static_cast<unsigned char>(ch)) != 0;
1987 return isspace(static_cast<unsigned char>(ch)) != 0;
1990 return isupper(static_cast<unsigned char>(ch)) != 0;
1993 return isxdigit(static_cast<unsigned char>(ch)) != 0;
1996 const unsigned char low_byte =
static_cast<unsigned char>(
ch);
1997 return ch == low_byte && isxdigit(low_byte) != 0;
2001 return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
2004 return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
2008 std::string::iterator it = str.end();
2009 while (it != str.begin() &&
IsSpace(*--it))
2024 #if GTEST_OS_WINDOWS 2026 typedef struct _stat StatStruct;
2028 # ifdef __BORLANDC__ 2029 inline int IsATTY(
int fd) {
return isatty(fd); }
2030 inline int StrCaseCmp(
const char* s1,
const char* s2) {
2031 return stricmp(s1, s2);
2033 inline char*
StrDup(
const char* src) {
return strdup(src); }
2034 # else // !__BORLANDC__ 2035 # if GTEST_OS_WINDOWS_MOBILE 2036 inline int IsATTY(
int ) {
return 0; }
2038 inline int IsATTY(
int fd) {
return _isatty(fd); }
2039 # endif // GTEST_OS_WINDOWS_MOBILE 2040 inline int StrCaseCmp(
const char* s1,
const char* s2) {
2041 return _stricmp(s1, s2);
2043 inline char*
StrDup(
const char* src) {
return _strdup(src); }
2044 # endif // __BORLANDC__ 2046 # if GTEST_OS_WINDOWS_MOBILE 2047 inline int FileNo(
FILE* file) {
return reinterpret_cast<int>(_fileno(file)); }
2051 inline int FileNo(
FILE* file) {
return _fileno(file); }
2052 inline int Stat(
const char* path, StatStruct* buf) {
return _stat(path, buf); }
2053 inline int RmDir(
const char* dir) {
return _rmdir(dir); }
2054 inline bool IsDir(
const StatStruct& st) {
2055 return (_S_IFDIR & st.st_mode) != 0;
2057 # endif // GTEST_OS_WINDOWS_MOBILE 2061 typedef struct stat StatStruct;
2064 inline int IsATTY(
int fd) {
return isatty(fd); }
2065 inline int Stat(
const char* path, StatStruct* buf) {
return stat(path, buf); }
2067 return strcasecmp(s1, s2);
2069 inline char*
StrDup(
const char* src) {
return strdup(src); }
2070 inline int RmDir(
const char* dir) {
return rmdir(dir); }
2071 inline bool IsDir(
const StatStruct& st) {
return S_ISDIR(st.st_mode); }
2073 #endif // GTEST_OS_WINDOWS 2080 return strncpy(dest, src, n);
2087 #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 2088 inline int ChDir(
const char* dir) {
return chdir(dir); }
2091 return fopen(path, mode);
2093 #if !GTEST_OS_WINDOWS_MOBILE 2095 return freopen(path, mode, stream);
2097 inline FILE*
FDOpen(
int fd,
const char* mode) {
return fdopen(fd, mode); }
2100 #if !GTEST_OS_WINDOWS_MOBILE 2102 return static_cast<int>(read(fd, buf, count));
2105 return static_cast<int>(write(fd, buf, count));
2107 inline int Close(
int fd) {
return close(fd); }
2108 inline const char*
StrError(
int errnum) {
return strerror(errnum); }
2110 inline const char*
GetEnv(
const char* name) {
2111 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT 2113 static_cast<void>(name);
2115 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) 2118 const char*
const env = getenv(name);
2119 return (env !=
nullptr && env[0] !=
'\0') ? env :
nullptr;
2121 return getenv(name);
2127 #if GTEST_OS_WINDOWS_MOBILE 2131 [[noreturn]]
void Abort();
2133 [[noreturn]]
inline void Abort() { abort(); }
2134 #endif // GTEST_OS_WINDOWS_MOBILE 2143 #if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE 2145 # define GTEST_SNPRINTF_(buffer, size, format, ...) \ 2146 _snprintf_s(buffer, size, size, format, __VA_ARGS__) 2147 #elif defined(_MSC_VER) 2149 # define GTEST_SNPRINTF_ _snprintf 2151 # define GTEST_SNPRINTF_ snprintf 2182 template <
size_t size>
2206 #if GTEST_OS_WINDOWS 2207 typedef __int64
Int;
2208 typedef unsigned __int64
UInt;
2212 #endif // GTEST_OS_WINDOWS 2225 #if !defined(GTEST_FLAG) 2226 # define GTEST_FLAG(name) FLAGS_gtest_##name 2227 #endif // !defined(GTEST_FLAG) 2229 #if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) 2230 # define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 2231 #endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) 2233 #if !defined(GTEST_DECLARE_bool_) 2234 # define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver 2237 # define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) 2238 # define GTEST_DECLARE_int32_(name) \ 2239 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name) 2240 # define GTEST_DECLARE_string_(name) \ 2241 GTEST_API_ extern ::std::string GTEST_FLAG(name) 2244 # define GTEST_DEFINE_bool_(name, default_val, doc) \ 2245 GTEST_API_ bool GTEST_FLAG(name) = (default_val) 2246 # define GTEST_DEFINE_int32_(name, default_val, doc) \ 2247 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) 2248 # define GTEST_DEFINE_string_(name, default_val, doc) \ 2249 GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) 2251 #endif // !defined(GTEST_DECLARE_bool_) 2254 #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) 2255 # define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) 2256 # define GTEST_LOCK_EXCLUDED_(locks) 2257 #endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) 2262 bool ParseInt32(
const Message& src_text,
const char* str, Int32*
value);
2274 #if !defined(GTEST_INTERNAL_DEPRECATED) 2284 #if defined(_MSC_VER) 2285 #define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message)) 2286 #elif defined(__GNUC__) 2287 #define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message))) 2289 #define GTEST_INTERNAL_DEPRECATED(message) 2292 #endif // !defined(GTEST_INTERNAL_DEPRECATED) 2294 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ bool IsXDigit(char ch)
Definition: gtest-port.h:1992
FILE * FReopen(const char *path, const char *mode, FILE *stream)
Definition: gtest-port.h:2094
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
Definition: gtest-port.cc:1339
GTEST_API_ bool IsTrue(bool condition)
Definition: gtest.cc:5653
GTEST_API_ std::string GetCapturedStdout()
GTEST_API_ std::string GetCapturedStderr()
To ImplicitCast_(To x)
Definition: gtest-port.h:1086
static bool FullMatch(const ::std::string &str, const RE &re)
Definition: gtest-port.h:916
Definition: gmock-actions.h:59
int * count
Definition: gmock_stress_test.cc:96
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
Definition: gtest-port.h:327
T & type
Definition: gtest-port.h:1038
Iterator::value_type value_type
Definition: gtest-port.h:1942
int FClose(FILE *fp)
Definition: gtest-port.h:2099
T & type
Definition: gtest-port.h:1059
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
Definition: gtest-port.h:711
GMockOutputTest ExpectedCall FILE
Definition: gmock_output_test_golden.txt:3
Definition: gtest-port.h:1906
Definition: googletest-port-test.cc:192
const T * pointer() const
Definition: gtest-port.h:1911
GTestMutexLock(Mutex *)
Definition: gtest-port.h:1900
RE(const RE &other)
Definition: gtest-port.h:901
Definition: gtest-port.h:965
const char * StringFromGTestEnv(const char *flag, const char *default_val)
Definition: gtest-port.cc:1382
void UInt
Definition: gtest-port.h:2187
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
Definition: gtest-port.cc:1018
int IsATTY(int fd)
Definition: gtest-port.h:2064
Definition: gtest-port.h:1057
bool_constant< bool_value > type
Definition: gtest-port.h:1926
ThreadLocal()
Definition: gtest-port.h:1908
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
Definition: gtest-port.cc:1283
RE(const ::std::string ®ex)
Definition: gtest-port.h:904
GTEST_API_ size_t GetThreadCount()
Definition: gtest-port.cc:271
bool IsDigit(char ch)
Definition: gtest-port.h:1980
dest
Definition: upload.py:394
Definition: gtest-port.h:967
int Stat(const char *path, StatStruct *buf)
Definition: gtest-port.h:2065
int ChDir(const char *dir)
Definition: gtest-port.h:2088
Definition: gtest-port.h:2183
const char * GetEnv(const char *name)
Definition: gtest-port.h:2110
unsigned long long UInt
Definition: gtest-port.h:2211
#define GTEST_API_
Definition: gtest-port.h:759
GTEST_API_ void CaptureStdout()
TypeWithSize< 8 >::Int TimeInMillis
Definition: gtest-port.h:2220
GTestLogSeverity
Definition: gtest-port.h:963
bool_constant< true > true_type
Definition: gtest-port.h:1932
static bool PartialMatch(const ::std::string &str, const RE &re)
Definition: gtest-port.h:919
To DownCast_(From *f)
Definition: gtest-port.h:1110
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
Definition: gtest-port.h:329
Definition: gtest-port.h:874
GTEST_API_ std::vector< std::string > GetArgvs()
Definition: gtest.cc:416
long long Int
Definition: gtest-port.h:2210
Definition: gtest-port.h:973
#define GTEST_DISALLOW_ASSIGN_(type)
Definition: gtest-port.h:683
GTEST_API_ std::string ReadEntireFile(FILE *file)
Definition: gtest-port.cc:1207
bool_constant< false > false_type
Definition: gtest-port.h:1931
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:2217
int Write(int fd, const void *buf, unsigned int count)
Definition: gtest-port.h:2104
char ToLower(char ch)
Definition: gtest-port.h:2000
::std::ostream & GetStream()
Definition: gtest-port.h:980
TypeWithSize< 4 >::Int Int32
Definition: gtest-port.h:2216
char ch
Definition: gmock-matchers_test.cc:3621
bool IsSpace(char ch)
Definition: gtest-port.h:1986
T & type
Definition: gtest-port.h:1036
void AssertHeld() const
Definition: gtest-port.h:1885
int RmDir(const char *dir)
Definition: gtest-port.h:2070
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1014
RE(const char *regex)
Definition: gtest-port.h:906
GTEST_API_ size_t GetFileSize(FILE *file)
Definition: gtest-port.cc:1202
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
void LogToStderr()
Definition: gtest-port.h:994
Definition: gtest-port.h:1898
int Read(int fd, void *buf, unsigned int count)
Definition: gtest-port.h:2101
GTestMutexLock MutexLock
Definition: gtest-port.h:1903
Definition: gtest-port.h:966
ThreadLocal(const T &value)
Definition: gtest-port.h:1909
Definition: gtest-port.h:865
int StrCaseCmp(const char *s1, const char *s2)
Definition: gtest-port.h:2066
long long BiggestInt
Definition: gtest-port.h:1964
bool IsDir(const StatStruct &st)
Definition: gtest-port.h:2071
bool IsAlpha(char ch)
Definition: gtest-port.h:1974
#define GTEST_CHECK_POSIX_SUCCESS_(posix_call)
Definition: gtest-port.h:1027
void Lock()
Definition: gtest-port.h:1883
Definition: gtest-port.h:1925
int FileNo(FILE *file)
Definition: gtest-port.h:2063
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
Definition: gtest-port.cc:1036
const char * pattern() const
Definition: gtest-port.h:910
Definition: gtest-port.h:964
bool BoolFromGTestEnv(const char *flag, bool default_val)
Definition: gtest-port.cc:1325
FILE * FOpen(const char *path, const char *mode)
Definition: gtest-port.h:2090
int value
Definition: gmock-matchers_test.cc:657
bool IsLower(char ch)
Definition: gtest-port.h:1983
int Close(int fd)
Definition: gtest-port.h:2107
Definition: gtest-port.h:1036
const T & type
Definition: gtest-port.h:1057
unsigned int UInt
Definition: gtest-port.h:2199
int x
Definition: gmock-matchers_test.cc:3610
Definition: gtest-port.h:1935
char ToUpper(char ch)
Definition: gtest-port.h:2003
Mutex()
Definition: gtest-port.h:1882
GTEST_API_ void CaptureStderr()
void Abort()
Definition: gtest-port.h:2133
const
Definition: upload.py:398
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:688
void FlushInfoLog()
Definition: gtest-port.h:995
const char * StrNCpy(char *dest, const char *src, size_t n)
Definition: gtest-port.h:2079
TypeWithSize< 8 >::UInt UInt64
Definition: gtest-port.h:2219
T value_type
Definition: gtest-port.h:1948
bool IsUpper(char ch)
Definition: gtest-port.h:1989
Definition: gtest-port.h:897
TypeWithSize< 8 >::Int Int64
Definition: gtest-port.h:2218
void Unlock()
Definition: gtest-port.h:1884
int Int
Definition: gtest-port.h:2198
def Run(command)
Definition: googletest-break-on-failure-unittest.py:76
FILE * FDOpen(int fd, const char *mode)
Definition: gtest-port.h:2097
const BiggestInt kMaxBiggestInt
Definition: gtest-port.h:2161
char * StrDup(const char *src)
Definition: gtest-port.h:2069
const char * StrError(int errnum)
Definition: gtest-port.h:2108
Derived * CheckedDowncastToActualType(Base *base)
Definition: gtest-port.h:1135
std::string OutputFlagAlsoCheckEnvVar()
Definition: gtest-port.cc:1371
T * pointer()
Definition: gtest-port.h:1910
std::string StripTrailingSpaces(std::string str)
Definition: gtest-port.h:2007
Definition: gtest-port.h:2020
#define GTEST_INTENTIONAL_CONST_COND_POP_()
Definition: gtest-port.h:713
Definition: gtest-port.h:1941
T value_type
Definition: gtest-port.h:1953
bool IsAlNum(char ch)
Definition: gtest-port.h:1977