MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / HasSameFixtureClass

Method HasSameFixtureClass

test/common/gtest/gtest.cpp:3744–3803  ·  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

3742// yes, it returns true; otherwise it generates a Google Test failure and
3743// returns false.
3744bool Test::HasSameFixtureClass() {
3745 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
3746 const TestCase* const test_case = impl->current_test_case();
3747
3748 // Info about the first test in the current test case.
3749 const TestInfo* const first_test_info = test_case->test_info_list()[0];
3750 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
3751 const char* const first_test_name = first_test_info->name();
3752
3753 // Info about the current test.
3754 const TestInfo* const this_test_info = impl->current_test_info();
3755 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
3756 const char* const this_test_name = this_test_info->name();
3757
3758 if (this_fixture_id != first_fixture_id) {
3759 // Is the first test defined using TEST?
3760 const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
3761 // Is this test defined using TEST?
3762 const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
3763
3764 if (first_is_TEST || this_is_TEST) {
3765 // Both TEST and TEST_F appear in same test case, which is incorrect.
3766 // Tell the user how to fix this.
3767
3768 // Gets the name of the TEST and the name of the TEST_F. Note
3769 // that first_is_TEST and this_is_TEST cannot both be true, as
3770 // the fixture IDs are different for the two tests.
3771 const char* const TEST_name =
3772 first_is_TEST ? first_test_name : this_test_name;
3773 const char* const TEST_F_name =
3774 first_is_TEST ? this_test_name : first_test_name;
3775
3776 ADD_FAILURE()
3777 << "All tests in the same test case must use the same test fixture\n"
3778 << "class, so mixing TEST_F and TEST in the same test case is\n"
3779 << "illegal. In test case " << this_test_info->test_case_name()
3780 << ",\n"
3781 << "test " << TEST_F_name << " is defined using TEST_F but\n"
3782 << "test " << TEST_name << " is defined using TEST. You probably\n"
3783 << "want to change the TEST to TEST_F or move it to another test\n"
3784 << "case.";
3785 } else {
3786 // Two fixture classes with the same name appear in two different
3787 // namespaces, which is not allowed. Tell the user how to fix this.
3788 ADD_FAILURE()
3789 << "All tests in the same test case must use the same test fixture\n"
3790 << "class. However, in test case "
3791 << this_test_info->test_case_name() << ",\n"
3792 << "you defined test " << first_test_name
3793 << " and test " << this_test_name << "\n"
3794 << "using two different test fixture classes. This can happen if\n"
3795 << "the two classes are from different namespaces or translation\n"
3796 << "units and have the same name. You should probably rename one\n"
3797 << "of the classes to put the tests into different test cases.";
3798 }
3799 return false;
3800 }
3801

Callers

nothing calls this directly

Calls 3

GetUnitTestImplFunction · 0.85
GetTestTypeIdFunction · 0.85
nameMethod · 0.80

Tested by

no test coverage detected