Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions deps/googletest/include/gtest/gtest-typed-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
// The variables defined in the type-parameterized test macros are
// static as typically these macros are used in a .h file that can be
// #included in multiple translation units linked together.
#define TYPED_TEST_SUITE_P(SuiteName) \
static ::testing::internal::TypedTestSuitePState \
// Marked [[maybe_unused]] because TypedTestSuitePState is
// constexpr-constructible and trivially destructible, so an uninstantiated
// suite would otherwise trigger -Wunused-variable.
#define TYPED_TEST_SUITE_P(SuiteName) \
[[maybe_unused]] static ::testing::internal::TypedTestSuitePState \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)

// Legacy API is deprecated but still available
Expand All @@ -267,22 +270,24 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_

#define TYPED_TEST_P(SuiteName, TestName) \
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
template <typename gtest_TypeParam_> \
class TestName : public SuiteName<gtest_TypeParam_> { \
private: \
typedef SuiteName<gtest_TypeParam_> TestFixture; \
typedef gtest_TypeParam_ TypeParam; \
void TestBody() override; \
}; \
[[maybe_unused]] static bool gtest_##TestName##_defined_ = \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \
__FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \
GTEST_STRINGIFY_(TestName)); \
} \
template <typename gtest_TypeParam_> \
void GTEST_SUITE_NAMESPACE_( \
#define TYPED_TEST_P(SuiteName, TestName) \
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
template <typename gtest_TypeParam_> \
class TestName : public SuiteName<gtest_TypeParam_> { \
private: \
typedef SuiteName<gtest_TypeParam_> TestFixture; \
typedef gtest_TypeParam_ TypeParam; \
void TestBody() override; \
}; \
static ::testing::internal::TypedTestSuitePState::RegisteredTest \
gtest_##TestName##_registered_test_ = {GTEST_STRINGIFY_(TestName), \
__FILE__, __LINE__, nullptr}; \
[[maybe_unused]] static bool gtest_##TestName##_defined_ = \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTest( \
&gtest_##TestName##_registered_test_, GTEST_STRINGIFY_(SuiteName)); \
} \
template <typename gtest_TypeParam_> \
void GTEST_SUITE_NAMESPACE_( \
SuiteName)::TestName<gtest_TypeParam_>::TestBody()

// Note: this won't work correctly if the trailing arguments are macros.
Expand Down
72 changes: 54 additions & 18 deletions deps/googletest/include/gtest/internal/gtest-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,51 +577,87 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)

// State of the definition of a type-parameterized test suite.
// Uses an intrusive linked list of caller-allocated POD RegisteredTest nodes
// rather than an STL container.
// REQUIRES: TypedTestSuitePState must be constexpr-constructible and trivially
// destructible so that namespace-scope static instances defined by
// TYPED_TEST_SUITE_P avoid -Wglobal-constructors and -Wexit-time-destructors.
class GTEST_API_ [[nodiscard]] TypedTestSuitePState {
public:
TypedTestSuitePState() : registered_(false) {}

// Adds the given test name to defined_test_names_ and return true
// if the test suite hasn't been registered; otherwise aborts the
// program.
bool AddTestName(const char* file, int line, const char* case_name,
const char* test_name) {
// Caller-owned POD node linked into registered_tests_; must outlive this
// TypedTestSuitePState instance.
struct RegisteredTest {
const char* name;
const char* file;
int line;
RegisteredTest* next;
};

constexpr TypedTestSuitePState() = default;

// Adds the given test to registered_tests_ and returns true if the test
// suite hasn't been registered; otherwise aborts the program.
bool AddTest(RegisteredTest* test, const char* case_name) {
if (registered_) {
fprintf(stderr,
"%s Test %s must be defined before "
"REGISTER_TYPED_TEST_SUITE_P(%s, ...).\n",
FormatFileLocation(file, line).c_str(), test_name, case_name);
FormatFileLocation(test->file, test->line).c_str(), test->name,
case_name);
fflush(stderr);
posix::Abort();
}
registered_tests_.emplace(test_name, CodeLocation(file, line));
// Insert into registered_tests_ in lexicographical order by test name
// (ignoring duplicates) so VerifyRegisteredTestNames reports missing tests
// in deterministic sorted order.
RegisteredTest** p = &registered_tests_;
while (*p != nullptr && strcmp((*p)->name, test->name) < 0) {
p = &(*p)->next;
}
if (*p == nullptr || strcmp((*p)->name, test->name) != 0) {
test->next = *p;
*p = test;
}
return true;
}

bool TestExists(const std::string& test_name) const {
return registered_tests_.count(test_name) > 0;
return FindTest(test_name) != nullptr;
}

const CodeLocation& GetCodeLocation(const std::string& test_name) const {
RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
GTEST_CHECK_(it != registered_tests_.end());
return it->second;
CodeLocation GetCodeLocation(const std::string& test_name) const {
const RegisteredTest* test = FindTest(test_name);
GTEST_CHECK_(test != nullptr);
return CodeLocation(test->file, test->line);
}

// Verifies that registered_tests match the test names in
// defined_test_names_; returns registered_tests if successful, or
// registered_tests_; returns registered_tests if successful, or
// aborts the program otherwise.
const char* VerifyRegisteredTestNames(const char* test_suite_name,
const char* file, int line,
const char* registered_tests);

private:
typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
const RegisteredTest* FindTest(const std::string& test_name) const {
for (const RegisteredTest* it = registered_tests_; it != nullptr;
it = it->next) {
if (test_name == it->name) {
return it;
}
}
return nullptr;
}

bool registered_;
RegisteredTestsMap registered_tests_;
bool registered_ = false;
RegisteredTest* registered_tests_ = nullptr;
};

static_assert((static_cast<void>(TypedTestSuitePState{}), true),
"TypedTestSuitePState must be constexpr-constructible");
static_assert(std::is_trivially_destructible_v<TypedTestSuitePState>,
"TypedTestSuitePState must be trivially destructible");

// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
using TypedTestCasePState = TypedTestSuitePState;
Expand Down
11 changes: 5 additions & 6 deletions deps/googletest/src/gtest-typed-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const char* TypedTestSuitePState::VerifyRegisteredTestNames(
const char* registered_tests) {
RegisterTypeParameterizedTestSuite(test_suite_name, CodeLocation(file, line));

typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
registered_ = true;

std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests);
Expand All @@ -78,18 +77,18 @@ const char* TypedTestSuitePState::VerifyRegisteredTestNames(
continue;
}

if (registered_tests_.count(name) != 0) {
if (TestExists(name)) {
tests.insert(name);
} else {
errors << "No test named " << name
<< " can be found in this test suite.\n";
}
}

for (RegisteredTestIter it = registered_tests_.begin();
it != registered_tests_.end(); ++it) {
if (tests.count(it->first) == 0) {
errors << "You forgot to list test " << it->first << ".\n";
for (const RegisteredTest* it = registered_tests_; it != nullptr;
it = it->next) {
if (tests.count(it->name) == 0) {
errors << "You forgot to list test " << it->name << ".\n";
}
}

Expand Down
Loading