MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / HasSameFixtureClass

Method HasSameFixtureClass

rtpose_wrapper/src/gtest/gtest-all.cpp:3254–3313  ·  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

3252// yes, it returns true; otherwise it generates a Google Test failure and
3253// returns false.
3254bool Test::HasSameFixtureClass() {
3255 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
3256 const TestCase* const test_case = impl->current_test_case();
3257
3258 // Info about the first test in the current test case.
3259 const TestInfo* const first_test_info = test_case->test_info_list()[0];
3260 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
3261 const char* const first_test_name = first_test_info->name();
3262
3263 // Info about the current test.
3264 const TestInfo* const this_test_info = impl->current_test_info();
3265 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
3266 const char* const this_test_name = this_test_info->name();
3267
3268 if (this_fixture_id != first_fixture_id) {
3269 // Is the first test defined using TEST?
3270 const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
3271 // Is this test defined using TEST?
3272 const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
3273
3274 if (first_is_TEST || this_is_TEST) {
3275 // The user mixed TEST and TEST_F in this test case - we'll tell
3276 // him/her how to fix it.
3277
3278 // Gets the name of the TEST and the name of the TEST_F. Note
3279 // that first_is_TEST and this_is_TEST cannot both be true, as
3280 // the fixture IDs are different for the two tests.
3281 const char* const TEST_name =
3282 first_is_TEST ? first_test_name : this_test_name;
3283 const char* const TEST_F_name =
3284 first_is_TEST ? this_test_name : first_test_name;
3285
3286 ADD_FAILURE()
3287 << "All tests in the same test case must use the same test fixture\n"
3288 << "class, so mixing TEST_F and TEST in the same test case is\n"
3289 << "illegal. In test case " << this_test_info->test_case_name()
3290 << ",\n"
3291 << "test " << TEST_F_name << " is defined using TEST_F but\n"
3292 << "test " << TEST_name << " is defined using TEST. You probably\n"
3293 << "want to change the TEST to TEST_F or move it to another test\n"
3294 << "case.";
3295 } else {
3296 // The user defined two fixture classes with the same name in
3297 // two namespaces - we'll tell him/her how to fix it.
3298 ADD_FAILURE()
3299 << "All tests in the same test case must use the same test fixture\n"
3300 << "class. However, in test case "
3301 << this_test_info->test_case_name() << ",\n"
3302 << "you defined test " << first_test_name
3303 << " and test " << this_test_name << "\n"
3304 << "using two different test fixture classes. This can happen if\n"
3305 << "the two classes are from different namespaces or translation\n"
3306 << "units and have the same name. You should probably rename one\n"
3307 << "of the classes to put the tests into different test cases.";
3308 }
3309 return false;
3310 }
3311

Callers

nothing calls this directly

Calls 4

GetUnitTestImplFunction · 0.85
GetTestTypeIdFunction · 0.85
current_test_caseMethod · 0.80
current_test_infoMethod · 0.80

Tested by

no test coverage detected