34#include "gtest/internal/gtest-port.h"
46#include "gtest/gtest.h"
47#include "gtest/gtest-spi.h"
54#define GTEST_IMPLEMENTATION_ 1
55#include "src/gtest-internal-inl.h"
56#undef GTEST_IMPLEMENTATION_
64TEST(IsXDigitTest, WorksForNarrowAscii) {
77TEST(IsXDigitTest, ReturnsFalseForNarrowNonAscii) {
82TEST(IsXDigitTest, WorksForWideAscii) {
95TEST(IsXDigitTest, ReturnsFalseForWideNonAscii) {
119TEST(ImplicitCastTest, ConvertsPointers) {
124TEST(ImplicitCastTest, CanUseInheritance) {
142TEST(ImplicitCastTest, CanUseNonConstCastOperator) {
143 bool converted =
false;
152 operator Base()
const {
161TEST(ImplicitCastTest, CanUseConstCastOperatorOnConstValues) {
162 bool converted =
false;
176 operator Base()
const {
186TEST(ImplicitCastTest, CanSelectBetweenConstAndNonConstCasrAppropriately) {
187 bool converted =
false;
188 bool const_converted =
false;
195 const_converted =
false;
204 To(
bool* converted) { *converted =
true; }
207TEST(ImplicitCastTest, CanUseImplicitConstructor) {
208 bool converted =
false;
214TEST(IteratorTraitsTest, WorksForSTLContainerIterators) {
221TEST(IteratorTraitsTest, WorksForPointerToNonConst) {
226TEST(IteratorTraitsTest, WorksForPointerToConst) {
234TEST(ScopedPtrTest, DefinesElementType) {
240TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
242 GTEST_CHECK_(
false) <<
"This should never be executed; "
243 "It's a compilation test only.";
256TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
270TEST(FormatFileLocationTest, FormatsFileLocation) {
275TEST(FormatFileLocationTest, FormatsUnknownFile) {
281TEST(FormatFileLocationTest, FormatsUknownLine) {
285TEST(FormatFileLocationTest, FormatsUknownFileAndLine) {
290TEST(FormatCompilerIndependentFileLocationTest, FormatsFileLocation) {
294TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFile) {
299TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownLine) {
303TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) {
307#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX
308void* ThreadFunc(
void*
data) {
315TEST(GetThreadCountTest, ReturnsCorrectValue) {
319 internal::Mutex mutex;
324 ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
326 const int status = pthread_create(&thread_id, &attr, &ThreadFunc, &mutex);
327 ASSERT_EQ(0, pthread_attr_destroy(&attr));
333 ASSERT_EQ(0, pthread_join(thread_id, &dummy));
338 for (
int i = 0;
i < 5; ++
i) {
342 SleepMilliseconds(100);
348TEST(GetThreadCountTest, ReturnsZeroWhenUnableToCountThreads) {
353TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) {
354 const bool a_false_condition =
false;
357 "gtest-port_test\\.cc\\(\\d+\\):"
358#elif GTEST_USES_POSIX_RE
359 "gtest-port_test\\.cc:[0-9]+"
361 "gtest-port_test\\.cc:\\d+"
363 ".*a_false_condition.*Extra info.*";
369#if GTEST_HAS_DEATH_TEST
371TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) {
374 ::std::cerr <<
"Success\n";
376 ::testing::ExitedWithCode(0),
"Success");
384TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
386# if GTEST_HAS_POSIX_RE
398#if GTEST_USES_POSIX_RE
400# if GTEST_HAS_TYPED_TEST
402template <
typename Str>
407typedef testing::Types<
409# if GTEST_HAS_GLOBAL_STRING
412 const char*> StringTypes;
418 const RE empty(TypeParam(
""));
421 const RE simple(TypeParam(
"hello"));
424 const RE normal(TypeParam(
".*(\\w+)"));
432 },
"\"?\" is not a valid POSIX Extended regular expression.");
441 const RE re(TypeParam(
"a.*z"));
454 const RE re(TypeParam(
"a.*z"));
464#elif GTEST_USES_SIMPLE_RE
466TEST(IsInSetTest, NulCharIsNotInAnySet) {
472TEST(IsInSetTest, WorksForNonNulChars) {
480TEST(IsAsciiDigitTest, IsFalseForNonDigit) {
489TEST(IsAsciiDigitTest, IsTrueForDigit) {
496TEST(IsAsciiPunctTest, IsFalseForNonPunct) {
504TEST(IsAsciiPunctTest, IsTrueForPunct) {
505 for (
const char* p =
"^-!\"#$%&'()*+,./:;<=>?@[\\]_`{|}~"; *
p;
p++) {
510TEST(IsRepeatTest, IsFalseForNonRepeatChar) {
518TEST(IsRepeatTest, IsTrueForRepeatChar) {
524TEST(IsAsciiWhiteSpaceTest, IsFalseForNonWhiteSpace) {
532TEST(IsAsciiWhiteSpaceTest, IsTrueForWhiteSpace) {
541TEST(IsAsciiWordCharTest, IsFalseForNonWordChar) {
549TEST(IsAsciiWordCharTest, IsTrueForLetter) {
556TEST(IsAsciiWordCharTest, IsTrueForDigit) {
563TEST(IsAsciiWordCharTest, IsTrueForUnderscore) {
567TEST(IsValidEscapeTest, IsFalseForNonPrintable) {
572TEST(IsValidEscapeTest, IsFalseForDigit) {
577TEST(IsValidEscapeTest, IsFalseForWhiteSpace) {
582TEST(IsValidEscapeTest, IsFalseForSomeLetter) {
587TEST(IsValidEscapeTest, IsTrueForPunct) {
598TEST(IsValidEscapeTest, IsTrueForSomeLetter) {
607TEST(AtomMatchesCharTest, EscapedPunct) {
619TEST(AtomMatchesCharTest, Escaped_d) {
628TEST(AtomMatchesCharTest, Escaped_D) {
637TEST(AtomMatchesCharTest, Escaped_s) {
648TEST(AtomMatchesCharTest, Escaped_S) {
657TEST(AtomMatchesCharTest, Escaped_w) {
669TEST(AtomMatchesCharTest, Escaped_W) {
680TEST(AtomMatchesCharTest, EscapedWhiteSpace) {
699TEST(AtomMatchesCharTest, UnescapedDot) {
708TEST(AtomMatchesCharTest, UnescapedChar) {
718TEST(ValidateRegexTest, GeneratesFailureAndReturnsFalseForInvalid) {
720 "NULL is not a valid simple regular expression");
723 "Syntax error at index 1 in simple regular expression \"a\\\": ");
725 "'\\' cannot appear at the end");
727 "'\\' cannot appear at the end");
729 "invalid escape sequence \"\\h\"");
731 "'^' can only appear at the beginning");
733 "'^' can only appear at the beginning");
735 "'$' can only appear at the end");
737 "'$' can only appear at the end");
739 "'(' is unsupported");
741 "')' is unsupported");
743 "'[' is unsupported");
745 "'{' is unsupported");
747 "'?' can only follow a repeatable token");
749 "'*' can only follow a repeatable token");
751 "'+' can only follow a repeatable token");
754TEST(ValidateRegexTest, ReturnsTrueForValid) {
762 EXPECT_TRUE(ValidateRegex(
"a\\^Z\\$\\(\\)\\|\\[\\]\\{\\}"));
765TEST(MatchRepetitionAndRegexAtHeadTest, WorksForZeroOrOne) {
766 EXPECT_FALSE(MatchRepetitionAndRegexAtHead(
false,
'a',
'?',
"a",
"ba"));
768 EXPECT_FALSE(MatchRepetitionAndRegexAtHead(
false,
'a',
'?',
"b",
"aab"));
771 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
false,
'a',
'?',
"b",
"ba"));
773 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
false,
'a',
'?',
"b",
"ab"));
774 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
false,
'#',
'?',
".",
"##"));
777TEST(MatchRepetitionAndRegexAtHeadTest, WorksForZeroOrMany) {
778 EXPECT_FALSE(MatchRepetitionAndRegexAtHead(
false,
'.',
'*',
"a$",
"baab"));
781 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
false,
'.',
'*',
"b",
"bc"));
783 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
false,
'.',
'*',
"b",
"abc"));
785 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
true,
'w',
'*',
"-",
"ab_1-g"));
788TEST(MatchRepetitionAndRegexAtHeadTest, WorksForOneOrMany) {
789 EXPECT_FALSE(MatchRepetitionAndRegexAtHead(
false,
'.',
'+',
"a$",
"baab"));
791 EXPECT_FALSE(MatchRepetitionAndRegexAtHead(
false,
'.',
'+',
"b",
"bc"));
794 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
false,
'.',
'+',
"b",
"abc"));
796 EXPECT_TRUE(MatchRepetitionAndRegexAtHead(
true,
'w',
'+',
"-",
"ab_1-g"));
799TEST(MatchRegexAtHeadTest, ReturnsTrueForEmptyRegex) {
804TEST(MatchRegexAtHeadTest, WorksWhenDollarIsInRegex) {
811TEST(MatchRegexAtHeadTest, WorksWhenRegexStartsWithEscapeSequence) {
819TEST(MatchRegexAtHeadTest, WorksWhenRegexStartsWithRepetition) {
828TEST(MatchRegexAtHeadTest,
829 WorksWhenRegexStartsWithRepetionOfEscapeSequence) {
839TEST(MatchRegexAtHeadTest, MatchesSequentially) {
845TEST(MatchRegexAnywhereTest, ReturnsFalseWhenStringIsNull) {
849TEST(MatchRegexAnywhereTest, WorksWhenRegexStartsWithCaret) {
858TEST(MatchRegexAnywhereTest, ReturnsFalseWhenNoMatch) {
860 EXPECT_FALSE(MatchRegexAnywhere(
"a.+a",
"--aa88888888"));
863TEST(MatchRegexAnywhereTest, ReturnsTrueWhenMatchingPrefix) {
864 EXPECT_TRUE(MatchRegexAnywhere(
"\\w+",
"ab1_ - 5"));
866 EXPECT_TRUE(MatchRegexAnywhere(
"x.*ab?.*bc",
"xaaabc"));
869TEST(MatchRegexAnywhereTest, ReturnsTrueWhenMatchingNonPrefix) {
870 EXPECT_TRUE(MatchRegexAnywhere(
"\\w+",
"$$$ ab1_ - 5"));
871 EXPECT_TRUE(MatchRegexAnywhere(
"\\.+=",
"= ...="));
875TEST(RETest, ImplicitConstructorWorks) {
879 const RE simple(
"hello");
884TEST(RETest, RejectsInvalidRegex) {
886 const RE normal(NULL);
887 },
"NULL is not a valid simple regular expression");
890 const RE normal(
".*(\\w+");
891 },
"'(' is unsupported");
895 },
"'?' can only follow a repeatable token");
899TEST(RETest, FullMatchWorks) {
915TEST(RETest, PartialMatchWorks) {
930#if !GTEST_OS_WINDOWS_MOBILE
932TEST(CaptureTest, CapturesStdout) {
934 fprintf(stdout,
"abc");
938 fprintf(stdout,
"def%cghi",
'\0');
939 EXPECT_EQ(::std::string(
"def\0ghi", 7), ::std::string(GetCapturedStdout()));
942TEST(CaptureTest, CapturesStderr) {
944 fprintf(stderr,
"jkl");
948 fprintf(stderr,
"jkl%cmno",
'\0');
949 EXPECT_EQ(::std::string(
"jkl\0mno", 7), ::std::string(GetCapturedStderr()));
953TEST(CaptureTest, CapturesStdoutAndStderr) {
956 fprintf(stdout,
"pqr");
957 fprintf(stderr,
"stu");
962TEST(CaptureDeathTest, CannotReenterStdoutCapture) {
965 "Only one stdout capturer can exist at a time");
974TEST(ThreadLocalTest, DefaultConstructorInitializesToDefaultValues) {
982TEST(ThreadLocalTest, SingleParamConstructorInitializesToParam) {
997TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) {
1002TEST(ThreadLocalTest, GetAndPointerReturnSameValue) {
1008 thread_local_string.
set(
"foo");
1012TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) {
1015 thread_local_string;
1019 thread_local_string.
set(
"foo");
1023#if GTEST_IS_THREADSAFE
1025void AddTwo(
int* param) { *param += 2; }
1027TEST(ThreadWithParamTest, ConstructorExecutesThreadFunc) {
1029 ThreadWithParam<int*> thread(&AddTwo, &i, NULL);
1034TEST(MutexDeathTest, AssertHeldShouldAssertWhenNotLocked) {
1045TEST(MutexTest, AssertHeldShouldNotAssertWhenLocked) {
1051class AtomicCounterWithMutex {
1053 explicit AtomicCounterWithMutex(Mutex* mutex) :
1054 value_(0), mutex_(mutex), random_(42) {}
1063#if GTEST_HAS_PTHREAD
1067 pthread_mutex_t memory_barrier_mutex;
1069 pthread_mutex_init(&memory_barrier_mutex, NULL));
1072 SleepMilliseconds(random_.Generate(30));
1076#elif GTEST_OS_WINDOWS
1078 volatile LONG dummy = 0;
1079 ::InterlockedIncrement(&dummy);
1080 SleepMilliseconds(random_.Generate(30));
1081 ::InterlockedIncrement(&dummy);
1083# error "Memory barrier not implemented on this platform."
1088 int value()
const {
return value_; }
1091 volatile int value_;
1092 Mutex*
const mutex_;
1096void CountingThreadFunc(pair<AtomicCounterWithMutex*, int> param) {
1097 for (
int i = 0;
i < param.second; ++
i)
1098 param.first->Increment();
1102TEST(MutexTest, OnlyOneThreadCanLockAtATime) {
1104 AtomicCounterWithMutex locked_counter(&mutex);
1106 typedef ThreadWithParam<pair<AtomicCounterWithMutex*, int> > ThreadType;
1107 const int kCycleCount = 20;
1108 const int kThreadCount = 7;
1110 Notification threads_can_start;
1113 for (
int i = 0;
i < kThreadCount; ++
i) {
1114 counting_threads[
i].reset(
new ThreadType(&CountingThreadFunc,
1115 make_pair(&locked_counter,
1117 &threads_can_start));
1119 threads_can_start.Notify();
1120 for (
int i = 0;
i < kThreadCount; ++
i)
1121 counting_threads[i]->Join();
1127 EXPECT_EQ(kCycleCount * kThreadCount, locked_counter.value());
1130template <
typename T>
1131void RunFromThread(
void (func)(
T),
T param) {
1132 ThreadWithParam<T> thread(func, param, NULL);
1136void RetrieveThreadLocalValue(
1138 *param.second = param.first->get();
1141TEST(ThreadLocalTest, ParameterizedConstructorSetsDefault) {
1143 EXPECT_STREQ(
"foo", thread_local_string.get().c_str());
1145 thread_local_string.set(
"bar");
1146 EXPECT_STREQ(
"bar", thread_local_string.get().c_str());
1149 RunFromThread(&RetrieveThreadLocalValue,
1150 make_pair(&thread_local_string, &
result));
1156class DestructorCall {
1161 wait_event_.Reset(::CreateEvent(NULL, TRUE, FALSE, NULL));
1166 bool CheckDestroyed()
const {
1168 if (::WaitForSingleObject(wait_event_.Get(), 1000) != WAIT_OBJECT_0)
1174 void ReportDestroyed() {
1177 ::SetEvent(wait_event_.Get());
1181 static std::vector<DestructorCall*>& List() {
return *list_; }
1183 static void ResetList() {
1184 for (
size_t i = 0;
i < list_->size(); ++
i) {
1185 delete list_->at(i);
1193 AutoHandle wait_event_;
1195 static std::vector<DestructorCall*>*
const list_;
1200std::vector<DestructorCall*>*
const DestructorCall::list_ =
1201 new std::vector<DestructorCall*>;
1205class DestructorTracker {
1207 DestructorTracker() : index_(GetNewIndex()) {}
1208 DestructorTracker(
const DestructorTracker& )
1209 : index_(GetNewIndex()) {}
1210 ~DestructorTracker() {
1213 DestructorCall::List()[index_]->ReportDestroyed();
1217 static size_t GetNewIndex() {
1218 DestructorCall::List().push_back(
new DestructorCall);
1219 return DestructorCall::List().size() - 1;
1221 const size_t index_;
1228void CallThreadLocalGet(ThreadParam thread_local_param) {
1229 thread_local_param->
get();
1234TEST(ThreadLocalTest, DestroysManagedObjectForOwnThreadWhenDying) {
1235 DestructorCall::ResetList();
1239 ASSERT_EQ(0U, DestructorCall::List().size());
1242 thread_local_tracker.get();
1243 ASSERT_EQ(1U, DestructorCall::List().size());
1244 ASSERT_FALSE(DestructorCall::List()[0]->CheckDestroyed());
1248 ASSERT_EQ(1U, DestructorCall::List().size());
1249 EXPECT_TRUE(DestructorCall::List()[0]->CheckDestroyed());
1251 DestructorCall::ResetList();
1256TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
1257 DestructorCall::ResetList();
1261 ASSERT_EQ(0U, DestructorCall::List().size());
1264 ThreadWithParam<ThreadParam> thread(
1265 &CallThreadLocalGet, &thread_local_tracker, NULL);
1270 ASSERT_EQ(1U, DestructorCall::List().size());
1274 ASSERT_EQ(1U, DestructorCall::List().size());
1275 EXPECT_TRUE(DestructorCall::List()[0]->CheckDestroyed());
1277 DestructorCall::ResetList();
1280TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) {
1282 thread_local_string.
set(
"Foo");
1283 EXPECT_STREQ(
"Foo", thread_local_string.get().c_str());
1286 RunFromThread(&RetrieveThreadLocalValue,
1287 make_pair(&thread_local_string, &
result));
1294TEST(WindowsTypesTest, HANDLEIsVoidStar) {
1298TEST(WindowsTypesTest, CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION) {
Base(int n)
Definition gtest-port_test.cc:106
Base()
Definition gtest-port_test.cc:105
int member()
Definition gtest-port_test.cc:108
int member_
Definition gtest-port_test.cc:111
virtual ~Base()
Definition gtest-port_test.cc:107
Definition gtest-port_test.cc:130
bool * converted_
Definition gtest-port_test.cc:139
Castable(bool *converted)
Definition gtest-port_test.cc:132
Definition gtest-port_test.cc:168
bool * converted_
Definition gtest-port_test.cc:182
bool * const_converted_
Definition gtest-port_test.cc:183
ConstAndNonConstCastable(bool *converted, bool *const_converted)
Definition gtest-port_test.cc:170
Definition gtest-port_test.cc:149
ConstCastable(bool *converted)
Definition gtest-port_test.cc:151
bool * converted_
Definition gtest-port_test.cc:158
Derived(int n)
Definition gtest-port_test.cc:116
Definition gtest-port.h:2136
void Unlock()
Definition gtest-port.h:2140
void Lock()
Definition gtest-port.h:2139
void AssertHeld() const
Definition gtest-port.h:2141
Definition gtest-port_test.cc:991
NoDefaultContructor(const char *)
Definition gtest-port_test.cc:993
NoDefaultContructor(const NoDefaultContructor &)
Definition gtest-port_test.cc:994
Definition gtest-port.h:1156
static bool PartialMatch(const ::std::string &str, const RE &re)
Definition gtest-port.h:1187
static bool FullMatch(const ::std::string &str, const RE &re)
Definition gtest-port.h:1184
Definition gtest-port.h:2162
T * pointer()
Definition gtest-port.h:2166
void set(const T &value)
Definition gtest-port.h:2169
const T & get() const
Definition gtest-port.h:2168
Definition gtest-port_test.cc:202
To(bool *converted)
Definition gtest-port_test.cc:204
Definition gtest-port.h:1115
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition gtest-death-test.h:286
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition gtest-spi.h:204
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define ASSERT_FALSE(condition)
Definition gtest.h:1868
#define EXPECT_TRUE(condition)
Definition gtest.h:1859
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1995
#define TEST(test_case_name, test_name)
Definition gtest.h:2187
#define EXPECT_FALSE(condition)
Definition gtest.h:1862
#define EXPECT_PRED1(pred, v1)
Definition gtest_pred_impl.h:115
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
Definition gtest_pred_impl.h:161
#define GTEST_CHECK_POSIX_SUCCESS_(posix_call)
Definition gtest-port.h:1308
#define GTEST_USES_SIMPLE_RE
Definition gtest-port.h:449
#define GTEST_CHECK_(condition)
Definition gtest-port.h:1295
#define GTEST_DISALLOW_ASSIGN_(type)
Definition gtest-port.h:869
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition gtest-port.h:874
#define L(m0, m1, m2, m3, m4, m5, m6, m7)
Definition jh.c:116
Definition gtest_output_test_.cc:549
base::threading::internal::NoMutex Mutex
Definition easylogging++.h:1029
@ invalid
Definition enums.h:42
Definition document.h:406
int i
Definition pymoduletest.py:23
p
Definition pymoduletest.py:75
@ empty
Definition readline_buffer.h:9
GTestMutexLock MutexLock
Definition gtest-port.h:2159
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
Definition gtest-port.cc:898
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
Definition gtest-port.cc:880
GTEST_API_ size_t GetThreadCount()
Definition gtest-port.cc:169
bool AlwaysFalse()
Definition gtest-internal.h:736
::std::string string
Definition gtest-port.h:1097
GTEST_API_ bool AlwaysTrue()
Definition gtest.cc:4988
To ImplicitCast_(To x)
Definition gtest-port.h:1343
bool IsXDigit(char ch)
Definition gtest-port.h:2269
Definition gmock-actions.h:53
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1606
TYPED_TEST(CodeLocationForTYPEDTEST, Verify)
Definition gtest_unittest.cc:5370
bool StaticAssertTypeEq()
Definition gtest.h:2150
TYPED_TEST_CASE(CodeLocationForTYPEDTEST, int)
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
t2
Definition pow22523.h:103
t1
Definition pow22523.h:58
tools::wallet2::message_signature_result_t result
Definition signature.cpp:62
Definition gtest-port.h:2219
Iterator::value_type value_type
Definition gtest-port.h:2220
std::string data
Definition base58.cpp:37