0

I have a list of preprocessor directives as :

#define __SIZE_TYPE__ long unsigned int
#define __UINT16_TYPE__ short unsigned int
#define __UINT_LEAST8_TYPE__ unsigned char
#define __VERSION__ 4
.
.

Now i am writing a cppunit test case which checks for these directives value as follows:

CPPUNIT_ASSERT_EQUAL(4, __VERSION__);

Now i want write same cppunit asserts for UINT16_TYPE , SIZE_TYPE , UINT_LEAST8_TYPE in order to make sure they have right value or not but i am not getting which cppunit assertion shall i use? So, please suggest which cppunit assert to use for this purpose?

Learner
  • 453
  • 13
  • 29
  • 2
    Do you define those macros yourself in your own headers for your own project? Then don't. Names beginning with double underscore [are reserved in all scopes for the implementation (compiler and standard library)](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – Some programmer dude Jan 29 '16 at 08:58
  • @JoachimPileborg no i have not defined them by myself they are generated by gcc -dM -E - < /dev/null command – Learner Jan 29 '16 at 09:01

2 Answers2

0

Going by their names, it seems they are the macros used for the "standard" integers defined in the <cstdint> header file.

In that case, __UINT16_TYPE__ should be an unsigned 16-bit value, which is easily testable. You could do e.g.

CPPUNIT_ASSERT_EQUAL(2, sizeof(__UINT16_TYPE__));

This of course relies on that you're in a "normal" computer based on 8-bit bytes.

To check the type, you could use the C++11 type-traits, like std::is_integral or std::is_unsigned.

I really don't see the point of doing these checks. If these macros are generated by the compiler then you can be pretty sure they are correct for the platform you're on.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
0

If you're using C++11, use std::is_same to check types. http://en.cppreference.com/w/cpp/types/is_same

For example: CPPUNIT_ASSERT(std::is_same<SIZE_TYPE, long unsigned int>::value)

But honestly, I don't see any rationale in such checks.

Igor Semenov
  • 483
  • 5
  • 13