Boost C++ Libraries: Ticket #5282: Test fixtures do not support virtual inheritance https://svn.boost.org/trac10/ticket/5282 <p> A typical use of fixtures for a test suite is to make it a subclass of the class under test (CUT) so that protected members can be accessed. </p> <p> However, if the CUT has a virtual base class in its inheritance chain, the call to that class's constructor cannot be specified, because the fixture macros introduce another level of inheritance (sub-struct). </p> <p> This means that we have to jump through some hoops to get to protected members. </p> <p> It would be nice to have an argument to the FIXTURE macros that would allow the tester to specify some or all of the initialization list for the final class/struct in the inheritance chain. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5282 Trac 1.4.3 Gennadiy Rozental Mon, 17 Oct 2011 02:34:43 GMT <link>https://svn.boost.org/trac10/ticket/5282#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5282#comment:1</guid> <description> <p> I am not sure I understand what the problem is. CUT is not a fixture. and why fixture needs virtual base classes is unclear. Please provide an example. </p> </description> <category>Ticket</category> </item> <item> <author>Tye Z. <tye.zdrojewski@…></author> <pubDate>Wed, 09 Nov 2011 22:04:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5282#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5282#comment:2</guid> <description> <p> Ok, so if I have a class <code>TestMe</code>... </p> <pre class="wiki">class TestMe { protected: bool protectedValue = 0; int protectedMethod(int arg) { ... } void someProtectedBehavior() { ... } } </pre><p> I will usually create a fixture as a subclass: </p> <pre class="wiki">/** * Override methods to add test functionality */ class TestMeFixture : public TestMe { // override production behavior for testing void someProtectedBehavior() { ... } } BOOST_FIXTURE_TEST_SUITE( MyTestSuite, TestMeFixture ) BOOST_AUTO_TEST_CASE( test_top_level_values ) { int expected = 123; BOOST_CHECK_EQUAL(expected, protectedMethod(456)); // call protected method BOOST_CHECK(protectedValue); // get protected value ... } BOOST_AUTO_TEST_SUITE_END() </pre><p> ...which is far more concise than writing a subclass as separate from the fixture, which would force you to write all sorts of getters and setters and wrappers for protected members. </p> </description> <category>Ticket</category> </item> <item> <author>Tye Z. <tye.zdrojewski@…></author> <pubDate>Wed, 09 Nov 2011 22:20:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5282#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5282#comment:3</guid> <description> <p> Sorry, I forgot to add that <code>TestMe</code> extends another class: </p> <blockquote class="citation"> <pre class="wiki">class TestMe : public TestMeParent { protected: bool protectedValue = 0; int protectedMethod(int arg) { ... } void someProtectedBehavior() { ... } } </pre></blockquote> <p> ...which is fine. But if the inheritance is <strong>virtual</strong>, and <code>TestMeParent</code> does not have a default constructor, then its constructor must be specified by every subclass at any level: </p> <pre class="wiki">class TestMeParent { public: TestMeParent(int initValue) { ... } } class TestMe : public virtual TestMeParent { public: TestMe() : TestMeParent(678) // initializer required at every inheritance level { ... } } </pre><p> This breaks my fixture arrangement, because the fixture is subclassed again by the fixture macros. </p> <p> Hopefully I explained it clearly enough! :) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Gennadiy Rozental</dc:creator> <pubDate>Wed, 08 Jul 2015 05:06:15 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5282#comment:4 https://svn.boost.org/trac10/ticket/5282#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> I am not sure what you recommend us to do in this case. I guess you will have to specialize your base class separately from fixture in this case. </p> Ticket tye.zdrojewski@… Wed, 08 Jul 2015 13:07:24 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/5282#comment:5 https://svn.boost.org/trac10/ticket/5282#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">wontfix</span> </li> </ul> <p> The recommendation is right in the original post: "an argument to the FIXTURE macros that would allow the tester to specify some or all of the initialization list". </p> <p> Is that not do-able for some reason? </p> Ticket Raffi Enficiaud Thu, 22 Jun 2017 22:52:37 GMT milestone changed https://svn.boost.org/trac10/ticket/5282#comment:6 https://svn.boost.org/trac10/ticket/5282#comment:6 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.65.0</span> </li> </ul> Ticket Raffi Enficiaud Fri, 23 Jun 2017 15:42:37 GMT owner, status changed https://svn.boost.org/trac10/ticket/5282#comment:7 https://svn.boost.org/trac10/ticket/5282#comment:7 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Gennadiy Rozental</span> to <span class="trac-author">Raffi Enficiaud</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket Raffi Enficiaud Fri, 23 Jun 2017 15:55:02 GMT <link>https://svn.boost.org/trac10/ticket/5282#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5282#comment:8</guid> <description> <p> I do not get it: you are writing a fixture for being able to test protected members of <code>TestMeParent</code>, and you do not want to specify the constructions of <code>TestMeParent</code> inside your fixture. </p> <p> OTOH, having an additional parameter passed to the <code>BOOST_FIXTURE_TEST_SUITE</code> will not help you very far here: you will still need to initialize <code>TestMeParent</code> in some way, and you will still need to forward whatever has been passed to the ctor of <code>TestMe</code> to <code>TestMeParent</code>. </p> <p> It is a bit confusing, I am flagging this as not doing. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Fri, 23 Jun 2017 15:55:11 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5282#comment:9 https://svn.boost.org/trac10/ticket/5282#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> Ticket Raffi Enficiaud Fri, 23 Jun 2017 15:55:52 GMT milestone changed https://svn.boost.org/trac10/ticket/5282#comment:10 https://svn.boost.org/trac10/ticket/5282#comment:10 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.65.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket tye.zdrojewski@… Mon, 07 Aug 2017 15:52:56 GMT <link>https://svn.boost.org/trac10/ticket/5282#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5282#comment:11</guid> <description> <blockquote class="citation"> <p> you do not want to specify the constructions of <a class="missing wiki">TestMeParent</a> inside your fixture </p> </blockquote> <p> ...as indicated in the description AND in the example, the virtual parent's init list is "required at every inheritance level". That would include the subclass created by the macro. </p> <p> We are talking about VIRTUAL inheritance, not regular inheritance. </p> <blockquote> <p> <br /> </p> </blockquote> <blockquote class="citation"> <p> It is a bit confusing, I am flagging this as not doing. </p> </blockquote> <p> Please do not close an issue because you are confused. </p> </description> <category>Ticket</category> </item> </channel> </rss>