MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / HasSameFixtureClass

Method HasSameFixtureClass

tests/external/gmock-1.7.0/gtest/src/gtest.cc:1945–2004  ·  view source on GitHub ↗

Google Test requires all tests in the same test case to use the same test fixture class. This function checks if the current test has the same fixture class as the first test in the current test case. If yes, it returns true; otherwise it generates a Google Test failure and returns false.

Source from the content-addressed store, hash-verified

1943// yes, it returns true; otherwise it generates a Google Test failure and
1944// returns false.
1945bool Test::HasSameFixtureClass() {
1946 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
1947 const TestCase* const test_case = impl->current_test_case();
1948
1949 // Info about the first test in the current test case.
1950 const TestInfo* const first_test_info = test_case->test_info_list()[0];
1951 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
1952 const char* const first_test_name = first_test_info->name();
1953
1954 // Info about the current test.
1955 const TestInfo* const this_test_info = impl->current_test_info();
1956 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
1957 const char* const this_test_name = this_test_info->name();
1958
1959 if (this_fixture_id != first_fixture_id) {
1960 // Is the first test defined using TEST?
1961 const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
1962 // Is this test defined using TEST?
1963 const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
1964
1965 if (first_is_TEST || this_is_TEST) {
1966 // The user mixed TEST and TEST_F in this test case - we'll tell
1967 // him/her how to fix it.
1968
1969 // Gets the name of the TEST and the name of the TEST_F. Note
1970 // that first_is_TEST and this_is_TEST cannot both be true, as
1971 // the fixture IDs are different for the two tests.
1972 const char* const TEST_name =
1973 first_is_TEST ? first_test_name : this_test_name;
1974 const char* const TEST_F_name =
1975 first_is_TEST ? this_test_name : first_test_name;
1976
1977 ADD_FAILURE()
1978 << "All tests in the same test case must use the same test fixture\n"
1979 << "class, so mixing TEST_F and TEST in the same test case is\n"
1980 << "illegal. In test case " << this_test_info->test_case_name()
1981 << ",\n"
1982 << "test " << TEST_F_name << " is defined using TEST_F but\n"
1983 << "test " << TEST_name << " is defined using TEST. You probably\n"
1984 << "want to change the TEST to TEST_F or move it to another test\n"
1985 << "case.";
1986 } else {
1987 // The user defined two fixture classes with the same name in
1988 // two namespaces - we'll tell him/her how to fix it.
1989 ADD_FAILURE()
1990 << "All tests in the same test case must use the same test fixture\n"
1991 << "class. However, in test case "
1992 << this_test_info->test_case_name() << ",\n"
1993 << "you defined test " << first_test_name
1994 << " and test " << this_test_name << "\n"
1995 << "using two different test fixture classes. This can happen if\n"
1996 << "the two classes are from different namespaces or translation\n"
1997 << "units and have the same name. You should probably rename one\n"
1998 << "of the classes to put the tests into different test cases.";
1999 }
2000 return false;
2001 }
2002

Callers

nothing calls this directly

Calls 2

GetUnitTestImplFunction · 0.70
GetTestTypeIdFunction · 0.70

Tested by

no test coverage detected