#191 Macro CPPUNIT_MAKE_UNIQUE_NAME doesn't make unique names

1.12.0
closed-fixed
5
2009-11-24
2008-07-29
Timo
No

Hi all,

the macro CPPUNIT_MAKE_UNIQUE_NAME is coded in a very optimistic style. It assumes there doesn't exist two files which contain this macro on the same line.

See the definition below:
#define CPPUNIT_MAKE_UNIQUE_NAME( prefix ) CPPUNIT_JOIN( prefix, __LINE__ )

A possible bugfix would be:

A)
#define CPPUNIT_MAKE_UNIQUE_NAME( prefix) CPPUNIT_JOIN( prefix, __COUNTER__ )

or

B)
I found this problem at calls to CPPUNIT_TEST_SUITE_REGISTRATION. I haven't made a deeper look at the source code of cppunit, but therefor this should also work.

Change CPPUNIT_TEST_SUITE_REGISTRATION definition like this:
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \ static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \ CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__, ATestFixtureType )

Change or add a second definition of CPPUNIT_MAKE_UNIQUE_NAME:
#define CPPUNIT_MAKE_UNIQUE_NAME( prefix, suffix ) CPPUNIT_JOIN( prefix, CPPUNIT_JOIN( suffix, __LINE__ ))

Cheers
Timo

Discussion

  • Steven Robbins

    Steven Robbins - 2008-10-11

    Unit test that demonstrates bug

     
  • Baptiste Lepilleur

    • milestone: --> 1.12.0
    • assigned_to: nobody --> blep
    • status: open --> closed-fixed
     
  • Baptiste Lepilleur

    Fixed in revision 579.

     

Log in to post a comment.