From 586f29128d305689fff68a66583ed9a81ce0e343 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Tue, 17 Nov 2015 18:24:44 +0100 Subject: [PATCH] Refactored the implementation of parameterized tests macros to internal/ --- include/criterion/internal/assert.h | 23 +++++++ include/criterion/internal/parameterized.h | 72 ++++++++++++++++++++ include/criterion/internal/theories.h | 23 +++++++ include/criterion/parameterized.h | 78 +++++++++------------- 4 files changed, 148 insertions(+), 48 deletions(-) create mode 100644 include/criterion/internal/parameterized.h diff --git a/include/criterion/internal/assert.h b/include/criterion/internal/assert.h index 9b23417..426e3ae 100644 --- a/include/criterion/internal/assert.h +++ b/include/criterion/internal/assert.h @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2015 Franklin "Snaipe" Mathieu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #ifndef CRITERION_INTERNAL_ASSERT_H_ # define CRITERION_INTERNAL_ASSERT_H_ diff --git a/include/criterion/internal/parameterized.h b/include/criterion/internal/parameterized.h new file mode 100644 index 0000000..017a599 --- /dev/null +++ b/include/criterion/internal/parameterized.h @@ -0,0 +1,72 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2015 Franklin "Snaipe" Mathieu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef CRITERION_INTERNAL_PARAMETERIZED_H_ +# define CRITERION_INTERNAL_PARAMETERIZED_H_ + +# include "test.h" +# include "../types.h" + +# ifdef __cplusplus +# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \ + extern "C" void CR_IDENTIFIER_(Category, Name, impl)(Param) +# else +# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \ + void CR_IDENTIFIER_(Category, Name, impl)(Param) +# endif + +# define CR_PARAM_TEST_BASE(Param, Category, Name, ...) \ + CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name); \ + struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ + CR_EXPAND(CRITERION_MAKE_STRUCT(struct criterion_test_extra_data, \ + .lang_ = CR_LANG, \ + .kind_ = CR_TEST_PARAMETERIZED, \ + .param_ = CR_IDENTIFIER_(Category, Name, param), \ + .identifier_ = #Category "/" #Name, \ + .file_ = __FILE__, \ + .line_ = __LINE__, \ + __VA_ARGS__ \ + )); \ + struct criterion_test CR_IDENTIFIER_(Category, Name, meta) = { \ + #Name, \ + #Category, \ + (void(*)(void)) CR_IDENTIFIER_(Category, Name, impl), \ + &CR_IDENTIFIER_(Category, Name, extra) \ + }; \ + CR_SECTION_("cr_tst") \ + struct criterion_test *CR_IDENTIFIER_(Category, Name, ptr) \ + = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_; \ + CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) + +# define CR_PARAM_TEST_PARAMS(Category, Name) \ + static struct criterion_test_params CR_IDENTIFIER_(Category, Name, param)(void) + +# ifdef __cplusplus +# define cr_make_param_array(Type, Array, ...) \ + criterion_test_params(sizeof (Type), (Array), __VA_ARGS__) +# else +# define cr_make_param_array(Type, Array, ...) \ + (struct criterion_test_params) { .size = sizeof (Type), (void*)(Array), __VA_ARGS__ } +# endif + +#endif /* !CRITERION_INTERNAL_PARAMETERIZED_H_ */ diff --git a/include/criterion/internal/theories.h b/include/criterion/internal/theories.h index a0176c8..172d96d 100644 --- a/include/criterion/internal/theories.h +++ b/include/criterion/internal/theories.h @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2015 Franklin "Snaipe" Mathieu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #ifndef CRITERION_INTERNAL_THEORIES_H_ # define CRITERION_INTERNAL_THEORIES_H_ diff --git a/include/criterion/parameterized.h b/include/criterion/parameterized.h index 2c6d96c..7099009 100644 --- a/include/criterion/parameterized.h +++ b/include/criterion/parameterized.h @@ -1,58 +1,40 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2015 Franklin "Snaipe" Mathieu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #ifndef CRITERION_PARAMETERIZED_H_ # define CRITERION_PARAMETERIZED_H_ -# include "criterion.h" # include "alloc.h" +# include "assert.h" +# include "internal/parameterized.h" + +# define ParameterizedTest(...) CR_EXPAND(CR_PARAM_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) + +# define ParameterizedTestParameters(Category, Name) CR_PARAM_TEST_PARAMS(Category, Name) + # ifdef __cplusplus # include -# endif -# ifdef __cplusplus -# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \ - extern "C" void CR_IDENTIFIER_(Category, Name, impl)(Param) -# else -# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \ - void CR_IDENTIFIER_(Category, Name, impl)(Param) -# endif - -# define ParameterizedTest(...) \ - CR_EXPAND(ParameterizedTest_(__VA_ARGS__, .sentinel_ = 0)) - -# define ParameterizedTest_(Param, Category, Name, ...) \ - CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name); \ - struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ - CR_EXPAND(CRITERION_MAKE_STRUCT(struct criterion_test_extra_data, \ - .lang_ = CR_LANG, \ - .kind_ = CR_TEST_PARAMETERIZED, \ - .param_ = CR_IDENTIFIER_(Category, Name, param), \ - .identifier_ = #Category "/" #Name, \ - .file_ = __FILE__, \ - .line_ = __LINE__, \ - __VA_ARGS__ \ - )); \ - struct criterion_test CR_IDENTIFIER_(Category, Name, meta) = { \ - #Name, \ - #Category, \ - (void(*)(void)) CR_IDENTIFIER_(Category, Name, impl), \ - &CR_IDENTIFIER_(Category, Name, extra) \ - }; \ - CR_SECTION_("cr_tst") \ - struct criterion_test *CR_IDENTIFIER_(Category, Name, ptr) \ - = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_; \ - CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) - -# define ParameterizedTestParameters(Category, Name) \ - static struct criterion_test_params CR_IDENTIFIER_(Category, Name, param)(void) - -# ifdef __cplusplus -# define cr_make_param_array(Type, Array, ...) \ - criterion_test_params(sizeof (Type), (Array), __VA_ARGS__) -# else -# define cr_make_param_array(Type, Array, ...) \ - (struct criterion_test_params) { .size = sizeof (Type), (void*)(Array), __VA_ARGS__ } -# endif - -# ifdef __cplusplus namespace criterion { template using parameters = std::vector>;