12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702 |
- #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
- #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
- #include <ctype.h> // for isspace, etc
- #include <stddef.h> // for ptrdiff_t
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #ifndef _WIN32_WCE
- # include <sys/types.h>
- # include <sys/stat.h>
- #endif
- #if defined __APPLE__
- # include <AvailabilityMacros.h>
- # include <TargetConditionals.h>
- #endif
- #include <string> // NOLINT
- #include <algorithm> // NOLINT
- #include <iostream> // NOLINT
- #include <sstream> // NOLINT
- #include <utility>
- #include <vector> // NOLINT
- #include "gtest/internal/gtest-port-arch.h"
- #include "gtest/internal/custom/gtest-port.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 _MSC_VER >= 1400
- # 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
- #ifndef GTEST_LANG_CXX11
- # if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L || _MSC_VER >= 1900
- # define GTEST_LANG_CXX11 1
- # else
- # define GTEST_LANG_CXX11 0
- # endif
- #endif
- #if GTEST_LANG_CXX11 && \
- (!defined(__GLIBCXX__) || ( \
- __GLIBCXX__ >= 20110325ul && \
- \
- __GLIBCXX__ != 20110416ul && \
- __GLIBCXX__ != 20120313ul && \
- __GLIBCXX__ != 20110428ul && \
- __GLIBCXX__ != 20120702ul))
- # define GTEST_STDLIB_CXX11 1
- #endif
- #if GTEST_STDLIB_CXX11
- # define GTEST_HAS_STD_BEGIN_AND_END_ 1
- # define GTEST_HAS_STD_FORWARD_LIST_ 1
- # if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824)
- # define GTEST_HAS_STD_FUNCTION_ 1
- # endif
- # define GTEST_HAS_STD_INITIALIZER_LIST_ 1
- # define GTEST_HAS_STD_MOVE_ 1
- # define GTEST_HAS_STD_UNIQUE_PTR_ 1
- # define GTEST_HAS_STD_SHARED_PTR_ 1
- # define GTEST_HAS_UNORDERED_MAP_ 1
- # define GTEST_HAS_UNORDERED_SET_ 1
- #endif
- #if GTEST_LANG_CXX11
- # define GTEST_HAS_STD_TUPLE_ 1
- # if defined(__clang__)
- # if defined(__has_include) && !__has_include(<tuple>)
- # undef GTEST_HAS_STD_TUPLE_
- # endif
- # elif defined(_MSC_VER)
- # if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
- # undef GTEST_HAS_STD_TUPLE_
- # endif
- # elif defined(__GLIBCXX__)
- # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
- # undef GTEST_HAS_STD_TUPLE_
- # endif
- # endif
- #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
- #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)
- # 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
- #if !defined(GTEST_HAS_STD_STRING)
- # define GTEST_HAS_STD_STRING 1
- #elif !GTEST_HAS_STD_STRING
- # error "::std::string isn't available."
- #endif
- #ifndef GTEST_HAS_GLOBAL_STRING
- # define GTEST_HAS_GLOBAL_STRING 0
- #endif
- #ifndef GTEST_HAS_STD_WSTRING
- # define GTEST_HAS_STD_WSTRING \
- (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
- #endif
- #ifndef GTEST_HAS_GLOBAL_WSTRING
- # define GTEST_HAS_GLOBAL_WSTRING \
- (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
- #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__) && (GTEST_GCC_VER_ >= 40302)
- # 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)
- #endif
- #if GTEST_HAS_PTHREAD
- # include <pthread.h> // NOLINT
- # include <time.h> // NOLINT
- #endif
- #if !defined(GTEST_HAS_HASH_MAP_)
- # if defined(_MSC_VER) && (_MSC_VER < 1900)
- # define GTEST_HAS_HASH_MAP_ 1
- # define GTEST_HAS_HASH_SET_ 1
- # endif
- #endif
- #ifndef GTEST_HAS_TR1_TUPLE
- # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
- # define GTEST_HAS_TR1_TUPLE 0
- # elif defined(_MSC_VER) && (_MSC_VER >= 1910)
- # define GTEST_HAS_TR1_TUPLE 0
- # elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION)
- # define GTEST_HAS_TR1_TUPLE 0
- # else
- # define GTEST_HAS_TR1_TUPLE 1
- # endif
- #endif
- #ifndef GTEST_USE_OWN_TR1_TUPLE
- # if GTEST_OS_SYMBIAN
- # define GTEST_USE_OWN_TR1_TUPLE 1
- # else
- # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
- && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) \
- || (_MSC_VER >= 1600 && _MSC_VER < 1900)
- # define GTEST_ENV_HAS_TR1_TUPLE_ 1
- # endif
- # if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
- # define GTEST_ENV_HAS_STD_TUPLE_ 1
- # endif
- # if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
- # define GTEST_USE_OWN_TR1_TUPLE 0
- # else
- # define GTEST_USE_OWN_TR1_TUPLE 1
- # endif
- # endif
- #endif
- #if GTEST_HAS_STD_TUPLE_
- # include <tuple> // IWYU pragma: export
- # define GTEST_TUPLE_NAMESPACE_ ::std
- #endif
- #if GTEST_HAS_TR1_TUPLE
- # ifndef GTEST_TUPLE_NAMESPACE_
- # define GTEST_TUPLE_NAMESPACE_ ::std::tr1
- # endif
- # if GTEST_USE_OWN_TR1_TUPLE
- # include "gtest/internal/gtest-tuple.h"
- # elif GTEST_OS_SYMBIAN
- # ifdef BOOST_HAS_TR1_TUPLE
- # undef BOOST_HAS_TR1_TUPLE
- # endif
- # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
- # include <tuple> // IWYU pragma: export // NOLINT
- # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
- # if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
- # define _TR1_FUNCTIONAL 1
- # include <tr1/tuple>
- # undef _TR1_FUNCTIONAL
-
- # else
- # include <tr1/tuple> // NOLINT
- # endif
- # elif _MSC_VER >= 1600
- # include <tuple> // IWYU pragma: export // NOLINT
- # else
- # include <tr1/tuple> // IWYU pragma: export // NOLINT
- # endif
- #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_SYMBIAN || \
- GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
- # 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 >= 1400) || \
- 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)
- # define GTEST_HAS_DEATH_TEST 1
- #endif
- #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
- defined(__IBMCPP__) || defined(__HP_aCC)
- # define GTEST_HAS_TYPED_TEST 1
- # define GTEST_HAS_TYPED_TEST_P 1
- #endif
- #if (GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_) && !defined(__SUNPRO_CC)
- # define GTEST_HAS_COMBINE 1
- #endif
- #define GTEST_WIDE_STRING_USES_UTF16_ \
- (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
- #if GTEST_OS_LINUX
- # 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 GTEST_LANG_CXX11
- # define GTEST_CXX11_EQUALS_DELETE_ = delete
- #else
- # define GTEST_CXX11_EQUALS_DELETE_
- #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) \
- void operator=(type const &) GTEST_CXX11_EQUALS_DELETE_
- #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
- type(type const &) GTEST_CXX11_EQUALS_DELETE_; \
- GTEST_DISALLOW_ASSIGN_(type)
- #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !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
- #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(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;
- #if defined(GTEST_TUPLE_NAMESPACE_)
- using GTEST_TUPLE_NAMESPACE_::get;
- using GTEST_TUPLE_NAMESPACE_::make_tuple;
- using GTEST_TUPLE_NAMESPACE_::tuple;
- using GTEST_TUPLE_NAMESPACE_::tuple_size;
- using GTEST_TUPLE_NAMESPACE_::tuple_element;
- #endif
- namespace internal {
- class Secret;
- #if GTEST_LANG_CXX11
- # define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
- #else
- template <bool>
- struct CompileAssert {
- };
- # define GTEST_COMPILE_ASSERT_(expr, msg) \
- typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
- msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
- #endif
- template <typename T1, typename T2>
- struct StaticAssertTypeEqHelper;
- template <typename T>
- struct StaticAssertTypeEqHelper<T, T> {
- enum { value = true };
- };
- template <typename T, typename U>
- struct IsSame {
- enum { value = false };
- };
- template <typename T>
- struct IsSame<T, T> {
- enum { value = true };
- };
- #define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
- #if GTEST_HAS_GLOBAL_STRING
- typedef ::string string;
- #else
- typedef ::std::string string;
- #endif
- #if GTEST_HAS_GLOBAL_WSTRING
- typedef ::wstring wstring;
- #elif GTEST_HAS_STD_WSTRING
- typedef ::std::wstring wstring;
- #endif
- GTEST_API_ bool IsTrue(bool condition);
- template <typename T>
- class scoped_ptr {
- public:
- typedef T element_type;
- explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
- ~scoped_ptr() { reset(); }
- T& operator*() const { return *ptr_; }
- T* operator->() const { return ptr_; }
- T* get() const { return ptr_; }
- T* release() {
- T* const ptr = ptr_;
- ptr_ = NULL;
- return ptr;
- }
- void reset(T* p = NULL) {
- if (p != ptr_) {
- if (IsTrue(sizeof(T) > 0)) {
- delete ptr_;
- }
- ptr_ = p;
- }
- }
- friend void swap(scoped_ptr& a, scoped_ptr& b) {
- using std::swap;
- swap(a.ptr_, b.ptr_);
- }
- private:
- T* ptr_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
- };
- #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()); }
- # if GTEST_HAS_GLOBAL_STRING
- RE(const ::string& regex) { Init(regex.c_str()); }
- # endif
- 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);
- }
- # if GTEST_HAS_GLOBAL_STRING
- static bool FullMatch(const ::string& str, const RE& re) {
- return FullMatch(str.c_str(), re);
- }
- static bool PartialMatch(const ::string& str, const RE& re) {
- return PartialMatch(str.c_str(), re);
- }
- # endif
- 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
- GTEST_DISALLOW_ASSIGN_(RE);
- };
- #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(NULL); }
- #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 AddReference { typedef T& type; };
- template <typename T>
- struct AddReference<T&> { typedef T& type; };
- #define GTEST_ADD_REFERENCE_(T) \
- typename ::testing::internal::AddReference<T>::type
- 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
- #if GTEST_HAS_STD_MOVE_
- using std::forward;
- using std::move;
- template <typename T>
- struct RvalueRef {
- typedef T&& type;
- };
- #else
- template <typename T>
- const T& move(const T& t) {
- return t;
- }
- template <typename T>
- GTEST_ADD_REFERENCE_(T) forward(GTEST_ADD_REFERENCE_(T) t) { return t; }
- template <typename T>
- struct RvalueRef {
- typedef const T& type;
- };
- #endif
- 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 = NULL;
- ::testing::internal::ImplicitCast_<From*>(to);
- }
- #if GTEST_HAS_RTTI
-
- GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
- #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);
- #if GTEST_HAS_GLOBAL_STRING
- void SetInjectableArgvs(const std::vector< ::string>& new_argvs);
- #endif
- 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, NULL);
- }
- # endif
- # if GTEST_HAS_NOTIFICATION_
- # elif GTEST_HAS_PTHREAD
- class Notification {
- public:
- Notification() : notified_(false) {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
- }
- ~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 NULL;
- }
- 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_, 0, &ThreadFuncWithCLinkage, base));
- }
- ~ThreadWithParam() { Join(); }
- void Join() {
- if (!finished_) {
- GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
- finished_ = true;
- }
- }
- virtual void Run() {
- if (thread_can_start_ != NULL)
- 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() {}
- virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
- };
- class InstanceValueHolderFactory : public ValueHolderFactory {
- public:
- explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
- virtual ValueHolder* MakeNewHolder() const {
- return new ValueHolder(value_);
- }
- private:
- const T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
- };
- scoped_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_, NULL));
- 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 != NULL) {
- 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() {}
- virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
- };
- class InstanceValueHolderFactory : public ValueHolderFactory {
- public:
- explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
- virtual ValueHolder* MakeNewHolder() const {
- return new ValueHolder(value_);
- }
- private:
- const T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
- };
-
- const pthread_key_t key_;
- scoped_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 defined(__SYMBIAN32__) || defined(__IBMCPP__) || \
- (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5130)
- # define GTEST_ELLIPSIS_NEEDS_POD_ 1
- #else
- # define GTEST_CAN_COMPARE_NULL 1
- #endif
- #if defined(__SYMBIAN32__) || defined(__IBMCPP__)
- # define GTEST_NEEDS_IS_POINTER_ 1
- #endif
- template <bool bool_value>
- struct bool_constant {
- typedef bool_constant<bool_value> type;
- static const bool value = bool_value;
- };
- template <bool bool_value> const bool bool_constant<bool_value>::value;
- typedef bool_constant<false> false_type;
- typedef bool_constant<true> true_type;
- template <typename T, typename U>
- struct is_same : public false_type {};
- template <typename T>
- struct is_same<T, T> : public true_type {};
- template <typename T>
- struct is_pointer : public false_type {};
- template <typename T>
- struct is_pointer<T*> : public true_type {};
- template <typename Iterator>
- struct IteratorTraits {
- typedef typename Iterator::value_type value_type;
- };
- template <typename T>
- struct IteratorTraits<T*> {
- typedef T value_type;
- };
- template <typename T>
- struct IteratorTraits<const T*> {
- typedef T value_type;
- };
- #if GTEST_OS_WINDOWS
- # define GTEST_PATH_SEP_ "\\"
- # define GTEST_HAS_ALT_PATH_SEP_ 1
- typedef __int64 BiggestInt;
- #else
- # define GTEST_PATH_SEP_ "/"
- # define GTEST_HAS_ALT_PATH_SEP_ 0
- typedef long long BiggestInt;
- #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;
- }
- 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 IsATTY(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 IsATTY(int ) { return 0; }
- # else
- inline int IsATTY(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
- #else
- typedef struct stat StatStruct;
- inline int FileNo(FILE* file) { return fileno(file); }
- inline int IsATTY(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
- GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
- inline const char* StrNCpy(char* dest, const char* src, size_t n) {
- return strncpy(dest, src, n);
- }
- #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
- inline int ChDir(const char* dir) { return chdir(dir); }
- #endif
- inline FILE* FOpen(const char* path, const char* mode) {
- return fopen(path, mode);
- }
- #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
-
- static_cast<void>(name);
- return NULL;
- #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
-
-
- const char* const env = getenv(name);
- return (env != NULL && env[0] != '\0') ? env : NULL;
- #else
- return getenv(name);
- #endif
- }
- GTEST_DISABLE_MSC_DEPRECATED_POP_()
- #if GTEST_OS_WINDOWS_MOBILE
- void Abort();
- #else
- inline void Abort() { abort(); }
- #endif
- }
- #if _MSC_VER >= 1400 && !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
- const BiggestInt kMaxBiggestInt =
- ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
- template <size_t size>
- class TypeWithSize {
- public:
-
-
- typedef void UInt;
- };
- template <>
- class TypeWithSize<4> {
- public:
-
-
-
-
- typedef int Int;
- typedef unsigned int UInt;
- };
- template <>
- class TypeWithSize<8> {
- public:
- #if GTEST_OS_WINDOWS
- typedef __int64 Int;
- typedef unsigned __int64 UInt;
- #else
- typedef long long Int;
- typedef unsigned long long UInt;
- #endif
- };
- typedef TypeWithSize<4>::Int Int32;
- typedef TypeWithSize<4>::UInt UInt32;
- typedef TypeWithSize<8>::Int Int64;
- typedef TypeWithSize<8>::UInt UInt64;
- typedef TypeWithSize<8>::Int TimeInMillis;
- #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 ::testing::internal::Int32 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_ ::testing::internal::Int32 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
- bool ParseInt32(const Message& src_text, const char* str, Int32* value);
- bool BoolFromGTestEnv(const char* flag, bool default_val);
- GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
- std::string OutputFlagAlsoCheckEnvVar();
- const char* StringFromGTestEnv(const char* flag, const char* default_val);
- }
- }
- #endif
|