Boost logo

Boost Users :

Subject: Re: [Boost-users] [BOOST]BOOST_AUTO_TEST_CASE_TEMPLATE vs BOOST_AUTO_TEST_CASE
From: Richard (legalize+jeeves_at_[hidden])
Date: 2013-12-29 02:45:26


[Please do not mail me a copy of your followup]

boost-users_at_[hidden] spake the secret code
<518813FAAE539546847B8F61C0C9B2FA9B7B2388_at_[hidden]> thusly:

>Why is the behaviour different in these 2 scenarios? How is Boost able
>to differenciate between the 2 test cases in Scenario1?

The difference is that non-template test cases are generated
statically with unique names that cannot violate the one-definition
rule.

When you use BOOST_AUTO_TEST_CASE in multiple translation units inside
the same test suite (which is really just a glorified namespace),
the test cases must have unique names in order to not violate the one
definition rule.

When you use BOOST_AUTO_TEST_CASE_TEMPLATE, you get a uniquely named
static instance of a class whose constructor registers the dynamically
generated test cases for each of the template arguments.

The same templatized code appears in each translation unit, but C++
allows the linker to discard all but one of the multiple instantiations
of the same template.

In order to provide this explanation, what I did was to take your
template example code and expand the BOOST_AUTO_TEST_CASE_TEMPLATE
macro until it was resolved down into actual code.

-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://computergraphicsmuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net