Jump to content

  • Log In with Google      Sign In   
  • Create Account

Quick help with a macro (preprocessor)


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1   Crossbones+   -  Reputation: 2572

Like
0Likes
Like

Posted 12 March 2014 - 12:30 PM

I'm using gtest (google's testing framework), and use the following code for my test fixtures:

#define TEST_NAME test_foo

TEST( TEST_NAME, bar )
{
    reset_ports();
    /* test body begins here */
}

The function reset_ports is part of some very primitive micro controller hardware emulation code, and I'd like it to be called between every test fixture to ensure a clean state. I tried writing a small macro for doing this for me, but I can't get it to work:

#define BEGIN(x) (TEST((TEST_NAME), (x)) { reset_ports();)
#define END }

BEGIN( bar )
    /* test body begins here */
END

The errors I'm getting are:

error: pasting ")" and "_" does not give a valid preprocessing token|
error: pasting "_" and "(" does not give a valid preprocessing token|
error: pasting ")" and "_Test" does not give a valid preprocessing token|
error: pasting ")" and "_" does not give a valid preprocessing token|
error: pasting "_" and "(" does not give a valid preprocessing token|
error: pasting ")" and "_Test" does not give a valid preprocessing token|
error: pasting ")" and "_" does not give a valid preprocessing token|
...

Any help? I've not practiced my preprocessor-voodoo enough to understand what's wrong.


"Windows 10 doesn't only include spyware, it is designed as spyware" -- Gaius Publius, The Big Picture RT Interview

"[...] we will access, disclose and preserve personal data, including your content (such as the content of your emails, other private communications or files in private folders), when we have a good faith belief that doing so is necessary" -- Windows 10 Privacy Statement


#2   Crossbones+   -  Reputation: 2572

Like
0Likes
Like

Posted 12 March 2014 - 12:44 PM

UPDATE

 

The following appears to be closer to solving the problem:

#define TEST_NAME test_regulator_getters_and_setters
#define BEGIN(x) (TEST(TEST_NAME, x)) { reset_ports();
#define END }

Now I'm only getting two errors:

error: expected unqualified-id before 'class'|
error: expected ')' before 'class'|

Also some more helpful information: the TEST macro is defined as:

#define GTEST_TEST(test_case_name, test_name)\
  GTEST_TEST_(test_case_name, test_name, \
              ::testing::Test, ::testing::internal::GetTestTypeId())

#if !GTEST_DONT_DEFINE_TEST
# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
#endif

"Windows 10 doesn't only include spyware, it is designed as spyware" -- Gaius Publius, The Big Picture RT Interview

"[...] we will access, disclose and preserve personal data, including your content (such as the content of your emails, other private communications or files in private folders), when we have a good faith belief that doing so is necessary" -- Windows 10 Privacy Statement


#3   Crossbones+   -  Reputation: 7984

Like
0Likes
Like

Posted 12 March 2014 - 01:19 PM

Looks to me like you're trying to reinvent, using a 1960's era text processor, what's already available in the test fixture SetUp() and TearDown() function.  Have you tried using those to set up and tear down your fixture instead?


Stephen M. Webb
Professional Free Software Developer

#4   Crossbones+   -  Reputation: 2572

Like
0Likes
Like

Posted 12 March 2014 - 05:05 PM

Exactly what I was looking for, thanks!


"Windows 10 doesn't only include spyware, it is designed as spyware" -- Gaius Publius, The Big Picture RT Interview

"[...] we will access, disclose and preserve personal data, including your content (such as the content of your emails, other private communications or files in private folders), when we have a good faith belief that doing so is necessary" -- Windows 10 Privacy Statement





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS