-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpp_iter_test.cpp
144 lines (119 loc) · 3.62 KB
/
pp_iter_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
// Module under test...
#include "pp_iter.h"
// Test includes
#include <string.h>
SCENARIO("PP_NARG") {
#if PP_IS_GCC_EXTENDED
GIVEN("should count no arguments") {
REQUIRE( PP_NARG() == 0 );
}
#endif
GIVEN("should count non-zero arguments") {
REQUIRE(13 == PP_NARG(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13));
}
//Upper limit...
GIVEN("should count maximum arguments (63)") {
REQUIRE(63 == PP_NARG(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
);
}
}
static int accumulated_values[10];
static size_t calls;
static size_t sum;
void accumulate(int next)
{
accumulated_values[calls++] = next;
sum+=next;
}
#define ACC(A) accumulate(A);
#define STRINGIFY(A) char const A##_tag[] = #A;
SCENARIO("PP_EACH") {
calls = sum = accumulated_values[0] = 0;
GIVEN("wrapped function") {
#if PP_IS_GCC_EXTENDED
WHEN("no additional arguments specified") {
PP_EACH(accumulate);
THEN("no calls are made") {
REQUIRE(calls==0);
}
}
#endif
WHEN("3 additional arguments specified") {
PP_EACH(ACC, 1, 2, 3);
THEN("3 calls are made") {
REQUIRE(calls==3);
}
THEN("arguments are passed in order") {
REQUIRE(accumulated_values[0] == 1);
REQUIRE(accumulated_values[1] == 2);
REQUIRE(accumulated_values[2] == 3);
}
}
}
#if PP_IS_CONFORMANT
GIVEN("stringifying macro") {
WHEN("applied") {
PP_EACH(STRINGIFY, a, b, c);
THEN("stringification occurs") {
REQUIRE(strcmp("a", a_tag)==0);
REQUIRE(strcmp("b", b_tag)==0);
REQUIRE(strcmp("c", c_tag)==0);
}
}
}
#endif
}
typedef struct {
uint16_t arg0;
uint16_t arg1;
uint16_t arg2;
} test_struct;
SCENARIO("PP_EACH_IDX") {
GIVEN("stringifying macro") {
#define TFEQ(ARG, ARG_IDX) REQUIRE(ARG == tested.arg##ARG_IDX);
WHEN("applied") {
test_struct tested = {.arg0 = 6, .arg1 = 5, .arg2 = 4};
PP_EACH_IDX(TFEQ, 6, 5, 4);
THEN("arg index stringifies as expected") {
}
}
}
}
#define TFEQFIX(FIXED_ARG, ARG, ARG_IDX) REQUIRE(ARG == FIXED_ARG##ARG_IDX);
// #define TFEQFIX(FIXED_ARG, ARG, ARG_IDX) REQUIRE(ARG == CAT(FIXED_ARG, ARG_IDX));
SCENARIO("PP_PAR_EACH_IDX") {
GIVEN("stringifying macro with 1 fixed argument") {
WHEN("applied") {
test_struct tested = {.arg0 = 6, .arg1 = 5, .arg2 = 4};
PP_PAR_EACH_IDX(TFEQFIX, (tested.arg), 6, 5, 4);
THEN("arg index stringifies as expected") {
}
}
}
GIVEN("stringifying macro with 2 fixed arguments") {
// #define TFEQFIX(FIXED_ARG, ARG, ARG_IDX) REQUIRE(ARG == FIXED_ARG##ARG_IDX);
#define TFEQ2FIX(FIXED_ARG1, FIXED_ARG2, ARG, ARG_IDX) REQUIRE(ARG == CAT(FIXED_ARG1, ARG_IDX));
WHEN("applied") {
test_struct tested = {.arg0 = 6, .arg1 = 5, .arg2 = 4};
PP_PAR_EACH_IDX(TFEQ2FIX, (tested.arg, bla), 6, 5, 4);
THEN("arg index stringifies as expected") {
}
}
}
}
// SCENARIO("PP_1PAR_EACH_IDX") {
// GIVEN("stringifying macro") {
// #define TFEQFIX(FIXED_ARG, ARG, ARG_IDX) REQUIRE(ARG == FIXED_ARG##ARG_IDX);
// WHEN("applied") {
// test_struct tested = {.arg0 = 6, .arg1 = 5, .arg2 = 4};
// PP_1PAR_EACH_IDX(TFEQFIX, tested.arg, 6, 5, 4);
// THEN("arg index stringifies as expected") {
// }
// }
// }
// }