mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-27 19:07:31 +09:00
re-introduce old nss im too tired for this
This commit is contained in:
parent
3c46be320d
commit
3a838106b9
2871 changed files with 1374431 additions and 1762417 deletions
|
|
@ -31,7 +31,6 @@
|
|||
// Tests for death tests.
|
||||
|
||||
#include "gtest/gtest-death-test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/internal/gtest-filepath.h"
|
||||
|
||||
|
|
@ -41,9 +40,7 @@ using testing::internal::AlwaysTrue;
|
|||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
# include <fcntl.h> // For O_BINARY
|
||||
# include <direct.h> // For chdir().
|
||||
# include <io.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# include <sys/wait.h> // For waitpid.
|
||||
|
|
@ -62,8 +59,6 @@ using testing::internal::AlwaysTrue;
|
|||
|
||||
namespace posix = ::testing::internal::posix;
|
||||
|
||||
using testing::ContainsRegex;
|
||||
using testing::Matcher;
|
||||
using testing::Message;
|
||||
using testing::internal::DeathTest;
|
||||
using testing::internal::DeathTestFactory;
|
||||
|
|
@ -102,8 +97,6 @@ class ReplaceDeathTestFactory {
|
|||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
namespace {
|
||||
|
||||
void DieWithMessage(const ::std::string& message) {
|
||||
fprintf(stderr, "%s", message.c_str());
|
||||
fflush(stderr); // Make sure the text is printed before the process exits.
|
||||
|
|
@ -130,7 +123,9 @@ class TestForDeathTest : public testing::Test {
|
|||
protected:
|
||||
TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
|
||||
|
||||
~TestForDeathTest() override { posix::ChDir(original_dir_.c_str()); }
|
||||
virtual ~TestForDeathTest() {
|
||||
posix::ChDir(original_dir_.c_str());
|
||||
}
|
||||
|
||||
// A static member function that's expected to die.
|
||||
static void StaticMemberFunction() { DieInside("StaticMemberFunction"); }
|
||||
|
|
@ -141,7 +136,7 @@ class TestForDeathTest : public testing::Test {
|
|||
DieInside("MemberFunction");
|
||||
}
|
||||
|
||||
// True if and only if MemberFunction() should die.
|
||||
// True iff MemberFunction() should die.
|
||||
bool should_die_;
|
||||
const FilePath original_dir_;
|
||||
};
|
||||
|
|
@ -158,7 +153,7 @@ class MayDie {
|
|||
}
|
||||
|
||||
private:
|
||||
// True if and only if MemberFunction() should die.
|
||||
// True iff MemberFunction() should die.
|
||||
bool should_die_;
|
||||
};
|
||||
|
||||
|
|
@ -204,26 +199,6 @@ int DieInDebugElse12(int* sideeffect) {
|
|||
return 12;
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Death in dbg due to Windows CRT assertion failure, not opt.
|
||||
int DieInCRTDebugElse12(int* sideeffect) {
|
||||
if (sideeffect) *sideeffect = 12;
|
||||
|
||||
// Create an invalid fd by closing a valid one
|
||||
int fdpipe[2];
|
||||
EXPECT_EQ(_pipe(fdpipe, 256, O_BINARY), 0);
|
||||
EXPECT_EQ(_close(fdpipe[0]), 0);
|
||||
EXPECT_EQ(_close(fdpipe[1]), 0);
|
||||
|
||||
// _dup() should crash in debug mode
|
||||
EXPECT_EQ(_dup(fdpipe[0]), -1);
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// Tests the ExitedWithCode predicate.
|
||||
|
|
@ -298,13 +273,6 @@ TEST(ExitStatusPredicateTest, KilledBySignal) {
|
|||
|
||||
# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
// Tests that the death test macros expand to code which may or may not
|
||||
// be followed by operator<<, and that in either case the complete text
|
||||
// comprises only a single C++ statement.
|
||||
|
|
@ -328,11 +296,6 @@ TEST_F(TestForDeathTest, SingleStatement) {
|
|||
else
|
||||
EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
# if GTEST_USES_PCRE
|
||||
|
||||
void DieWithEmbeddedNul() {
|
||||
fprintf(stderr, "Hello%cmy null world.\n", '\0');
|
||||
|
|
@ -340,6 +303,8 @@ void DieWithEmbeddedNul() {
|
|||
_exit(1);
|
||||
}
|
||||
|
||||
# if GTEST_USES_PCRE
|
||||
|
||||
// Tests that EXPECT_DEATH and ASSERT_DEATH work when the error
|
||||
// message has a NUL character in it.
|
||||
TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
|
||||
|
|
@ -401,19 +366,17 @@ void SigprofAction(int, siginfo_t*, void*) { /* no op */ }
|
|||
|
||||
// Sets SIGPROF action and ITIMER_PROF timer (interval: 1ms).
|
||||
void SetSigprofActionAndTimer() {
|
||||
struct itimerval timer;
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 1;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL));
|
||||
struct sigaction signal_action;
|
||||
memset(&signal_action, 0, sizeof(signal_action));
|
||||
sigemptyset(&signal_action.sa_mask);
|
||||
signal_action.sa_sigaction = SigprofAction;
|
||||
signal_action.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, nullptr));
|
||||
// timer comes second, to avoid SIGPROF premature delivery, as suggested at
|
||||
// https://www.gnu.org/software/libc/manual/html_node/Setting-an-Alarm.html
|
||||
struct itimerval timer;
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 1;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
|
||||
ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, NULL));
|
||||
}
|
||||
|
||||
// Disables ITIMER_PROF timer and ignores SIGPROF signal.
|
||||
|
|
@ -422,7 +385,7 @@ void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) {
|
|||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 0;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL));
|
||||
struct sigaction signal_action;
|
||||
memset(&signal_action, 0, sizeof(signal_action));
|
||||
sigemptyset(&signal_action.sa_mask);
|
||||
|
|
@ -489,17 +452,21 @@ TEST_F(TestForDeathTest, MixedStyles) {
|
|||
|
||||
# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
|
||||
|
||||
namespace {
|
||||
|
||||
bool pthread_flag;
|
||||
|
||||
void SetPthreadFlag() {
|
||||
pthread_flag = true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
|
||||
if (!testing::GTEST_FLAG(death_test_use_fork)) {
|
||||
testing::GTEST_FLAG(death_test_style) = "threadsafe";
|
||||
pthread_flag = false;
|
||||
ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr));
|
||||
ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, NULL, NULL));
|
||||
ASSERT_DEATH(_exit(1), "");
|
||||
ASSERT_FALSE(pthread_flag);
|
||||
}
|
||||
|
|
@ -527,15 +494,18 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
|
|||
const testing::internal::RE regex(regex_c_str);
|
||||
EXPECT_DEATH(GlobalFunction(), regex);
|
||||
|
||||
# if GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
const ::string regex_str(regex_c_str);
|
||||
EXPECT_DEATH(GlobalFunction(), regex_str);
|
||||
|
||||
# endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
# if !GTEST_USES_PCRE
|
||||
|
||||
const ::std::string regex_std_str(regex_c_str);
|
||||
EXPECT_DEATH(GlobalFunction(), regex_std_str);
|
||||
|
||||
// This one is tricky; a temporary pointer into another temporary. Reference
|
||||
// lifetime extension of the pointer is not sufficient.
|
||||
EXPECT_DEATH(GlobalFunction(), ::std::string(regex_c_str).c_str());
|
||||
|
||||
# endif // !GTEST_USES_PCRE
|
||||
}
|
||||
|
||||
|
|
@ -585,8 +555,8 @@ TEST_F(TestForDeathTest, ErrorMessageMismatch) {
|
|||
}, "died but not with expected error");
|
||||
}
|
||||
|
||||
// On exit, *aborted will be true if and only if the EXPECT_DEATH()
|
||||
// statement aborted the function.
|
||||
// On exit, *aborted will be true iff the EXPECT_DEATH() statement
|
||||
// aborted the function.
|
||||
void ExpectDeathTestHelper(bool* aborted) {
|
||||
*aborted = true;
|
||||
EXPECT_DEATH(DieIf(false), "DieIf"); // This assertion should fail.
|
||||
|
|
@ -666,40 +636,6 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
|
|||
# endif
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Tests that EXPECT_DEBUG_DEATH works as expected when in debug mode
|
||||
// the Windows CRT crashes the process with an assertion failure.
|
||||
// 1. Asserts on death.
|
||||
// 2. Has no side effect (doesn't pop up a window or wait for user input).
|
||||
//
|
||||
// And in opt mode, it:
|
||||
// 1. Has side effects but does not assert.
|
||||
TEST_F(TestForDeathTest, CRTDebugDeath) {
|
||||
int sideeffect = 0;
|
||||
|
||||
// Put the regex in a local variable to make sure we don't get an "unused"
|
||||
// warning in opt mode.
|
||||
const char* regex = "dup.* : Assertion failed";
|
||||
|
||||
EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
|
||||
<< "Must accept a streamed message";
|
||||
|
||||
# ifdef NDEBUG
|
||||
|
||||
// Checks that the assignment occurs in opt mode (sideeffect).
|
||||
EXPECT_EQ(12, sideeffect);
|
||||
|
||||
# else
|
||||
|
||||
// Checks that the assignment does not occur in dbg mode (no sideeffect).
|
||||
EXPECT_EQ(0, sideeffect);
|
||||
|
||||
# endif
|
||||
}
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a
|
||||
// message to it, and in debug mode it:
|
||||
// 1. Asserts on death.
|
||||
|
|
@ -940,9 +876,9 @@ TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
|
|||
class MockDeathTestFactory : public DeathTestFactory {
|
||||
public:
|
||||
MockDeathTestFactory();
|
||||
bool Create(const char* statement,
|
||||
testing::Matcher<const std::string&> matcher, const char* file,
|
||||
int line, DeathTest** test) override;
|
||||
virtual bool Create(const char* statement,
|
||||
const ::testing::internal::RE* regex,
|
||||
const char* file, int line, DeathTest** test);
|
||||
|
||||
// Sets the parameters for subsequent calls to Create.
|
||||
void SetParameters(bool create, DeathTest::TestRole role,
|
||||
|
|
@ -952,12 +888,10 @@ class MockDeathTestFactory : public DeathTestFactory {
|
|||
int AssumeRoleCalls() const { return assume_role_calls_; }
|
||||
int WaitCalls() const { return wait_calls_; }
|
||||
size_t PassedCalls() const { return passed_args_.size(); }
|
||||
bool PassedArgument(int n) const {
|
||||
return passed_args_[static_cast<size_t>(n)];
|
||||
}
|
||||
bool PassedArgument(int n) const { return passed_args_[n]; }
|
||||
size_t AbortCalls() const { return abort_args_.size(); }
|
||||
DeathTest::AbortReason AbortArgument(int n) const {
|
||||
return abort_args_[static_cast<size_t>(n)];
|
||||
return abort_args_[n];
|
||||
}
|
||||
bool TestDeleted() const { return test_deleted_; }
|
||||
|
||||
|
|
@ -999,20 +933,22 @@ class MockDeathTest : public DeathTest {
|
|||
TestRole role, int status, bool passed) :
|
||||
parent_(parent), role_(role), status_(status), passed_(passed) {
|
||||
}
|
||||
~MockDeathTest() override { parent_->test_deleted_ = true; }
|
||||
TestRole AssumeRole() override {
|
||||
virtual ~MockDeathTest() {
|
||||
parent_->test_deleted_ = true;
|
||||
}
|
||||
virtual TestRole AssumeRole() {
|
||||
++parent_->assume_role_calls_;
|
||||
return role_;
|
||||
}
|
||||
int Wait() override {
|
||||
virtual int Wait() {
|
||||
++parent_->wait_calls_;
|
||||
return status_;
|
||||
}
|
||||
bool Passed(bool exit_status_ok) override {
|
||||
virtual bool Passed(bool exit_status_ok) {
|
||||
parent_->passed_args_.push_back(exit_status_ok);
|
||||
return passed_;
|
||||
}
|
||||
void Abort(AbortReason reason) override {
|
||||
virtual void Abort(AbortReason reason) {
|
||||
parent_->abort_args_.push_back(reason);
|
||||
}
|
||||
|
||||
|
|
@ -1056,14 +992,16 @@ void MockDeathTestFactory::SetParameters(bool create,
|
|||
// Sets test to NULL (if create_ is false) or to the address of a new
|
||||
// MockDeathTest object with parameters taken from the last call
|
||||
// to SetParameters (if create_ is true). Always returns true.
|
||||
bool MockDeathTestFactory::Create(
|
||||
const char* /*statement*/, testing::Matcher<const std::string&> /*matcher*/,
|
||||
const char* /*file*/, int /*line*/, DeathTest** test) {
|
||||
bool MockDeathTestFactory::Create(const char* /*statement*/,
|
||||
const ::testing::internal::RE* /*regex*/,
|
||||
const char* /*file*/,
|
||||
int /*line*/,
|
||||
DeathTest** test) {
|
||||
test_deleted_ = false;
|
||||
if (create_) {
|
||||
*test = new MockDeathTest(this, role_, status_, passed_);
|
||||
} else {
|
||||
*test = nullptr;
|
||||
*test = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1076,16 +1014,16 @@ class MacroLogicDeathTest : public testing::Test {
|
|||
static testing::internal::ReplaceDeathTestFactory* replacer_;
|
||||
static MockDeathTestFactory* factory_;
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
static void SetUpTestCase() {
|
||||
factory_ = new MockDeathTestFactory;
|
||||
replacer_ = new testing::internal::ReplaceDeathTestFactory(factory_);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
delete replacer_;
|
||||
replacer_ = nullptr;
|
||||
replacer_ = NULL;
|
||||
delete factory_;
|
||||
factory_ = nullptr;
|
||||
factory_ = NULL;
|
||||
}
|
||||
|
||||
// Runs a death test that breaks the rules by returning. Such a death
|
||||
|
|
@ -1099,9 +1037,10 @@ class MacroLogicDeathTest : public testing::Test {
|
|||
}
|
||||
};
|
||||
|
||||
testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
|
||||
nullptr;
|
||||
MockDeathTestFactory* MacroLogicDeathTest::factory_ = nullptr;
|
||||
testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_
|
||||
= NULL;
|
||||
MockDeathTestFactory* MacroLogicDeathTest::factory_ = NULL;
|
||||
|
||||
|
||||
// Test that nothing happens when the factory doesn't return a DeathTest:
|
||||
TEST_F(MacroLogicDeathTest, NothingHappens) {
|
||||
|
|
@ -1340,6 +1279,9 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
|
|||
|
||||
# if GTEST_OS_WINDOWS
|
||||
TEST(EnvironmentTest, HandleFitsIntoSizeT) {
|
||||
// FIXME: Remove this test after this condition is verified
|
||||
// in a static assertion in gtest-death-test.cc in the function
|
||||
// GetStatusFileDescriptor.
|
||||
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
|
||||
}
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
|
@ -1377,53 +1319,8 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
|
|||
}, "Inside");
|
||||
}
|
||||
|
||||
void DieWithMessage(const char* message) {
|
||||
fputs(message, stderr);
|
||||
fflush(stderr); // Make sure the text is printed before the process exits.
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
|
||||
// googletest tests this, of course; here we ensure that including googlemock
|
||||
// has not broken it.
|
||||
#if GTEST_USES_POSIX_RE
|
||||
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e");
|
||||
#else
|
||||
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
|
||||
EXPECT_DEATH(DieWithMessage("Behind O, I am slain!"),
|
||||
Matcher<const std::string&>(ContainsRegex("I am slain")));
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
EXPECT_DEATH(
|
||||
DieWithMessage("Behind O, I am slain!"),
|
||||
Matcher<const std::string&>(ContainsRegex("Ow, I am slain"))),
|
||||
"Expected: contains regular expression \"Ow, I am slain\"");
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
|
||||
EXPECT_DEATH(DieWithMessage("The rest is silence."),
|
||||
ContainsRegex("rest is silence"));
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
EXPECT_DEATH(DieWithMessage("The rest is silence."),
|
||||
ContainsRegex("rest is science")),
|
||||
"Expected: contains regular expression \"rest is science\"");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#else // !GTEST_HAS_DEATH_TEST follows
|
||||
|
||||
namespace {
|
||||
|
||||
using testing::internal::CaptureStderr;
|
||||
using testing::internal::GetCapturedStderr;
|
||||
|
||||
|
|
@ -1472,19 +1369,8 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
|
|||
EXPECT_EQ(1, n);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // !GTEST_HAS_DEATH_TEST
|
||||
|
||||
namespace {
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
// Tests that the death test macros expand to code which may or may not
|
||||
// be followed by operator<<, and that in either case the complete text
|
||||
// comprises only a single C++ statement.
|
||||
|
|
@ -1510,9 +1396,6 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
|
|||
else
|
||||
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// Tests that conditional death test macros expand to code which interacts
|
||||
// well with switch statements.
|
||||
|
|
@ -1538,5 +1421,3 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
|
|||
TEST(NotADeathTest, Test) {
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue