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 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
00038 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
00039
00040 #include "gtest/internal/gtest-port.h"
00041
00042 #if GTEST_OS_LINUX
00043 # include <stdlib.h>
00044 # include <sys/types.h>
00045 # include <sys/wait.h>
00046 # include <unistd.h>
00047 #endif // GTEST_OS_LINUX
00048
00049 #if GTEST_HAS_EXCEPTIONS
00050 # include <stdexcept>
00051 #endif
00052
00053 #include <ctype.h>
00054 #include <float.h>
00055 #include <string.h>
00056 #include <iomanip>
00057 #include <limits>
00058 #include <set>
00059
00060 #include "gtest/gtest-message.h"
00061 #include "gtest/internal/gtest-string.h"
00062 #include "gtest/internal/gtest-filepath.h"
00063 #include "gtest/internal/gtest-type-util.h"
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
00074 #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
00075
00076 class ProtocolMessage;
00077 namespace proto2 { class Message; }
00078
00079 namespace testing {
00080
00081
00082
00083 class AssertionResult;
00084 class Message;
00085 class Test;
00086 class TestInfo;
00087 class TestPartResult;
00088 class UnitTest;
00089
00090 template <typename T>
00091 ::std::string PrintToString(const T& value);
00092
00093 namespace internal {
00094
00095 struct TraceInfo;
00096 class ScopedTrace;
00097 class TestInfoImpl;
00098 class UnitTestImpl;
00099
00100
00101 GTEST_API_ extern int g_init_gtest_count;
00102
00103
00104
00105 GTEST_API_ extern const char kStackTraceMarker[];
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 char IsNullLiteralHelper(Secret* p);
00122 char (&IsNullLiteralHelper(...))[2];
00123
00124
00125
00126
00127 #ifdef GTEST_ELLIPSIS_NEEDS_POD_
00128
00129
00130 # define GTEST_IS_NULL_LITERAL_(x) false
00131 #else
00132 # define GTEST_IS_NULL_LITERAL_(x) \
00133 (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
00134 #endif // GTEST_ELLIPSIS_NEEDS_POD_
00135
00136
00137 GTEST_API_ std::string AppendUserMessage(
00138 const std::string& gtest_msg, const Message& user_msg);
00139
00140 #if GTEST_HAS_EXCEPTIONS
00141
00142
00143
00144
00145
00146
00147
00148 class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
00149 public:
00150 explicit GoogleTestFailureException(const TestPartResult& failure);
00151 };
00152
00153 #endif // GTEST_HAS_EXCEPTIONS
00154
00155
00156 class GTEST_API_ ScopedTrace {
00157 public:
00158
00159
00160 ScopedTrace(const char* file, int line, const Message& message);
00161
00162
00163
00164
00165
00166 ~ScopedTrace();
00167
00168 private:
00169 GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
00170 } GTEST_ATTRIBUTE_UNUSED_;
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
00190 const char* actual_expression,
00191 const std::string& expected_value,
00192 const std::string& actual_value,
00193 bool ignoring_case);
00194
00195
00196 GTEST_API_ std::string GetBoolAssertionFailureMessage(
00197 const AssertionResult& assertion_result,
00198 const char* expression_text,
00199 const char* actual_predicate_value,
00200 const char* expected_predicate_value);
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 template <typename RawType>
00232 class FloatingPoint {
00233 public:
00234
00235
00236 typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
00237
00238
00239
00240
00241 static const size_t kBitCount = 8*sizeof(RawType);
00242
00243
00244 static const size_t kFractionBitCount =
00245 std::numeric_limits<RawType>::digits - 1;
00246
00247
00248 static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
00249
00250
00251 static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
00252
00253
00254 static const Bits kFractionBitMask =
00255 ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
00256
00257
00258 static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 static const size_t kMaxUlps = 4;
00273
00274
00275
00276
00277
00278
00279
00280 explicit FloatingPoint(const RawType& x) { u_.value_ = x; }
00281
00282
00283
00284
00285
00286
00287 static RawType ReinterpretBits(const Bits bits) {
00288 FloatingPoint fp(0);
00289 fp.u_.bits_ = bits;
00290 return fp.u_.value_;
00291 }
00292
00293
00294 static RawType Infinity() {
00295 return ReinterpretBits(kExponentBitMask);
00296 }
00297
00298
00299 static RawType Max();
00300
00301
00302
00303
00304 const Bits &bits() const { return u_.bits_; }
00305
00306
00307 Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
00308
00309
00310 Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }
00311
00312
00313 Bits sign_bit() const { return kSignBitMask & u_.bits_; }
00314
00315
00316 bool is_nan() const {
00317
00318
00319 return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
00320 }
00321
00322
00323
00324
00325
00326
00327
00328 bool AlmostEquals(const FloatingPoint& rhs) const {
00329
00330
00331 if (is_nan() || rhs.is_nan()) return false;
00332
00333 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
00334 <= kMaxUlps;
00335 }
00336
00337 private:
00338
00339 union FloatingPointUnion {
00340 RawType value_;
00341 Bits bits_;
00342 };
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 static Bits SignAndMagnitudeToBiased(const Bits &sam) {
00360 if (kSignBitMask & sam) {
00361
00362 return ~sam + 1;
00363 } else {
00364
00365 return kSignBitMask | sam;
00366 }
00367 }
00368
00369
00370
00371 static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,
00372 const Bits &sam2) {
00373 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
00374 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
00375 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
00376 }
00377
00378 FloatingPointUnion u_;
00379 };
00380
00381
00382
00383 template <>
00384 inline float FloatingPoint<float>::Max() { return FLT_MAX; }
00385 template <>
00386 inline double FloatingPoint<double>::Max() { return DBL_MAX; }
00387
00388
00389
00390 typedef FloatingPoint<float> Float;
00391 typedef FloatingPoint<double> Double;
00392
00393
00394
00395
00396
00397
00398
00399 typedef const void* TypeId;
00400
00401 template <typename T>
00402 class TypeIdHelper {
00403 public:
00404
00405
00406
00407 static bool dummy_;
00408 };
00409
00410 template <typename T>
00411 bool TypeIdHelper<T>::dummy_ = false;
00412
00413
00414
00415
00416 template <typename T>
00417 TypeId GetTypeId() {
00418
00419
00420
00421
00422 return &(TypeIdHelper<T>::dummy_);
00423 }
00424
00425
00426
00427
00428
00429
00430 GTEST_API_ TypeId GetTestTypeId();
00431
00432
00433
00434 class TestFactoryBase {
00435 public:
00436 virtual ~TestFactoryBase() {}
00437
00438
00439
00440 virtual Test* CreateTest() = 0;
00441
00442 protected:
00443 TestFactoryBase() {}
00444
00445 private:
00446 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);
00447 };
00448
00449
00450
00451 template <class TestClass>
00452 class TestFactoryImpl : public TestFactoryBase {
00453 public:
00454 virtual Test* CreateTest() { return new TestClass; }
00455 };
00456
00457 #if GTEST_OS_WINDOWS
00458
00459
00460
00461
00462
00463 GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
00464 long hr);
00465 GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
00466 long hr);
00467
00468 #endif // GTEST_OS_WINDOWS
00469
00470
00471 typedef void (*SetUpTestCaseFunc)();
00472 typedef void (*TearDownTestCaseFunc)();
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
00492 const char* test_case_name,
00493 const char* name,
00494 const char* type_param,
00495 const char* value_param,
00496 TypeId fixture_class_id,
00497 SetUpTestCaseFunc set_up_tc,
00498 TearDownTestCaseFunc tear_down_tc,
00499 TestFactoryBase* factory);
00500
00501
00502
00503
00504 GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
00505
00506 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
00507
00508
00509 class GTEST_API_ TypedTestCasePState {
00510 public:
00511 TypedTestCasePState() : registered_(false) {}
00512
00513
00514
00515
00516 bool AddTestName(const char* file, int line, const char* case_name,
00517 const char* test_name) {
00518 if (registered_) {
00519 fprintf(stderr, "%s Test %s must be defined before "
00520 "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
00521 FormatFileLocation(file, line).c_str(), test_name, case_name);
00522 fflush(stderr);
00523 posix::Abort();
00524 }
00525 defined_test_names_.insert(test_name);
00526 return true;
00527 }
00528
00529
00530
00531
00532 const char* VerifyRegisteredTestNames(
00533 const char* file, int line, const char* registered_tests);
00534
00535 private:
00536 bool registered_;
00537 ::std::set<const char*> defined_test_names_;
00538 };
00539
00540
00541
00542 inline const char* SkipComma(const char* str) {
00543 const char* comma = strchr(str, ',');
00544 if (comma == NULL) {
00545 return NULL;
00546 }
00547 while (IsSpace(*(++comma))) {}
00548 return comma;
00549 }
00550
00551
00552
00553 inline std::string GetPrefixUntilComma(const char* str) {
00554 const char* comma = strchr(str, ',');
00555 return comma == NULL ? str : std::string(str, comma);
00556 }
00557
00558
00559
00560
00561
00562
00563
00564
00565 template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
00566 class TypeParameterizedTest {
00567 public:
00568
00569
00570
00571
00572 static bool Register(const char* prefix, const char* case_name,
00573 const char* test_names, int index) {
00574 typedef typename Types::Head Type;
00575 typedef Fixture<Type> FixtureClass;
00576 typedef typename GTEST_BIND_(TestSel, Type) TestClass;
00577
00578
00579
00580 MakeAndRegisterTestInfo(
00581 (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
00582 + StreamableToString(index)).c_str(),
00583 GetPrefixUntilComma(test_names).c_str(),
00584 GetTypeName<Type>().c_str(),
00585 NULL,
00586 GetTypeId<FixtureClass>(),
00587 TestClass::SetUpTestCase,
00588 TestClass::TearDownTestCase,
00589 new TestFactoryImpl<TestClass>);
00590
00591
00592 return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
00593 ::Register(prefix, case_name, test_names, index + 1);
00594 }
00595 };
00596
00597
00598 template <GTEST_TEMPLATE_ Fixture, class TestSel>
00599 class TypeParameterizedTest<Fixture, TestSel, Types0> {
00600 public:
00601 static bool Register(const char* , const char* ,
00602 const char* , int ) {
00603 return true;
00604 }
00605 };
00606
00607
00608
00609
00610
00611 template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
00612 class TypeParameterizedTestCase {
00613 public:
00614 static bool Register(const char* prefix, const char* case_name,
00615 const char* test_names) {
00616 typedef typename Tests::Head Head;
00617
00618
00619 TypeParameterizedTest<Fixture, Head, Types>::Register(
00620 prefix, case_name, test_names, 0);
00621
00622
00623 return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
00624 ::Register(prefix, case_name, SkipComma(test_names));
00625 }
00626 };
00627
00628
00629 template <GTEST_TEMPLATE_ Fixture, typename Types>
00630 class TypeParameterizedTestCase<Fixture, Templates0, Types> {
00631 public:
00632 static bool Register(const char* , const char* ,
00633 const char* ) {
00634 return true;
00635 }
00636 };
00637
00638 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
00651 UnitTest* unit_test, int skip_count);
00652
00653
00654
00655
00656
00657 GTEST_API_ bool AlwaysTrue();
00658
00659
00660 inline bool AlwaysFalse() { return !AlwaysTrue(); }
00661
00662
00663
00664
00665 struct GTEST_API_ ConstCharPtr {
00666 ConstCharPtr(const char* str) : value(str) {}
00667 operator bool() const { return true; }
00668 const char* value;
00669 };
00670
00671
00672
00673
00674
00675
00676 class GTEST_API_ Random {
00677 public:
00678 static const UInt32 kMaxRange = 1u << 31;
00679
00680 explicit Random(UInt32 seed) : state_(seed) {}
00681
00682 void Reseed(UInt32 seed) { state_ = seed; }
00683
00684
00685
00686 UInt32 Generate(UInt32 range);
00687
00688 private:
00689 UInt32 state_;
00690 GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
00691 };
00692
00693
00694
00695 template <typename T1, typename T2>
00696 struct CompileAssertTypesEqual;
00697
00698 template <typename T>
00699 struct CompileAssertTypesEqual<T, T> {
00700 };
00701
00702
00703
00704
00705 template <typename T>
00706 struct RemoveReference { typedef T type; };
00707 template <typename T>
00708 struct RemoveReference<T&> { typedef T type; };
00709
00710
00711
00712 #define GTEST_REMOVE_REFERENCE_(T) \
00713 typename ::testing::internal::RemoveReference<T>::type
00714
00715
00716
00717
00718 template <typename T>
00719 struct RemoveConst { typedef T type; };
00720 template <typename T>
00721 struct RemoveConst<const T> { typedef T type; };
00722
00723
00724
00725
00726 template <typename T, size_t N>
00727 struct RemoveConst<const T[N]> {
00728 typedef typename RemoveConst<T>::type type[N];
00729 };
00730
00731 #if defined(_MSC_VER) && _MSC_VER < 1400
00732
00733
00734
00735 template <typename T, size_t N>
00736 struct RemoveConst<T[N]> {
00737 typedef typename RemoveConst<T>::type type[N];
00738 };
00739 #endif
00740
00741
00742
00743 #define GTEST_REMOVE_CONST_(T) \
00744 typename ::testing::internal::RemoveConst<T>::type
00745
00746
00747 #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
00748 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
00749
00750
00751
00752
00753 template <typename T>
00754 struct AddReference { typedef T& type; };
00755 template <typename T>
00756 struct AddReference<T&> { typedef T& type; };
00757
00758
00759
00760 #define GTEST_ADD_REFERENCE_(T) \
00761 typename ::testing::internal::AddReference<T>::type
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772 #define GTEST_REFERENCE_TO_CONST_(T) \
00773 GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
00774
00775
00776
00777
00778 template <typename From, typename To>
00779 class ImplicitlyConvertible {
00780 private:
00781
00782
00783
00784
00785
00786
00787 static From MakeFrom();
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799 static char Helper(To);
00800 static char (&Helper(...))[2];
00801
00802
00803
00804 public:
00805
00806
00807
00808 #ifdef _MSC_VER
00809 # pragma warning(push) // Saves the current warning state.
00810 # pragma warning(disable:4244) // Temporarily disables warning 4244.
00811
00812 static const bool value =
00813 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
00814 # pragma warning(pop) // Restores the warning state.
00815 #elif defined(__BORLANDC__)
00816
00817
00818
00819 static const bool value = __is_convertible(From, To);
00820 #else
00821 static const bool value =
00822 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
00823 #endif // _MSV_VER
00824 };
00825 template <typename From, typename To>
00826 const bool ImplicitlyConvertible<From, To>::value;
00827
00828
00829
00830
00831 template <typename T>
00832 struct IsAProtocolMessage
00833 : public bool_constant<
00834 ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
00835 ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
00836 };
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859 typedef int IsContainer;
00860 template <class C>
00861 IsContainer IsContainerTest(int ,
00862 typename C::iterator* = NULL,
00863 typename C::const_iterator* = NULL) {
00864 return 0;
00865 }
00866
00867 typedef char IsNotContainer;
00868 template <class C>
00869 IsNotContainer IsContainerTest(long ) { return '\0'; }
00870
00871
00872
00873
00874
00875 template<bool> struct EnableIf;
00876 template<> struct EnableIf<true> { typedef void type; };
00877
00878
00879
00880
00881
00882
00883
00884 template <typename T, typename U>
00885 bool ArrayEq(const T* lhs, size_t size, const U* rhs);
00886
00887
00888 template <typename T, typename U>
00889 inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
00890
00891
00892 template <typename T, typename U, size_t N>
00893 inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
00894 return internal::ArrayEq(lhs, N, rhs);
00895 }
00896
00897
00898
00899
00900 template <typename T, typename U>
00901 bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
00902 for (size_t i = 0; i != size; i++) {
00903 if (!internal::ArrayEq(lhs[i], rhs[i]))
00904 return false;
00905 }
00906 return true;
00907 }
00908
00909
00910
00911 template <typename Iter, typename Element>
00912 Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
00913 for (Iter it = begin; it != end; ++it) {
00914 if (internal::ArrayEq(*it, elem))
00915 return it;
00916 }
00917 return end;
00918 }
00919
00920
00921
00922
00923
00924 template <typename T, typename U>
00925 void CopyArray(const T* from, size_t size, U* to);
00926
00927
00928 template <typename T, typename U>
00929 inline void CopyArray(const T& from, U* to) { *to = from; }
00930
00931
00932 template <typename T, typename U, size_t N>
00933 inline void CopyArray(const T(&from)[N], U(*to)[N]) {
00934 internal::CopyArray(from, N, *to);
00935 }
00936
00937
00938
00939
00940 template <typename T, typename U>
00941 void CopyArray(const T* from, size_t size, U* to) {
00942 for (size_t i = 0; i != size; i++) {
00943 internal::CopyArray(from[i], to + i);
00944 }
00945 }
00946
00947
00948
00949 enum RelationToSource {
00950 kReference,
00951 kCopy
00952
00953 };
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963 template <typename Element>
00964 class NativeArray {
00965 public:
00966
00967 typedef Element value_type;
00968 typedef Element* iterator;
00969 typedef const Element* const_iterator;
00970
00971
00972 NativeArray(const Element* array, size_t count, RelationToSource relation) {
00973 Init(array, count, relation);
00974 }
00975
00976
00977 NativeArray(const NativeArray& rhs) {
00978 Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
00979 }
00980
00981 ~NativeArray() {
00982
00983
00984 static_cast<void>(StaticAssertTypeEqHelper<Element,
00985 GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
00986 if (relation_to_source_ == kCopy)
00987 delete[] array_;
00988 }
00989
00990
00991 size_t size() const { return size_; }
00992 const_iterator begin() const { return array_; }
00993 const_iterator end() const { return array_ + size_; }
00994 bool operator==(const NativeArray& rhs) const {
00995 return size() == rhs.size() &&
00996 ArrayEq(begin(), size(), rhs.begin());
00997 }
00998
00999 private:
01000
01001
01002 void Init(const Element* array, size_t a_size, RelationToSource relation) {
01003 if (relation == kReference) {
01004 array_ = array;
01005 } else {
01006 Element* const copy = new Element[a_size];
01007 CopyArray(array, a_size, copy);
01008 array_ = copy;
01009 }
01010 size_ = a_size;
01011 relation_to_source_ = relation;
01012 }
01013
01014 const Element* array_;
01015 size_t size_;
01016 RelationToSource relation_to_source_;
01017
01018 GTEST_DISALLOW_ASSIGN_(NativeArray);
01019 };
01020
01021 }
01022 }
01023
01024 #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
01025 ::testing::internal::AssertHelper(result_type, file, line, message) \
01026 = ::testing::Message()
01027
01028 #define GTEST_MESSAGE_(message, result_type) \
01029 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
01030
01031 #define GTEST_FATAL_FAILURE_(message) \
01032 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
01033
01034 #define GTEST_NONFATAL_FAILURE_(message) \
01035 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
01036
01037 #define GTEST_SUCCESS_(message) \
01038 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
01039
01040
01041
01042
01043 #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
01044 if (::testing::internal::AlwaysTrue()) { statement; }
01045
01046 #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
01047 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01048 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
01049 bool gtest_caught_expected = false; \
01050 try { \
01051 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01052 } \
01053 catch (expected_exception const&) { \
01054 gtest_caught_expected = true; \
01055 } \
01056 catch (...) { \
01057 gtest_msg.value = \
01058 "Expected: " #statement " throws an exception of type " \
01059 #expected_exception ".\n Actual: it throws a different type."; \
01060 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
01061 } \
01062 if (!gtest_caught_expected) { \
01063 gtest_msg.value = \
01064 "Expected: " #statement " throws an exception of type " \
01065 #expected_exception ".\n Actual: it throws nothing."; \
01066 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
01067 } \
01068 } else \
01069 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
01070 fail(gtest_msg.value)
01071
01072 #define GTEST_TEST_NO_THROW_(statement, fail) \
01073 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01074 if (::testing::internal::AlwaysTrue()) { \
01075 try { \
01076 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01077 } \
01078 catch (...) { \
01079 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
01080 } \
01081 } else \
01082 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
01083 fail("Expected: " #statement " doesn't throw an exception.\n" \
01084 " Actual: it throws.")
01085
01086 #define GTEST_TEST_ANY_THROW_(statement, fail) \
01087 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01088 if (::testing::internal::AlwaysTrue()) { \
01089 bool gtest_caught_any = false; \
01090 try { \
01091 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01092 } \
01093 catch (...) { \
01094 gtest_caught_any = true; \
01095 } \
01096 if (!gtest_caught_any) { \
01097 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
01098 } \
01099 } else \
01100 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
01101 fail("Expected: " #statement " throws an exception.\n" \
01102 " Actual: it doesn't.")
01103
01104
01105
01106
01107
01108 #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
01109 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01110 if (const ::testing::AssertionResult gtest_ar_ = \
01111 ::testing::AssertionResult(expression)) \
01112 ; \
01113 else \
01114 fail(::testing::internal::GetBoolAssertionFailureMessage(\
01115 gtest_ar_, text, #actual, #expected).c_str())
01116
01117 #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
01118 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01119 if (::testing::internal::AlwaysTrue()) { \
01120 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
01121 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01122 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
01123 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
01124 } \
01125 } else \
01126 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
01127 fail("Expected: " #statement " doesn't generate new fatal " \
01128 "failures in the current thread.\n" \
01129 " Actual: it does.")
01130
01131
01132 #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
01133 test_case_name##_##test_name##_Test
01134
01135
01136 #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
01137 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
01138 public:\
01139 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
01140 private:\
01141 virtual void TestBody();\
01142 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
01143 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
01144 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
01145 };\
01146 \
01147 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
01148 ::test_info_ =\
01149 ::testing::internal::MakeAndRegisterTestInfo(\
01150 #test_case_name, #test_name, NULL, NULL, \
01151 (parent_id), \
01152 parent_class::SetUpTestCase, \
01153 parent_class::TearDownTestCase, \
01154 new ::testing::internal::TestFactoryImpl<\
01155 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
01156 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
01157
01158 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_