Added criterion::parameters for simpler C++ parameter generation

This commit is contained in:
Snaipe 2015-09-23 20:10:00 +02:00
parent 37a043147f
commit 2b66cda524
2 changed files with 21 additions and 0 deletions

View file

@ -2,6 +2,10 @@
# define CRITERION_PARAMETERIZED_H_
# include "criterion.h"
# include "alloc.h"
# ifdef __cplusplus
# include <vector>
# endif
# ifdef __cplusplus
# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \
@ -47,4 +51,11 @@
(struct criterion_test_params) { .size = sizeof (Type), (void*)(Array), __VA_ARGS__ }
# endif
# ifdef __cplusplus
namespace criterion {
template <typename T>
using parameters = std::vector<T, criterion::allocator<T>>;
}
# endif
#endif /* !CRITERION_PARAMETERIZED_H_ */

View file

@ -24,8 +24,10 @@
#ifndef CRITERION_TYPES_H_
# define CRITERION_TYPES_H_
# include "alloc.h"
# ifdef __cplusplus
# include <cstddef>
# include <vector>
using std::size_t;
# else
# include <stdbool.h>
@ -59,6 +61,14 @@ struct criterion_test_params {
, length(length)
, cleanup(cleanup)
{}
template <typename T>
constexpr criterion_test_params(std::vector<T, criterion::allocator<T>>& vec)
: size(sizeof (T))
, params(&vec[0])
, length(vec.size())
, cleanup(nullptr)
{}
# endif
};