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