Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/util/VA_NARGSTest.cc @ 10259

Last change on this file since 10259 was 9114, checked in by landauf, 13 years ago

added tests for several classes and functions in util

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1#include <gtest/gtest.h>
2#include "util/VA_NARGS.h"
3
4TEST(VA_NARGS, DirectCall)
5{
6    //EXPECT_EQ(0, ORXONOX_VA_NARGS()); // documented issue of the macro - min number of elements is 1
7
8    EXPECT_EQ(1, ORXONOX_VA_NARGS(some));
9    EXPECT_EQ(2, ORXONOX_VA_NARGS(some, argument));
10    EXPECT_EQ(3, ORXONOX_VA_NARGS(some, argument, to));
11    EXPECT_EQ(4, ORXONOX_VA_NARGS(some, argument, to, test));
12    EXPECT_EQ(5, ORXONOX_VA_NARGS(some, argument, to, test, the));
13    EXPECT_EQ(6, ORXONOX_VA_NARGS(some, argument, to, test, the, macro));
14}
15
16
17#define TEST_MACRO_CONSTANT(...) \
18    BOOST_PP_EXPAND(BOOST_PP_CAT(TEST_MACRO_CONSTANT, ORXONOX_VA_NARGS(__VA_ARGS__)))
19
20#define TEST_MACRO_CONSTANT0 000
21#define TEST_MACRO_CONSTANT1 100
22#define TEST_MACRO_CONSTANT2 200
23#define TEST_MACRO_CONSTANT3 300
24#define TEST_MACRO_CONSTANT4 400
25#define TEST_MACRO_CONSTANT5 500
26#define TEST_MACRO_CONSTANT6 600
27
28TEST(VA_NARGS, MacroConstant)
29{
30    //EXPECT_EQ(000, TEST_MACRO_CONSTANT()); // documented issue of the macro - min number of elements is 1
31
32    EXPECT_EQ(100, TEST_MACRO_CONSTANT(some));
33    EXPECT_EQ(200, TEST_MACRO_CONSTANT(some, argument));
34    EXPECT_EQ(300, TEST_MACRO_CONSTANT(some, argument, to));
35    EXPECT_EQ(400, TEST_MACRO_CONSTANT(some, argument, to, test));
36    EXPECT_EQ(500, TEST_MACRO_CONSTANT(some, argument, to, test, the));
37    EXPECT_EQ(600, TEST_MACRO_CONSTANT(some, argument, to, test, the, macro));
38}
39
40
41#define TEST_MACRO_FUNCTION(...) \
42    BOOST_PP_EXPAND(BOOST_PP_CAT(TEST_MACRO_FUNCTION, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__))
43
44#define TEST_MACRO_FUNCTION0(...) 000
45#define TEST_MACRO_FUNCTION1(...) 100
46#define TEST_MACRO_FUNCTION2(...) 200
47#define TEST_MACRO_FUNCTION3(...) 300
48#define TEST_MACRO_FUNCTION4(...) 400
49#define TEST_MACRO_FUNCTION5(...) 500
50#define TEST_MACRO_FUNCTION6(...) 600
51
52TEST(VA_NARGS, MacroFunction)
53{
54    //EXPECT_EQ(000, TEST_MACRO_FUNCTION()); // documented issue of the macro - min number of elements is 1
55
56    EXPECT_EQ(100, TEST_MACRO_FUNCTION(some));
57    EXPECT_EQ(200, TEST_MACRO_FUNCTION(some, argument));
58    EXPECT_EQ(300, TEST_MACRO_FUNCTION(some, argument, to));
59    EXPECT_EQ(400, TEST_MACRO_FUNCTION(some, argument, to, test));
60    EXPECT_EQ(500, TEST_MACRO_FUNCTION(some, argument, to, test, the));
61    EXPECT_EQ(600, TEST_MACRO_FUNCTION(some, argument, to, test, the, macro));
62}
Note: See TracBrowser for help on using the repository browser.