Replace NSS with Pale Moon's

This commit is contained in:
wuggy 2026-06-29 21:29:25 +01:00
commit 8c2e376f94
2870 changed files with 1762232 additions and 1374220 deletions

View file

@ -31,6 +31,7 @@
// Tests for death tests.
#include "gtest/gtest-death-test.h"
#include "gtest/gtest.h"
#include "gtest/internal/gtest-filepath.h"
@ -40,7 +41,9 @@ 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.
@ -59,6 +62,8 @@ 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;
@ -97,6 +102,8 @@ 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.
@ -123,9 +130,7 @@ class TestForDeathTest : public testing::Test {
protected:
TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
virtual ~TestForDeathTest() {
posix::ChDir(original_dir_.c_str());
}
~TestForDeathTest() override { posix::ChDir(original_dir_.c_str()); }
// A static member function that's expected to die.
static void StaticMemberFunction() { DieInside("StaticMemberFunction"); }
@ -136,7 +141,7 @@ class TestForDeathTest : public testing::Test {
DieInside("MemberFunction");
}
// True iff MemberFunction() should die.
// True if and only if MemberFunction() should die.
bool should_die_;
const FilePath original_dir_;
};
@ -153,7 +158,7 @@ class MayDie {
}
private:
// True iff MemberFunction() should die.
// True if and only if MemberFunction() should die.
bool should_die_;
};
@ -199,6 +204,26 @@ 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.
@ -273,6 +298,13 @@ 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.
@ -296,6 +328,11 @@ 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');
@ -303,8 +340,6 @@ 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) {
@ -366,17 +401,19 @@ 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, NULL));
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));
}
// Disables ITIMER_PROF timer and ignores SIGPROF signal.
@ -385,7 +422,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, NULL));
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
struct sigaction signal_action;
memset(&signal_action, 0, sizeof(signal_action));
sigemptyset(&signal_action.sa_mask);
@ -452,21 +489,17 @@ 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, NULL, NULL));
ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr));
ASSERT_DEATH(_exit(1), "");
ASSERT_FALSE(pthread_flag);
}
@ -494,18 +527,15 @@ 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
}
@ -555,8 +585,8 @@ TEST_F(TestForDeathTest, ErrorMessageMismatch) {
}, "died but not with expected error");
}
// On exit, *aborted will be true iff the EXPECT_DEATH() statement
// aborted the function.
// On exit, *aborted will be true if and only if the EXPECT_DEATH()
// statement aborted the function.
void ExpectDeathTestHelper(bool* aborted) {
*aborted = true;
EXPECT_DEATH(DieIf(false), "DieIf"); // This assertion should fail.
@ -636,6 +666,40 @@ 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.
@ -876,9 +940,9 @@ TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
class MockDeathTestFactory : public DeathTestFactory {
public:
MockDeathTestFactory();
virtual bool Create(const char* statement,
const ::testing::internal::RE* regex,
const char* file, int line, DeathTest** test);
bool Create(const char* statement,
testing::Matcher<const std::string&> matcher, const char* file,
int line, DeathTest** test) override;
// Sets the parameters for subsequent calls to Create.
void SetParameters(bool create, DeathTest::TestRole role,
@ -888,10 +952,12 @@ 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_[n]; }
bool PassedArgument(int n) const {
return passed_args_[static_cast<size_t>(n)];
}
size_t AbortCalls() const { return abort_args_.size(); }
DeathTest::AbortReason AbortArgument(int n) const {
return abort_args_[n];
return abort_args_[static_cast<size_t>(n)];
}
bool TestDeleted() const { return test_deleted_; }
@ -933,22 +999,20 @@ class MockDeathTest : public DeathTest {
TestRole role, int status, bool passed) :
parent_(parent), role_(role), status_(status), passed_(passed) {
}
virtual ~MockDeathTest() {
parent_->test_deleted_ = true;
}
virtual TestRole AssumeRole() {
~MockDeathTest() override { parent_->test_deleted_ = true; }
TestRole AssumeRole() override {
++parent_->assume_role_calls_;
return role_;
}
virtual int Wait() {
int Wait() override {
++parent_->wait_calls_;
return status_;
}
virtual bool Passed(bool exit_status_ok) {
bool Passed(bool exit_status_ok) override {
parent_->passed_args_.push_back(exit_status_ok);
return passed_;
}
virtual void Abort(AbortReason reason) {
void Abort(AbortReason reason) override {
parent_->abort_args_.push_back(reason);
}
@ -992,16 +1056,14 @@ 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*/,
const ::testing::internal::RE* /*regex*/,
const char* /*file*/,
int /*line*/,
DeathTest** test) {
bool MockDeathTestFactory::Create(
const char* /*statement*/, testing::Matcher<const std::string&> /*matcher*/,
const char* /*file*/, int /*line*/, DeathTest** test) {
test_deleted_ = false;
if (create_) {
*test = new MockDeathTest(this, role_, status_, passed_);
} else {
*test = NULL;
*test = nullptr;
}
return true;
}
@ -1014,16 +1076,16 @@ class MacroLogicDeathTest : public testing::Test {
static testing::internal::ReplaceDeathTestFactory* replacer_;
static MockDeathTestFactory* factory_;
static void SetUpTestCase() {
static void SetUpTestSuite() {
factory_ = new MockDeathTestFactory;
replacer_ = new testing::internal::ReplaceDeathTestFactory(factory_);
}
static void TearDownTestCase() {
static void TearDownTestSuite() {
delete replacer_;
replacer_ = NULL;
replacer_ = nullptr;
delete factory_;
factory_ = NULL;
factory_ = nullptr;
}
// Runs a death test that breaks the rules by returning. Such a death
@ -1037,10 +1099,9 @@ class MacroLogicDeathTest : public testing::Test {
}
};
testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_
= NULL;
MockDeathTestFactory* MacroLogicDeathTest::factory_ = NULL;
testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
nullptr;
MockDeathTestFactory* MacroLogicDeathTest::factory_ = nullptr;
// Test that nothing happens when the factory doesn't return a DeathTest:
TEST_F(MacroLogicDeathTest, NothingHappens) {
@ -1279,9 +1340,6 @@ 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
@ -1319,8 +1377,53 @@ 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;
@ -1369,8 +1472,19 @@ 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.
@ -1396,6 +1510,9 @@ 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.
@ -1421,3 +1538,5 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
TEST(NotADeathTest, Test) {
SUCCEED();
}
} // namespace