1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389 |
- #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
- #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
- #include <ctype.h> // for isspace, etc
- #include <stddef.h> // for ptrdiff_t
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <cerrno>
- #include <cstdint>
- #include <limits>
- #include <type_traits>
- #ifndef _WIN32_WCE
- # include <sys/types.h>
- # include <sys/stat.h>
- #endif
- #if defined __APPLE__
- # include <AvailabilityMacros.h>
- # include <TargetConditionals.h>
- #endif
- #include <iostream> // NOLINT
- #include <locale>
- #include <memory>
- #include <string> // NOLINT
- #include <tuple>
- #include <vector> // NOLINT
- #include "gtest/internal/custom/gtest-port.h"
- #include "gtest/internal/gtest-port-arch.h"
- #if !defined(GTEST_DEV_EMAIL_)
- # define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
- # define GTEST_FLAG_PREFIX_ "gtest_"
- # define GTEST_FLAG_PREFIX_DASH_ "gtest-"
- # define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
- # define GTEST_NAME_ "Google Test"
- # define GTEST_PROJECT_URL_ "https://github.com/google/googletest/"
- #endif
- #if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
- # define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"
- #endif
- #ifdef __GNUC__
- # define GTEST_GCC_VER_ \
- (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
- #endif
- #if defined(_MSC_VER)
- # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
- __pragma(warning(push)) \
- __pragma(warning(disable: warnings))
- # define GTEST_DISABLE_MSC_WARNINGS_POP_() \
- __pragma(warning(pop))
- #else
- # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
- # define GTEST_DISABLE_MSC_WARNINGS_POP_()
- #endif
- #ifdef __clang__
- # define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
- _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")
- #define GTEST_DISABLE_MSC_DEPRECATED_POP_() \
- _Pragma("clang diagnostic pop")
- #else
- # define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
- # define GTEST_DISABLE_MSC_DEPRECATED_POP_() \
- GTEST_DISABLE_MSC_WARNINGS_POP_()
- #endif
- #if GTEST_OS_WINDOWS
- # if !GTEST_OS_WINDOWS_MOBILE
- # include <direct.h>
- # include <io.h>
- # endif
- #if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR)
- typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
- #else
- typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
- #endif
- #elif GTEST_OS_XTENSA
- #include <unistd.h>
- #else
- # include <unistd.h>
- # include <strings.h>
- #endif
- #if GTEST_OS_LINUX_ANDROID
- # include <android/api-level.h> // NOLINT
- #endif
- #ifndef GTEST_HAS_POSIX_RE
- # if GTEST_OS_LINUX_ANDROID
- # define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
- # else
- #define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA)
- # endif
- #endif
- #if GTEST_USES_PCRE
- #elif GTEST_HAS_POSIX_RE
- # include <regex.h> // NOLINT
- # define GTEST_USES_POSIX_RE 1
- #elif GTEST_OS_WINDOWS
- # define GTEST_USES_SIMPLE_RE 1
- #else
- # define GTEST_USES_SIMPLE_RE 1
- #endif
- #ifndef GTEST_HAS_EXCEPTIONS
- # if defined(_MSC_VER) && defined(_CPPUNWIND)
- # define GTEST_HAS_EXCEPTIONS 1
- # elif defined(__BORLANDC__)
- # ifndef _HAS_EXCEPTIONS
- # define _HAS_EXCEPTIONS 1
- # endif
- # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
- # elif defined(__clang__)
- # define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
- # elif defined(__GNUC__) && __EXCEPTIONS
- # define GTEST_HAS_EXCEPTIONS 1
- # elif defined(__SUNPRO_CC)
- # define GTEST_HAS_EXCEPTIONS 1
- # elif defined(__IBMCPP__) && __EXCEPTIONS
- # define GTEST_HAS_EXCEPTIONS 1
- # elif defined(__HP_aCC)
- # define GTEST_HAS_EXCEPTIONS 1
- # else
- # define GTEST_HAS_EXCEPTIONS 0
- # endif
- #endif
- #ifndef GTEST_HAS_STD_WSTRING
- #define GTEST_HAS_STD_WSTRING \
- (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
- GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || GTEST_OS_XTENSA))
- #endif
- #ifndef GTEST_HAS_RTTI
- # ifdef _MSC_VER
- #ifdef _CPPRTTI
- # define GTEST_HAS_RTTI 1
- # else
- # define GTEST_HAS_RTTI 0
- # endif
- # elif defined(__GNUC__)
- # ifdef __GXX_RTTI
- # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
- !defined(__EXCEPTIONS)
- # define GTEST_HAS_RTTI 0
- # else
- # define GTEST_HAS_RTTI 1
- # endif
- # else
- # define GTEST_HAS_RTTI 0
- # endif
- # elif defined(__clang__)
- # define GTEST_HAS_RTTI __has_feature(cxx_rtti)
- # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
- # ifdef __RTTI_ALL__
- # define GTEST_HAS_RTTI 1
- # else
- # define GTEST_HAS_RTTI 0
- # endif
- # else
- # define GTEST_HAS_RTTI 1
- # endif
- #endif
- #if GTEST_HAS_RTTI
- # include <typeinfo>
- #endif
- #ifndef GTEST_HAS_PTHREAD
- #define GTEST_HAS_PTHREAD \
- (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \
- GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
- GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \
- GTEST_OS_HAIKU)
- #endif
- #if GTEST_HAS_PTHREAD
- # include <pthread.h> // NOLINT
- # include <time.h> // NOLINT
- #endif
- #ifndef GTEST_HAS_CLONE
- # if GTEST_OS_LINUX && !defined(__ia64__)
- # if GTEST_OS_LINUX_ANDROID
- # if defined(__LP64__) || \
- (defined(__arm__) && __ANDROID_API__ >= 9) || \
- (defined(__mips__) && __ANDROID_API__ >= 12) || \
- (defined(__i386__) && __ANDROID_API__ >= 17)
- # define GTEST_HAS_CLONE 1
- # else
- # define GTEST_HAS_CLONE 0
- # endif
- # else
- # define GTEST_HAS_CLONE 1
- # endif
- # else
- # define GTEST_HAS_CLONE 0
- # endif
- #endif
- #ifndef GTEST_HAS_STREAM_REDIRECTION
- #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
- GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA
- # define GTEST_HAS_STREAM_REDIRECTION 0
- # else
- # define GTEST_HAS_STREAM_REDIRECTION 1
- # endif
- #endif
- #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
- (GTEST_OS_MAC && !GTEST_OS_IOS) || \
- (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \
- GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \
- GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
- GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU)
- # define GTEST_HAS_DEATH_TEST 1
- #endif
- #if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \
- defined(__IBMCPP__) || defined(__HP_aCC)
- # define GTEST_HAS_TYPED_TEST 1
- # define GTEST_HAS_TYPED_TEST_P 1
- #endif
- #define GTEST_WIDE_STRING_USES_UTF16_ \
- (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2)
- #if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \
- GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD
- # define GTEST_CAN_STREAM_RESULTS_ 1
- #endif
- #ifdef __INTEL_COMPILER
- # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
- #else
- # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:
- #endif
- #if defined(__GNUC__) && !defined(COMPILER_ICC)
- # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
- #elif defined(__clang__)
- # if __has_attribute(unused)
- # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
- # endif
- #endif
- #ifndef GTEST_ATTRIBUTE_UNUSED_
- # define GTEST_ATTRIBUTE_UNUSED_
- #endif
- #if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
- # if defined(__MINGW_PRINTF_FORMAT)
- # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
- __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
- first_to_check)))
- # else
- # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
- __attribute__((__format__(__printf__, string_index, first_to_check)))
- # endif
- #else
- # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
- #endif
- #define GTEST_DISALLOW_ASSIGN_(type) \
- type& operator=(type const &) = delete
- #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
- type(type const&) = delete; \
- type& operator=(type const&) = delete
- #define GTEST_DISALLOW_MOVE_ASSIGN_(type) \
- type& operator=(type &&) noexcept = delete
- #define GTEST_DISALLOW_MOVE_AND_ASSIGN_(type) \
- type(type&&) noexcept = delete; \
- type& operator=(type&&) noexcept = delete
- #if defined(__GNUC__) && !defined(COMPILER_ICC)
- # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
- #else
- # define GTEST_MUST_USE_RESULT_
- #endif
- # define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
- # define GTEST_INTENTIONAL_CONST_COND_POP_() \
- GTEST_DISABLE_MSC_WARNINGS_POP_()
- #ifndef GTEST_HAS_SEH
- # if defined(_MSC_VER) || defined(__BORLANDC__)
- # define GTEST_HAS_SEH 1
- # else
- # define GTEST_HAS_SEH 0
- # endif
- #endif
- #ifndef GTEST_IS_THREADSAFE
- #define GTEST_IS_THREADSAFE \
- (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \
- (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \
- GTEST_HAS_PTHREAD)
- #endif
- #ifndef GTEST_API_
- #ifdef _MSC_VER
- # if GTEST_LINKED_AS_SHARED_LIBRARY
- # define GTEST_API_ __declspec(dllimport)
- # elif GTEST_CREATE_SHARED_LIBRARY
- # define GTEST_API_ __declspec(dllexport)
- # endif
- #elif __GNUC__ >= 4 || defined(__clang__)
- # define GTEST_API_ __attribute__((visibility ("default")))
- #endif
- #endif
- #ifndef GTEST_API_
- # define GTEST_API_
- #endif
- #ifndef GTEST_DEFAULT_DEATH_TEST_STYLE
- # define GTEST_DEFAULT_DEATH_TEST_STYLE "fast"
- #endif
- #ifdef __GNUC__
- # define GTEST_NO_INLINE_ __attribute__((noinline))
- #else
- # define GTEST_NO_INLINE_
- #endif
- #if !defined(GTEST_HAS_CXXABI_H_)
- # if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
- # define GTEST_HAS_CXXABI_H_ 1
- # else
- # define GTEST_HAS_CXXABI_H_ 0
- # endif
- #endif
- #if defined(__clang__)
- # if __has_feature(memory_sanitizer)
- # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
- __attribute__((no_sanitize_memory))
- # else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
- # endif
- #else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
- #endif
- #if defined(__clang__)
- # if __has_feature(address_sanitizer)
- # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
- __attribute__((no_sanitize_address))
- # else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
- # endif
- #else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
- #endif
- #if defined(__clang__)
- # if __has_feature(hwaddress_sanitizer)
- # define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \
- __attribute__((no_sanitize("hwaddress")))
- # else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
- # endif
- #else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
- #endif
- #if defined(__clang__)
- # if __has_feature(thread_sanitizer)
- # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
- __attribute__((no_sanitize_thread))
- # else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
- # endif
- #else
- # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
- #endif
- namespace testing {
- class Message;
- using std::get;
- using std::make_tuple;
- using std::tuple;
- using std::tuple_element;
- using std::tuple_size;
- namespace internal {
- class Secret;
- #define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
- GTEST_API_ bool IsTrue(bool condition);
- #if GTEST_USES_PCRE
- #elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE
- class GTEST_API_ RE {
- public:
-
-
- RE(const RE& other) { Init(other.pattern()); }
-
- RE(const ::std::string& regex) { Init(regex.c_str()); }
- RE(const char* regex) { Init(regex); }
- ~RE();
-
- const char* pattern() const { return pattern_; }
-
-
-
-
- static bool FullMatch(const ::std::string& str, const RE& re) {
- return FullMatch(str.c_str(), re);
- }
- static bool PartialMatch(const ::std::string& str, const RE& re) {
- return PartialMatch(str.c_str(), re);
- }
- static bool FullMatch(const char* str, const RE& re);
- static bool PartialMatch(const char* str, const RE& re);
- private:
- void Init(const char* regex);
- const char* pattern_;
- bool is_valid_;
- # if GTEST_USES_POSIX_RE
- regex_t full_regex_;
- regex_t partial_regex_;
- # else
- const char* full_pattern_;
- # endif
- };
- #endif
- GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
- GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
- int line);
- enum GTestLogSeverity {
- GTEST_INFO,
- GTEST_WARNING,
- GTEST_ERROR,
- GTEST_FATAL
- };
- class GTEST_API_ GTestLog {
- public:
- GTestLog(GTestLogSeverity severity, const char* file, int line);
-
- ~GTestLog();
- ::std::ostream& GetStream() { return ::std::cerr; }
- private:
- const GTestLogSeverity severity_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
- };
- #if !defined(GTEST_LOG_)
- # define GTEST_LOG_(severity) \
- ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
- __FILE__, __LINE__).GetStream()
- inline void LogToStderr() {}
- inline void FlushInfoLog() { fflush(nullptr); }
- #endif
- #if !defined(GTEST_CHECK_)
- # define GTEST_CHECK_(condition) \
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (::testing::internal::IsTrue(condition)) \
- ; \
- else \
- GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
- #endif
- #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
- if (const int gtest_error = (posix_call)) \
- GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
- << gtest_error
- template <typename T>
- struct ConstRef { typedef const T& type; };
- template <typename T>
- struct ConstRef<T&> { typedef T& type; };
- #define GTEST_REFERENCE_TO_CONST_(T) \
- typename ::testing::internal::ConstRef<T>::type
- template<typename To>
- inline To ImplicitCast_(To x) { return x; }
- template<typename To, typename From>
- inline To DownCast_(From* f) {
-
-
-
-
- GTEST_INTENTIONAL_CONST_COND_PUSH_()
- if (false) {
- GTEST_INTENTIONAL_CONST_COND_POP_()
- const To to = nullptr;
- ::testing::internal::ImplicitCast_<From*>(to);
- }
- #if GTEST_HAS_RTTI
-
- GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != nullptr);
- #endif
- return static_cast<To>(f);
- }
- template <class Derived, class Base>
- Derived* CheckedDowncastToActualType(Base* base) {
- #if GTEST_HAS_RTTI
- GTEST_CHECK_(typeid(*base) == typeid(Derived));
- #endif
- #if GTEST_HAS_DOWNCAST_
- return ::down_cast<Derived*>(base);
- #elif GTEST_HAS_RTTI
- return dynamic_cast<Derived*>(base);
- #else
- return static_cast<Derived*>(base);
- #endif
- }
- #if GTEST_HAS_STREAM_REDIRECTION
- GTEST_API_ void CaptureStdout();
- GTEST_API_ std::string GetCapturedStdout();
- GTEST_API_ void CaptureStderr();
- GTEST_API_ std::string GetCapturedStderr();
- #endif
- GTEST_API_ size_t GetFileSize(FILE* file);
- GTEST_API_ std::string ReadEntireFile(FILE* file);
- GTEST_API_ std::vector<std::string> GetArgvs();
- #if GTEST_HAS_DEATH_TEST
- std::vector<std::string> GetInjectableArgvs();
- void SetInjectableArgvs(const std::vector<std::string>* new_argvs);
- void SetInjectableArgvs(const std::vector<std::string>& new_argvs);
- void ClearInjectableArgvs();
- #endif
- #if GTEST_IS_THREADSAFE
- # if GTEST_HAS_PTHREAD
- inline void SleepMilliseconds(int n) {
- const timespec time = {
- 0,
- n * 1000L * 1000L,
- };
- nanosleep(&time, nullptr);
- }
- # endif
- # if GTEST_HAS_NOTIFICATION_
- # elif GTEST_HAS_PTHREAD
- class Notification {
- public:
- Notification() : notified_(false) {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
- }
- ~Notification() {
- pthread_mutex_destroy(&mutex_);
- }
-
-
- void Notify() {
- pthread_mutex_lock(&mutex_);
- notified_ = true;
- pthread_mutex_unlock(&mutex_);
- }
-
-
- void WaitForNotification() {
- for (;;) {
- pthread_mutex_lock(&mutex_);
- const bool notified = notified_;
- pthread_mutex_unlock(&mutex_);
- if (notified)
- break;
- SleepMilliseconds(10);
- }
- }
- private:
- pthread_mutex_t mutex_;
- bool notified_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
- };
- # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
- GTEST_API_ void SleepMilliseconds(int n);
- class GTEST_API_ AutoHandle {
- public:
-
-
-
-
-
- typedef void* Handle;
- AutoHandle();
- explicit AutoHandle(Handle handle);
- ~AutoHandle();
- Handle Get() const;
- void Reset();
- void Reset(Handle handle);
- private:
-
-
- bool IsCloseable() const;
- Handle handle_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
- };
- class GTEST_API_ Notification {
- public:
- Notification();
- void Notify();
- void WaitForNotification();
- private:
- AutoHandle event_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
- };
- # endif
- # if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
- class ThreadWithParamBase {
- public:
- virtual ~ThreadWithParamBase() {}
- virtual void Run() = 0;
- };
- extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
- static_cast<ThreadWithParamBase*>(thread)->Run();
- return nullptr;
- }
- template <typename T>
- class ThreadWithParam : public ThreadWithParamBase {
- public:
- typedef void UserThreadFunc(T);
- ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
- : func_(func),
- param_(param),
- thread_can_start_(thread_can_start),
- finished_(false) {
- ThreadWithParamBase* const base = this;
-
-
- GTEST_CHECK_POSIX_SUCCESS_(
- pthread_create(&thread_, nullptr, &ThreadFuncWithCLinkage, base));
- }
- ~ThreadWithParam() override { Join(); }
- void Join() {
- if (!finished_) {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, nullptr));
- finished_ = true;
- }
- }
- void Run() override {
- if (thread_can_start_ != nullptr) thread_can_start_->WaitForNotification();
- func_(param_);
- }
- private:
- UserThreadFunc* const func_;
- const T param_;
-
-
- Notification* const thread_can_start_;
- bool finished_;
-
- pthread_t thread_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
- };
- # endif
-
- # if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
- # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
- class GTEST_API_ Mutex {
- public:
- enum MutexType { kStatic = 0, kDynamic = 1 };
-
-
-
- enum StaticConstructorSelector { kStaticMutex = 0 };
-
-
-
- explicit Mutex(StaticConstructorSelector ) {}
- Mutex();
- ~Mutex();
- void Lock();
- void Unlock();
-
-
- void AssertHeld();
- private:
-
- void ThreadSafeLazyInit();
-
-
- unsigned int owner_thread_id_;
-
-
- MutexType type_;
- long critical_section_init_phase_;
- GTEST_CRITICAL_SECTION* critical_section_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
- };
- # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
- extern ::testing::internal::Mutex mutex
- # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
- ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
- class GTestMutexLock {
- public:
- explicit GTestMutexLock(Mutex* mutex)
- : mutex_(mutex) { mutex_->Lock(); }
- ~GTestMutexLock() { mutex_->Unlock(); }
- private:
- Mutex* const mutex_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
- };
- typedef GTestMutexLock MutexLock;
- class ThreadLocalValueHolderBase {
- public:
- virtual ~ThreadLocalValueHolderBase() {}
- };
- class ThreadLocalBase {
- public:
-
-
-
-
- virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
- protected:
- ThreadLocalBase() {}
- virtual ~ThreadLocalBase() {}
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase);
- };
- class GTEST_API_ ThreadLocalRegistry {
- public:
-
-
- static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
- const ThreadLocalBase* thread_local_instance);
-
- static void OnThreadLocalDestroyed(
- const ThreadLocalBase* thread_local_instance);
- };
- class GTEST_API_ ThreadWithParamBase {
- public:
- void Join();
- protected:
- class Runnable {
- public:
- virtual ~Runnable() {}
- virtual void Run() = 0;
- };
- ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
- virtual ~ThreadWithParamBase();
- private:
- AutoHandle thread_;
- };
- template <typename T>
- class ThreadWithParam : public ThreadWithParamBase {
- public:
- typedef void UserThreadFunc(T);
- ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
- : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {
- }
- virtual ~ThreadWithParam() {}
- private:
- class RunnableImpl : public Runnable {
- public:
- RunnableImpl(UserThreadFunc* func, T param)
- : func_(func),
- param_(param) {
- }
- virtual ~RunnableImpl() {}
- virtual void Run() {
- func_(param_);
- }
- private:
- UserThreadFunc* const func_;
- const T param_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl);
- };
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
- };
- template <typename T>
- class ThreadLocal : public ThreadLocalBase {
- public:
- ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
- explicit ThreadLocal(const T& value)
- : default_factory_(new InstanceValueHolderFactory(value)) {}
- ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); }
- T* pointer() { return GetOrCreateValue(); }
- const T* pointer() const { return GetOrCreateValue(); }
- const T& get() const { return *pointer(); }
- void set(const T& value) { *pointer() = value; }
- private:
-
-
- class ValueHolder : public ThreadLocalValueHolderBase {
- public:
- ValueHolder() : value_() {}
- explicit ValueHolder(const T& value) : value_(value) {}
- T* pointer() { return &value_; }
- private:
- T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
- };
- T* GetOrCreateValue() const {
- return static_cast<ValueHolder*>(
- ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer();
- }
- virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const {
- return default_factory_->MakeNewHolder();
- }
- class ValueHolderFactory {
- public:
- ValueHolderFactory() {}
- virtual ~ValueHolderFactory() {}
- virtual ValueHolder* MakeNewHolder() const = 0;
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory);
- };
- class DefaultValueHolderFactory : public ValueHolderFactory {
- public:
- DefaultValueHolderFactory() {}
- ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
- };
- class InstanceValueHolderFactory : public ValueHolderFactory {
- public:
- explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
- ValueHolder* MakeNewHolder() const override {
- return new ValueHolder(value_);
- }
- private:
- const T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
- };
- std::unique_ptr<ValueHolderFactory> default_factory_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
- };
- # elif GTEST_HAS_PTHREAD
- class MutexBase {
- public:
-
- void Lock() {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
- owner_ = pthread_self();
- has_owner_ = true;
- }
-
- void Unlock() {
-
-
-
-
- has_owner_ = false;
- GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
- }
-
-
- void AssertHeld() const {
- GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
- << "The current thread is not holding the mutex @" << this;
- }
-
-
-
-
-
- public:
- pthread_mutex_t mutex_;
-
-
-
-
-
-
- bool has_owner_;
- pthread_t owner_;
- };
- # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
- extern ::testing::internal::MutexBase mutex
- #define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
- ::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0}
- class Mutex : public MutexBase {
- public:
- Mutex() {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
- has_owner_ = false;
- }
- ~Mutex() {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
- }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
- };
- class GTestMutexLock {
- public:
- explicit GTestMutexLock(MutexBase* mutex)
- : mutex_(mutex) { mutex_->Lock(); }
- ~GTestMutexLock() { mutex_->Unlock(); }
- private:
- MutexBase* const mutex_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
- };
- typedef GTestMutexLock MutexLock;
- class ThreadLocalValueHolderBase {
- public:
- virtual ~ThreadLocalValueHolderBase() {}
- };
- extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
- delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
- }
- template <typename T>
- class GTEST_API_ ThreadLocal {
- public:
- ThreadLocal()
- : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
- explicit ThreadLocal(const T& value)
- : key_(CreateKey()),
- default_factory_(new InstanceValueHolderFactory(value)) {}
- ~ThreadLocal() {
-
- DeleteThreadLocalValue(pthread_getspecific(key_));
-
-
- GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
- }
- T* pointer() { return GetOrCreateValue(); }
- const T* pointer() const { return GetOrCreateValue(); }
- const T& get() const { return *pointer(); }
- void set(const T& value) { *pointer() = value; }
- private:
-
- class ValueHolder : public ThreadLocalValueHolderBase {
- public:
- ValueHolder() : value_() {}
- explicit ValueHolder(const T& value) : value_(value) {}
- T* pointer() { return &value_; }
- private:
- T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
- };
- static pthread_key_t CreateKey() {
- pthread_key_t key;
-
-
- GTEST_CHECK_POSIX_SUCCESS_(
- pthread_key_create(&key, &DeleteThreadLocalValue));
- return key;
- }
- T* GetOrCreateValue() const {
- ThreadLocalValueHolderBase* const holder =
- static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
- if (holder != nullptr) {
- return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
- }
- ValueHolder* const new_holder = default_factory_->MakeNewHolder();
- ThreadLocalValueHolderBase* const holder_base = new_holder;
- GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
- return new_holder->pointer();
- }
- class ValueHolderFactory {
- public:
- ValueHolderFactory() {}
- virtual ~ValueHolderFactory() {}
- virtual ValueHolder* MakeNewHolder() const = 0;
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory);
- };
- class DefaultValueHolderFactory : public ValueHolderFactory {
- public:
- DefaultValueHolderFactory() {}
- ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
- };
- class InstanceValueHolderFactory : public ValueHolderFactory {
- public:
- explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
- ValueHolder* MakeNewHolder() const override {
- return new ValueHolder(value_);
- }
- private:
- const T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
- };
-
- const pthread_key_t key_;
- std::unique_ptr<ValueHolderFactory> default_factory_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
- };
- # endif
- #else
- class Mutex {
- public:
- Mutex() {}
- void Lock() {}
- void Unlock() {}
- void AssertHeld() const {}
- };
- # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
- extern ::testing::internal::Mutex mutex
- # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
- class GTestMutexLock {
- public:
- explicit GTestMutexLock(Mutex*) {}
- };
- typedef GTestMutexLock MutexLock;
- template <typename T>
- class GTEST_API_ ThreadLocal {
- public:
- ThreadLocal() : value_() {}
- explicit ThreadLocal(const T& value) : value_(value) {}
- T* pointer() { return &value_; }
- const T* pointer() const { return &value_; }
- const T& get() const { return value_; }
- void set(const T& value) { value_ = value; }
- private:
- T value_;
- };
- #endif
- GTEST_API_ size_t GetThreadCount();
- #if GTEST_OS_WINDOWS
- # define GTEST_PATH_SEP_ "\\"
- # define GTEST_HAS_ALT_PATH_SEP_ 1
- #else
- # define GTEST_PATH_SEP_ "/"
- # define GTEST_HAS_ALT_PATH_SEP_ 0
- #endif
- inline bool IsAlpha(char ch) {
- return isalpha(static_cast<unsigned char>(ch)) != 0;
- }
- inline bool IsAlNum(char ch) {
- return isalnum(static_cast<unsigned char>(ch)) != 0;
- }
- inline bool IsDigit(char ch) {
- return isdigit(static_cast<unsigned char>(ch)) != 0;
- }
- inline bool IsLower(char ch) {
- return islower(static_cast<unsigned char>(ch)) != 0;
- }
- inline bool IsSpace(char ch) {
- return isspace(static_cast<unsigned char>(ch)) != 0;
- }
- inline bool IsUpper(char ch) {
- return isupper(static_cast<unsigned char>(ch)) != 0;
- }
- inline bool IsXDigit(char ch) {
- return isxdigit(static_cast<unsigned char>(ch)) != 0;
- }
- #ifdef __cpp_char8_t
- inline bool IsXDigit(char8_t ch) {
- return isxdigit(static_cast<unsigned char>(ch)) != 0;
- }
- #endif
- inline bool IsXDigit(char16_t ch) {
- const unsigned char low_byte = static_cast<unsigned char>(ch);
- return ch == low_byte && isxdigit(low_byte) != 0;
- }
- inline bool IsXDigit(char32_t ch) {
- const unsigned char low_byte = static_cast<unsigned char>(ch);
- return ch == low_byte && isxdigit(low_byte) != 0;
- }
- inline bool IsXDigit(wchar_t ch) {
- const unsigned char low_byte = static_cast<unsigned char>(ch);
- return ch == low_byte && isxdigit(low_byte) != 0;
- }
- inline char ToLower(char ch) {
- return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
- }
- inline char ToUpper(char ch) {
- return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
- }
- inline std::string StripTrailingSpaces(std::string str) {
- std::string::iterator it = str.end();
- while (it != str.begin() && IsSpace(*--it))
- it = str.erase(it);
- return str;
- }
- namespace posix {
- #if GTEST_OS_WINDOWS
- typedef struct _stat StatStruct;
- # ifdef __BORLANDC__
- inline int DoIsATTY(int fd) { return isatty(fd); }
- inline int StrCaseCmp(const char* s1, const char* s2) {
- return stricmp(s1, s2);
- }
- inline char* StrDup(const char* src) { return strdup(src); }
- # else
- # if GTEST_OS_WINDOWS_MOBILE
- inline int DoIsATTY(int ) { return 0; }
- # else
- inline int DoIsATTY(int fd) { return _isatty(fd); }
- # endif
- inline int StrCaseCmp(const char* s1, const char* s2) {
- return _stricmp(s1, s2);
- }
- inline char* StrDup(const char* src) { return _strdup(src); }
- # endif
- # if GTEST_OS_WINDOWS_MOBILE
- inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
- # else
- inline int FileNo(FILE* file) { return _fileno(file); }
- inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
- inline int RmDir(const char* dir) { return _rmdir(dir); }
- inline bool IsDir(const StatStruct& st) {
- return (_S_IFDIR & st.st_mode) != 0;
- }
- # endif
- #elif GTEST_OS_ESP8266
- typedef struct stat StatStruct;
- inline int FileNo(FILE* file) { return fileno(file); }
- inline int DoIsATTY(int fd) { return isatty(fd); }
- inline int Stat(const char* path, StatStruct* buf) {
-
- return 0;
- }
- inline int StrCaseCmp(const char* s1, const char* s2) {
- return strcasecmp(s1, s2);
- }
- inline char* StrDup(const char* src) { return strdup(src); }
- inline int RmDir(const char* dir) { return rmdir(dir); }
- inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
- #else
- typedef struct stat StatStruct;
- inline int FileNo(FILE* file) { return fileno(file); }
- inline int DoIsATTY(int fd) { return isatty(fd); }
- inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
- inline int StrCaseCmp(const char* s1, const char* s2) {
- return strcasecmp(s1, s2);
- }
- inline char* StrDup(const char* src) { return strdup(src); }
- inline int RmDir(const char* dir) { return rmdir(dir); }
- inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
- #endif
- inline int IsATTY(int fd) {
-
-
-
- int savedErrno = errno;
- int isAttyValue = DoIsATTY(fd);
- errno = savedErrno;
- return isAttyValue;
- }
- GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
- #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \
- !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA
- inline int ChDir(const char* dir) { return chdir(dir); }
- #endif
- inline FILE* FOpen(const char* path, const char* mode) {
- #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
- struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {};
- std::wstring_convert<wchar_codecvt> converter;
- std::wstring wide_path = converter.from_bytes(path);
- std::wstring wide_mode = converter.from_bytes(mode);
- return _wfopen(wide_path.c_str(), wide_mode.c_str());
- #else
- return fopen(path, mode);
- #endif
- }
- #if !GTEST_OS_WINDOWS_MOBILE
- inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
- return freopen(path, mode, stream);
- }
- inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
- #endif
- inline int FClose(FILE* fp) { return fclose(fp); }
- #if !GTEST_OS_WINDOWS_MOBILE
- inline int Read(int fd, void* buf, unsigned int count) {
- return static_cast<int>(read(fd, buf, count));
- }
- inline int Write(int fd, const void* buf, unsigned int count) {
- return static_cast<int>(write(fd, buf, count));
- }
- inline int Close(int fd) { return close(fd); }
- inline const char* StrError(int errnum) { return strerror(errnum); }
- #endif
- inline const char* GetEnv(const char* name) {
- #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
- GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA
-
- static_cast<void>(name);
- return nullptr;
- #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
-
-
- const char* const env = getenv(name);
- return (env != nullptr && env[0] != '\0') ? env : nullptr;
- #else
- return getenv(name);
- #endif
- }
- GTEST_DISABLE_MSC_DEPRECATED_POP_()
- #if GTEST_OS_WINDOWS_MOBILE
- [[noreturn]] void Abort();
- #else
- [[noreturn]] inline void Abort() { abort(); }
- #endif
- }
- #if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE
- # define GTEST_SNPRINTF_(buffer, size, format, ...) \
- _snprintf_s(buffer, size, size, format, __VA_ARGS__)
- #elif defined(_MSC_VER)
- # define GTEST_SNPRINTF_ _snprintf
- #else
- # define GTEST_SNPRINTF_ snprintf
- #endif
- using BiggestInt = long long;
- constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)();
- template <size_t size>
- class TypeWithSize {
- public:
-
-
- using UInt = void;
- };
- template <>
- class TypeWithSize<4> {
- public:
- using Int = std::int32_t;
- using UInt = std::uint32_t;
- };
- template <>
- class TypeWithSize<8> {
- public:
- using Int = std::int64_t;
- using UInt = std::uint64_t;
- };
- using TimeInMillis = int64_t;
- #if !defined(GTEST_FLAG)
- # define GTEST_FLAG(name) FLAGS_gtest_##name
- #endif
- #if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
- # define GTEST_USE_OWN_FLAGFILE_FLAG_ 1
- #endif
- #if !defined(GTEST_DECLARE_bool_)
- # define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
- # define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
- # define GTEST_DECLARE_int32_(name) \
- GTEST_API_ extern std::int32_t GTEST_FLAG(name)
- # define GTEST_DECLARE_string_(name) \
- GTEST_API_ extern ::std::string GTEST_FLAG(name)
- # define GTEST_DEFINE_bool_(name, default_val, doc) \
- GTEST_API_ bool GTEST_FLAG(name) = (default_val)
- # define GTEST_DEFINE_int32_(name, default_val, doc) \
- GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val)
- # define GTEST_DEFINE_string_(name, default_val, doc) \
- GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
- #endif
- #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
- # define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
- # define GTEST_LOCK_EXCLUDED_(locks)
- #endif
- GTEST_API_ bool ParseInt32(const Message& src_text, const char* str,
- int32_t* value);
- bool BoolFromGTestEnv(const char* flag, bool default_val);
- GTEST_API_ int32_t Int32FromGTestEnv(const char* flag, int32_t default_val);
- std::string OutputFlagAlsoCheckEnvVar();
- const char* StringFromGTestEnv(const char* flag, const char* default_val);
- }
- }
- #if !defined(GTEST_INTERNAL_DEPRECATED)
- #if defined(_MSC_VER)
- #define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message))
- #elif defined(__GNUC__)
- #define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message)))
- #else
- #define GTEST_INTERNAL_DEPRECATED(message)
- #endif
- #endif
- #if GTEST_HAS_ABSL
- #define GTEST_INTERNAL_HAS_ANY 1
- #include "absl/types/any.h"
- namespace testing {
- namespace internal {
- using Any = ::absl::any;
- }
- }
- #else
- #ifdef __has_include
- #if __has_include(<any>) && __cplusplus >= 201703L
- #define GTEST_INTERNAL_HAS_ANY 1
- #include <any>
- namespace testing {
- namespace internal {
- using Any = ::std::any;
- }
- }
- #endif
- #endif
- #endif
- #if GTEST_HAS_ABSL
- #define GTEST_INTERNAL_HAS_OPTIONAL 1
- #include "absl/types/optional.h"
- namespace testing {
- namespace internal {
- template <typename T>
- using Optional = ::absl::optional<T>;
- }
- }
- #else
- #ifdef __has_include
- #if __has_include(<optional>) && __cplusplus >= 201703L
- #define GTEST_INTERNAL_HAS_OPTIONAL 1
- #include <optional>
- namespace testing {
- namespace internal {
- template <typename T>
- using Optional = ::std::optional<T>;
- }
- }
- #endif
- #endif
- #endif
- #if GTEST_HAS_ABSL
- # define GTEST_INTERNAL_HAS_STRING_VIEW 1
- #include "absl/strings/string_view.h"
- namespace testing {
- namespace internal {
- using StringView = ::absl::string_view;
- }
- }
- #else
- # ifdef __has_include
- # if __has_include(<string_view>) && __cplusplus >= 201703L
- # define GTEST_INTERNAL_HAS_STRING_VIEW 1
- #include <string_view>
- namespace testing {
- namespace internal {
- using StringView = ::std::string_view;
- }
- }
- # endif
- # endif
- #endif
- #if GTEST_HAS_ABSL
- #define GTEST_INTERNAL_HAS_VARIANT 1
- #include "absl/types/variant.h"
- namespace testing {
- namespace internal {
- template <typename... T>
- using Variant = ::absl::variant<T...>;
- }
- }
- #else
- #ifdef __has_include
- #if __has_include(<variant>) && __cplusplus >= 201703L
- #define GTEST_INTERNAL_HAS_VARIANT 1
- #include <variant>
- namespace testing {
- namespace internal {
- template <typename... T>
- using Variant = ::std::variant<T...>;
- }
- }
- #endif
- #endif
- #endif
- #endif
|