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