43 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
44 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
260 #include <type_traits>
263 # include <sys/types.h>
264 # include <sys/stat.h>
267 #if defined __APPLE__
268 # include <AvailabilityMacros.h>
269 # include <TargetConditionals.h>
285 #if !defined(GTEST_DEV_EMAIL_)
286 # define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
287 # define GTEST_FLAG_PREFIX_ "gtest_"
288 # define GTEST_FLAG_PREFIX_DASH_ "gtest-"
289 # define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
290 # define GTEST_NAME_ "Google Test"
291 # define GTEST_PROJECT_URL_ "https://github.com/google/googletest/"
294 #if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
295 # define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"
301 # define GTEST_GCC_VER_ \
302 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
310 #if defined(_MSC_VER)
311 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
312 __pragma(warning(push)) \
313 __pragma(warning(disable: warnings))
314 # define GTEST_DISABLE_MSC_WARNINGS_POP_() \
315 __pragma(warning(pop))
318 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
319 # define GTEST_DISABLE_MSC_WARNINGS_POP_()
325 # define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
326 _Pragma("clang diagnostic push") \
327 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
328 _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")
329 #define GTEST_DISABLE_MSC_DEPRECATED_POP_() \
330 _Pragma("clang diagnostic pop")
332 # define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
333 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
334 # define GTEST_DISABLE_MSC_DEPRECATED_POP_() \
335 GTEST_DISABLE_MSC_WARNINGS_POP_()
342 # if !GTEST_OS_WINDOWS_MOBILE
347 #if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR)
350 typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
355 typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
362 # include <strings.h>
365 #if GTEST_OS_LINUX_ANDROID
367 # include <android/api-level.h>
371 #ifndef GTEST_HAS_POSIX_RE
372 # if GTEST_OS_LINUX_ANDROID
374 # define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
376 # define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
383 #elif GTEST_HAS_POSIX_RE
391 # define GTEST_USES_POSIX_RE 1
393 #elif GTEST_OS_WINDOWS
397 # define GTEST_USES_SIMPLE_RE 1
403 # define GTEST_USES_SIMPLE_RE 1
407 #ifndef GTEST_HAS_EXCEPTIONS
410 # if defined(_MSC_VER) && defined(_CPPUNWIND)
412 # define GTEST_HAS_EXCEPTIONS 1
413 # elif defined(__BORLANDC__)
417 # ifndef _HAS_EXCEPTIONS
418 # define _HAS_EXCEPTIONS 1
420 # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
421 # elif defined(__clang__)
429 # define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
430 # elif defined(__GNUC__) && __EXCEPTIONS
432 # define GTEST_HAS_EXCEPTIONS 1
433 # elif defined(__SUNPRO_CC)
437 # define GTEST_HAS_EXCEPTIONS 1
438 # elif defined(__IBMCPP__) && __EXCEPTIONS
440 # define GTEST_HAS_EXCEPTIONS 1
441 # elif defined(__HP_aCC)
444 # define GTEST_HAS_EXCEPTIONS 1
448 # define GTEST_HAS_EXCEPTIONS 0
452 #if !defined(GTEST_HAS_STD_STRING)
455 # define GTEST_HAS_STD_STRING 1
456 #elif !GTEST_HAS_STD_STRING
458 # error "::std::string isn't available."
461 #ifndef GTEST_HAS_GLOBAL_STRING
462 # define GTEST_HAS_GLOBAL_STRING 0
465 #ifndef GTEST_HAS_STD_WSTRING
471 # define GTEST_HAS_STD_WSTRING \
472 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
476 #ifndef GTEST_HAS_GLOBAL_WSTRING
479 # define GTEST_HAS_GLOBAL_WSTRING \
480 (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
484 #ifndef GTEST_HAS_RTTI
491 # define GTEST_HAS_RTTI 1
493 # define GTEST_HAS_RTTI 0
497 # elif defined(__GNUC__)
504 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
505 !defined(__EXCEPTIONS)
506 # define GTEST_HAS_RTTI 0
508 # define GTEST_HAS_RTTI 1
511 # define GTEST_HAS_RTTI 0
517 # elif defined(__clang__)
519 # define GTEST_HAS_RTTI __has_feature(cxx_rtti)
523 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
526 # define GTEST_HAS_RTTI 1
528 # define GTEST_HAS_RTTI 0
534 # define GTEST_HAS_RTTI 1
547 #ifndef GTEST_HAS_PTHREAD
553 #define GTEST_HAS_PTHREAD \
554 (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \
555 GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
556 GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD)
559 #if GTEST_HAS_PTHREAD
562 # include <pthread.h>
572 #ifndef GTEST_HAS_CLONE
575 # if GTEST_OS_LINUX && !defined(__ia64__)
576 # if GTEST_OS_LINUX_ANDROID
579 # if defined(__LP64__) || \
580 (defined(__arm__) && __ANDROID_API__ >= 9) || \
581 (defined(__mips__) && __ANDROID_API__ >= 12) || \
582 (defined(__i386__) && __ANDROID_API__ >= 17)
583 # define GTEST_HAS_CLONE 1
585 # define GTEST_HAS_CLONE 0
588 # define GTEST_HAS_CLONE 1
591 # define GTEST_HAS_CLONE 0
598 #ifndef GTEST_HAS_STREAM_REDIRECTION
601 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
602 # define GTEST_HAS_STREAM_REDIRECTION 0
604 # define GTEST_HAS_STREAM_REDIRECTION 1
610 #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
611 (GTEST_OS_MAC && !GTEST_OS_IOS) || \
612 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || \
613 GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
614 GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || \
615 GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || GTEST_OS_DRAGONFLY || \
616 GTEST_OS_GNU_KFREEBSD)
617 # define GTEST_HAS_DEATH_TEST 1
624 #if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \
625 defined(__IBMCPP__) || defined(__HP_aCC)
626 # define GTEST_HAS_TYPED_TEST 1
627 # define GTEST_HAS_TYPED_TEST_P 1
631 #define GTEST_WIDE_STRING_USES_UTF16_ \
632 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2)
635 #if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \
636 GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD
637 # define GTEST_CAN_STREAM_RESULTS_ 1
650 #ifdef __INTEL_COMPILER
651 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
653 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:
667 #if defined(__GNUC__) && !defined(COMPILER_ICC)
668 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
669 #elif defined(__clang__)
670 # if __has_attribute(unused)
671 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
674 #ifndef GTEST_ATTRIBUTE_UNUSED_
675 # define GTEST_ATTRIBUTE_UNUSED_
679 #if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
680 # if defined(__MINGW_PRINTF_FORMAT)
684 # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
685 __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
688 # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
689 __attribute__((__format__(__printf__, string_index, first_to_check)))
692 # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
698 #define GTEST_DISALLOW_ASSIGN_(type) \
699 void operator=(type const &) = delete
703 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
704 type(type const &) = delete; \
705 GTEST_DISALLOW_ASSIGN_(type)
712 #if defined(__GNUC__) && !defined(COMPILER_ICC)
713 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
715 # define GTEST_MUST_USE_RESULT_
726 # define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
727 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
728 # define GTEST_INTENTIONAL_CONST_COND_POP_() \
729 GTEST_DISABLE_MSC_WARNINGS_POP_()
734 #ifndef GTEST_HAS_SEH
737 # if defined(_MSC_VER) || defined(__BORLANDC__)
739 # define GTEST_HAS_SEH 1
742 # define GTEST_HAS_SEH 0
747 #ifndef GTEST_IS_THREADSAFE
749 #define GTEST_IS_THREADSAFE \
750 (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \
751 (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \
762 # if GTEST_LINKED_AS_SHARED_LIBRARY
763 # define GTEST_API_ __declspec(dllimport)
764 # elif GTEST_CREATE_SHARED_LIBRARY
765 # define GTEST_API_ __declspec(dllexport)
767 #elif __GNUC__ >= 4 || defined(__clang__)
768 # define GTEST_API_ __attribute__((visibility ("default")))
777 #ifndef GTEST_DEFAULT_DEATH_TEST_STYLE
778 # define GTEST_DEFAULT_DEATH_TEST_STYLE "fast"
783 # define GTEST_NO_INLINE_ __attribute__((noinline))
785 # define GTEST_NO_INLINE_
789 #if !defined(GTEST_HAS_CXXABI_H_)
790 # if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
791 # define GTEST_HAS_CXXABI_H_ 1
793 # define GTEST_HAS_CXXABI_H_ 0
799 #if defined(__clang__)
800 # if __has_feature(memory_sanitizer)
801 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
802 __attribute__((no_sanitize_memory))
804 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
807 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
811 #if defined(__clang__)
812 # if __has_feature(address_sanitizer)
813 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
814 __attribute__((no_sanitize_address))
816 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
819 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
823 #if defined(__clang__)
824 # if __has_feature(thread_sanitizer)
825 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
826 __attribute__((no_sanitize_thread))
828 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
831 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
841 using std::make_tuple;
843 using std::tuple_element;
844 using std::tuple_size;
862 #define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
867 template <
typename T1,
typename T2>
870 template <
typename T>
872 enum { value =
true };
876 template <
typename T,
typename U>
880 template <
typename T>
886 #define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
888 #if GTEST_HAS_GLOBAL_STRING
894 #if GTEST_HAS_GLOBAL_WSTRING
896 #elif GTEST_HAS_STD_WSTRING
908 #elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE
921 # if GTEST_HAS_GLOBAL_STRING
927 RE(
const char* regex) { Init(regex); }
931 const char*
pattern()
const {
return pattern_; }
938 return FullMatch(str.c_str(), re);
941 return PartialMatch(str.c_str(), re);
944 # if GTEST_HAS_GLOBAL_STRING
947 return FullMatch(str.c_str(), re);
950 return PartialMatch(str.c_str(), re);
959 void Init(
const char* regex);
960 const char* pattern_;
963 # if GTEST_USES_POSIX_RE
966 regex_t partial_regex_;
970 const char* full_pattern_;
1020 #if !defined(GTEST_LOG_)
1022 # define GTEST_LOG_(severity) \
1023 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
1024 __FILE__, __LINE__).GetStream()
1031 #if !defined(GTEST_CHECK_)
1046 # define GTEST_CHECK_(condition) \
1047 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1048 if (::testing::internal::IsTrue(condition)) \
1051 GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
1059 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
1060 if (const int gtest_error = (posix_call)) \
1061 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
1067 template <
typename T>
1069 template <
typename T>
1074 #define GTEST_ADD_REFERENCE_(T) \
1075 typename ::testing::internal::AddReference<T>::type
1088 template <
typename T>
1090 template <
typename T>
1094 #define GTEST_REFERENCE_TO_CONST_(T) \
1095 typename ::testing::internal::ConstRef<T>::type
1117 template<
typename To>
1141 template<
typename To,
typename From>
1150 const To to =
nullptr;
1151 ::testing::internal::ImplicitCast_<From*>(to);
1156 GTEST_CHECK_(f ==
nullptr ||
dynamic_cast<To
>(f) !=
nullptr);
1158 return static_cast<To
>(f);
1166 template <
class Derived,
class Base>
1172 #if GTEST_HAS_DOWNCAST_
1173 return ::down_cast<Derived*>(base);
1174 #elif GTEST_HAS_RTTI
1175 return dynamic_cast<Derived*
>(base);
1177 return static_cast<Derived*
>(base);
1181 #if GTEST_HAS_STREAM_REDIRECTION
1204 #if GTEST_HAS_DEATH_TEST
1206 std::vector<std::string> GetInjectableArgvs();
1208 void SetInjectableArgvs(
const std::vector<std::string>* new_argvs);
1209 void SetInjectableArgvs(
const std::vector<std::string>& new_argvs);
1210 #if GTEST_HAS_GLOBAL_STRING
1211 void SetInjectableArgvs(
const std::vector< ::string>& new_argvs);
1213 void ClearInjectableArgvs();
1218 #if GTEST_IS_THREADSAFE
1219 # if GTEST_HAS_PTHREAD
1223 inline void SleepMilliseconds(
int n) {
1224 const timespec time = {
1228 nanosleep(&time,
nullptr);
1232 # if GTEST_HAS_NOTIFICATION_
1236 # elif GTEST_HAS_PTHREAD
1243 class Notification {
1245 Notification() : notified_(false) {
1249 pthread_mutex_destroy(&mutex_);
1255 pthread_mutex_lock(&mutex_);
1257 pthread_mutex_unlock(&mutex_);
1262 void WaitForNotification() {
1264 pthread_mutex_lock(&mutex_);
1265 const bool notified = notified_;
1266 pthread_mutex_unlock(&mutex_);
1269 SleepMilliseconds(10);
1274 pthread_mutex_t mutex_;
1280 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
1293 typedef void* Handle;
1295 explicit AutoHandle(Handle handle);
1301 void Reset(Handle handle);
1305 bool IsCloseable()
const;
1322 void WaitForNotification();
1334 # if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
1341 class ThreadWithParamBase {
1343 virtual ~ThreadWithParamBase() {}
1344 virtual void Run() = 0;
1353 extern "C" inline void* ThreadFuncWithCLinkage(
void* thread) {
1354 static_cast<ThreadWithParamBase*
>(thread)->Run();
1370 template <
typename T>
1371 class ThreadWithParam :
public ThreadWithParamBase {
1373 typedef void UserThreadFunc(T);
1375 ThreadWithParam(UserThreadFunc* func, T
param, Notification* thread_can_start)
1378 thread_can_start_(thread_can_start),
1380 ThreadWithParamBase*
const base =
this;
1384 pthread_create(&thread_,
nullptr, &ThreadFuncWithCLinkage, base));
1386 ~ThreadWithParam()
override { Join(); }
1395 void Run()
override {
1396 if (thread_can_start_ !=
nullptr) thread_can_start_->WaitForNotification();
1401 UserThreadFunc*
const func_;
1405 Notification*
const thread_can_start_;
1414 # if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
1418 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
1436 enum MutexType { kStatic = 0, kDynamic = 1 };
1440 enum StaticConstructorSelector { kStaticMutex = 0 };
1445 explicit Mutex(StaticConstructorSelector ) {}
1460 void ThreadSafeLazyInit();
1464 unsigned int owner_thread_id_;
1469 long critical_section_init_phase_;
1470 GTEST_CRITICAL_SECTION* critical_section_;
1475 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1476 extern ::testing::internal::Mutex mutex
1478 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1479 ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
1486 class GTestMutexLock {
1489 : mutex_(mutex) { mutex_->Lock(); }
1494 Mutex*
const mutex_;
1503 class ThreadLocalValueHolderBase {
1505 virtual ~ThreadLocalValueHolderBase() {}
1510 class ThreadLocalBase {
1516 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread()
const = 0;
1519 ThreadLocalBase() {}
1520 virtual ~ThreadLocalBase() {}
1533 static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
1534 const ThreadLocalBase* thread_local_instance);
1537 static void OnThreadLocalDestroyed(
1538 const ThreadLocalBase* thread_local_instance);
1548 virtual ~Runnable() {}
1549 virtual void Run() = 0;
1552 ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
1553 virtual ~ThreadWithParamBase();
1560 template <
typename T>
1561 class ThreadWithParam :
public ThreadWithParamBase {
1563 typedef void UserThreadFunc(T);
1565 ThreadWithParam(UserThreadFunc* func, T
param, Notification* thread_can_start)
1566 : ThreadWithParamBase(new RunnableImpl(func,
param), thread_can_start) {
1568 virtual ~ThreadWithParam() {}
1571 class RunnableImpl :
public Runnable {
1573 RunnableImpl(UserThreadFunc* func, T
param)
1577 virtual ~RunnableImpl() {}
1578 virtual void Run() {
1583 UserThreadFunc*
const func_;
1619 template <
typename T>
1620 class ThreadLocal :
public ThreadLocalBase {
1622 ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
1624 : default_factory_(new InstanceValueHolderFactory(value)) {}
1626 ~
ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(
this); }
1628 T*
pointer() {
return GetOrCreateValue(); }
1629 const T*
pointer()
const {
return GetOrCreateValue(); }
1631 void set(
const T& value) { *
pointer() = value; }
1636 class ValueHolder :
public ThreadLocalValueHolderBase {
1638 ValueHolder() : value_() {}
1639 explicit ValueHolder(
const T& value) : value_(value) {}
1641 T*
pointer() {
return &value_; }
1649 T* GetOrCreateValue()
const {
1650 return static_cast<ValueHolder*
>(
1651 ThreadLocalRegistry::GetValueOnCurrentThread(
this))->
pointer();
1654 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread()
const {
1655 return default_factory_->MakeNewHolder();
1658 class ValueHolderFactory {
1660 ValueHolderFactory() {}
1661 virtual ~ValueHolderFactory() {}
1662 virtual ValueHolder* MakeNewHolder()
const = 0;
1668 class DefaultValueHolderFactory :
public ValueHolderFactory {
1670 DefaultValueHolderFactory() {}
1671 virtual ValueHolder* MakeNewHolder()
const {
return new ValueHolder(); }
1677 class InstanceValueHolderFactory :
public ValueHolderFactory {
1679 explicit InstanceValueHolderFactory(
const T& value) : value_(value) {}
1680 virtual ValueHolder* MakeNewHolder()
const {
1681 return new ValueHolder(value_);
1690 std::unique_ptr<ValueHolderFactory> default_factory_;
1695 # elif GTEST_HAS_PTHREAD
1703 owner_ = pthread_self();
1719 void AssertHeld()
const {
1720 GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
1721 <<
"The current thread is not holding the mutex @" <<
this;
1730 pthread_mutex_t mutex_;
1742 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1743 extern ::testing::internal::MutexBase mutex
1751 #define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1752 ::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0}
1756 class Mutex :
public MutexBase {
1775 class GTestMutexLock {
1778 : mutex_(mutex) { mutex_->Lock(); }
1783 MutexBase*
const mutex_;
1796 class ThreadLocalValueHolderBase {
1798 virtual ~ThreadLocalValueHolderBase() {}
1803 extern "C" inline void DeleteThreadLocalValue(
void* value_holder) {
1804 delete static_cast<ThreadLocalValueHolderBase*
>(value_holder);
1808 template <
typename T>
1812 : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
1813 explicit ThreadLocal(
const T& value)
1814 : key_(CreateKey()),
1815 default_factory_(new InstanceValueHolderFactory(value)) {}
1819 DeleteThreadLocalValue(pthread_getspecific(key_));
1826 T* pointer() {
return GetOrCreateValue(); }
1827 const T* pointer()
const {
return GetOrCreateValue(); }
1828 const T&
get()
const {
return *pointer(); }
1829 void set(
const T& value) { *pointer() = value; }
1833 class ValueHolder :
public ThreadLocalValueHolderBase {
1835 ValueHolder() : value_() {}
1836 explicit ValueHolder(
const T& value) : value_(value) {}
1838 T* pointer() {
return &value_; }
1845 static pthread_key_t CreateKey() {
1850 pthread_key_create(&key, &DeleteThreadLocalValue));
1854 T* GetOrCreateValue()
const {
1855 ThreadLocalValueHolderBase*
const holder =
1856 static_cast<ThreadLocalValueHolderBase*
>(pthread_getspecific(key_));
1857 if (holder !=
nullptr) {
1858 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
1861 ValueHolder*
const new_holder = default_factory_->MakeNewHolder();
1862 ThreadLocalValueHolderBase*
const holder_base = new_holder;
1864 return new_holder->pointer();
1867 class ValueHolderFactory {
1869 ValueHolderFactory() {}
1870 virtual ~ValueHolderFactory() {}
1871 virtual ValueHolder* MakeNewHolder()
const = 0;
1877 class DefaultValueHolderFactory :
public ValueHolderFactory {
1879 DefaultValueHolderFactory() {}
1880 virtual ValueHolder* MakeNewHolder()
const {
return new ValueHolder(); }
1886 class InstanceValueHolderFactory :
public ValueHolderFactory {
1888 explicit InstanceValueHolderFactory(
const T& value) : value_(value) {}
1889 virtual ValueHolder* MakeNewHolder()
const {
1890 return new ValueHolder(value_);
1900 const pthread_key_t key_;
1901 std::unique_ptr<ValueHolderFactory> default_factory_;
1923 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1924 extern ::testing::internal::Mutex mutex
1926 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
1940 template <
typename T>
1947 const T&
get()
const {
return value_; }
1948 void set(
const T& value) { value_ = value; }
1959 template <
bool bool_value>
1969 template <
typename T,
typename U>
1972 template <
typename T>
1975 template <
typename Iterator>
1981 template <
typename T>
1986 template <
typename T>
1991 #if GTEST_OS_WINDOWS
1992 # define GTEST_PATH_SEP_ "\\"
1993 # define GTEST_HAS_ALT_PATH_SEP_ 1
1997 # define GTEST_PATH_SEP_ "/"
1998 # define GTEST_HAS_ALT_PATH_SEP_ 0
2010 return isalpha(
static_cast<unsigned char>(ch)) != 0;
2013 return isalnum(
static_cast<unsigned char>(ch)) != 0;
2016 return isdigit(
static_cast<unsigned char>(ch)) != 0;
2019 return islower(
static_cast<unsigned char>(ch)) != 0;
2022 return isspace(
static_cast<unsigned char>(ch)) != 0;
2025 return isupper(
static_cast<unsigned char>(ch)) != 0;
2028 return isxdigit(
static_cast<unsigned char>(ch)) != 0;
2031 const unsigned char low_byte =
static_cast<unsigned char>(ch);
2032 return ch == low_byte && isxdigit(low_byte) != 0;
2036 return static_cast<char>(tolower(
static_cast<unsigned char>(ch)));
2039 return static_cast<char>(toupper(
static_cast<unsigned char>(ch)));
2043 std::string::iterator it = str.end();
2044 while (it != str.begin() &&
IsSpace(*--it))
2059 #if GTEST_OS_WINDOWS
2063 # ifdef __BORLANDC__
2064 inline int IsATTY(
int fd) {
return isatty(fd); }
2065 inline int StrCaseCmp(
const char* s1,
const char* s2) {
2066 return stricmp(s1, s2);
2068 inline char*
StrDup(
const char* src) {
return strdup(src); }
2070 # if GTEST_OS_WINDOWS_MOBILE
2071 inline int IsATTY(
int ) {
return 0; }
2073 inline int IsATTY(
int fd) {
return _isatty(fd); }
2075 inline int StrCaseCmp(
const char* s1,
const char* s2) {
2076 return _stricmp(s1, s2);
2078 inline char*
StrDup(
const char* src) {
return _strdup(src); }
2081 # if GTEST_OS_WINDOWS_MOBILE
2082 inline int FileNo(FILE* file) {
return reinterpret_cast<int>(_fileno(file)); }
2086 inline int FileNo(FILE* file) {
return _fileno(file); }
2087 inline int Stat(
const char* path,
StatStruct* buf) {
return _stat(path, buf); }
2088 inline int RmDir(
const char* dir) {
return _rmdir(dir); }
2090 return (_S_IFDIR & st.st_mode) != 0;
2098 inline int FileNo(FILE* file) {
return fileno(file); }
2099 inline int IsATTY(
int fd) {
return isatty(fd); }
2102 return strcasecmp(s1, s2);
2104 inline char*
StrDup(
const char* src) {
return strdup(src); }
2105 inline int RmDir(
const char* dir) {
return rmdir(dir); }
2114 inline const
char*
StrNCpy(
char* dest, const
char* src,
size_t n) {
2115 return strncpy(dest, src, n);
2122 #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
2123 inline int ChDir(
const char* dir) {
return chdir(dir); }
2125 inline FILE*
FOpen(
const char* path,
const char* mode) {
2126 return fopen(path, mode);
2128 #if !GTEST_OS_WINDOWS_MOBILE
2130 return freopen(path, mode,
stream);
2132 inline FILE*
FDOpen(
int fd,
const char* mode) {
return fdopen(fd, mode); }
2134 inline int FClose(FILE* fp) {
return fclose(fp); }
2135 #if !GTEST_OS_WINDOWS_MOBILE
2136 inline int Read(
int fd,
void* buf,
unsigned int count) {
2137 return static_cast<int>(read(fd, buf, count));
2139 inline int Write(
int fd,
const void* buf,
unsigned int count) {
2140 return static_cast<int>(write(fd, buf, count));
2142 inline int Close(
int fd) {
return close(fd); }
2143 inline const char*
StrError(
int errnum) {
return strerror(errnum); }
2145 inline const char*
GetEnv(
const char* name) {
2146 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
2148 static_cast<void>(name);
2150 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
2153 const char*
const env = getenv(name);
2154 return (env !=
nullptr && env[0] !=
'\0') ? env :
nullptr;
2156 return getenv(name);
2162 #if GTEST_OS_WINDOWS_MOBILE
2166 [[noreturn]]
void Abort();
2168 [[noreturn]]
inline void Abort() { abort(); }
2178 #if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE
2180 # define GTEST_SNPRINTF_(buffer, size, format, ...) \
2181 _snprintf_s(buffer, size, size, format, __VA_ARGS__)
2182 #elif defined(_MSC_VER)
2184 # define GTEST_SNPRINTF_ _snprintf
2186 # define GTEST_SNPRINTF_ snprintf
2217 template <
size_t size>
2241 #if GTEST_OS_WINDOWS
2242 typedef __int64
Int;
2243 typedef unsigned __int64
UInt;
2260 #if !defined(GTEST_FLAG)
2261 # define GTEST_FLAG(name) FLAGS_gtest_##name
2264 #if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
2265 # define GTEST_USE_OWN_FLAGFILE_FLAG_ 1
2268 #if !defined(GTEST_DECLARE_bool_)
2269 # define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
2272 # define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
2273 # define GTEST_DECLARE_int32_(name) \
2274 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
2275 # define GTEST_DECLARE_string_(name) \
2276 GTEST_API_ extern ::std::string GTEST_FLAG(name)
2279 # define GTEST_DEFINE_bool_(name, default_val, doc) \
2280 GTEST_API_ bool GTEST_FLAG(name) = (default_val)
2281 # define GTEST_DEFINE_int32_(name, default_val, doc) \
2282 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
2283 # define GTEST_DEFINE_string_(name, default_val, doc) \
2284 GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
2289 #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
2290 # define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
2291 # define GTEST_LOCK_EXCLUDED_(locks)
2309 #if !defined(GTEST_INTERNAL_DEPRECATED)
2319 #if defined(_MSC_VER)
2320 #define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message))
2321 #elif defined(__GNUC__)
2322 #define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message)))
2324 #define GTEST_INTERNAL_DEPRECATED(message)
GTestLog(GTestLogSeverity severity, const char *file, int line)
::std::ostream & GetStream()
static bool PartialMatch(const ::std::string &str, const RE &re)
const char * pattern() const
static bool FullMatch(const char *str, const RE &re)
RE(const ::std::string ®ex)
static bool PartialMatch(const char *str, const RE &re)
static bool FullMatch(const ::std::string &str, const RE &re)
const T * pointer() const
ThreadLocal(const T &value)
#define GTEST_CHECK_POSIX_SUCCESS_(posix_call)
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_ASSIGN_(type)
#define GTEST_INTENTIONAL_CONST_COND_POP_()
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
__host__ __device__ __forceinline__ T & get(array< T, m > &src)
const char * GetEnv(const char *name)
int ChDir(const char *dir)
int StrCaseCmp(const char *s1, const char *s2)
int Stat(const char *path, StatStruct *buf)
const char * StrNCpy(char *dest, const char *src, size_t n)
int Read(int fd, void *buf, unsigned int count)
FILE * FOpen(const char *path, const char *mode)
const char * StrError(int errnum)
char * StrDup(const char *src)
FILE * FReopen(const char *path, const char *mode, FILE *stream)
int RmDir(const char *dir)
bool IsDir(const StatStruct &st)
int Write(int fd, const void *buf, unsigned int count)
FILE * FDOpen(int fd, const char *mode)
std::string OutputFlagAlsoCheckEnvVar()
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
TypeWithSize< 8 >::Int Int64
GTEST_API_ std::string GetCapturedStderr()
GTEST_API_ size_t GetFileSize(FILE *file)
TypeWithSize< 4 >::UInt UInt32
bool_constant< true > true_type
TypeWithSize< 8 >::Int TimeInMillis
bool BoolFromGTestEnv(const char *flag, bool default_val)
const char * StringFromGTestEnv(const char *flag, const char *default_val)
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
GTEST_API_ size_t GetThreadCount()
GTEST_API_ std::vector< std::string > GetArgvs()
GTEST_API_ void CaptureStderr()
TypeWithSize< 4 >::Int Int32
TypeWithSize< 8 >::UInt UInt64
std::string StripTrailingSpaces(std::string str)
GTEST_API_ bool IsTrue(bool condition)
GTEST_API_ std::string ReadEntireFile(FILE *file)
bool_constant< false > false_type
Derived * CheckedDowncastToActualType(Base *base)
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
GTEST_API_ void CaptureStdout()
const BiggestInt kMaxBiggestInt
GTEST_API_ ::std::string FormatFileLocation(const char *file, int line)
GTEST_API_ std::string GetCapturedStdout()
Iterator::value_type value_type
bool_constant< bool_value > type