• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 // Many of these tests are static asserts. If these compile, they pass. The TEST
16 // functions are used for organization only.
17 
18 #include "pw_preprocessor/arguments.h"
19 
20 #include <tuple>
21 
22 #include "gtest/gtest.h"
23 
24 namespace pw {
25 namespace {
26 
27 #define EMPTY_ARG
28 
TEST(HasArgs,WithoutArguments)29 TEST(HasArgs, WithoutArguments) {
30   static_assert(PW_HAS_ARGS() == 0);
31   static_assert(PW_HAS_ARGS(/**/) == 0);
32   static_assert(PW_HAS_ARGS(/* uhm, hi */) == 0);
33   static_assert(PW_HAS_ARGS(EMPTY_ARG) == 0);
34 
35   // Test how the macro handles whitespace and comments.
36   // clang-format off
37   static_assert(PW_HAS_ARGS(     ) == 0);
38   static_assert(PW_HAS_ARGS(
39       ) == 0);
40   static_assert(PW_HAS_ARGS(
41       // wow
42       // This is a comment.
43       ) == 0);
44   // clang-format on
45 
46   static_assert(PW_EMPTY_ARGS() == 1);
47   static_assert(PW_EMPTY_ARGS(/* hello */) == 1);
48   static_assert(PW_EMPTY_ARGS(
49                     // hello
50                     /* goodbye */) == 1);
51 }
52 
TEST(HasArgs,WithArguments)53 TEST(HasArgs, WithArguments) {
54   static_assert(PW_HAS_ARGS(()) == 1);
55   static_assert(PW_HAS_ARGS(0) == 1);
56   static_assert(PW_HAS_ARGS(, ) == 1);
57   static_assert(PW_HAS_ARGS(a, b, c) == 1);
58   static_assert(PW_HAS_ARGS(PW_HAS_ARGS) == 1);
59   static_assert(PW_HAS_ARGS(PW_HAS_ARGS()) == 1);
60 
61   static_assert(PW_EMPTY_ARGS(0) == 0);
62   static_assert(PW_EMPTY_ARGS(, ) == 0);
63   static_assert(PW_EMPTY_ARGS(a, b, c) == 0);
64   static_assert(PW_EMPTY_ARGS(PW_HAS_ARGS) == 0);
65   static_assert(PW_EMPTY_ARGS(PW_HAS_ARGS()) == 0);
66 }
67 
TestFunc(int arg,...)68 constexpr int TestFunc(int arg, ...) { return arg; }
69 
70 #define CALL_FUNCTION(arg, ...) TestFunc(arg PW_COMMA_ARGS(__VA_ARGS__))
71 
72 template <typename T, typename... Args>
TemplateArgCount()73 constexpr T TemplateArgCount() {
74   return sizeof...(Args);
75 }
76 
77 #define COUNT_ARGS_TEMPLATE(...) \
78   TemplateArgCount<int PW_COMMA_ARGS(__VA_ARGS__)>()
79 
TEST(CommaVarargs,NoArguments)80 TEST(CommaVarargs, NoArguments) {
81   static_assert(TestFunc(0 PW_COMMA_ARGS()) == 0);
82   static_assert(TestFunc(1 /* whoa */ PW_COMMA_ARGS(
83                     /* this macro */) /* is cool! */) == 1);
84 
85   static_assert(TemplateArgCount<int PW_COMMA_ARGS()>() == 0);
86   static_assert(TemplateArgCount<int PW_COMMA_ARGS(/* nothing */)>() == 0);
87 
88   static_assert(CALL_FUNCTION(2) == 2);
89   static_assert(CALL_FUNCTION(3, ) == 3);
90   static_assert(CALL_FUNCTION(4, /* nothing */) == 4);
91 
92   static_assert(COUNT_ARGS_TEMPLATE() == 0);
93   static_assert(COUNT_ARGS_TEMPLATE(/* nothing */) == 0);
94 }
95 
TEST(CommaVarargs,WithArguments)96 TEST(CommaVarargs, WithArguments) {
97   static_assert(TestFunc(0 PW_COMMA_ARGS(1)) == 0);
98   static_assert(TestFunc(1 PW_COMMA_ARGS(1, 2)) == 1);
99   static_assert(TestFunc(2 PW_COMMA_ARGS(1, 2, "three")) == 2);
100 
101   static_assert(TemplateArgCount<int PW_COMMA_ARGS(bool)>() == 1);
102   static_assert(TemplateArgCount<int PW_COMMA_ARGS(char, const char*)>() == 2);
103   static_assert(TemplateArgCount<int PW_COMMA_ARGS(int, char, const char*)>() ==
104                 3);
105 
106   static_assert(CALL_FUNCTION(3) == 3);
107   static_assert(CALL_FUNCTION(4, ) == 4);
108   static_assert(CALL_FUNCTION(5, /* nothing */) == 5);
109 
110   static_assert(COUNT_ARGS_TEMPLATE(int) == 1);
111   static_assert(COUNT_ARGS_TEMPLATE(int, int) == 2);
112   static_assert(COUNT_ARGS_TEMPLATE(int, int, int) == 3);
113 }
114 
TEST(CommaVarargs,EmptyFinalArgument)115 TEST(CommaVarargs, EmptyFinalArgument) {
116   static_assert(COUNT_ARGS_TEMPLATE(EMPTY_ARG) == 0);
117   static_assert(COUNT_ARGS_TEMPLATE(int, ) == 1);
118   static_assert(COUNT_ARGS_TEMPLATE(int, EMPTY_ARG) == 1);
119   static_assert(COUNT_ARGS_TEMPLATE(int, /* EMPTY_ARG */) == 1);
120   static_assert(COUNT_ARGS_TEMPLATE(int, int, ) == 2);
121   static_assert(COUNT_ARGS_TEMPLATE(int, int, int, ) == 3);
122   static_assert(COUNT_ARGS_TEMPLATE(int, int, int, EMPTY_ARG) == 3);
123 }
124 
125 // This test demonstrates that PW_COMMA_ARGS behaves unexpectedly when it is
126 // used when invoking another macro. DO NOT use PW_COMMA_ARGS when invoking
127 // another macro!
128 #define BAD_DEMO(fmt, ...) _BAD_DEMO_ADD_123(fmt PW_COMMA_ARGS(__VA_ARGS__))
129 
130 #define _BAD_DEMO_ADD_123(fmt, ...) \
131   _BAD_DEMO_CAPTURE_ARGS("%d: " fmt, 123 PW_COMMA_ARGS(__VA_ARGS__))
132 
133 #define _BAD_DEMO_CAPTURE_ARGS(...) std::make_tuple(__VA_ARGS__)
134 
TEST(CommaVarargs,MisbehavesWithMacroToMacroUse_NoArgs_ArgsAreOkay)135 TEST(CommaVarargs, MisbehavesWithMacroToMacroUse_NoArgs_ArgsAreOkay) {
136   auto [a1, a2] = BAD_DEMO("Hello world");
137   EXPECT_STREQ(a1, "%d: Hello world");
138   EXPECT_EQ(a2, 123);
139 }
140 
TEST(CommaVarargs,MisbehavesWithMacroToMacroUse_WithArgs_ArgsOutOfOrder)141 TEST(CommaVarargs, MisbehavesWithMacroToMacroUse_WithArgs_ArgsOutOfOrder) {
142   // If there is an additional argument, the order is incorrect! The 123
143   // argument should go before the "world?" argument, but it is inserted after.
144   // This would be a compilation error if these arguments were passed to printf.
145   // What's worse is that this can silently fail if the arguments happen to be
146   // compatible types.
147   const auto [a1, a2, a3] = BAD_DEMO("Hello %s", "world?");
148   EXPECT_STREQ(a1, "%d: Hello %s");
149   EXPECT_STREQ(a2, "world?");
150   EXPECT_EQ(a3, 123);
151 }
152 
TEST(CountArgs,Zero)153 TEST(CountArgs, Zero) {
154   static_assert(PW_MACRO_ARG_COUNT() == 0);
155   static_assert(PW_MACRO_ARG_COUNT(/**/) == 0);
156   static_assert(PW_MACRO_ARG_COUNT(/* uhm, hi */) == 0);
157 
158   // clang-format off
159   static_assert(PW_MACRO_ARG_COUNT(     ) == 0);
160   static_assert(PW_MACRO_ARG_COUNT(
161       ) == 0);
162   static_assert(PW_MACRO_ARG_COUNT(
163       // wow
164       // This is a comment.
165       ) == 0);
166   // clang-format on
167 }
168 
TEST(CountArgs,Commas)169 TEST(CountArgs, Commas) {
170   // clang-format off
171   static_assert(PW_MACRO_ARG_COUNT(,) == 2);
172   static_assert(PW_MACRO_ARG_COUNT(,,) == 3);
173   static_assert(PW_MACRO_ARG_COUNT(,,,) == 4);
174   // clang-format on
175   static_assert(PW_MACRO_ARG_COUNT(, ) == 2);
176   static_assert(PW_MACRO_ARG_COUNT(, , ) == 3);
177   static_assert(PW_MACRO_ARG_COUNT(, , , ) == 4);
178 }
179 
TEST(CountArgs,Parentheses)180 TEST(CountArgs, Parentheses) {
181   static_assert(PW_MACRO_ARG_COUNT(()) == 1);
182   static_assert(PW_MACRO_ARG_COUNT((1, 2, 3, 4)) == 1);
183   static_assert(PW_MACRO_ARG_COUNT((1, 2, 3), (1, 2, 3, 4)) == 2);
184   static_assert(PW_MACRO_ARG_COUNT((), ()) == 2);
185   static_assert(PW_MACRO_ARG_COUNT((-), (o)) == 2);
186   static_assert(PW_MACRO_ARG_COUNT((, , (, , ), ), (123, 4)) == 2);
187   static_assert(PW_MACRO_ARG_COUNT(1, (2, 3, 4), (<5, 6>)) == 3);
188 }
189 
190 template <typename... Args>
FunctionArgCount(Args...)191 constexpr size_t FunctionArgCount(Args...) {
192   return sizeof...(Args);
193 }
194 
195 static_assert(FunctionArgCount() == 0);
196 static_assert(FunctionArgCount(1) == 1);
197 static_assert(FunctionArgCount(1, 2) == 2);
198 
TEST(CountFunctionArgs,NonEmptyLastArg)199 TEST(CountFunctionArgs, NonEmptyLastArg) {
200   static_assert(PW_FUNCTION_ARG_COUNT(a) == 1);
201   static_assert(PW_FUNCTION_ARG_COUNT(1, 2) == 2);
202   static_assert(PW_FUNCTION_ARG_COUNT(1, 2, 3) == 3);
203 }
204 
TEST(CountFunctionArgs,EmptyLastArg)205 TEST(CountFunctionArgs, EmptyLastArg) {
206   static_assert(PW_FUNCTION_ARG_COUNT() == 0);
207   static_assert(PW_FUNCTION_ARG_COUNT(a, ) == 1);
208   static_assert(PW_FUNCTION_ARG_COUNT(1, 2, ) == 2);
209   static_assert(PW_FUNCTION_ARG_COUNT(1, 2, 3, ) == 3);
210 
211   static_assert(PW_FUNCTION_ARG_COUNT(a, EMPTY_ARG) == 1);
212   static_assert(PW_FUNCTION_ARG_COUNT(1, 2, EMPTY_ARG) == 2);
213   static_assert(PW_FUNCTION_ARG_COUNT(1, 2, 3, EMPTY_ARG) == 3);
214 }
215 
Value(const char * str=nullptr)216 constexpr const char* Value(const char* str = nullptr) { return str; }
217 
TEST(LastArg,NonEmptyLastArg)218 TEST(LastArg, NonEmptyLastArg) {
219   constexpr const char* last = "last!";
220   static_assert(Value(PW_LAST_ARG(last)) == last);
221   static_assert(Value(PW_LAST_ARG(1, last)) == last);
222   static_assert(Value(PW_LAST_ARG(1, 2, last)) == last);
223 }
224 
TEST(LastArg,EmptyLastArg)225 TEST(LastArg, EmptyLastArg) {
226   static_assert(Value(PW_LAST_ARG()) == nullptr);
227   static_assert(Value(PW_LAST_ARG(1, )) == nullptr);
228   static_assert(Value(PW_LAST_ARG(1, 2, )) == nullptr);
229   static_assert(Value(PW_LAST_ARG(1, 2, 3, )) == nullptr);
230 }
231 
TEST(DropLastArg,NonEmptyLastArg)232 TEST(DropLastArg, NonEmptyLastArg) {
233   static_assert(FunctionArgCount(PW_DROP_LAST_ARG(1)) == 0);
234   static_assert(FunctionArgCount(PW_DROP_LAST_ARG(1, 2)) == 1);
235   static_assert(FunctionArgCount(PW_DROP_LAST_ARG(1, 2, 3)) == 2);
236 }
237 
TEST(DropLastArg,EmptyLastArg)238 TEST(DropLastArg, EmptyLastArg) {
239   static_assert(FunctionArgCount(PW_DROP_LAST_ARG()) == 0);
240   static_assert(FunctionArgCount(PW_DROP_LAST_ARG(1, )) == 1);
241   static_assert(FunctionArgCount(PW_DROP_LAST_ARG(1, 2, )) == 2);
242   static_assert(FunctionArgCount(PW_DROP_LAST_ARG(1, 2, 3, )) == 3);
243 }
244 
TEST(DropLastArgIfEmpty,NonEmptyLastArg)245 TEST(DropLastArgIfEmpty, NonEmptyLastArg) {
246   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY(1)) == 1);
247   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY(1, 2)) == 2);
248   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY(1, 2, 3)) == 3);
249 }
250 
TEST(DropLastArgIfEmpty,EmptyLastArg)251 TEST(DropLastArgIfEmpty, EmptyLastArg) {
252   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY()) == 0);
253   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY(1, )) == 1);
254   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY(1, 2, )) == 2);
255   static_assert(FunctionArgCount(PW_DROP_LAST_ARG_IF_EMPTY(1, 2, 3, )) == 3);
256 }
257 
258 #define SOME_VARIADIC_MACRO(...) PW_MACRO_ARG_COUNT(__VA_ARGS__)
259 
260 #define ANOTHER_VARIADIC_MACRO(arg, ...) SOME_VARIADIC_MACRO(__VA_ARGS__)
261 
262 #define ALWAYS_ONE_ARG(...) SOME_VARIADIC_MACRO((__VA_ARGS__))
263 
TEST(CountArgs,NestedMacros)264 TEST(CountArgs, NestedMacros) {
265   static_assert(SOME_VARIADIC_MACRO() == 0);
266   static_assert(SOME_VARIADIC_MACRO(X1) == 1);
267   static_assert(SOME_VARIADIC_MACRO(X1, X2) == 2);
268   static_assert(SOME_VARIADIC_MACRO(X1, X2, X3) == 3);
269   static_assert(SOME_VARIADIC_MACRO(X1, X2, X3, X4) == 4);
270   static_assert(SOME_VARIADIC_MACRO(X1, X2, X3, X4, X5) == 5);
271 
272   static_assert(ANOTHER_VARIADIC_MACRO() == 0);
273   static_assert(ANOTHER_VARIADIC_MACRO(X0) == 0);
274   static_assert(ANOTHER_VARIADIC_MACRO(X0, X1) == 1);
275   static_assert(ANOTHER_VARIADIC_MACRO(X0, X1, X2) == 2);
276   static_assert(ANOTHER_VARIADIC_MACRO(X0, X1, X2, X3) == 3);
277   static_assert(ANOTHER_VARIADIC_MACRO(X0, X1, X2, X3, X4) == 4);
278   static_assert(ANOTHER_VARIADIC_MACRO(X0, X1, X2, X3, X4, X5) == 5);
279 
280   static_assert(ALWAYS_ONE_ARG() == 1);
281   static_assert(ALWAYS_ONE_ARG(X0) == 1);
282   static_assert(ALWAYS_ONE_ARG(X0, X1) == 1);
283   static_assert(ALWAYS_ONE_ARG(X0, X1, X2) == 1);
284   static_assert(ALWAYS_ONE_ARG(X0, X1, X2, X3) == 1);
285   static_assert(ALWAYS_ONE_ARG(X0, X1, X2, X3, X4) == 1);
286   static_assert(ALWAYS_ONE_ARG(X0, X1, X2, X3, X4, X5) == 1);
287 }
288 
289 /* Tests all supported arg counts. This test was generated by the following
290    Python 3 code:
291 for i in range(64 + 1):
292   args = [f'X{x}' for x in range(1, i + 1)]
293   print(f'  static_assert(PW_MACRO_ARG_COUNT({", ".join(args)}) == {i})  ')
294 */
TEST(CountArgs,AllSupported)295 TEST(CountArgs, AllSupported) {
296   // clang-format off
297   static_assert(PW_MACRO_ARG_COUNT() == 0);
298   static_assert(PW_MACRO_ARG_COUNT(X1) == 1);
299   static_assert(PW_MACRO_ARG_COUNT(X1, X2) == 2);
300   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3) == 3);
301   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4) == 4);
302   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5) == 5);
303   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6) == 6);
304   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7) == 7);
305   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8) == 8);
306   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9) == 9);
307   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) == 10);
308   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) == 11);
309   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) == 12);
310   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) == 13);
311   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) == 14);
312   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15) == 15);
313   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16) == 16);
314   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17) == 17);
315   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18) == 18);
316   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19) == 19);
317   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20) == 20);
318   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21) == 21);
319   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22) == 22);
320   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23) == 23);
321   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24) == 24);
322   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25) == 25);
323   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26) == 26);
324   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27) == 27);
325   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28) == 28);
326   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29) == 29);
327   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30) == 30);
328   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31) == 31);
329   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32) == 32);
330   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33) == 33);
331   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34) == 34);
332   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35) == 35);
333   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36) == 36);
334   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37) == 37);
335   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38) == 38);
336   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39) == 39);
337   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40) == 40);
338   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41) == 41);
339   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42) == 42);
340   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43) == 43);
341   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44) == 44);
342   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45) == 45);
343   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46) == 46);
344   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47) == 47);
345   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48) == 48);
346   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49) == 49);
347   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50) == 50);
348   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51) == 51);
349   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52) == 52);
350   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53) == 53);
351   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54) == 54);
352   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55) == 55);
353   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56) == 56);
354   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57) == 57);
355   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58) == 58);
356   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59) == 59);
357   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59, X60) == 60);
358   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59, X60, X61) == 61);
359   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59, X60, X61, X62) == 62);
360   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59, X60, X61, X62, X63) == 63);
361   static_assert(PW_MACRO_ARG_COUNT(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59, X60, X61, X62, X63, X64) == 64);
362   // clang-format on
363 }
364 
TEST(DelegateByArgCount,WithoutAndWithoutArguments)365 TEST(DelegateByArgCount, WithoutAndWithoutArguments) {
366 #define TEST_SUM0() (0)
367 #define TEST_SUM1(a) (a)
368 #define TEST_SUM2(a, b) ((a) + (b))
369 #define TEST_SUM3(a, b, c) ((a) + (b) + (c))
370 
371   static_assert(PW_DELEGATE_BY_ARG_COUNT(TEST_SUM) == 0);
372   static_assert(PW_DELEGATE_BY_ARG_COUNT(TEST_SUM, 5) == 5);
373   static_assert(PW_DELEGATE_BY_ARG_COUNT(TEST_SUM, 1, 2) == 3);
374   static_assert(PW_DELEGATE_BY_ARG_COUNT(TEST_SUM, 1, 2, 3) == 6);
375 }
376 
377 }  // namespace
378 }  // namespace pw
379