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