43#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
44#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
270# include <sys/types.h>
271# include <sys/stat.h>
275# include <AvailabilityMacros.h>
276# include <TargetConditionals.h>
291#if !defined(GTEST_DEV_EMAIL_)
292# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
293# define GTEST_FLAG_PREFIX_ "gtest_"
294# define GTEST_FLAG_PREFIX_DASH_ "gtest-"
295# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
296# define GTEST_NAME_ "Google Test"
297# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/"
300#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
301# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"
307# define GTEST_GCC_VER_ \
308 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
317# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
318 __pragma(warning(push)) \
319 __pragma(warning(disable: warnings))
320# define GTEST_DISABLE_MSC_WARNINGS_POP_() \
321 __pragma(warning(pop))
324# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
325# define GTEST_DISABLE_MSC_WARNINGS_POP_()
328#ifndef GTEST_LANG_CXX11
333# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L || _MSC_VER >= 1900
335# define GTEST_LANG_CXX11 1
337# define GTEST_LANG_CXX11 0
350#if GTEST_LANG_CXX11 && \
351 (!defined(__GLIBCXX__) || ( \
352 __GLIBCXX__ >= 20110325ul && \
354 __GLIBCXX__ != 20110416ul && \
355 __GLIBCXX__ != 20120313ul && \
356 __GLIBCXX__ != 20110428ul && \
357 __GLIBCXX__ != 20120702ul))
358# define GTEST_STDLIB_CXX11 1
362#if GTEST_STDLIB_CXX11
363# define GTEST_HAS_STD_BEGIN_AND_END_ 1
364# define GTEST_HAS_STD_FORWARD_LIST_ 1
365# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824)
367# define GTEST_HAS_STD_FUNCTION_ 1
369# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
370# define GTEST_HAS_STD_MOVE_ 1
371# define GTEST_HAS_STD_UNIQUE_PTR_ 1
372# define GTEST_HAS_STD_SHARED_PTR_ 1
373# define GTEST_HAS_UNORDERED_MAP_ 1
374# define GTEST_HAS_UNORDERED_SET_ 1
380# define GTEST_HAS_STD_TUPLE_ 1
381# if defined(__clang__)
383# if defined(__has_include) && !__has_include(<tuple>)
384# undef GTEST_HAS_STD_TUPLE_
386# elif defined(_MSC_VER)
388# if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
389# undef GTEST_HAS_STD_TUPLE_
391# elif defined(__GLIBCXX__)
395# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
396# undef GTEST_HAS_STD_TUPLE_
405# if !GTEST_OS_WINDOWS_MOBILE
410#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR)
413typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
418typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
428#if GTEST_OS_LINUX_ANDROID
430# include <android/api-level.h>
434#ifndef GTEST_HAS_POSIX_RE
435# if GTEST_OS_LINUX_ANDROID
437# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
439# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
446#elif GTEST_HAS_POSIX_RE
454# define GTEST_USES_POSIX_RE 1
456#elif GTEST_OS_WINDOWS
460# define GTEST_USES_SIMPLE_RE 1
466# define GTEST_USES_SIMPLE_RE 1
470#ifndef GTEST_HAS_EXCEPTIONS
473# if defined(_MSC_VER) && defined(_CPPUNWIND)
475# define GTEST_HAS_EXCEPTIONS 1
476# elif defined(__BORLANDC__)
480# ifndef _HAS_EXCEPTIONS
481# define _HAS_EXCEPTIONS 1
483# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
484# elif defined(__clang__)
492# define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
493# elif defined(__GNUC__) && __EXCEPTIONS
495# define GTEST_HAS_EXCEPTIONS 1
496# elif defined(__SUNPRO_CC)
500# define GTEST_HAS_EXCEPTIONS 1
501# elif defined(__IBMCPP__) && __EXCEPTIONS
503# define GTEST_HAS_EXCEPTIONS 1
504# elif defined(__HP_aCC)
507# define GTEST_HAS_EXCEPTIONS 1
511# define GTEST_HAS_EXCEPTIONS 0
515#if !defined(GTEST_HAS_STD_STRING)
518# define GTEST_HAS_STD_STRING 1
519#elif !GTEST_HAS_STD_STRING
521# error "::std::string isn't available."
524#ifndef GTEST_HAS_GLOBAL_STRING
528# define GTEST_HAS_GLOBAL_STRING 0
532#ifndef GTEST_HAS_STD_WSTRING
541# define GTEST_HAS_STD_WSTRING \
542 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
546#ifndef GTEST_HAS_GLOBAL_WSTRING
549# define GTEST_HAS_GLOBAL_WSTRING \
550 (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
554#ifndef GTEST_HAS_RTTI
561# define GTEST_HAS_RTTI 1
563# define GTEST_HAS_RTTI 0
567# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
574# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
575 !defined(__EXCEPTIONS)
576# define GTEST_HAS_RTTI 0
578# define GTEST_HAS_RTTI 1
581# define GTEST_HAS_RTTI 0
587# elif defined(__clang__)
589# define GTEST_HAS_RTTI __has_feature(cxx_rtti)
593# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
596# define GTEST_HAS_RTTI 1
598# define GTEST_HAS_RTTI 0
604# define GTEST_HAS_RTTI 1
617#ifndef GTEST_HAS_PTHREAD
623#define GTEST_HAS_PTHREAD \
624 (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \
625 GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA)
639#if !defined(GTEST_HAS_HASH_MAP_)
640# if defined(_MSC_VER) && (_MSC_VER < 1900)
641# define GTEST_HAS_HASH_MAP_ 1
642# define GTEST_HAS_HASH_SET_ 1
649#ifndef GTEST_HAS_TR1_TUPLE
650# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
652# define GTEST_HAS_TR1_TUPLE 0
653# elif defined(_MSC_VER) && (_MSC_VER >= 1910)
657# define GTEST_HAS_TR1_TUPLE 0
658# elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION)
660# define GTEST_HAS_TR1_TUPLE 0
663# define GTEST_HAS_TR1_TUPLE 1
669#ifndef GTEST_USE_OWN_TR1_TUPLE
672# define GTEST_USE_OWN_TR1_TUPLE 1
686# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
687 && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) \
688 || (_MSC_VER >= 1600 && _MSC_VER < 1900)
689# define GTEST_ENV_HAS_TR1_TUPLE_ 1
695# if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
696# define GTEST_ENV_HAS_STD_TUPLE_ 1
699# if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
700# define GTEST_USE_OWN_TR1_TUPLE 0
702# define GTEST_USE_OWN_TR1_TUPLE 1
709#if GTEST_HAS_STD_TUPLE_
711# define GTEST_TUPLE_NAMESPACE_ ::std
716#if GTEST_HAS_TR1_TUPLE
717# ifndef GTEST_TUPLE_NAMESPACE_
718# define GTEST_TUPLE_NAMESPACE_ ::std::tr1
721# if GTEST_USE_OWN_TR1_TUPLE
723# elif GTEST_OS_SYMBIAN
730# ifdef BOOST_HAS_TR1_TUPLE
731# undef BOOST_HAS_TR1_TUPLE
736# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
739# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
743# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
749# define _TR1_FUNCTIONAL 1
751# undef _TR1_FUNCTIONAL
758# elif _MSC_VER >= 1600
771#ifndef GTEST_HAS_CLONE
774# if GTEST_OS_LINUX && !defined(__ia64__)
775# if GTEST_OS_LINUX_ANDROID
778# if defined(__LP64__) || \
779 (defined(__arm__) && __ANDROID_API__ >= 9) || \
780 (defined(__mips__) && __ANDROID_API__ >= 12) || \
781 (defined(__i386__) && __ANDROID_API__ >= 17)
782# define GTEST_HAS_CLONE 1
784# define GTEST_HAS_CLONE 0
787# define GTEST_HAS_CLONE 1
790# define GTEST_HAS_CLONE 0
797#ifndef GTEST_HAS_STREAM_REDIRECTION
800# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \
801 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
802# define GTEST_HAS_STREAM_REDIRECTION 0
804# define GTEST_HAS_STREAM_REDIRECTION 1
812#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
813 (GTEST_OS_MAC && !GTEST_OS_IOS) || \
814 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
815 GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
816 GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || \
817 GTEST_OS_NETBSD || GTEST_OS_FUCHSIA)
818# define GTEST_HAS_DEATH_TEST 1
825#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
826 defined(__IBMCPP__) || defined(__HP_aCC)
827# define GTEST_HAS_TYPED_TEST 1
828# define GTEST_HAS_TYPED_TEST_P 1
835#if (GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_) && !defined(__SUNPRO_CC)
836# define GTEST_HAS_COMBINE 1
840#define GTEST_WIDE_STRING_USES_UTF16_ \
841 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
845# define GTEST_CAN_STREAM_RESULTS_ 1
858#ifdef __INTEL_COMPILER
859# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
861# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:
875#if defined(__GNUC__) && !defined(COMPILER_ICC)
876# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
877#elif defined(__clang__)
878# if __has_attribute(unused)
879# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
882#ifndef GTEST_ATTRIBUTE_UNUSED_
883# define GTEST_ATTRIBUTE_UNUSED_
887# define GTEST_CXX11_EQUALS_DELETE_ = delete
889# define GTEST_CXX11_EQUALS_DELETE_
893#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
894# if defined(__MINGW_PRINTF_FORMAT)
898# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
899 __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
902# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
903 __attribute__((__format__(__printf__, string_index, first_to_check)))
906# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
912#define GTEST_DISALLOW_ASSIGN_(type) \
913 void operator=(type const &) GTEST_CXX11_EQUALS_DELETE_
917#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
918 type(type const &) GTEST_CXX11_EQUALS_DELETE_; \
919 GTEST_DISALLOW_ASSIGN_(type)
926#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
927# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
929# define GTEST_MUST_USE_RESULT_
940# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
941 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
942# define GTEST_INTENTIONAL_CONST_COND_POP_() \
943 GTEST_DISABLE_MSC_WARNINGS_POP_()
951# if defined(_MSC_VER) || defined(__BORLANDC__)
953# define GTEST_HAS_SEH 1
956# define GTEST_HAS_SEH 0
959#define GTEST_IS_THREADSAFE \
960 (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ \
961 || (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) \
962 || GTEST_HAS_PTHREAD)
972# if GTEST_LINKED_AS_SHARED_LIBRARY
973# define GTEST_API_ __declspec(dllimport)
974# elif GTEST_CREATE_SHARED_LIBRARY
975# define GTEST_API_ __declspec(dllexport)
977#elif __GNUC__ >= 4 || defined(__clang__)
978# define GTEST_API_ __attribute__((visibility ("default")))
987#ifndef GTEST_DEFAULT_DEATH_TEST_STYLE
988# define GTEST_DEFAULT_DEATH_TEST_STYLE "fast"
993# define GTEST_NO_INLINE_ __attribute__((noinline))
995# define GTEST_NO_INLINE_
999#if !defined(GTEST_HAS_CXXABI_H_)
1000# if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
1001# define GTEST_HAS_CXXABI_H_ 1
1003# define GTEST_HAS_CXXABI_H_ 0
1009#if defined(__clang__)
1010# if __has_feature(memory_sanitizer)
1011# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
1012 __attribute__((no_sanitize_memory))
1014# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
1017# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
1021#if defined(__clang__)
1022# if __has_feature(address_sanitizer)
1023# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
1024 __attribute__((no_sanitize_address))
1026# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
1029# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
1033#if defined(__clang__)
1034# if __has_feature(thread_sanitizer)
1035# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
1036 __attribute__((no_sanitize_thread))
1038# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
1041# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
1048#if defined(GTEST_TUPLE_NAMESPACE_)
1052using GTEST_TUPLE_NAMESPACE_::get;
1053using GTEST_TUPLE_NAMESPACE_::make_tuple;
1054using GTEST_TUPLE_NAMESPACE_::tuple;
1055using GTEST_TUPLE_NAMESPACE_::tuple_size;
1056using GTEST_TUPLE_NAMESPACE_::tuple_element;
1082# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
1088# define GTEST_COMPILE_ASSERT_(expr, msg) \
1089 typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
1090 msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
1139template <
typename T1,
typename T2>
1142template <
typename T>
1148template <
typename T,
typename U>
1152template <
typename T>
1158#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
1160#if GTEST_HAS_GLOBAL_STRING
1166#if GTEST_HAS_GLOBAL_WSTRING
1168#elif GTEST_HAS_STD_WSTRING
1180template <
typename T>
1193 T*
const ptr = ptr_;
1209 swap(
a.ptr_, b.ptr_);
1222#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE
1233 RE(const ::std::string& regex) {
Init(regex.c_str()); }
1235# if GTEST_HAS_GLOBAL_STRING
1237 RE(const ::string& regex) {
Init(regex.c_str()); }
1255 return FullMatch(str.c_str(), re);
1258 return PartialMatch(str.c_str(), re);
1261# if GTEST_HAS_GLOBAL_STRING
1263 static bool FullMatch(const ::string& str,
const RE& re) {
1264 return FullMatch(str.c_str(), re);
1266 static bool PartialMatch(const ::string& str,
const RE& re) {
1267 return PartialMatch(str.c_str(), re);
1276 void Init(
const char* regex);
1281 const char* pattern_;
1284# if GTEST_USES_POSIX_RE
1286 regex_t full_regex_;
1287 regex_t partial_regex_;
1291 const char* full_pattern_;
1341#if !defined(GTEST_LOG_)
1343# define GTEST_LOG_(severity) \
1344 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
1345 __FILE__, __LINE__).GetStream()
1352#if !defined(GTEST_CHECK_)
1367# define GTEST_CHECK_(condition) \
1368 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1369 if (::testing::internal::IsTrue(condition)) \
1372 GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
1380#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
1381 if (const int gtest_error = (posix_call)) \
1382 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
1388template <
typename T>
1390template <
typename T>
1395#define GTEST_ADD_REFERENCE_(T) \
1396 typename ::testing::internal::AddReference<T>::type
1409template <
typename T>
1411template <
typename T>
1415#define GTEST_REFERENCE_TO_CONST_(T) \
1416 typename ::testing::internal::ConstRef<T>::type
1418#if GTEST_HAS_STD_MOVE_
1422template <
typename T>
1427template <
typename T>
1431template <
typename T>
1434template <
typename T>
1460template<
typename To>
1484template<
typename To,
typename From>
1501 return static_cast<To>(
f);
1509template <
class Derived,
class Base>
1515#if GTEST_HAS_DOWNCAST_
1516 return ::down_cast<Derived*>(base);
1518 return dynamic_cast<Derived*
>(base);
1520 return static_cast<Derived*
>(base);
1524#if GTEST_HAS_STREAM_REDIRECTION
1547#if GTEST_HAS_DEATH_TEST
1549std::vector<std::string> GetInjectableArgvs();
1551void SetInjectableArgvs(
const std::vector<std::string>* new_argvs);
1552void SetInjectableArgvs(
const std::vector<std::string>& new_argvs);
1553#if GTEST_HAS_GLOBAL_STRING
1554void SetInjectableArgvs(
const std::vector< ::string>& new_argvs);
1556void ClearInjectableArgvs();
1561#if GTEST_IS_THREADSAFE
1562# if GTEST_HAS_PTHREAD
1566inline void SleepMilliseconds(
int n) {
1567 const timespec time = {
1571 nanosleep(&time, NULL);
1575# if GTEST_HAS_NOTIFICATION_
1579# elif GTEST_HAS_PTHREAD
1588 Notification() : notified_(false) {
1592 pthread_mutex_destroy(&mutex_);
1598 pthread_mutex_lock(&mutex_);
1600 pthread_mutex_unlock(&mutex_);
1605 void WaitForNotification() {
1607 pthread_mutex_lock(&mutex_);
1608 const bool notified = notified_;
1609 pthread_mutex_unlock(&mutex_);
1612 SleepMilliseconds(10);
1617 pthread_mutex_t mutex_;
1623# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
1636 typedef void* Handle;
1638 explicit AutoHandle(Handle handle);
1644 void Reset(Handle handle);
1648 bool IsCloseable()
const;
1665 void WaitForNotification();
1677# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
1684class ThreadWithParamBase {
1686 virtual ~ThreadWithParamBase() {}
1687 virtual void Run() = 0;
1696extern "C" inline void* ThreadFuncWithCLinkage(
void* thread) {
1697 static_cast<ThreadWithParamBase*
>(thread)->Run();
1713template <
typename T>
1714class ThreadWithParam :
public ThreadWithParamBase {
1716 typedef void UserThreadFunc(
T);
1718 ThreadWithParam(UserThreadFunc* func,
T param, Notification* thread_can_start)
1721 thread_can_start_(thread_can_start),
1723 ThreadWithParamBase*
const base =
this;
1727 pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
1729 ~ThreadWithParam() {
Join(); }
1738 virtual void Run() {
1739 if (thread_can_start_ != NULL)
1740 thread_can_start_->WaitForNotification();
1745 UserThreadFunc*
const func_;
1749 Notification*
const thread_can_start_;
1758# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
1762# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
1780 enum MutexType { kStatic = 0, kDynamic = 1 };
1784 enum StaticConstructorSelector { kStaticMutex = 0 };
1789 explicit Mutex(StaticConstructorSelector ) {}
1804 void ThreadSafeLazyInit();
1808 unsigned int owner_thread_id_;
1813 long critical_section_init_phase_;
1814 GTEST_CRITICAL_SECTION* critical_section_;
1819# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1820 extern ::testing::internal::Mutex mutex
1822# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1823 ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
1830class GTestMutexLock {
1833 : mutex_(mutex) { mutex_->Lock(); }
1835 ~GTestMutexLock() { mutex_->Unlock(); }
1838 Mutex*
const mutex_;
1847class ThreadLocalValueHolderBase {
1849 virtual ~ThreadLocalValueHolderBase() {}
1854class ThreadLocalBase {
1860 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread()
const = 0;
1863 ThreadLocalBase() {}
1864 virtual ~ThreadLocalBase() {}
1877 static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
1878 const ThreadLocalBase* thread_local_instance);
1881 static void OnThreadLocalDestroyed(
1882 const ThreadLocalBase* thread_local_instance);
1892 virtual ~Runnable() {}
1893 virtual void Run() = 0;
1896 ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
1897 virtual ~ThreadWithParamBase();
1904template <
typename T>
1905class ThreadWithParam :
public ThreadWithParamBase {
1907 typedef void UserThreadFunc(
T);
1909 ThreadWithParam(UserThreadFunc* func,
T param, Notification* thread_can_start)
1910 : ThreadWithParamBase(new RunnableImpl(
func, param), thread_can_start) {
1912 virtual ~ThreadWithParam() {}
1915 class RunnableImpl :
public Runnable {
1917 RunnableImpl(UserThreadFunc* func,
T param)
1921 virtual ~RunnableImpl() {}
1922 virtual void Run() {
1927 UserThreadFunc*
const func_;
1963template <
typename T>
1964class ThreadLocal :
public ThreadLocalBase {
1966 ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
1968 : default_factory_(new InstanceValueHolderFactory(
value)) {}
1970 ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(
this); }
1972 T*
pointer() {
return GetOrCreateValue(); }
1973 const T*
pointer()
const {
return GetOrCreateValue(); }
1980 class ValueHolder :
public ThreadLocalValueHolderBase {
1982 ValueHolder() : value_() {}
1983 explicit ValueHolder(
const T&
value) : value_(
value) {}
1993 T* GetOrCreateValue()
const {
1994 return static_cast<ValueHolder*
>(
1995 ThreadLocalRegistry::GetValueOnCurrentThread(
this))->
pointer();
1998 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread()
const {
1999 return default_factory_->MakeNewHolder();
2002 class ValueHolderFactory {
2004 ValueHolderFactory() {}
2005 virtual ~ValueHolderFactory() {}
2006 virtual ValueHolder* MakeNewHolder()
const = 0;
2012 class DefaultValueHolderFactory :
public ValueHolderFactory {
2014 DefaultValueHolderFactory() {}
2015 virtual ValueHolder* MakeNewHolder()
const {
return new ValueHolder(); }
2021 class InstanceValueHolderFactory :
public ValueHolderFactory {
2023 explicit InstanceValueHolderFactory(
const T&
value) : value_(
value) {}
2024 virtual ValueHolder* MakeNewHolder()
const {
2025 return new ValueHolder(value_);
2034 scoped_ptr<ValueHolderFactory> default_factory_;
2039# elif GTEST_HAS_PTHREAD
2047 owner_ = pthread_self();
2063 void AssertHeld()
const {
2064 GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
2065 <<
"The current thread is not holding the mutex @" <<
this;
2074 pthread_mutex_t mutex_;
2086# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
2087 extern ::testing::internal::MutexBase mutex
2095# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
2096 ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
2100class Mutex :
public MutexBase {
2119class GTestMutexLock {
2122 : mutex_(mutex) { mutex_->Lock(); }
2124 ~GTestMutexLock() { mutex_->Unlock(); }
2127 MutexBase*
const mutex_;
2140class ThreadLocalValueHolderBase {
2142 virtual ~ThreadLocalValueHolderBase() {}
2147extern "C" inline void DeleteThreadLocalValue(
void* value_holder) {
2148 delete static_cast<ThreadLocalValueHolderBase*
>(value_holder);
2152template <
typename T>
2156 : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
2157 explicit ThreadLocal(
const T&
value)
2158 : key_(CreateKey()),
2159 default_factory_(new InstanceValueHolderFactory(
value)) {}
2163 DeleteThreadLocalValue(pthread_getspecific(key_));
2170 T*
pointer() {
return GetOrCreateValue(); }
2171 const T*
pointer()
const {
return GetOrCreateValue(); }
2172 const T& get()
const {
return *
pointer(); }
2177 class ValueHolder :
public ThreadLocalValueHolderBase {
2179 ValueHolder() : value_() {}
2180 explicit ValueHolder(
const T&
value) : value_(
value) {}
2189 static pthread_key_t CreateKey() {
2194 pthread_key_create(&key, &DeleteThreadLocalValue));
2198 T* GetOrCreateValue()
const {
2199 ThreadLocalValueHolderBase*
const holder =
2200 static_cast<ThreadLocalValueHolderBase*
>(pthread_getspecific(key_));
2201 if (holder != NULL) {
2202 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
2205 ValueHolder*
const new_holder = default_factory_->MakeNewHolder();
2206 ThreadLocalValueHolderBase*
const holder_base = new_holder;
2208 return new_holder->pointer();
2211 class ValueHolderFactory {
2213 ValueHolderFactory() {}
2214 virtual ~ValueHolderFactory() {}
2215 virtual ValueHolder* MakeNewHolder()
const = 0;
2221 class DefaultValueHolderFactory :
public ValueHolderFactory {
2223 DefaultValueHolderFactory() {}
2224 virtual ValueHolder* MakeNewHolder()
const {
return new ValueHolder(); }
2230 class InstanceValueHolderFactory :
public ValueHolderFactory {
2232 explicit InstanceValueHolderFactory(
const T&
value) : value_(
value) {}
2233 virtual ValueHolder* MakeNewHolder()
const {
2234 return new ValueHolder(value_);
2244 const pthread_key_t key_;
2245 scoped_ptr<ValueHolderFactory> default_factory_;
2267# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
2268 extern ::testing::internal::Mutex mutex
2270# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
2284template <
typename T>
2291 const T&
get()
const {
return value_; }
2309#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || \
2310 (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5130)
2313# define GTEST_ELLIPSIS_NEEDS_POD_ 1
2315# define GTEST_CAN_COMPARE_NULL 1
2322#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
2323# define GTEST_NEEDS_IS_POINTER_ 1
2326template <
bool bool_value>
2336template <
typename T,
typename U>
2339template <
typename T>
2343template <
typename T>
2346template <
typename T>
2349template <
typename Iterator>
2355template <
typename T>
2360template <
typename T>
2366# define GTEST_PATH_SEP_ "\\"
2367# define GTEST_HAS_ALT_PATH_SEP_ 1
2371# define GTEST_PATH_SEP_ "/"
2372# define GTEST_HAS_ALT_PATH_SEP_ 0
2384 return isalpha(
static_cast<unsigned char>(ch)) != 0;
2387 return isalnum(
static_cast<unsigned char>(ch)) != 0;
2390 return isdigit(
static_cast<unsigned char>(ch)) != 0;
2393 return islower(
static_cast<unsigned char>(ch)) != 0;
2396 return isspace(
static_cast<unsigned char>(ch)) != 0;
2399 return isupper(
static_cast<unsigned char>(ch)) != 0;
2402 return isxdigit(
static_cast<unsigned char>(ch)) != 0;
2405 const unsigned char low_byte =
static_cast<unsigned char>(ch);
2406 return ch == low_byte && isxdigit(low_byte) != 0;
2410 return static_cast<char>(tolower(
static_cast<unsigned char>(ch)));
2413 return static_cast<char>(toupper(
static_cast<unsigned char>(ch)));
2417 std::string::iterator it = str.end();
2418 while (it != str.begin() &&
IsSpace(*--it))
2438inline int IsATTY(
int fd) {
return isatty(fd); }
2439inline int StrCaseCmp(
const char* s1,
const char* s2) {
2440 return stricmp(s1, s2);
2442inline char*
StrDup(
const char* src) {
return strdup(src); }
2444# if GTEST_OS_WINDOWS_MOBILE
2445inline int IsATTY(
int ) {
return 0; }
2447inline int IsATTY(
int fd) {
return _isatty(fd); }
2449inline int StrCaseCmp(
const char* s1,
const char* s2) {
2450 return _stricmp(s1, s2);
2452inline char*
StrDup(
const char* src) {
return _strdup(src); }
2455# if GTEST_OS_WINDOWS_MOBILE
2456inline int FileNo(FILE* file) {
return reinterpret_cast<int>(_fileno(file)); }
2460inline int FileNo(FILE* file) {
return _fileno(file); }
2462inline int RmDir(
const char* dir) {
return _rmdir(dir); }
2464 return (_S_IFDIR & st.st_mode) != 0;
2472inline int FileNo(FILE* file) {
return fileno(file); }
2473inline int IsATTY(
int fd) {
return isatty(fd); }
2476 return strcasecmp(s1, s2);
2478inline char*
StrDup(
const char* src) {
return strdup(src); }
2479inline int RmDir(
const char* dir) {
return rmdir(dir); }
2488inline const
char*
StrNCpy(
char* dest, const
char* src,
size_t n) {
2489 return strncpy(dest, src, n);
2496#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
2497inline int ChDir(
const char* dir) {
return chdir(dir); }
2499inline FILE*
FOpen(
const char* path,
const char* mode) {
2500 return fopen(path, mode);
2502#if !GTEST_OS_WINDOWS_MOBILE
2503inline FILE *
FReopen(
const char* path,
const char* mode, FILE* stream) {
2504 return freopen(path, mode, stream);
2506inline FILE*
FDOpen(
int fd,
const char* mode) {
return fdopen(fd, mode); }
2508inline int FClose(FILE* fp) {
return fclose(fp); }
2509#if !GTEST_OS_WINDOWS_MOBILE
2511 return static_cast<int>(read(fd,
buf,
count));
2514 return static_cast<int>(write(fd,
buf,
count));
2517inline const char*
StrError(
int errnum) {
return strerror(errnum); }
2520#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
2522 static_cast<void>(
name);
2524#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
2527 const char*
const env = getenv(
name);
2528 return (env != NULL && env[0] !=
'\0') ? env : NULL;
2530 return getenv(
name);
2536#if GTEST_OS_WINDOWS_MOBILE
2552#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
2554# define GTEST_SNPRINTF_(buffer, size, format, ...) \
2555 _snprintf_s(buffer, size, size, format, __VA_ARGS__)
2556#elif defined(_MSC_VER)
2559# define GTEST_SNPRINTF_ _snprintf
2561# define GTEST_SNPRINTF_ snprintf
2592template <
size_t size>
2617 typedef __int64
Int;
2618 typedef unsigned __int64
UInt;
2635#if !defined(GTEST_FLAG)
2636# define GTEST_FLAG(name) FLAGS_gtest_##name
2639#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
2640# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1
2643#if !defined(GTEST_DECLARE_bool_)
2644# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
2647# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
2648# define GTEST_DECLARE_int32_(name) \
2649 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
2650# define GTEST_DECLARE_string_(name) \
2651 GTEST_API_ extern ::std::string GTEST_FLAG(name)
2654# define GTEST_DEFINE_bool_(name, default_val, doc) \
2655 GTEST_API_ bool GTEST_FLAG(name) = (default_val)
2656# define GTEST_DEFINE_int32_(name, default_val, doc) \
2657 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
2658# define GTEST_DEFINE_string_(name, default_val, doc) \
2659 GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
2664#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
2665# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
2666# define GTEST_LOCK_EXCLUDED_(locks)
::std::ostream & GetStream()
static bool PartialMatch(const ::std::string &str, const RE &re)
static bool FullMatch(const char *str, const RE &re)
const char * pattern() const
RE(const ::std::string ®ex)
static bool PartialMatch(const char *str, const RE &re)
static bool FullMatch(const ::std::string &str, const RE &re)
ThreadLocal(const T &value)
const T * pointer() const
friend void swap(scoped_ptr &a, scoped_ptr &b)
#define GTEST_CHECK_POSIX_SUCCESS_(posix_call)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_ADD_REFERENCE_(T)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_ASSIGN_(type)
#define GTEST_INTENTIONAL_CONST_COND_POP_()
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
void close(T *e, websocketpp::connection_hdl hdl)
@ Join
merge all the arguments together into a single string via the delimiter character default(' ')
void swap(picojson::value &x, picojson::value &y)
int ChDir(const char *dir)
int StrCaseCmp(const char *s1, const char *s2)
int Stat(const char *path, StatStruct *buf)
int Read(int fd, void *buf, unsigned int count)
const char * StrNCpy(char *dest, const char *src, size_t n)
char * StrDup(const char *src)
const char * StrError(int errnum)
FILE * FReopen(const char *path, const char *mode, FILE *stream)
FILE * FDOpen(int fd, const char *mode)
const char * GetEnv(const char *name)
int RmDir(const char *dir)
bool IsDir(const StatStruct &st)
int Write(int fd, const void *buf, unsigned int count)
FILE * FOpen(const char *path, const char *mode)
GTEST_API_ size_t GetFileSize(FILE *file)
std::string OutputFlagAlsoCheckEnvVar()
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
TypeWithSize< 8 >::Int Int64
GTEST_API_ std::string ReadEntireFile(FILE *file)
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
GTEST_API_ std::string GetCapturedStderr()
GTEST_API_ size_t GetThreadCount()
TypeWithSize< 4 >::UInt UInt32
GTEST_API_ bool IsTrue(bool condition)
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_ void CaptureStderr()
TypeWithSize< 4 >::Int Int32
GTEST_API_ std::vector< std::string > GetArgvs()
const T & move(const T &t)
TypeWithSize< 8 >::UInt UInt64
std::string StripTrailingSpaces(std::string str)
bool_constant< false > false_type
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
GTEST_API_ void CaptureStdout()
const BiggestInt kMaxBiggestInt
GTEST_API_ std::string GetCapturedStdout()
Derived * CheckedDowncastToActualType(Base *base)
const GenericPointer< typename T::ValueType > & pointer
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)
Iterator::value_type value_type
bool_constant< bool_value > type
CK_SLOT_ID CK_FLAGS CK_VOID_PTR CK_NOTIFY Notify