00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
00044 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 #include <ctype.h>
00260 #include <stddef.h>
00261 #include <stdlib.h>
00262 #include <stdio.h>
00263 #include <string.h>
00264 #ifndef _WIN32_WCE
00265 # include <sys/types.h>
00266 # include <sys/stat.h>
00267 #endif // !_WIN32_WCE
00268
00269 #if defined __APPLE__
00270 # include <AvailabilityMacros.h>
00271 # include <TargetConditionals.h>
00272 #endif
00273
00274 #include <algorithm>
00275 #include <iostream>
00276 #include <sstream>
00277 #include <string>
00278 #include <utility>
00279
00280 #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
00281 #define GTEST_FLAG_PREFIX_ "gtest_"
00282 #define GTEST_FLAG_PREFIX_DASH_ "gtest-"
00283 #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
00284 #define GTEST_NAME_ "Google Test"
00285 #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
00286
00287
00288 #ifdef __GNUC__
00289
00290 # define GTEST_GCC_VER_ \
00291 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
00292 #endif // __GNUC__
00293
00294
00295 #ifdef __CYGWIN__
00296 # define GTEST_OS_CYGWIN 1
00297 #elif defined __SYMBIAN32__
00298 # define GTEST_OS_SYMBIAN 1
00299 #elif defined _WIN32
00300 # define GTEST_OS_WINDOWS 1
00301 # ifdef _WIN32_WCE
00302 # define GTEST_OS_WINDOWS_MOBILE 1
00303 # elif defined(__MINGW__) || defined(__MINGW32__)
00304 # define GTEST_OS_WINDOWS_MINGW 1
00305 # elif defined(WINAPI_FAMILY)
00306 # include <winapifamily.h>
00307 # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
00308 # define GTEST_OS_WINDOWS_DESKTOP 1
00309 # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
00310 # define GTEST_OS_WINDOWS_PHONE 1
00311 # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
00312 # define GTEST_OS_WINDOWS_RT 1
00313 # else
00314
00315
00316 # define GTEST_OS_WINDOWS_DESKTOP 1
00317 # endif
00318 # else
00319 # define GTEST_OS_WINDOWS_DESKTOP 1
00320 # endif // _WIN32_WCE
00321 #elif defined __APPLE__
00322 # define GTEST_OS_MAC 1
00323 # if TARGET_OS_IPHONE
00324 # define GTEST_OS_IOS 1
00325 # endif
00326 #elif defined __FreeBSD__
00327 # define GTEST_OS_FREEBSD 1
00328 #elif defined __linux__
00329 # define GTEST_OS_LINUX 1
00330 # if defined __ANDROID__
00331 # define GTEST_OS_LINUX_ANDROID 1
00332 # endif
00333 #elif defined __MVS__
00334 # define GTEST_OS_ZOS 1
00335 #elif defined(__sun) && defined(__SVR4)
00336 # define GTEST_OS_SOLARIS 1
00337 #elif defined(_AIX)
00338 # define GTEST_OS_AIX 1
00339 #elif defined(__hpux)
00340 # define GTEST_OS_HPUX 1
00341 #elif defined __native_client__
00342 # define GTEST_OS_NACL 1
00343 #elif defined __OpenBSD__
00344 # define GTEST_OS_OPENBSD 1
00345 #elif defined __QNX__
00346 # define GTEST_OS_QNX 1
00347 #endif // __CYGWIN__
00348
00349
00350
00351
00352
00353
00354 #if _MSC_VER >= 1500
00355 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
00356 __pragma(warning(push)) \
00357 __pragma(warning(disable: warnings))
00358 # define GTEST_DISABLE_MSC_WARNINGS_POP_() \
00359 __pragma(warning(pop))
00360 #else
00361
00362 # define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
00363 # define GTEST_DISABLE_MSC_WARNINGS_POP_()
00364 #endif
00365
00366 #ifndef GTEST_LANG_CXX11
00367
00368
00369
00370
00371 # if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
00372
00373 # define GTEST_LANG_CXX11 1
00374 # else
00375 # define GTEST_LANG_CXX11 0
00376 # endif
00377 #endif
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 #if GTEST_LANG_CXX11 && \
00389 (!defined(__GLIBCXX__) || ( \
00390 __GLIBCXX__ >= 20110325ul && \
00391 \
00392 __GLIBCXX__ != 20110416ul && \
00393 __GLIBCXX__ != 20120313ul && \
00394 __GLIBCXX__ != 20110428ul && \
00395 __GLIBCXX__ != 20120702ul))
00396 # define GTEST_STDLIB_CXX11 1
00397 #endif
00398
00399
00400 #if GTEST_STDLIB_CXX11
00401 # define GTEST_HAS_STD_BEGIN_AND_END_ 1
00402 # define GTEST_HAS_STD_FORWARD_LIST_ 1
00403 # define GTEST_HAS_STD_FUNCTION_ 1
00404 # define GTEST_HAS_STD_INITIALIZER_LIST_ 1
00405 # define GTEST_HAS_STD_MOVE_ 1
00406 # define GTEST_HAS_STD_UNIQUE_PTR_ 1
00407 #endif
00408
00409
00410
00411 #if GTEST_LANG_CXX11
00412 # define GTEST_HAS_STD_TUPLE_ 1
00413 # if defined(__clang__)
00414
00415 # if defined(__has_include) && !__has_include(<tuple>)
00416 # undef GTEST_HAS_STD_TUPLE_
00417 # endif
00418 # elif defined(_MSC_VER)
00419
00420 # if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
00421 # undef GTEST_HAS_STD_TUPLE_
00422 # endif
00423 # elif defined(__GLIBCXX__)
00424
00425
00426
00427 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
00428 # undef GTEST_HAS_STD_TUPLE_
00429 # endif
00430 # endif
00431 #endif
00432
00433
00434
00435
00436 #if GTEST_OS_WINDOWS
00437 # if !GTEST_OS_WINDOWS_MOBILE
00438 # include <direct.h>
00439 # include <io.h>
00440 # endif
00441
00442
00443
00444
00445 struct _RTL_CRITICAL_SECTION;
00446 #else
00447
00448
00449
00450 # include <unistd.h>
00451 # include <strings.h>
00452 #endif // GTEST_OS_WINDOWS
00453
00454 #if GTEST_OS_LINUX_ANDROID
00455
00456 # include <android/api-level.h>
00457 #endif
00458
00459
00460 #ifndef GTEST_HAS_POSIX_RE
00461 # if GTEST_OS_LINUX_ANDROID
00462
00463 # define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
00464 # else
00465 # define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
00466 # endif
00467 #endif
00468
00469 #if GTEST_HAS_POSIX_RE
00470
00471
00472
00473
00474
00475 # include <regex.h>
00476
00477 # define GTEST_USES_POSIX_RE 1
00478
00479 #elif GTEST_OS_WINDOWS
00480
00481
00482
00483 # define GTEST_USES_SIMPLE_RE 1
00484
00485 #else
00486
00487
00488
00489 # define GTEST_USES_SIMPLE_RE 1
00490
00491 #endif // GTEST_HAS_POSIX_RE
00492
00493 #ifndef GTEST_HAS_EXCEPTIONS
00494
00495
00496 # if defined(_MSC_VER) || defined(__BORLANDC__)
00497
00498
00499
00500 # ifndef _HAS_EXCEPTIONS
00501 # define _HAS_EXCEPTIONS 1
00502 # endif // _HAS_EXCEPTIONS
00503 # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
00504 # elif defined(__clang__)
00505
00506
00507
00508
00509
00510
00511
00512 # define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
00513 # elif defined(__GNUC__) && __EXCEPTIONS
00514
00515 # define GTEST_HAS_EXCEPTIONS 1
00516 # elif defined(__SUNPRO_CC)
00517
00518
00519
00520 # define GTEST_HAS_EXCEPTIONS 1
00521 # elif defined(__IBMCPP__) && __EXCEPTIONS
00522
00523 # define GTEST_HAS_EXCEPTIONS 1
00524 # elif defined(__HP_aCC)
00525
00526
00527 # define GTEST_HAS_EXCEPTIONS 1
00528 # else
00529
00530
00531 # define GTEST_HAS_EXCEPTIONS 0
00532 # endif // defined(_MSC_VER) || defined(__BORLANDC__)
00533 #endif // GTEST_HAS_EXCEPTIONS
00534
00535 #if !defined(GTEST_HAS_STD_STRING)
00536
00537
00538 # define GTEST_HAS_STD_STRING 1
00539 #elif !GTEST_HAS_STD_STRING
00540
00541 # error "Google Test cannot be used where ::std::string isn't available."
00542 #endif // !defined(GTEST_HAS_STD_STRING)
00543
00544 #ifndef GTEST_HAS_GLOBAL_STRING
00545
00546
00547
00548 # define GTEST_HAS_GLOBAL_STRING 0
00549
00550 #endif // GTEST_HAS_GLOBAL_STRING
00551
00552 #ifndef GTEST_HAS_STD_WSTRING
00553
00554
00555
00556
00557
00558
00559
00560
00561 # define GTEST_HAS_STD_WSTRING \
00562 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
00563
00564 #endif // GTEST_HAS_STD_WSTRING
00565
00566 #ifndef GTEST_HAS_GLOBAL_WSTRING
00567
00568
00569 # define GTEST_HAS_GLOBAL_WSTRING \
00570 (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
00571 #endif // GTEST_HAS_GLOBAL_WSTRING
00572
00573
00574 #ifndef GTEST_HAS_RTTI
00575
00576
00577
00578 # ifdef _MSC_VER
00579
00580 # ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
00581 # define GTEST_HAS_RTTI 1
00582 # else
00583 # define GTEST_HAS_RTTI 0
00584 # endif
00585
00586
00587 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
00588
00589 # ifdef __GXX_RTTI
00590
00591
00592
00593
00594 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
00595 !defined(__EXCEPTIONS)
00596 # define GTEST_HAS_RTTI 0
00597 # else
00598 # define GTEST_HAS_RTTI 1
00599 # endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
00600 # else
00601 # define GTEST_HAS_RTTI 0
00602 # endif // __GXX_RTTI
00603
00604
00605
00606
00607 # elif defined(__clang__)
00608
00609 # define GTEST_HAS_RTTI __has_feature(cxx_rtti)
00610
00611
00612
00613 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
00614
00615 # ifdef __RTTI_ALL__
00616 # define GTEST_HAS_RTTI 1
00617 # else
00618 # define GTEST_HAS_RTTI 0
00619 # endif
00620
00621 # else
00622
00623
00624 # define GTEST_HAS_RTTI 1
00625
00626 # endif // _MSC_VER
00627
00628 #endif // GTEST_HAS_RTTI
00629
00630
00631
00632 #if GTEST_HAS_RTTI
00633 # include <typeinfo>
00634 #endif
00635
00636
00637 #ifndef GTEST_HAS_PTHREAD
00638
00639
00640
00641
00642
00643 # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \
00644 || GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NACL)
00645 #endif // GTEST_HAS_PTHREAD
00646
00647 #if GTEST_HAS_PTHREAD
00648
00649
00650 # include <pthread.h>
00651
00652
00653 # include <time.h>
00654 #endif
00655
00656
00657
00658
00659 #ifndef GTEST_HAS_TR1_TUPLE
00660 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
00661
00662 # define GTEST_HAS_TR1_TUPLE 0
00663 # else
00664
00665 # define GTEST_HAS_TR1_TUPLE 1
00666 # endif
00667 #endif // GTEST_HAS_TR1_TUPLE
00668
00669
00670
00671 #ifndef GTEST_USE_OWN_TR1_TUPLE
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
00685 && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600
00686 # define GTEST_ENV_HAS_TR1_TUPLE_ 1
00687 # endif
00688
00689
00690
00691
00692 # if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
00693 # define GTEST_ENV_HAS_STD_TUPLE_ 1
00694 # endif
00695
00696 # if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
00697 # define GTEST_USE_OWN_TR1_TUPLE 0
00698 # else
00699 # define GTEST_USE_OWN_TR1_TUPLE 1
00700 # endif
00701
00702 #endif // GTEST_USE_OWN_TR1_TUPLE
00703
00704
00705
00706
00707 #if GTEST_HAS_STD_TUPLE_
00708 # include <tuple>
00709 # define GTEST_TUPLE_NAMESPACE_ ::std
00710 #endif // GTEST_HAS_STD_TUPLE_
00711
00712
00713
00714 #if GTEST_HAS_TR1_TUPLE
00715 # ifndef GTEST_TUPLE_NAMESPACE_
00716 # define GTEST_TUPLE_NAMESPACE_ ::std::tr1
00717 # endif // GTEST_TUPLE_NAMESPACE_
00718
00719 # if GTEST_USE_OWN_TR1_TUPLE
00720 # include "gtest/internal/gtest-tuple.h"
00721 # elif GTEST_ENV_HAS_STD_TUPLE_
00722 # include <tuple>
00723
00724
00725
00726
00727 namespace std {
00728 namespace tr1 {
00729 using ::std::get;
00730 using ::std::make_tuple;
00731 using ::std::tuple;
00732 using ::std::tuple_element;
00733 using ::std::tuple_size;
00734 }
00735 }
00736
00737 # elif GTEST_OS_SYMBIAN
00738
00739
00740
00741
00742
00743
00744 # ifdef BOOST_HAS_TR1_TUPLE
00745 # undef BOOST_HAS_TR1_TUPLE
00746 # endif // BOOST_HAS_TR1_TUPLE
00747
00748
00749
00750 # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
00751 # include <tuple>
00752
00753 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
00754
00755
00756
00757 # if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
00758
00759
00760
00761
00762
00763 # define _TR1_FUNCTIONAL 1
00764 # include <tr1/tuple>
00765 # undef _TR1_FUNCTIONAL // Allows the user to #include
00766
00767 # else
00768 # include <tr1/tuple>
00769 # endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
00770
00771 # else
00772
00773
00774 # include <tuple>
00775 # endif // GTEST_USE_OWN_TR1_TUPLE
00776
00777 #endif // GTEST_HAS_TR1_TUPLE
00778
00779
00780
00781
00782
00783 #ifndef GTEST_HAS_CLONE
00784
00785
00786 # if GTEST_OS_LINUX && !defined(__ia64__)
00787 # if GTEST_OS_LINUX_ANDROID
00788
00789 # if defined(__arm__) && __ANDROID_API__ >= 9
00790 # define GTEST_HAS_CLONE 1
00791 # else
00792 # define GTEST_HAS_CLONE 0
00793 # endif
00794 # else
00795 # define GTEST_HAS_CLONE 1
00796 # endif
00797 # else
00798 # define GTEST_HAS_CLONE 0
00799 # endif // GTEST_OS_LINUX && !defined(__ia64__)
00800
00801 #endif // GTEST_HAS_CLONE
00802
00803
00804
00805 #ifndef GTEST_HAS_STREAM_REDIRECTION
00806
00807
00808 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \
00809 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
00810 # define GTEST_HAS_STREAM_REDIRECTION 0
00811 # else
00812 # define GTEST_HAS_STREAM_REDIRECTION 1
00813 # endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
00814 #endif // GTEST_HAS_STREAM_REDIRECTION
00815
00816
00817
00818
00819
00820 #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
00821 (GTEST_OS_MAC && !GTEST_OS_IOS) || \
00822 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
00823 GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
00824 GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD)
00825 # define GTEST_HAS_DEATH_TEST 1
00826 # include <vector>
00827 #endif
00828
00829
00830
00831
00832 #define GTEST_HAS_PARAM_TEST 1
00833
00834
00835
00836
00837
00838 #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
00839 defined(__IBMCPP__) || defined(__HP_aCC)
00840 # define GTEST_HAS_TYPED_TEST 1
00841 # define GTEST_HAS_TYPED_TEST_P 1
00842 #endif
00843
00844
00845
00846
00847
00848 #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
00849 # define GTEST_HAS_COMBINE 1
00850 #endif
00851
00852
00853 #define GTEST_WIDE_STRING_USES_UTF16_ \
00854 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
00855
00856
00857 #if GTEST_OS_LINUX
00858 # define GTEST_CAN_STREAM_RESULTS_ 1
00859 #endif
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871 #ifdef __INTEL_COMPILER
00872 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
00873 #else
00874 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT
00875 #endif
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888 #if defined(__GNUC__) && !defined(COMPILER_ICC)
00889 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
00890 #elif defined(__clang__)
00891 # if __has_attribute(unused)
00892 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
00893 # endif
00894 #endif
00895 #ifndef GTEST_ATTRIBUTE_UNUSED_
00896 # define GTEST_ATTRIBUTE_UNUSED_
00897 #endif
00898
00899
00900
00901 #define GTEST_DISALLOW_ASSIGN_(type)\
00902 void operator=(type const &)
00903
00904
00905
00906 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
00907 type(type const &);\
00908 GTEST_DISALLOW_ASSIGN_(type)
00909
00910
00911
00912
00913
00914
00915 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
00916 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
00917 #else
00918 # define GTEST_MUST_USE_RESULT_
00919 #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929 # define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
00930 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
00931 # define GTEST_INTENTIONAL_CONST_COND_POP_() \
00932 GTEST_DISABLE_MSC_WARNINGS_POP_()
00933
00934
00935
00936
00937 #ifndef GTEST_HAS_SEH
00938
00939
00940 # if defined(_MSC_VER) || defined(__BORLANDC__)
00941
00942 # define GTEST_HAS_SEH 1
00943 # else
00944
00945 # define GTEST_HAS_SEH 0
00946 # endif
00947
00948 #define GTEST_IS_THREADSAFE \
00949 (0 \
00950 || (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) \
00951 || GTEST_HAS_PTHREAD)
00952
00953 #endif // GTEST_HAS_SEH
00954
00955 #ifdef _MSC_VER
00956
00957 # if GTEST_LINKED_AS_SHARED_LIBRARY
00958 # define GTEST_API_ __declspec(dllimport)
00959 # elif GTEST_CREATE_SHARED_LIBRARY
00960 # define GTEST_API_ __declspec(dllexport)
00961 # endif
00962
00963 #endif // _MSC_VER
00964
00965 #ifndef GTEST_API_
00966 # define GTEST_API_
00967 #endif
00968
00969 #ifdef __GNUC__
00970
00971 # define GTEST_NO_INLINE_ __attribute__((noinline))
00972 #else
00973 # define GTEST_NO_INLINE_
00974 #endif
00975
00976
00977 #if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
00978 # define GTEST_HAS_CXXABI_H_ 1
00979 #else
00980 # define GTEST_HAS_CXXABI_H_ 0
00981 #endif
00982
00983
00984
00985 #if defined(__clang__)
00986 # if __has_feature(memory_sanitizer)
00987 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
00988 __attribute__((no_sanitize_memory))
00989 # else
00990 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
00991 # endif // __has_feature(memory_sanitizer)
00992 #else
00993 # define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
00994 #endif // __clang__
00995
00996
00997 #if defined(__clang__)
00998 # if __has_feature(address_sanitizer)
00999 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
01000 __attribute__((no_sanitize_address))
01001 # else
01002 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
01003 # endif // __has_feature(address_sanitizer)
01004 #else
01005 # define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
01006 #endif // __clang__
01007
01008
01009 #if defined(__clang__)
01010 # if __has_feature(thread_sanitizer)
01011 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
01012 __attribute__((no_sanitize_thread))
01013 # else
01014 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
01015 # endif // __has_feature(thread_sanitizer)
01016 #else
01017 # define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
01018 #endif // __clang__
01019
01020 namespace testing {
01021
01022 class Message;
01023
01024 #if defined(GTEST_TUPLE_NAMESPACE_)
01025
01026
01027
01028 using GTEST_TUPLE_NAMESPACE_::get;
01029 using GTEST_TUPLE_NAMESPACE_::make_tuple;
01030 using GTEST_TUPLE_NAMESPACE_::tuple;
01031 using GTEST_TUPLE_NAMESPACE_::tuple_size;
01032 using GTEST_TUPLE_NAMESPACE_::tuple_element;
01033 #endif // defined(GTEST_TUPLE_NAMESPACE_)
01034
01035 namespace internal {
01036
01037
01038
01039
01040 class Secret;
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057 #if GTEST_LANG_CXX11
01058 # define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
01059 #else // !GTEST_LANG_CXX11
01060 template <bool>
01061 struct CompileAssert {
01062 };
01063
01064 # define GTEST_COMPILE_ASSERT_(expr, msg) \
01065 typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
01066 msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
01067 #endif // !GTEST_LANG_CXX11
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115 template <typename T1, typename T2>
01116 struct StaticAssertTypeEqHelper;
01117
01118 template <typename T>
01119 struct StaticAssertTypeEqHelper<T, T> {
01120 enum { value = true };
01121 };
01122
01123
01124 #define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
01125
01126 #if GTEST_HAS_GLOBAL_STRING
01127 typedef ::string string;
01128 #else
01129 typedef ::std::string string;
01130 #endif // GTEST_HAS_GLOBAL_STRING
01131
01132 #if GTEST_HAS_GLOBAL_WSTRING
01133 typedef ::wstring wstring;
01134 #elif GTEST_HAS_STD_WSTRING
01135 typedef ::std::wstring wstring;
01136 #endif // GTEST_HAS_GLOBAL_WSTRING
01137
01138
01139
01140 GTEST_API_ bool IsTrue(bool condition);
01141
01142
01143
01144
01145
01146 template <typename T>
01147 class scoped_ptr {
01148 public:
01149 typedef T element_type;
01150
01151 explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
01152 ~scoped_ptr() { reset(); }
01153
01154 T& operator*() const { return *ptr_; }
01155 T* operator->() const { return ptr_; }
01156 T* get() const { return ptr_; }
01157
01158 T* release() {
01159 T* const ptr = ptr_;
01160 ptr_ = NULL;
01161 return ptr;
01162 }
01163
01164 void reset(T* p = NULL) {
01165 if (p != ptr_) {
01166 if (IsTrue(sizeof(T) > 0)) {
01167 delete ptr_;
01168 }
01169 ptr_ = p;
01170 }
01171 }
01172
01173 friend void swap(scoped_ptr& a, scoped_ptr& b) {
01174 using std::swap;
01175 swap(a.ptr_, b.ptr_);
01176 }
01177
01178 private:
01179 T* ptr_;
01180
01181 GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
01182 };
01183
01184
01185
01186
01187
01188 class GTEST_API_ RE {
01189 public:
01190
01191
01192 RE(const RE& other) { Init(other.pattern()); }
01193
01194
01195 RE(const ::std::string& regex) { Init(regex.c_str()); }
01196
01197 #if GTEST_HAS_GLOBAL_STRING
01198
01199 RE(const ::string& regex) { Init(regex.c_str()); }
01200
01201 #endif // GTEST_HAS_GLOBAL_STRING
01202
01203 RE(const char* regex) { Init(regex); }
01204 ~RE();
01205
01206
01207 const char* pattern() const { return pattern_; }
01208
01209
01210
01211
01212
01213
01214
01215
01216 static bool FullMatch(const ::std::string& str, const RE& re) {
01217 return FullMatch(str.c_str(), re);
01218 }
01219 static bool PartialMatch(const ::std::string& str, const RE& re) {
01220 return PartialMatch(str.c_str(), re);
01221 }
01222
01223 #if GTEST_HAS_GLOBAL_STRING
01224
01225 static bool FullMatch(const ::string& str, const RE& re) {
01226 return FullMatch(str.c_str(), re);
01227 }
01228 static bool PartialMatch(const ::string& str, const RE& re) {
01229 return PartialMatch(str.c_str(), re);
01230 }
01231
01232 #endif // GTEST_HAS_GLOBAL_STRING
01233
01234 static bool FullMatch(const char* str, const RE& re);
01235 static bool PartialMatch(const char* str, const RE& re);
01236
01237 private:
01238 void Init(const char* regex);
01239
01240
01241
01242
01243 const char* pattern_;
01244 bool is_valid_;
01245
01246 #if GTEST_USES_POSIX_RE
01247
01248 regex_t full_regex_;
01249 regex_t partial_regex_;
01250
01251 #else // GTEST_USES_SIMPLE_RE
01252
01253 const char* full_pattern_;
01254
01255 #endif
01256
01257 GTEST_DISALLOW_ASSIGN_(RE);
01258 };
01259
01260
01261
01262 GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
01263
01264
01265
01266
01267 GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
01268 int line);
01269
01270
01271
01272
01273
01274
01275
01276 enum GTestLogSeverity {
01277 GTEST_INFO,
01278 GTEST_WARNING,
01279 GTEST_ERROR,
01280 GTEST_FATAL
01281 };
01282
01283
01284
01285
01286 class GTEST_API_ GTestLog {
01287 public:
01288 GTestLog(GTestLogSeverity severity, const char* file, int line);
01289
01290
01291 ~GTestLog();
01292
01293 ::std::ostream& GetStream() { return ::std::cerr; }
01294
01295 private:
01296 const GTestLogSeverity severity_;
01297
01298 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
01299 };
01300
01301 #define GTEST_LOG_(severity) \
01302 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
01303 __FILE__, __LINE__).GetStream()
01304
01305 inline void LogToStderr() {}
01306 inline void FlushInfoLog() { fflush(NULL); }
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322 #define GTEST_CHECK_(condition) \
01323 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01324 if (::testing::internal::IsTrue(condition)) \
01325 ; \
01326 else \
01327 GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
01328
01329
01330
01331
01332
01333
01334 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
01335 if (const int gtest_error = (posix_call)) \
01336 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
01337 << gtest_error
01338
01339 #if GTEST_HAS_STD_MOVE_
01340 using std::move;
01341 #else // GTEST_HAS_STD_MOVE_
01342 template <typename T>
01343 const T& move(const T& t) {
01344 return t;
01345 }
01346 #endif // GTEST_HAS_STD_MOVE_
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368 template<typename To>
01369 inline To ImplicitCast_(To x) { return ::testing::internal::move(x); }
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392 template<typename To, typename From>
01393 inline To DownCast_(From* f) {
01394
01395
01396
01397
01398 GTEST_INTENTIONAL_CONST_COND_PUSH_()
01399 if (false) {
01400 GTEST_INTENTIONAL_CONST_COND_POP_()
01401 const To to = NULL;
01402 ::testing::internal::ImplicitCast_<From*>(to);
01403 }
01404
01405 #if GTEST_HAS_RTTI
01406
01407 GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
01408 #endif
01409 return static_cast<To>(f);
01410 }
01411
01412
01413
01414
01415
01416
01417 template <class Derived, class Base>
01418 Derived* CheckedDowncastToActualType(Base* base) {
01419 #if GTEST_HAS_RTTI
01420 GTEST_CHECK_(typeid(*base) == typeid(Derived));
01421 return dynamic_cast<Derived*>(base);
01422 #else
01423 return static_cast<Derived*>(base);
01424 #endif
01425 }
01426
01427 #if GTEST_HAS_STREAM_REDIRECTION
01428
01429
01430
01431
01432
01433
01434
01435 GTEST_API_ void CaptureStdout();
01436 GTEST_API_ std::string GetCapturedStdout();
01437 GTEST_API_ void CaptureStderr();
01438 GTEST_API_ std::string GetCapturedStderr();
01439
01440 #endif // GTEST_HAS_STREAM_REDIRECTION
01441
01442
01443 #if GTEST_HAS_DEATH_TEST
01444
01445 const ::std::vector<testing::internal::string>& GetInjectableArgvs();
01446 void SetInjectableArgvs(const ::std::vector<testing::internal::string>*
01447 new_argvs);
01448
01449
01450 extern ::std::vector<testing::internal::string> g_argvs;
01451
01452 #endif // GTEST_HAS_DEATH_TEST
01453
01454
01455 #if GTEST_IS_THREADSAFE
01456 # if GTEST_HAS_PTHREAD
01457
01458
01459
01460 inline void SleepMilliseconds(int n) {
01461 const timespec time = {
01462 0,
01463 n * 1000L * 1000L,
01464 };
01465 nanosleep(&time, NULL);
01466 }
01467 # endif // GTEST_HAS_PTHREAD
01468
01469 # if 0 // OS detection
01470 # elif GTEST_HAS_PTHREAD
01471
01472
01473
01474
01475
01476
01477 class Notification {
01478 public:
01479 Notification() : notified_(false) {
01480 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
01481 }
01482 ~Notification() {
01483 pthread_mutex_destroy(&mutex_);
01484 }
01485
01486
01487
01488 void Notify() {
01489 pthread_mutex_lock(&mutex_);
01490 notified_ = true;
01491 pthread_mutex_unlock(&mutex_);
01492 }
01493
01494
01495
01496 void WaitForNotification() {
01497 for (;;) {
01498 pthread_mutex_lock(&mutex_);
01499 const bool notified = notified_;
01500 pthread_mutex_unlock(&mutex_);
01501 if (notified)
01502 break;
01503 SleepMilliseconds(10);
01504 }
01505 }
01506
01507 private:
01508 pthread_mutex_t mutex_;
01509 bool notified_;
01510
01511 GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
01512 };
01513
01514 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
01515
01516 GTEST_API_ void SleepMilliseconds(int n);
01517
01518
01519
01520 class GTEST_API_ AutoHandle {
01521 public:
01522
01523
01524
01525
01526
01527 typedef void* Handle;
01528 AutoHandle();
01529 explicit AutoHandle(Handle handle);
01530
01531 ~AutoHandle();
01532
01533 Handle Get() const;
01534 void Reset();
01535 void Reset(Handle handle);
01536
01537 private:
01538
01539 bool IsCloseable() const;
01540
01541 Handle handle_;
01542
01543 GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
01544 };
01545
01546
01547
01548
01549
01550
01551
01552 class GTEST_API_ Notification {
01553 public:
01554 Notification();
01555 void Notify();
01556 void WaitForNotification();
01557
01558 private:
01559 AutoHandle event_;
01560
01561 GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
01562 };
01563 # endif // OS detection
01564
01565
01566
01567
01568 # if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
01569
01570
01571
01572
01573
01574
01575 class ThreadWithParamBase {
01576 public:
01577 virtual ~ThreadWithParamBase() {}
01578 virtual void Run() = 0;
01579 };
01580
01581
01582
01583
01584
01585
01586
01587 extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
01588 static_cast<ThreadWithParamBase*>(thread)->Run();
01589 return NULL;
01590 }
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604 template <typename T>
01605 class ThreadWithParam : public ThreadWithParamBase {
01606 public:
01607 typedef void UserThreadFunc(T);
01608
01609 ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
01610 : func_(func),
01611 param_(param),
01612 thread_can_start_(thread_can_start),
01613 finished_(false) {
01614 ThreadWithParamBase* const base = this;
01615
01616
01617 GTEST_CHECK_POSIX_SUCCESS_(
01618 pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
01619 }
01620 ~ThreadWithParam() { Join(); }
01621
01622 void Join() {
01623 if (!finished_) {
01624 GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
01625 finished_ = true;
01626 }
01627 }
01628
01629 virtual void Run() {
01630 if (thread_can_start_ != NULL)
01631 thread_can_start_->WaitForNotification();
01632 func_(param_);
01633 }
01634
01635 private:
01636 UserThreadFunc* const func_;
01637 const T param_;
01638
01639
01640 Notification* const thread_can_start_;
01641 bool finished_;
01642 pthread_t thread_;
01643
01644 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
01645 };
01646 # endif // GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
01647
01648 # if 0 // OS detection
01649 # elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665 class GTEST_API_ Mutex {
01666 public:
01667 enum MutexType { kStatic = 0, kDynamic = 1 };
01668
01669
01670
01671 enum StaticConstructorSelector { kStaticMutex = 0 };
01672
01673
01674
01675
01676 explicit Mutex(StaticConstructorSelector ) {}
01677
01678 Mutex();
01679 ~Mutex();
01680
01681 void Lock();
01682
01683 void Unlock();
01684
01685
01686
01687 void AssertHeld();
01688
01689 private:
01690
01691 void ThreadSafeLazyInit();
01692
01693
01694
01695 unsigned int owner_thread_id_;
01696
01697
01698
01699 MutexType type_;
01700 long critical_section_init_phase_;
01701 _RTL_CRITICAL_SECTION* critical_section_;
01702
01703 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
01704 };
01705
01706 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
01707 extern ::testing::internal::Mutex mutex
01708
01709 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
01710 ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
01711
01712
01713
01714
01715
01716
01717 class GTestMutexLock {
01718 public:
01719 explicit GTestMutexLock(Mutex* mutex)
01720 : mutex_(mutex) { mutex_->Lock(); }
01721
01722 ~GTestMutexLock() { mutex_->Unlock(); }
01723
01724 private:
01725 Mutex* const mutex_;
01726
01727 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
01728 };
01729
01730 typedef GTestMutexLock MutexLock;
01731
01732
01733
01734 class ThreadLocalValueHolderBase {
01735 public:
01736 virtual ~ThreadLocalValueHolderBase() {}
01737 };
01738
01739
01740
01741 class ThreadLocalBase {
01742 public:
01743
01744
01745
01746
01747 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
01748
01749 protected:
01750 ThreadLocalBase() {}
01751 virtual ~ThreadLocalBase() {}
01752
01753 private:
01754 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase);
01755 };
01756
01757
01758
01759
01760 class GTEST_API_ ThreadLocalRegistry {
01761 public:
01762
01763
01764 static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
01765 const ThreadLocalBase* thread_local_instance);
01766
01767
01768 static void OnThreadLocalDestroyed(
01769 const ThreadLocalBase* thread_local_instance);
01770 };
01771
01772 class GTEST_API_ ThreadWithParamBase {
01773 public:
01774 void Join();
01775
01776 protected:
01777 class Runnable {
01778 public:
01779 virtual ~Runnable() {}
01780 virtual void Run() = 0;
01781 };
01782
01783 ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
01784 virtual ~ThreadWithParamBase();
01785
01786 private:
01787 AutoHandle thread_;
01788 };
01789
01790
01791 template <typename T>
01792 class ThreadWithParam : public ThreadWithParamBase {
01793 public:
01794 typedef void UserThreadFunc(T);
01795
01796 ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
01797 : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {
01798 }
01799 virtual ~ThreadWithParam() {}
01800
01801 private:
01802 class RunnableImpl : public Runnable {
01803 public:
01804 RunnableImpl(UserThreadFunc* func, T param)
01805 : func_(func),
01806 param_(param) {
01807 }
01808 virtual ~RunnableImpl() {}
01809 virtual void Run() {
01810 func_(param_);
01811 }
01812
01813 private:
01814 UserThreadFunc* const func_;
01815 const T param_;
01816
01817 GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl);
01818 };
01819
01820 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
01821 };
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850 template <typename T>
01851 class ThreadLocal : public ThreadLocalBase {
01852 public:
01853 ThreadLocal() : default_() {}
01854 explicit ThreadLocal(const T& value) : default_(value) {}
01855
01856 ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); }
01857
01858 T* pointer() { return GetOrCreateValue(); }
01859 const T* pointer() const { return GetOrCreateValue(); }
01860 const T& get() const { return *pointer(); }
01861 void set(const T& value) { *pointer() = value; }
01862
01863 private:
01864
01865
01866 class ValueHolder : public ThreadLocalValueHolderBase {
01867 public:
01868 explicit ValueHolder(const T& value) : value_(value) {}
01869
01870 T* pointer() { return &value_; }
01871
01872 private:
01873 T value_;
01874 GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
01875 };
01876
01877
01878 T* GetOrCreateValue() const {
01879 return static_cast<ValueHolder*>(
01880 ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer();
01881 }
01882
01883 virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const {
01884 return new ValueHolder(default_);
01885 }
01886
01887 const T default_;
01888
01889 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
01890 };
01891
01892 # elif GTEST_HAS_PTHREAD
01893
01894
01895 class MutexBase {
01896 public:
01897
01898 void Lock() {
01899 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
01900 owner_ = pthread_self();
01901 has_owner_ = true;
01902 }
01903
01904
01905 void Unlock() {
01906
01907
01908
01909
01910 has_owner_ = false;
01911 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
01912 }
01913
01914
01915
01916 void AssertHeld() const {
01917 GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
01918 << "The current thread is not holding the mutex @" << this;
01919 }
01920
01921
01922
01923
01924
01925
01926 public:
01927 pthread_mutex_t mutex_;
01928
01929
01930
01931
01932
01933
01934 bool has_owner_;
01935 pthread_t owner_;
01936 };
01937
01938
01939 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
01940 extern ::testing::internal::MutexBase mutex
01941
01942
01943
01944
01945
01946
01947
01948 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
01949 ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
01950
01951
01952
01953 class Mutex : public MutexBase {
01954 public:
01955 Mutex() {
01956 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
01957 has_owner_ = false;
01958 }
01959 ~Mutex() {
01960 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
01961 }
01962
01963 private:
01964 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
01965 };
01966
01967
01968
01969
01970
01971
01972 class GTestMutexLock {
01973 public:
01974 explicit GTestMutexLock(MutexBase* mutex)
01975 : mutex_(mutex) { mutex_->Lock(); }
01976
01977 ~GTestMutexLock() { mutex_->Unlock(); }
01978
01979 private:
01980 MutexBase* const mutex_;
01981
01982 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
01983 };
01984
01985 typedef GTestMutexLock MutexLock;
01986
01987
01988
01989
01990
01991
01992
01993 class ThreadLocalValueHolderBase {
01994 public:
01995 virtual ~ThreadLocalValueHolderBase() {}
01996 };
01997
01998
01999
02000 extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
02001 delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
02002 }
02003
02004
02005 template <typename T>
02006 class ThreadLocal {
02007 public:
02008 ThreadLocal() : key_(CreateKey()),
02009 default_() {}
02010 explicit ThreadLocal(const T& value) : key_(CreateKey()),
02011 default_(value) {}
02012
02013 ~ThreadLocal() {
02014
02015 DeleteThreadLocalValue(pthread_getspecific(key_));
02016
02017
02018
02019 GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
02020 }
02021
02022 T* pointer() { return GetOrCreateValue(); }
02023 const T* pointer() const { return GetOrCreateValue(); }
02024 const T& get() const { return *pointer(); }
02025 void set(const T& value) { *pointer() = value; }
02026
02027 private:
02028
02029 class ValueHolder : public ThreadLocalValueHolderBase {
02030 public:
02031 explicit ValueHolder(const T& value) : value_(value) {}
02032
02033 T* pointer() { return &value_; }
02034
02035 private:
02036 T value_;
02037 GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
02038 };
02039
02040 static pthread_key_t CreateKey() {
02041 pthread_key_t key;
02042
02043
02044 GTEST_CHECK_POSIX_SUCCESS_(
02045 pthread_key_create(&key, &DeleteThreadLocalValue));
02046 return key;
02047 }
02048
02049 T* GetOrCreateValue() const {
02050 ThreadLocalValueHolderBase* const holder =
02051 static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
02052 if (holder != NULL) {
02053 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
02054 }
02055
02056 ValueHolder* const new_holder = new ValueHolder(default_);
02057 ThreadLocalValueHolderBase* const holder_base = new_holder;
02058 GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
02059 return new_holder->pointer();
02060 }
02061
02062
02063 const pthread_key_t key_;
02064 const T default_;
02065
02066 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
02067 };
02068
02069 # endif // OS detection
02070
02071 #else // GTEST_IS_THREADSAFE
02072
02073
02074
02075
02076
02077
02078 class Mutex {
02079 public:
02080 Mutex() {}
02081 void Lock() {}
02082 void Unlock() {}
02083 void AssertHeld() const {}
02084 };
02085
02086 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
02087 extern ::testing::internal::Mutex mutex
02088
02089 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
02090
02091
02092
02093
02094
02095
02096 class GTestMutexLock {
02097 public:
02098 explicit GTestMutexLock(Mutex*) {}
02099 };
02100
02101 typedef GTestMutexLock MutexLock;
02102
02103 template <typename T>
02104 class ThreadLocal {
02105 public:
02106 ThreadLocal() : value_() {}
02107 explicit ThreadLocal(const T& value) : value_(value) {}
02108 T* pointer() { return &value_; }
02109 const T* pointer() const { return &value_; }
02110 const T& get() const { return value_; }
02111 void set(const T& value) { value_ = value; }
02112 private:
02113 T value_;
02114 };
02115
02116 #endif // GTEST_IS_THREADSAFE
02117
02118
02119
02120 GTEST_API_ size_t GetThreadCount();
02121
02122
02123
02124
02125
02126
02127
02128 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
02129
02130
02131 # define GTEST_ELLIPSIS_NEEDS_POD_ 1
02132 #else
02133 # define GTEST_CAN_COMPARE_NULL 1
02134 #endif
02135
02136
02137
02138
02139
02140 #if defined(__SYMBIAN32__) || defined(__IBMCPP__)
02141 # define GTEST_NEEDS_IS_POINTER_ 1
02142 #endif
02143
02144 template <bool bool_value>
02145 struct bool_constant {
02146 typedef bool_constant<bool_value> type;
02147 static const bool value = bool_value;
02148 };
02149 template <bool bool_value> const bool bool_constant<bool_value>::value;
02150
02151 typedef bool_constant<false> false_type;
02152 typedef bool_constant<true> true_type;
02153
02154 template <typename T>
02155 struct is_pointer : public false_type {};
02156
02157 template <typename T>
02158 struct is_pointer<T*> : public true_type {};
02159
02160 template <typename Iterator>
02161 struct IteratorTraits {
02162 typedef typename Iterator::value_type value_type;
02163 };
02164
02165 template <typename T>
02166 struct IteratorTraits<T*> {
02167 typedef T value_type;
02168 };
02169
02170 template <typename T>
02171 struct IteratorTraits<const T*> {
02172 typedef T value_type;
02173 };
02174
02175 #if GTEST_OS_WINDOWS
02176 # define GTEST_PATH_SEP_ "\\"
02177 # define GTEST_HAS_ALT_PATH_SEP_ 1
02178
02179 typedef __int64 BiggestInt;
02180 #else
02181 # define GTEST_PATH_SEP_ "/"
02182 # define GTEST_HAS_ALT_PATH_SEP_ 0
02183 typedef long long BiggestInt;
02184 #endif // GTEST_OS_WINDOWS
02185
02186
02187
02188
02189
02190
02191
02192
02193 inline bool IsAlpha(char ch) {
02194 return isalpha(static_cast<unsigned char>(ch)) != 0;
02195 }
02196 inline bool IsAlNum(char ch) {
02197 return isalnum(static_cast<unsigned char>(ch)) != 0;
02198 }
02199 inline bool IsDigit(char ch) {
02200 return isdigit(static_cast<unsigned char>(ch)) != 0;
02201 }
02202 inline bool IsLower(char ch) {
02203 return islower(static_cast<unsigned char>(ch)) != 0;
02204 }
02205 inline bool IsSpace(char ch) {
02206 return isspace(static_cast<unsigned char>(ch)) != 0;
02207 }
02208 inline bool IsUpper(char ch) {
02209 return isupper(static_cast<unsigned char>(ch)) != 0;
02210 }
02211 inline bool IsXDigit(char ch) {
02212 return isxdigit(static_cast<unsigned char>(ch)) != 0;
02213 }
02214 inline bool IsXDigit(wchar_t ch) {
02215 const unsigned char low_byte = static_cast<unsigned char>(ch);
02216 return ch == low_byte && isxdigit(low_byte) != 0;
02217 }
02218
02219 inline char ToLower(char ch) {
02220 return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
02221 }
02222 inline char ToUpper(char ch) {
02223 return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
02224 }
02225
02226 inline std::string StripTrailingSpaces(std::string str) {
02227 std::string::iterator it = str.end();
02228 while (it != str.begin() && IsSpace(*--it))
02229 it = str.erase(it);
02230 return str;
02231 }
02232
02233
02234
02235
02236
02237
02238
02239 namespace posix {
02240
02241
02242
02243 #if GTEST_OS_WINDOWS
02244
02245 typedef struct _stat StatStruct;
02246
02247 # ifdef __BORLANDC__
02248 inline int IsATTY(int fd) { return isatty(fd); }
02249 inline int StrCaseCmp(const char* s1, const char* s2) {
02250 return stricmp(s1, s2);
02251 }
02252 inline char* StrDup(const char* src) { return strdup(src); }
02253 # else // !__BORLANDC__
02254 # if GTEST_OS_WINDOWS_MOBILE
02255 inline int IsATTY(int ) { return 0; }
02256 # else
02257 inline int IsATTY(int fd) { return _isatty(fd); }
02258 # endif // GTEST_OS_WINDOWS_MOBILE
02259 inline int StrCaseCmp(const char* s1, const char* s2) {
02260 return _stricmp(s1, s2);
02261 }
02262 inline char* StrDup(const char* src) { return _strdup(src); }
02263 # endif // __BORLANDC__
02264
02265 # if GTEST_OS_WINDOWS_MOBILE
02266 inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
02267
02268
02269 # else
02270 inline int FileNo(FILE* file) { return _fileno(file); }
02271 inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
02272 inline int RmDir(const char* dir) { return _rmdir(dir); }
02273 inline bool IsDir(const StatStruct& st) {
02274 return (_S_IFDIR & st.st_mode) != 0;
02275 }
02276 # endif // GTEST_OS_WINDOWS_MOBILE
02277
02278 #else
02279
02280 typedef struct stat StatStruct;
02281
02282 inline int FileNo(FILE* file) { return fileno(file); }
02283 inline int IsATTY(int fd) { return isatty(fd); }
02284 inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
02285 inline int StrCaseCmp(const char* s1, const char* s2) {
02286 return strcasecmp(s1, s2);
02287 }
02288 inline char* StrDup(const char* src) { return strdup(src); }
02289 inline int RmDir(const char* dir) { return rmdir(dir); }
02290 inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
02291
02292 #endif // GTEST_OS_WINDOWS
02293
02294
02295
02296 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 )
02297
02298 inline const char* StrNCpy(char* dest, const char* src, size_t n) {
02299 return strncpy(dest, src, n);
02300 }
02301
02302
02303
02304
02305
02306 #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
02307 inline int ChDir(const char* dir) { return chdir(dir); }
02308 #endif
02309 inline FILE* FOpen(const char* path, const char* mode) {
02310 return fopen(path, mode);
02311 }
02312 #if !GTEST_OS_WINDOWS_MOBILE
02313 inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
02314 return freopen(path, mode, stream);
02315 }
02316 inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
02317 #endif
02318 inline int FClose(FILE* fp) { return fclose(fp); }
02319 #if !GTEST_OS_WINDOWS_MOBILE
02320 inline int Read(int fd, void* buf, unsigned int count) {
02321 return static_cast<int>(read(fd, buf, count));
02322 }
02323 inline int Write(int fd, const void* buf, unsigned int count) {
02324 return static_cast<int>(write(fd, buf, count));
02325 }
02326 inline int Close(int fd) { return close(fd); }
02327 inline const char* StrError(int errnum) { return strerror(errnum); }
02328 #endif
02329 inline const char* GetEnv(const char* name) {
02330 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE | GTEST_OS_WINDOWS_RT
02331
02332 static_cast<void>(name);
02333 return NULL;
02334 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
02335
02336
02337 const char* const env = getenv(name);
02338 return (env != NULL && env[0] != '\0') ? env : NULL;
02339 #else
02340 return getenv(name);
02341 #endif
02342 }
02343
02344 GTEST_DISABLE_MSC_WARNINGS_POP_()
02345
02346 #if GTEST_OS_WINDOWS_MOBILE
02347
02348
02349
02350 void Abort();
02351 #else
02352 inline void Abort() { abort(); }
02353 #endif // GTEST_OS_WINDOWS_MOBILE
02354
02355 }
02356
02357
02358
02359
02360
02361
02362 #if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
02363
02364 # define GTEST_SNPRINTF_(buffer, size, format, ...) \
02365 _snprintf_s(buffer, size, size, format, __VA_ARGS__)
02366 #elif defined(_MSC_VER)
02367
02368
02369 # define GTEST_SNPRINTF_ _snprintf
02370 #else
02371 # define GTEST_SNPRINTF_ snprintf
02372 #endif
02373
02374
02375
02376
02377
02378
02379
02380
02381 const BiggestInt kMaxBiggestInt =
02382 ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402 template <size_t size>
02403 class TypeWithSize {
02404 public:
02405
02406
02407 typedef void UInt;
02408 };
02409
02410
02411 template <>
02412 class TypeWithSize<4> {
02413 public:
02414
02415
02416
02417
02418 typedef int Int;
02419 typedef unsigned int UInt;
02420 };
02421
02422
02423 template <>
02424 class TypeWithSize<8> {
02425 public:
02426 #if GTEST_OS_WINDOWS
02427 typedef __int64 Int;
02428 typedef unsigned __int64 UInt;
02429 #else
02430 typedef long long Int;
02431 typedef unsigned long long UInt;
02432 #endif // GTEST_OS_WINDOWS
02433 };
02434
02435
02436 typedef TypeWithSize<4>::Int Int32;
02437 typedef TypeWithSize<4>::UInt UInt32;
02438 typedef TypeWithSize<8>::Int Int64;
02439 typedef TypeWithSize<8>::UInt UInt64;
02440 typedef TypeWithSize<8>::Int TimeInMillis;
02441
02442
02443
02444
02445 #define GTEST_FLAG(name) FLAGS_gtest_##name
02446
02447
02448 #define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
02449 #define GTEST_DECLARE_int32_(name) \
02450 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
02451 #define GTEST_DECLARE_string_(name) \
02452 GTEST_API_ extern ::std::string GTEST_FLAG(name)
02453
02454
02455 #define GTEST_DEFINE_bool_(name, default_val, doc) \
02456 GTEST_API_ bool GTEST_FLAG(name) = (default_val)
02457 #define GTEST_DEFINE_int32_(name, default_val, doc) \
02458 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
02459 #define GTEST_DEFINE_string_(name, default_val, doc) \
02460 GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
02461
02462
02463 #define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
02464 #define GTEST_LOCK_EXCLUDED_(locks)
02465
02466
02467
02468
02469
02470
02471
02472 bool ParseInt32(const Message& src_text, const char* str, Int32* value);
02473
02474
02475
02476 bool BoolFromGTestEnv(const char* flag, bool default_val);
02477 GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
02478 const char* StringFromGTestEnv(const char* flag, const char* default_val);
02479
02480 }
02481 }
02482
02483 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
02484