diff --git a/.githooks/canonicalize_filename.sh b/.githooks/canonicalize_filename.sh new file mode 100644 index 0000000..5eecabf --- /dev/null +++ b/.githooks/canonicalize_filename.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# Provide the canonicalize filename (physical filename with out any symlinks) +# like the GNU version readlink with the -f option regardless of the version of +# readlink (GNU or BSD). + +# This file is part of a set of unofficial pre-commit hooks available +# at github. +# Link: https://github.com/githubbrowser/Pre-commit-hooks +# Contact: David Martin, david.martin.mailbox@googlemail.com + +########################################################### +# There should be no need to change anything below this line. + +# Canonicalize by recursively following every symlink in every component of the +# specified filename. This should reproduce the results of the GNU version of +# readlink with the -f option. +# +# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac +canonicalize_filename () { + local target_file="$1" + local physical_directory="" + local result="" + + # Need to restore the working directory after work. + local working_dir="`pwd`" + + cd -- "$(dirname -- "$target_file")" + target_file="$(basename -- "$target_file")" + + # Iterate down a (possible) chain of symlinks + while [ -L "$target_file" ] + do + target_file="$(readlink -- "$target_file")" + cd -- "$(dirname -- "$target_file")" + target_file="$(basename -- "$target_file")" + done + + # Compute the canonicalized name by finding the physical path + # for the directory we're in and appending the target file. + physical_directory="`pwd -P`" + result="$physical_directory/$target_file" + + # restore the working directory after work. + cd -- "$working_dir" + + echo "$result" +} diff --git a/.githooks/install.sh b/.githooks/install.sh new file mode 100755 index 0000000..fb77478 --- /dev/null +++ b/.githooks/install.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -Rf .git/hooks +ln -s ../.githooks .git/hooks diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..e69ce45 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,165 @@ +#!/bin/sh + +# git pre-commit hook that runs an Uncrustify stylecheck. +# Features: +# - abort commit when commit does not comply with the style guidelines +# - create a patch of the proposed style changes +# +# More info on Uncrustify: http://uncrustify.sourceforge.net/ + +# This file is part of a set of unofficial pre-commit hooks available +# at github. +# Link: https://github.com/githubbrowser/Pre-commit-hooks +# Contact: David Martin, david.martin.mailbox@googlemail.com + + +################################################################## +# CONFIGURATION +# set uncrustify path or executable +# UNCRUSTIFY="/usr/bin/uncrustify" +UNCRUSTIFY="uncrustify" + +# set uncrustify config location +# CONFIG="/home/user/.config/uncrustify.cfg" +CONFIG=".uncrustify.cfg" + +# the source language: C, CPP, D, CS, JAVA, PAWN, VALA, OC, OC+ +# use AUTO to let Uncrustify decide which language a given file uses. +# the detected language is printed to the console when Uncrustify is called. +# override if the automatic detection seems off. +# SOURCE_LANGUAGE="AUTO" +SOURCE_LANGUAGE="AUTO" + +# remove any older patches from previous commits. Set to true or false. +# DELETE_OLD_PATCHES=false +DELETE_OLD_PATCHES=false + +# only parse files with the extensions in FILE_EXTS. Set to true or false. +# if false every changed file in the commit will be parsed with Uncrustify. +# if true only files matching one of the extensions are parsed with Uncrustify. +# PARSE_EXTS=true +PARSE_EXTS=true + +# file types to parse. Only effective when PARSE_EXTS is true. +# FILE_EXTS=".c .h .cpp .hpp" +FILE_EXTS=".c .h .cc .hh .cpp .hpp .hxx" + +################################################################## +# There should be no need to change anything below this line. + +. "$(dirname -- "$0")/canonicalize_filename.sh" + +# exit on error +set -e + +# check whether the given file matches any of the set extensions +matches_extension() { + local filename="$(basename -- "$1")" + local extension=".${filename##*.}" + local ext + + for ext in $FILE_EXTS; do [ "$ext" = "$extension" ] && return 0; done + + return 1 +} + +# necessary check for initial commit +if git rev-parse --verify HEAD >/dev/null 2>&1 ; then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +# make sure the config file and executable are correctly set +if [ ! -f "$CONFIG" ] ; then + printf "Error: uncrustify config file not found.\n" + printf "Set the correct path in $(canonicalize_filename "$0").\n" + exit 1 +fi + +if ! command -v "$UNCRUSTIFY" > /dev/null ; then + printf "Error: uncrustify executable not found.\n" + printf "Set the correct path in $(canonicalize_filename "$0").\n" + exit 1 +fi + +# create a filename to store our generated patch +prefix="pre-commit-uncrustify" +suffix="$(date +%C%y-%m-%d_%Hh%Mm%Ss)" +patch="/tmp/$prefix-$suffix.patch" + +# clean up any older uncrustify patches +$DELETE_OLD_PATCHES && rm -f /tmp/$prefix*.patch + +# create one patch containing all changes to the files +# sed to remove quotes around the filename, if inserted by the system +# (done sometimes, if the filename contains special characters, like the quote itself) +git diff-index --cached --diff-filter=ACMR --name-only $against -- | \ +sed -e 's/^"\(.*\)"$/\1/' | \ +while read file +do + # ignore file if we do check for file extensions and the file + # does not match any of the extensions specified in $FILE_EXTS + if $PARSE_EXTS && ! matches_extension "$file"; then + continue; + fi + + # escape special characters in the source filename: + # - '\': backslash needs to be escaped + # - '*': used as matching string => '*' would mean expansion + # (curiously, '?' must not be escaped) + # - '[': used as matching string => '[' would mean start of set + # - '|': used as sed split char instead of '/', so it needs to be escaped + # in the filename + # printf %s particularly important if the filename contains the % character + file_escaped_source=$(printf "%s" "$file" | sed -e 's/[\*[|]/\\&/g') + + # escape special characters in the target filename: + # phase 1 (characters escaped in the output diff): + # - '\': backslash needs to be escaped in the output diff + # - '"': quote needs to be escaped in the output diff if present inside + # of the filename, as it used to bracket the entire filename part + # phase 2 (characters escaped in the match replacement): + # - '\': backslash needs to be escaped again for sed itself + # (i.e. double escaping after phase 1) + # - '&': would expand to matched string + # - '|': used as sed split char instead of '/' + # printf %s particularly important if the filename contains the % character + file_escaped_target=$(printf "%s" "$file" | sed -e 's/[\"]/\\&/g' -e 's/[\&|]/\\&/g') + + # Uncrustify detects the language automatically if it is not specified + language_option="" + if [ "$SOURCE_LANGUAGE" != "AUTO" ] ; then + language_option="-l $SOURCE_LANGUAGE" + fi + + # uncrustify our sourcefile, create a patch with diff and append it to our $patch + # The sed call is necessary to transform the patch from + # --- $file timestamp + # +++ - timestamp + # to both lines working on the same file and having a a/ and b/ prefix. + # Else it can not be applied with 'git apply'. + "$UNCRUSTIFY" -c "$CONFIG" -f "$file" $language_option | \ + git --no-pager diff --color=always --no-index -- "$file" - | \ + sed -e "1s|--- $file_escaped_source|--- \"a/$file_escaped_target\"|" -e "2s|+++ -|+++ \"b/$file_escaped_target\"|" >> "$patch" +done + +# if no patch has been generated all is ok, clean up the file stub and exit +if [ ! -s "$patch" ] ; then + printf "Files in this commit comply with the uncrustify rules.\n" + rm -f "$patch" + exit 0 +fi + +# a patch has been created, notify the user and exit +printf "\nThe following differences were found between the code to commit " +printf "and the uncrustify rules:\n\n" +cat "$patch" + +printf "\nYou can apply these changes with:\n git apply $patch\n" +printf "(may need to be called from the root directory of your repository)\n" +printf "Aborting commit. Apply changes and commit again or skip checking with" +printf " --no-verify (not recommended).\n" + +exit 1 diff --git a/.uncrustify.cfg b/.uncrustify.cfg new file mode 100644 index 0000000..0b3cbfc --- /dev/null +++ b/.uncrustify.cfg @@ -0,0 +1,238 @@ +# +# uncrustify config file (initially based on the linux kernel coding style) +# + +input_tab_size = 4 # original tab size +output_tab_size = 4 # new tab size + +newlines = lf # \n + +utf8_force = true +utf8_bom = remove + +# Indent + +indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs +indent_columns = 4 # indents are 4 cols +indent_continue = 8 # line continuations are indented by 8 columns +indent_label = -4 # pos: absolute col, neg: relative column +indent_xml_string = 2 # embedded XML indents are 2 cols +indent_ctor_init = 4 # indent c++ ctor initializer list +indent_switch_case = 4 # indent 'case' inside switch statements +indent_namespace = false +indent_extern = false +indent_class = false +indent_class_colon = true +indent_access_spec_body = true + +# Newlines + +nl_max = 2 # no duplicate blank lines +nl_func_paren = remove # "int foo()" vs "int foo\n()" +nl_func_decl_start = ignore +nl_func_decl_empty = remove +nl_func_decl_args = ignore +nl_func_decl_end = remove +nl_enum_brace = remove # "enum {" vs "enum \n {" +nl_union_brace = remove # "union {" vs "union \n {" +nl_struct_brace = remove # "struct {" vs "struct \n {" +nl_do_brace = remove # "do {" vs "do \n {" +nl_if_brace = remove # "if () {" vs "if () \n {" +nl_for_brace = remove # "for () {" vs "for () \n {" +nl_else_brace = remove # "else {" vs "else \n {" +nl_while_brace = remove # "while () {" vs "while () \n {" +nl_switch_brace = remove # "switch () {" vs "switch () \n {" +nl_brace_while = remove # "} while" vs "} \n while" - cuddle while +nl_brace_else = remove # "} else" vs "} \n else" - cuddle else +nl_namespace_brace = force # "namespace name {" vs "namespace name \n {" +nl_func_var_def_blk = 1 +nl_fcall_brace = remove # "list_for_each() {" vs "list_for_each()\n{" +nl_fdef_brace = add # "int foo() {" vs "int foo()\n{" +nl_after_label_colon = false # "fail:\nfree(foo);" vs "fail: free(foo);" +nl_start_of_file = remove +nl_end_of_file = force +nl_end_of_file_min = 1 +nl_comment_func_def = 1 +nl_assign_leave_one_liners = true +nl_class_leave_one_liners = true +nl_enum_leave_one_liners = true +nl_getset_leave_one_liners = true +nl_func_leave_one_liners = true +nl_cpp_lambda_leave_one_liners = true +nl_while_leave_one_liners = false +nl_if_leave_one_liners = false +nl_multi_line_define = true +nl_func_call_start_multi_line = false +nl_func_call_end_multi_line = false + +# Source code modifications + +mod_paren_on_return = remove # "return 1;" vs "return (1);" +mod_full_brace_if = remove # "if (a) a--;" vs "if (a) { a--; }" +mod_full_brace_if_chain = true +mod_full_brace_for = remove # "for () a--;" vs "for () { a--; }" +mod_full_brace_do = force # "do a--; while ();" vs "do { a--; } while ();" +mod_full_brace_while = remove # "while (a) a--;" vs "while (a) { a--; }" +mod_full_brace_nl = 3 # don't remove if more than 3 newlines + +# Spacing + +sp_addr = remove +sp_after_angle = force +sp_after_byref = remove +sp_after_byref_func = remove +sp_after_cast = force # "(int) a" vs "(int)a" +sp_after_class_colon = force +sp_after_comma = force +sp_after_dc = remove +sp_after_new = force +sp_after_operator = remove +sp_after_operator_sym = remove +sp_after_ptr_star = remove # "int *foo" vs "int * foo" +sp_after_ptr_star_func = remove +sp_after_semi = force +sp_after_semi_for = force +sp_after_semi_for_empty = remove +sp_after_sparen = force # "if () {" vs "if (){" +sp_after_type = force +sp_angle_paren = remove +sp_angle_shift = ignore +sp_angle_word = force +sp_arith = force +sp_assign = add +sp_assign_default = force +sp_attribute_paren = remove +sp_balance_nested_parens = false +sp_before_angle = remove +sp_before_byref = force +sp_before_byref_func = force +sp_before_case_colon = remove +sp_before_class_colon = force +sp_before_comma = remove +sp_before_dc = remove +sp_before_ellipsis = remove +sp_before_nl_cont = force +sp_before_ptr_star = force # "int*" vs "int *" +sp_before_ptr_star_func = force +sp_before_semi = remove +sp_before_semi_for = remove +sp_before_semi_for_empty = remove +sp_before_sparen = force # "if (" vs "if(" +sp_before_square = remove +sp_before_tr_emb_cmt = force +sp_before_unnamed_byref = force +sp_between_ptr_star = remove # "int **" vs "int * *" +sp_bool = force +sp_brace_catch = force +sp_brace_else = force # "}else" vs "} else" +sp_brace_finally = force +sp_brace_typedef = force +sp_case_label = force +sp_catch_brace = force +sp_catch_paren = force +sp_cmt_cpp_start = force +sp_compare = force +sp_cond_colon = add +sp_cond_question = add +sp_cpp_cast_paren = force +sp_defined_paren = force +sp_deref = remove +sp_else_brace = force # "else{" vs "else {" +sp_endif_cmt = force +sp_enum_assign = force +sp_finally_brace = force +sp_fparen_brace = force +sp_func_call_paren = remove # "foo (" vs "foo(" +sp_func_call_user_paren = remove +sp_func_class_paren = remove +sp_func_def_paren = remove # "int foo (){" vs "int foo(){" +sp_func_proto_paren = remove # "int foo ();" vs "int foo();" +sp_getset_brace = force +sp_incdec = remove +sp_inside_angle = remove +sp_inside_braces = force # "{ 1 }" vs "{1}" +sp_inside_braces_empty = remove +sp_inside_braces_enum = force # "{ 1 }" vs "{1}" +sp_inside_braces_struct = force # "{ 1 }" vs "{1}" +sp_inside_fparen = remove +sp_inside_fparens = remove +sp_inside_paren = remove +sp_inside_paren_cast = remove +sp_inside_sparen = remove +sp_inside_square = remove +sp_inv = remove +sp_macro = force +sp_macro_func = force +sp_member = remove +sp_not = remove +sp_num_before_tr_emb_cmt = 1 +sp_paren_brace = force +sp_paren_comma = ignore +sp_paren_paren = remove # "((" vs "( (" +sp_pp_concat = force +sp_pp_stringify = remove +sp_return_paren = force # "return (1);" vs "return(1);" +sp_sign = remove +sp_sizeof_paren = force # "sizeof (int)" vs "sizeof(int)" +sp_sparen_brace = force +sp_special_semi = remove +sp_square_fparen = remove +sp_template_angle = add +sp_throw_paren = force +sp_try_brace = force + +cmt_sp_before_star_cont = 0 +cmt_sp_after_star_cont = 1 + +# Positioning + +pos_arith = lead +pos_assign = trail +pos_bool = lead +pos_compare = lead +pos_conditional = lead +pos_comma = trail +pos_class_comma = trail +pos_class_colon = lead + +# Alignment + +align_with_tabs = false # use tabs to align +align_on_tabstop = false # align on tabstops +align_enum_equ_span = 4 # '=' in enum definition +align_nl_cont = true +align_assign_span = 0 +align_struct_init_span = 3 # align stuff in a structure init '= { }' +align_right_cmt_span = 3 +align_pp_define_span = 8 +align_pp_define_gap = 4 +align_func_params = false +align_var_struct_span = 0 + +# Comment + +cmt_indent_multi = true +cmt_c_group = false +cmt_c_nl_start = false +cmt_c_nl_end = false +cmt_cpp_group = true +cmt_cpp_nl_start = false +cmt_cpp_nl_end = false +cmt_cpp_to_c = true +cmt_star_cont = false +cmt_multi_check_last = true + +eat_blanks_after_open_brace = true +eat_blanks_before_close_brace = true + +# Preprocessor + +pp_indent = remove +pp_space = force +pp_space_count = 1 + +# Misc + +set cpp_cast nonstd # nonstd cast attributes +set func_call_user _ N_ # gettext macros +set attribute CR_FORMAT CR_API CR_PURE CR_INLINE diff --git a/include/criterion/abort.h b/include/criterion/abort.h index ef5d155..bbf9ad5 100644 --- a/include/criterion/abort.h +++ b/include/criterion/abort.h @@ -26,9 +26,9 @@ * @brief Functions to abort and continue tests *****************************************************************************/ #ifndef CRITERION_ABORT_H_ -# define CRITERION_ABORT_H_ +#define CRITERION_ABORT_H_ -# include "internal/common.h" +#include "internal/common.h" CR_BEGIN_C_API diff --git a/include/criterion/alloc.h b/include/criterion/alloc.h index 3de9e2f..7bf04d1 100644 --- a/include/criterion/alloc.h +++ b/include/criterion/alloc.h @@ -26,16 +26,16 @@ * @brief Test intern memory managment *****************************************************************************/ #ifndef CRITERION_ALLOC_H_ -# define CRITERION_ALLOC_H_ +#define CRITERION_ALLOC_H_ -# ifdef __cplusplus -# include -# include +#ifdef __cplusplus +# include +# include using std::size_t; -# else -# include -# endif -# include "internal/common.h" +#else +# include +#endif +#include "internal/common.h" CR_BEGIN_C_API @@ -92,177 +92,187 @@ CR_API void cr_free(void *ptr); CR_END_C_API -# ifdef __cplusplus -# include +#ifdef __cplusplus +# include -namespace criterion { +namespace criterion +{ +void *(*const malloc)(size_t) = cr_malloc; +void(*const free)(void *) = cr_free; +void *(*const calloc)(size_t, size_t) = cr_calloc; +void *(*const realloc)(void *, size_t) = cr_realloc; - void *(*const malloc)(size_t) = cr_malloc; - void (*const free)(void *) = cr_free; - void *(*const calloc)(size_t, size_t) = cr_calloc; - void *(*const realloc)(void *, size_t) = cr_realloc; +/** + * Allocates and construct a new object. + * + * It is undefined behaviour to access a pointer returned by the new + * operator inside a test or its setup and teardown functions; + * new_obj must be used in its place for this purpose. + * + * This function is semantically identical to the new operator. + * + * @tparam T The type of the object to construct + * @param[in] params The constructor parameters of T. + * @returns The pointer to the newly constructed object. + */ +template +T *new_obj(Params... params) +{ + T *obj = static_cast(cr_malloc(sizeof (T))); - /** - * Allocates and construct a new object. - * - * It is undefined behaviour to access a pointer returned by the new - * operator inside a test or its setup and teardown functions; - * new_obj must be used in its place for this purpose. - * - * This function is semantically identical to the new operator. - * - * @tparam T The type of the object to construct - * @param[in] params The constructor parameters of T. - * @returns The pointer to the newly constructed object. - */ - template - T* new_obj(Params... params) { - T* obj = static_cast(cr_malloc(sizeof (T))); - new (obj) T(params...); - return obj; - } + new (obj) T(params...); + return obj; +} - /** - * Allocates and construct a new array of primitive types - * - * It is undefined behaviour to access a pointer returned by the new[] - * operator inside a test or its setup and teardown functions; - * new_arr must be used in its place for this purpose. - * - * This function is semantically identical to the new[] operator. - * - * @tparam T The compound type of the array to construct - * @param[in] len The length of the array. - * @returns The pointer to the newly constructed array. - */ - template - typename std::enable_if::value>::type* - new_arr(size_t len) { - void *ptr = cr_malloc(sizeof (size_t) + sizeof (T) * len); - *(reinterpret_cast(ptr)) = len; - T* arr = reinterpret_cast(reinterpret_cast(ptr) + 1); - return arr; - } +/** + * Allocates and construct a new array of primitive types + * + * It is undefined behaviour to access a pointer returned by the new[] + * operator inside a test or its setup and teardown functions; + * new_arr must be used in its place for this purpose. + * + * This function is semantically identical to the new[] operator. + * + * @tparam T The compound type of the array to construct + * @param[in] len The length of the array. + * @returns The pointer to the newly constructed array. + */ +template +typename std::enable_if::value>::type +* new_arr(size_t len) { + void *ptr = cr_malloc(sizeof (size_t) + sizeof (T) * len); - /** - * Allocates and construct a new array of object types - * - * It is undefined behaviour to access a pointer returned by the new[] - * operator inside a test or its setup and teardown functions; - * new_arr must be used in its place for this purpose. - * - * This function is semantically identical to the new[] operator. - * - * @tparam T The compound type of the array to construct - * @param[in] len The length of the array. - * @returns The pointer to the newly constructed array. - */ - template - T* new_arr(size_t len) { - void *ptr = cr_malloc(sizeof (size_t) + sizeof (T) * len); - *(reinterpret_cast(ptr)) = len; + *(reinterpret_cast(ptr)) = len; + T *arr = reinterpret_cast(reinterpret_cast(ptr) + 1); + return arr; +} - T* arr = reinterpret_cast(reinterpret_cast(ptr) + 1); - for (size_t i = 0; i < len; ++i) - new (arr + i) T(); - return arr; - } +/** + * Allocates and construct a new array of object types + * + * It is undefined behaviour to access a pointer returned by the new[] + * operator inside a test or its setup and teardown functions; + * new_arr must be used in its place for this purpose. + * + * This function is semantically identical to the new[] operator. + * + * @tparam T The compound type of the array to construct + * @param[in] len The length of the array. + * @returns The pointer to the newly constructed array. + */ +template +T *new_arr(size_t len) +{ + void *ptr = cr_malloc(sizeof (size_t) + sizeof (T) * len); - /** - * Destroys and frees an object allocated by new_obj. - * - * This function is semantically identical to the delete operator. - * - * @tparam T The type of the object to construct - * @param[in] ptr The object to destroy. - */ - template - void delete_obj(T* ptr) { - ptr->~T(); - cr_free(ptr); - } + *(reinterpret_cast(ptr)) = len; - /** - * Destroys and frees an array allocated by delete_arr. - * - * This function is semantically identical to the delete[] operator. - * - * @tparam T The type of the object to construct - * @param[in] ptr The object to destroy. - */ - template - void delete_arr(typename std::enable_if::value>::type* ptr) { - cr_free(ptr); - } + T *arr = reinterpret_cast(reinterpret_cast(ptr) + 1); + for (size_t i = 0; i < len; ++i) + new (arr + i)T(); + return arr; +} - /** - * Destroys and frees an array allocated by delete_arr. - * - * This function is semantically identical to the delete[] operator. - * - * @tparam T The type of the object to construct - * @param[in] ptr The object to destroy. - */ - template - void delete_arr(T* ptr) { - size_t *ptr_ = reinterpret_cast(ptr); - size_t len = *(ptr_ - 1); - T* arr = reinterpret_cast(ptr_); - for (size_t i = 0; i < len; ++i) - arr[i].~T(); - cr_free(ptr_ - 1); - } +/** + * Destroys and frees an object allocated by new_obj. + * + * This function is semantically identical to the delete operator. + * + * @tparam T The type of the object to construct + * @param[in] ptr The object to destroy. + */ +template +void delete_obj(T *ptr) +{ + ptr->~T(); + cr_free(ptr); +} - /** - * Allocator for use in the STL. - * - * This internally uses calls to the cr_malloc function family, which - * means that STL collections can be safely used inside tests or - * setup/teardown functions if this allocator is used. - */ - template - struct allocator { - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; +/** + * Destroys and frees an array allocated by delete_arr. + * + * This function is semantically identical to the delete[] operator. + * + * @tparam T The type of the object to construct + * @param[in] ptr The object to destroy. + */ +template +void delete_arr(typename std::enable_if::value>::type *ptr) +{ + cr_free(ptr); +} - template - struct rebind { - typedef allocator other; - }; +/** + * Destroys and frees an array allocated by delete_arr. + * + * This function is semantically identical to the delete[] operator. + * + * @tparam T The type of the object to construct + * @param[in] ptr The object to destroy. + */ +template +void delete_arr(T *ptr) +{ + size_t *ptr_ = reinterpret_cast(ptr); + size_t len = *(ptr_ - 1); + T *arr = reinterpret_cast(ptr_); - inline explicit allocator() {} - inline ~allocator() {} - inline explicit allocator(allocator const&) {} - template - inline explicit allocator(allocator const&) {} + for (size_t i = 0; i < len; ++i) + arr[i].~T(); + cr_free(ptr_ - 1); +} - inline pointer address(reference r) { return &r; } - inline const_pointer address(const_reference r) { return &r; } +/** + * Allocator for use in the STL. + * + * This internally uses calls to the cr_malloc function family, which + * means that STL collections can be safely used inside tests or + * setup/teardown functions if this allocator is used. + */ +template +struct allocator { + typedef T value_type; + typedef value_type *pointer; + typedef const value_type *const_pointer; + typedef value_type &reference; + typedef const value_type &const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; - inline pointer allocate(size_type cnt, typename std::allocator::const_pointer = 0) { - return reinterpret_cast(cr_malloc(cnt * sizeof (T))); - } - - inline void deallocate(pointer p, size_type) { cr_free(p); } - - inline size_type max_size() const { - return size_type(-1) / sizeof(T); - } - - inline void construct(pointer p, const T& t) { new(p) T(t); } - inline void construct(pointer p, T&& t) { new (p) T(std::move(t)); } - inline void destroy(pointer p) { p->~T(); } - - inline bool operator==(allocator const&) { return true; } - inline bool operator!=(allocator const& a) { return !operator==(a); } + template + struct rebind { + typedef allocator other; }; + inline explicit allocator() {} + inline ~allocator() {} + inline explicit allocator(allocator const &) {} + template + inline explicit allocator(allocator const &) {} + + inline pointer address(reference r) { return &r; } + inline const_pointer address(const_reference r) { return &r; } + + inline pointer allocate(size_type cnt, typename std::allocator::const_pointer = 0) + { + return reinterpret_cast(cr_malloc(cnt * sizeof (T))); + } + + inline void deallocate(pointer p, size_type) { cr_free(p); } + + inline size_type max_size() const + { + return size_type(-1) / sizeof (T); + } + + inline void construct(pointer p, const T &t) { new(p) T(t); } + inline void construct(pointer p, T &&t) { new (p) T(std::move(t)); } + inline void destroy(pointer p) { p->~T(); } + + inline bool operator==(allocator const &) { return true; } + inline bool operator!=(allocator const &a) { return !operator==(a); } +}; } -# endif +#endif #endif /* !CRITERION_ALLOC_H_ */ diff --git a/include/criterion/assert.h b/include/criterion/assert.h index fe14a37..d05509c 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -27,11 +27,11 @@ * @brief Assertion API *****************************************************************************/ #ifndef CRITERION_ASSERT_H_ -# define CRITERION_ASSERT_H_ +#define CRITERION_ASSERT_H_ -# ifdef __cplusplus -# include -# endif +#ifdef __cplusplus +# include +#endif /** * @defgroup BaseAsserts Base assertions @@ -49,14 +49,14 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_fail(FormatString, ...) -/** - * Skips the test - * - * The test is marked as skipped and the execution of the function is aborted. - * - *****************************************************************************/ -# define cr_skip_test(FormatString, ...) +#define cr_assert_fail(FormatString, ...) < internal +> /** + * Skips the test + * + * The test is marked as skipped and the execution of the function is aborted. + * + *****************************************************************************/ +#define cr_skip_test(FormatString, ...) < internal > /** * Fails always. @@ -69,7 +69,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_fail(FormatString, ...) +#define cr_expect_fail(FormatString, ...) < internal > /** * Passes if Condition is true @@ -85,7 +85,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert(Condition, FormatString, ...) +#define cr_assert(Condition, FormatString, ...) < internal > /** * Passes if Condition is true @@ -100,7 +100,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect(Condition, FormatString, ...) +#define cr_expect(Condition, FormatString, ...) < internal > /** * Passes if Condition is false @@ -116,7 +116,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_not(Condition, FormatString, ...) +#define cr_assert_not(Condition, FormatString, ...) < internal > /** * Passes if Condition is false @@ -131,7 +131,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_not(Condition, FormatString, ...) +#define cr_expect_not(Condition, FormatString, ...) < internal > /**@}*/ @@ -157,7 +157,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_eq(Actual, Expected, FormatString, ...) +#define cr_assert_eq(Actual, Expected, FormatString, ...) < internal > /** * Passes if Actual is equal to Expected @@ -175,7 +175,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_eq(Actual, Expected, FormatString, ...) +#define cr_expect_eq(Actual, Expected, FormatString, ...) < internal > /** * Passes if Actual is not equal to Unexpected @@ -194,7 +194,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_neq(Actual, Unexpected, FormatString, ...) +#define cr_assert_neq(Actual, Unexpected, FormatString, ...) < internal > /** * Passes if Actual is not equal to Unexpected @@ -212,7 +212,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_neq(Actual, Unexpected, FormatString, ...) +#define cr_expect_neq(Actual, Unexpected, FormatString, ...) < internal > /** * Passes if Actual is less than Reference @@ -231,7 +231,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_lt(Actual, Reference, FormatString, ...) +#define cr_assert_lt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is less than Reference @@ -249,7 +249,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_lt(Actual, Reference, FormatString, ...) +#define cr_expect_lt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is less or equal to Reference @@ -268,7 +268,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_leq(Actual, Reference, FormatString, ...) +#define cr_assert_leq(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is less or equal to Reference @@ -286,7 +286,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_leq(Actual, Reference, FormatString, ...) +#define cr_expect_leq(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is greater than Reference @@ -305,7 +305,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_gt(Actual, Reference, FormatString, ...) +#define cr_assert_gt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is greater than Reference @@ -323,7 +323,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_gt(Actual, Reference, FormatString, ...) +#define cr_expect_gt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is greater or equal to Reference @@ -342,7 +342,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_geq(Actual, Reference, FormatString, ...) +#define cr_assert_geq(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is greater or equal to Reference @@ -360,7 +360,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_geq(Actual, Reference, FormatString, ...) +#define cr_expect_geq(Actual, Reference, FormatString, ...) < internal > /**@}*/ @@ -383,7 +383,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_null(Value, FormatString, ...) +#define cr_assert_null(Value, FormatString, ...) < internal > /** * Passes if Value is NULL @@ -398,7 +398,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_null(Value, FormatString, ...) +#define cr_expect_null(Value, FormatString, ...) < internal > /** * Passes if Value is not NULL @@ -414,7 +414,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_not_null(Value, FormatString, ...) +#define cr_assert_not_null(Value, FormatString, ...) < internal > /** * Passes if Value is not NULL @@ -429,7 +429,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_not_null(Value, FormatString, ...) +#define cr_expect_not_null(Value, FormatString, ...) < internal > /**@}*/ @@ -456,7 +456,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_float_eq(Actual, Expected, Epsilon, FormatString, ...) +#define cr_assert_float_eq(Actual, Expected, Epsilon, FormatString, ...) < internal > /** * Passes if Actual is equal to Expected with a tolerance of Epsilon @@ -475,7 +475,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_float_eq(Actual, Expected, Epsilon, FormatString, ...) +#define cr_expect_float_eq(Actual, Expected, Epsilon, FormatString, ...) < internal > /** * Passes if Actual is not equal to Unexpected with a tolerance of Epsilon @@ -495,7 +495,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) +#define cr_assert_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) < internal > /** * Passes if Actual is not equal to Unexpected with a tolerance of Epsilon @@ -514,7 +514,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) +#define cr_expect_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) < internal > /**@}*/ @@ -545,7 +545,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_empty(Value, FormatString, ...) +#define cr_assert_str_empty(Value, FormatString, ...) < internal > /** * Passes if Value is an empty string @@ -562,7 +562,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_empty(Value, FormatString, ...) +#define cr_expect_str_empty(Value, FormatString, ...) < internal > /** * Passes if Value is not an empty string @@ -580,7 +580,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_not_empty(Value, FormatString, ...) +#define cr_assert_str_not_empty(Value, FormatString, ...) < internal > /** * Passes if Value is not an empty string @@ -597,7 +597,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_not_empty(Value, FormatString, ...) +#define cr_expect_str_not_empty(Value, FormatString, ...) < internal > /** * Passes if Actual is lexicographically equal to Expected @@ -614,7 +614,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_eq(Actual, Expected, FormatString, ...) +#define cr_assert_str_eq(Actual, Expected, FormatString, ...) < internal > /** * Passes if Actual is lexicographically equal to Expected @@ -630,7 +630,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_eq(Actual, Expected, FormatString, ...) +#define cr_expect_str_eq(Actual, Expected, FormatString, ...) < internal > /** * Passes if Actual is not lexicographically equal to Unexpected @@ -647,7 +647,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_neq(Actual, Unexpected, FormatString, ...) +#define cr_assert_str_neq(Actual, Unexpected, FormatString, ...) < internal > /** * Passes if Actual is not lexicographically equal to Unexpected @@ -663,7 +663,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_neq(Actual, Unexpected, FormatString, ...) +#define cr_expect_str_neq(Actual, Unexpected, FormatString, ...) < internal > /** * Passes if Actual is lexicographically less than Reference @@ -680,7 +680,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_lt(Actual, Reference, FormatString, ...) +#define cr_assert_str_lt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically less than Reference @@ -696,7 +696,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_lt(Actual, Reference, FormatString, ...) +#define cr_expect_str_lt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically less or equal to Reference @@ -713,7 +713,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_leq(Actual, Reference, FormatString, ...) +#define cr_assert_str_leq(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically less or equal to Reference @@ -729,7 +729,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_leq(Actual, Reference, FormatString, ...) +#define cr_expect_str_leq(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically greater than Reference @@ -746,7 +746,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_gt(Actual, Reference, FormatString, ...) +#define cr_assert_str_gt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically greater than Reference @@ -762,7 +762,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_gt(Actual, Reference, FormatString, ...) +#define cr_expect_str_gt(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically greater or equal to Reference @@ -779,7 +779,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_str_geq(Actual, Reference, FormatString, ...) +#define cr_assert_str_geq(Actual, Reference, FormatString, ...) < internal > /** * Passes if Actual is lexicographically greater or equal to Reference @@ -795,7 +795,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_str_geq(Actual, Reference, FormatString, ...) +#define cr_expect_str_geq(Actual, Reference, FormatString, ...) < internal > /**@}*/ @@ -822,7 +822,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_eq(Actual, Expected, FormatString, ...) +#define cr_assert_arr_eq(Actual, Expected, FormatString, ...) < internal > /** * Passes if Actual is byte-to-byte equal to Expected @@ -841,7 +841,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_eq(Actual, Expected, FormatString, ...) +#define cr_expect_arr_eq(Actual, Expected, FormatString, ...) < internal > /** * Passes if Actual is not byte-to-byte equal to Expected @@ -862,7 +862,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_neq(Actual, Unexpected, Size, FormatString, ...) +#define cr_assert_arr_neq(Actual, Unexpected, Size, FormatString, ...) < internal > /** * Passes if Actual is not byte-to-byte equal to Unexpected @@ -882,7 +882,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_neq(Actual, Unexpected, Size, FormatString, ...) +#define cr_expect_arr_neq(Actual, Unexpected, Size, FormatString, ...) < internal > /**@}*/ @@ -917,7 +917,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) +#define cr_assert_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively equal to Expected (C++ / GNU C99 only) @@ -941,7 +941,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) +#define cr_expect_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is not comparatively equal to Unexpected (C++ / GNU C99 @@ -967,7 +967,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) +#define cr_assert_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is not comparatively equal to Unexpected (C++ / GNU C99 @@ -992,7 +992,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) +#define cr_expect_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively less than Reference (C++ / GNU C99 only) @@ -1017,7 +1017,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_assert_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively less than Reference (C++ / GNU C99 only) @@ -1041,7 +1041,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_expect_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively less or equal to Reference (C++ / GNU C99 @@ -1067,7 +1067,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_assert_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively less or equal to Reference (C++ / GNU C99 @@ -1092,7 +1092,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_expect_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively greater than Reference (C++ / GNU C99 only) @@ -1117,7 +1117,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_assert_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively greater than Reference (C++ / GNU C99 only) @@ -1141,7 +1141,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_expect_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively greater or equal to Reference (C++ / GNU @@ -1167,7 +1167,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_assert_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /** * Passes if Actual is comparatively greater or equal to Reference (C++ / GNU @@ -1192,11 +1192,11 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) +#define cr_expect_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) < internal > /**@}*/ -# ifdef __cplusplus +#ifdef __cplusplus /** * @defgroup ExceptionAsserts Exception asserts @@ -1223,7 +1223,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_throw(Statement, Exception, FormatString, ...) +# define cr_assert_throw(Statement, Exception, FormatString, ...) < internal > /** * Passes if Statement throws an instance of Exception (C++ only) @@ -1241,7 +1241,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_throw(Statement, Exception, FormatString, ...) +# define cr_expect_throw(Statement, Exception, FormatString, ...) < internal > /** * Passes if Statement does not throws an instance of Exception (C++ only) @@ -1260,7 +1260,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_no_throw(Statement, Exception, FormatString, ...) +# define cr_assert_no_throw(Statement, Exception, FormatString, ...) < internal > /** * Passes if Statement does not throws an instance of Exception (C++ only) @@ -1278,7 +1278,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_no_throw(Statement, Exception, FormatString, ...) +# define cr_expect_no_throw(Statement, Exception, FormatString, ...) < internal > /** * Passes if Statement throws any kind of exception (C++ only) @@ -1296,7 +1296,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_any_throw(Statement, FormatString, ...) +# define cr_assert_any_throw(Statement, FormatString, ...) < internal > /** * Passes if Statement throws any kind of exception (C++ only) @@ -1313,7 +1313,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_any_throw(Statement, FormatString, ...) +# define cr_expect_any_throw(Statement, FormatString, ...) < internal > /** * Passes if Statement does not throws any kind of exception (C++ only) @@ -1331,7 +1331,7 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_none_throw(Statement, FormatString, ...) +# define cr_assert_none_throw(Statement, FormatString, ...) < internal > /** * Passes if Statement does not throws any kind of exception (C++ only) @@ -1348,23 +1348,23 @@ * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_none_throw(Statement, FormatString, ...) +# define cr_expect_none_throw(Statement, FormatString, ...) < internal > -# endif +#endif /**@}*/ /** @cond CRITERION_DOC_DEPRECATED */ -// The section below is here for backward compatibility purposes. -// It shall be removed in the next major version of Criterion -# ifndef CRITERION_NO_COMPAT +/* The section below is here for backward compatibility purposes. + It shall be removed in the next major version of Criterion */ +#ifndef CRITERION_NO_COMPAT -# define CRITERION_ASSERT_DEPRECATED_B(Name, Newname) \ - CRITERION_ASSERT_DEPRECATED__( \ - message \ - ("The `" #Name "` macro is deprecated, " \ - "please use `" #Newname "` instead.") \ - ) +# define CRITERION_ASSERT_DEPRECATED_B(Name, Newname) \ + CRITERION_ASSERT_DEPRECATED__( \ + message \ + ("The `" #Name "` macro is deprecated, " \ + "please use `" #Newname "` instead.") \ + ) # ifdef _MSC_VER # define CRITERION_ASSERT_DEPRECATED__(Msg) \ @@ -1374,25 +1374,25 @@ _Pragma(#Msg) # endif -// scheduled for removal after 2.0 -# define cr_abort_test(Message) CRITERION_ASSERT_DEPRECATED_B(cr_abort_test, cr_assert_fail) cr_assert_fail(Message) -# define cr_assert_strings_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_eq, cr_assert_str_eq) cr_assert_str_eq(__VA_ARGS__) -# define cr_assert_strings_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_neq, cr_assert_str_neq) cr_assert_str_neq(__VA_ARGS__) -# define cr_assert_strings_lt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_lt, cr_assert_str_lt) cr_assert_str_lt(__VA_ARGS__) -# define cr_assert_strings_leq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_leq, cr_assert_str_leq) cr_assert_str_leq(__VA_ARGS__) -# define cr_assert_strings_gt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_gt, cr_assert_str_gt) cr_assert_str_gt(__VA_ARGS__) -# define cr_assert_strings_geq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_geq, cr_assert_str_geq) cr_assert_str_geq(__VA_ARGS__) +/* scheduled for removal after 2.0 */ +# define cr_abort_test(Message) CRITERION_ASSERT_DEPRECATED_B(cr_abort_test, cr_assert_fail) cr_assert_fail(Message) +# define cr_assert_strings_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_eq, cr_assert_str_eq) cr_assert_str_eq(__VA_ARGS__) +# define cr_assert_strings_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_neq, cr_assert_str_neq) cr_assert_str_neq(__VA_ARGS__) +# define cr_assert_strings_lt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_lt, cr_assert_str_lt) cr_assert_str_lt(__VA_ARGS__) +# define cr_assert_strings_leq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_leq, cr_assert_str_leq) cr_assert_str_leq(__VA_ARGS__) +# define cr_assert_strings_gt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_gt, cr_assert_str_gt) cr_assert_str_gt(__VA_ARGS__) +# define cr_assert_strings_geq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_strings_geq, cr_assert_str_geq) cr_assert_str_geq(__VA_ARGS__) -# define cr_assert_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_eq, cr_assert_arr_eq) cr_assert_arr_eq(__VA_ARGS__) -# define cr_assert_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_neq, cr_assert_arr_neq) cr_assert_arr_neq(__VA_ARGS__) +# define cr_assert_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_eq, cr_assert_arr_eq) cr_assert_arr_eq(__VA_ARGS__) +# define cr_assert_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_neq, cr_assert_arr_neq) cr_assert_arr_neq(__VA_ARGS__) -# define cr_assert_arrays_eq_cmp(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_eq_cmp, cr_assert_arr_eq_cmp) cr_assert_arr_eq_cmp(__VA_ARGS__) -# define cr_assert_arrays_neq_cmp(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_neq_cmp, cr_assert_arr_neq_cmp) cr_assert_arr_neq_cmp(__VA_ARGS__) +# define cr_assert_arrays_eq_cmp(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_eq_cmp, cr_assert_arr_eq_cmp) cr_assert_arr_eq_cmp(__VA_ARGS__) +# define cr_assert_arrays_neq_cmp(...) CRITERION_ASSERT_DEPRECATED_B(cr_assert_arrays_neq_cmp, cr_assert_arr_neq_cmp) cr_assert_arr_neq_cmp(__VA_ARGS__) -# endif +#endif /** @endcond */ -# include "internal/assert.h" +#include "internal/assert.h" #endif /* !CRITERION_ASSERT_H_ */ diff --git a/include/criterion/criterion.h b/include/criterion/criterion.h index df66d54..6b57dae 100644 --- a/include/criterion/criterion.h +++ b/include/criterion/criterion.h @@ -26,11 +26,11 @@ * @brief Include this to use criterion *****************************************************************************/ #ifndef CRITERION_H_ -# define CRITERION_H_ +#define CRITERION_H_ -# include "types.h" -# include "assert.h" -# include "alloc.h" +#include "types.h" +#include "assert.h" +#include "alloc.h" /** * Defines a new test. @@ -42,7 +42,7 @@ * (see criterion/types.h).\n * Example: .exit_code = 1 */ -# define Test(Suite, Name, ...) +#define Test(Suite, Name, ...) < internal > /** * Explicitely defines a test suite and its options. @@ -53,7 +53,7 @@ * (see criterion/types.h). * These options will provide the defaults for each test. */ -# define TestSuite(Name, ...) +#define TestSuite(Name, ...) < internal > CR_BEGIN_C_API @@ -109,13 +109,13 @@ CR_API int criterion_handle_args(int argc, char *argv[], bool handle_unknown_arg * @param[in] test The newly created test. */ CR_API void criterion_register_test(struct criterion_test_set *tests, - struct criterion_test *test); + struct criterion_test *test); -CR_API extern const struct criterion_test *const criterion_current_test; +CR_API extern const struct criterion_test *const criterion_current_test; CR_API extern const struct criterion_suite *const criterion_current_suite; CR_END_C_API -# include "internal/test.h" +#include "internal/test.h" #endif /* !CRITERION_H_ */ diff --git a/include/criterion/event.h b/include/criterion/event.h index 0ca76e9..041f6f6 100644 --- a/include/criterion/event.h +++ b/include/criterion/event.h @@ -22,15 +22,15 @@ * THE SOFTWARE. */ #ifndef CRITERION_EVENT_H_ -# define CRITERION_EVENT_H_ +#define CRITERION_EVENT_H_ -# ifdef __cplusplus -# include -# else -# include -# endif -# include "internal/common.h" -# include "stats.h" +#ifdef __cplusplus +# include +#else +# include +#endif +#include "internal/common.h" +#include "stats.h" CR_BEGIN_C_API diff --git a/include/criterion/hooks.h b/include/criterion/hooks.h index d7c687d..861b9a4 100644 --- a/include/criterion/hooks.h +++ b/include/criterion/hooks.h @@ -26,9 +26,9 @@ * @brief Report hooks *****************************************************************************/ #ifndef CRITERION_HOOKS_H_ -# define CRITERION_HOOKS_H_ +#define CRITERION_HOOKS_H_ -# include "internal/hooks.h" +#include "internal/hooks.h" /** * This enum lists all the phases of the runner lifecycle. @@ -67,6 +67,6 @@ typedef void (*f_report_hook)(); * * @param Kind The report phase to hook the function onto. */ -# define ReportHook(Kind) CR_REPORT_HOOK_IMPL(Kind) +#define ReportHook(Kind) CR_REPORT_HOOK_IMPL(Kind) #endif /* !CRITERION_HOOKS_H_ */ diff --git a/include/criterion/internal/asprintf-compat.h b/include/criterion/internal/asprintf-compat.h index 6e99a9c..2579d88 100644 --- a/include/criterion/internal/asprintf-compat.h +++ b/include/criterion/internal/asprintf-compat.h @@ -22,15 +22,15 @@ * THE SOFTWARE. */ #ifndef CRITERION_ASPRINTF_COMPAT_H_ -# define CRITERION_ASPRINTF_COMPAT_H_ +#define CRITERION_ASPRINTF_COMPAT_H_ -# ifdef __cplusplus -# include -# else -# include -# endif +#ifdef __cplusplus +# include +#else +# include +#endif -# include "common.h" +#include "common.h" CR_BEGIN_C_API diff --git a/include/criterion/internal/assert.h b/include/criterion/internal/assert.h index ef135ae..ba923e7 100644 --- a/include/criterion/internal/assert.h +++ b/include/criterion/internal/assert.h @@ -22,26 +22,26 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_ASSERT_H_ -# define CRITERION_INTERNAL_ASSERT_H_ +#define CRITERION_INTERNAL_ASSERT_H_ -# include "common.h" -# include "preprocess.h" -# include "asprintf-compat.h" -# include "designated-initializer-compat.h" +#include "common.h" +#include "preprocess.h" +#include "asprintf-compat.h" +#include "designated-initializer-compat.h" -# ifdef __cplusplus -# include -# include -# else -# include -# include -# include -# endif -# include "../types.h" -# include "../stats.h" -# include "../hooks.h" -# include "../event.h" -# include "../abort.h" +#ifdef __cplusplus +# include +# include +#else +# include +# include +# include +#endif +#include "../types.h" +#include "../stats.h" +#include "../hooks.h" +#include "../event.h" +#include "../abort.h" struct criterion_assert_args { const char *msg; @@ -53,7 +53,7 @@ struct criterion_assert_args { #endif }; -// Do NOT reorder unless you want to break the ABI +/* Do NOT reorder unless you want to break the ABI */ enum criterion_assert_messages { CRITERION_ASSERT_MSG_FAIL, CRITERION_ASSERT_MSG_EXPR_FALSE, @@ -76,561 +76,560 @@ CR_API char *cr_translate_assert_msg(int msg_index, ...); CR_END_C_API -# define CR_GET_CONDITION(Condition, ...) Condition -# define CR_GET_CONDITION_STR(Condition, ...) #Condition -# define CR_VA_SKIP(_, ...) __VA_ARGS__ +#define CR_GET_CONDITION(Condition, ...) Condition +#define CR_GET_CONDITION_STR(Condition, ...) #Condition +#define CR_VA_SKIP(_, ...) __VA_ARGS__ -# define CR_TRANSLATE_DEF_MSG__(Arg) \ +#define CR_TRANSLATE_DEF_MSG__(Arg) \ CR_IDENTITY Arg -# define CR_TRANSLATE_DEF_MSG_(...) \ - CR_EXPAND(cr_translate_assert_msg( \ - CR_VA_HEAD(__VA_ARGS__), \ - "" CR_TRANSLATE_DEF_MSG__(CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__))) \ - )) +#define CR_TRANSLATE_DEF_MSG_(...) \ + CR_EXPAND(cr_translate_assert_msg( \ + CR_VA_HEAD(__VA_ARGS__), \ + "" CR_TRANSLATE_DEF_MSG__(CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__))) \ + )) -# define CR_INIT_STATS_(MsgVar, Shifted, ...) CR_EXPAND( \ - do { \ - char *cr_def_msg__ = CR_EXPAND(CR_TRANSLATE_DEF_MSG_(__VA_ARGS__)); \ - char *cr_fmt_msg__ = NULL; \ - cr_asprintf(&cr_fmt_msg__, "x" CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))); \ - if (cr_fmt_msg__ && cr_fmt_msg__[1]) { \ - MsgVar = cr_fmt_msg__ + 1; \ - Shifted = 1; \ - cr_asprintf_free(cr_def_msg__); \ - } else { \ - MsgVar = cr_def_msg__; \ - cr_asprintf_free(cr_fmt_msg__); \ - } \ +#define CR_INIT_STATS_(MsgVar, Shifted, ...) \ + CR_EXPAND( \ + do { \ + char *cr_def_msg__ = CR_EXPAND(CR_TRANSLATE_DEF_MSG_(__VA_ARGS__)); \ + char *cr_fmt_msg__ = NULL; \ + cr_asprintf(&cr_fmt_msg__, "x" CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))); \ + if (cr_fmt_msg__ && cr_fmt_msg__[1]) { \ + MsgVar = cr_fmt_msg__ + 1; \ + Shifted = 1; \ + cr_asprintf_free(cr_def_msg__); \ + } else { \ + MsgVar = cr_def_msg__; \ + cr_asprintf_free(cr_fmt_msg__); \ + } \ } while (0)) -# define CR_FAIL_ABORT_ criterion_abort_test -# define CR_FAIL_CONTINUES_ criterion_continue_test +#define CR_FAIL_ABORT_ criterion_abort_test +#define CR_FAIL_CONTINUES_ criterion_continue_test -# define cr_assert_impl(Fail, Condition, ...) \ - do { \ - bool cr_passed__ = !!(Condition); \ - char *cr_msg__ = NULL; \ - int cr_shifted__ = 0; \ - \ - CR_EXPAND(CR_INIT_STATS_(cr_msg__, cr_shifted__, \ - CR_VA_TAIL(__VA_ARGS__))); \ - struct criterion_assert_stats cr_stat__; \ - cr_stat__.passed = cr_passed__; \ - cr_stat__.file = __FILE__; \ - cr_stat__.line = __LINE__; \ - cr_stat__.message = cr_msg__; \ - criterion_send_assert(&cr_stat__); \ - \ - cr_asprintf_free(cr_msg__ - cr_shifted__); \ - \ - if (!cr_passed__) \ - Fail(); \ +#define cr_assert_impl(Fail, Condition, ...) \ + do { \ + bool cr_passed__ = !!(Condition); \ + char *cr_msg__ = NULL; \ + int cr_shifted__ = 0; \ + \ + CR_EXPAND(CR_INIT_STATS_(cr_msg__, cr_shifted__, \ + CR_VA_TAIL(__VA_ARGS__))); \ + struct criterion_assert_stats cr_stat__; \ + cr_stat__.passed = cr_passed__; \ + cr_stat__.file = __FILE__; \ + cr_stat__.line = __LINE__; \ + cr_stat__.message = cr_msg__; \ + criterion_send_assert(&cr_stat__); \ + \ + cr_asprintf_free(cr_msg__ - cr_shifted__); \ + \ + if (!cr_passed__) \ + Fail(); \ } while (0) +#define cr_fail(Fail, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + 0, \ + dummy, \ + CRITERION_ASSERT_MSG_FAIL, \ + (), \ + __VA_ARGS__ \ + )) -# define cr_fail(Fail, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - 0, \ - dummy, \ - CRITERION_ASSERT_MSG_FAIL, \ - (), \ - __VA_ARGS__ \ - )) - -# define cr_skip(...) \ +#define cr_skip(...) \ criterion_skip_test("" __VA_ARGS__) +#define cr_assert_(...) \ + CR_EXPAND(cr_assert_impl( \ + CR_FAIL_ABORT_, \ + CR_VA_HEAD(__VA_ARGS__), \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR(CR_VA_HEAD(__VA_ARGS__))), \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_assert_(...) \ - CR_EXPAND(cr_assert_impl( \ - CR_FAIL_ABORT_, \ - CR_VA_HEAD(__VA_ARGS__), \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR(CR_VA_HEAD(__VA_ARGS__))), \ - CR_VA_TAIL(__VA_ARGS__) \ - )) +#define cr_expect_(...) \ + CR_EXPAND(cr_assert_impl( \ + CR_FAIL_CONTINUES_, \ + CR_VA_HEAD(__VA_ARGS__), \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR(CR_VA_HEAD(__VA_ARGS__))), \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_expect_(...) \ - CR_EXPAND(cr_assert_impl( \ - CR_FAIL_CONTINUES_, \ - CR_VA_HEAD(__VA_ARGS__), \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR(CR_VA_HEAD(__VA_ARGS__))), \ - CR_VA_TAIL(__VA_ARGS__) \ - )) +#define cr_assert_not_(...) \ + CR_EXPAND(cr_assert_impl( \ + CR_FAIL_ABORT_, \ + !(CR_VA_HEAD(__VA_ARGS__)), \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR(!(CR_VA_HEAD(__VA_ARGS__)))), \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_assert_not_(...) \ - CR_EXPAND(cr_assert_impl( \ - CR_FAIL_ABORT_, \ - !(CR_VA_HEAD(__VA_ARGS__)), \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR(!(CR_VA_HEAD(__VA_ARGS__)))), \ - CR_VA_TAIL(__VA_ARGS__) \ - )) +#define cr_expect_not_(...) \ + CR_EXPAND(cr_assert_impl( \ + CR_FAIL_CONTINUES_, \ + !(CR_VA_HEAD(__VA_ARGS__)), \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR(!(CR_VA_HEAD(__VA_ARGS__)))), \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_expect_not_(...) \ - CR_EXPAND(cr_assert_impl( \ - CR_FAIL_CONTINUES_, \ - !(CR_VA_HEAD(__VA_ARGS__)), \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR(!(CR_VA_HEAD(__VA_ARGS__)))), \ - CR_VA_TAIL(__VA_ARGS__) \ - )) +/* Binary */ +#define cr_assert_op_(Fail, Op, Actual, Expected, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + (Actual) Op(Expected), \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR((Actual) Op(Expected))), \ + __VA_ARGS__ \ + )) -// Binary +#define cr_assert_op_va_(Fail, Op, ...) \ + CR_EXPAND(cr_assert_op_( \ + Fail, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -# define cr_assert_op_(Fail, Op, Actual, Expected, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - (Actual) Op (Expected), \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR((Actual) Op (Expected))), \ - __VA_ARGS__ \ - )) +/* Unary */ -# define cr_assert_op_va_(Fail, Op, ...) \ - CR_EXPAND(cr_assert_op_( \ - Fail, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_null_op_(Fail, Op, Msg, Value, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + (Value) Op NULL, \ + dummy, \ + Msg, \ + (CR_STR(Value)), \ + __VA_ARGS__ \ + )) -// Unary +#define cr_assert_null_op_va_(Fail, Op, Msg, ...) \ + CR_EXPAND(cr_assert_null_op_( \ + Fail, \ + Op, \ + Msg, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_assert_null_op_(Fail, Op, Msg, Value, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - (Value) Op NULL, \ - dummy, \ - Msg, \ - (CR_STR(Value)), \ - __VA_ARGS__ \ - )) +/* Floating point */ -# define cr_assert_null_op_va_(Fail, Op, Msg, ...) \ - CR_EXPAND(cr_assert_null_op_( \ - Fail, \ - Op, \ - Msg, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_TAIL(__VA_ARGS__) \ - )) - -// Floating point - -# define cr_assert_float_eq_op_(Actual, Expected, Epsilon) \ +#define cr_assert_float_eq_op_(Actual, Expected, Epsilon) \ (Expected) - (Actual) <= (Epsilon) && (Actual) - (Expected) <= (Epsilon) -# define cr_assert_float_neq_op_(Actual, Expected, Epsilon) \ +#define cr_assert_float_neq_op_(Actual, Expected, Epsilon) \ (Expected) - (Actual) > (Epsilon) || (Actual) - (Expected) > (Epsilon) -# define cr_assert_float_op_(Fail, Op, Actual, Expected, Epsilon, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - Op(Actual, Expected, Epsilon), \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR(Op(Actual, Expected, Epsilon))), \ - __VA_ARGS__ \ - )) +#define cr_assert_float_op_(Fail, Op, Actual, Expected, Epsilon, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + Op(Actual, Expected, Epsilon), \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR(Op(Actual, Expected, Epsilon))), \ + __VA_ARGS__ \ + )) -# define cr_assert_float_op_va_(Fail, Op, ...) \ - CR_EXPAND(cr_assert_float_op_( \ - Fail, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ - CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ - )) +#define cr_assert_float_op_va_(Fail, Op, ...) \ + CR_EXPAND(cr_assert_float_op_( \ + Fail, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ + CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ + )) -// String +/* String */ -# define cr_assert_str_op_empty_(Fail, Op, Msg, Value, ...) \ - do { \ - const char *cr_str_value__ = (Value); \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - ((cr_str_value__) != NULL) && (cr_str_value__)[0] Op '\0', \ - dummy, \ - ((cr_str_value__) != NULL) ? Msg: CRITERION_ASSERT_MSG_IS_NULL, \ - (CR_STR(Value), cr_str_value__), \ - __VA_ARGS__ \ - )); \ +#define cr_assert_str_op_empty_(Fail, Op, Msg, Value, ...) \ + do { \ + const char *cr_str_value__ = (Value); \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + ((cr_str_value__) != NULL) && (cr_str_value__)[0] Op '\0', \ + dummy, \ + ((cr_str_value__) != NULL) ? Msg : CRITERION_ASSERT_MSG_IS_NULL, \ + (CR_STR(Value), cr_str_value__), \ + __VA_ARGS__ \ + )); \ } while (0) -# define cr_assert_str_op_empty_va_(Fail, Op, Msg, ...) \ - CR_EXPAND(cr_assert_str_op_empty_( \ - Fail, \ - Op, \ - Msg, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_TAIL(__VA_ARGS__) \ - )) +#define cr_assert_str_op_empty_va_(Fail, Op, Msg, ...) \ + CR_EXPAND(cr_assert_str_op_empty_( \ + Fail, \ + Op, \ + Msg, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_assert_str_op_(Fail, Op, Actual, Expected, ...) \ - do { \ - const char *cr_str_actual__ = (Actual); \ - const char *cr_str_expected__ = (Expected); \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - ((cr_str_actual__) != NULL) && ((cr_str_expected__) != NULL) && \ - CR_STDN strcmp((cr_str_actual__), (cr_str_expected__)) Op 0, \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE, \ - (CR_STR((Actual) Op (Expected)), cr_str_actual__, cr_str_expected__), \ - __VA_ARGS__ \ - )); \ +#define cr_assert_str_op_(Fail, Op, Actual, Expected, ...) \ + do { \ + const char *cr_str_actual__ = (Actual); \ + const char *cr_str_expected__ = (Expected); \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + ((cr_str_actual__) != NULL) && ((cr_str_expected__) != NULL) \ + && CR_STDN strcmp((cr_str_actual__), (cr_str_expected__)) Op 0, \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE, \ + (CR_STR((Actual) Op(Expected)), cr_str_actual__, cr_str_expected__), \ + __VA_ARGS__ \ + )); \ } while (0) -# define cr_assert_str_op_va_(Fail, Op, ...) \ - CR_EXPAND(cr_assert_str_op_( \ - Fail, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_str_op_va_(Fail, Op, ...) \ + CR_EXPAND(cr_assert_str_op_( \ + Fail, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -// Array +/* Array */ -# define cr_assert_mem_op_(Fail, Op, Actual, Expected, Size, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - CR_STDN memcmp((Actual), (Expected), (Size)) Op 0, \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR((Actual)[0 .. Size] Op (Expected)[0 .. Size])), \ - __VA_ARGS__ \ - )) +#define cr_assert_mem_op_(Fail, Op, Actual, Expected, Size, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + CR_STDN memcmp((Actual), (Expected), (Size)) Op 0, \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR((Actual)[0..Size] Op(Expected)[0..Size])), \ + __VA_ARGS__ \ + )) -# define cr_assert_mem_op_va_(Fail, Op, ...) \ - CR_EXPAND(cr_assert_mem_op_( \ - Fail, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ - CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ - )) +#define cr_assert_mem_op_va_(Fail, Op, ...) \ + CR_EXPAND(cr_assert_mem_op_( \ + Fail, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ + CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ + )) -// Array comparisons +/* Array comparisons */ -# ifdef __cplusplus -# define CR_ARR_COMPARE_(A, B, Size, Cmp, Result) \ +#ifdef __cplusplus +# define CR_ARR_COMPARE_(A, B, Size, Cmp, Result) \ int Result = std::lexicographical_compare((A), (A) + Size, (B), (B) + Size, Cmp) -# else -# define CR_ARR_COMPARE_(A, B, Size, Cmp, Result) \ - __typeof__(&(A)[0]) first = (A); \ - __typeof__(&(B)[0]) second = (B); \ - int Result = 0; \ - size_t i, size; \ - for (i = 0, size = (Size); !Result && i < size; ++i) \ - Result = Cmp(first + i, second + i) -# endif +#else +# define CR_ARR_COMPARE_(A, B, Size, Cmp, Result) \ + __typeof__ (&(A)[0])first = (A); \ + __typeof__ (&(B)[0])second = (B); \ + int Result = 0; \ + size_t i, size; \ + for (i = 0, size = (Size); !Result && i < size; ++i) \ + Result = Cmp(first + i, second + i) +#endif -# define cr_assert_arr_op_cmp_(Fail, Op, Actual, Expected, Size, Cmp, ...) \ - do { \ - CR_ARR_COMPARE_(Actual, Expected, Size, Cmp, order); \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - order Op 0, \ - dummy, \ - CRITERION_ASSERT_MSG_EXPR_FALSE, \ - (CR_STR((Actual)[0 .. Size] Op (Expected)[0 .. Size])), \ - __VA_ARGS__ \ - )); \ +#define cr_assert_arr_op_cmp_(Fail, Op, Actual, Expected, Size, Cmp, ...) \ + do { \ + CR_ARR_COMPARE_(Actual, Expected, Size, Cmp, order); \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + order Op 0, \ + dummy, \ + CRITERION_ASSERT_MSG_EXPR_FALSE, \ + (CR_STR((Actual)[0..Size] Op(Expected)[0..Size])), \ + __VA_ARGS__ \ + )); \ } while (0) -# define cr_assert_arr_op_cmp_va_(Fail, Op, ...) \ - CR_EXPAND(cr_assert_arr_op_cmp_( \ - Fail, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ - CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)))), \ - CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)))) \ - )) +#define cr_assert_arr_op_cmp_va_(Fail, Op, ...) \ + CR_EXPAND(cr_assert_arr_op_cmp_( \ + Fail, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ + CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)))), \ + CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)))) \ + )) -// Exceptions +/* Exceptions */ -# define cr_assert_throw_abort_(Fail, Msg, MsgArgs, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - 0, \ - dummy, \ - Msg, \ - MsgArgs, \ - CR_VA_TAIL(__VA_ARGS__) \ - )) +#define cr_assert_throw_abort_(Fail, Msg, MsgArgs, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + 0, \ + dummy, \ + Msg, \ + MsgArgs, \ + CR_VA_TAIL(__VA_ARGS__) \ + )) -# define cr_assert_throw_(Fail, Statement, Exception, ...) \ - try { \ - Statement; \ - } catch (Exception const &) { \ - } catch (...) { \ - CR_EXPAND(cr_assert_throw_abort_( \ - Fail, \ - CRITERION_ASSERT_MSG_NO_THROW, \ - (CR_STR(Statement), CR_STR(Exception)), \ - __VA_ARGS__)); \ +#define cr_assert_throw_(Fail, Statement, Exception, ...) \ + try { \ + Statement; \ + } catch (Exception const &) { \ + } catch (...) { \ + CR_EXPAND(cr_assert_throw_abort_( \ + Fail, \ + CRITERION_ASSERT_MSG_NO_THROW, \ + (CR_STR(Statement), CR_STR(Exception)), \ + __VA_ARGS__)); \ } -# define cr_assert_throw_va_(...) \ - CR_EXPAND(cr_assert_throw_( \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ - dummy, \ - CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ - )) +#define cr_assert_throw_va_(...) \ + CR_EXPAND(cr_assert_throw_( \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ + dummy, \ + CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ + )) -# define cr_assert_no_throw_(Fail, Statement, Exception, ...) \ - try { \ - Statement; \ - } catch (Exception const &) { \ - CR_EXPAND(cr_assert_throw_abort_( \ - Fail, \ - CRITERION_ASSERT_MSG_THROW, \ - (CR_STR(Statement), CR_STR(Exception)), \ - __VA_ARGS__)); \ +#define cr_assert_no_throw_(Fail, Statement, Exception, ...) \ + try { \ + Statement; \ + } catch (Exception const &) { \ + CR_EXPAND(cr_assert_throw_abort_( \ + Fail, \ + CRITERION_ASSERT_MSG_THROW, \ + (CR_STR(Statement), CR_STR(Exception)), \ + __VA_ARGS__)); \ } -# define cr_assert_no_throw_va_(...) \ - CR_EXPAND(cr_assert_no_throw_( \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ - dummy, \ - CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ - )) +#define cr_assert_no_throw_va_(...) \ + CR_EXPAND(cr_assert_no_throw_( \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_HEAD(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))), \ + dummy, \ + CR_VA_TAIL(CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))) \ + )) -# define cr_assert_any_throw_(Fail, Statement, ...) \ - try { \ - Statement; \ - CR_EXPAND(cr_assert_throw_abort_( \ - Fail, \ - CRITERION_ASSERT_MSG_ANY_THROW, \ - (CR_STR(Statement)), \ - __VA_ARGS__)); \ +#define cr_assert_any_throw_(Fail, Statement, ...) \ + try { \ + Statement; \ + CR_EXPAND(cr_assert_throw_abort_( \ + Fail, \ + CRITERION_ASSERT_MSG_ANY_THROW, \ + (CR_STR(Statement)), \ + __VA_ARGS__)); \ } catch (...) {} -# define cr_assert_any_throw_va_(...) \ - CR_EXPAND(cr_assert_any_throw_( \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - dummy, \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_any_throw_va_(...) \ + CR_EXPAND(cr_assert_any_throw_( \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + dummy, \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -# define cr_assert_none_throw_(Fail, Statement, ...) \ - try { \ - Statement; \ - } catch (...) { \ - CR_EXPAND(cr_assert_throw_abort_( \ - Fail, \ - CRITERION_ASSERT_MSG_NONE_THROW, \ - (CR_STR(Statement)), \ - __VA_ARGS__)); \ +#define cr_assert_none_throw_(Fail, Statement, ...) \ + try { \ + Statement; \ + } catch (...) { \ + CR_EXPAND(cr_assert_throw_abort_( \ + Fail, \ + CRITERION_ASSERT_MSG_NONE_THROW, \ + (CR_STR(Statement)), \ + __VA_ARGS__)); \ } -# define cr_assert_none_throw_va_(...) \ - CR_EXPAND(cr_assert_none_throw_( \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - dummy, \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_none_throw_va_(...) \ + CR_EXPAND(cr_assert_none_throw_( \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + dummy, \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -// Messages +/* Messages */ -# define CRITERION_GNUC_WARN__(Msg) \ +#define CRITERION_GNUC_WARN__(Msg) \ _Pragma(#Msg) -# define CRITERION_GNUC_WARN_(Name) CRITERION_GNUC_WARN__( \ - message \ - "The `" #Name "` macro is only available on GNU C compilers." \ - ) +#define CRITERION_GNUC_WARN_(Name) \ + CRITERION_GNUC_WARN__( \ + message \ + "The `" #Name "` macro is only available on GNU C compilers." \ + ) -// Actual implementation +/* Actual implementation */ -# undef cr_skip_test -# define cr_skip_test(...) CR_EXPAND(cr_skip(__VA_ARGS__)) -# undef cr_assert_fail -# define cr_assert_fail(...) CR_EXPAND(cr_fail(CR_FAIL_ABORT_, __VA_ARGS__)) -# undef cr_expect_fail -# define cr_expect_fail(...) CR_EXPAND(cr_fail(CR_FAIL_CONTINUES_, __VA_ARGS__)) -# undef cr_assert -# define cr_assert(...) CR_EXPAND(cr_assert_(__VA_ARGS__)) -# undef cr_expect -# define cr_expect(...) CR_EXPAND(cr_expect_(__VA_ARGS__)) -# undef cr_assert_not -# define cr_assert_not(...) CR_EXPAND(cr_assert_not_(__VA_ARGS__)) -# undef cr_expect_not -# define cr_expect_not(...) CR_EXPAND(cr_expect_not_(__VA_ARGS__)) -# undef cr_assert_eq -# define cr_assert_eq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) -# undef cr_expect_eq -# define cr_expect_eq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) -# undef cr_assert_neq -# define cr_assert_neq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) -# undef cr_expect_neq -# define cr_expect_neq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) -# undef cr_assert_lt -# define cr_assert_lt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, <, __VA_ARGS__)) -# undef cr_expect_lt -# define cr_expect_lt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, <, __VA_ARGS__)) -# undef cr_assert_leq -# define cr_assert_leq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, <=, __VA_ARGS__)) -# undef cr_expect_leq -# define cr_expect_leq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, <=, __VA_ARGS__)) -# undef cr_assert_gt -# define cr_assert_gt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, >, __VA_ARGS__)) -# undef cr_expect_gt -# define cr_expect_gt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, >, __VA_ARGS__)) -# undef cr_assert_geq -# define cr_assert_geq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, >=, __VA_ARGS__)) -# undef cr_expect_geq -# define cr_expect_geq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, >=, __VA_ARGS__)) -# undef cr_assert_null -# define cr_assert_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_ABORT_, ==, CRITERION_ASSERT_MSG_IS_NOT_NULL, __VA_ARGS__)) -# undef cr_expect_null -# define cr_expect_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_CONTINUES_, ==, CRITERION_ASSERT_MSG_IS_NOT_NULL, __VA_ARGS__)) -# undef cr_assert_not_null -# define cr_assert_not_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_ABORT_, !=, CRITERION_ASSERT_MSG_IS_NULL, __VA_ARGS__)) -# undef cr_expect_not_null -# define cr_expect_not_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_CONTINUES_, !=, CRITERION_ASSERT_MSG_IS_NULL, __VA_ARGS__)) -# undef cr_assert_float_eq -# define cr_assert_float_eq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_ABORT_, cr_assert_float_eq_op_, __VA_ARGS__)) -# undef cr_expect_float_eq -# define cr_expect_float_eq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_CONTINUES_, cr_assert_float_eq_op_, __VA_ARGS__)) -# undef cr_assert_float_neq -# define cr_assert_float_neq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_ABORT_, cr_assert_float_neq_op_, __VA_ARGS__)) -# undef cr_expect_float_neq -# define cr_expect_float_neq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_CONTINUES_, cr_assert_float_neq_op_, __VA_ARGS__)) -# undef cr_assert_str_empty -# define cr_assert_str_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_ABORT_, ==, CRITERION_ASSERT_MSG_IS_NOT_EMPTY, __VA_ARGS__)) -# undef cr_expect_str_empty -# define cr_expect_str_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_CONTINUES_, ==, CRITERION_ASSERT_MSG_IS_NOT_EMPTY, __VA_ARGS__)) -# undef cr_assert_str_not_empty -# define cr_assert_str_not_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_ABORT_, !=, CRITERION_ASSERT_MSG_IS_EMPTY, __VA_ARGS__)) -# undef cr_expect_str_not_empty -# define cr_expect_str_not_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_CONTINUES_, !=, CRITERION_ASSERT_MSG_IS_EMPTY, __VA_ARGS__)) -# undef cr_assert_str_eq -# define cr_assert_str_eq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) -# undef cr_expect_str_eq -# define cr_expect_str_eq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) -# undef cr_assert_str_neq -# define cr_assert_str_neq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) -# undef cr_expect_str_neq -# define cr_expect_str_neq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) -# undef cr_assert_str_lt -# define cr_assert_str_lt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, <, __VA_ARGS__)) -# undef cr_expect_str_lt -# define cr_expect_str_lt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, <, __VA_ARGS__)) -# undef cr_assert_str_leq -# define cr_assert_str_leq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, <=, __VA_ARGS__)) -# undef cr_expect_str_leq -# define cr_expect_str_leq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, <=, __VA_ARGS__)) -# undef cr_assert_str_gt -# define cr_assert_str_gt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, >, __VA_ARGS__)) -# undef cr_expect_str_gt -# define cr_expect_str_gt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, >, __VA_ARGS__)) -# undef cr_assert_str_geq -# define cr_assert_str_geq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, >=, __VA_ARGS__)) -# undef cr_expect_str_geq -# define cr_expect_str_geq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, >=, __VA_ARGS__)) -# undef cr_assert_arr_eq -# define cr_assert_arr_eq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) -# undef cr_expect_arr_eq -# define cr_expect_arr_eq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) -# undef cr_assert_arr_neq -# define cr_assert_arr_neq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) -# undef cr_expect_arr_neq -# define cr_expect_arr_neq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) +#undef cr_skip_test +#define cr_skip_test(...) CR_EXPAND(cr_skip(__VA_ARGS__)) +#undef cr_assert_fail +#define cr_assert_fail(...) CR_EXPAND(cr_fail(CR_FAIL_ABORT_, __VA_ARGS__)) +#undef cr_expect_fail +#define cr_expect_fail(...) CR_EXPAND(cr_fail(CR_FAIL_CONTINUES_, __VA_ARGS__)) +#undef cr_assert +#define cr_assert(...) CR_EXPAND(cr_assert_(__VA_ARGS__)) +#undef cr_expect +#define cr_expect(...) CR_EXPAND(cr_expect_(__VA_ARGS__)) +#undef cr_assert_not +#define cr_assert_not(...) CR_EXPAND(cr_assert_not_(__VA_ARGS__)) +#undef cr_expect_not +#define cr_expect_not(...) CR_EXPAND(cr_expect_not_(__VA_ARGS__)) +#undef cr_assert_eq +#define cr_assert_eq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) +#undef cr_expect_eq +#define cr_expect_eq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) +#undef cr_assert_neq +#define cr_assert_neq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) +#undef cr_expect_neq +#define cr_expect_neq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) +#undef cr_assert_lt +#define cr_assert_lt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, <, __VA_ARGS__)) +#undef cr_expect_lt +#define cr_expect_lt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, <, __VA_ARGS__)) +#undef cr_assert_leq +#define cr_assert_leq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, <=, __VA_ARGS__)) +#undef cr_expect_leq +#define cr_expect_leq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, <=, __VA_ARGS__)) +#undef cr_assert_gt +#define cr_assert_gt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, >, __VA_ARGS__)) +#undef cr_expect_gt +#define cr_expect_gt(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, >, __VA_ARGS__)) +#undef cr_assert_geq +#define cr_assert_geq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_ABORT_, >=, __VA_ARGS__)) +#undef cr_expect_geq +#define cr_expect_geq(...) CR_EXPAND(cr_assert_op_va_(CR_FAIL_CONTINUES_, >=, __VA_ARGS__)) +#undef cr_assert_null +#define cr_assert_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_ABORT_, ==, CRITERION_ASSERT_MSG_IS_NOT_NULL, __VA_ARGS__)) +#undef cr_expect_null +#define cr_expect_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_CONTINUES_, ==, CRITERION_ASSERT_MSG_IS_NOT_NULL, __VA_ARGS__)) +#undef cr_assert_not_null +#define cr_assert_not_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_ABORT_, !=, CRITERION_ASSERT_MSG_IS_NULL, __VA_ARGS__)) +#undef cr_expect_not_null +#define cr_expect_not_null(...) CR_EXPAND(cr_assert_null_op_va_(CR_FAIL_CONTINUES_, !=, CRITERION_ASSERT_MSG_IS_NULL, __VA_ARGS__)) +#undef cr_assert_float_eq +#define cr_assert_float_eq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_ABORT_, cr_assert_float_eq_op_, __VA_ARGS__)) +#undef cr_expect_float_eq +#define cr_expect_float_eq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_CONTINUES_, cr_assert_float_eq_op_, __VA_ARGS__)) +#undef cr_assert_float_neq +#define cr_assert_float_neq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_ABORT_, cr_assert_float_neq_op_, __VA_ARGS__)) +#undef cr_expect_float_neq +#define cr_expect_float_neq(...) CR_EXPAND(cr_assert_float_op_va_(CR_FAIL_CONTINUES_, cr_assert_float_neq_op_, __VA_ARGS__)) +#undef cr_assert_str_empty +#define cr_assert_str_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_ABORT_, ==, CRITERION_ASSERT_MSG_IS_NOT_EMPTY, __VA_ARGS__)) +#undef cr_expect_str_empty +#define cr_expect_str_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_CONTINUES_, ==, CRITERION_ASSERT_MSG_IS_NOT_EMPTY, __VA_ARGS__)) +#undef cr_assert_str_not_empty +#define cr_assert_str_not_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_ABORT_, !=, CRITERION_ASSERT_MSG_IS_EMPTY, __VA_ARGS__)) +#undef cr_expect_str_not_empty +#define cr_expect_str_not_empty(...) CR_EXPAND(cr_assert_str_op_empty_va_(CR_FAIL_CONTINUES_, !=, CRITERION_ASSERT_MSG_IS_EMPTY, __VA_ARGS__)) +#undef cr_assert_str_eq +#define cr_assert_str_eq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) +#undef cr_expect_str_eq +#define cr_expect_str_eq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) +#undef cr_assert_str_neq +#define cr_assert_str_neq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) +#undef cr_expect_str_neq +#define cr_expect_str_neq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) +#undef cr_assert_str_lt +#define cr_assert_str_lt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, <, __VA_ARGS__)) +#undef cr_expect_str_lt +#define cr_expect_str_lt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, <, __VA_ARGS__)) +#undef cr_assert_str_leq +#define cr_assert_str_leq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, <=, __VA_ARGS__)) +#undef cr_expect_str_leq +#define cr_expect_str_leq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, <=, __VA_ARGS__)) +#undef cr_assert_str_gt +#define cr_assert_str_gt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, >, __VA_ARGS__)) +#undef cr_expect_str_gt +#define cr_expect_str_gt(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, >, __VA_ARGS__)) +#undef cr_assert_str_geq +#define cr_assert_str_geq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_ABORT_, >=, __VA_ARGS__)) +#undef cr_expect_str_geq +#define cr_expect_str_geq(...) CR_EXPAND(cr_assert_str_op_va_(CR_FAIL_CONTINUES_, >=, __VA_ARGS__)) +#undef cr_assert_arr_eq +#define cr_assert_arr_eq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) +#undef cr_expect_arr_eq +#define cr_expect_arr_eq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) +#undef cr_assert_arr_neq +#define cr_assert_arr_neq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) +#undef cr_expect_arr_neq +#define cr_expect_arr_neq(...) CR_EXPAND(cr_assert_mem_op_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) -# if defined(__GNUC__) || defined(__clang__) || defined(__cplusplus) +#if defined (__GNUC__) || defined (__clang__) || defined (__cplusplus) -# undef cr_assert_arr_eq_cmp -# define cr_assert_arr_eq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) -# undef cr_expect_arr_eq_cmp -# define cr_expect_arr_eq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) -# undef cr_assert_arr_neq_cmp -# define cr_assert_arr_neq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) -# undef cr_expect_arr_neq_cmp -# define cr_expect_arr_neq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) -# undef cr_assert_arr_lt_cmp -# define cr_assert_arr_lt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, <, __VA_ARGS__)) -# undef cr_expect_arr_lt_cmp -# define cr_expect_arr_lt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, <, __VA_ARGS__)) -# undef cr_assert_arr_leq_cmp -# define cr_assert_arr_leq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, <=, __VA_ARGS__)) -# undef cr_expect_arr_leq_cmp -# define cr_expect_arr_leq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, <=, __VA_ARGS__)) -# undef cr_assert_arr_gt_cmp -# define cr_assert_arr_gt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, >, __VA_ARGS__)) -# undef cr_expect_arr_gt_cmp -# define cr_expect_arr_gt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, >, __VA_ARGS__)) -# undef cr_assert_arr_geq_cmp -# define cr_assert_arr_geq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, >=, __VA_ARGS__)) -# undef cr_expect_arr_geq_cmp -# define cr_expect_arr_geq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, >=, __VA_ARGS__)) +# undef cr_assert_arr_eq_cmp +# define cr_assert_arr_eq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, ==, __VA_ARGS__)) +# undef cr_expect_arr_eq_cmp +# define cr_expect_arr_eq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, ==, __VA_ARGS__)) +# undef cr_assert_arr_neq_cmp +# define cr_assert_arr_neq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, !=, __VA_ARGS__)) +# undef cr_expect_arr_neq_cmp +# define cr_expect_arr_neq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, !=, __VA_ARGS__)) +# undef cr_assert_arr_lt_cmp +# define cr_assert_arr_lt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, <, __VA_ARGS__)) +# undef cr_expect_arr_lt_cmp +# define cr_expect_arr_lt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, <, __VA_ARGS__)) +# undef cr_assert_arr_leq_cmp +# define cr_assert_arr_leq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, <=, __VA_ARGS__)) +# undef cr_expect_arr_leq_cmp +# define cr_expect_arr_leq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, <=, __VA_ARGS__)) +# undef cr_assert_arr_gt_cmp +# define cr_assert_arr_gt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, >, __VA_ARGS__)) +# undef cr_expect_arr_gt_cmp +# define cr_expect_arr_gt_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, >, __VA_ARGS__)) +# undef cr_assert_arr_geq_cmp +# define cr_assert_arr_geq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_ABORT_, >=, __VA_ARGS__)) +# undef cr_expect_arr_geq_cmp +# define cr_expect_arr_geq_cmp(...) CR_EXPAND(cr_assert_arr_op_cmp_va_(CR_FAIL_CONTINUES_, >=, __VA_ARGS__)) -# else +#else -# undef cr_assert_arr_eq_cmp -# define cr_assert_arr_eq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_eq_cmp) CR_NOOP -# undef cr_expect_arr_eq_cmp -# define cr_expect_arr_eq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_eq_cmp) CR_NOOP -# undef cr_assert_arr_neq_cmp -# define cr_assert_arr_neq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_neq_cmp) CR_NOOP -# undef cr_expect_arr_neq_cmp -# define cr_expect_arr_neq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_neq_cmp) CR_NOOP -# undef cr_assert_arr_lt_cmp -# define cr_assert_arr_lt_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_lt_cmp) CR_NOOP -# undef cr_expect_arr_lt_cmp -# define cr_expect_arr_lt_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_lt_cmp) CR_NOOP -# undef cr_assert_arr_leq_cmp -# define cr_assert_arr_leq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_leq_cmp) CR_NOOP -# undef cr_expect_arr_leq_cmp -# define cr_expect_arr_leq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_leq_cmp) CR_NOOP -# undef cr_assert_arr_gt_cmp -# define cr_assert_arr_gt_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_gt_cmp) CR_NOOP -# undef cr_expect_arr_gt_cmp -# define cr_expect_arr_gt_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_gt_cmp) CR_NOOP -# undef cr_assert_arr_geq_cmp -# define cr_assert_arr_geq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_geq_cmp) CR_NOOP -# undef cr_expect_arr_geq_cmp -# define cr_expect_arr_geq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_geq_cmp) CR_NOOP +# undef cr_assert_arr_eq_cmp +# define cr_assert_arr_eq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_eq_cmp) CR_NOOP +# undef cr_expect_arr_eq_cmp +# define cr_expect_arr_eq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_eq_cmp) CR_NOOP +# undef cr_assert_arr_neq_cmp +# define cr_assert_arr_neq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_neq_cmp) CR_NOOP +# undef cr_expect_arr_neq_cmp +# define cr_expect_arr_neq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_neq_cmp) CR_NOOP +# undef cr_assert_arr_lt_cmp +# define cr_assert_arr_lt_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_lt_cmp) CR_NOOP +# undef cr_expect_arr_lt_cmp +# define cr_expect_arr_lt_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_lt_cmp) CR_NOOP +# undef cr_assert_arr_leq_cmp +# define cr_assert_arr_leq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_leq_cmp) CR_NOOP +# undef cr_expect_arr_leq_cmp +# define cr_expect_arr_leq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_leq_cmp) CR_NOOP +# undef cr_assert_arr_gt_cmp +# define cr_assert_arr_gt_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_gt_cmp) CR_NOOP +# undef cr_expect_arr_gt_cmp +# define cr_expect_arr_gt_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_gt_cmp) CR_NOOP +# undef cr_assert_arr_geq_cmp +# define cr_assert_arr_geq_cmp(...) CRITERION_GNUC_WARN_(cr_assert_arr_geq_cmp) CR_NOOP +# undef cr_expect_arr_geq_cmp +# define cr_expect_arr_geq_cmp(...) CRITERION_GNUC_WARN_(cr_expect_arr_geq_cmp) CR_NOOP -# endif +#endif -# undef cr_assert_throw -# define cr_assert_throw(...) CR_EXPAND(cr_assert_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) -# undef cr_expect_throw -# define cr_expect_throw(...) CR_EXPAND(cr_assert_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) -# undef cr_assert_no_throw -# define cr_assert_no_throw(...) CR_EXPAND(cr_assert_no_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) -# undef cr_expect_no_throw -# define cr_expect_no_throw(...) CR_EXPAND(cr_assert_no_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) -# undef cr_assert_any_throw -# define cr_assert_any_throw(...) CR_EXPAND(cr_assert_any_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) -# undef cr_expect_any_throw -# define cr_expect_any_throw(...) CR_EXPAND(cr_assert_any_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) -# undef cr_assert_none_throw -# define cr_assert_none_throw(...) CR_EXPAND(cr_assert_none_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) -# undef cr_expect_none_throw -# define cr_expect_none_throw(...) CR_EXPAND(cr_assert_none_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) +#undef cr_assert_throw +#define cr_assert_throw(...) CR_EXPAND(cr_assert_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) +#undef cr_expect_throw +#define cr_expect_throw(...) CR_EXPAND(cr_assert_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) +#undef cr_assert_no_throw +#define cr_assert_no_throw(...) CR_EXPAND(cr_assert_no_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) +#undef cr_expect_no_throw +#define cr_expect_no_throw(...) CR_EXPAND(cr_assert_no_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) +#undef cr_assert_any_throw +#define cr_assert_any_throw(...) CR_EXPAND(cr_assert_any_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) +#undef cr_expect_any_throw +#define cr_expect_any_throw(...) CR_EXPAND(cr_assert_any_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) +#undef cr_assert_none_throw +#define cr_assert_none_throw(...) CR_EXPAND(cr_assert_none_throw_va_(CR_FAIL_ABORT_, __VA_ARGS__)) +#undef cr_expect_none_throw +#define cr_expect_none_throw(...) CR_EXPAND(cr_assert_none_throw_va_(CR_FAIL_CONTINUES_, __VA_ARGS__)) #endif /* !CRITERION_INTERNAL_ASSERT_H_ */ diff --git a/include/criterion/internal/common.h b/include/criterion/internal/common.h index 5c573f3..fa27d88 100644 --- a/include/criterion/internal/common.h +++ b/include/criterion/internal/common.h @@ -22,118 +22,118 @@ * THE SOFTWARE. */ #ifndef CRITERION_COMMON_H_ -# define CRITERION_COMMON_H_ +#define CRITERION_COMMON_H_ -# if defined(_MSC_VER) -# if _MSC_VER < 1900 -# error \ - Your version of MSVC++ is too old, please compile your tests using \ - a c99 compiler, like MinGW or MSVC 14.0+ (Included in visual studio \ - 2015) -# endif +#if defined (_MSC_VER) +# if _MSC_VER < 1900 +# error \ + Your version of MSVC++ is too old, please compile your tests using \ + a c99 compiler, like MinGW or MSVC 14.0+ (Included in visual studio \ + 2015) # endif +#endif -# ifndef CR_IS_MSVC -# ifdef _MSC_VER -# define CR_IS_MSVC _MSC_VER -# else -# define CR_IS_MSVC 0 -# endif -# endif - -# ifdef __cplusplus -# ifdef __GNUC__ -# define CR_ATTRIBUTE(Arg) __attribute__((Arg)) -# else -# define CR_ATTRIBUTE(Arg) [[gnu::Arg]] -# endif -# define CR_BEGIN_C_API extern "C" { -# define CR_END_C_API } +#ifndef CR_IS_MSVC +# ifdef _MSC_VER +# define CR_IS_MSVC _MSC_VER # else -# define CR_ATTRIBUTE(Arg) __attribute__((Arg)) -# define CR_BEGIN_C_API -# define CR_END_C_API +# define CR_IS_MSVC 0 # endif +#endif -# ifdef __APPLE__ -# define CR_SECTION_START_SUFFIX(Name) __asm("section$start$__DATA$" Name) -# define CR_SECTION_END_SUFFIX(Name) __asm("section$end$__DATA$" Name) -# define CR_SECTION_(Name) CR_ATTRIBUTE(section("__DATA," Name)) -# define CR_SECTION_SUFFIX_ -# elif CR_IS_MSVC -# define CR_SECTION_START_SUFFIX(Name) -# define CR_SECTION_END_SUFFIX(Name) -# define CR_SECTION_(Name) \ - __pragma(data_seg(push)) \ - __pragma(section(Name, read)) \ +#ifdef __cplusplus +# ifdef __GNUC__ +# define CR_ATTRIBUTE(Arg) __attribute__((Arg)) +# else +# define CR_ATTRIBUTE(Arg) [[gnu::Arg]] +# endif +# define CR_BEGIN_C_API extern "C" { +# define CR_END_C_API } +#else +# define CR_ATTRIBUTE(Arg) __attribute__((Arg)) +# define CR_BEGIN_C_API +# define CR_END_C_API +#endif + +#ifdef __APPLE__ +# define CR_SECTION_START_SUFFIX(Name) __asm("section$start$__DATA$" Name) +# define CR_SECTION_END_SUFFIX(Name) __asm("section$end$__DATA$" Name) +# define CR_SECTION_(Name) CR_ATTRIBUTE(section("__DATA," Name)) +# define CR_SECTION_SUFFIX_ +#elif CR_IS_MSVC +# define CR_SECTION_START_SUFFIX(Name) +# define CR_SECTION_END_SUFFIX(Name) +# define CR_SECTION_(Name) \ + __pragma(data_seg(push)) \ + __pragma(section(Name, read)) \ __declspec(allocate(Name)) -# define CR_SECTION_SUFFIX_ \ +# define CR_SECTION_SUFFIX_ \ __pragma(data_seg(pop)) -# else -# define CR_SECTION_START_SUFFIX(Name) -# define CR_SECTION_END_SUFFIX(Name) -# define CR_SECTION_(Name) CR_ATTRIBUTE(section(Name)) -# define CR_SECTION_SUFFIX_ -# endif +#else +# define CR_SECTION_START_SUFFIX(Name) +# define CR_SECTION_END_SUFFIX(Name) +# define CR_SECTION_(Name) CR_ATTRIBUTE(section(Name)) +# define CR_SECTION_SUFFIX_ +#endif -# define CR_MAKE_IDENTIFIER_(Prefix, Id) CR_MAKE_IDENTIFIER__(Prefix, Id) -# define CR_MAKE_IDENTIFIER__(Prefix, Id) Prefix ## _ ## Id +#define CR_MAKE_IDENTIFIER_(Prefix, Id) CR_MAKE_IDENTIFIER__(Prefix, Id) +#define CR_MAKE_IDENTIFIER__(Prefix, Id) Prefix ## _ ## Id -# ifdef __GNUC__ -# define CR_UNUSED CR_ATTRIBUTE(unused) -# define CR_NORETURN CR_ATTRIBUTE(noreturn) -# define CR_INLINE CR_ATTRIBUTE(always_inline) inline -# elif CR_IS_MSVC -# define CR_UNUSED __pragma(warning(suppress:4100)) -# define CR_NORETURN __declspec(noreturn) -# define CR_INLINE __forceinline -# else -# define CR_UNUSED -# define CR_NORETURN -# define CR_INLINE inline -# endif +#ifdef __GNUC__ +# define CR_UNUSED CR_ATTRIBUTE(unused) +# define CR_NORETURN CR_ATTRIBUTE(noreturn) +# define CR_INLINE CR_ATTRIBUTE(always_inline) inline +#elif CR_IS_MSVC +# define CR_UNUSED __pragma(warning(suppress: 4100)) +# define CR_NORETURN __declspec(noreturn) +# define CR_INLINE __forceinline +#else +# define CR_UNUSED +# define CR_NORETURN +# define CR_INLINE inline +#endif -# ifdef _WIN32 -# define CR_SIZE_T_FORMAT "%Iu" -# else -# define CR_SIZE_T_FORMAT "%zu" -# endif +#ifdef _WIN32 +# define CR_SIZE_T_FORMAT "%Iu" +#else +# define CR_SIZE_T_FORMAT "%zu" +#endif -# ifdef __GNUC__ -# define CR_FORMAT(Archetype, Index, Ftc) CR_ATTRIBUTE(format(Archetype, Index, Ftc)) -# else -# define CR_FORMAT(Archetype, Index, Ftc) -# endif +#ifdef __GNUC__ +# define CR_FORMAT(Archetype, Index, Ftc) CR_ATTRIBUTE(format(Archetype, Index, Ftc)) +#else +# define CR_FORMAT(Archetype, Index, Ftc) +#endif -# if defined _WIN32 || defined __CYGWIN__ -# ifdef CRITERION_BUILDING_DLL -# ifdef __GNUC__ -# define CR_API CR_ATTRIBUTE(dllexport) -# else -# define CR_API __declspec(dllexport) -# endif +#if defined _WIN32 || defined __CYGWIN__ +# ifdef CRITERION_BUILDING_DLL +# ifdef __GNUC__ +# define CR_API CR_ATTRIBUTE(dllexport) # else -# ifdef __GNUC__ -# define CR_API CR_ATTRIBUTE(dllimport) -# else -# define CR_API __declspec(dllimport) -# endif +# define CR_API __declspec(dllexport) # endif +# else +# ifdef __GNUC__ +# define CR_API CR_ATTRIBUTE(dllimport) +# else +# define CR_API __declspec(dllimport) +# endif +# endif +# define CR_LOCAL +#else +# if __GNUC__ >= 4 +# define CR_API CR_ATTRIBUTE(visibility("default")) +# define CR_LOCAL CR_ATTRIBUTE(visibility("hidden")) +# else +# define CR_API # define CR_LOCAL -# else -# if __GNUC__ >= 4 -# define CR_API CR_ATTRIBUTE(visibility("default")) -# define CR_LOCAL CR_ATTRIBUTE(visibility("hidden")) -# else -# define CR_API -# define CR_LOCAL -# endif # endif +#endif -# ifdef __cplusplus -# define CR_STDN std:: -# else -# define CR_STDN -# endif +#ifdef __cplusplus +# define CR_STDN std:: +#else +# define CR_STDN +#endif #endif /* !CRITERION_COMMON_H_ */ diff --git a/include/criterion/internal/deprecation.h b/include/criterion/internal/deprecation.h index 0af6204..ffc4682 100644 --- a/include/criterion/internal/deprecation.h +++ b/include/criterion/internal/deprecation.h @@ -22,20 +22,20 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_DEPRECATION_H_ -# define CRITERION_INTERNAL_DEPRECATION_H_ +#define CRITERION_INTERNAL_DEPRECATION_H_ -# define CR_DEPRECATED(Msg) CR_DEPRECATED_(message (Msg)) +#define CR_DEPRECATED(Msg) CR_DEPRECATED_(message(Msg)) -# ifdef _MSC_VER -# define CR_DEPRECATED_(Msg) __pragma(Msg) -# else -# define CR_DEPRECATED_(Msg) _Pragma(#Msg) -# endif +#ifdef _MSC_VER +# define CR_DEPRECATED_(Msg) __pragma(Msg) +#else +# define CR_DEPRECATED_(Msg) _Pragma(#Msg) +#endif -# ifdef __GNUC__ -# define CR_DEPRECATED_MEMBER(Member) Member __attribute__((deprecated)) -# else -# define CR_DEPRECATED_MEMBER(Member) Member -# endif +#ifdef __GNUC__ +# define CR_DEPRECATED_MEMBER(Member) Member __attribute__((deprecated)) +#else +# define CR_DEPRECATED_MEMBER(Member) Member +#endif #endif /* !CRITERION_INTERNAL_DEPRECATION_H_ */ diff --git a/include/criterion/internal/designated-initializer-compat.h b/include/criterion/internal/designated-initializer-compat.h index aa1e1ba..77f803e 100644 --- a/include/criterion/internal/designated-initializer-compat.h +++ b/include/criterion/internal/designated-initializer-compat.h @@ -22,104 +22,106 @@ * THE SOFTWARE. */ #ifndef CRITERION_DESIGNATED_INITIALIZER_COMPAT_HH_ -# define CRITERION_DESIGNATED_INITIALIZER_COMPAT_HH_ +#define CRITERION_DESIGNATED_INITIALIZER_COMPAT_HH_ -# include "common.h" +#include "common.h" -# define CRITERION_ARG_LENGTH(...) CR_EXPAND(CRITERION_ARG_LENGTH_(__VA_ARGS__,\ - 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45,\ - 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26,\ - 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6,\ - 5, 4, 3, 2, 1, 0)) -# define CRITERION_ARG_LENGTH_(_63, _62, _61, _60, _59, _58, _57, _56, _55, _54, _53, \ - _52, _51, _50, _49, _48, _47, _46, _45, _44, _43, _42, _41, _40, _39, _38, \ - _37, _36, _35, _34, _33, _32, _31, _30, _29, _28, _27, _26, _25, _24, _23, \ - _22, _21, _20, _19, _18, _17, _16, _15, _14, _13, _12, _11, _10, _9, _8, \ - _7, _6, _5, _4, _3, _2, _1, count, ...) count +#define CRITERION_ARG_LENGTH(...) \ + CR_EXPAND(CRITERION_ARG_LENGTH_(__VA_ARGS__, \ + 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, \ + 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, \ + 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, \ + 5, 4, 3, 2, 1, 0)) +#define CRITERION_ARG_LENGTH_(_63, _62, _61, _60, _59, _58, _57, _56, _55, _54, _53, \ + _52, _51, _50, _49, _48, _47, _46, _45, _44, _43, _42, _41, _40, _39, _38, \ + _37, _36, _35, _34, _33, _32, _31, _30, _29, _28, _27, _26, _25, _24, _23, \ + _22, _21, _20, _19, _18, _17, _16, _15, _14, _13, _12, _11, _10, _9, _8, \ + _7, _6, _5, _4, _3, _2, _1, count, ...) count -# define CRITERION_APPLY_1(Macro, ...) -# define CRITERION_APPLY_2(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_1(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_3(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_2(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_4(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_3(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_5(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_4(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_6(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_5(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_7(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_6(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_8(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_7(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_9(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_8(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_10(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_9(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_11(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_10(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_12(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_11(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_13(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_12(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_14(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_13(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_15(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_14(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_16(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_15(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_17(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_16(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_18(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_17(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_19(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_18(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_20(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_19(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_21(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_20(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_22(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_21(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_23(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_22(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_24(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_23(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_25(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_24(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_26(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_25(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_27(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_26(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_28(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_27(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_29(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_28(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_30(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_29(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_31(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_30(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_32(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_31(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_33(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_32(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_34(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_33(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_35(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_34(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_36(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_35(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_37(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_36(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_38(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_37(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_39(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_38(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_40(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_39(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_41(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_40(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_42(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_41(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_43(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_42(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_44(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_43(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_45(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_44(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_46(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_45(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_47(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_46(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_48(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_47(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_49(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_48(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_50(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_49(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_51(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_50(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_52(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_51(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_53(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_52(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_54(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_53(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_55(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_54(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_56(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_55(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_57(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_56(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_58(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_57(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_59(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_58(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_60(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_59(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_61(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_60(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_62(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_61(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_63(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_62(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_64(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_63(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY_65(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_64(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_1(Macro, ...) +#define CRITERION_APPLY_2(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_1(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_3(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_2(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_4(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_3(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_5(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_4(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_6(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_5(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_7(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_6(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_8(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_7(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_9(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_8(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_10(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_9(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_11(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_10(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_12(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_11(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_13(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_12(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_14(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_13(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_15(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_14(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_16(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_15(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_17(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_16(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_18(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_17(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_19(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_18(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_20(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_19(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_21(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_20(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_22(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_21(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_23(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_22(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_24(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_23(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_25(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_24(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_26(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_25(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_27(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_26(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_28(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_27(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_29(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_28(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_30(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_29(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_31(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_30(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_32(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_31(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_33(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_32(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_34(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_33(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_35(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_34(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_36(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_35(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_37(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_36(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_38(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_37(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_39(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_38(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_40(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_39(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_41(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_40(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_42(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_41(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_43(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_42(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_44(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_43(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_45(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_44(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_46(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_45(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_47(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_46(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_48(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_47(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_49(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_48(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_50(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_49(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_51(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_50(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_52(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_51(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_53(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_52(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_54(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_53(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_55(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_54(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_56(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_55(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_57(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_56(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_58(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_57(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_59(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_58(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_60(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_59(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_61(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_60(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_62(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_61(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_63(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_62(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_64(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_63(Macro, Prefix, __VA_ARGS__)) +#define CRITERION_APPLY_65(Macro, Prefix, Head, ...) Macro(Prefix, Head) CR_EXPAND(CRITERION_APPLY_64(Macro, Prefix, __VA_ARGS__)) -# define CRITERION_APPLY__(Macro, Prefix, n, ...) CR_EXPAND(CRITERION_APPLY_##n(Macro, Prefix, __VA_ARGS__,)) -# define CRITERION_APPLY_(Macro, n, Prefix, ...) CR_EXPAND(CRITERION_APPLY__(Macro, Prefix, n, __VA_ARGS__)) -# define CRITERION_APPLY(Macro, ...) CR_EXPAND(CRITERION_APPLY_(Macro, CRITERION_ARG_LENGTH(__VA_ARGS__), __VA_ARGS__)) +#define CRITERION_APPLY__(Macro, Prefix, n, ...) CR_EXPAND(CRITERION_APPLY_ ## n(Macro, Prefix, __VA_ARGS__, )) +#define CRITERION_APPLY_(Macro, n, Prefix, ...) CR_EXPAND(CRITERION_APPLY__(Macro, Prefix, n, __VA_ARGS__)) +#define CRITERION_APPLY(Macro, ...) CR_EXPAND(CRITERION_APPLY_(Macro, CRITERION_ARG_LENGTH(__VA_ARGS__), __VA_ARGS__)) -# define CRITERION_ADD_PREFIX_ONCE(Prefix, Field) Prefix Field; -# define CRITERION_ADD_PREFIX(...) \ +#define CRITERION_ADD_PREFIX_ONCE(Prefix, Field) Prefix Field; +#define CRITERION_ADD_PREFIX(...) \ CR_EXPAND(CRITERION_APPLY(CRITERION_ADD_PREFIX_ONCE, __VA_ARGS__)) -# ifdef __cplusplus -# define CRITERION_MAKE_STRUCT(Type, ...) []() -> Type { \ - Type t; \ - std::memset(&t, 0, sizeof (t)); \ - CR_EXPAND(CRITERION_ADD_PREFIX(t, __VA_ARGS__)) \ - return t; \ - }() -# else -# define CRITERION_MAKE_STRUCT(Type, ...) { __VA_ARGS__ } -# endif +#ifdef __cplusplus +# define CRITERION_MAKE_STRUCT(Type, ...) \ + []() -> Type { \ + Type t; \ + std::memset(&t, 0, sizeof (t)); \ + CR_EXPAND(CRITERION_ADD_PREFIX(t, __VA_ARGS__)) \ + return t; \ + } () +#else +# define CRITERION_MAKE_STRUCT(Type, ...) { __VA_ARGS__ } +#endif #endif /* !CRITERION_DESIGNATED_INITIALIZER_COMPAT_HH_ */ diff --git a/include/criterion/internal/hooks.h b/include/criterion/internal/hooks.h index 995b715..5b0d317 100644 --- a/include/criterion/internal/hooks.h +++ b/include/criterion/internal/hooks.h @@ -22,63 +22,62 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_HOOKS_H_ -# define CRITERION_INTERNAL_HOOKS_H_ +#define CRITERION_INTERNAL_HOOKS_H_ -# include "common.h" -# include "../types.h" +#include "common.h" +#include "../types.h" -# define CR_HOOK_IDENTIFIER_(Suffix) CR_HOOK_IDENTIFIER__(__LINE__, Suffix) -# define CR_HOOK_IDENTIFIER__(Line, Suffix) CR_HOOK_IDENTIFIER___(Line, Suffix) -# define CR_HOOK_IDENTIFIER___(Line, Suffix) hook_l ## Line ## _ ## Suffix +#define CR_HOOK_IDENTIFIER_(Suffix) CR_HOOK_IDENTIFIER__(__LINE__, Suffix) +#define CR_HOOK_IDENTIFIER__(Line, Suffix) CR_HOOK_IDENTIFIER___(Line, Suffix) +#define CR_HOOK_IDENTIFIER___(Line, Suffix) hook_l ## Line ## _ ## Suffix -# ifdef __cplusplus -# define CR_HOOK_PROTOTYPE_ \ +#ifdef __cplusplus +# define CR_HOOK_PROTOTYPE_ \ extern "C" void CR_HOOK_IDENTIFIER_(impl) -# else -# define CR_HOOK_PROTOTYPE_ \ +#else +# define CR_HOOK_PROTOTYPE_ \ void CR_HOOK_IDENTIFIER_(impl) -# endif +#endif -// Section abbreviations -# define CR_HOOK_SECTION_PRE_ALL cr_pra -# define CR_HOOK_SECTION_PRE_SUITE cr_prs -# define CR_HOOK_SECTION_PRE_INIT cr_pri -# define CR_HOOK_SECTION_PRE_TEST cr_prt -# define CR_HOOK_SECTION_ASSERT cr_ast -# define CR_HOOK_SECTION_THEORY_FAIL cr_thf -# define CR_HOOK_SECTION_TEST_CRASH cr_tsc -# define CR_HOOK_SECTION_POST_TEST cr_pot -# define CR_HOOK_SECTION_POST_FINI cr_pof -# define CR_HOOK_SECTION_POST_SUITE cr_pos -# define CR_HOOK_SECTION_POST_ALL cr_poa +/* Section abbreviations */ +#define CR_HOOK_SECTION_PRE_ALL cr_pra +#define CR_HOOK_SECTION_PRE_SUITE cr_prs +#define CR_HOOK_SECTION_PRE_INIT cr_pri +#define CR_HOOK_SECTION_PRE_TEST cr_prt +#define CR_HOOK_SECTION_ASSERT cr_ast +#define CR_HOOK_SECTION_THEORY_FAIL cr_thf +#define CR_HOOK_SECTION_TEST_CRASH cr_tsc +#define CR_HOOK_SECTION_POST_TEST cr_pot +#define CR_HOOK_SECTION_POST_FINI cr_pof +#define CR_HOOK_SECTION_POST_SUITE cr_pos +#define CR_HOOK_SECTION_POST_ALL cr_poa -# define CR_HOOK_SECTION(Kind) CR_HOOK_SECTION_ ## Kind +#define CR_HOOK_SECTION(Kind) CR_HOOK_SECTION_ ## Kind -# define CR_HOOK_SECTION_STRINGIFY__(Sec) #Sec -# define CR_HOOK_SECTION_STRINGIFY_(Sec) CR_HOOK_SECTION_STRINGIFY__(Sec) -# define CR_HOOK_SECTION_STRINGIFY(Kind) CR_HOOK_SECTION_STRINGIFY_(CR_HOOK_SECTION(Kind)) +#define CR_HOOK_SECTION_STRINGIFY__(Sec) #Sec +#define CR_HOOK_SECTION_STRINGIFY_(Sec) CR_HOOK_SECTION_STRINGIFY__(Sec) +#define CR_HOOK_SECTION_STRINGIFY(Kind) CR_HOOK_SECTION_STRINGIFY_(CR_HOOK_SECTION(Kind)) -# define CR_HOOK_PARAM_TYPE_PRE_ALL struct criterion_test_set * -# define CR_HOOK_PARAM_TYPE_PRE_SUITE struct criterion_suite_set * -# define CR_HOOK_PARAM_TYPE_PRE_INIT struct criterion_test * -# define CR_HOOK_PARAM_TYPE_PRE_TEST struct criterion_test * -# define CR_HOOK_PARAM_TYPE_ASSERT struct criterion_assert_stats * -# define CR_HOOK_PARAM_TYPE_THEORY_FAIL struct criterion_theory_stats * -# define CR_HOOK_PARAM_TYPE_TEST_CRASH struct criterion_test_stats * -# define CR_HOOK_PARAM_TYPE_POST_TEST struct criterion_test_stats * -# define CR_HOOK_PARAM_TYPE_POST_FINI struct criterion_test_stats * -# define CR_HOOK_PARAM_TYPE_POST_SUITE struct criterion_suite_stats * -# define CR_HOOK_PARAM_TYPE_POST_ALL struct criterion_global_stats * +#define CR_HOOK_PARAM_TYPE_PRE_ALL struct criterion_test_set * +#define CR_HOOK_PARAM_TYPE_PRE_SUITE struct criterion_suite_set * +#define CR_HOOK_PARAM_TYPE_PRE_INIT struct criterion_test * +#define CR_HOOK_PARAM_TYPE_PRE_TEST struct criterion_test * +#define CR_HOOK_PARAM_TYPE_ASSERT struct criterion_assert_stats * +#define CR_HOOK_PARAM_TYPE_THEORY_FAIL struct criterion_theory_stats * +#define CR_HOOK_PARAM_TYPE_TEST_CRASH struct criterion_test_stats * +#define CR_HOOK_PARAM_TYPE_POST_TEST struct criterion_test_stats * +#define CR_HOOK_PARAM_TYPE_POST_FINI struct criterion_test_stats * +#define CR_HOOK_PARAM_TYPE_POST_SUITE struct criterion_suite_stats * +#define CR_HOOK_PARAM_TYPE_POST_ALL struct criterion_global_stats * -# define CR_HOOK_PARAM_TYPE(Kind) CR_HOOK_PARAM_TYPE_ ## Kind +#define CR_HOOK_PARAM_TYPE(Kind) CR_HOOK_PARAM_TYPE_ ## Kind -# define CR_REPORT_HOOK_IMPL(Kind) \ - CR_HOOK_PROTOTYPE_(CR_HOOK_PARAM_TYPE(Kind)); \ - CR_SECTION_(CR_HOOK_SECTION_STRINGIFY(Kind)) \ - f_report_hook CR_HOOK_IDENTIFIER_(func) = \ - (f_report_hook) CR_HOOK_IDENTIFIER_(impl) \ - CR_SECTION_SUFFIX_; \ +#define CR_REPORT_HOOK_IMPL(Kind) \ + CR_HOOK_PROTOTYPE_(CR_HOOK_PARAM_TYPE(Kind)); \ + CR_SECTION_(CR_HOOK_SECTION_STRINGIFY(Kind)) \ + f_report_hook CR_HOOK_IDENTIFIER_(func) = \ + (f_report_hook) CR_HOOK_IDENTIFIER_(impl) \ + CR_SECTION_SUFFIX_; \ CR_HOOK_PROTOTYPE_ - #endif /* !CRITERION_INTERNAL_HOOKS_H_ */ diff --git a/include/criterion/internal/ordered-set.h b/include/criterion/internal/ordered-set.h index 607f970..10fef8c 100644 --- a/include/criterion/internal/ordered-set.h +++ b/include/criterion/internal/ordered-set.h @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #ifndef CRITERION_ORDERED_SET_H_ -# define CRITERION_ORDERED_SET_H_ +#define CRITERION_ORDERED_SET_H_ -# include "../types.h" +#include "../types.h" typedef int (*f_criterion_cmp)(void *, void *); @@ -32,7 +32,7 @@ struct criterion_ordered_set { struct criterion_ordered_set_node *first; size_t size; f_criterion_cmp cmp; - void (*const dtor)(void *, void *); + void(*const dtor)(void *, void *); }; struct criterion_ordered_set_node { @@ -42,17 +42,17 @@ struct criterion_ordered_set_node { CR_BEGIN_C_API CR_API struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, - void (*dtor)(void *, void *)); + void (*dtor)(void *, void *)); CR_API void *insert_ordered_set(struct criterion_ordered_set *l, - void *ptr, - size_t size); + void *ptr, + size_t size); CR_END_C_API -# define FOREACH_SET(Elt, Set) \ +#define FOREACH_SET(Elt, Set) \ for (struct criterion_ordered_set_node *n = Set->first; n; n = n->next) \ for (int cond = 1; cond;) \ - for (Elt = (void*) (n + 1); cond && (cond = 0, 1);) + for (Elt = (void *) (n + 1); cond && (cond = 0, 1);) #endif /* !CRITERION_ORDERED_SET_H_ */ diff --git a/include/criterion/internal/parameterized.h b/include/criterion/internal/parameterized.h index 5ef6d95..8623530 100644 --- a/include/criterion/internal/parameterized.h +++ b/include/criterion/internal/parameterized.h @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_PARAMETERIZED_H_ -# define CRITERION_INTERNAL_PARAMETERIZED_H_ +#define CRITERION_INTERNAL_PARAMETERIZED_H_ -# include "test.h" -# include "../types.h" +#include "test.h" +#include "../types.h" struct criterion_test_params { size_t size; @@ -33,93 +33,93 @@ struct criterion_test_params { size_t length; void (*cleanup)(struct criterion_test_params *); -# ifdef __cplusplus +#ifdef __cplusplus constexpr criterion_test_params(size_t size, void *params, size_t length) - : size(size) - , params(params) - , length(length) - , cleanup(nullptr) + : size(size), + params(params), + length(length), + cleanup(nullptr) {} constexpr criterion_test_params(size_t size, void *params, size_t length, - void (*cleanup)(struct criterion_test_params *)) - : size(size) - , params(params) - , length(length) - , cleanup(cleanup) + void(*cleanup)(struct criterion_test_params *)) + : size(size), + params(params), + length(length), + cleanup(cleanup) {} template - constexpr criterion_test_params(std::vector>& vec, - void (*cleanup)(criterion_test_params *) = nullptr) - : size(sizeof (T)) - , params(&vec[0]) - , length(vec.size()) - , cleanup(cleanup) + constexpr criterion_test_params(std::vector > &vec, + void(*cleanup)(criterion_test_params *) = nullptr) + : size(sizeof (T)), + params(&vec[0]), + length(vec.size()), + cleanup(cleanup) {} template constexpr criterion_test_params(T (&arr)[N], - void (*cleanup)(criterion_test_params *) = nullptr) - : size(sizeof (arr[0])) - , params(static_cast(&arr)) - , length(N) - , cleanup(cleanup) + void(*cleanup)(criterion_test_params *) = nullptr) + : size(sizeof (arr[0])), + params(static_cast(&arr)), + length(N), + cleanup(cleanup) {} -# endif +#endif }; -# ifdef __cplusplus -# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \ +#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) \ +#else +# define CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name) \ void CR_IDENTIFIER_(Category, Name, impl)(Param) -# endif +#endif -# define CR_PARAM_TEST_BASE(Param, Category, Name, ...) \ - CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name); \ - CR_TEST_TRAMPOLINE_(Category, Name) \ - struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ - CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ - .compiler_ = CR_COMPILER_, \ - .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, \ - CR_IDENTIFIER_(Category, Name, jmp), \ - &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_; \ +#define CR_PARAM_TEST_BASE(Param, Category, Name, ...) \ + CR_PARAM_TEST_PROTOTYPE_(Param, Category, Name); \ + CR_TEST_TRAMPOLINE_(Category, Name) \ + struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ + CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ + .compiler_ = CR_COMPILER_, \ + .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, \ + CR_IDENTIFIER_(Category, Name, jmp), \ + &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) \ +#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, ...) \ +#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 +#else +# define cr_make_param_array_(Type, Array, ...) \ + (struct criterion_test_params) { .size = sizeof (Type), (void *) (Array), __VA_ARGS__ } +#endif -# undef ParameterizedTest -# define ParameterizedTest(...) CR_EXPAND(CR_PARAM_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) +#undef ParameterizedTest +#define ParameterizedTest(...) CR_EXPAND(CR_PARAM_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) -# undef ParameterizedTestParameters -# define ParameterizedTestParameters(Suite, Name) CR_PARAM_TEST_PARAMS(Suite, Name) +#undef ParameterizedTestParameters +#define ParameterizedTestParameters(Suite, Name) CR_PARAM_TEST_PARAMS(Suite, Name) -# undef cr_make_param_array -# define cr_make_param_array(...) CR_EXPAND(cr_make_param_array_(__VA_ARGS__)) +#undef cr_make_param_array +#define cr_make_param_array(...) CR_EXPAND(cr_make_param_array_(__VA_ARGS__)) #endif /* !CRITERION_INTERNAL_PARAMETERIZED_H_ */ diff --git a/include/criterion/internal/preprocess.h b/include/criterion/internal/preprocess.h index be9c576..9b3fc81 100644 --- a/include/criterion/internal/preprocess.h +++ b/include/criterion/internal/preprocess.h @@ -22,52 +22,53 @@ * THE SOFTWARE. */ #ifndef CRITERION_PREPROCESS_H_ -# define CRITERION_PREPROCESS_H_ +#define CRITERION_PREPROCESS_H_ -# define CR_NOOP do {} while(0) +#define CR_NOOP do {} while (0) -# ifdef __cplusplus -# define CR_NOTHROW throw() -# else -# define CR_NOTHROW -# endif +#ifdef __cplusplus +# define CR_NOTHROW throw () +#else +# define CR_NOTHROW +#endif -# define CR_EXPAND(x) x -# define CR_IDENTITY(...) __VA_ARGS__ +#define CR_EXPAND(x) x +#define CR_IDENTITY(...) __VA_ARGS__ -# define CR_STR(x) CR_EXPAND(CR_STR_(x)) -# define CR_STR_(x) #x +#define CR_STR(x) CR_EXPAND(CR_STR_(x)) +#define CR_STR_(x) #x -# define CR_VA_TAIL(...) CR_EXPAND(CR_VA_TAIL_HELPER(CR_VA_TAIL_SELECT(__VA_ARGS__), __VA_ARGS__)) +#define CR_VA_TAIL(...) CR_EXPAND(CR_VA_TAIL_HELPER(CR_VA_TAIL_SELECT(__VA_ARGS__), __VA_ARGS__)) -# define CR_VA_TAIL_HELPER(N, ...) CR_EXPAND(CR_VA_TAIL_HELPER_(N, __VA_ARGS__)) -# define CR_VA_TAIL_HELPER_(N, ...) CR_EXPAND(CR_VA_TAIL_HELPER_##N(__VA_ARGS__)) -# define CR_VA_TAIL_HELPER_1(Head) -# define CR_VA_TAIL_HELPER_2(Head, ...) __VA_ARGS__ +#define CR_VA_TAIL_HELPER(N, ...) CR_EXPAND(CR_VA_TAIL_HELPER_(N, __VA_ARGS__)) +#define CR_VA_TAIL_HELPER_(N, ...) CR_EXPAND(CR_VA_TAIL_HELPER_ ## N(__VA_ARGS__)) +#define CR_VA_TAIL_HELPER_1(Head) +#define CR_VA_TAIL_HELPER_2(Head, ...) __VA_ARGS__ -# define CR_VA_HEAD(...) CR_EXPAND(CR_VA_HEAD_HELPER(CR_VA_TAIL_SELECT(__VA_ARGS__), __VA_ARGS__)) +#define CR_VA_HEAD(...) CR_EXPAND(CR_VA_HEAD_HELPER(CR_VA_TAIL_SELECT(__VA_ARGS__), __VA_ARGS__)) -# define CR_VA_HEAD_HELPER(N, ...) CR_EXPAND(CR_VA_HEAD_HELPER_(N, __VA_ARGS__)) -# define CR_VA_HEAD_HELPER_(N, ...) CR_EXPAND(CR_VA_HEAD_HELPER_##N(__VA_ARGS__)) -# define CR_VA_HEAD_HELPER_1(Head) Head -# define CR_VA_HEAD_HELPER_2(Head, ...) Head +#define CR_VA_HEAD_HELPER(N, ...) CR_EXPAND(CR_VA_HEAD_HELPER_(N, __VA_ARGS__)) +#define CR_VA_HEAD_HELPER_(N, ...) CR_EXPAND(CR_VA_HEAD_HELPER_ ## N(__VA_ARGS__)) +#define CR_VA_HEAD_HELPER_1(Head) Head +#define CR_VA_HEAD_HELPER_2(Head, ...) Head -# define CR_VA_TAIL_SELECT(...) CR_EXPAND(CR_VA_TAIL_SELECT64(__VA_ARGS__, \ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ - 2, 2, 1, _)) +#define CR_VA_TAIL_SELECT(...) \ + CR_EXPAND(CR_VA_TAIL_SELECT64(__VA_ARGS__, \ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ + 2, 2, 1, _)) -# define CR_VA_TAIL_SELECT64( \ +#define CR_VA_TAIL_SELECT64( \ _01, _02, _03, _04, _05, _06, _07, _08, _09, _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, X, ...) X + _61, _62, _63, X, ...) X #endif /* !CRITERION_PREPROCESS_H_ */ diff --git a/include/criterion/internal/redirect.h b/include/criterion/internal/redirect.h index a3e9b50..a8d8624 100644 --- a/include/criterion/internal/redirect.h +++ b/include/criterion/internal/redirect.h @@ -22,148 +22,148 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_REDIRECT_H_ -# define CRITERION_INTERNAL_REDIRECT_H_ +#define CRITERION_INTERNAL_REDIRECT_H_ -# include "common.h" -# include "assert.h" +#include "common.h" +#include "assert.h" CR_BEGIN_C_API -CR_API int cr_stdout_match_file(CR_STDN FILE* ref); -CR_API int cr_stdout_match_str(const char* ref); -CR_API int cr_stderr_match_file(CR_STDN FILE* ref); -CR_API int cr_stderr_match_str(const char* ref); +CR_API int cr_stdout_match_file(CR_STDN FILE *ref); +CR_API int cr_stdout_match_str(const char *ref); +CR_API int cr_stderr_match_file(CR_STDN FILE *ref); +CR_API int cr_stderr_match_str(const char *ref); CR_END_C_API -# define cr_assert_redir_op_(Fail, Fun, Op, File, Str, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - !(Fun((File), (Str)) Op 0), \ - dummy, \ - CRITERION_ASSERT_MSG_FILE_STR_MATCH, \ - (CR_STR(File), Str), \ - __VA_ARGS__ \ - )) +#define cr_assert_redir_op_(Fail, Fun, Op, File, Str, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + !(Fun((File), (Str)) Op 0), \ + dummy, \ + CRITERION_ASSERT_MSG_FILE_STR_MATCH, \ + (CR_STR(File), Str), \ + __VA_ARGS__ \ + )) -# define cr_assert_redir_op_va_(Fail, Fun, Op, ...) \ - CR_EXPAND(cr_assert_redir_op_( \ - Fail, \ - Fun, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_redir_op_va_(Fail, Fun, Op, ...) \ + CR_EXPAND(cr_assert_redir_op_( \ + Fail, \ + Fun, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -# define cr_assert_redir_f_op_(Fail, Fun, Op, File, Ref, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - !(Fun((File), (Ref)) Op 0), \ - dummy, \ - CRITERION_ASSERT_MSG_FILE_MATCH, \ - (CR_STR(File), CR_STR(Ref)), \ - __VA_ARGS__ \ - )) +#define cr_assert_redir_f_op_(Fail, Fun, Op, File, Ref, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + !(Fun((File), (Ref)) Op 0), \ + dummy, \ + CRITERION_ASSERT_MSG_FILE_MATCH, \ + (CR_STR(File), CR_STR(Ref)), \ + __VA_ARGS__ \ + )) -# define cr_assert_redir_f_op_va_(Fail, Fun, Op, ...) \ - CR_EXPAND(cr_assert_redir_f_op_( \ - Fail, \ - Fun, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_redir_f_op_va_(Fail, Fun, Op, ...) \ + CR_EXPAND(cr_assert_redir_f_op_( \ + Fail, \ + Fun, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -# undef cr_assert_file_contents_eq_str -# define cr_assert_file_contents_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, ==, __VA_ARGS__)) -# undef cr_expect_file_contents_eq_str -# define cr_expect_file_contents_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, ==, __VA_ARGS__)) -# undef cr_assert_file_contents_neq_str -# define cr_assert_file_contents_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, !=, __VA_ARGS__)) -# undef cr_expect_file_contents_neq_str -# define cr_expect_file_contents_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, !=, __VA_ARGS__)) -# undef cr_assert_file_contents_eq -# define cr_assert_file_contents_eq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_ABORT_, cr_file_match_file, ==, __VA_ARGS__)) -# undef cr_expect_file_contents_eq -# define cr_expect_file_contents_eq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_CONTINUES_, cr_file_match_file, ==, __VA_ARGS__)) -# undef cr_assert_file_contents_neq -# define cr_assert_file_contents_neq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_ABORT_, cr_file_match_file, !=, __VA_ARGS__)) -# undef cr_expect_file_contents_neq -# define cr_expect_file_contents_neq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_CONTINUES_, cr_file_match_file, !=, __VA_ARGS__)) +#undef cr_assert_file_contents_eq_str +#define cr_assert_file_contents_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, ==, __VA_ARGS__)) +#undef cr_expect_file_contents_eq_str +#define cr_expect_file_contents_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, ==, __VA_ARGS__)) +#undef cr_assert_file_contents_neq_str +#define cr_assert_file_contents_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, !=, __VA_ARGS__)) +#undef cr_expect_file_contents_neq_str +#define cr_expect_file_contents_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, !=, __VA_ARGS__)) +#undef cr_assert_file_contents_eq +#define cr_assert_file_contents_eq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_ABORT_, cr_file_match_file, ==, __VA_ARGS__)) +#undef cr_expect_file_contents_eq +#define cr_expect_file_contents_eq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_CONTINUES_, cr_file_match_file, ==, __VA_ARGS__)) +#undef cr_assert_file_contents_neq +#define cr_assert_file_contents_neq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_ABORT_, cr_file_match_file, !=, __VA_ARGS__)) +#undef cr_expect_file_contents_neq +#define cr_expect_file_contents_neq(...) CR_EXPAND(cr_assert_redir_f_op_va_(CR_FAIL_CONTINUES_, cr_file_match_file, !=, __VA_ARGS__)) -# undef cr_assert_stdout_eq_str -# define cr_assert_stdout_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_str, ==, stdout, __VA_ARGS__)) -# undef cr_expect_stdout_eq_str -# define cr_expect_stdout_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_str, ==, stdout, __VA_ARGS__)) -# undef cr_assert_stdout_neq_str -# define cr_assert_stdout_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_str, !=, stdout, __VA_ARGS__)) -# undef cr_expect_stdout_neq_str -# define cr_expect_stdout_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_str, !=, stdout, __VA_ARGS__)) -# undef cr_assert_stderr_eq_str -# define cr_assert_stderr_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_str, ==, stderr, __VA_ARGS__)) -# undef cr_expect_stderr_eq_str -# define cr_expect_stderr_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_str, ==, stderr, __VA_ARGS__)) -# undef cr_assert_stderr_neq_str -# define cr_assert_stderr_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_str, !=, stderr, __VA_ARGS__)) -# undef cr_expect_stderr_neq_str -# define cr_expect_stderr_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_str, !=, stderr, __VA_ARGS__)) -# undef cr_assert_stdout_eq -# define cr_assert_stdout_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_file, ==, stdout, __VA_ARGS__)) -# undef cr_expect_stdout_eq -# define cr_expect_stdout_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_file, ==, stdout, __VA_ARGS__)) -# undef cr_assert_stdout_neq -# define cr_assert_stdout_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_file, !=, stdout, __VA_ARGS__)) -# undef cr_expect_stdout_neq -# define cr_expect_stdout_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_file, !=, stdout, __VA_ARGS__)) -# undef cr_assert_stderr_eq -# define cr_assert_stderr_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_file, ==, stderr, __VA_ARGS__)) -# undef cr_expect_stderr_eq -# define cr_expect_stderr_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_file, ==, stderr, __VA_ARGS__)) -# undef cr_assert_stderr_neq -# define cr_assert_stderr_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_file, !=, stderr, __VA_ARGS__)) -# undef cr_expect_stderr_neq -# define cr_expect_stderr_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_file, !=, stderr, __VA_ARGS__)) +#undef cr_assert_stdout_eq_str +#define cr_assert_stdout_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_str, ==, stdout, __VA_ARGS__)) +#undef cr_expect_stdout_eq_str +#define cr_expect_stdout_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_str, ==, stdout, __VA_ARGS__)) +#undef cr_assert_stdout_neq_str +#define cr_assert_stdout_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_str, !=, stdout, __VA_ARGS__)) +#undef cr_expect_stdout_neq_str +#define cr_expect_stdout_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_str, !=, stdout, __VA_ARGS__)) +#undef cr_assert_stderr_eq_str +#define cr_assert_stderr_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_str, ==, stderr, __VA_ARGS__)) +#undef cr_expect_stderr_eq_str +#define cr_expect_stderr_eq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_str, ==, stderr, __VA_ARGS__)) +#undef cr_assert_stderr_neq_str +#define cr_assert_stderr_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_str, !=, stderr, __VA_ARGS__)) +#undef cr_expect_stderr_neq_str +#define cr_expect_stderr_neq_str(...) CR_EXPAND(cr_assert_redir_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_str, !=, stderr, __VA_ARGS__)) +#undef cr_assert_stdout_eq +#define cr_assert_stdout_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_file, ==, stdout, __VA_ARGS__)) +#undef cr_expect_stdout_eq +#define cr_expect_stdout_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_file, ==, stdout, __VA_ARGS__)) +#undef cr_assert_stdout_neq +#define cr_assert_stdout_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stdout_match_file, !=, stdout, __VA_ARGS__)) +#undef cr_expect_stdout_neq +#define cr_expect_stdout_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stdout_match_file, !=, stdout, __VA_ARGS__)) +#undef cr_assert_stderr_eq +#define cr_assert_stderr_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_file, ==, stderr, __VA_ARGS__)) +#undef cr_expect_stderr_eq +#define cr_expect_stderr_eq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_file, ==, stderr, __VA_ARGS__)) +#undef cr_assert_stderr_neq +#define cr_assert_stderr_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_ABORT_, cr_stderr_match_file, !=, stderr, __VA_ARGS__)) +#undef cr_expect_stderr_neq +#define cr_expect_stderr_neq(...) CR_EXPAND(cr_assert_redir_f_unop_va_(CR_FAIL_CONTINUES_, cr_stderr_match_file, !=, stderr, __VA_ARGS__)) -# define cr_assert_redir_unop_(Fail, Fun, Op, File, Str, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - !(Fun((Str)) Op 0), \ - dummy, \ - CRITERION_ASSERT_MSG_FILE_STR_MATCH, \ - (CR_STR(File), Str), \ - __VA_ARGS__ \ - )) +#define cr_assert_redir_unop_(Fail, Fun, Op, File, Str, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + !(Fun((Str)) Op 0), \ + dummy, \ + CRITERION_ASSERT_MSG_FILE_STR_MATCH, \ + (CR_STR(File), Str), \ + __VA_ARGS__ \ + )) -# define cr_assert_redir_unop_va_(Fail, Fun, Op, ...) \ - CR_EXPAND(cr_assert_redir_unop_( \ - Fail, \ - Fun, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_redir_unop_va_(Fail, Fun, Op, ...) \ + CR_EXPAND(cr_assert_redir_unop_( \ + Fail, \ + Fun, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) -# define cr_assert_redir_f_unop_(Fail, Fun, Op, File, Ref, ...) \ - CR_EXPAND(cr_assert_impl( \ - Fail, \ - !(Fun((Ref)) Op 0), \ - dummy, \ - CRITERION_ASSERT_MSG_FILE_MATCH, \ - (CR_STR(File), CR_STR(Ref)), \ - __VA_ARGS__ \ - )) +#define cr_assert_redir_f_unop_(Fail, Fun, Op, File, Ref, ...) \ + CR_EXPAND(cr_assert_impl( \ + Fail, \ + !(Fun((Ref)) Op 0), \ + dummy, \ + CRITERION_ASSERT_MSG_FILE_MATCH, \ + (CR_STR(File), CR_STR(Ref)), \ + __VA_ARGS__ \ + )) -# define cr_assert_redir_f_unop_va_(Fail, Fun, Op, ...) \ - CR_EXPAND(cr_assert_redir_f_unop_( \ - Fail, \ - Fun, \ - Op, \ - CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ - CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ - )) +#define cr_assert_redir_f_unop_va_(Fail, Fun, Op, ...) \ + CR_EXPAND(cr_assert_redir_f_unop_( \ + Fail, \ + Fun, \ + Op, \ + CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_HEAD(CR_VA_TAIL(__VA_ARGS__)), \ + CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__)) \ + )) #endif /* !CRITERION_INTERNAL_REDIRECT_H_ */ diff --git a/include/criterion/internal/stdio_filebuf.hxx b/include/criterion/internal/stdio_filebuf.hxx index 155e4aa..c58bbe1 100644 --- a/include/criterion/internal/stdio_filebuf.hxx +++ b/include/criterion/internal/stdio_filebuf.hxx @@ -22,141 +22,159 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_STDIO_FILEBUF_HXX_ -# define CRITERION_INTERNAL_STDIO_FILEBUF_HXX_ +#define CRITERION_INTERNAL_STDIO_FILEBUF_HXX_ -# include +#include /* *INDENT-OFF* */ namespace criterion { namespace internal { /* *INDENT-ON* */ - template > - class stdio_sync_filebuf : public std::basic_streambuf { - public: - typedef Traits traits; - typedef std::basic_filebuf super; - typedef typename Traits::int_type int_type; - typedef typename Traits::pos_type pos_type; - typedef typename Traits::off_type off_type; +template > +class stdio_sync_filebuf : public std::basic_streambuf { +public: + typedef Traits traits; + typedef std::basic_filebuf super; + typedef typename Traits::int_type int_type; + typedef typename Traits::pos_type pos_type; + typedef typename Traits::off_type off_type; - stdio_sync_filebuf(std::FILE *file) - : file(file) - , lastchar(Traits::eof()) - {} + stdio_sync_filebuf(std::FILE *file) + : file(file), + lastchar(Traits::eof()) + {} - stdio_sync_filebuf(stdio_sync_filebuf&& other) = default; - stdio_sync_filebuf& operator=(stdio_sync_filebuf&& other) = default; + stdio_sync_filebuf(stdio_sync_filebuf &&other) = default; + stdio_sync_filebuf &operator=(stdio_sync_filebuf &&other) = default; - void swap(stdio_sync_filebuf& other) { - super::swap(other); - std::swap(file, other.file); - std::swap(lastchar, other.lastchar); - } + void swap(stdio_sync_filebuf &other) + { + super::swap(other); + std::swap(file, other.file); + std::swap(lastchar, other.lastchar); + } - protected: - int_type syncgetc(); - int_type syncungetc(int_type); - int_type syncputc(int_type); +protected: + int_type syncgetc(); + int_type syncungetc(int_type); + int_type syncputc(int_type); - virtual std::streampos seekoff(std::streamoff off, - std::ios_base::seekdir dir, - std::ios_base::openmode = std::ios_base::in | std::ios_base::out) { + virtual std::streampos seekoff(std::streamoff off, + std::ios_base::seekdir dir, + std::ios_base::openmode = std::ios_base::in | std::ios_base::out) + { + int whence; - int whence; - if (dir == std::ios_base::beg) - whence = SEEK_SET; - else if (dir == std::ios_base::cur) - whence = SEEK_CUR; + if (dir == std::ios_base::beg) + whence = SEEK_SET; + else if (dir == std::ios_base::cur) + whence = SEEK_CUR; + else + whence = SEEK_END; + + if (!fseek(file, off, whence)) + return std::streampos(std::ftell(file)); + return std::streamoff(-1); + } + + virtual std::streampos seekpos(std::streampos pos, + std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) + { + return seekoff(std::streamoff(pos), std::ios_base::beg, mode); + } + + virtual std::streamsize xsgetn(CharT *s, std::streamsize n); + virtual std::streamsize xsputn(const CharT *s, std::streamsize n); + + virtual int sync() + { + return std::fflush(file); + } + + virtual int_type underflow() + { + int_type c = syncgetc(); + + return syncungetc(c); + } + + virtual int_type uflow() + { + return lastchar = syncgetc(); + } + + static inline bool is_eof(int_type c) + { + static const int_type eof = Traits::eof(); + + return Traits::eq_int_type(c, eof); + } + + virtual int_type overflow(int_type c = Traits::eof()) + { + int_type ret; + + if (is_eof(c)) { + if (std::fflush(file)) + ret = Traits::eof(); else - whence = SEEK_END; - - if (!fseek(file, off, whence)) - return std::streampos(std::ftell(file)); - return std::streamoff(-1); + ret = Traits::not_eof(c); + } else { + ret = syncputc(c); } - - virtual std::streampos seekpos(std::streampos pos, - std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - return seekoff(std::streamoff(pos), std::ios_base::beg, mode); - } - - virtual std::streamsize xsgetn(CharT* s, std::streamsize n); - virtual std::streamsize xsputn(const CharT* s, std::streamsize n); - - virtual int sync() { - return std::fflush(file); - } - - virtual int_type underflow() { - int_type c = syncgetc(); - return syncungetc(c); - } - - virtual int_type uflow() { - return lastchar = syncgetc(); - } - - static inline bool is_eof(int_type c) { - static const int_type eof = Traits::eof(); - return Traits::eq_int_type(c, eof); - } - - virtual int_type overflow(int_type c = Traits::eof()) { - int_type ret; - if (is_eof(c)) { - if (std::fflush(file)) - ret = Traits::eof(); - else - ret = Traits::not_eof(c); - } else { - ret = syncputc(c); - } - return ret; - } - - virtual int_type pbackfail(int_type c = Traits::eof()) { - int_type ret = syncungetc(is_eof(c) && !is_eof(lastchar) ? lastchar : c); - lastchar = Traits::eof(); - return ret; - } - - private: - std::FILE *file; - bool file_open; - int_type lastchar; - }; - - template <> - inline stdio_sync_filebuf::int_type - stdio_sync_filebuf::syncgetc() { - return std::getc(file); + return ret; } - template <> - inline stdio_sync_filebuf::int_type - stdio_sync_filebuf::syncungetc(stdio_sync_filebuf::int_type c) { - return std::ungetc(c, file); + virtual int_type pbackfail(int_type c = Traits::eof()) + { + int_type ret = syncungetc(is_eof(c) && !is_eof(lastchar) ? lastchar : c); + + lastchar = Traits::eof(); + return ret; } - template <> - inline stdio_sync_filebuf::int_type - stdio_sync_filebuf::syncputc(stdio_sync_filebuf::int_type c) { - return std::putc(c, file); - } +private: + std::FILE *file; + bool file_open; + int_type lastchar; +}; - template <> - inline std::streamsize - stdio_sync_filebuf::xsgetn(char *s, std::streamsize n) { - std::streamsize res = std::fread(s, 1, n, file); - lastchar = res > 0 ? traits::to_int_type(s[res - 1]) : traits::eof(); - return res; - } +template <> +inline stdio_sync_filebuf::int_type +stdio_sync_filebuf::syncgetc() +{ + return std::getc(file); +} - template <> - inline std::streamsize - stdio_sync_filebuf::xsputn(const char *s, std::streamsize n) { - return std::fwrite(s, 1, n, file); - } +template <> +inline stdio_sync_filebuf::int_type +stdio_sync_filebuf::syncungetc(stdio_sync_filebuf::int_type c) +{ + return std::ungetc(c, file); +} + +template <> +inline stdio_sync_filebuf::int_type +stdio_sync_filebuf::syncputc(stdio_sync_filebuf::int_type c) +{ + return std::putc(c, file); +} + +template <> +inline std::streamsize +stdio_sync_filebuf::xsgetn(char *s, std::streamsize n) +{ + std::streamsize res = std::fread(s, 1, n, file); + lastchar = res > 0 ? traits::to_int_type(s[res - 1]) : traits::eof(); + return res; +} + +template <> +inline std::streamsize +stdio_sync_filebuf::xsputn(const char *s, std::streamsize n) +{ + return std::fwrite(s, 1, n, file); +} /* *INDENT-OFF* */ }} diff --git a/include/criterion/internal/stream.hxx b/include/criterion/internal/stream.hxx index f9a1af6..2207fc2 100644 --- a/include/criterion/internal/stream.hxx +++ b/include/criterion/internal/stream.hxx @@ -22,113 +22,117 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_STREAM_HXX_ -# define CRITERION_INTERNAL_STREAM_HXX_ +#define CRITERION_INTERNAL_STREAM_HXX_ -# include -# include -# include +#include +#include +#include -# include "stdio_filebuf.hxx" +#include "stdio_filebuf.hxx" /* *INDENT-OFF* */ namespace criterion { namespace internal { /* *INDENT-ON* */ - template - class stream_mixin : public Super { +template +class stream_mixin : public Super { public: - stream_mixin(FILE* f) - : Super() - , fbuf(new stdio_sync_filebuf(f)) - , file(f) - { - std::ios::rdbuf(&*fbuf); - } + stream_mixin(FILE *f) + : Super(), + fbuf(new stdio_sync_filebuf(f)), + file(f) + { + std::ios::rdbuf(&*fbuf); + } -# if __cplusplus > 199711L - stream_mixin(const stream_mixin& other) = delete; - stream_mixin& operator=(const stream_mixin& other) = delete; -# endif +#if __cplusplus > 199711L + stream_mixin(const stream_mixin &other) = delete; + stream_mixin &operator=(const stream_mixin &other) = delete; +#endif - stream_mixin(stream_mixin&& other) : - fbuf(std::move(other.fbuf)), - file(std::move(other.file)) - {} + stream_mixin(stream_mixin &&other) : + fbuf(std::move(other.fbuf)), + file(std::move(other.file)) + {} - stream_mixin& operator=(stream_mixin&& other) { - fbuf = std::move(other.fbuf); - file = std::move(other.file); - } + stream_mixin &operator=(stream_mixin &&other) + { + fbuf = std::move(other.fbuf); + file = std::move(other.file); + } - void close(void) { - Super::flush(); - Super::close(); - std::fclose(file); - } + void close(void) + { + Super::flush(); + Super::close(); + std::fclose(file); + } - private: - std::shared_ptr> fbuf; - std::FILE* file; - }; +private: + std::shared_ptr > fbuf; + std::FILE *file; +}; - template - class basic_ofstream : public stream_mixin> { - typedef stream_mixin> super; - public: - basic_ofstream(FILE* f) - : super(f) - {} +template +class basic_ofstream : public stream_mixin > { +typedef stream_mixin > super; +public: + basic_ofstream(FILE *f) + : super(f) + {} - basic_ofstream(basic_ofstream&& other) - : super(std::move(other)) - {} - }; + basic_ofstream(basic_ofstream &&other) + : super(std::move(other)) + {} +}; - template - class basic_ifstream : public stream_mixin> { - typedef stream_mixin> super; - public: - basic_ifstream(FILE* f) - : super(f) - {} +template +class basic_ifstream : public stream_mixin > { +typedef stream_mixin > super; +public: + basic_ifstream(FILE *f) + : super(f) + {} - basic_ifstream(basic_ifstream&& other) - : super(std::move(other)) - {} - }; + basic_ifstream(basic_ifstream &&other) + : super(std::move(other)) + {} +}; - template - class basic_fstream : public stream_mixin> { - typedef stream_mixin> super; - public: - basic_fstream(FILE* f) - : super(f) - {} +template +class basic_fstream : public stream_mixin > { +typedef stream_mixin > super; +public: + basic_fstream(FILE *f) + : super(f) + {} - basic_fstream(basic_fstream&& other) - : super(std::move(other)) - {} - }; + basic_fstream(basic_fstream &&other) + : super(std::move(other)) + {} +}; - struct get_redirected_out_stream_ { - static inline basic_ofstream& call(std::FILE* f) { - static std::unique_ptr> stream; +struct get_redirected_out_stream_ { + static inline basic_ofstream &call(std::FILE *f) + { + static std::unique_ptr > stream; - if (!stream) - stream.reset(new basic_ofstream(f)); - return *stream; - } + if (!stream) + stream.reset(new basic_ofstream(f)); + return *stream; + } +}; - }; +struct get_redirected_in_stream_ { + static inline basic_ifstream &call(std::FILE *f) + { + static std::unique_ptr > stream; - struct get_redirected_in_stream_ { - static inline basic_ifstream& call(std::FILE* f) { - static std::unique_ptr> stream; - if (!stream) - stream.reset(new basic_ifstream(f)); - return *stream; - } - }; + if (!stream) + stream.reset(new basic_ifstream(f)); + return *stream; + } +}; /* *INDENT-OFF* */ }} diff --git a/include/criterion/internal/test.h b/include/criterion/internal/test.h index 6010a2c..3f9da58 100644 --- a/include/criterion/internal/test.h +++ b/include/criterion/internal/test.h @@ -22,45 +22,45 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_TEST_H_ -# define CRITERION_INTERNAL_TEST_H_ +#define CRITERION_INTERNAL_TEST_H_ -# include "designated-initializer-compat.h" -# include "common.h" +#include "designated-initializer-compat.h" +#include "common.h" -# ifdef __OBJC__ -#import -# endif +#ifdef __OBJC__ +# import +#endif -# ifdef __cplusplus -# include -# endif +#ifdef __cplusplus +# include +#endif -# define CR_IDENTIFIER_(Category, Name, Suffix) \ +#define CR_IDENTIFIER_(Category, Name, Suffix) \ Category ## _ ## Name ## _ ## Suffix -# ifdef __cplusplus -# ifdef __OBJC__ -# define CR_LANG CR_LANG_OBJCXX -# else -# define CR_LANG CR_LANG_CXX -# endif +#ifdef __cplusplus +# ifdef __OBJC__ +# define CR_LANG CR_LANG_OBJCXX # else -# ifdef __OBJC__ -# define CR_LANG CR_LANG_OBJC -# else -# define CR_LANG CR_LANG_C -# endif +# define CR_LANG CR_LANG_CXX # endif +#else +# ifdef __OBJC__ +# define CR_LANG CR_LANG_OBJC +# else +# define CR_LANG CR_LANG_C +# endif +#endif -# ifdef __cplusplus -# define CR_TEST_PROTOTYPE_(Category, Name) \ +#ifdef __cplusplus +# define CR_TEST_PROTOTYPE_(Category, Name) \ extern "C" void CR_IDENTIFIER_(Category, Name, impl)(void) -# else -# define CR_TEST_PROTOTYPE_(Category, Name) \ +#else +# define CR_TEST_PROTOTYPE_(Category, Name) \ void CR_IDENTIFIER_(Category, Name, impl)(void) -# endif +#endif -# define CR_SUITE_IDENTIFIER_(Name, Suffix) \ +#define CR_SUITE_IDENTIFIER_(Name, Suffix) \ suite_ ## Name ## _ ## Suffix CR_BEGIN_C_API @@ -78,123 +78,123 @@ static const char *const cr_msg_test_main_other_exception = "Caught some unexpec static const char *const cr_msg_test_fini_std_exception = "Caught an unexpected exception during the test finalization: %s."; static const char *const cr_msg_test_fini_other_exception = "Caught some unexpected exception during the test finalization."; -# ifdef __cplusplus -# define CR_TEST_TRAMPOLINE_(Category, Name) \ - static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ - try { \ - criterion_internal_test_setup(); \ - } catch (const std::exception &e) { \ - criterion_test_die(cr_msg_test_init_std_exception, e.what()); \ - } catch (...) { \ - criterion_test_die(cr_msg_test_init_other_exception); \ - } \ - try { \ - criterion_internal_test_main((void(*)(void)) CR_IDENTIFIER_(Category, Name, impl)); \ - } catch (const std::exception &e) { \ - criterion_test_die(cr_msg_test_main_std_exception, e.what()); \ - } catch (...) { \ - criterion_test_die(cr_msg_test_main_other_exception); \ - } \ - try { \ - criterion_internal_test_teardown(); \ - } catch (const std::exception &e) { \ - criterion_test_die(cr_msg_test_fini_std_exception, e.what()); \ - } catch (...) { \ - criterion_test_die(cr_msg_test_fini_other_exception); \ - } \ +#ifdef __cplusplus +# define CR_TEST_TRAMPOLINE_(Category, Name) \ + static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ + try { \ + criterion_internal_test_setup(); \ + } catch (const std::exception &e) { \ + criterion_test_die(cr_msg_test_init_std_exception, e.what()); \ + } catch (...) { \ + criterion_test_die(cr_msg_test_init_other_exception); \ + } \ + try { \ + criterion_internal_test_main((void (*)(void))CR_IDENTIFIER_(Category, Name, impl)); \ + } catch (const std::exception &e) { \ + criterion_test_die(cr_msg_test_main_std_exception, e.what()); \ + } catch (...) { \ + criterion_test_die(cr_msg_test_main_other_exception); \ + } \ + try { \ + criterion_internal_test_teardown(); \ + } catch (const std::exception &e) { \ + criterion_test_die(cr_msg_test_fini_std_exception, e.what()); \ + } catch (...) { \ + criterion_test_die(cr_msg_test_fini_other_exception); \ + } \ + } +#else +# if defined (__OBJC__) && defined (__EXCEPTIONS) +# define CR_TEST_TRAMPOLINE_(Category, Name) \ + static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ + @try { \ + criterion_internal_test_setup(); \ + } @catch (NSException *e) { \ + NSString *reason = [e reason]; \ + criterion_test_die(cr_msg_test_init_std_exception, [reason UTF8String]); \ + } @catch (...) { \ + criterion_test_die(cr_msg_test_init_other_exception); \ + } \ + @try { \ + criterion_internal_test_main((void (*)(void))CR_IDENTIFIER_(Category, Name, impl)); \ + } @catch (NSException *e) { \ + NSString *reason = [e reason]; \ + criterion_test_die(cr_msg_test_main_std_exception, [reason UTF8String]); \ + } @catch (...) { \ + criterion_test_die(cr_msg_test_main_other_exception); \ + } \ + @try { \ + criterion_internal_test_teardown(); \ + } @catch (NSException *e) { \ + NSString *reason = [e reason]; \ + criterion_test_die(cr_msg_test_fini_std_exception, [reason UTF8String]); \ + } @catch (...) { \ + criterion_test_die(cr_msg_test_fini_other_exception); \ + } \ } # else -# if defined(__OBJC__) && defined(__EXCEPTIONS) -# define CR_TEST_TRAMPOLINE_(Category, Name) \ - static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ - @try { \ - criterion_internal_test_setup(); \ - } @catch (NSException *e) { \ - NSString *reason = [e reason]; \ - criterion_test_die(cr_msg_test_init_std_exception, [reason UTF8String]); \ - } @catch (...) { \ - criterion_test_die(cr_msg_test_init_other_exception); \ - } \ - @try { \ - criterion_internal_test_main((void(*)(void)) CR_IDENTIFIER_(Category, Name, impl)); \ - } @catch (NSException *e) { \ - NSString *reason = [e reason]; \ - criterion_test_die(cr_msg_test_main_std_exception, [reason UTF8String]); \ - } @catch (...) { \ - criterion_test_die(cr_msg_test_main_other_exception); \ - } \ - @try { \ - criterion_internal_test_teardown(); \ - } @catch (NSException *e) { \ - NSString *reason = [e reason]; \ - criterion_test_die(cr_msg_test_fini_std_exception, [reason UTF8String]); \ - } @catch (...) { \ - criterion_test_die(cr_msg_test_fini_other_exception); \ - } \ +# define CR_TEST_TRAMPOLINE_(Category, Name) \ + static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ + criterion_internal_test_setup(); \ + criterion_internal_test_main((void (*)(void))CR_IDENTIFIER_(Category, Name, impl)); \ + criterion_internal_test_teardown(); \ } -# else -# define CR_TEST_TRAMPOLINE_(Category, Name) \ - static inline void CR_IDENTIFIER_(Category, Name, jmp)(void) { \ - criterion_internal_test_setup(); \ - criterion_internal_test_main((void(*)(void)) CR_IDENTIFIER_(Category, Name, impl)); \ - criterion_internal_test_teardown(); \ - } -# endif # endif +#endif -# if defined(_MSC_VER) -# define CR_COMPILER_ CR_COMP_MSVC -# elif defined(__clang__) -# define CR_COMPILER_ CR_COMP_CLANG -# elif defined(__GNUC__) -# define CR_COMPILER_ CR_COMP_GCC -# else -# define CR_COMPILER_ CR_COMP_UNKNOWN -# endif +#if defined (_MSC_VER) +# define CR_COMPILER_ CR_COMP_MSVC +#elif defined (__clang__) +# define CR_COMPILER_ CR_COMP_CLANG +#elif defined (__GNUC__) +# define CR_COMPILER_ CR_COMP_GCC +#else +# define CR_COMPILER_ CR_COMP_UNKNOWN +#endif -# define CR_TEST_BASE(Category, Name, ...) \ - CR_TEST_PROTOTYPE_(Category, Name); \ - CR_TEST_TRAMPOLINE_(Category, Name) \ - struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ - CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ - .compiler_ = CR_COMPILER_, \ - .lang_ = CR_LANG, \ - .kind_ = CR_TEST_NORMAL, \ - .param_ = (struct criterion_test_params(*)(void)) NULL, \ - .identifier_ = #Category "/" #Name, \ - .file_ = __FILE__, \ - .line_ = __LINE__, \ - __VA_ARGS__ \ - )); \ - struct criterion_test CR_IDENTIFIER_(Category, Name, meta) = { \ - #Name, \ - #Category, \ - CR_IDENTIFIER_(Category, Name, jmp), \ - &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_; \ +#define CR_TEST_BASE(Category, Name, ...) \ + CR_TEST_PROTOTYPE_(Category, Name); \ + CR_TEST_TRAMPOLINE_(Category, Name) \ + struct criterion_test_extra_data CR_IDENTIFIER_(Category, Name, extra) = \ + CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ + .compiler_ = CR_COMPILER_, \ + .lang_ = CR_LANG, \ + .kind_ = CR_TEST_NORMAL, \ + .param_ = (struct criterion_test_params (*)(void))NULL, \ + .identifier_ = #Category "/" #Name, \ + .file_ = __FILE__, \ + .line_ = __LINE__, \ + __VA_ARGS__ \ + )); \ + struct criterion_test CR_IDENTIFIER_(Category, Name, meta) = { \ + #Name, \ + #Category, \ + CR_IDENTIFIER_(Category, Name, jmp), \ + &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_TEST_PROTOTYPE_(Category, Name) -# define CR_SUITE_BASE(Name, ...) \ - struct criterion_test_extra_data CR_SUITE_IDENTIFIER_(Name, extra) = \ - CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ - .file_ = __FILE__, \ - .line_ = 0, \ - __VA_ARGS__ \ - )); \ - struct criterion_suite CR_SUITE_IDENTIFIER_(Name, meta) = { \ - #Name, \ - &CR_SUITE_IDENTIFIER_(Name, extra), \ - }; \ - CR_SECTION_("cr_sts") \ - struct criterion_suite *CR_SUITE_IDENTIFIER_(Name, ptr) \ - = &CR_SUITE_IDENTIFIER_(Name, meta) CR_SECTION_SUFFIX_ +#define CR_SUITE_BASE(Name, ...) \ + struct criterion_test_extra_data CR_SUITE_IDENTIFIER_(Name, extra) = \ + CR_EXPAND(CRITERION_MAKE_STRUCT(criterion_test_extra_data, \ + .file_ = __FILE__, \ + .line_ = 0, \ + __VA_ARGS__ \ + )); \ + struct criterion_suite CR_SUITE_IDENTIFIER_(Name, meta) = { \ + #Name, \ + &CR_SUITE_IDENTIFIER_(Name, extra), \ + }; \ + CR_SECTION_("cr_sts") \ + struct criterion_suite *CR_SUITE_IDENTIFIER_(Name, ptr) \ + = &CR_SUITE_IDENTIFIER_(Name, meta) CR_SECTION_SUFFIX_ -# undef Test -# define Test(...) CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) -# undef TestSuite -# define TestSuite(...) CR_EXPAND(CR_SUITE_BASE(__VA_ARGS__, .sentinel_ = 0)) +#undef Test +#define Test(...) CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) +#undef TestSuite +#define TestSuite(...) CR_EXPAND(CR_SUITE_BASE(__VA_ARGS__, .sentinel_ = 0)) #endif /* !CRITERION_INTERNAL_TEST_H_ */ diff --git a/include/criterion/internal/theories.h b/include/criterion/internal/theories.h index 4749658..68fc163 100644 --- a/include/criterion/internal/theories.h +++ b/include/criterion/internal/theories.h @@ -22,23 +22,24 @@ * THE SOFTWARE. */ #ifndef CRITERION_INTERNAL_THEORIES_H_ -# define CRITERION_INTERNAL_THEORIES_H_ +#define CRITERION_INTERNAL_THEORIES_H_ -# include "test.h" +#include "test.h" -# ifdef __cplusplus -# include +#ifdef __cplusplus +# include using std::size_t; -# else -# include -# endif +#else +# include +#endif -# ifdef __cplusplus +#ifdef __cplusplus template -constexpr size_t criterion_va_num__(const T &...) { - return sizeof...(T); +constexpr size_t criterion_va_num__(const T & ...) +{ + return sizeof ... (T); } -# endif +#endif struct criterion_datapoints { size_t size; @@ -53,50 +54,51 @@ CR_API void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, CR_END_C_API -# ifdef __cplusplus -# define CR_TH_VA_NUM(Type, ...) criterion_va_num__(__VA_ARGS__) -# define CR_TH_TEMP_ARRAY(Type, ...) []() -> Type* { static Type arr[] = { __VA_ARGS__ }; return reinterpret_cast(&arr); }() -# else -# define CR_TH_VA_NUM(Type, ...) sizeof ((Type[]) { __VA_ARGS__ }) / sizeof (Type) -# define CR_TH_TEMP_ARRAY(Type, ...) &(Type[]) { __VA_ARGS__ } -# endif +#ifdef __cplusplus +# define CR_TH_VA_NUM(Type, ...) criterion_va_num__(__VA_ARGS__) +# define CR_TH_TEMP_ARRAY(Type, ...) []() -> Type * { static Type arr[] = { __VA_ARGS__ }; return reinterpret_cast(&arr); } () +#else +# define CR_TH_VA_NUM(Type, ...) sizeof ((Type[]) { __VA_ARGS__ }) / sizeof (Type) +# define CR_TH_TEMP_ARRAY(Type, ...) & (Type[]) { __VA_ARGS__ } +#endif -# define CR_TH_INTERNAL_TDPS(Category, Name) \ +#define CR_TH_INTERNAL_TDPS(Category, Name) \ static struct criterion_datapoints CR_IDENTIFIER_(Category, Name, dps)[] -# define CR_TH_INTERNAL_TDP(Category, Name) \ +#define CR_TH_INTERNAL_TDP(Category, Name) \ (CR_IDENTIFIER_(Category, Name, dps)) -# define CR_TH_INTERNAL_DP(Type, ...) { \ - sizeof (Type), \ - CR_EXPAND(CR_TH_VA_NUM(Type, __VA_ARGS__)), \ - #Type, \ +#define CR_TH_INTERNAL_DP(Type, ...) \ + { \ + sizeof (Type), \ + CR_EXPAND(CR_TH_VA_NUM(Type, __VA_ARGS__)), \ + #Type, \ CR_EXPAND(CR_TH_TEMP_ARRAY(Type, __VA_ARGS__)), \ } -# define CR_NB_DATAPOINTS(Var) \ +#define CR_NB_DATAPOINTS(Var) \ (sizeof (Var) / sizeof (struct criterion_datapoints)) -# define CR_VAARG_ID(Suffix, Category, Name, ...) \ +#define CR_VAARG_ID(Suffix, Category, Name, ...) \ CR_IDENTIFIER_(Category, Name, Suffix) -# define CR_THEORY_BASE(Args, ...) \ - void CR_EXPAND(CR_VAARG_ID(theory, __VA_ARGS__,))Args; \ - CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) { \ - cr_theory_main( \ - CR_EXPAND(CR_VAARG_ID(dps, __VA_ARGS__,)), \ - CR_NB_DATAPOINTS(CR_EXPAND(CR_VAARG_ID(dps, __VA_ARGS__,))), \ - (void(*)(void)) CR_EXPAND(CR_VAARG_ID(theory, __VA_ARGS__,)) \ - ); \ - } \ - void CR_EXPAND(CR_VAARG_ID(theory, __VA_ARGS__,))Args +#define CR_THEORY_BASE(Args, ...) \ + void CR_EXPAND(CR_VAARG_ID(theory, __VA_ARGS__, )) Args; \ + CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) { \ + cr_theory_main( \ + CR_EXPAND(CR_VAARG_ID(dps, __VA_ARGS__, )), \ + CR_NB_DATAPOINTS(CR_EXPAND(CR_VAARG_ID(dps, __VA_ARGS__, ))), \ + (void (*)(void))CR_EXPAND(CR_VAARG_ID(theory, __VA_ARGS__, )) \ + ); \ + } \ + void CR_EXPAND(CR_VAARG_ID(theory, __VA_ARGS__, )) Args -# define cr_assume_op_(Op, Actual, Expected) cr_assume((Actual) Op (Expected)) +#define cr_assume_op_(Op, Actual, Expected) cr_assume((Actual) Op(Expected)) -# define cr_assume_str_op_(Op, Actual, Expected) \ +#define cr_assume_str_op_(Op, Actual, Expected) \ cr_assume(strcmp((Actual), (Expected)) Op 0) -# undef Theory -# define Theory(Args, ...) CR_EXPAND(CR_THEORY_BASE(Args, __VA_ARGS__)) +#undef Theory +#define Theory(Args, ...) CR_EXPAND(CR_THEORY_BASE(Args, __VA_ARGS__)) #endif /* !CRITERION_INTERNAL_THEORIES_H_ */ diff --git a/include/criterion/logging.h b/include/criterion/logging.h index 360b1b4..1d6362a 100644 --- a/include/criterion/logging.h +++ b/include/criterion/logging.h @@ -26,12 +26,12 @@ * @brief Logging functions *****************************************************************************/ #ifndef CRITERION_LOGGING_H_ -# define CRITERION_LOGGING_H_ +#define CRITERION_LOGGING_H_ -# include "internal/common.h" -# include "internal/ordered-set.h" -# include "internal/deprecation.h" -# include "stats.h" +#include "internal/common.h" +#include "internal/ordered-set.h" +#include "internal/deprecation.h" +#include "stats.h" CR_BEGIN_C_API @@ -71,7 +71,7 @@ CR_API void cr_log(enum criterion_severity severity, const char *msg, ...); * @param[in] ... Additional arguments depending on msg * *****************************************************************************/ -# define cr_log_info(...) cr_log(CR_LOG_INFO, __VA_ARGS__) +#define cr_log_info(...) cr_log(CR_LOG_INFO, __VA_ARGS__) /** * Prints a warning message @@ -83,7 +83,7 @@ CR_API void cr_log(enum criterion_severity severity, const char *msg, ...); * @param[in] ... Additional arguments depending on msg * *****************************************************************************/ -# define cr_log_warn(...) cr_log(CR_LOG_WARNING, __VA_ARGS__) +#define cr_log_warn(...) cr_log(CR_LOG_WARNING, __VA_ARGS__) /** * Prints a error message @@ -95,7 +95,7 @@ CR_API void cr_log(enum criterion_severity severity, const char *msg, ...); * @param[in] ... Additional arguments depending on msg * *****************************************************************************/ -# define cr_log_error(...) cr_log(CR_LOG_ERROR, __VA_ARGS__) +#define cr_log_error(...) cr_log(CR_LOG_ERROR, __VA_ARGS__) struct criterion_logger { void (*log_pre_all )(struct criterion_test_set *set); @@ -120,56 +120,57 @@ extern struct criterion_logger normal_logging; CR_END_C_API -# define CR_NORMAL_LOGGING (&normal_logging) +#define CR_NORMAL_LOGGING (&normal_logging) -# ifdef __cplusplus -# include +#ifdef __cplusplus +# include -namespace criterion { namespace logging { +namespace criterion +{ namespace logging + { + static void(*const log)(enum criterion_severity, const char *, ...) = cr_log; -static void (*const log)(enum criterion_severity, const char *, ...) = cr_log; + class streambuf : public std::stringbuf { + public: + streambuf(enum criterion_severity severity__) + : std::stringbuf(), severity__(severity__) + {} -class streambuf : public std::stringbuf { -public: - streambuf(enum criterion_severity severity__) - : std::stringbuf(), severity__(severity__) - {} + virtual int sync() override + { + criterion::logging::log(severity__, "%s", str().c_str()); + str(std::string()); + return 0; + } + private: + enum criterion_severity severity__; + }; - virtual int sync() override { - criterion::logging::log(severity__, "%s", str().c_str()); - str(std::string()); - return 0; - } -private: - enum criterion_severity severity__; -}; + class stream : public std::ostream { + public: + stream(enum criterion_severity severity__) + : std::ostream(&buf), buf(severity__) + {} + private: + streambuf buf; + }; -class stream : public std::ostream { -public: - stream(enum criterion_severity severity__) - : std::ostream(&buf), buf(severity__) - {} -private: - streambuf buf; -}; + stream info { CR_LOG_INFO }; + stream warn { CR_LOG_WARNING }; + stream error { CR_LOG_ERROR }; + } } +#endif -stream info { CR_LOG_INFO }; -stream warn { CR_LOG_WARNING }; -stream error { CR_LOG_ERROR }; +/* Deprecated old logging system, schedule removal for 3.0 */ +#ifndef CRITERION_NO_COMPAT -}} -# endif +# define criterion_log(_, ...) CR_DEPRECATED("criterion_log is deprecated, please use cr_log instead.") cr_log_info(__VA_ARGS__) +# define criterion_info(...) CR_DEPRECATED("criterion_info is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) +# define criterion_pinfo(_, ...) CR_DEPRECATED("criterion_pinfo is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) +# define criterion_important(...) CR_DEPRECATED("criterion_important is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) +# define criterion_pimportant(_, ...) CR_DEPRECATED("criterion_pimportant is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) +# define criterion_perror(...) CR_DEPRECATED("criterion_perror is deprecated, please use cr_log_error instead.") cr_log_error(__VA_ARGS__) -// Deprecated old logging system, schedule removal for 3.0 -# ifndef CRITERION_NO_COMPAT - -# define criterion_log(_, ...) CR_DEPRECATED("criterion_log is deprecated, please use cr_log instead.") cr_log_info(__VA_ARGS__) -# define criterion_info(...) CR_DEPRECATED("criterion_info is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) -# define criterion_pinfo(_, ...) CR_DEPRECATED("criterion_pinfo is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) -# define criterion_important(...) CR_DEPRECATED("criterion_important is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) -# define criterion_pimportant(_, ...) CR_DEPRECATED("criterion_pimportant is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__) -# define criterion_perror(...) CR_DEPRECATED("criterion_perror is deprecated, please use cr_log_error instead.") cr_log_error(__VA_ARGS__) - -# endif /* !CRITERION_NO_COMPAT */ +#endif /* !CRITERION_NO_COMPAT */ #endif /* !CRITERION_LOGGING_H_ */ diff --git a/include/criterion/options.h b/include/criterion/options.h index 267bba2..95be026 100644 --- a/include/criterion/options.h +++ b/include/criterion/options.h @@ -26,11 +26,11 @@ * @brief criterion options *****************************************************************************/ #ifndef CRITERION_OPTIONS_H_ -# define CRITERION_OPTIONS_H_ +#define CRITERION_OPTIONS_H_ -# include -# include "logging.h" -# include "internal/common.h" +#include +#include "logging.h" +#include "internal/common.h" enum criterion_debugger { /** @@ -61,7 +61,6 @@ enum criterion_debugger { }; struct criterion_options { - /** * The current logging threshold. * diff --git a/include/criterion/output.h b/include/criterion/output.h index 4af8bd0..2574e6a 100644 --- a/include/criterion/output.h +++ b/include/criterion/output.h @@ -26,11 +26,11 @@ * @brief Report functions *****************************************************************************/ #ifndef CRITERION_OUTPUT_H_ -# define CRITERION_OUTPUT_H_ +#define CRITERION_OUTPUT_H_ -# include "stats.h" +#include "stats.h" -typedef void criterion_reporter(FILE *stream, struct criterion_global_stats *); +typedef void criterion_reporter (FILE *stream, struct criterion_global_stats *); /** * Register an output provider. diff --git a/include/criterion/parameterized.h b/include/criterion/parameterized.h index 817c3c9..db0576f 100644 --- a/include/criterion/parameterized.h +++ b/include/criterion/parameterized.h @@ -26,10 +26,10 @@ * @brief Parameterized tests *****************************************************************************/ #ifndef CRITERION_PARAMETERIZED_H_ -# define CRITERION_PARAMETERIZED_H_ +#define CRITERION_PARAMETERIZED_H_ -# include "alloc.h" -# include "assert.h" +#include "alloc.h" +#include "assert.h" /** * @defgroup ParameterizedBase Parameterized test & generator macros @@ -52,7 +52,7 @@ * (see criterion/types.h). * Example: `.exit_code = 1` */ -# define ParameterizedTest(Type, Suite, Name, ...) +#define ParameterizedTest(Type, Suite, Name, ...) < internal > /** * Defines the parameter generator prototype for the associated parameterized @@ -63,7 +63,7 @@ * @returns A constructed instance of criterion::parameters, or the result of * the cr_make_param_array macro. */ -# define ParameterizedTestParameters(Suite, Name) +#define ParameterizedTestParameters(Suite, Name) < internal > /** * Constructs a parameter list used as a return value for a parameter generator. @@ -77,27 +77,27 @@ * @param Cleanup The optional cleanup function for the array. * @returns The parameter list. */ -# define cr_make_param_array(Type, Array, Len, Cleanup) +#define cr_make_param_array(Type, Array, Len, Cleanup) < internal > /** @} */ -# ifdef __cplusplus -# include +#ifdef __cplusplus +# include -namespace criterion { - - /** - * Represents a C++ dynamic parameter list for a parameter generator. - * - * @ingroup ParameterizedBase - * - * @param T The type of the parameter. - */ - template - using parameters = std::vector>; +namespace criterion +{ +/** + * Represents a C++ dynamic parameter list for a parameter generator. + * + * @ingroup ParameterizedBase + * + * @param T The type of the parameter. + */ +template +using parameters = std::vector >; } -# endif +#endif -# include "internal/parameterized.h" +#include "internal/parameterized.h" #endif /* !CRITERION_PARAMETERIZED_H_ */ diff --git a/include/criterion/redirect.h b/include/criterion/redirect.h index d8bdc52..1599d4c 100644 --- a/include/criterion/redirect.h +++ b/include/criterion/redirect.h @@ -26,15 +26,15 @@ * @brief Redirect functions and file asserts *****************************************************************************/ #ifndef CRITERION_REDIRECT_H_ -# define CRITERION_REDIRECT_H_ +#define CRITERION_REDIRECT_H_ -# include "internal/common.h" +#include "internal/common.h" -# ifdef __cplusplus -# include -# else -# include -# endif +#ifdef __cplusplus +# include +#else +# include +#endif CR_BEGIN_C_API @@ -59,21 +59,21 @@ CR_API void cr_redirect_stdin(void); * * @returns the file handle. */ -CR_API CR_STDN FILE* cr_get_redirected_stdout(void); +CR_API CR_STDN FILE *cr_get_redirected_stdout(void); /** * Get a file handle representing the read-end of the redirected stderr. * * @returns the file handle. */ -CR_API CR_STDN FILE* cr_get_redirected_stderr(void); +CR_API CR_STDN FILE *cr_get_redirected_stderr(void); /** * Get a file handle representing the write-end of the redirected stdin. * * @returns the file handle. */ -CR_API CR_STDN FILE* cr_get_redirected_stdin(void); +CR_API CR_STDN FILE *cr_get_redirected_stdin(void); /** * Compare the contents of a file with a string. @@ -82,7 +82,7 @@ CR_API CR_STDN FILE* cr_get_redirected_stdin(void); * @param[in] str The string to compare the contents to. * @returns 1 if the contents of the file is equal to the string, 0 otherwise. */ -CR_API int cr_file_match_str(CR_STDN FILE* f, const char *str); +CR_API int cr_file_match_str(CR_STDN FILE *f, const char *str); /** * Compare the contents of a file with the contents of another file. @@ -91,7 +91,7 @@ CR_API int cr_file_match_str(CR_STDN FILE* f, const char *str); * @param[in] ref The second file to compare the contents to. * @returns 1 if the contents of the files are equal, 0 otherwise. */ -CR_API int cr_file_match_file(CR_STDN FILE* f, CR_STDN FILE* ref); +CR_API int cr_file_match_file(CR_STDN FILE *f, CR_STDN FILE *ref); /** * Create a file mock. @@ -124,7 +124,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_file_contents_eq_str(File, ExpectedContents, FormatString, ...) +#define cr_assert_file_contents_eq_str(File, ExpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c File are equal to the string \c ExpectedContents @@ -141,7 +141,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_file_contents_eq_str(File, ExpectedContents, FormatString, ...) +#define cr_expect_file_contents_eq_str(File, ExpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c File are not equal to the string @@ -160,7 +160,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_file_contents_neq_str(File, UnexpectedContents, FormatString, ...) +#define cr_assert_file_contents_neq_str(File, UnexpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c File are not equal to the string @@ -178,7 +178,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_file_contents_neq_str(File, UnexpectedContents, FormatString, ...) +#define cr_expect_file_contents_neq_str(File, UnexpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c File are equal to the contents of \c RefFile @@ -195,7 +195,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_file_contents_eq(File, RefFile, FormatString, ...) +#define cr_assert_file_contents_eq(File, RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c File are equal to the contents of \c RefFile @@ -211,7 +211,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_file_contents_eq(File, RefFile, FormatString, ...) +#define cr_expect_file_contents_eq(File, RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c File are not equal to the contents of @@ -230,7 +230,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_file_contents_neq(File, RefFile, FormatString, ...) +#define cr_assert_file_contents_neq(File, RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c File are not equal to the contents of @@ -248,7 +248,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_file_contents_neq(File, RefFile, FormatString, ...) +#define cr_expect_file_contents_neq(File, RefFile, FormatString, ...) < internal > /**@}*/ @@ -273,7 +273,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stdout_eq_str(ExpectedContents, FormatString, ...) +#define cr_assert_stdout_eq_str(ExpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are equal to the contents of the string @@ -290,7 +290,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stdout_eq_str(ExpectedContents, FormatString, ...) +#define cr_expect_stdout_eq_str(ExpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are not equal to the contents of the @@ -308,7 +308,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stdout_neq_str(UnexpectedContents, FormatString, ...) +#define cr_assert_stdout_neq_str(UnexpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are not equal to the contents of the @@ -325,7 +325,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stdout_neq_str(UnexpectedContents, FormatString, ...) +#define cr_expect_stdout_neq_str(UnexpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are equal to the contents of the string @@ -343,7 +343,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stderr_eq_str(ExpectedContents, FormatString, ...) +#define cr_assert_stderr_eq_str(ExpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are equal to the contents of the string @@ -360,7 +360,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stderr_eq_str(ExpectedContents, FormatString, ...) +#define cr_expect_stderr_eq_str(ExpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are not equal to the contents of the @@ -378,7 +378,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stderr_neq_str(UnexpectedContents, FormatString, ...) +#define cr_assert_stderr_neq_str(UnexpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are not equal to the contents of the @@ -395,7 +395,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stderr_neq_str(UnexpectedContents, FormatString, ...) +#define cr_expect_stderr_neq_str(UnexpectedContents, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are equal to the contents of \c RefFile @@ -411,7 +411,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stdout_eq(RefFile, FormatString, ...) +#define cr_assert_stdout_eq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are equal to the contents of \c RefFile @@ -426,7 +426,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stdout_eq(RefFile, FormatString, ...) +#define cr_expect_stdout_eq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are not equal to the contents of \c @@ -444,7 +444,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stdout_neq(RefFile, FormatString, ...) +#define cr_assert_stdout_neq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stdout are not equal to the contents of \c @@ -461,7 +461,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stdout_neq(RefFile, FormatString, ...) +#define cr_expect_stdout_neq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are equal to the contents of \c RefFile @@ -477,7 +477,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stderr_eq(RefFile, FormatString, ...) +#define cr_assert_stderr_eq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are equal to the contents of \c RefFile @@ -492,7 +492,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stderr_eq(RefFile, FormatString, ...) +#define cr_expect_stderr_eq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are not equal to the contents of \c @@ -510,7 +510,7 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_assert_stderr_neq(RefFile, FormatString, ...) +#define cr_assert_stderr_neq(RefFile, FormatString, ...) < internal > /** * Passes if the contents of \c stderr are not equal to the contents of \c @@ -527,43 +527,48 @@ CR_END_C_API * @param[in] ... (optional) format string parameters * *****************************************************************************/ -# define cr_expect_stderr_neq(RefFile, FormatString, ...) +#define cr_expect_stderr_neq(RefFile, FormatString, ...) < internal > /**@}*/ -# ifdef __cplusplus -# include "internal/stream.hxx" +#ifdef __cplusplus +# include "internal/stream.hxx" -namespace criterion { +namespace criterion +{ +typedef internal::basic_ofstream ofstream; +typedef internal::basic_ifstream ifstream; +typedef internal::basic_fstream fstream; - typedef internal::basic_ofstream ofstream; - typedef internal::basic_ifstream ifstream; - typedef internal::basic_fstream fstream; +static inline ofstream &get_redirected_cin(void) +{ + return internal::get_redirected_out_stream_::call(cr_get_redirected_stdin()); +} - static inline ofstream& get_redirected_cin(void) { - return internal::get_redirected_out_stream_::call(cr_get_redirected_stdin()); - } +static inline ifstream &get_redirected_cout(void) +{ + return internal::get_redirected_in_stream_::call(cr_get_redirected_stdout()); +} - static inline ifstream& get_redirected_cout(void) { - return internal::get_redirected_in_stream_::call(cr_get_redirected_stdout()); - } +static inline ifstream &get_redirected_cerr(void) +{ + return internal::get_redirected_in_stream_::call(cr_get_redirected_stderr()); +} - static inline ifstream& get_redirected_cerr(void) { - return internal::get_redirected_in_stream_::call(cr_get_redirected_stderr()); - } +# if __GNUC__ >= 5 +static inline fstream mock_file(size_t max_size) +{ + return fstream(cr_mock_file_size(max_size)); +} -# if __GNUC__ >= 5 - static inline fstream mock_file(size_t max_size) { - return fstream(cr_mock_file_size(max_size)); - } - - static inline fstream mock_file(void) { - return mock_file(4096); - } -# endif +static inline fstream mock_file(void) +{ + return mock_file(4096); } # endif +} +#endif -# include "internal/redirect.h" +#include "internal/redirect.h" #endif /* !CRITERION_REDIRECT_H_ */ diff --git a/include/criterion/stats.h b/include/criterion/stats.h index 7f63d4d..b289136 100644 --- a/include/criterion/stats.h +++ b/include/criterion/stats.h @@ -26,14 +26,14 @@ * @brief Test stats *****************************************************************************/ #ifndef CRITERION_STATS_H_ -# define CRITERION_STATS_H_ +#define CRITERION_STATS_H_ -# include "types.h" -# include "internal/deprecation.h" +#include "types.h" +#include "internal/deprecation.h" enum criterion_test_status { - CR_STATUS_PASSED = 0, - CR_STATUS_FAILED = 1, + CR_STATUS_PASSED = 0, + CR_STATUS_FAILED = 1, CR_STATUS_SKIPPED = 2, }; diff --git a/include/criterion/theories.h b/include/criterion/theories.h index 689dc88..52c3584 100644 --- a/include/criterion/theories.h +++ b/include/criterion/theories.h @@ -26,9 +26,9 @@ * @brief Theory tests *****************************************************************************/ #ifndef CRITERION_THEORIES_H_ -# define CRITERION_THEORIES_H_ +#define CRITERION_THEORIES_H_ -# include "criterion.h" +#include "criterion.h" CR_BEGIN_C_API @@ -66,7 +66,7 @@ CR_END_C_API * (see criterion/types.h). * Example: .exit_code = 1 */ -# define Theory(Params, Suite, Name, ...) +#define Theory(Params, Suite, Name, ...) < internal > /** * Defines an array of data points. @@ -87,7 +87,7 @@ CR_END_C_API * @param Suite The name of the test suite containing this test. * @param Name The name of the test. */ -# define TheoryDataPoints(Suite, Name) CR_TH_INTERNAL_TDPS(Suite, Name) +#define TheoryDataPoints(Suite, Name) CR_TH_INTERNAL_TDPS(Suite, Name) /** * Defines a new set of data points. @@ -95,7 +95,7 @@ CR_END_C_API * @param Type The type of each data point in the set. * @param ... The data points in the set. */ -# define DataPoints(Type, ...) CR_EXPAND(CR_TH_INTERNAL_DP(Type, __VA_ARGS__)) +#define DataPoints(Type, ...) CR_EXPAND(CR_TH_INTERNAL_DP(Type, __VA_ARGS__)) /**@}*/ @@ -114,10 +114,10 @@ CR_END_C_API * @param[in] Condition Condition to test * *****************************************************************************/ -# define cr_assume(Condition) \ - do { \ - if (!(Condition)) \ - cr_theory_abort(); \ +#define cr_assume(Condition) \ + do { \ + if (!(Condition)) \ + cr_theory_abort(); \ } while (0) /** @@ -130,7 +130,7 @@ CR_END_C_API * @param[in] Condition Condition to test * *****************************************************************************/ -# define cr_assume_not(Condition) cr_assume(!(Condition)) +#define cr_assume_not(Condition) cr_assume(!(Condition)) /** * Assumes `Actual` is equal to `Expected` @@ -143,7 +143,7 @@ CR_END_C_API * @param[in] Expected Expected value * *****************************************************************************/ -# define cr_assume_eq(Actual, Expected) cr_assume_op_(==, Actual, Expected) +#define cr_assume_eq(Actual, Expected) cr_assume_op_(==, Actual, Expected) /** * Assumes `Actual` is not equal to `Unexpected` @@ -156,7 +156,7 @@ CR_END_C_API * @param[in] Unexpected Unexpected value * *****************************************************************************/ -# define cr_assume_neq(Actual, Unexpected) cr_assume_op_(!=, Actual, Unexpected) +#define cr_assume_neq(Actual, Unexpected) cr_assume_op_(!=, Actual, Unexpected) /** * Assumes `Actual` is greater than `Reference` @@ -169,7 +169,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_gt(Actual, Reference) cr_assume_op_(>, Actual, Reference) +#define cr_assume_gt(Actual, Reference) cr_assume_op_(>, Actual, Reference) /** * Assumes `Actual` is greater or equal to `Reference` @@ -182,7 +182,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_geq(Actual, Reference) cr_assume_op_(>=, Actual, Reference) +#define cr_assume_geq(Actual, Reference) cr_assume_op_(>=, Actual, Reference) /** * Assumes `Actual` is less than `Reference` @@ -195,7 +195,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_lt(Actual, Reference) cr_assume_op_(<, Actual, Reference) +#define cr_assume_lt(Actual, Reference) cr_assume_op_(<, Actual, Reference) /** * Assumes `Actual` is less or equal to `Reference` @@ -208,7 +208,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_leq(Actual, Reference) cr_assume_op_(<=, Actual, Reference) +#define cr_assume_leq(Actual, Reference) cr_assume_op_(<=, Actual, Reference) /** * Assumes `Value` is NULL. @@ -220,7 +220,7 @@ CR_END_C_API * @param[in] Value Value to test * *****************************************************************************/ -# define cr_assume_null(Value) cr_assume_eq(Value, NULL) +#define cr_assume_null(Value) cr_assume_eq(Value, NULL) /** * Assumes `Value` is not NULL. @@ -232,7 +232,7 @@ CR_END_C_API * @param[in] Value Value to test * *****************************************************************************/ -# define cr_assume_not_null(Value) cr_assume_neq(Value, NULL) +#define cr_assume_not_null(Value) cr_assume_neq(Value, NULL) /** * Assumes `Actual` is equal to `Expected` with a tolerance of `Epsilon` @@ -248,9 +248,9 @@ CR_END_C_API * @param[in] Epsilon Tolerance between Actual and Expected * *****************************************************************************/ -# define cr_assume_float_eq(Actual, Expected, Epsilon) \ - cr_assume((Expected) - (Actual) <= (Epsilon) \ - && (Actual) - (Expected) <= (Epsilon)) +#define cr_assume_float_eq(Actual, Expected, Epsilon) \ + cr_assume((Expected) - (Actual) <= (Epsilon) \ + && (Actual) - (Expected) <= (Epsilon)) /** * Assumes `Actual` is not equal to `Expected` with a tolerance of `Epsilon` @@ -266,9 +266,9 @@ CR_END_C_API * @param[in] Epsilon Tolerance between Actual and Expected * *****************************************************************************/ -# define cr_assume_float_neq(Actual, Expected, Epsilon) \ - cr_assume((Expected) - (Actual) > (Epsilon) \ - || (Actual) - (Expected) > (Epsilon)) +#define cr_assume_float_neq(Actual, Expected, Epsilon) \ + cr_assume((Expected) - (Actual) > (Epsilon) \ + || (Actual) - (Expected) > (Epsilon)) /** * Assumes `Actual` is lexicographically equal to `Expected` @@ -281,7 +281,7 @@ CR_END_C_API * @param[in] Expected Expected string * *****************************************************************************/ -# define cr_assume_str_eq(Actual, Expected) cr_assume_str_op_(==, Actual, Expected) +#define cr_assume_str_eq(Actual, Expected) cr_assume_str_op_(==, Actual, Expected) /** * Assumes `Actual` is not lexicographically equal to `Unexpected` @@ -294,7 +294,7 @@ CR_END_C_API * @param[in] Unexpected Unexpected string * *****************************************************************************/ -# define cr_assume_str_neq(Actual, Unexpected) cr_assume_str_op_(!=, Actual, Unexpected) +#define cr_assume_str_neq(Actual, Unexpected) cr_assume_str_op_(!=, Actual, Unexpected) /** * Assumes `Actual` is lexicographically less than `Reference` @@ -307,7 +307,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_str_lt(Actual, Reference) cr_assume_str_op_(<, Actual, Reference) +#define cr_assume_str_lt(Actual, Reference) cr_assume_str_op_(<, Actual, Reference) /** * Assumes `Actual` is lexicographically less or equal to `Reference` @@ -320,7 +320,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_str_leq(Actual, Reference) cr_assume_str_op_(<=, Actual, Reference) +#define cr_assume_str_leq(Actual, Reference) cr_assume_str_op_(<=, Actual, Reference) /** * Assumes `Actual` is lexicographically greater than `Reference` @@ -333,7 +333,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_str_gt(Actual, Reference) cr_assume_str_op_(>, Actual, Reference) +#define cr_assume_str_gt(Actual, Reference) cr_assume_str_op_(>, Actual, Reference) /** * Assumes `Actual` is lexicographically greater or equal to `Reference` @@ -346,7 +346,7 @@ CR_END_C_API * @param[in] Reference Reference value * *****************************************************************************/ -# define cr_assume_str_geq(Actual, Reference) cr_assume_str_op_(>=, Actual, Reference) +#define cr_assume_str_geq(Actual, Reference) cr_assume_str_op_(>=, Actual, Reference) /** * Assumes `Actual` is byte-to-byte equal to `Expected` @@ -362,7 +362,7 @@ CR_END_C_API * @param[in] Size The size of both arrays * *****************************************************************************/ -# define cr_assume_arr_eq(Actual, Expected, Size) cr_assume(!memcmp((Actual), (Expected), (Size))) +#define cr_assume_arr_eq(Actual, Expected, Size) cr_assume(!memcmp((Actual), (Expected), (Size))) /** * Assumes `Actual` is not byte-to-byte equal to `Unexpected` * @@ -377,24 +377,24 @@ CR_END_C_API * @param[in] Size The size of both arrays * *****************************************************************************/ -# define cr_assume_arr_neq(Actual, Unexpected, Size) cr_assume(memcmp((Actual), (Unexpected), (Size))) +#define cr_assume_arr_neq(Actual, Unexpected, Size) cr_assume(memcmp((Actual), (Unexpected), (Size))) /**@}*/ -// Deprecated +/* Deprecated */ -# ifndef CRITERION_NO_COMPAT -# define cr_assume_strings_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_eq, cr_assume_str_eq) cr_assume_str_eq(__VA_ARGS__) -# define cr_assume_strings_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_neq, cr_assume_str_neq) cr_assume_str_neq(__VA_ARGS__) -# define cr_assume_strings_lt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_lt, cr_assume_str_lt) cr_assume_str_lt(__VA_ARGS__) -# define cr_assume_strings_leq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_leq, cr_assume_str_leq) cr_assume_str_leq(__VA_ARGS__) -# define cr_assume_strings_gt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_gt, cr_assume_str_gt) cr_assume_str_gt(__VA_ARGS__) -# define cr_assume_strings_geq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_geq, cr_assume_str_geq) cr_assume_str_geq(__VA_ARGS__) +#ifndef CRITERION_NO_COMPAT +# define cr_assume_strings_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_eq, cr_assume_str_eq) cr_assume_str_eq(__VA_ARGS__) +# define cr_assume_strings_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_neq, cr_assume_str_neq) cr_assume_str_neq(__VA_ARGS__) +# define cr_assume_strings_lt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_lt, cr_assume_str_lt) cr_assume_str_lt(__VA_ARGS__) +# define cr_assume_strings_leq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_leq, cr_assume_str_leq) cr_assume_str_leq(__VA_ARGS__) +# define cr_assume_strings_gt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_gt, cr_assume_str_gt) cr_assume_str_gt(__VA_ARGS__) +# define cr_assume_strings_geq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_geq, cr_assume_str_geq) cr_assume_str_geq(__VA_ARGS__) -# define cr_assume_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_arrays_eq, cr_assume_arr_eq) cr_assume_arr_eq(__VA_ARGS__) -# define cr_assume_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_arrays_neq, cr_assume_arr_neq) cr_assume_arr_neq(__VA_ARGS__) -# endif +# define cr_assume_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_arrays_eq, cr_assume_arr_eq) cr_assume_arr_eq(__VA_ARGS__) +# define cr_assume_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_arrays_neq, cr_assume_arr_neq) cr_assume_arr_neq(__VA_ARGS__) +#endif -# include "internal/theories.h" +#include "internal/theories.h" #endif /* !CRITERION_THEORIES_H_ */ diff --git a/include/criterion/types.h b/include/criterion/types.h index 69290cc..3bf1397 100644 --- a/include/criterion/types.h +++ b/include/criterion/types.h @@ -26,29 +26,29 @@ * @brief Types for tests *****************************************************************************/ #ifndef CRITERION_TYPES_H_ -# define CRITERION_TYPES_H_ +#define CRITERION_TYPES_H_ -# include "alloc.h" -# ifdef __cplusplus -# include -# include +#include "alloc.h" +#ifdef __cplusplus +# include +# include using std::size_t; -# else -# include -# include -# endif -# include "internal/common.h" +#else +# include +# include +#endif +#include "internal/common.h" /** * Enumerates the supported languages for tests */ enum criterion_language { - CR_LANG_C, //!< C - CR_LANG_CXX, //!< C++ - CR_LANG_OBJC, //!< Objective-C - CR_LANG_OBJCXX, //!< Objective-C++ + CR_LANG_C, /* !< C */ + CR_LANG_CXX, /* !< C++ */ + CR_LANG_OBJC, /* !< Objective-C */ + CR_LANG_OBJCXX, /* !< Objective-C++ */ - CR_LANG_SIZE_ // leave this at the end + CR_LANG_SIZE_ /* leave this at the end */ }; /** @@ -76,8 +76,8 @@ struct criterion_test_params; * the Test and TestSuite macros, or other means. */ struct criterion_test_extra_data { - /// @cond CRITERION_TEST_EXTRA_DATA_PRIVATE_API - // Start of private API + /* / @cond CRITERION_TEST_EXTRA_DATA_PRIVATE_API + Start of private API */ /* * Warning: the fields below are not meant to be set manually. * Setting them improperly *will* wreck havock in your tests. @@ -92,8 +92,8 @@ struct criterion_test_extra_data { const char *identifier_; const char *file_; unsigned line_; - // Enf of private API - /// @endcond + /* Enf of private API + / @endcond */ /** * The setup test fixture. diff --git a/samples/asserts.c b/samples/asserts.c index 7cdcf86..b3125b7 100644 --- a/samples/asserts.c +++ b/samples/asserts.c @@ -15,7 +15,7 @@ Test(asserts, base) { Test(asserts, old_school) { cr_expect_fail("You can fail an assertion with a message from anywhere"); - cr_assert_fail(); // or without a message + cr_assert_fail(); /* or without a message */ } Test(asserts, string) { @@ -57,27 +57,28 @@ struct dummy_struct { size_t b; }; -int eq_dummy(struct dummy_struct *a, struct dummy_struct *b) { +int eq_dummy(struct dummy_struct *a, struct dummy_struct *b) +{ return a->a != b->a || a->b != b->b; } Test(asserts, array) { - int arr1[] = {1, 2, 3, 4}; - int arr2[] = {4, 3, 2, 1}; + int arr1[] = { 1, 2, 3, 4 }; + int arr2[] = { 4, 3, 2, 1 }; cr_assert_arr_eq(arr1, arr1, 4 * sizeof (int)); cr_assert_arr_neq(arr1, arr2, 4 * sizeof (int)); #ifdef __GNUC__ - struct dummy_struct s1[] = {{4, 2}, {2, 4}}; + struct dummy_struct s1[] = { { 4, 2 }, { 2, 4 } }; struct dummy_struct s2[2]; - memset(s2, 0xFF, sizeof(s2)); + memset(s2, 0xFF, sizeof (s2)); s2[0].a = 4; s2[0].b = 2; s2[1].a = 2; s2[1].b = 4; - // cr_assert_arr_eq(s1, s2, 2); not guaranteed to work on structs. + /* cr_assert_arr_eq(s1, s2, 2); not guaranteed to work on structs. */ cr_assert_arr_eq_cmp(s1, s2, 2, eq_dummy); #endif } diff --git a/samples/asserts.cc b/samples/asserts.cc index e87d90d..640ef19 100644 --- a/samples/asserts.cc +++ b/samples/asserts.cc @@ -18,7 +18,7 @@ Test(asserts, base) { Test(asserts, old_school) { cr_expect_fail("You can fail an assertion with a message from anywhere"); - cr_assert_fail(); // or without a message + cr_assert_fail(); /* or without a message */ } Test(asserts, string) { @@ -59,24 +59,27 @@ struct dummy_struct { char a; size_t b; - bool operator==(const struct dummy_struct& rhs) const { + bool operator==(const struct dummy_struct &rhs) const + { return this->a == rhs.a && this->b == rhs.b; } - bool operator<(const struct dummy_struct& rhs) const { + bool operator<(const struct dummy_struct &rhs) const + { return this->a < rhs.a; } }; -int eq_dummy(struct dummy_struct *a, struct dummy_struct *b) { +int eq_dummy(struct dummy_struct *a, struct dummy_struct *b) +{ return *a == *b ? 0 : (*a < *b ? -1 : 1); } Test(asserts, array) { - // 1. (recommended): use std::array and cr_assert_eq - std::array cpparr1 = {{{4, 2}, {2, 4}}}; + /* 1. (recommended): use std::array and cr_assert_eq */ + std::array cpparr1 = { { { 4, 2 }, { 2, 4 } } }; std::array cpparr2; - memset(&cpparr2[0], 0xFF, 2 * sizeof(struct dummy_struct)); + memset(&cpparr2[0], 0xFF, 2 * sizeof (struct dummy_struct)); cpparr2[0].a = 4; cpparr2[0].b = 2; cpparr2[1].a = 2; @@ -84,24 +87,24 @@ Test(asserts, array) { cr_assert_eq(cpparr1, cpparr2); - // 2. Compare arrays byte-to-byte - int arr1[] = {1, 2, 3, 4}; - int arr2[] = {4, 3, 2, 1}; + /* 2. Compare arrays byte-to-byte */ + int arr1[] = { 1, 2, 3, 4 }; + int arr2[] = { 4, 3, 2, 1 }; cr_assert_arr_eq(arr1, arr1, 4 * sizeof (int)); cr_assert_arr_neq(arr1, arr2, 4 * sizeof (int)); - // 3. Compare arrays with a comparison function - struct dummy_struct s1[] = {{4, 2}, {2, 4}}; + /* 3. Compare arrays with a comparison function */ + struct dummy_struct s1[] = { { 4, 2 }, { 2, 4 } }; struct dummy_struct s2[2]; - memset(s2, 0xFF, sizeof(s2)); + memset(s2, 0xFF, sizeof (s2)); s2[0].a = 4; s2[0].b = 2; s2[1].a = 2; s2[1].b = 4; - // cr_assert_arr_eq(&s1, &s2, 2 * sizeof (struct dummy_struct)); - // isn't guaranteed to work on structs. + /* cr_assert_arr_eq(&s1, &s2, 2 * sizeof (struct dummy_struct)); + isn't guaranteed to work on structs. */ cr_assert_arr_eq_cmp(&s1, &s2, 2, eq_dummy); } diff --git a/samples/fixtures.c b/samples/fixtures.c index 1f7851c..b9d2ec9 100644 --- a/samples/fixtures.c +++ b/samples/fixtures.c @@ -1,11 +1,13 @@ #include #include -void setup(void) { +void setup(void) +{ puts("Runs before the test"); } -void teardown(void) { +void teardown(void) +{ puts("Runs after the test"); } diff --git a/samples/fixtures.cc b/samples/fixtures.cc index 1f7851c..b9d2ec9 100644 --- a/samples/fixtures.cc +++ b/samples/fixtures.cc @@ -1,11 +1,13 @@ #include #include -void setup(void) { +void setup(void) +{ puts("Runs before the test"); } -void teardown(void) { +void teardown(void) +{ puts("Runs after the test"); } diff --git a/samples/log.cc b/samples/log.cc index 89eeed1..6b6e0ef 100644 --- a/samples/log.cc +++ b/samples/log.cc @@ -7,12 +7,12 @@ using criterion::logging::error; Test(logging, stream) { info << "This is an informational message. They are not displayed " - "by default." + "by default." << std::endl; warn << "This is a warning. They indicate some possible malfunction " - "or misconfiguration in the test." + "or misconfiguration in the test." << std::endl; error << "This is an error. They indicate serious problems and " - "are usually shown before the test is aborted." + "are usually shown before the test is aborted." << std::endl; } diff --git a/samples/more-suites.c b/samples/more-suites.c index 95d7039..b71661a 100644 --- a/samples/more-suites.c +++ b/samples/more-suites.c @@ -1,9 +1,11 @@ #include -void setup_suite(void) { +void setup_suite(void) +{ } -void teardown_suite(void) { +void teardown_suite(void) +{ } TestSuite(suite1, .init = setup_suite, .fini = teardown_suite); @@ -18,4 +20,5 @@ Test(suite2, test) { TestSuite(disabled, .disabled = true); -Test(disabled, test) {} +Test(disabled, test) { +} diff --git a/samples/more-suites.cc b/samples/more-suites.cc index 95d7039..b71661a 100644 --- a/samples/more-suites.cc +++ b/samples/more-suites.cc @@ -1,9 +1,11 @@ #include -void setup_suite(void) { +void setup_suite(void) +{ } -void teardown_suite(void) { +void teardown_suite(void) +{ } TestSuite(suite1, .init = setup_suite, .fini = teardown_suite); @@ -18,4 +20,5 @@ Test(suite2, test) { TestSuite(disabled, .disabled = true); -Test(disabled, test) {} +Test(disabled, test) { +} diff --git a/samples/parameterized.c b/samples/parameterized.c index edb123e..174b94c 100644 --- a/samples/parameterized.c +++ b/samples/parameterized.c @@ -1,7 +1,7 @@ #include #include -// Basic usage +/* Basic usage */ ParameterizedTestParameters(params, simple) { static int vals[] = { 1, 2, 3 }; @@ -13,7 +13,7 @@ ParameterizedTest(int *val, params, simple) { cr_assert_fail("Parameter: %d", *val); } -// Multiple parameters must be coalesced in a single parameter +/* Multiple parameters must be coalesced in a single parameter */ struct parameter_tuple { int i; @@ -22,9 +22,9 @@ struct parameter_tuple { ParameterizedTestParameters(params, multiple) { static struct parameter_tuple params[] = { - {1, 2}, - {3, 4}, - {5, 6}, + { 1, 2 }, + { 3, 4 }, + { 5, 6 }, }; return cr_make_param_array(struct parameter_tuple, params, sizeof (params) / sizeof (struct parameter_tuple)); @@ -34,27 +34,30 @@ ParameterizedTest(struct parameter_tuple *tup, params, multiple) { cr_assert_fail("Parameters: (%d, %f)", tup->i, tup->d); } -// Cleaning up dynamically generated parameters +/* Cleaning up dynamically generated parameters */ -// you **MUST** use cr_malloc, cr_free, cr_realloc, and cr_calloc instead of their -// unprefixed counterparts to allocate dynamic memory in parameters, otherwise -// this will crash. +/* you **MUST** use cr_malloc, cr_free, cr_realloc, and cr_calloc instead of their + unprefixed counterparts to allocate dynamic memory in parameters, otherwise + this will crash. */ struct parameter_tuple_dyn { int i; double *d; }; -void free_params(struct criterion_test_params *crp) { +void free_params(struct criterion_test_params *crp) +{ for (size_t i = 0; i < crp->length; ++i) { - struct parameter_tuple_dyn *tup = (struct parameter_tuple_dyn*) crp->params + i; + struct parameter_tuple_dyn *tup = (struct parameter_tuple_dyn *) crp->params + i; cr_free(tup->d); } cr_free(crp->params); } -double *gen_double(double val) { +double *gen_double(double val) +{ double *ptr = cr_malloc(sizeof (double)); + *ptr = val; return ptr; } @@ -63,6 +66,7 @@ ParameterizedTestParameters(params, cleanup) { const size_t nb_tuples = 3; struct parameter_tuple_dyn *params = cr_malloc(sizeof (struct parameter_tuple_dyn) * nb_tuples); + params[0] = (struct parameter_tuple_dyn) { 1, gen_double(2) }; params[1] = (struct parameter_tuple_dyn) { 3, gen_double(4) }; params[2] = (struct parameter_tuple_dyn) { 5, gen_double(6) }; diff --git a/samples/parameterized.cc b/samples/parameterized.cc index 424d6d6..fff6406 100644 --- a/samples/parameterized.cc +++ b/samples/parameterized.cc @@ -1,6 +1,6 @@ #include -// Basic usage +/* Basic usage */ ParameterizedTestParameters(params, simple) { static int vals[] = { 1, 2, 3 }; @@ -12,7 +12,7 @@ ParameterizedTest(int *val, params, simple) { cr_assert_fail("Parameter: %d", *val); } -// Multiple parameters must be coalesced in a single parameter +/* Multiple parameters must be coalesced in a single parameter */ struct parameter_tuple { int i; @@ -21,9 +21,9 @@ struct parameter_tuple { ParameterizedTestParameters(params, multiple) { static struct parameter_tuple params[] = { - {1, 2}, - {3, 4}, - {5, 6}, + { 1, 2 }, + { 3, 4 }, + { 5, 6 }, }; return criterion_test_params(params); @@ -33,14 +33,14 @@ ParameterizedTest(struct parameter_tuple *tup, params, multiple) { cr_assert_fail("Parameters: (%d, %f)", tup->i, tup->d); } -// Using dynamically generated parameters +/* Using dynamically generated parameters */ -// you **MUST** use new_obj, new_arr, delete_obj, delete_arr instead of -// the new, new[], delete and delete[] operators (respectively) to allocate and -// deallocate dynamic memory in parameters, otherwise this will crash. +/* you **MUST** use new_obj, new_arr, delete_obj, delete_arr instead of + the new, new[], delete and delete[] operators (respectively) to allocate and + deallocate dynamic memory in parameters, otherwise this will crash. */ -// the criterion::allocator allocator may be used with STL containers to -// allocate objects with the functions described above. +/* the criterion::allocator allocator may be used with STL containers to + allocate objects with the functions described above. */ using criterion::new_obj; using criterion::new_arr; @@ -49,7 +49,7 @@ using criterion::delete_arr; struct parameter_tuple_dyn { int i; - std::unique_ptr d; + std::unique_ptr d; parameter_tuple_dyn() : i(0), d(nullptr, criterion::free) {} parameter_tuple_dyn(int i, double *d) : i(i), d(d, criterion::free) {} @@ -62,11 +62,11 @@ ParameterizedTestParameters(params, cleanup) { params.push_back(parameter_tuple_dyn(3, new_obj(4))); params.push_back(parameter_tuple_dyn(5, new_obj(6))); - // A criterion::parameters can be returned in place of a - // criterion_test_params. + /* A criterion::parameters can be returned in place of a + criterion_test_params. */ return params; } -ParameterizedTest(parameter_tuple_dyn *tup, params, cleanup) { +ParameterizedTest(parameter_tuple_dyn * tup, params, cleanup) { cr_assert_fail("Parameters: (%d, %f)", tup->i, *tup->d); } diff --git a/samples/redirect.c b/samples/redirect.c index 9a0db12..a6fbbd4 100644 --- a/samples/redirect.c +++ b/samples/redirect.c @@ -4,9 +4,10 @@ #include #include -// Testing stdout/stderr +/* Testing stdout/stderr */ -void redirect_all_std(void) { +void redirect_all_std(void) +{ cr_redirect_stdout(); cr_redirect_stderr(); } @@ -23,16 +24,19 @@ Test(redirect, test_outputs, .init = redirect_all_std) { cr_assert_stderr_eq_str("bar"); } -// Testing general I/O with sample command-line rot13 +/* Testing general I/O with sample command-line rot13 */ -char rot13_char(char c) { +char rot13_char(char c) +{ return isalpha(c) ? (c - 'a' + 13) % 26 + 'a' : c; } -void rot13_io(void) { +void rot13_io(void) +{ char buf[512]; size_t read; + while ((read = fread(buf, 1, sizeof (buf), stdin)) > 0) { for (size_t i = 0; i < read; ++i) buf[i] = rot13_char(buf[i]); @@ -42,7 +46,8 @@ void rot13_io(void) { } Test(redirect, rot13, .init = cr_redirect_stdout) { - FILE* f_stdin = cr_get_redirected_stdin(); + FILE *f_stdin = cr_get_redirected_stdin(); + fprintf(f_stdin, "the quick brown fox jumps over the lazy dog"); fclose(f_stdin); diff --git a/samples/redirect.cc b/samples/redirect.cc index 6ff5d81..8369de7 100644 --- a/samples/redirect.cc +++ b/samples/redirect.cc @@ -5,9 +5,10 @@ #include #include -// Testing stdout/stderr +/* Testing stdout/stderr */ -void redirect_all_std(void) { +void redirect_all_std(void) +{ cr_redirect_stdout(); cr_redirect_stderr(); } @@ -20,13 +21,15 @@ Test(redirect, test_outputs, .init = redirect_all_std) { cr_assert_stderr_eq_str("bar"); } -// Testing general I/O with sample command-line rot13 +/* Testing general I/O with sample command-line rot13 */ -char rot13_char(char c) { +char rot13_char(char c) +{ return std::isalpha(c) ? (c - 'a' + 13) % 26 + 'a' : c; } -void rot13_io(void) { +void rot13_io(void) +{ std::string s; std::cin >> s; @@ -36,7 +39,7 @@ void rot13_io(void) { } Test(redirect, rot13, .init = cr_redirect_stdout) { - auto& f_cin = criterion::get_redirected_cin(); + auto &f_cin = criterion::get_redirected_cin(); f_cin << "the quick brown fox jumps over the lazy dog"; f_cin.close(); diff --git a/samples/signal.c b/samples/signal.c index c717317..72a37fc 100644 --- a/samples/signal.c +++ b/samples/signal.c @@ -15,17 +15,17 @@ Test(simple, uncaught) { crash(); } - -// Cross platform segfault simulator â„¢ -// a.k.a. "I can't believe I have to write this for a sample" +/* Cross platform segfault simulator â„¢ + a.k.a. "I can't believe I have to write this for a sample" */ #ifdef _WIN32 # include #endif -void crash(void) { +void crash(void) +{ #ifdef _WIN32 - // This translates to a SIGSEGV + /* This translates to a SIGSEGV */ RaiseException(EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL); #else raise(SIGSEGV); diff --git a/samples/signal.cc b/samples/signal.cc index 42cc76f..f99c51b 100644 --- a/samples/signal.cc +++ b/samples/signal.cc @@ -15,16 +15,17 @@ Test(simple, uncaught) { crash(); } -// Cross platform segfault simulator â„¢ -// a.k.a. "I can't believe I have to write this for a sample" +/* Cross platform segfault simulator â„¢ + a.k.a. "I can't believe I have to write this for a sample" */ #ifdef _WIN32 # include #endif -void crash(void) { +void crash(void) +{ #ifdef _WIN32 - // This translates to a SIGSEGV + /* This translates to a SIGSEGV */ RaiseException(EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL); #else std::raise(SIGSEGV); diff --git a/samples/tests/exception.cc b/samples/tests/exception.cc index 2cbf7f3..7341323 100644 --- a/samples/tests/exception.cc +++ b/samples/tests/exception.cc @@ -1,18 +1,28 @@ #include #include -void raise_std(void) { +void raise_std(void) +{ throw std::invalid_argument("Some exception message"); } -void raise_any(void) { +void raise_any(void) +{ throw 1; } -Test(exception, raise_std) { raise_std(); } -Test(exception, raise_any) { raise_any(); } +Test(exception, raise_std) { + raise_std(); +} +Test(exception, raise_any) { + raise_any(); +} -Test(exception, raise_std_init, .init = raise_std) {} -Test(exception, raise_any_init, .init = raise_any) {} -Test(exception, raise_std_fini, .fini = raise_std) {} -Test(exception, raise_any_fini, .fini = raise_any) {} +Test(exception, raise_std_init, .init = raise_std) { +} +Test(exception, raise_any_init, .init = raise_any) { +} +Test(exception, raise_std_fini, .fini = raise_std) { +} +Test(exception, raise_any_fini, .fini = raise_any) { +} diff --git a/samples/tests/exit.c b/samples/tests/exit.c index f9c95dd..6e291a5 100644 --- a/samples/tests/exit.c +++ b/samples/tests/exit.c @@ -13,7 +13,8 @@ Test(exit, unexpected_exit) { exit(127); } -void do_exit (void) { +void do_exit(void) +{ exit(127); } diff --git a/samples/tests/exit.cc b/samples/tests/exit.cc index f9c95dd..6e291a5 100644 --- a/samples/tests/exit.cc +++ b/samples/tests/exit.cc @@ -13,7 +13,8 @@ Test(exit, unexpected_exit) { exit(127); } -void do_exit (void) { +void do_exit(void) +{ exit(127); } diff --git a/samples/tests/failmessages.c b/samples/tests/failmessages.c index 7de8e6e..d64fbbf 100644 --- a/samples/tests/failmessages.c +++ b/samples/tests/failmessages.c @@ -1,8 +1,8 @@ #include -// Define NULL consistenly for the regression tests -# undef NULL -# define NULL ((void *)0) +/* Define NULL consistenly for the regression tests */ +#undef NULL +#define NULL ((void *) 0) Test(messages, default) { cr_expect(0); diff --git a/samples/tests/other-crashes.c b/samples/tests/other-crashes.c index ab689bb..d41da27 100644 --- a/samples/tests/other-crashes.c +++ b/samples/tests/other-crashes.c @@ -1,7 +1,9 @@ #include -void crash(void) { +void crash(void) +{ int *i = NULL; + *i = 42; } diff --git a/samples/tests/other-crashes.cc b/samples/tests/other-crashes.cc index ab689bb..d41da27 100644 --- a/samples/tests/other-crashes.cc +++ b/samples/tests/other-crashes.cc @@ -1,7 +1,9 @@ #include -void crash(void) { +void crash(void) +{ int *i = NULL; + *i = 42; } diff --git a/samples/tests/theories_regression.c b/samples/tests/theories_regression.c index bcb953e..4c0d515 100644 --- a/samples/tests/theories_regression.c +++ b/samples/tests/theories_regression.c @@ -1,19 +1,19 @@ #ifdef _MSC_VER -#pragma warning(disable : 4090) +# pragma warning(disable : 4090) #endif #include -// Testing for various parameters +/* Testing for various parameters */ TheoryDataPoints(theory, misc) = { - DataPoints(char, 'a'), - DataPoints(bool, true), - DataPoints(short, 1), - DataPoints(int, 1), - DataPoints(float, 3.14f), - DataPoints(double, 3.14), - DataPoints(char *, "test"), + DataPoints(char, 'a'), + DataPoints(bool, true), + DataPoints(short, 1), + DataPoints(int, 1), + DataPoints(float, 3.14f), + DataPoints(double, 3.14), + DataPoints(char *, "test"), DataPoints(const char *, "other test"), }; @@ -30,6 +30,6 @@ Theory((char c, bool b, short s, int i, float f, double d, char *str, const char cr_assert_str_eq(str, "test"); cr_assert_str_eq(cstr, "other test"); - // abort to see the formatted string of all parameters + /* abort to see the formatted string of all parameters */ cr_assert_fail(); } diff --git a/samples/tests/theories_regression.cc b/samples/tests/theories_regression.cc index 75fdc0d..02dcb53 100644 --- a/samples/tests/theories_regression.cc +++ b/samples/tests/theories_regression.cc @@ -1,21 +1,21 @@ #ifdef _MSC_VER -#pragma warning(disable : 4090) +# pragma warning(disable : 4090) #endif #include -// Testing for various parameters +/* Testing for various parameters */ -char test_str[] = {'t', 'e', 's', 't', '\0'}; +char test_str[] = { 't', 'e', 's', 't', '\0' }; TheoryDataPoints(theory, misc) = { - DataPoints(char, 'a'), - DataPoints(bool, true), - DataPoints(short, 1), - DataPoints(int, 1), - DataPoints(float, 3.14f), - DataPoints(double, 3.14), - DataPoints(char *, test_str), + DataPoints(char, 'a'), + DataPoints(bool, true), + DataPoints(short, 1), + DataPoints(int, 1), + DataPoints(float, 3.14f), + DataPoints(double, 3.14), + DataPoints(char *, test_str), DataPoints(const char *, "other test"), }; @@ -32,6 +32,6 @@ Theory((char c, bool b, short s, int i, float f, double d, char *str, const char cr_assert_str_eq(str, "test"); cr_assert_str_eq(cstr, "other test"); - // abort to see the formatted string of all parameters + /* abort to see the formatted string of all parameters */ cr_assert_fail(); } diff --git a/samples/theories.c b/samples/theories.c index 055811f..3094a74 100644 --- a/samples/theories.c +++ b/samples/theories.c @@ -1,19 +1,21 @@ #ifdef _MSC_VER -#pragma warning(disable : 4090) +# pragma warning(disable : 4090) #endif #include #include -# define INT_DATAPOINTS DataPoints(int, 0, 1, 2, -1, -2, INT_MAX, INT_MIN) +#define INT_DATAPOINTS DataPoints(int, 0, 1, 2, -1, -2, INT_MAX, INT_MIN) -// Let's test the multiplicative properties of 32-bit integers: +/* Let's test the multiplicative properties of 32-bit integers: */ -int bad_mul(int a, int b) { +int bad_mul(int a, int b) +{ return a * b; } -int bad_div(int a, int b) { +int bad_div(int a, int b) +{ return a / b; } @@ -27,14 +29,15 @@ Theory((int a, int b), algebra, bad_divide_is_inverse_of_multiply) { cr_assert_eq(a, bad_div(bad_mul(a, b), b)); } -// The above implementation of mul & div fails the test because of overflows, -// let's try again: - -long long good_mul(long long a, long long b) { +/* The above implementation of mul & div fails the test because of overflows, + let's try again: */ +long long good_mul(long long a, long long b) +{ return a * b; } -long long good_div(long long a, long long b) { +long long good_div(long long a, long long b) +{ return a / b; } @@ -48,13 +51,13 @@ Theory((int a, int b), algebra, good_divide_is_inverse_of_multiply) { cr_assert_eq(a, good_div(good_mul(a, b), b)); } -// For triangulation +/* For triangulation */ Test(algebra, multiplication_by_integer) { cr_assert_eq(10, good_mul(5, 2)); } -// Another property test +/* Another property test */ TheoryDataPoints(algebra, zero_is_absorbing) = { INT_DATAPOINTS, @@ -66,24 +69,24 @@ Theory((int a, int b), algebra, zero_is_absorbing) { cr_assert_eq(0, good_mul(a, b)); } -// Testing for various parameters +/* Testing for various parameters */ struct my_object { int foo; }; TheoryDataPoints(theory, misc) = { - DataPoints(char, 'a'), - DataPoints(bool, true), - DataPoints(short, 1), - DataPoints(int, 1), - DataPoints(long, 1), - DataPoints(long long, 1), - DataPoints(float, 3.14f), - DataPoints(double, 3.14), - DataPoints(char *, "test"), - DataPoints(const char *, "other test"), - DataPoints(struct my_object *, &(struct my_object) {42}), + DataPoints(char, 'a'), + DataPoints(bool, true), + DataPoints(short, 1), + DataPoints(int, 1), + DataPoints(long, 1), + DataPoints(long long, 1), + DataPoints(float, 3.14f), + DataPoints(double, 3.14), + DataPoints(char *, "test"), + DataPoints(const char *, "other test"), + DataPoints(struct my_object *, & (struct my_object) { 42 }), }; Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d, char *str, const char *cstr, struct my_object *obj), theory, misc) { @@ -102,6 +105,6 @@ Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d, cr_assert_str_eq(cstr, "other test"); cr_assert_eq(obj->foo, 42); - // abort to see the formatted string of all parameters + /* abort to see the formatted string of all parameters */ cr_assert_fail(); } diff --git a/samples/theories.cc b/samples/theories.cc index b79cb00..a711aab 100644 --- a/samples/theories.cc +++ b/samples/theories.cc @@ -1,5 +1,5 @@ #ifdef _MSC_VER -#pragma warning(disable : 4090) +# pragma warning(disable : 4090) #endif #include @@ -9,15 +9,17 @@ # include #endif -# define INT_DATAPOINTS DataPoints(int, 0, 1, 2, -1, -2, INT_MAX, INT_MIN) +#define INT_DATAPOINTS DataPoints(int, 0, 1, 2, -1, -2, INT_MAX, INT_MIN) -// Let's test the multiplicative properties of 32-bit integers: +/* Let's test the multiplicative properties of 32-bit integers: */ -int bad_mul(int a, int b) { +int bad_mul(int a, int b) +{ return a * b; } -int bad_div(int a, int b) { +int bad_div(int a, int b) +{ return a / b; } @@ -31,14 +33,15 @@ Theory((int a, int b), algebra, bad_divide_is_inverse_of_multiply) { cr_assert_eq(a, bad_div(bad_mul(a, b), b)); } -// The above implementation of mul & div fails the test because of overflows, -// let's try again: - -long long good_mul(long long a, long long b) { +/* The above implementation of mul & div fails the test because of overflows, + let's try again: */ +long long good_mul(long long a, long long b) +{ return a * b; } -long long good_div(long long a, long long b) { +long long good_div(long long a, long long b) +{ return a / b; } @@ -52,13 +55,13 @@ Theory((int a, int b), algebra, good_divide_is_inverse_of_multiply) { cr_assert_eq(a, good_div(good_mul(a, b), b)); } -// For triangulation +/* For triangulation */ Test(algebra, multiplication_by_integer) { cr_assert_eq(10, good_mul(5, 2)); } -// Another property test +/* Another property test */ TheoryDataPoints(algebra, zero_is_absorbing) = { INT_DATAPOINTS, @@ -70,27 +73,27 @@ Theory((int a, int b), algebra, zero_is_absorbing) { cr_assert_eq(0, good_mul(a, b)); } -// Testing for various parameters +/* Testing for various parameters */ struct my_object { int foo; }; -struct my_object o = {42}; +struct my_object o = { 42 }; -char test_str[] = {'t', 'e', 's', 't', '\0'}; +char test_str[] = { 't', 'e', 's', 't', '\0' }; TheoryDataPoints(theory, misc) = { - DataPoints(char, 'a'), - DataPoints(bool, true), - DataPoints(short, 1), - DataPoints(int, 1), - DataPoints(long, 1), - DataPoints(long long, 1), - DataPoints(float, 3.14f), - DataPoints(double, 3.14), - DataPoints(char *, test_str), - DataPoints(const char *, "other test"), + DataPoints(char, 'a'), + DataPoints(bool, true), + DataPoints(short, 1), + DataPoints(int, 1), + DataPoints(long, 1), + DataPoints(long long, 1), + DataPoints(float, 3.14f), + DataPoints(double, 3.14), + DataPoints(char *, test_str), + DataPoints(const char *, "other test"), DataPoints(struct my_object *, &o), }; @@ -110,6 +113,6 @@ Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d, cr_assert_str_eq(cstr, "other test"); cr_assert_eq(obj->foo, 42); - // abort to see the formatted string of all parameters + /* abort to see the formatted string of all parameters */ cr_assert_fail(); } diff --git a/samples/timeout.c b/samples/timeout.c index 6876477..a2b03b2 100644 --- a/samples/timeout.c +++ b/samples/timeout.c @@ -2,7 +2,7 @@ #ifdef _WIN32 # include -# define sleep(x) Sleep(x * 1000) +# define sleep(x) Sleep(x * 1000) #else # include #endif diff --git a/src/common.h b/src/common.h index e9d30a2..56c19e9 100644 --- a/src/common.h +++ b/src/common.h @@ -22,13 +22,13 @@ * THE SOFTWARE. */ #ifndef COMMON_H_ -# define COMMON_H_ +#define COMMON_H_ -# include -# include +#include +#include -# include "criterion/internal/common.h" +#include "criterion/internal/common.h" -# define DEF(X, Y) ((X) ? (X) : (Y)) +#define DEF(X, Y) ((X) ? (X) : (Y)) #endif /* !COMMON_H_ */ diff --git a/src/compat/alloc.c b/src/compat/alloc.c index 30621ef..c5aba0b 100644 --- a/src/compat/alloc.c +++ b/src/compat/alloc.c @@ -32,7 +32,7 @@ static bxf_arena inheritable_arena; void cri_alloc_init(void) { int rc = bxf_arena_init(0, BXF_ARENA_RESIZE | BXF_ARENA_IDENTITY - | BXF_ARENA_KEEPMAPPED, &inheritable_arena); + | BXF_ARENA_KEEPMAPPED, &inheritable_arena); if (rc < 0) cr_panic("Could not initialize inheritable arena: %s", strerror(-rc)); @@ -51,6 +51,7 @@ bxf_arena cri_alloc_getarena(void) void *cr_malloc(size_t size) { bxf_ptr ptr = bxf_arena_alloc(&inheritable_arena, size); + if (ptr < 0) { errno = -ptr; return NULL; @@ -61,6 +62,7 @@ void *cr_malloc(size_t size) void *cr_calloc(size_t nmemb, size_t size) { void *ptr = cr_malloc(size * nmemb); + if (ptr) memset(ptr, 0, size * nmemb); return ptr; @@ -68,8 +70,9 @@ void *cr_calloc(size_t nmemb, size_t size) void *cr_realloc(void *ptr, size_t size) { - bxf_ptr p = (intptr_t)ptr - (intptr_t)inheritable_arena; + bxf_ptr p = (intptr_t) ptr - (intptr_t) inheritable_arena; bxf_ptr newptr = bxf_arena_realloc(&inheritable_arena, p, size); + if (newptr < 0) { errno = -newptr; return NULL; @@ -79,6 +82,7 @@ void *cr_realloc(void *ptr, size_t size) void cr_free(void *ptr) { - bxf_ptr p = (intptr_t)ptr - (intptr_t)inheritable_arena; + bxf_ptr p = (intptr_t) ptr - (intptr_t) inheritable_arena; + (void) bxf_arena_free(&inheritable_arena, p); } diff --git a/src/compat/alloc.h b/src/compat/alloc.h index 61f9988..8d761e7 100644 --- a/src/compat/alloc.h +++ b/src/compat/alloc.h @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #ifndef COMPAT_ALLOC_H_ -# define COMPAT_ALLOC_H_ +#define COMPAT_ALLOC_H_ -# include -# include "criterion/alloc.h" +#include +#include "criterion/alloc.h" void cri_alloc_init(void); void cri_alloc_term(void); diff --git a/src/compat/basename.c b/src/compat/basename.c index ed9fe8a..cbec7e4 100644 --- a/src/compat/basename.c +++ b/src/compat/basename.c @@ -23,8 +23,10 @@ */ #include "basename.h" -const char *basename_compat(const char *str) { +const char *basename_compat(const char *str) +{ const char *start = str; + for (const char *c = str; *c; ++c) if ((*c == '/' || *c == '\\') && c[1]) start = c + 1; diff --git a/src/compat/basename.h b/src/compat/basename.h index a7d45aa..3a83ddd 100644 --- a/src/compat/basename.h +++ b/src/compat/basename.h @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #ifndef BASENAME_H_ -# define BASENAME_H_ +#define BASENAME_H_ const char *basename_compat(const char *str); diff --git a/src/compat/internal.h b/src/compat/internal.h index acfb568..5e52348 100644 --- a/src/compat/internal.h +++ b/src/compat/internal.h @@ -22,46 +22,46 @@ * THE SOFTWARE. */ #ifndef INTERNAL_H_ -# define INTERNAL_H_ +#define INTERNAL_H_ -# if defined(_WIN32) && !defined(__CYGWIN__) -# include +#if defined (_WIN32) && !defined (__CYGWIN__) +# include -# if defined(MINGW_DEFINE_OFF_T) && (defined(__MINGW32__) || defined(__MINGW64__)) -# include "off_t.h" +# if defined (MINGW_DEFINE_OFF_T) && (defined (__MINGW32__) || defined (__MINGW64__)) +# include "off_t.h" -# if !defined(__MINGW64__) -# define off_t cr_off32 -# else -# define off_t cr_off64 -# endif -# define off64_t cr_off64 +# if !defined (__MINGW64__) +# define off_t cr_off32 +# else +# define off_t cr_off64 # endif -# include -# if defined(MINGW_DEFINE_OFF_T) && (defined(__MINGW32__) || defined(__MINGW64__)) -# undef off_t -# undef off64_t -# endif -# include -# include -# include -# include -# else -# include -# include -# include -# include -# include -# ifdef BSD -# include +# define off64_t cr_off64 +# endif +# include +# if defined (MINGW_DEFINE_OFF_T) && (defined (__MINGW32__) || defined (__MINGW64__)) +# undef off_t +# undef off64_t +# endif +# include +# include +# include +# include +#else +# include +# include +# include +# include +# include +# ifdef BSD +# include typedef unsigned long u_long; typedef unsigned int u_int; typedef unsigned short u_short; typedef unsigned char u_char; -# include -# endif +# include # endif +#endif -# include "posix.h" +#include "posix.h" #endif /* !INTERNAL_H_ */ diff --git a/src/compat/kill.c b/src/compat/kill.c index b440682..6df5eb3 100644 --- a/src/compat/kill.c +++ b/src/compat/kill.c @@ -36,7 +36,8 @@ #ifdef VANILLA_WIN32 static HANDLE cr_job; #else -static void handle_sigterm(CR_UNUSED int signum) { +static void handle_sigterm(CR_UNUSED int signum) +{ assert(signum == SIGTERM); kill(-getpid(), SIGTERM); @@ -44,32 +45,34 @@ static void handle_sigterm(CR_UNUSED int signum) { } #endif -void setup_parent_job(void) { +void setup_parent_job(void) +{ #ifdef VANILLA_WIN32 - // Put runner in its own job + /* Put runner in its own job */ cr_job = CreateJobObject(NULL, NULL); if (!AssignProcessToJobObject(cr_job, GetCurrentProcess())) abort(); #else - // Put runner in its own group + /* Put runner in its own group */ setpgid(0, 0); - // Setup termination handlers + /* Setup termination handlers */ sigset_t block_mask; - sigemptyset (&block_mask); - sigaddset (&block_mask, SIGINT); - sigaddset (&block_mask, SIGQUIT); - sigaddset (&block_mask, SIGTSTP); + sigemptyset(&block_mask); + sigaddset(&block_mask, SIGINT); + sigaddset(&block_mask, SIGQUIT); + sigaddset(&block_mask, SIGTSTP); struct sigaction sa = { - .sa_handler = handle_sigterm, - .sa_mask = block_mask, + .sa_handler = handle_sigterm, + .sa_mask = block_mask, }; sigaction(SIGTERM, &sa, NULL); #endif } -void cr_killall(void) { +void cr_killall(void) +{ fflush(NULL); #ifdef VANILLA_WIN32 if (!TerminateJobObject(cr_job, 1)) @@ -79,7 +82,8 @@ void cr_killall(void) { #endif } -void cr_terminate(struct criterion_global_stats *stats) { +void cr_terminate(struct criterion_global_stats *stats) +{ report(POST_ALL, stats); process_all_output(stats); log(post_all, stats); diff --git a/src/compat/kill.h b/src/compat/kill.h index f239cb2..c95c7bf 100644 --- a/src/compat/kill.h +++ b/src/compat/kill.h @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #ifndef COMPAT_KILL_H_ -# define COMPAT_KILL_H_ +#define COMPAT_KILL_H_ -# include "posix.h" -# include "criterion/stats.h" +#include "posix.h" +#include "criterion/stats.h" void setup_parent_job(void); void cr_killall(void); diff --git a/src/compat/mockfile.c b/src/compat/mockfile.c index ce4f8a7..106f851 100644 --- a/src/compat/mockfile.c +++ b/src/compat/mockfile.c @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#define _GNU_SOURCE 1 +#define _GNU_SOURCE 1 #include #include #include @@ -31,7 +31,7 @@ #include "internal.h" #include "criterion/redirect.h" -#if defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE) +#if defined (HAVE_FUNOPEN) || defined (HAVE_FOPENCOOKIE) # ifdef HAVE_FUNOPEN typedef int cr_count; @@ -51,12 +51,14 @@ struct memfile { char *mem; }; -static inline size_t size_safe_add(size_t size, size_t cur, cr_off off) { +static inline size_t size_safe_add(size_t size, size_t cur, cr_off off) +{ cur = cur < SIZE_MAX - off ? cur + off : SIZE_MAX; return cur < size ? cur : size; } -static inline size_t off_safe_add(size_t size, size_t cur, cr_off off) { +static inline size_t off_safe_add(size_t size, size_t cur, cr_off off) +{ if (off >= 0) cur = cur < SIZE_MAX - off ? cur + off : SIZE_MAX; else @@ -64,17 +66,19 @@ static inline size_t off_safe_add(size_t size, size_t cur, cr_off off) { return cur < size ? cur : size; } -# define errno_return(Errno, Val) \ - do { \ - errno = (Errno); \ - return (Val); \ +# define errno_return(Errno, Val) \ + do { \ + errno = (Errno); \ + return (Val); \ } while (0) -static cr_retcount mock_file_read(void *cookie, char *buf, cr_count count) { +static cr_retcount mock_file_read(void *cookie, char *buf, cr_count count) +{ struct memfile *mf = cookie; + # ifdef HAVE_FUNOPEN if (count < 0) - errno_return(EINVAL, (cr_retcount) -1); + errno_return(EINVAL, (cr_retcount) - 1); # endif if (mf->cur >= mf->size || count == 0) return 0; @@ -86,17 +90,19 @@ static cr_retcount mock_file_read(void *cookie, char *buf, cr_count count) { return count; } -static cr_retcount mock_file_write(void *cookie, const char *buf, cr_count count) { +static cr_retcount mock_file_write(void *cookie, const char *buf, cr_count count) +{ struct memfile *mf = cookie; + # ifdef HAVE_FUNOPEN if (count < 0) - errno_return(EINVAL, (cr_retcount) -1); + errno_return(EINVAL, (cr_retcount) - 1); # endif if (count == 0) return 0; if (mf->cur >= mf->max_size) - errno_return(EIO, (cr_retcount) -1); + errno_return(EIO, (cr_retcount) - 1); size_t end = size_safe_add(mf->max_size, mf->cur, count); if (mf->size < end) @@ -108,7 +114,7 @@ static cr_retcount mock_file_write(void *cookie, const char *buf, cr_count count mf->region_size = mf->region_size * 3 / 2; char *newptr = realloc(mf->mem, mf->region_size); if (!newptr) - errno_return(EIO, (cr_retcount) -1); + errno_return(EIO, (cr_retcount) - 1); mf->mem = newptr; } memcpy(mf->mem + mf->cur, buf, count); @@ -117,20 +123,24 @@ static cr_retcount mock_file_write(void *cookie, const char *buf, cr_count count } # ifdef HAVE_FUNOPEN -static cr_off mock_file_seek(void *cookie, cr_off off, int whence) { +static cr_off mock_file_seek(void *cookie, cr_off off, int whence) +{ struct memfile *mf = cookie; + switch (whence) { - case SEEK_SET: return (mf->cur = off); - case SEEK_CUR: return (mf->cur = off_safe_add(mf->size, mf->cur, off)); - case SEEK_END: return (mf->cur = off_safe_add(mf->size, mf->size, off)); + case SEEK_SET: return mf->cur = off; + case SEEK_CUR: return mf->cur = off_safe_add(mf->size, mf->cur, off); + case SEEK_END: return mf->cur = off_safe_add(mf->size, mf->size, off); default: break; } errno = EINVAL; return (off_t) -1; } # else -static int mock_file_seek(void *cookie, cr_off *off, int whence) { +static int mock_file_seek(void *cookie, cr_off *off, int whence) +{ struct memfile *mf = cookie; + switch (whence) { case SEEK_SET: mf->cur = *off; break; case SEEK_CUR: *off = (mf->cur = off_safe_add(mf->size, mf->cur, *off)); break; @@ -141,16 +151,19 @@ static int mock_file_seek(void *cookie, cr_off *off, int whence) { } # endif -static int mock_file_close(void *cookie) { +static int mock_file_close(void *cookie) +{ struct memfile *mf = cookie; + free(mf->mem); free(cookie); return 0; } #endif /* defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE) */ -FILE *cr_mock_file_size(size_t max_size) { -#if defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE) +FILE *cr_mock_file_size(size_t max_size) +{ +#if defined (HAVE_FUNOPEN) || defined (HAVE_FOPENCOOKIE) struct memfile *cookie = malloc(sizeof (struct memfile)); *cookie = (struct memfile) { .max_size = max_size, @@ -159,7 +172,7 @@ FILE *cr_mock_file_size(size_t max_size) { }; FILE *f; -# if defined(HAVE_FOPENCOOKIE) +# if defined (HAVE_FOPENCOOKIE) f = fopencookie(cookie, "w+", (cookie_io_functions_t) { .read = mock_file_read, .write = mock_file_write, @@ -168,10 +181,10 @@ FILE *cr_mock_file_size(size_t max_size) { }); # else f = funopen(cookie, - mock_file_read, - mock_file_write, - mock_file_seek, - mock_file_close); + mock_file_read, + mock_file_write, + mock_file_seek, + mock_file_close); # endif return f; #elif defined (HAVE_OPEN_MEMSTREAM) @@ -187,7 +200,7 @@ FILE *cr_mock_file_size(size_t max_size) { #else (void) max_size; - // fallback to tmpfile() - return tmpfile(); + /* fallback to tmpfile() */ + return tmpfile(); #endif } diff --git a/src/compat/off_t.h b/src/compat/off_t.h index ee14849..a57dec3 100644 --- a/src/compat/off_t.h +++ b/src/compat/off_t.h @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #ifndef CR_OFF_T_DEFINED -# define CR_OFF_T_DEFINED +#define CR_OFF_T_DEFINED -# include +#include typedef int32_t cr_off32; typedef int64_t cr_off64; diff --git a/src/compat/pipe-internal.h b/src/compat/pipe-internal.h index 35a7cdf..f44f6d1 100644 --- a/src/compat/pipe-internal.h +++ b/src/compat/pipe-internal.h @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #ifndef PIPE_INTERNAL_H_ -# define PIPE_INTERNAL_H_ +#define PIPE_INTERNAL_H_ -# include "internal.h" -# include "pipe.h" +#include "internal.h" +#include "pipe.h" struct pipe_handle { #ifdef VANILLA_WIN32 diff --git a/src/compat/pipe.c b/src/compat/pipe.c index 7f2a1a5..04af634 100644 --- a/src/compat/pipe.c +++ b/src/compat/pipe.c @@ -27,7 +27,8 @@ #include "criterion/assert.h" #include "pipe-internal.h" -FILE *pipe_in(s_pipe_handle *p, enum pipe_opt opts) { +FILE *pipe_in(s_pipe_handle *p, enum pipe_opt opts) +{ #ifdef VANILLA_WIN32 if (opts & PIPE_CLOSE) CloseHandle(p->fhs[1]); @@ -52,7 +53,8 @@ FILE *pipe_in(s_pipe_handle *p, enum pipe_opt opts) { return in; } -FILE *pipe_out(s_pipe_handle *p, enum pipe_opt opts) { +FILE *pipe_out(s_pipe_handle *p, enum pipe_opt opts) +{ #ifdef VANILLA_WIN32 if (opts & PIPE_CLOSE) CloseHandle(p->fhs[0]); @@ -77,69 +79,73 @@ FILE *pipe_out(s_pipe_handle *p, enum pipe_opt opts) { return out; } -int stdpipe_stack(s_pipe_handle *out) { +int stdpipe_stack(s_pipe_handle *out) +{ #ifdef VANILLA_WIN32 HANDLE fhs[2]; SECURITY_ATTRIBUTES attr = { - .nLength = sizeof (SECURITY_ATTRIBUTES), + .nLength = sizeof (SECURITY_ATTRIBUTES), .bInheritHandle = TRUE }; if (!CreatePipe(fhs, fhs + 1, &attr, 0)) return -1; - *out = (s_pipe_handle) {{ fhs[0], fhs[1] }}; + *out = (s_pipe_handle) { { fhs[0], fhs[1] } }; #else int fds[2] = { -1, -1 }; if (pipe(fds) == -1) return -1; - *out = (s_pipe_handle) {{ fds[0], fds[1] }}; + *out = (s_pipe_handle) { { fds[0], fds[1] } }; #endif return 0; } -s_pipe_handle *stdpipe() { +s_pipe_handle *stdpipe() +{ s_pipe_handle *handle = smalloc(sizeof (s_pipe_handle)); + if (stdpipe_stack(handle) < 0) return NULL; return handle; } -int stdpipe_options(s_pipe_handle *handle, int id, int noblock) { +int stdpipe_options(s_pipe_handle *handle, int id, int noblock) +{ #ifdef VANILLA_WIN32 HANDLE fhs[2]; SECURITY_ATTRIBUTES attr = { - .nLength = sizeof (SECURITY_ATTRIBUTES), + .nLength = sizeof (SECURITY_ATTRIBUTES), .bInheritHandle = TRUE }; - char pipe_name[256] = {0}; + char pipe_name[256] = { 0 }; snprintf(pipe_name, sizeof (pipe_name), - "\\\\.\\pipe\\criterion_%lu_%d", GetCurrentProcessId(), id); + "\\\\.\\pipe\\criterion_%lu_%d", GetCurrentProcessId(), id); fhs[0] = CreateNamedPipe(pipe_name, - PIPE_ACCESS_INBOUND, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE - | (noblock ? PIPE_NOWAIT : PIPE_WAIT), - 1, - 4096 * 4, - 4096 * 4, - 0, - &attr); + PIPE_ACCESS_INBOUND, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE + | (noblock ? PIPE_NOWAIT : PIPE_WAIT), + 1, + 4096 * 4, + 4096 * 4, + 0, + &attr); if (fhs[0] == INVALID_HANDLE_VALUE) return 0; fhs[1] = CreateFile(pipe_name, - GENERIC_WRITE, - 0, - &attr, - OPEN_EXISTING, - 0, - NULL); + GENERIC_WRITE, + 0, + &attr, + OPEN_EXISTING, + 0, + NULL); if (fhs[1] == INVALID_HANDLE_VALUE) { CloseHandle(fhs[0]); return 0; } - *handle = (s_pipe_handle) {{ fhs[0], fhs[1] }}; + *handle = (s_pipe_handle) { { fhs[0], fhs[1] } }; #else (void) id; @@ -151,13 +157,15 @@ int stdpipe_options(s_pipe_handle *handle, int id, int noblock) { for (int i = 0; i < 2; ++i) fcntl(fds[i], F_SETFL, fcntl(fds[i], F_GETFL) | O_NONBLOCK); - *handle = (s_pipe_handle) {{ fds[0], fds[1] }}; + *handle = (s_pipe_handle) { { fds[0], fds[1] } }; #endif return 1; } -void pipe_std_redirect(s_pipe_handle *pipe, enum criterion_std_fd fd) { +void pipe_std_redirect(s_pipe_handle *pipe, enum criterion_std_fd fd) +{ enum pipe_end end = fd == CR_STDIN ? PIPE_READ : PIPE_WRITE; + #ifdef VANILLA_WIN32 int stdfd = _open_osfhandle((intptr_t) pipe->fhs[end], end == PIPE_READ ? _O_RDONLY : _O_WRONLY); if (stdfd == -1) @@ -182,8 +190,10 @@ void pipe_std_redirect(s_pipe_handle *pipe, enum criterion_std_fd fd) { #endif } -void close_pipe_file_handle(void *ptr, CR_UNUSED void *meta) { +void close_pipe_file_handle(void *ptr, CR_UNUSED void *meta) +{ s_pipe_file_handle *h = ptr; + #ifdef VANILLA_WIN32 CloseHandle(h->fh); #else @@ -192,20 +202,23 @@ void close_pipe_file_handle(void *ptr, CR_UNUSED void *meta) { } #ifdef VANILLA_WIN32 -static HANDLE win_dup(HANDLE h) { +static HANDLE win_dup(HANDLE h) +{ HANDLE dup; + DuplicateHandle(GetCurrentProcess(), - h, - GetCurrentProcess(), - &dup, - 0, - TRUE, - DUPLICATE_SAME_ACCESS); + h, + GetCurrentProcess(), + &dup, + 0, + TRUE, + DUPLICATE_SAME_ACCESS); return dup; } #endif -s_pipe_file_handle *pipe_out_handle(s_pipe_handle *p, enum pipe_opt opts) { +s_pipe_file_handle *pipe_out_handle(s_pipe_handle *p, enum pipe_opt opts) +{ #ifdef VANILLA_WIN32 if (opts & PIPE_CLOSE) CloseHandle(p->fhs[0]); @@ -214,8 +227,8 @@ s_pipe_file_handle *pipe_out_handle(s_pipe_handle *p, enum pipe_opt opts) { fh = win_dup(fh); s_pipe_file_handle *h = smalloc( - .size = sizeof (s_pipe_file_handle), - .dtor = close_pipe_file_handle); + .size = sizeof (s_pipe_file_handle), + .dtor = close_pipe_file_handle); h->fh = fh; return h; @@ -227,15 +240,16 @@ s_pipe_file_handle *pipe_out_handle(s_pipe_handle *p, enum pipe_opt opts) { fd = dup(fd); s_pipe_file_handle *h = smalloc( - .size = sizeof (s_pipe_file_handle), - .dtor = close_pipe_file_handle); + .size = sizeof (s_pipe_file_handle), + .dtor = close_pipe_file_handle); h->fd = fd; return h; #endif } -s_pipe_file_handle *pipe_in_handle(s_pipe_handle *p, enum pipe_opt opts) { +s_pipe_file_handle *pipe_in_handle(s_pipe_handle *p, enum pipe_opt opts) +{ #ifdef VANILLA_WIN32 if (opts & PIPE_CLOSE) CloseHandle(p->fhs[1]); @@ -244,8 +258,8 @@ s_pipe_file_handle *pipe_in_handle(s_pipe_handle *p, enum pipe_opt opts) { fh = win_dup(fh); s_pipe_file_handle *h = smalloc( - .size = sizeof (s_pipe_file_handle), - .dtor = close_pipe_file_handle); + .size = sizeof (s_pipe_file_handle), + .dtor = close_pipe_file_handle); h->fh = fh; return h; @@ -257,15 +271,16 @@ s_pipe_file_handle *pipe_in_handle(s_pipe_handle *p, enum pipe_opt opts) { fd = dup(fd); s_pipe_file_handle *h = smalloc( - .size = sizeof (s_pipe_file_handle), - .dtor = close_pipe_file_handle); + .size = sizeof (s_pipe_file_handle), + .dtor = close_pipe_file_handle); h->fd = fd; return h; #endif } -int pipe_write(const void *buf, size_t size, s_pipe_file_handle *pipe) { +int pipe_write(const void *buf, size_t size, s_pipe_file_handle *pipe) +{ #ifdef VANILLA_WIN32 DWORD written = 0; size_t off = 0; @@ -288,7 +303,8 @@ int pipe_write(const void *buf, size_t size, s_pipe_file_handle *pipe) { #endif } -int pipe_read(void *buf, size_t size, s_pipe_file_handle *pipe) { +int pipe_read(void *buf, size_t size, s_pipe_file_handle *pipe) +{ #ifdef VANILLA_WIN32 DWORD read = 0; size_t off = 0; @@ -319,20 +335,22 @@ s_pipe_handle *stdout_redir = &stdout_redir_; s_pipe_handle *stderr_redir = &stderr_redir_; s_pipe_handle *stdin_redir = &stdin_redir_; -s_pipe_file_handle *pipe_file_open(const char *path) { +s_pipe_file_handle *pipe_file_open(const char *path) +{ s_pipe_file_handle *h = smalloc( - .size = sizeof (s_pipe_file_handle), - .dtor = close_pipe_file_handle); + .size = sizeof (s_pipe_file_handle), + .dtor = close_pipe_file_handle); + #ifdef VANILLA_WIN32 if (!path) path = "nul"; h->fh = CreateFile(path, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); #else if (!path) path = "/dev/null"; diff --git a/src/compat/pipe.h b/src/compat/pipe.h index 5a7cc08..336728e 100644 --- a/src/compat/pipe.h +++ b/src/compat/pipe.h @@ -22,12 +22,12 @@ * THE SOFTWARE. */ #ifndef PIPE_H_ -# define PIPE_H_ +#define PIPE_H_ -# include -# include -# include "common.h" -# include "log/logging.h" +#include +#include +#include "common.h" +#include "log/logging.h" struct pipe_handle; typedef struct pipe_handle s_pipe_handle; @@ -48,7 +48,7 @@ enum criterion_std_fd { enum pipe_opt { PIPE_NOOPT = 0, - PIPE_DUP = 1 << 0, + PIPE_DUP = 1 << 0, PIPE_CLOSE = 1 << 1, }; @@ -65,7 +65,8 @@ void pipe_std_redirect(s_pipe_handle *pipe, enum criterion_std_fd fd); int pipe_write(const void *buf, size_t size, s_pipe_file_handle *pipe); int pipe_read(void *buf, size_t size, s_pipe_file_handle *pipe); -CR_INLINE FILE* get_std_file(enum criterion_std_fd fd_kind) { +CR_INLINE FILE *get_std_file(enum criterion_std_fd fd_kind) +{ switch (fd_kind) { case CR_STDIN: return stdin; case CR_STDOUT: return stdout; diff --git a/src/compat/posix.h b/src/compat/posix.h index 750e3aa..1a6c17b 100644 --- a/src/compat/posix.h +++ b/src/compat/posix.h @@ -22,53 +22,53 @@ * THE SOFTWARE. */ #ifndef POSIX_COMPAT_H_ -# define POSIX_COMPAT_H_ +#define POSIX_COMPAT_H_ -# if defined(_WIN32) && !defined(__CYGWIN__) -# define VANILLA_WIN32 -# endif +#if defined (_WIN32) && !defined (__CYGWIN__) +# define VANILLA_WIN32 +#endif -# if defined(BSD) \ - || defined(__FreeBSD__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__DragonFly__) -# define OS_BSD 1 -# endif +#if defined (BSD) \ + || defined (__FreeBSD__) \ + || defined (__NetBSD__) \ + || defined (__OpenBSD__) \ + || defined (__DragonFly__) +# define OS_BSD 1 +#endif -# if !defined(_POSIX_SOURCE) -# define _POSIX_SOURCE 1 -# define TMP_POSIX -# endif -# if defined(MINGW_DEFINE_OFF_T) && (defined(__MINGW32__) || defined(__MINGW64__)) -# include "off_t.h" +#if !defined (_POSIX_SOURCE) +# define _POSIX_SOURCE 1 +# define TMP_POSIX +#endif +#if defined (MINGW_DEFINE_OFF_T) && (defined (__MINGW32__) || defined (__MINGW64__)) +# include "off_t.h" -# if !defined(__MINGW64__) -# define off_t cr_off32 -# else -# define off_t cr_off64 -# endif -# define off64_t cr_off64 -# endif -# include -# include -# if defined(MINGW_DEFINE_OFF_T) && defined(__MINGW32__) || defined(__MINGW64__) -# undef off_t -# undef off64_t -# endif -# ifdef TMP_POSIX -# undef _POSIX_SOURCE -# undef TMP_POSIX +# if !defined (__MINGW64__) +# define off_t cr_off32 +# else +# define off_t cr_off64 # endif +# define off64_t cr_off64 +#endif +#include +#include +#if defined (MINGW_DEFINE_OFF_T) && defined (__MINGW32__) || defined (__MINGW64__) +# undef off_t +# undef off64_t +#endif +#ifdef TMP_POSIX +# undef _POSIX_SOURCE +# undef TMP_POSIX +#endif -# ifdef VANILLA_WIN32 -# define WEXITSTATUS(Status) (((Status) & 0xFF00) >> 8) -# define WTERMSIG(Status) ((Status) & 0x7F) -# define WIFEXITED(Status) (WTERMSIG(Status) == 0) -# define WIFSIGNALED(Status) (((signed char) (WTERMSIG(Status) + 1) >> 1) > 0) +#ifdef VANILLA_WIN32 +# define WEXITSTATUS(Status) (((Status) & 0xFF00) >> 8) +# define WTERMSIG(Status) ((Status) & 0x7F) +# define WIFEXITED(Status) (WTERMSIG(Status) == 0) +# define WIFSIGNALED(Status) (((signed char) (WTERMSIG(Status) + 1) >> 1) > 0) -# define SIGPROF 27 -# define SIGSYS 31 +# define SIGPROF 27 +# define SIGSYS 31 /* * We define a custom exception code following the ntstatus specification: @@ -81,15 +81,15 @@ * |`------------------------------------- Customer code: Yes (0b1) * `-------------------------------------- Severity: Error (0b11) */ -# define CR_EXCEPTION_TIMEOUT 0xEFFFFFFF +# define CR_EXCEPTION_TIMEOUT 0xEFFFFFFF -# else -# include -# endif +#else +# include +#endif -# include "compat/pipe.h" -# include "compat/section.h" -# include "compat/process.h" -# include "compat/basename.h" +#include "compat/pipe.h" +#include "compat/section.h" +#include "compat/process.h" +#include "compat/basename.h" #endif /* !POSIX_COMPAT_H_ */ diff --git a/src/compat/process.c b/src/compat/process.c index 1ca22dc..4663819 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -24,7 +24,8 @@ #include "process.h" #include "internal.h" -unsigned long long get_process_id(void) { +unsigned long long get_process_id(void) +{ #ifdef VANILLA_WIN32 return (unsigned long long) GetCurrentProcessId(); #else diff --git a/src/compat/process.h b/src/compat/process.h index dad97c6..22f9c47 100644 --- a/src/compat/process.h +++ b/src/compat/process.h @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #ifndef COMPAT_PROCESS_H_ -# define COMPAT_PROCESS_H_ +#define COMPAT_PROCESS_H_ unsigned long long get_process_id(void); diff --git a/src/compat/processor.c b/src/compat/processor.c index 8bfb655..01297b2 100644 --- a/src/compat/processor.c +++ b/src/compat/processor.c @@ -24,7 +24,8 @@ #include "internal.h" -size_t get_processor_count(void) { +size_t get_processor_count(void) +{ #ifdef _WIN32 /* This code shall return 1 until https://github.com/Snaipe/Criterion/issues/118 gets fixed. */ @@ -36,7 +37,7 @@ size_t get_processor_count(void) { # else return 1; # endif -#elif defined(BSD) +#elif defined (BSD) int mib[2] = { CTL_HW, HW_NCPU }; # ifdef __APPLE__ size_t miblen = 2; @@ -51,7 +52,7 @@ size_t get_processor_count(void) { if (count < 1 || res == -1) count = 1; return (size_t) count; -#elif defined(__linux__) +#elif defined (__linux__) return sysconf(_SC_NPROCESSORS_ONLN); #else # error System not supported diff --git a/src/compat/processor.h b/src/compat/processor.h index acb7a96..d48ca07 100644 --- a/src/compat/processor.h +++ b/src/compat/processor.h @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #ifndef COMPAT_PROCESSOR_H_ -# define COMPAT_PROCESSOR_H_ +#define COMPAT_PROCESSOR_H_ -# include +#include size_t get_processor_count(void); diff --git a/src/compat/section-elf.c b/src/compat/section-elf.c index 5152796..6b7760c 100644 --- a/src/compat/section-elf.c +++ b/src/compat/section-elf.c @@ -21,14 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -# include "section.h" +#include "section.h" -# include -# include -# include -# include +#include +#include +#include +#include -static int open_self(void) { +static int open_self(void) +{ #if defined __linux__ return open("/proc/self/exe", O_RDONLY); #elif defined __NetBSD__ @@ -54,20 +55,20 @@ static int open_self(void) { static int open_module_map(mod_handle *mod) { /* Load the ELF header and the section header table */ - const ElfW(Ehdr) *elf = mmap(NULL, sizeof (ElfW(Ehdr)), - PROT_READ, MAP_PRIVATE, mod->fd, 0); + const ElfW(Ehdr) * elf = mmap(NULL, sizeof (ElfW(Ehdr)), + PROT_READ, MAP_PRIVATE, mod->fd, 0); const void *oldm = elf; if (elf == MAP_FAILED) goto fail; - if (memcmp(elf->e_ident, (char [4]) { 0x7f, 'E', 'L', 'F' }, 4)) + if (memcmp(elf->e_ident, (char[4]) { 0x7f, 'E', 'L', 'F' }, 4)) goto fail; size_t new_map_len = elf->e_shoff + elf->e_shnum * elf->e_shentsize; #ifdef HAVE_MREMAP - elf = mremap((void*) elf, sizeof (ElfW(Ehdr)), new_map_len, MREMAP_MAYMOVE); + elf = mremap((void *) elf, sizeof (ElfW(Ehdr)), new_map_len, MREMAP_MAYMOVE); #else elf = mmap(NULL, new_map_len, PROT_READ, MAP_PRIVATE, mod->fd, 0); #endif @@ -98,6 +99,7 @@ static void close_module_map(mod_handle *mod) int open_module_self(mod_handle *mod) { int fd = open_self(); + if (fd == -1) return 0; @@ -111,13 +113,13 @@ void close_module(mod_handle *mod) close(mod->fd); } -static const void *map_shdr(int fd, const ElfW(Shdr) *shdr, struct section_mapping *out) +static const void *map_shdr(int fd, const ElfW (Shdr) *shdr, struct section_mapping *out) { size_t shdr_map_off = shdr->sh_offset & ~0xfffllu; size_t shdr_map_len = shdr->sh_size + (shdr->sh_offset - shdr_map_off); const uint8_t *shdr_map = mmap(NULL, shdr_map_len, - PROT_READ, MAP_PRIVATE, fd, shdr_map_off); + PROT_READ, MAP_PRIVATE, fd, shdr_map_off); if (shdr_map == MAP_FAILED) return NULL; @@ -132,14 +134,14 @@ static const void *map_shdr(int fd, const ElfW(Shdr) *shdr, struct section_mappi static void unmap_shdr(struct section_mapping *map) { - munmap((void*) map->map, map->len); + munmap((void *) map->map, map->len); } void *map_section_data(mod_handle *mod, const char *name, struct section_mapping *map) { - const ElfW(Shdr) *shdr = (void *) ((char *) mod->map + mod->map->e_shoff); - const ElfW(Shdr) *shstr_shdr = shdr + mod->map->e_shstrndx; + const ElfW(Shdr) * shdr = (void *) ((char *) mod->map + mod->map->e_shoff); + const ElfW(Shdr) * shstr_shdr = shdr + mod->map->e_shstrndx; struct section_mapping shstr_map; const char *shstr = map_shdr(mod->fd, shstr_shdr, &shstr_map); @@ -148,7 +150,7 @@ void *map_section_data(mod_handle *mod, const char *name, for (size_t i = 0; i < mod->map->e_shnum; i++) { const char *section_name = shstr + shdr[i].sh_name; if (!strcmp(section_name, name)) { - const ElfW(Shdr) *hdr = shdr + i; + const ElfW(Shdr) * hdr = shdr + i; ptr = map_shdr(mod->fd, hdr, map); map->sec_len = hdr->sh_size; break; @@ -156,12 +158,10 @@ void *map_section_data(mod_handle *mod, const char *name, } unmap_shdr(&shstr_map); - return (void *)ptr; + return (void *) ptr; } void unmap_section_data(struct section_mapping *map) { unmap_shdr(map); } - - diff --git a/src/compat/section-mach-o.c b/src/compat/section-mach-o.c index 3350384..e7d406a 100644 --- a/src/compat/section-mach-o.c +++ b/src/compat/section-mach-o.c @@ -36,12 +36,13 @@ typedef struct mach_header mach_hdr; typedef struct section section; #endif -static inline void *get_real_address(int lib, void *addr) { +static inline void *get_real_address(int lib, void *addr) +{ if (!addr) return NULL; - // We need to slide the section address to get a valid pointer - // because ASLR will shift the image by a random offset + /* We need to slide the section address to get a valid pointer + because ASLR will shift the image by a random offset */ return addr + _dyld_get_image_vmaddr_slide(lib); } @@ -79,7 +80,7 @@ void *map_section_data(mod_handle *mod, const char *name, continue; map->sec_len = s->size; - return get_real_address(*mod, (void *)(uintptr_t) s->addr); + return get_real_address(*mod, (void *) (uintptr_t) s->addr); } } else if (lc->cmd == LC_SEGMENT_64) { const struct segment_command_64 *sc = (void *) lc; @@ -91,7 +92,7 @@ void *map_section_data(mod_handle *mod, const char *name, continue; map->sec_len = s->size; - return get_real_address(*mod, (void *)(uintptr_t) s->addr); + return get_real_address(*mod, (void *) (uintptr_t) s->addr); } } } diff --git a/src/compat/section-pe.c b/src/compat/section-pe.c index 0344d2c..044e2d8 100644 --- a/src/compat/section-pe.c +++ b/src/compat/section-pe.c @@ -43,7 +43,8 @@ void *map_section_data(mod_handle *mod, const char *name, + dos_hdr->e_lfanew); PIMAGE_SECTION_HEADER sec_hdr = IMAGE_FIRST_SECTION(nt_hdr); - for(int i = 0; i < nt_hdr->FileHeader.NumberOfSections; i++, sec_hdr++) { + + for (int i = 0; i < nt_hdr->FileHeader.NumberOfSections; i++, sec_hdr++) { if (!strncmp((char *) sec_hdr->Name, name, IMAGE_SIZEOF_SHORT_NAME)) { map->sec_len = sec_hdr->SizeOfRawData; return (char *) dos_hdr + sec_hdr->VirtualAddress; diff --git a/src/compat/section.h b/src/compat/section.h index bdb13ce..52d5936 100644 --- a/src/compat/section.h +++ b/src/compat/section.h @@ -22,27 +22,27 @@ * THE SOFTWARE. */ #ifndef SECTION_H_ -# define SECTION_H_ +#define SECTION_H_ -# include "config.h" +#include "config.h" -# if defined (__ELF__) -# define MODULE_INVALID NULL -# include +#if defined (__ELF__) +# define MODULE_INVALID NULL +# include typedef struct mod_handle { int fd; - const ElfW(Ehdr) *map; + const ElfW(Ehdr) * map; size_t len; } mod_handle; -# elif defined (__APPLE__) -# define MODULE_INVALID -1 +#elif defined (__APPLE__) +# define MODULE_INVALID -1 typedef int mod_handle; -# elif defined (_WIN32) -# include -# define MODULE_INVALID NULL +#elif defined (_WIN32) +# include +# define MODULE_INVALID NULL typedef HMODULE mod_handle; -# endif +#endif struct section_mapping { const void *map; diff --git a/src/compat/strtok.h b/src/compat/strtok.h index f733bdd..c287c33 100644 --- a/src/compat/strtok.h +++ b/src/compat/strtok.h @@ -22,24 +22,25 @@ * THE SOFTWARE. */ #ifndef COMPAT_STRTOK_H_ -# define COMPAT_STRTOK_H_ +#define COMPAT_STRTOK_H_ -# include "config.h" +#include "config.h" -# ifdef VANILLA_WIN32 -# if !HAVE_STRTOK_R -# if HAVE_STRTOK_S -# define strtok_r strtok_s -# else -static CR_INLINE char *strtok_r(char *str, const char *delim, CR_UNUSED char **saveptr) { - return strtok(str, delim); +#ifdef VANILLA_WIN32 +# if !HAVE_STRTOK_R +# if HAVE_STRTOK_S +# define strtok_r strtok_s +# else +static CR_INLINE char *strtok_r(char *str, const char *delim, CR_UNUSED char **saveptr) +{ + return strtok(str, delim); } -# endif -# endif - -# ifdef _MSC_VER -# define strdup _strdup # endif # endif +# ifdef _MSC_VER +# define strdup _strdup +# endif +#endif + #endif /* !COMPAT_STRTOK_H_ */ diff --git a/src/compat/time.c b/src/compat/time.c index 7841c43..e74f902 100644 --- a/src/compat/time.c +++ b/src/compat/time.c @@ -26,43 +26,43 @@ #include "config.h" #include "time.h" -#define KILO 1000ull -#define MEGA (KILO * 1000ull) -#define GIGA (MEGA * 1000ull) +#define KILO 1000ull +#define MEGA (KILO * 1000ull) +#define GIGA (MEGA * 1000ull) -#if defined(HAVE_GETTIMEOFDAY) +#if defined (HAVE_GETTIMEOFDAY) # include #endif -#if defined(HAVE_CLOCK_GETTIME) +#if defined (HAVE_CLOCK_GETTIME) # include #endif -#if defined(__APPLE__) +#if defined (__APPLE__) # include # include # include #endif -#if defined(_WIN32) || defined(__CYGWIN__) +#if defined (_WIN32) || defined (__CYGWIN__) # include #endif -#if defined(HAVE_CLOCK_GETTIME) -# if defined(HAVE_CLOCK_MONOTONIC_RAW) -# define CLOCK CLOCK_MONOTONIC_RAW +#if defined (HAVE_CLOCK_GETTIME) +# if defined (HAVE_CLOCK_MONOTONIC_RAW) +# define CLOCK CLOCK_MONOTONIC_RAW # else -# define CLOCK CLOCK_MONOTONIC +# define CLOCK CLOCK_MONOTONIC # endif #endif uint64_t cri_timestamp_monotonic(void) { -#if defined(HAVE_CLOCK_GETTIME) +#if defined (HAVE_CLOCK_GETTIME) struct timespec now; clock_gettime(CLOCK, &now); return now.tv_sec * GIGA + now.tv_nsec; -#elif defined(__APPLE__) +#elif defined (__APPLE__) clock_serv_t cclock; mach_timespec_t mts; @@ -71,10 +71,10 @@ uint64_t cri_timestamp_monotonic(void) mach_port_deallocate(mach_task_self(), cclock); return mts.tv_sec * GIGA + mts.tv_nsec; -#elif defined(_WIN32) || defined(__CYGWIN__) +#elif defined (_WIN32) || defined (__CYGWIN__) LARGE_INTEGER freq, count; if (!QueryPerformanceFrequency(&freq) - || !QueryPerformanceCounter(&count)) + || !QueryPerformanceCounter(&count)) return -1; uint64_t sec = count.QuadPart / freq.QuadPart; diff --git a/src/compat/time.h b/src/compat/time.h index ccb7bc1..723ba67 100644 --- a/src/compat/time.h +++ b/src/compat/time.h @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #ifndef TIMER_H_ -# define TIMER_H_ +#define TIMER_H_ -# include +#include uint64_t cri_timestamp_monotonic(void); diff --git a/src/core/abort.c b/src/core/abort.c index 840e8c7..5ad74be 100644 --- a/src/core/abort.c +++ b/src/core/abort.c @@ -33,17 +33,19 @@ jmp_buf g_pre_test; -void criterion_abort_test(void) { +void criterion_abort_test(void) +{ if (criterion_options.crash) debug_break(); longjmp(g_pre_test, 1); } -void criterion_skip_test(const char *format, ...) { +void criterion_skip_test(const char *format, ...) +{ char *msg = NULL; - if(*format) - { + + if (*format) { va_list args; va_start(args, format); cr_vasprintf(&msg, format, args); @@ -51,10 +53,10 @@ void criterion_skip_test(const char *format, ...) { } criterion_protocol_msg skip_msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_SKIP, - .name = (char *) criterion_current_test->name, - .message = msg, - ); + .phase = criterion_protocol_phase_kind_SKIP, + .name = (char *) criterion_current_test->name, + .message = msg, + ); criterion_message_set_id(skip_msg); cr_send_to_runner(&skip_msg); free(msg); @@ -62,13 +64,16 @@ void criterion_skip_test(const char *format, ...) { exit(0); } -void criterion_continue_test(void) { +void criterion_continue_test(void) +{ if (criterion_options.crash) debug_break(); } -void criterion_test_die(const char *msg, ...) { +void criterion_test_die(const char *msg, ...) +{ va_list vl; + va_start(vl, msg); char *formatted_msg = NULL; int res = cr_vasprintf(&formatted_msg, msg, vl); @@ -78,10 +83,10 @@ void criterion_test_die(const char *msg, ...) { abort(); criterion_protocol_msg abort_msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_ABORT, - .name = (char *) criterion_current_test->name, - .message = formatted_msg, - ); + .phase = criterion_protocol_phase_kind_ABORT, + .name = (char *) criterion_current_test->name, + .message = formatted_msg, + ); criterion_message_set_id(abort_msg); cr_send_to_runner(&abort_msg); diff --git a/src/core/abort.h b/src/core/abort.h index b9a2d10..b2845cc 100644 --- a/src/core/abort.h +++ b/src/core/abort.h @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #ifndef ABORT_H_ -# define ABORT_H_ +#define ABORT_H_ -# include -# include +#include +#include extern jmp_buf g_pre_test; diff --git a/src/core/client.c b/src/core/client.c index d5aacd5..d74b673 100644 --- a/src/core/client.c +++ b/src/core/client.c @@ -58,8 +58,8 @@ static const char *state_to_string[] = { [CS_SKIP] = "skip", }; -typedef bool message_handler(struct server_ctx *, struct client_ctx *, const criterion_protocol_msg *); -typedef bool phase_handler(struct server_ctx *, struct client_ctx *, const criterion_protocol_phase *); +typedef bool message_handler (struct server_ctx *, struct client_ctx *, const criterion_protocol_msg *); +typedef bool phase_handler (struct server_ctx *, struct client_ctx *, const criterion_protocol_phase *); bool handle_birth(struct server_ctx *, struct client_ctx *, const criterion_protocol_msg *); bool handle_phase(struct server_ctx *, struct client_ctx *, const criterion_protocol_msg *); @@ -75,7 +75,8 @@ static message_handler *message_handlers[] = { [criterion_protocol_submessage_message_tag] = handle_message, }; -static void get_message_id(char *out, size_t n, const criterion_protocol_msg *msg) { +static void get_message_id(char *out, size_t n, const criterion_protocol_msg *msg) +{ switch (msg->which_id) { case criterion_protocol_msg_pid_tag: snprintf(out, n, "[PID %" PRId64 "]", msg->id.pid); return; @@ -85,7 +86,8 @@ static void get_message_id(char *out, size_t n, const criterion_protocol_msg *ms } } -void init_server_context(struct server_ctx *sctx, struct criterion_global_stats *gstats) { +void init_server_context(struct server_ctx *sctx, struct criterion_global_stats *gstats) +{ sctx->subprocesses = kh_init(ht_client); sctx->clients = kh_init(ht_extern); @@ -100,7 +102,8 @@ void init_server_context(struct server_ctx *sctx, struct criterion_global_stats sctx->extern_sstats = suite_stats_init(&sctx->extern_suite); } -void destroy_client_context(struct client_ctx *ctx) { +void destroy_client_context(struct client_ctx *ctx) +{ if (ctx->kind == WORKER) { int rc = bxf_wait(ctx->instance, BXF_FOREVER); if (rc < 0) @@ -113,13 +116,14 @@ void destroy_client_context(struct client_ctx *ctx) { sfree(ctx->sstats); } -void destroy_server_context(struct server_ctx *sctx) { +void destroy_server_context(struct server_ctx *sctx) +{ khint_t k; struct client_ctx v; kh_foreach(sctx->subprocesses, k, v, { - destroy_client_context(&v); - }); + destroy_client_context(&v); + }); (void) k; (void) v; @@ -137,27 +141,32 @@ struct client_ctx *add_client_from_worker(struct server_ctx *sctx, unsigned long long pid = instance->pid; int absent; khint_t k = kh_put(ht_client, sctx->subprocesses, pid, &absent); + ctx->instance = instance; ctx->kind = WORKER; kh_value(sctx->subprocesses, k) = *ctx; return &kh_value(sctx->subprocesses, k); } -void remove_client_by_pid(struct server_ctx *sctx, int pid) { +void remove_client_by_pid(struct server_ctx *sctx, int pid) +{ khint_t k = kh_get(ht_client, sctx->subprocesses, pid); + if (k != kh_end(sctx->subprocesses)) { destroy_client_context(&kh_value(sctx->subprocesses, k)); kh_del(ht_client, sctx->subprocesses, k); } } -struct client_ctx *add_external_client(struct server_ctx *sctx, char *id) { +struct client_ctx *add_external_client(struct server_ctx *sctx, char *id) +{ int absent; khint_t k = kh_put(ht_extern, sctx->clients, id, &absent); + kh_value(sctx->clients, k) = (struct client_ctx) { .kind = EXTERN, .extern_test = { - .name = strdup(id), + .name = strdup(id), .category = "external", }, .gstats = sctx->gstats, @@ -173,9 +182,11 @@ struct client_ctx *add_external_client(struct server_ctx *sctx, char *id) { return ctx; } -static void process_client_message_impl(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) { +static void process_client_message_impl(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) +{ message_handler *handler = message_handlers[msg->data.which_value]; bool ack = false; + if (handler) ack = handler(sctx, ctx, msg); @@ -183,13 +194,14 @@ static void process_client_message_impl(struct server_ctx *sctx, struct client_c send_ack(sctx->socket, true, NULL); } -# define handler_error(Ctx, IdFmt, Id, Fmt, ...) \ - do { \ - criterion_perror(IdFmt Fmt "\n", Id, __VA_ARGS__); \ - send_ack((Ctx)->socket, false, Fmt, __VA_ARGS__); \ +#define handler_error(Ctx, IdFmt, Id, Fmt, ...) \ + do { \ + criterion_perror(IdFmt Fmt "\n", Id, __VA_ARGS__); \ + send_ack((Ctx)->socket, false, Fmt, __VA_ARGS__); \ } while (0) -struct client_ctx *process_client_message(struct server_ctx *ctx, const criterion_protocol_msg *msg) { +struct client_ctx *process_client_message(struct server_ctx *ctx, const criterion_protocol_msg *msg) +{ if (msg->version != PROTOCOL_V1) { handler_error(ctx, "%s", "", "Received message using invalid protocol version number '%" PRIi32 "'.", msg->version); return NULL; @@ -199,24 +211,22 @@ struct client_ctx *process_client_message(struct server_ctx *ctx, const criterio switch (msg->which_id) { case criterion_protocol_msg_pid_tag: { khiter_t k = kh_get(ht_client, ctx->subprocesses, msg->id.pid); - if (k != kh_end(ctx->subprocesses)) { + if (k != kh_end(ctx->subprocesses)) client = &kh_value(ctx->subprocesses, k); - } else { + else handler_error(ctx, "%s", "", "Received message identified by a PID '%" PRIi64 "' " "that is not a child process.", msg->id.pid); - } } break; case criterion_protocol_msg_uid_tag: { khiter_t k = kh_get(ht_extern, ctx->clients, msg->id.uid); bool client_found = k != kh_end(ctx->clients); - if (!client_found && msg->data.which_value == criterion_protocol_submessage_birth_tag) { + if (!client_found && msg->data.which_value == criterion_protocol_submessage_birth_tag) client = add_external_client(ctx, msg->id.uid); - } else if (client_found) { + else if (client_found) client = &kh_value(ctx->clients, k); - } else { + else handler_error(ctx, "%s", "", "Received message identified by the ID '%s'" "that did not send a birth message previously.", msg->id.uid); - } } break; default: { handler_error(ctx, "%s", "", "Received message with malformed id tag '%d'.\n", @@ -229,24 +239,25 @@ struct client_ctx *process_client_message(struct server_ctx *ctx, const criterio return client; } -#define push_event(...) \ - do { \ - push_event_noreport(__VA_ARGS__); \ - report(CR_VA_HEAD(__VA_ARGS__), ctx->tstats); \ +#define push_event(...) \ + do { \ + push_event_noreport(__VA_ARGS__); \ + report(CR_VA_HEAD(__VA_ARGS__), ctx->tstats); \ } while (0) -#define push_event_noreport(...) \ - do { \ - stat_push_event(ctx->gstats, \ - ctx->sstats, \ - ctx->tstats, \ - &(struct event) { \ - .kind = CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_TAIL(__VA_ARGS__) \ - }); \ +#define push_event_noreport(...) \ + do { \ + stat_push_event(ctx->gstats, \ + ctx->sstats, \ + ctx->tstats, \ + &(struct event) { \ + .kind = CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_TAIL(__VA_ARGS__) \ + }); \ } while (0) -bool handle_birth(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) { +bool handle_birth(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) +{ (void) sctx; (void) msg; @@ -254,11 +265,12 @@ bool handle_birth(struct server_ctx *sctx, struct client_ctx *ctx, const criteri return false; } -bool handle_pre_init(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_pre_init(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) msg; - if (ctx->state == 0) { // only pre_init if there are no nested states + if (ctx->state == 0) { /* only pre_init if there are no nested states */ push_event_noreport(PRE_INIT); report(PRE_INIT, ctx->test); log(pre_init, ctx->suite, ctx->test); @@ -266,7 +278,8 @@ bool handle_pre_init(struct server_ctx *sctx, struct client_ctx *ctx, const crit return false; } -bool handle_pre_test(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_pre_test(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) msg; @@ -278,12 +291,13 @@ bool handle_pre_test(struct server_ctx *sctx, struct client_ctx *ctx, const crit return false; } -bool handle_post_test(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_post_test(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) msg; if (ctx->state < CS_MAX_CLIENT_STATES) { - double elapsed_time = 0; // TODO: restore elapsed time handling + double elapsed_time = 0; /* TODO: restore elapsed time handling */ push_event_noreport(POST_TEST, .data = &elapsed_time); report(POST_TEST, ctx->tstats); log(post_test, ctx->tstats); @@ -291,7 +305,8 @@ bool handle_post_test(struct server_ctx *sctx, struct client_ctx *ctx, const cri return false; } -bool handle_post_fini(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_post_fini(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) ctx; (void) msg; @@ -302,7 +317,8 @@ bool handle_post_fini(struct server_ctx *sctx, struct client_ctx *ctx, const cri return false; } -bool handle_abort(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_abort(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) ctx; (void) msg; @@ -325,7 +341,7 @@ bool handle_abort(struct server_ctx *sctx, struct client_ctx *ctx, const criteri } else { struct criterion_theory_stats ths = { .formatted_args = strdup(msg->message), - .stats = ctx->tstats, + .stats = ctx->tstats, }; report(THEORY_FAIL, &ths); log(theory_fail, &ths); @@ -333,7 +349,8 @@ bool handle_abort(struct server_ctx *sctx, struct client_ctx *ctx, const criteri return false; } -bool handle_timeout(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_timeout(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) msg; @@ -347,7 +364,8 @@ bool handle_timeout(struct server_ctx *sctx, struct client_ctx *ctx, const crite return false; } -bool handle_skip(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) { +bool handle_skip(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_phase *msg) +{ (void) sctx; (void) msg; @@ -361,9 +379,10 @@ bool handle_skip(struct server_ctx *sctx, struct client_ctx *ctx, const criterio } return false; } -# define MAX_TEST_DEPTH 16 +#define MAX_TEST_DEPTH 16 -bool handle_phase(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) { +bool handle_phase(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) +{ const criterion_protocol_phase *phase_msg = &msg->data.value.phase; enum client_state new_state = phase_to_state[phase_msg->phase]; @@ -414,11 +433,11 @@ bool handle_phase(struct server_ctx *sctx, struct client_ctx *ctx, const criteri if (new_state >= CS_END) { if ((ctx->state >> 2) != 0) - ctx->state >>= 2; // pop the current state + ctx->state >>= 2; /* pop the current state */ else ctx->state = CS_END; } else if (new_state == CS_SETUP) { - ctx->state <<= 2; // shift the state to make space for a new state + ctx->state <<= 2; /* shift the state to make space for a new state */ } else { ++ctx->state; } @@ -426,7 +445,8 @@ bool handle_phase(struct server_ctx *sctx, struct client_ctx *ctx, const criteri return ack; } -bool handle_death(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) { +bool handle_death(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) +{ (void) sctx; ctx->alive = false; @@ -483,16 +503,17 @@ bool handle_death(struct server_ctx *sctx, struct client_ctx *ctx, const criteri return false; } -bool handle_assert(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) { +bool handle_assert(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) +{ (void) sctx; (void) ctx; (void) msg; const criterion_protocol_assert *asrt = &msg->data.value.assert; struct criterion_assert_stats asrt_stats = { .message = asrt->message, - .passed = asrt->passed, - .line = asrt->has_line ? asrt->line : 0, - .file = asrt->file ? asrt->file : "unknown", + .passed = asrt->passed, + .line = asrt->has_line ? asrt->line : 0, + .file = asrt->file ? asrt->file : "unknown", }; push_event_noreport(ASSERT, .data = &asrt_stats); @@ -501,7 +522,8 @@ bool handle_assert(struct server_ctx *sctx, struct client_ctx *ctx, const criter return false; } -bool handle_message(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) { +bool handle_message(struct server_ctx *sctx, struct client_ctx *ctx, const criterion_protocol_msg *msg) +{ (void) sctx; (void) ctx; const criterion_protocol_log *lg = &msg->data.value.message; diff --git a/src/core/client.h b/src/core/client.h index d9bd3e8..08ec710 100644 --- a/src/core/client.h +++ b/src/core/client.h @@ -22,27 +22,27 @@ * THE SOFTWARE. */ #ifndef CLIENT_H_ -# define CLIENT_H_ +#define CLIENT_H_ -# include -# include +#include +#include -// order matters here +/* order matters here */ enum client_state { CS_SETUP, CS_MAIN, CS_TEARDOWN, CS_END, - // The states belows are non-states that should not be - // added in the state count + /* The states belows are non-states that should not be + added in the state count */ CS_ABORT, CS_TIMEOUT, CS_SKIP, }; -// always make it a power of 2 -# define CS_MAX_CLIENT_STATES 4 +/* always make it a power of 2 */ +#define CS_MAX_CLIENT_STATES 4 enum client_kind { WORKER, diff --git a/src/core/ordered-set.c b/src/core/ordered-set.c index 7738ca7..b2a7d68 100644 --- a/src/core/ordered-set.c +++ b/src/core/ordered-set.c @@ -27,58 +27,63 @@ #include #include "common.h" -static void destroy_ordered_set(void *ptr, CR_UNUSED void *meta) { +static void destroy_ordered_set(void *ptr, CR_UNUSED void *meta) +{ sfree(((struct criterion_ordered_set *) ptr)->first); } static CR_INLINE void nothing(CR_UNUSED void *ptr, CR_UNUSED void *meta) {} -static void destroy_ordered_set_node(void *ptr, void *meta) { +static void destroy_ordered_set_node(void *ptr, void *meta) +{ struct criterion_ordered_set *set = *(void **) meta; struct criterion_ordered_set_node *n = ptr; + DEF(set->dtor, nothing)(n + 1, NULL); sfree(((struct criterion_ordered_set_node *) ptr)->next); } struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, - f_destructor dtor) { - + f_destructor dtor) +{ struct criterion_ordered_set *newset = smalloc( - .size = sizeof (struct criterion_ordered_set), - .dtor = destroy_ordered_set + .size = sizeof (struct criterion_ordered_set), + .dtor = destroy_ordered_set ); struct criterion_ordered_set data = { .cmp = cmp, .dtor = dtor }; + memcpy(newset, &data, sizeof (struct criterion_ordered_set)); return newset; } void *insert_ordered_set(struct criterion_ordered_set *l, - void *ptr, - size_t size) { + void *ptr, + size_t size) +{ int cmp; struct criterion_ordered_set_node *n, *prev = NULL; + for (n = l->first; n && (cmp = l->cmp(ptr, n + 1)) > 0; n = n->next) prev = n; - if (n && !cmp) // element already exists + if (n && !cmp) /* element already exists */ return n + 1; struct criterion_ordered_set_node *new = smalloc( - .size = sizeof(struct criterion_ordered_set_node) + size, - .dtor = destroy_ordered_set_node, - .meta = { &l, sizeof (void *) }, + .size = sizeof (struct criterion_ordered_set_node) + size, + .dtor = destroy_ordered_set_node, + .meta = { &l, sizeof (void *) }, ); if (!new) return NULL; memcpy(new + 1, ptr, size); new->next = n; - if (prev) { + if (prev) prev->next = new; - } else { + else l->first = new; - } ++l->size; return new + 1; diff --git a/src/core/report.c b/src/core/report.c index e07ce42..9d1b8b3 100644 --- a/src/core/report.c +++ b/src/core/report.c @@ -33,22 +33,22 @@ #include "config.h" #include "compat/posix.h" -#define CR_HSEC_STR(Kind) CR_HSEC_STR_(CR_HOOK_SECTION(Kind)) -#define CR_HSEC_STR_(S) CR_HSEC_STR__(S) -#define CR_HSEC_STR__(S) #S +#define CR_HSEC_STR(Kind) CR_HSEC_STR_(CR_HOOK_SECTION(Kind)) +#define CR_HSEC_STR_(S) CR_HSEC_STR__(S) +#define CR_HSEC_STR__(S) #S -#define IMPL_CALL_REPORT_HOOKS(Kind) \ - void call_report_hooks_##Kind(void *data) { \ - mod_handle self; \ - struct section_mapping sect; \ - if (!open_module_self(&self)) \ - abort(); \ - void *start = map_section_data(&self, CR_HSEC_STR(Kind), §); \ - if (!start) \ - return; \ - void *end = (char *)start + sect.sec_len; \ - for (f_report_hook *hook = start; hook < (f_report_hook*) end; ++hook) \ - (*hook ? *hook : nothing)(data); \ +#define IMPL_CALL_REPORT_HOOKS(Kind) \ + void call_report_hooks_ ## Kind(void *data) { \ + mod_handle self; \ + struct section_mapping sect; \ + if (!open_module_self(&self)) \ + abort(); \ + void *start = map_section_data(&self, CR_HSEC_STR(Kind), §); \ + if (!start) \ + return; \ + void *end = (char *) start + sect.sec_len; \ + for (f_report_hook *hook = start; hook < (f_report_hook *) end; ++hook) \ + (*hook ? *hook : nothing)(data); \ } IMPL_CALL_REPORT_HOOKS(PRE_ALL) @@ -63,15 +63,25 @@ IMPL_CALL_REPORT_HOOKS(POST_FINI) IMPL_CALL_REPORT_HOOKS(POST_SUITE) IMPL_CALL_REPORT_HOOKS(POST_ALL) -ReportHook(PRE_ALL)(CR_UNUSED struct criterion_test_set *arg) {} -ReportHook(PRE_SUITE)(CR_UNUSED struct criterion_suite_set *arg) {} -ReportHook(PRE_INIT)(CR_UNUSED struct criterion_test *arg) {} -ReportHook(PRE_TEST)(CR_UNUSED struct criterion_test *arg) {} -ReportHook(ASSERT)(CR_UNUSED struct criterion_assert_stats *arg) {} -ReportHook(THEORY_FAIL)(CR_UNUSED struct criterion_theory_stats *arg) {} -ReportHook(TEST_CRASH)(CR_UNUSED struct criterion_test_stats *arg) {} -ReportHook(POST_TEST)(CR_UNUSED struct criterion_test_stats *arg) {} -ReportHook(POST_FINI)(CR_UNUSED struct criterion_test_stats *arg) {} -ReportHook(POST_SUITE)(CR_UNUSED struct criterion_suite_stats *arg) {} -ReportHook(POST_ALL)(CR_UNUSED struct criterion_global_stats *arg) {} - +ReportHook(PRE_ALL)(CR_UNUSED struct criterion_test_set *arg) { +} +ReportHook(PRE_SUITE)(CR_UNUSED struct criterion_suite_set *arg) { +} +ReportHook(PRE_INIT)(CR_UNUSED struct criterion_test *arg) { +} +ReportHook(PRE_TEST)(CR_UNUSED struct criterion_test *arg) { +} +ReportHook(ASSERT)(CR_UNUSED struct criterion_assert_stats *arg) { +} +ReportHook(THEORY_FAIL)(CR_UNUSED struct criterion_theory_stats *arg) { +} +ReportHook(TEST_CRASH)(CR_UNUSED struct criterion_test_stats *arg) { +} +ReportHook(POST_TEST)(CR_UNUSED struct criterion_test_stats *arg) { +} +ReportHook(POST_FINI)(CR_UNUSED struct criterion_test_stats *arg) { +} +ReportHook(POST_SUITE)(CR_UNUSED struct criterion_suite_stats *arg) { +} +ReportHook(POST_ALL)(CR_UNUSED struct criterion_global_stats *arg) { +} diff --git a/src/core/report.h b/src/core/report.h index f573e13..326fb64 100644 --- a/src/core/report.h +++ b/src/core/report.h @@ -22,16 +22,16 @@ * THE SOFTWARE. */ #ifndef REPORT_H_ -# define REPORT_H_ +#define REPORT_H_ -# include "criterion/hooks.h" -# include "criterion/options.h" +#include "criterion/hooks.h" +#include "criterion/options.h" -# define report(Kind, Data) report_(Kind, Data) -# define report_(Kind, Data) call_report_hooks_##Kind(Data) +#define report(Kind, Data) report_(Kind, Data) +#define report_(Kind, Data) call_report_hooks_ ## Kind(Data) -# define DECL_CALL_REPORT_HOOKS(Kind) \ - void call_report_hooks_##Kind(void *data) +#define DECL_CALL_REPORT_HOOKS(Kind) \ + void call_report_hooks_ ## Kind(void *data) DECL_CALL_REPORT_HOOKS(PRE_ALL); DECL_CALL_REPORT_HOOKS(PRE_SUITE); diff --git a/src/core/runner.c b/src/core/runner.c index c1f6cea..024dd45 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -59,65 +59,70 @@ # include #else # define ENABLE_VALGRIND_ERRORS -# define RUNNING_ON_VALGRIND 0 +# define RUNNING_ON_VALGRIND 0 #endif typedef const char *const msg_t; #ifdef ENABLE_NLS static msg_t msg_valgrind_jobs = N_("%1$sWarning! Criterion has detected " - "that it is running under valgrind, but the number of jobs have been " - "explicitely set. Reports might appear confusing!%2$s\n"); + "that it is running under valgrind, but the number of jobs have been " + "explicitely set. Reports might appear confusing!%2$s\n"); #else static msg_t msg_valgrind_jobs = "%sWarning! Criterion has detected " "that it is running under valgrind, but the number of jobs have been " "explicitely set. Reports might appear confusing!%s\n"; #endif -// This is here to make the test suite & test sections non-empty +/* This is here to make the test suite & test sections non-empty */ CR_SECTION_("cr_sts") struct criterion_suite *dummy_suite = NULL; -CR_SECTION_("cr_tst") struct criterion_test *dummy_test = NULL; +CR_SECTION_("cr_tst") struct criterion_test *dummy_test = NULL; static int cmp_suite(void *a, void *b) { struct criterion_suite *s1 = a, *s2 = b; + return strcmp(s1->name, s2->name); } static int cmp_test(void *a, void *b) { struct criterion_test *s1 = a, *s2 = b; + return strcmp(s1->name, s2->name); } static void dtor_suite_set(void *ptr, CR_UNUSED void *meta) { struct criterion_suite_set *s = ptr; + sfree(s->tests); } static void dtor_test_set(void *ptr, CR_UNUSED void *meta) { struct criterion_test_set *t = ptr; + sfree(t->suites); } CR_API void criterion_register_test(struct criterion_test_set *set, struct criterion_test *test) { - struct criterion_suite_set css = { .suite = { .name = test->category }, }; struct criterion_suite_set *s = insert_ordered_set(set->suites, &css, sizeof (css)); + if (!s->tests) s->tests = new_ordered_set(cmp_test, NULL); - insert_ordered_set(s->tests, test, sizeof(*test)); + insert_ordered_set(s->tests, test, sizeof (*test)); ++set->tests; } -struct criterion_test_set *criterion_init(void) { +struct criterion_test_set *criterion_init(void) +{ struct criterion_ordered_set *suites = new_ordered_set(cmp_suite, dtor_suite_set); mod_handle self; @@ -140,8 +145,8 @@ struct criterion_test_set *criterion_init(void) { } struct criterion_test_set *set = smalloc( - .size = sizeof (struct criterion_test_set), - .dtor = dtor_test_set + .size = sizeof (struct criterion_test_set), + .dtor = dtor_test_set ); *set = (struct criterion_test_set) { @@ -166,37 +171,38 @@ struct criterion_test_set *criterion_init(void) { return set; } -#define push_event(...) \ - do { \ - stat_push_event(ctx->stats, \ - ctx->suite_stats, \ - ctx->test_stats, \ - &(struct event) { \ - .kind = CR_VA_HEAD(__VA_ARGS__), \ - CR_VA_TAIL(__VA_ARGS__) \ - }); \ - report(CR_VA_HEAD(__VA_ARGS__), ctx->test_stats); \ +#define push_event(...) \ + do { \ + stat_push_event(ctx->stats, \ + ctx->suite_stats, \ + ctx->test_stats, \ + &(struct event) { \ + .kind = CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_TAIL(__VA_ARGS__) \ + }); \ + report(CR_VA_HEAD(__VA_ARGS__), ctx->test_stats); \ } while (0) -void disable_unmatching(struct criterion_test_set *set) { - if (!compile_pattern(criterion_options.pattern)) { +void disable_unmatching(struct criterion_test_set *set) +{ + if (!compile_pattern(criterion_options.pattern)) exit(3); - } FOREACH_SET(struct criterion_suite_set *s, set->suites) { if ((s->suite.data && s->suite.data->disabled) || !s->tests) continue; FOREACH_SET(struct criterion_test *test, s->tests) { int ret = match(test->data->identifier_); - if (ret == 0) { + + if (ret == 0) test->data->disabled = true; - } } } free_pattern(); } -CR_API struct criterion_test_set *criterion_initialize(void) { +CR_API struct criterion_test_set *criterion_initialize(void) +{ init_i18n(); #ifndef ENABLE_VALGRIND_ERRORS @@ -216,7 +222,8 @@ CR_API struct criterion_test_set *criterion_initialize(void) { return criterion_init(); } -CR_API void criterion_finalize(struct criterion_test_set *set) { +CR_API void criterion_finalize(struct criterion_test_set *set) +{ sfree(set); #ifndef ENABLE_VALGRIND_ERRORS @@ -226,10 +233,12 @@ CR_API void criterion_finalize(struct criterion_test_set *set) { criterion_free_output(); } -static struct client_ctx *spawn_next_client(struct server_ctx *sctx, ccrContext *ctx) { +static struct client_ctx *spawn_next_client(struct server_ctx *sctx, ccrContext *ctx) +{ struct client_ctx new_ctx; bxf_instance *instance = cri_run_next_test(NULL, NULL, NULL, &new_ctx, ctx); + if (!instance) return NULL; @@ -237,9 +246,9 @@ static struct client_ctx *spawn_next_client(struct server_ctx *sctx, ccrContext } static void run_tests_async(struct criterion_test_set *set, - struct criterion_global_stats *stats, - const char *url, - int socket) + struct criterion_global_stats *stats, + const char *url, + int socket) { ccrContext ctx = 0; @@ -248,11 +257,12 @@ static void run_tests_async(struct criterion_test_set *set, int has_msg = 0; struct server_ctx sctx; + init_server_context(&sctx, stats); sctx.socket = socket; - // initialization of coroutine + /* initialization of coroutine */ cri_run_next_test(set, stats, url, NULL, &ctx); for (size_t i = 0; i < nb_workers; ++i) { @@ -270,14 +280,13 @@ static void run_tests_async(struct criterion_test_set *set, while ((has_msg = read_message(socket, &msg)) == 1) { struct client_ctx *cctx = process_client_message(&sctx, &msg); - // drop invalid messages + /* drop invalid messages */ if (!cctx) continue; if (!cctx->alive) { - if ((cctx->tstats->test_status == CR_STATUS_FAILED) && criterion_options.fail_fast) { + if ((cctx->tstats->test_status == CR_STATUS_FAILED) && criterion_options.fail_fast) cr_terminate(cctx->gstats); - } if (cctx->kind == WORKER) { remove_client_by_pid(&sctx, cctx->instance->pid); @@ -348,9 +357,8 @@ CR_API int criterion_run_all_tests(struct criterion_test_set *set) VALGRIND_DISABLE_ERROR_REPORTING; #endif - if (criterion_options.pattern) { + if (criterion_options.pattern) disable_unmatching(set); - } if (criterion_options.debug) { criterion_options.jobs = 1; diff --git a/src/core/runner.h b/src/core/runner.h index c479641..ab4c971 100644 --- a/src/core/runner.h +++ b/src/core/runner.h @@ -22,21 +22,21 @@ * THE SOFTWARE. */ #ifndef CRITERION_RUNNER_H_ -# define CRITERION_RUNNER_H_ +#define CRITERION_RUNNER_H_ -# include "criterion/types.h" -# include "compat/pipe.h" +#include "criterion/types.h" +#include "compat/pipe.h" struct criterion_test_set *criterion_init(void); -# define FOREACH_TEST_SEC(Test, Start, End) \ - for (struct criterion_test **Test = Start; \ - Test < (struct criterion_test**) End; \ +#define FOREACH_TEST_SEC(Test, Start, End) \ + for (struct criterion_test **Test = Start; \ + Test < (struct criterion_test **) End; \ ++Test) -# define FOREACH_SUITE_SEC(Suite, Start, End) \ - for (struct criterion_suite **Suite = Start; \ - Suite < (struct criterion_suite**) End; \ +#define FOREACH_SUITE_SEC(Suite, Start, End) \ + for (struct criterion_suite **Suite = Start; \ + Suite < (struct criterion_suite **) End; \ ++Suite) #endif /* !CRITERION_RUNNER_H_ */ diff --git a/src/core/runner_coroutine.c b/src/core/runner_coroutine.c index cccd18c..a596c81 100644 --- a/src/core/runner_coroutine.c +++ b/src/core/runner_coroutine.c @@ -47,7 +47,7 @@ # include #else # define ENABLE_VALGRIND_ERRORS -# define RUNNING_ON_VALGRIND 0 +# define RUNNING_ON_VALGRIND 0 #endif /* *INDENT-OFF* - This is a structure definition in disguise */ @@ -69,7 +69,7 @@ ccrBeginDefineContextType(run_next_context); ccrEndDefineContextType; /* *INDENT-ON* */ -CR_API const struct criterion_test *criterion_current_test; +CR_API const struct criterion_test *criterion_current_test; CR_API const struct criterion_suite *criterion_current_suite; static int serialize_test(bxf_context ctx, struct criterion_test *test, @@ -79,36 +79,36 @@ static int serialize_test(bxf_context ctx, struct criterion_test *test, if (!rc) rc = bxf_context_addobject(ctx, "criterion.test.name", - test->name, strlen(test->name) + 1); + test->name, strlen(test->name) + 1); if (!rc) rc = bxf_context_addobject(ctx, "criterion.test.suite", - test->category, strlen(test->category) + 1); + test->category, strlen(test->category) + 1); if (!rc && test->test) rc = bxf_context_addfnaddr(ctx, "criterion.test.test", - test->test); + test->test); if (!rc) rc = bxf_context_addobject(ctx, "criterion.test.extra", - test->data, sizeof (*test->data)); + test->data, sizeof (*test->data)); if (!rc && test->data->init) rc = bxf_context_addfnaddr(ctx, "criterion.test.extra.init", - test->data->init); + test->data->init); if (!rc && test->data->fini) rc = bxf_context_addfnaddr(ctx, "criterion.test.extra.fini", - test->data->fini); + test->data->fini); if (!rc) rc = bxf_context_addobject(ctx, "criterion.suite.name", - suite->name, strlen(suite->name) + 1); + suite->name, strlen(suite->name) + 1); if (suite->data) { if (!rc) rc = bxf_context_addobject(ctx, "criterion.suite.extra", - suite->data, sizeof (*suite->data)); + suite->data, sizeof (*suite->data)); if (!rc && suite->data->init) rc = bxf_context_addfnaddr(ctx, "criterion.suite.extra.init", - suite->data->init); + suite->data->init); if (!rc && suite->data->fini) rc = bxf_context_addfnaddr(ctx, "criterion.suite.extra.fini", - suite->data->fini); + suite->data->fini); } return rc; } @@ -124,44 +124,44 @@ static int deserialize_test(struct criterion_test *test, int rc; rc = bxf_context_getobject(ctx, "criterion.test.name", - (void **)&test->name); + (void **) &test->name); if (rc <= 0) goto err; rc = bxf_context_getobject(ctx, "criterion.test.suite", - (void **)&test->category); + (void **) &test->category); if (rc <= 0) goto err; rc = bxf_context_getfnaddr(ctx, "criterion.test.test", - &test->test); + &test->test); if (rc < 0) goto err; rc = bxf_context_getobject(ctx, "criterion.test.extra", - (void **)&test_data); + (void **) &test_data); if (rc <= 0) goto err; rc = bxf_context_getfnaddr(ctx, "criterion.test.extra.init", - &test_data->init); + &test_data->init); if (rc < 0) goto err; rc = bxf_context_getfnaddr(ctx, "criterion.test.extra.fini", - &test_data->fini); + &test_data->fini); if (rc < 0) goto err; rc = bxf_context_getobject(ctx, "criterion.suite.name", - (void **)&suite->name); + (void **) &suite->name); if (rc <= 0) goto err; rc = bxf_context_getobject(ctx, "criterion.suite.extra", - (void **)&suite_data); + (void **) &suite_data); if (rc < 0) goto err; if (suite_data) { rc = bxf_context_getfnaddr(ctx, "criterion.suite.extra.init", - &suite_data->init); + &suite_data->init); if (rc < 0) goto err; rc = bxf_context_getfnaddr(ctx, "criterion.suite.extra.fini", - &suite_data->fini); + &suite_data->fini); if (rc < 0) goto err; } @@ -175,7 +175,6 @@ err: static int run_test_child(void) { - #ifndef ENABLE_VALGRIND_ERRORS VALGRIND_DISABLE_ERROR_REPORTING; #endif @@ -191,7 +190,7 @@ static int run_test_child(void) int rc = deserialize_test(&test, &suite); if (rc > 0) - rc = bxf_context_getobject(ctx, "criterion.url", (void **)&url); + rc = bxf_context_getobject(ctx, "criterion.url", (void **) &url); if (rc < 0) cr_panic("Could not get the test context: %s", strerror(-rc)); else if (!rc) @@ -203,7 +202,7 @@ static int run_test_child(void) if (g_client_socket < 0) cr_panic("could not initialize the message client: %s", strerror(errno)); - // Notify the runner that the test was born + /* Notify the runner that the test was born */ criterion_protocol_msg msg = criterion_message(birth, .name = (char *) test.name); criterion_message_set_id(msg); cr_send_to_runner(&msg); @@ -233,16 +232,16 @@ static int run_test_child(void) static void death_callback(bxf_instance *instance) { int result = instance->status.signal - ? criterion_protocol_death_result_type_CRASH - : criterion_protocol_death_result_type_NORMAL; + ? criterion_protocol_death_result_type_CRASH + : criterion_protocol_death_result_type_NORMAL; int code = instance->status.signal - ? instance->status.signal - : instance->status.exit; + ? instance->status.signal + : instance->status.exit; if (instance->status.timed_out) { criterion_protocol_msg msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_TIMEOUT, - ); + .phase = criterion_protocol_phase_kind_TIMEOUT, + ); msg.id.pid = instance->pid; cr_send_to_runner(&msg); @@ -252,10 +251,10 @@ static void death_callback(bxf_instance *instance) } criterion_protocol_msg msg = criterion_message(death, - .result = result, - .has_status = true, - .status = code, - ); + .result = result, + .has_status = true, + .status = code, + ); msg.id.pid = instance->pid; cr_send_to_runner(&msg); @@ -276,7 +275,7 @@ static bxf_instance *run_test(struct run_next_context *ctx, if (!rc && ctx->params.params) { void *param = (char *) ctx->params.params + ctx->i * ctx->params.size; rc = bxf_context_addobject(inst_ctx, "criterion.param", - param, ctx->params.size); + param, ctx->params.size); } if (!rc) @@ -286,8 +285,8 @@ static bxf_instance *run_test(struct run_next_context *ctx, cr_panic("Could not initialize test context: %s", strerror(-rc)); struct bxf_spawn_params sp = { - .fn = run_test_child, - .callback = death_callback, + .fn = run_test_child, + .callback = death_callback, .inherit.context = inst_ctx, }; @@ -301,11 +300,11 @@ static bxf_instance *run_test(struct run_next_context *ctx, default: break; } } else { - debugger = (enum bxf_debugger)(criterion_options.debug - 1); + debugger = (enum bxf_debugger) (criterion_options.debug - 1); } if (!debugger) cr_panic("Could not choose the debugger server for an " - "unknown compiler"); + "unknown compiler"); sp.debug.debugger = debugger; sp.debug.tcp = criterion_options.debug_port; } @@ -341,11 +340,9 @@ static bxf_instance *run_test(struct run_next_context *ctx, static CR_INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { - return t->data->disabled || (s->data && s->data->disabled); } - static int skip_disabled(struct run_next_context *ctx) { if (is_disabled(ctx->test, ctx->suite_stats->suite)) { @@ -381,7 +378,7 @@ bxf_instance *cri_run_next_test(struct criterion_test_set *p_set, } while (ctx->set == NULL && ctx->stats == NULL); for (ctx->ns = ctx->set->suites->first; ctx->ns; ctx->ns = ctx->ns->next) { - ctx->suite_set = (void*) (ctx->ns + 1); + ctx->suite_set = (void *) (ctx->ns + 1); if (!ctx->suite_set->tests) continue; @@ -394,14 +391,13 @@ bxf_instance *cri_run_next_test(struct criterion_test_set *p_set, stat_push_event(ctx->stats, ctx->suite_stats, NULL, &(struct event) { .kind = PRE_SUITE }); for (ctx->nt = ctx->suite_set->tests->first; ctx->nt; ctx->nt = ctx->nt->next) { - ctx->test = (void*) (ctx->nt + 1); + ctx->test = (void *) (ctx->nt + 1); if (skip_disabled(ctx)) continue; if (ctx->test->data->kind_ == CR_TEST_PARAMETERIZED && ctx->test->data->param_) { - ctx->params = ctx->test->data->param_(); for (ctx->i = 0; ctx->i < ctx->params.length; ++ctx->i) ccrReturn(run_test(ctx, client)); diff --git a/src/core/runner_coroutine.h b/src/core/runner_coroutine.h index cb27c91..37980c6 100644 --- a/src/core/runner_coroutine.h +++ b/src/core/runner_coroutine.h @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #ifndef RUNNER_COROUTINE_H_ -# define RUNNER_COROUTINE_H_ +#define RUNNER_COROUTINE_H_ -# include -# include "coroutine.h" +#include +#include "coroutine.h" bxf_instance *cri_run_next_test(struct criterion_test_set *p_set, struct criterion_global_stats *p_stats, diff --git a/src/core/stats.c b/src/core/stats.c index ee58f7f..30d9865 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -30,98 +30,113 @@ #include typedef struct criterion_global_stats s_glob_stats; -typedef struct criterion_suite_stats s_suite_stats; -typedef struct criterion_test_stats s_test_stats; +typedef struct criterion_suite_stats s_suite_stats; +typedef struct criterion_test_stats s_test_stats; typedef struct criterion_assert_stats s_assert_stats; static void push_pre_suite(s_glob_stats *stats, - s_suite_stats *sstats, - s_test_stats *tstats, - void *data); + s_suite_stats *sstats, + s_test_stats *tstats, + void *data); static void push_pre_init(s_glob_stats *stats, - s_suite_stats *sstats, - s_test_stats *tstats, - void *data); + s_suite_stats *sstats, + s_test_stats *tstats, + void *data); static void push_assert(s_glob_stats *stats, - s_suite_stats *sstats, - s_test_stats *tstats, - void *data); + s_suite_stats *sstats, + s_test_stats *tstats, + void *data); static void push_post_test(s_glob_stats *stats, - s_suite_stats *sstats, - s_test_stats *tstats, - void *data); + s_suite_stats *sstats, + s_test_stats *tstats, + void *data); static void push_test_crash(s_glob_stats *stats, - s_suite_stats *sstats, - s_test_stats *tstats, - void *data); + s_suite_stats *sstats, + s_test_stats *tstats, + void *data); static void nothing(CR_UNUSED s_glob_stats *stats, - CR_UNUSED s_suite_stats *sstats, - CR_UNUSED s_test_stats *tstats, - CR_UNUSED void *data) { + CR_UNUSED s_suite_stats *sstats, + CR_UNUSED s_test_stats *tstats, + CR_UNUSED void *data) +{ } -static void destroy_stats(void *ptr, CR_UNUSED void *meta) { +static void destroy_stats(void *ptr, CR_UNUSED void *meta) +{ s_glob_stats *stats = ptr; + for (s_suite_stats *s = stats->suites, *next; s; s = next) { next = s->next; sfree(s); } } -s_glob_stats *stats_init(void) { +s_glob_stats *stats_init(void) +{ s_glob_stats *stats = smalloc( - .size = sizeof (s_glob_stats), - .kind = SHARED, - .dtor = destroy_stats + .size = sizeof (s_glob_stats), + .kind = SHARED, + .dtor = destroy_stats ); + *stats = (s_glob_stats) { .suites = NULL }; return stats; } -static void destroy_suite_stats(void *ptr, CR_UNUSED void *meta) { +static void destroy_suite_stats(void *ptr, CR_UNUSED void *meta) +{ s_suite_stats *stats = ptr; + for (s_test_stats *t = stats->tests, *next; t; t = next) { next = t->next; sfree(t); } } -s_suite_stats *suite_stats_init(struct criterion_suite *s) { +s_suite_stats *suite_stats_init(struct criterion_suite *s) +{ s_suite_stats *stats = smalloc( - .size = sizeof (s_suite_stats), - .kind = SHARED, - .dtor = destroy_suite_stats + .size = sizeof (s_suite_stats), + .kind = SHARED, + .dtor = destroy_suite_stats ); + *stats = (s_suite_stats) { .suite = s }; return stats; } -static void destroy_test_stats(void *ptr, CR_UNUSED void *meta) { +static void destroy_test_stats(void *ptr, CR_UNUSED void *meta) +{ s_test_stats *stats = ptr; + for (s_assert_stats *a = stats->asserts, *next; a; a = next) { next = a->next; sfree(a); } - free((void*)stats->message); + free((void *) stats->message); } -static void destroy_assert_stats(void *ptr, CR_UNUSED void *meta) { +static void destroy_assert_stats(void *ptr, CR_UNUSED void *meta) +{ s_assert_stats *stats = ptr; + free((void *) stats->message); free((void *) stats->file); } -s_test_stats *test_stats_init(struct criterion_test *t) { +s_test_stats *test_stats_init(struct criterion_test *t) +{ s_test_stats *stats = smalloc( - .size = sizeof (s_test_stats), - .kind = SHARED, - .dtor = destroy_test_stats + .size = sizeof (s_test_stats), + .kind = SHARED, + .dtor = destroy_test_stats ); + *stats = (s_test_stats) { - .test = t, - .progress = t->data->line_, - .file = t->data->file_ + .test = t, + .progress = t->data->line_, + .file = t->data->file_ }; return stats; } @@ -129,21 +144,22 @@ s_test_stats *test_stats_init(struct criterion_test *t) { typedef void (*f_handle)(s_glob_stats *, s_suite_stats *, s_test_stats *, void *); void stat_push_event(s_glob_stats *stats, - s_suite_stats *suite, - s_test_stats *test, - struct event *data) { + s_suite_stats *suite, + s_test_stats *test, + struct event *data) +{ static const f_handle handles[] = { - nothing, // PRE_ALL - push_pre_suite, // PRE_SUITE - push_pre_init, // PRE_INIT - nothing, // PRE_TEST - push_assert, // ASSERT - nothing, // THEORY_FAIL - push_test_crash, // TEST_CRASH - push_post_test, // POST_TEST - nothing, // POST_FINI - nothing, // PRE_SUITE - nothing, // POST_ALL + nothing, /* PRE_ALL */ + push_pre_suite, /* PRE_SUITE */ + push_pre_init, /* PRE_INIT */ + nothing, /* PRE_TEST */ + push_assert, /* ASSERT */ + nothing, /* THEORY_FAIL */ + push_test_crash, /* TEST_CRASH */ + push_post_test, /* POST_TEST */ + nothing, /* POST_FINI */ + nothing, /* PRE_SUITE */ + nothing, /* POST_ALL */ }; assert(data->kind > 0); @@ -153,19 +169,20 @@ void stat_push_event(s_glob_stats *stats, } static void push_pre_suite(s_glob_stats *stats, - s_suite_stats *suite, - CR_UNUSED s_test_stats *test, - CR_UNUSED void *ptr) { + s_suite_stats *suite, + CR_UNUSED s_test_stats *test, + CR_UNUSED void *ptr) +{ suite->next = stats->suites; stats->suites = sref(suite); ++stats->nb_suites; } - static void push_pre_init(s_glob_stats *stats, - s_suite_stats *suite, - s_test_stats *test, - CR_UNUSED void *ptr) { + s_suite_stats *suite, + s_test_stats *test, + CR_UNUSED void *ptr) +{ test->next = suite->tests; suite->tests = sref(test); ++stats->nb_tests; @@ -178,15 +195,16 @@ static void push_pre_init(s_glob_stats *stats, } static void push_assert(s_glob_stats *stats, - s_suite_stats *suite, - s_test_stats *test, - void *ptr) { - + s_suite_stats *suite, + s_test_stats *test, + void *ptr) +{ s_assert_stats *data = ptr; s_assert_stats *dup = smalloc( - .size = sizeof (s_assert_stats), - .dtor = destroy_assert_stats); + .size = sizeof (s_assert_stats), + .dtor = destroy_assert_stats); + memcpy(dup, data, sizeof (s_assert_stats)); dup->message = strdup(data->message); dup->file = strdup(data->file); @@ -209,18 +227,18 @@ static void push_assert(s_glob_stats *stats, } static void push_post_test(s_glob_stats *stats, - s_suite_stats *suite, - s_test_stats *test, - void *ptr) { + s_suite_stats *suite, + s_test_stats *test, + void *ptr) +{ double *data = ptr; test->elapsed_time = (float) *data; if (test->failed_asserts > 0 || test->timed_out || test->signal != test->test->data->signal - || test->exit_code != test->test->data->exit_code) { + || test->exit_code != test->test->data->exit_code) test->test_status = CR_STATUS_FAILED; - } switch (test->test_status) { case CR_STATUS_FAILED: @@ -236,13 +254,13 @@ static void push_post_test(s_glob_stats *stats, ++suite->tests_skipped; break; } - } static void push_test_crash(s_glob_stats *stats, - s_suite_stats *suite, - s_test_stats *test, - CR_UNUSED void *ptr) { + s_suite_stats *suite, + s_test_stats *test, + CR_UNUSED void *ptr) +{ test->test_status = CR_STATUS_FAILED; test->crashed = 1; ++suite->tests_failed; diff --git a/src/core/stats.h b/src/core/stats.h index ff3fed8..8caa121 100644 --- a/src/core/stats.h +++ b/src/core/stats.h @@ -22,17 +22,17 @@ * THE SOFTWARE. */ #ifndef STATS_H_ -# define STATS_H_ +#define STATS_H_ -# include "criterion/stats.h" -# include "io/event.h" +#include "criterion/stats.h" +#include "io/event.h" struct criterion_global_stats *stats_init(void); struct criterion_test_stats *test_stats_init(struct criterion_test *t); struct criterion_suite_stats *suite_stats_init(struct criterion_suite *s); void stat_push_event(struct criterion_global_stats *stats, - struct criterion_suite_stats *suite, - struct criterion_test_stats *test, - struct event *data); + struct criterion_suite_stats *suite, + struct criterion_test_stats *test, + struct event *data); #endif /* !STATS_H_ */ diff --git a/src/core/test.c b/src/core/test.c index cb0ab33..3fe38fa 100644 --- a/src/core/test.c +++ b/src/core/test.c @@ -31,19 +31,22 @@ #include "protocol/messages.h" #include "io/event.h" -extern const struct criterion_test *criterion_current_test; +extern const struct criterion_test *criterion_current_test; extern const struct criterion_suite *criterion_current_suite; -static void send_event(int phase) { +static void send_event(int phase) +{ criterion_protocol_msg msg = criterion_message(phase, - .phase = phase, - .name = (char *) criterion_current_test->name, - ); + .phase = phase, + .name = (char *) criterion_current_test->name, + ); + criterion_message_set_id(msg); cr_send_to_runner(&msg); } -void criterion_internal_test_setup(void) { +void criterion_internal_test_setup(void) +{ const struct criterion_suite *suite = criterion_current_suite; const struct criterion_test *test = criterion_current_test; @@ -58,7 +61,8 @@ static void *getparam(void) void *param; bxf_context ctx = bxf_context_current(); - int rc = bxf_context_getobject(ctx, "criterion.param", (void **)¶m); + int rc = bxf_context_getobject(ctx, "criterion.param", (void **) ¶m); + if (rc < 0) { cr_log_error("Could not retrieve test parameter -- aborting."); abort(); @@ -66,7 +70,8 @@ static void *getparam(void) return param; } -void criterion_internal_test_main(void (*fn)(void)) { +void criterion_internal_test_main(void (*fn)(void)) +{ const struct criterion_test *test = criterion_current_test; send_event(criterion_protocol_phase_kind_MAIN); @@ -75,7 +80,7 @@ void criterion_internal_test_main(void (*fn)(void)) { if (!test->data->param_) { fn(); } else { - void(*param_test_func)(void *) = (void(*)(void*)) fn; + void (*param_test_func)(void *) = (void (*)(void *))fn; param_test_func(getparam()); } } @@ -83,7 +88,8 @@ void criterion_internal_test_main(void (*fn)(void)) { send_event(criterion_protocol_phase_kind_TEARDOWN); } -void criterion_internal_test_teardown(void) { +void criterion_internal_test_teardown(void) +{ const struct criterion_suite *suite = criterion_current_suite; const struct criterion_test *test = criterion_current_test; @@ -93,4 +99,3 @@ void criterion_internal_test_teardown(void) { send_event(criterion_protocol_phase_kind_END); } - diff --git a/src/core/theories.c b/src/core/theories.c index 8814950..8bc01eb 100644 --- a/src/core/theories.c +++ b/src/core/theories.c @@ -36,139 +36,150 @@ #include "abort.h" struct criterion_theory_context { - DCCallVM* vm; + DCCallVM *vm; }; -void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr) { +void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr) +{ if (is_float) { - if (size == sizeof (float)) { - dcArgFloat(ctx->vm, *(float*)ptr); - } else if (size == sizeof (double)) { - dcArgDouble(ctx->vm, *(double*)ptr); - } else if (size == sizeof (long double)) { - dcArgDouble(ctx->vm, *(long double*)ptr); - } + if (size == sizeof (float)) + dcArgFloat(ctx->vm, *(float *) ptr); + else if (size == sizeof (double)) + dcArgDouble(ctx->vm, *(double *) ptr); + else if (size == sizeof (long double)) + dcArgDouble(ctx->vm, *(long double *) ptr); } else { if (size == sizeof (char)) { - dcArgChar(ctx->vm, *(char*)ptr); + dcArgChar(ctx->vm, *(char *) ptr); } else if (size == sizeof (short)) { - dcArgShort(ctx->vm, *(short*)ptr); + dcArgShort(ctx->vm, *(short *) ptr); } else if (size == sizeof (int)) { - dcArgInt(ctx->vm, *(int*)ptr); + dcArgInt(ctx->vm, *(int *) ptr); } else if (size == sizeof (bool)) { - dcArgBool(ctx->vm, *(bool*)ptr); + dcArgBool(ctx->vm, *(bool *) ptr); #if INT_MAX < LONG_MAX } else if (size == sizeof (long)) { - dcArgLong(ctx->vm, *(long*)ptr); + dcArgLong(ctx->vm, *(long *) ptr); #endif #if LONG_MAX < LLONG_MAX } else if (size == sizeof (long long)) { - dcArgLongLong(ctx->vm, *(long long*)ptr); + dcArgLongLong(ctx->vm, *(long long *) ptr); #endif - } else if (size == sizeof (void*)) { - dcArgPointer(ctx->vm, *(void**)ptr); + } else if (size == sizeof (void *)) { + dcArgPointer(ctx->vm, *(void **) ptr); } else { dcArgPointer(ctx->vm, ptr); } } } -struct criterion_theory_context* cr_theory_init(void) { - struct criterion_theory_context* ctx = malloc(sizeof (struct criterion_theory_context)); +struct criterion_theory_context *cr_theory_init(void) +{ + struct criterion_theory_context *ctx = malloc(sizeof (struct criterion_theory_context)); + ctx->vm = dcNewCallVM(4096); dcMode(ctx->vm, DC_CALL_C_DEFAULT); return ctx; } -void cr_theory_free(struct criterion_theory_context *ctx) { +void cr_theory_free(struct criterion_theory_context *ctx) +{ dcFree(ctx->vm); } static jmp_buf theory_jmp; -void cr_theory_abort(void) { +void cr_theory_abort(void) +{ longjmp(theory_jmp, 1); } -void cr_theory_reset(struct criterion_theory_context *ctx) { +void cr_theory_reset(struct criterion_theory_context *ctx) +{ dcReset(ctx->vm); } -void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)) { +void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)) +{ dcCallVoid(ctx->vm, (DCpointer) fnptr); } -static bool contains_word(const char *str, const char *pattern, size_t sz) { +static bool contains_word(const char *str, const char *pattern, size_t sz) +{ char *res = strstr(str, pattern); return res - && (res == str || (res > str && res[-1] == ' ')) - && (!res[sz - 1] || res[sz - 1] == ' '); + && (res == str || (res > str && res[-1] == ' ')) + && (!res[sz - 1] || res[sz - 1] == ' '); } -static bool is_string(const char *name) { +static bool is_string(const char *name) +{ return !strcmp(name, "char*") - || !strcmp(name, "char *") - || !strcmp(name, "const char*") - || !strcmp(name, "const char *") - || !strcmp(name, "char const *") - || !strcmp(name, "char const*") - || !strcmp(name, "char[]") - || !strcmp(name, "char []") - || !strcmp(name, "const char[]") - || !strcmp(name, "const char []") - || !strcmp(name, "char const[]") - || !strcmp(name, "char const []"); + || !strcmp(name, "char *") + || !strcmp(name, "const char*") + || !strcmp(name, "const char *") + || !strcmp(name, "char const *") + || !strcmp(name, "char const*") + || !strcmp(name, "char[]") + || !strcmp(name, "char []") + || !strcmp(name, "const char[]") + || !strcmp(name, "const char []") + || !strcmp(name, "char const[]") + || !strcmp(name, "char const []"); } -static bool is_float(const char *name) { +static bool is_float(const char *name) +{ return contains_word(name, "float", sizeof ("float")) - || contains_word(name, "double", sizeof ("double")); + || contains_word(name, "double", sizeof ("double")); } -static bool is_unsigned_int(const char *name) { +static bool is_unsigned_int(const char *name) +{ return contains_word(name, "unsigned", sizeof ("unsigned")) - || !strncmp(name, "uint", 4); + || !strncmp(name, "uint", 4); } -static bool is_bool(const char *name) { +static bool is_bool(const char *name) +{ return contains_word(name, "bool", sizeof ("bool")) - || contains_word(name, "_Bool", sizeof ("_Bool")); + || contains_word(name, "_Bool", sizeof ("_Bool")); } -static void format_arg(char (*arg)[1024], struct criterion_datapoints *dp, void *data) { +static void format_arg(char (*arg)[1024], struct criterion_datapoints *dp, void *data) +{ if (is_float(dp->name)) { - if (dp->size == sizeof (float)) { - snprintf(*arg, sizeof (*arg) - 1, "%gf", *(float*) data); - } else if (dp->size == sizeof (double)) { - snprintf(*arg, sizeof (*arg) - 1, "%g", *(double*) data); - } else if (dp->size == sizeof (long double)) { - snprintf(*arg, sizeof (*arg) - 1, "%gl", (double) *(long double*) data); - } + if (dp->size == sizeof (float)) + snprintf(*arg, sizeof (*arg) - 1, "%gf", *(float *) data); + else if (dp->size == sizeof (double)) + snprintf(*arg, sizeof (*arg) - 1, "%g", *(double *) data); + else if (dp->size == sizeof (long double)) + snprintf(*arg, sizeof (*arg) - 1, "%gl", (double) *(long double *) data); } else { if (is_string(dp->name)) { - snprintf(*arg, sizeof (*arg) - 1, "\"%s\"", *(char**) data); + snprintf(*arg, sizeof (*arg) - 1, "\"%s\"", *(char **) data); } else if (dp->size == sizeof (bool) && is_bool(dp->name)) { - snprintf(*arg, sizeof (*arg) - 1, "%s", (*(bool*) data) ? "true" : "false"); + snprintf(*arg, sizeof (*arg) - 1, "%s", (*(bool *) data) ? "true" : "false"); } else if (dp->size == sizeof (char)) { - snprintf(*arg, sizeof (*arg) - 1, "'%c'", *(char*) data); + snprintf(*arg, sizeof (*arg) - 1, "'%c'", *(char *) data); } else if (dp->size == sizeof (short)) { const char *fmt = is_unsigned_int(dp->name) ? "%hu" : "%hd"; - snprintf(*arg, sizeof (*arg) - 1, fmt, *(short*) data); + snprintf(*arg, sizeof (*arg) - 1, fmt, *(short *) data); } else if (dp->size == sizeof (int)) { const char *fmt = is_unsigned_int(dp->name) ? "%u" : "%d"; - snprintf(*arg, sizeof (*arg) - 1, fmt, *(int*) data); - } else if (dp->size == sizeof (void*) && strstr(dp->name, "*")) { - snprintf(*arg, sizeof (*arg) - 1, "%p", *(void**) data); + snprintf(*arg, sizeof (*arg) - 1, fmt, *(int *) data); + } else if (dp->size == sizeof (void *) && strstr(dp->name, "*")) { + snprintf(*arg, sizeof (*arg) - 1, "%p", *(void **) data); #if INT_MAX < LONG_MAX } else if (dp->size == sizeof (long)) { const char *fmt = is_unsigned_int(dp->name) ? "%lulu" : "%ldl"; - snprintf(*arg, sizeof (*arg) - 1, fmt, *(long*) data); + snprintf(*arg, sizeof (*arg) - 1, fmt, *(long *) data); #endif #if LONG_MAX < LLONG_MAX } else if (dp->size == sizeof (long long)) { const char *fmt = is_unsigned_int(dp->name) ? "%llullu" : "%lldll"; - snprintf(*arg, sizeof (*arg) - 1, fmt, *(long long*) data); + snprintf(*arg, sizeof (*arg) - 1, fmt, *(long long *) data); #endif } else { snprintf(*arg, sizeof (*arg) - 1, "%s", ""); @@ -176,17 +187,20 @@ static void format_arg(char (*arg)[1024], struct criterion_datapoints *dp, void } } -# define BUFSIZE 4096 +#define BUFSIZE 4096 -static void concat_arg(char (*msg)[BUFSIZE], struct criterion_datapoints *dps, size_t *indices, size_t i) { - void *data = ((char*) dps[i].arr) + dps[i].size * indices[i]; +static void concat_arg(char (*msg)[BUFSIZE], struct criterion_datapoints *dps, size_t *indices, size_t i) +{ + void *data = ((char *) dps[i].arr) + dps[i].size * indices[i]; char arg[1024]; + format_arg(&arg, dps + i, data); strncat(*msg, arg, BUFSIZE - 1); } -int try_call_theory(struct criterion_theory_context *ctx, void (*fnptr)(void)) { +int try_call_theory(struct criterion_theory_context *ctx, void (*fnptr)(void)) +{ if (!setjmp(g_pre_test)) { cr_theory_call(ctx, fnptr); return 1; @@ -194,10 +208,12 @@ int try_call_theory(struct criterion_theory_context *ctx, void (*fnptr)(void)) { return 0; } -void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)) { +void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)) +{ struct criterion_theory_context *ctx = cr_theory_init(); size_t *indices = malloc(sizeof (size_t) * datapoints); + memset(indices, 0, datapoints * sizeof (size_t)); volatile int round = 1; @@ -207,16 +223,16 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (* cr_asprintf(&name, "%s::%d", criterion_current_test->name, round); criterion_protocol_msg setup_msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_SETUP, - .name = name, - ); + .phase = criterion_protocol_phase_kind_SETUP, + .name = name, + ); criterion_message_set_id(setup_msg); cr_send_to_runner(&setup_msg); criterion_protocol_msg main_msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_MAIN, - .name = name, - ); + .phase = criterion_protocol_phase_kind_MAIN, + .name = name, + ); criterion_message_set_id(main_msg); cr_send_to_runner(&main_msg); @@ -224,14 +240,13 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (* if (!setjmp(theory_jmp)) { cr_theory_reset(ctx); for (size_t i = 0; i < datapoints; ++i) { - bool is_float = contains_word(dps[i].name, "float", sizeof ("float")) - || contains_word(dps[i].name, "double", sizeof ("double")); + || contains_word(dps[i].name, "double", sizeof ("double")); cr_theory_push_arg(ctx, is_float, dps[i].size, - ((char*) dps[i].arr) + dps[i].size * indices[i]); + ((char *) dps[i].arr) + dps[i].size * indices[i]); } if (!try_call_theory(ctx, fnptr)) { @@ -251,10 +266,10 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (* result.msg[result.len] = '\0'; criterion_protocol_msg msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_ABORT, - .name = name, - .message = result.msg - ); + .phase = criterion_protocol_phase_kind_ABORT, + .name = name, + .message = result.msg + ); criterion_message_set_id(msg); cr_send_to_runner(&msg); } @@ -262,16 +277,16 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (* if (!theory_aborted) { criterion_protocol_msg teardown_msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_TEARDOWN, - .name = name, - ); + .phase = criterion_protocol_phase_kind_TEARDOWN, + .name = name, + ); criterion_message_set_id(teardown_msg); cr_send_to_runner(&teardown_msg); criterion_protocol_msg end_msg = criterion_message(phase, - .phase = criterion_protocol_phase_kind_END, - .name = name, - ); + .phase = criterion_protocol_phase_kind_END, + .name = name, + ); criterion_message_set_id(end_msg); cr_send_to_runner(&end_msg); } diff --git a/src/entry/entry.c b/src/entry/entry.c index 143b28f..09a2e0d 100644 --- a/src/entry/entry.c +++ b/src/entry/entry.c @@ -23,10 +23,12 @@ */ #include "criterion/criterion.h" -CR_API int main(int argc, char *argv[]) { +CR_API int main(int argc, char *argv[]) +{ struct criterion_test_set *tests = criterion_initialize(); int result = 0; + if (criterion_handle_args(argc, argv, true)) result = !criterion_run_all_tests(tests); diff --git a/src/entry/options.c b/src/entry/options.c index ac68d3d..71a593f 100644 --- a/src/entry/options.c +++ b/src/entry/options.c @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -# include "criterion/options.h" +#include "criterion/options.h" CR_API struct criterion_options criterion_options = { .logging_threshold = CRITERION_IMPORTANT, diff --git a/src/entry/params.c b/src/entry/params.c index 3a53a9c..c6f38ba 100644 --- a/src/entry/params.c +++ b/src/entry/params.c @@ -41,67 +41,71 @@ # include #endif -# define VERSION_MSG "Tests compiled with Criterion v" VERSION "\n" +#define VERSION_MSG "Tests compiled with Criterion v" VERSION "\n" -# define USAGE \ +#define USAGE \ VERSION_MSG "\n" \ "usage: %s OPTIONS\n" \ "options: \n" \ " -h or --help: prints this message\n" \ " -q or --quiet: disables all logging\n" \ " -v or --version: prints the version of criterion " \ - "these tests have been linked against\n" \ + "these tests have been linked against\n" \ " -l or --list: prints all the tests in a list\n" \ " -jN or --jobs N: use N concurrent jobs\n" \ " -f or --fail-fast: exit after the first failure\n" \ " --ascii: don't use fancy unicode symbols " \ - "or colors in the output\n" \ + "or colors in the output\n" \ " -S or --short-filename: only display the base " \ - "name of the source file on a failure\n" \ + "name of the source file on a failure\n" \ " --filter [PATTERN]: run tests matching the " \ - "given pattern\n" \ + "given pattern\n" \ " --timeout [TIMEOUT]: set a timeout (in seconds) " \ - "for all tests\n" \ + "for all tests\n" \ " --tap[=FILE]: writes TAP report in FILE " \ - "(no file or \"-\" means stderr)\n" \ + "(no file or \"-\" means stderr)\n" \ " --xml[=FILE]: writes XML report in FILE " \ - "(no file or \"-\" means stderr)\n" \ + "(no file or \"-\" means stderr)\n" \ " --always-succeed: always exit with 0\n" \ " --verbose[=level]: sets verbosity to level " \ - "(1 by default)\n" \ + "(1 by default)\n" \ " --crash: crash failing assertions rather than " \ - "aborting (for debugging purposes)\n" \ + "aborting (for debugging purposes)\n" \ " --debug[=TYPE]: run tests with a debugging " \ - "server, listening on localhost:1234 by " \ - "default. TYPE may be gdb, lldb, or wingbd.\n" \ + "server, listening on localhost:1234 by " \ + "default. TYPE may be gdb, lldb, or wingbd.\n" \ " --debug-transport=VAL: the transport to use by " \ - "the debugging server. `tcp:1234` by default\n" \ + "the debugging server. `tcp:1234` by default\n" \ " -OP:F or --output=PROVIDER=FILE: write test " \ - "report to FILE using the specified provider\n" + "report to FILE using the specified provider\n" -int print_usage(char *progname) { +int print_usage(char *progname) +{ fprintf(stderr, USAGE, progname); return 0; } -int print_version(void) { +int print_version(void) +{ fputs(VERSION_MSG, stderr); return 0; } -# define UTF8_TREE_NODE "├" -# define UTF8_TREE_END "â””" -# define UTF8_TREE_JOIN "──" +#define UTF8_TREE_NODE "├" +#define UTF8_TREE_END "â””" +#define UTF8_TREE_JOIN "──" -# define ASCII_TREE_NODE "|" -# define ASCII_TREE_END "`" -# define ASCII_TREE_JOIN "--" +#define ASCII_TREE_NODE "|" +#define ASCII_TREE_END "`" +#define ASCII_TREE_JOIN "--" -bool is_disabled(struct criterion_suite *s, struct criterion_test *t) { +bool is_disabled(struct criterion_suite *s, struct criterion_test *t) +{ return (s->data && s->data->disabled) || t->data->disabled; } -int list_tests(bool unicode) { +int list_tests(bool unicode) +{ struct criterion_test_set *set = criterion_init(); const char *node = unicode ? UTF8_TREE_NODE : ASCII_TREE_NODE; @@ -110,6 +114,7 @@ int list_tests(bool unicode) { FOREACH_SET(struct criterion_suite_set *s, set->suites) { size_t tests = s->tests ? s->tests->size : 0; + if (!tests) continue; @@ -131,8 +136,10 @@ int list_tests(bool unicode) { return 0; } -int atou(const char *str) { +int atou(const char *str) +{ int res = atoi(str); + return res < 0 ? 0 : res; } @@ -145,6 +152,7 @@ static int parse_dbg_transport(const char *arg) char *val = dup + strlen(transport) + 1; int ok = 1; + if (!strcmp(transport, "tcp")) { criterion_options.debug_port = atou(val); } else { @@ -162,8 +170,8 @@ static int parse_dbg(const char *arg) return CR_DBG_NATIVE; static struct { char *name; enum criterion_debugger dbg; } values[] = { - { "gdb", CR_DBG_GDB }, - { "lldb", CR_DBG_LLDB }, + { "gdb", CR_DBG_GDB }, + { "lldb", CR_DBG_LLDB }, { "windbg", CR_DBG_WINDBG }, }; @@ -182,35 +190,35 @@ CR_API int criterion_handle_args(int argc, char *argv[], bool handle_unknown_arg) { static struct option opts[] = { - {"verbose", optional_argument, 0, 'b'}, - {"quiet", no_argument, 0, 'q'}, - {"version", no_argument, 0, 'v'}, - {"tap", optional_argument, 0, 'T'}, - {"xml", optional_argument, 0, 'x'}, - {"json", optional_argument, 0, 'n'}, - {"help", no_argument, 0, 'h'}, - {"list", no_argument, 0, 'l'}, - {"ascii", no_argument, 0, 'k'}, - {"jobs", required_argument, 0, 'j'}, - {"timeout", required_argument, 0, 't'}, - {"fail-fast", no_argument, 0, 'f'}, - {"short-filename", no_argument, 0, 'S'}, - {"single", required_argument, 0, 's'}, - {"pattern", required_argument, 0, 'p'}, - {"filter", required_argument, 0, 'F'}, - {"always-succeed", no_argument, 0, 'y'}, - {"no-early-exit", no_argument, 0, 'z'}, - {"output", required_argument, 0, 'O'}, - {"wait", no_argument, 0, 'w'}, - {"crash", no_argument, 0, 'c'}, - {"debug", optional_argument, 0, 'd'}, - {"debug-transport", required_argument, 0, 'D'}, - {0, 0, 0, 0 } + { "verbose", optional_argument, 0, 'b' }, + { "quiet", no_argument, 0, 'q' }, + { "version", no_argument, 0, 'v' }, + { "tap", optional_argument, 0, 'T' }, + { "xml", optional_argument, 0, 'x' }, + { "json", optional_argument, 0, 'n' }, + { "help", no_argument, 0, 'h' }, + { "list", no_argument, 0, 'l' }, + { "ascii", no_argument, 0, 'k' }, + { "jobs", required_argument, 0, 'j' }, + { "timeout", required_argument, 0, 't' }, + { "fail-fast", no_argument, 0, 'f' }, + { "short-filename", no_argument, 0, 'S' }, + { "single", required_argument, 0, 's' }, + { "pattern", required_argument, 0, 'p' }, + { "filter", required_argument, 0, 'F' }, + { "always-succeed", no_argument, 0, 'y' }, + { "no-early-exit", no_argument, 0, 'z' }, + { "output", required_argument, 0, 'O' }, + { "wait", no_argument, 0, 'w' }, + { "crash", no_argument, 0, 'c' }, + { "debug", optional_argument, 0, 'd' }, + { "debug-transport", required_argument, 0, 'D' }, + { 0, 0, 0, 0 } }; setlocale(LC_ALL, ""); #if ENABLE_NLS - textdomain (PACKAGE "-test"); + textdomain(PACKAGE "-test"); #endif if (!handle_unknown_arg) @@ -247,8 +255,8 @@ CR_API int criterion_handle_args(int argc, char *argv[], bool quiet = false; - // CRITERION_ENABLE_TAP backward compatibility. - // The environment variable is otherwise deprecated. + /* CRITERION_ENABLE_TAP backward compatibility. + The environment variable is otherwise deprecated. */ if (!strcmp("1", DEF(getenv("CRITERION_ENABLE_TAP"), "0"))) { quiet = true; criterion_add_output("tap", DEF(optarg, "-")); @@ -306,7 +314,7 @@ CR_API int criterion_handle_args(int argc, char *argv[], exit(3); break; - /* *INDENT-OFF* - Duff devices are often mishandled by formatters */ + /* *INDENT-OFF* - Duff devices are often mishandled by formatters */ { const char *provider; case 'T': provider = "tap"; goto provider_def; @@ -318,7 +326,7 @@ CR_API int criterion_handle_args(int argc, char *argv[], quiet = !strcmp(path, "-"); criterion_add_output(provider, path); } break; - /* *INDENT-ON* */ + /* *INDENT-ON* */ case 'l': do_list_tests = true; break; case 'v': do_print_version = true; break; @@ -326,7 +334,7 @@ CR_API int criterion_handle_args(int argc, char *argv[], case 'O': { char *arg = strdup(optarg); char *buf = NULL; - strtok_r(arg, ":", &buf); + strtok_r(arg, ":", &buf); char *path = strtok_r(NULL, ":", &buf); if (arg == NULL || path == NULL) { @@ -343,7 +351,7 @@ CR_API int criterion_handle_args(int argc, char *argv[], exit(3); case '?': case 'c': criterion_options.crash = true; break; - default : do_print_usage = handle_unknown_arg; break; + default: do_print_usage = handle_unknown_arg; break; } } diff --git a/src/err.c b/src/err.c index e198845..a54ad34 100644 --- a/src/err.c +++ b/src/err.c @@ -30,6 +30,7 @@ CR_NORETURN void cr_panic(const char *str, ...) { va_list vl; + va_start(vl, str); fprintf(stderr, "criterion: "); vfprintf(stderr, str, vl); diff --git a/src/err.h b/src/err.h index a82148a..94c9658 100644 --- a/src/err.h +++ b/src/err.h @@ -22,41 +22,41 @@ * THE SOFTWARE. */ #ifndef ERR_H_ -# define ERR_H_ +#define ERR_H_ -# include +#include -# include "common.h" +#include "common.h" CR_FORMAT(printf, 1, 2) CR_NORETURN void cr_panic(const char *str, ...); -# define errno_ignore(Stmt) \ - do { \ - int err = errno; \ - Stmt; \ - errno = err; \ +#define errno_ignore(Stmt) \ + do { \ + int err = errno; \ + Stmt; \ + errno = err; \ } while (0) -# define errno_return(Err, Val) \ - do { \ - errno = (Err); \ - return (Val); \ +#define errno_return(Err, Val) \ + do { \ + errno = (Err); \ + return (Val); \ } while (0) -# undef assert -# define assert(Cnd) \ - do { \ - if (!(Cnd)) { \ - cr_panic("Assertion failed: %s\n\t@ %s:%d (%s)", #Cnd, __FILE__, \ - __LINE__, __func__); \ - } \ +#undef assert +#define assert(Cnd) \ + do { \ + if (!(Cnd)) { \ + cr_panic("Assertion failed: %s\n\t@ %s:%d (%s)", #Cnd, __FILE__, \ + __LINE__, __func__); \ + } \ } while (0) -# ifdef NDEBUG -# define debug_assert(Cnd) -# else -# define debug_assert(Cnd) assert(Cnd) -# endif +#ifdef NDEBUG +# define debug_assert(Cnd) +#else +# define debug_assert(Cnd) assert(Cnd) +#endif #endif /* !ERR_H_ */ diff --git a/src/io/asprintf.c b/src/io/asprintf.c index 2823a4d..3733a73 100644 --- a/src/io/asprintf.c +++ b/src/io/asprintf.c @@ -27,24 +27,27 @@ #include #include "criterion/internal/asprintf-compat.h" -int cr_asprintf(char **strp, const char *fmt, ...) { +int cr_asprintf(char **strp, const char *fmt, ...) +{ va_list ap; + va_start(ap, fmt); int res = cr_vasprintf(strp, fmt, ap); va_end(ap); return res; } -int cr_vasprintf(char **strp, const char *fmt, va_list ap) { +int cr_vasprintf(char **strp, const char *fmt, va_list ap) +{ va_list vl; + va_copy(vl, ap); int size = vsnprintf(0, 0, fmt, vl); int res = -1; - if (size < 0 || size >= INT_MAX) { + if (size < 0 || size >= INT_MAX) goto cleanup; - } char *str = malloc(size + 1); if (str) { diff --git a/src/io/asprintf.h b/src/io/asprintf.h index edb19b6..80761f9 100644 --- a/src/io/asprintf.h +++ b/src/io/asprintf.h @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #ifndef ASPRINTF_H_ -# define ASPRINTF_H_ +#define ASPRINTF_H_ int cr_vasprintf(char **strp, const char *fmt, va_list ap); int cr_asprintf(char **strp, const char *fmt, ...); diff --git a/src/io/event.c b/src/io/event.c index 32b1eca..783dd74 100644 --- a/src/io/event.c +++ b/src/io/event.c @@ -30,15 +30,16 @@ int g_client_socket = -1; -void criterion_send_assert(struct criterion_assert_stats *stats) { +void criterion_send_assert(struct criterion_assert_stats *stats) +{ assert(stats->message); criterion_protocol_msg msg = criterion_message(assert, - .message = (char *) stats->message, - .passed = stats->passed, - .file = (char *) stats->file, - .has_line = true, - .line = stats->line, - ); + .message = (char *) stats->message, + .passed = stats->passed, + .file = (char *) stats->file, + .has_line = true, + .line = stats->line, + ); criterion_message_set_id(msg); cr_send_to_runner(&msg); } diff --git a/src/io/event.h b/src/io/event.h index d82c3cc..d3805f7 100644 --- a/src/io/event.h +++ b/src/io/event.h @@ -22,11 +22,11 @@ * THE SOFTWARE. */ #ifndef EVENT_H_ -# define EVENT_H_ +#define EVENT_H_ -# include "criterion/event.h" -# include -# include +#include "criterion/event.h" +#include +#include extern int g_client_socket; diff --git a/src/io/file.c b/src/io/file.c index 4d01422..9e802fa 100644 --- a/src/io/file.c +++ b/src/io/file.c @@ -1,11 +1,13 @@ #include -int cr_file_match_str(FILE* f, const char *str) { +int cr_file_match_str(FILE *f, const char *str) +{ size_t len = strlen(str); char buf[512]; size_t read; int matches = 0; + while ((read = fread(buf, 1, sizeof (buf), f)) > 0) { matches = !strncmp(buf, str, read); if (!matches || read > len) { @@ -17,13 +19,14 @@ int cr_file_match_str(FILE* f, const char *str) { str += read; } - // consume the rest of what's available - while (fread(buf, 1, sizeof (buf), f) > 0); + /* consume the rest of what's available */ + while (fread(buf, 1, sizeof (buf), f) > 0) ; return matches; } -int cr_file_match_file(FILE* f, FILE* ref) { +int cr_file_match_file(FILE *f, FILE *ref) +{ if (f == ref) return true; @@ -37,8 +40,7 @@ int cr_file_match_file(FILE* f, FILE* ref) { size_t read1 = 1, read2 = 1; int matches = 0; while ((read1 = fread(buf1, 1, sizeof (buf1), f)) > 0 - && (read2 = fread(buf2, 1, sizeof (buf2), ref)) > 0) { - + && (read2 = fread(buf2, 1, sizeof (buf2), ref)) > 0) { if (read1 != read2) { matches = 0; break; @@ -47,38 +49,46 @@ int cr_file_match_file(FILE* f, FILE* ref) { matches = !memcmp(buf1, buf2, read1); } - // consume the rest of what's available - while (fread(buf1, 1, sizeof (buf1), f) > 0); + /* consume the rest of what's available */ + while (fread(buf1, 1, sizeof (buf1), f) > 0) ; fsetpos(ref, &orig_pos); return matches; } -int cr_stdout_match_file(FILE* ref) { +int cr_stdout_match_file(FILE *ref) +{ FILE *f = cr_get_redirected_stdout(); int res = cr_file_match_file(f, ref); + fclose(f); return res; } -int cr_stdout_match_str(const char* ref) { +int cr_stdout_match_str(const char *ref) +{ FILE *f = cr_get_redirected_stdout(); int res = cr_file_match_str(f, ref); + fclose(f); return res; } -int cr_stderr_match_file(FILE* ref) { +int cr_stderr_match_file(FILE *ref) +{ FILE *f = cr_get_redirected_stderr(); int res = cr_file_match_file(f, ref); + fclose(f); return res; } -int cr_stderr_match_str(const char* ref) { +int cr_stderr_match_str(const char *ref) +{ FILE *f = cr_get_redirected_stderr(); int res = cr_file_match_str(f, ref); + fclose(f); return res; } diff --git a/src/io/json.c b/src/io/json.c index 6671282..ce2db42 100644 --- a/src/io/json.c +++ b/src/io/json.c @@ -35,37 +35,37 @@ #include "config.h" #include "common.h" -#define JSON_TEST_TEMPLATE_BEGIN \ - " {\n" \ - " \"name\": \"%s\",\n" \ - " \"assertions\": " CR_SIZE_T_FORMAT ",\n" \ +#define JSON_TEST_TEMPLATE_BEGIN \ + " {\n" \ + " \"name\": \"%s\",\n" \ + " \"assertions\": " CR_SIZE_T_FORMAT ",\n" \ " \"status\": \"%s\"" #define JSON_TEST_TEMPLATE_END \ - "\n" \ + "\n" \ " }" #define JSON_TEST_FAILED_TEMPLATE_BEGIN \ - ",\n" \ + ",\n" \ " \"messages\": [\n" #define JSON_TEST_FAILED_TEMPLATE_END \ - "\n" \ + "\n" \ " ]" #define JSON_FAILURE_MSG_ENTRY \ " \"%s:%u: %s\"" #define JSON_CRASH_MSG_ENTRY \ - ",\n" \ + ",\n" \ " \"messages\": [\"The test crashed.\"]" #define JSON_TIMEOUT_MSG_ENTRY \ - ",\n" \ + ",\n" \ " \"messages\": [\"The test timed out.\"]" #define JSON_TEST_SKIPPED_TEMPLATE_BEGIN \ - ",\n" \ + ",\n" \ " \"messages\": [\"" #define JSON_TEST_SKIPPED_TEMPLATE_END \ @@ -80,11 +80,11 @@ #define JSON_TEST_LIST_TEMPLATE_END \ " ]\n" -#define JSON_TESTSUITE_TEMPLATE_BEGIN \ - " {\n" \ - " \"name\": \"%s\",\n" \ - " \"passed\": " CR_SIZE_T_FORMAT ",\n" \ - " \"failed\": " CR_SIZE_T_FORMAT ",\n" \ +#define JSON_TESTSUITE_TEMPLATE_BEGIN \ + " {\n" \ + " \"name\": \"%s\",\n" \ + " \"passed\": " CR_SIZE_T_FORMAT ",\n" \ + " \"failed\": " CR_SIZE_T_FORMAT ",\n" \ " \"errored\": " CR_SIZE_T_FORMAT ",\n" \ " \"skipped\": " CR_SIZE_T_FORMAT ",\n" @@ -97,35 +97,35 @@ #define JSON_TESTSUITE_LIST_TEMPLATE_END \ " ]\n" -#define JSON_BASE_TEMPLATE_BEGIN \ - "{\n" \ +#define JSON_BASE_TEMPLATE_BEGIN \ + "{\n" \ " \"id\": \"Criterion v" VERSION "\",\n" \ - " \"passed\": " CR_SIZE_T_FORMAT ",\n" \ - " \"failed\": " CR_SIZE_T_FORMAT ",\n" \ - " \"errored\": " CR_SIZE_T_FORMAT ",\n" \ - " \"skipped\": " CR_SIZE_T_FORMAT ",\n" \ + " \"passed\": " CR_SIZE_T_FORMAT ",\n" \ + " \"failed\": " CR_SIZE_T_FORMAT ",\n" \ + " \"errored\": " CR_SIZE_T_FORMAT ",\n" \ + " \"skipped\": " CR_SIZE_T_FORMAT ",\n" \ #define JSON_BASE_TEMPLATE_END \ "}\n" - -static CR_INLINE const char *get_status_string(struct criterion_test_stats *ts){ - return (ts->crashed || ts->timed_out) ? "ERRORED" : - ts->test_status == CR_STATUS_FAILED ? "FAILED" : - ts->test_status == CR_STATUS_SKIPPED ? "SKIPPED" : - "PASSED"; +static CR_INLINE const char *get_status_string(struct criterion_test_stats *ts) +{ + return (ts->crashed || ts->timed_out) ? "ERRORED" + : ts->test_status == CR_STATUS_FAILED ? "FAILED" + : ts->test_status == CR_STATUS_SKIPPED ? "SKIPPED" + : "PASSED"; } -static void print_test(FILE *f, struct criterion_test_stats *ts){ - +static void print_test(FILE *f, struct criterion_test_stats *ts) +{ fprintf(f, JSON_TEST_TEMPLATE_BEGIN, ts->test->name, (size_t) (ts->passed_asserts + ts->failed_asserts), get_status_string(ts) - ); + ); if (ts->test_status == CR_STATUS_SKIPPED) { - fprintf(f,"%s%s%s", JSON_TEST_SKIPPED_TEMPLATE_BEGIN, + fprintf(f, "%s%s%s", JSON_TEST_SKIPPED_TEMPLATE_BEGIN, ts->message ? ts->message : JSON_SKIPPED_MSG_ENTRY, JSON_TEST_SKIPPED_TEMPLATE_END); } else if (ts->crashed) { @@ -138,11 +138,10 @@ static void print_test(FILE *f, struct criterion_test_stats *ts){ bool first = true; for (struct criterion_assert_stats *asrt = ts->asserts; asrt; asrt = asrt->next) { if (!asrt->passed) { - if (!first) { + if (!first) fprintf(f, ",\n"); - } else { + else first = false; - } bool sf = criterion_options.short_filename; char *dup = strdup(*asrt->message ? asrt->message : ""); @@ -153,11 +152,10 @@ static void print_test(FILE *f, struct criterion_test_stats *ts){ sf ? basename_compat(asrt->file) : asrt->file, asrt->line, line - ); + ); - while ((line = strtok_r(NULL, "\n", &saveptr))) { + while ((line = strtok_r(NULL, "\n", &saveptr))) fprintf(f, ",\n \" %s\"", line); - } free(dup); } } @@ -167,24 +165,24 @@ static void print_test(FILE *f, struct criterion_test_stats *ts){ fprintf(f, JSON_TEST_TEMPLATE_END); } -void json_report(FILE *f, struct criterion_global_stats *stats) { +void json_report(FILE *f, struct criterion_global_stats *stats) +{ fprintf(f, JSON_BASE_TEMPLATE_BEGIN, stats->tests_passed, stats->tests_failed, stats->tests_crashed, stats->tests_skipped - ); + ); fprintf(f, JSON_TESTSUITE_LIST_TEMPLATE_BEGIN); for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) { - fprintf(f, JSON_TESTSUITE_TEMPLATE_BEGIN, ss->suite->name, ss->tests_passed, ss->tests_failed, ss->tests_crashed, ss->tests_skipped - ); + ); fprintf(f, JSON_TEST_LIST_TEMPLATE_BEGIN); for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) { diff --git a/src/io/output.c b/src/io/output.c index 1408920..0013189 100644 --- a/src/io/output.c +++ b/src/io/output.c @@ -17,15 +17,16 @@ static msg_t msg_err = "Could not open the file @ `%s` for %s reporting: %s.\n"; static msg_t msg_ok = "Writing %s report in `%s`.\n"; #endif -typedef kvec_t(const char *) str_vec; +typedef kvec_t (const char *) str_vec; -KHASH_MAP_INIT_STR(ht_str, criterion_reporter*) -KHASH_MAP_INIT_STR(ht_path, str_vec*) +KHASH_MAP_INIT_STR(ht_str, criterion_reporter *) +KHASH_MAP_INIT_STR(ht_path, str_vec *) -static khash_t(ht_str) *reporters; -static khash_t(ht_path) *outputs; +static khash_t(ht_str) * reporters; +static khash_t(ht_path) * outputs; -int criterion_register_output_provider(const char *name, criterion_reporter *reporter) { +int criterion_register_output_provider(const char *name, criterion_reporter *reporter) +{ if (!reporters) reporters = kh_init(ht_str); @@ -35,7 +36,8 @@ int criterion_register_output_provider(const char *name, criterion_reporter *rep return absent; } -int criterion_add_output(const char *provider, const char *path) { +int criterion_add_output(const char *provider, const char *path) +{ if (!outputs) outputs = kh_init(ht_path); @@ -57,7 +59,8 @@ int criterion_add_output(const char *provider, const char *path) { return 1; } -void criterion_free_output(void) { +void criterion_free_output(void) +{ if (reporters) kh_destroy(ht_str, reporters); @@ -73,7 +76,8 @@ void criterion_free_output(void) { } } -void process_all_output(struct criterion_global_stats *stats) { +void process_all_output(struct criterion_global_stats *stats) +{ if (!outputs || !reporters) return; diff --git a/src/io/output.h b/src/io/output.h index ff2df48..6a20132 100644 --- a/src/io/output.h +++ b/src/io/output.h @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #ifndef OUTPUT_H_ -# define OUTPUT_H_ +#define OUTPUT_H_ -# include "criterion/output.h" +#include "criterion/output.h" void process_all_output(struct criterion_global_stats *stats); void criterion_free_output(void); diff --git a/src/io/redirect.c b/src/io/redirect.c index f52152e..56361db 100644 --- a/src/io/redirect.c +++ b/src/io/redirect.c @@ -26,7 +26,8 @@ #include "criterion/redirect.h" #include "compat/pipe.h" -void cr_redirect(enum criterion_std_fd fd_kind, s_pipe_handle *pipe) { +void cr_redirect(enum criterion_std_fd fd_kind, s_pipe_handle *pipe) +{ fflush(get_std_file(fd_kind)); if (!stdpipe_options(pipe, fd_kind, fd_kind == CR_STDIN ? 0 : 1)) cr_assert_fail("Could not redirect standard file descriptor."); @@ -34,20 +35,25 @@ void cr_redirect(enum criterion_std_fd fd_kind, s_pipe_handle *pipe) { pipe_std_redirect(pipe, fd_kind); } -void cr_redirect_stdout(void) { +void cr_redirect_stdout(void) +{ cr_redirect(CR_STDOUT, stdout_redir); } -void cr_redirect_stderr(void) { +void cr_redirect_stderr(void) +{ cr_redirect(CR_STDERR, stderr_redir); } -void cr_redirect_stdin(void) { +void cr_redirect_stdin(void) +{ cr_redirect(CR_STDIN, stdin_redir); } -FILE* cr_get_redirected_stdout(void) { +FILE *cr_get_redirected_stdout(void) +{ static FILE *f; + if (!f) { f = pipe_in(stdout_redir, PIPE_NOOPT); if (!f) @@ -56,8 +62,10 @@ FILE* cr_get_redirected_stdout(void) { return f; } -FILE* cr_get_redirected_stderr(void) { +FILE *cr_get_redirected_stderr(void) +{ static FILE *f; + if (!f) { f = pipe_in(stderr_redir, PIPE_NOOPT); if (!f) @@ -66,8 +74,10 @@ FILE* cr_get_redirected_stderr(void) { return f; } -FILE* cr_get_redirected_stdin(void) { +FILE *cr_get_redirected_stdin(void) +{ static FILE *f; + if (!f) { f = pipe_out(stdin_redir, PIPE_NOOPT); if (!f) diff --git a/src/io/tap.c b/src/io/tap.c index 3dadf14..c1f8082 100644 --- a/src/io/tap.c +++ b/src/io/tap.c @@ -33,24 +33,27 @@ #include "config.h" #include "common.h" -static void print_prelude(FILE *f, struct criterion_global_stats *stats) { +static void print_prelude(FILE *f, struct criterion_global_stats *stats) +{ fprintf(f, "TAP version 13\n1.." - CR_SIZE_T_FORMAT - "\n", stats->nb_tests); + CR_SIZE_T_FORMAT + "\n", stats->nb_tests); fprintf(f, "# Criterion v%s\n", VERSION); } -static void print_pre_suite(FILE *f, struct criterion_suite_stats *stats) { +static void print_pre_suite(FILE *f, struct criterion_suite_stats *stats) +{ fprintf(f, "\n# Running " - CR_SIZE_T_FORMAT - " tests from %s\n", + CR_SIZE_T_FORMAT + " tests from %s\n", stats->nb_tests, stats->suite->name); } - -static void print_test_normal(FILE *f, struct criterion_test_stats *stats) { +static void print_test_normal(FILE *f, struct criterion_test_stats *stats) +{ const char *format = "%s - %s::%s %s (%3.2fs)\n"; + fprintf(f, format, stats->test_status == CR_STATUS_FAILED ? "not ok" : "ok", stats->test->category, @@ -75,8 +78,10 @@ static void print_test_normal(FILE *f, struct criterion_test_stats *stats) { } } -static void print_test_crashed(FILE *f, struct criterion_test_stats *stats) { +static void print_test_crashed(FILE *f, struct criterion_test_stats *stats) +{ bool sf = criterion_options.short_filename; + fprintf(f, "not ok - %s::%s unexpected signal after %s:%u\n", stats->test->category, stats->test->name, @@ -84,16 +89,17 @@ static void print_test_crashed(FILE *f, struct criterion_test_stats *stats) { stats->progress); } -static void print_test_timeout(FILE *f, struct criterion_test_stats *stats) { +static void print_test_timeout(FILE *f, struct criterion_test_stats *stats) +{ fprintf(f, "not ok - %s::%s timed out (%3.2fs)\n", stats->test->category, stats->test->name, stats->elapsed_time); } -static void print_test(FILE *f, struct criterion_test_stats *ts){ - - if (ts->test_status == CR_STATUS_SKIPPED){ +static void print_test(FILE *f, struct criterion_test_stats *ts) +{ + if (ts->test_status == CR_STATUS_SKIPPED) { fprintf(f, "ok - %s::%s %s # SKIP %s\n", ts->test->category, ts->test->name, @@ -108,14 +114,14 @@ static void print_test(FILE *f, struct criterion_test_stats *ts){ } } -void tap_report(FILE *f, struct criterion_global_stats *stats) { +void tap_report(FILE *f, struct criterion_global_stats *stats) +{ print_prelude(f, stats); for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) { print_pre_suite(f, ss); - for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) { + for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) print_test(f, ts); - } } } diff --git a/src/io/xml.c b/src/io/xml.c index b113e9f..3f76803 100644 --- a/src/io/xml.c +++ b/src/io/xml.c @@ -36,11 +36,11 @@ #include "config.h" #include "common.h" -#define TESTSUITES_PROPERTIES \ - "name=\"Criterion Tests\" " \ - "tests=\"" CR_SIZE_T_FORMAT "\" " \ - "failures=\"" CR_SIZE_T_FORMAT "\" " \ - "errors=\"" CR_SIZE_T_FORMAT "\" " \ +#define TESTSUITES_PROPERTIES \ + "name=\"Criterion Tests\" " \ + "tests=\"" CR_SIZE_T_FORMAT "\" " \ + "failures=\"" CR_SIZE_T_FORMAT "\" " \ + "errors=\"" CR_SIZE_T_FORMAT "\" " \ "disabled=\"" CR_SIZE_T_FORMAT "\"" #define XML_BASE_TEMPLATE_BEGIN \ @@ -48,48 +48,47 @@ "\n" \ "\n" \ -#define XML_BASE_TEMPLATE_END \ +#define XML_BASE_TEMPLATE_END \ "\n" -#define TESTSUITE_PROPERTIES \ - "name=\"%s\" " \ - "tests=\"" CR_SIZE_T_FORMAT "\" " \ - "failures=\"" CR_SIZE_T_FORMAT "\" " \ - "errors=\"" CR_SIZE_T_FORMAT "\" " \ - "disabled=\"" CR_SIZE_T_FORMAT "\" " \ - "skipped=\"" CR_SIZE_T_FORMAT "\" " \ +#define TESTSUITE_PROPERTIES \ + "name=\"%s\" " \ + "tests=\"" CR_SIZE_T_FORMAT "\" " \ + "failures=\"" CR_SIZE_T_FORMAT "\" " \ + "errors=\"" CR_SIZE_T_FORMAT "\" " \ + "disabled=\"" CR_SIZE_T_FORMAT "\" " \ + "skipped=\"" CR_SIZE_T_FORMAT "\" " \ "time=\"%.3f\"" - -#define XML_TESTSUITE_TEMPLATE_BEGIN \ +#define XML_TESTSUITE_TEMPLATE_BEGIN \ " \n" -#define XML_TESTSUITE_TEMPLATE_END \ +#define XML_TESTSUITE_TEMPLATE_END \ " \n" -#define TEST_PROPERTIES \ - "name=\"%s\" " \ - "assertions=\"" CR_SIZE_T_FORMAT "\" " \ - "status=\"%s\" " \ +#define TEST_PROPERTIES \ + "name=\"%s\" " \ + "assertions=\"" CR_SIZE_T_FORMAT "\" " \ + "status=\"%s\" " \ "time=\"%.3f\"" #define XML_TEST_TEMPLATE_BEGIN \ " \n" \ -#define XML_TEST_TEMPLATE_END \ +#define XML_TEST_TEMPLATE_END \ " \n" -#define XML_TEST_SKIPPED " \n" +#define XML_TEST_SKIPPED " \n" -#define LF " " +#define LF " " #define XML_FAILURE_MSG_ENTRY \ "%s:%u: %s" LF -#define XML_TEST_FAILED_TEMPLATE_BEGIN \ +#define XML_TEST_FAILED_TEMPLATE_BEGIN \ " " -#define XML_TEST_FAILED_TEMPLATE_END \ +#define XML_TEST_FAILED_TEMPLATE_END \ "\n" #define XML_CRASH_MSG_ENTRY \ @@ -98,12 +97,12 @@ #define XML_TIMEOUT_MSG_ENTRY \ " " - -static CR_INLINE const char *get_status_string(struct criterion_test_stats *ts){ - return (ts->crashed || ts->timed_out) ? "ERRORED" : - ts->test_status == CR_STATUS_FAILED ? "FAILED" : - ts->test_status == CR_STATUS_SKIPPED ? "SKIPPED" : - "PASSED"; +static CR_INLINE const char *get_status_string(struct criterion_test_stats *ts) +{ + return (ts->crashed || ts->timed_out) ? "ERRORED" + : ts->test_status == CR_STATUS_FAILED ? "FAILED" + : ts->test_status == CR_STATUS_SKIPPED ? "SKIPPED" + : "PASSED"; } /* @@ -112,10 +111,12 @@ static CR_INLINE const char *get_status_string(struct criterion_test_stats *ts){ * Therefore we set the locale temporarily to print dots. */ static int fprintf_locale(FILE *stream, - const char *format, ...) { + const char *format, ...) +{ va_list args; int result; const char *locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); va_start(args, format); result = vfprintf(stream, format, args); @@ -124,16 +125,16 @@ static int fprintf_locale(FILE *stream, return result; } -static void print_test(FILE *f, struct criterion_test_stats *ts){ - +static void print_test(FILE *f, struct criterion_test_stats *ts) +{ fprintf_locale(f, XML_TEST_TEMPLATE_BEGIN, ts->test->name, (size_t) (ts->passed_asserts + ts->failed_asserts), get_status_string(ts), ts->elapsed_time - ); + ); - if (ts->test_status == CR_STATUS_SKIPPED){ + if (ts->test_status == CR_STATUS_SKIPPED) { fprintf(f, XML_TEST_SKIPPED); } else if (ts->crashed) { fprintf(f, XML_CRASH_MSG_ENTRY); @@ -153,7 +154,7 @@ static void print_test(FILE *f, struct criterion_test_stats *ts){ sf ? basename_compat(asrt->file) : asrt->file, asrt->line, line - ); + ); while ((line = strtok_r(NULL, "\n", &saveptr))) fprintf(f, " %s" LF, line); @@ -170,22 +171,22 @@ static void print_test(FILE *f, struct criterion_test_stats *ts){ static CR_INLINE float get_time_elapsed_suite(struct criterion_suite_stats *ss) { float result = 0; - for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) { + + for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) result += ts->elapsed_time; - } return result; } -void xml_report(FILE *f, struct criterion_global_stats *stats) { +void xml_report(FILE *f, struct criterion_global_stats *stats) +{ fprintf(f, XML_BASE_TEMPLATE_BEGIN, stats->nb_tests, stats->tests_failed, stats->tests_crashed, stats->tests_skipped - ); + ); for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) { - fprintf_locale(f, XML_TESTSUITE_TEMPLATE_BEGIN, ss->suite->name, ss->nb_tests, @@ -194,11 +195,10 @@ void xml_report(FILE *f, struct criterion_global_stats *stats) { ss->tests_skipped, ss->tests_skipped, get_time_elapsed_suite(ss) - ); + ); - for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) { + for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) print_test(f, ts); - } fprintf(f, XML_TESTSUITE_TEMPLATE_END); } diff --git a/src/log/logging.c b/src/log/logging.c index e17cc47..f0d8bc1 100644 --- a/src/log/logging.c +++ b/src/log/logging.c @@ -35,11 +35,11 @@ #include "string/i18n.h" #ifdef ENABLE_NLS -# define LOG_FORMAT "[%1$s%2$s%3$s] %4$s" -# define ERROR_FORMAT "[%1$s%2$s%3$s] %4$s%5$s%6$s%7$s" +# define LOG_FORMAT "[%1$s%2$s%3$s] %4$s" +# define ERROR_FORMAT "[%1$s%2$s%3$s] %4$s%5$s%6$s%7$s" #else -# define LOG_FORMAT "[%s%s%s] %s" -# define ERROR_FORMAT "[%s%s%s] %s%s%s%s" +# define LOG_FORMAT "[%s%s%s] %s" +# define ERROR_FORMAT "[%s%s%s] %s%s%s%s" #endif const struct criterion_prefix_data g_criterion_logging_prefixes[] = { @@ -51,10 +51,11 @@ const struct criterion_prefix_data g_criterion_logging_prefixes[] = { [CRITERION_LOGGING_PREFIX_FAIL] = { "FAIL", CRIT_FG_RED }, [CRITERION_LOGGING_PREFIX_ERR] = { "ERR ", CRIT_FG_RED }, [CRITERION_LOGGING_PREFIX_WARN] = { "WARN", CRIT_FG_GOLD }, - { NULL, NULL } + { NULL, NULL } }; -void criterion_log_noformat(enum criterion_severity severity, const char *msg) { +void criterion_log_noformat(enum criterion_severity severity, const char *msg) +{ static const struct criterion_prefix_data *prefixes[] = { [CR_LOG_INFO] = CRITERION_PREFIX_DASHES, [CR_LOG_WARNING] = CRITERION_PREFIX_WARN, @@ -73,24 +74,25 @@ void criterion_log_noformat(enum criterion_severity severity, const char *msg) { const struct criterion_prefix_data *prefix = prefixes[severity]; if (severity == CR_LOG_ERROR) { fprintf(stderr, _(ERROR_FORMAT), - CRIT_COLOR_NORMALIZE(prefix->color), - prefix->prefix, - CR_RESET, - CR_FG_RED, - CR_FG_BOLD, - msg, - CR_RESET); + CRIT_COLOR_NORMALIZE(prefix->color), + prefix->prefix, + CR_RESET, + CR_FG_RED, + CR_FG_BOLD, + msg, + CR_RESET); } else { fprintf(stderr, _(LOG_FORMAT), - CRIT_COLOR_NORMALIZE(prefix->color), - prefix->prefix, - CR_RESET, - msg); + CRIT_COLOR_NORMALIZE(prefix->color), + prefix->prefix, + CR_RESET, + msg); } fprintf(stderr, "\n"); } -void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...) { +void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...) +{ va_list args; if (level < criterion_options.logging_threshold) @@ -103,46 +105,51 @@ void criterion_plog(enum criterion_logging_level level, const struct criterion_p if (prefix == &g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_ERR]) { fprintf(stderr, _(ERROR_FORMAT), - CRIT_COLOR_NORMALIZE(prefix->color), - prefix->prefix, + CRIT_COLOR_NORMALIZE(prefix->color), + prefix->prefix, CR_RESET, CR_FG_RED, CR_FG_BOLD, - formatted_msg, + formatted_msg, CR_RESET); } else { fprintf(stderr, _(LOG_FORMAT), - CRIT_COLOR_NORMALIZE(prefix->color), - prefix->prefix, + CRIT_COLOR_NORMALIZE(prefix->color), + prefix->prefix, CR_RESET, - formatted_msg); + formatted_msg); } - } -void criterion_log(enum criterion_logging_level level, const char *msg, ...) { +void criterion_log(enum criterion_logging_level level, const char *msg, ...) +{ va_list args; + va_start(args, msg); criterion_vlog(level, msg, args); va_end(args); } -void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args) { +void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args) +{ if (level < criterion_options.logging_threshold) return; vfprintf(stderr, msg, args); } -void cr_log_noformat(enum criterion_severity severity, const char *out) { +void cr_log_noformat(enum criterion_severity severity, const char *out) +{ criterion_protocol_msg msg = criterion_message(message, - .severity = (criterion_protocol_log_level) severity, - .message = (char *) out); + .severity = (criterion_protocol_log_level) severity, + .message = (char *) out); + criterion_message_set_id(msg); cr_send_to_runner(&msg); } -void cr_log(enum criterion_severity severity, const char *msg, ...) { +void cr_log(enum criterion_severity severity, const char *msg, ...) +{ va_list args; char *out = NULL; diff --git a/src/log/logging.h b/src/log/logging.h index 3e366c5..cd88f2b 100644 --- a/src/log/logging.h +++ b/src/log/logging.h @@ -22,16 +22,16 @@ * THE SOFTWARE. */ #ifndef LOGGING_H_ -# define LOGGING_H_ +#define LOGGING_H_ -# ifdef __cplusplus -# include +#ifdef __cplusplus +# include using std::va_list; -# else -# include -# include -# endif -# include "criterion/logging.h" +#else +# include +# include +#endif +#include "criterion/logging.h" enum criterion_logging_prefix { CRITERION_LOGGING_PREFIX_DASHES, @@ -49,41 +49,41 @@ struct criterion_prefix_data { const char *color; }; -# ifdef CRITERION_LOGGING_COLORS -# define CRIT_COLOR_NORMALIZE(Str) (criterion_options.use_ascii ? "" : Str) +#ifdef CRITERION_LOGGING_COLORS +# define CRIT_COLOR_NORMALIZE(Str) (criterion_options.use_ascii ? "" : Str) -# define CRIT_FG_BOLD "\33[0;1m" -# define CRIT_FG_RED "\33[0;31m" -# define CRIT_FG_GREEN "\33[0;32m" -# define CRIT_FG_GOLD "\33[0;33m" -# define CRIT_FG_BLUE "\33[0;34m" -# define CRIT_RESET "\33[0m" +# define CRIT_FG_BOLD "\33[0;1m" +# define CRIT_FG_RED "\33[0;31m" +# define CRIT_FG_GREEN "\33[0;32m" +# define CRIT_FG_GOLD "\33[0;33m" +# define CRIT_FG_BLUE "\33[0;34m" +# define CRIT_RESET "\33[0m" -# define CR_FG_BOLD CRIT_COLOR_NORMALIZE(CRIT_FG_BOLD) -# define CR_FG_RED CRIT_COLOR_NORMALIZE(CRIT_FG_RED) -# define CR_FG_GREEN CRIT_COLOR_NORMALIZE(CRIT_FG_GREEN) -# define CR_FG_GOLD CRIT_COLOR_NORMALIZE(CRIT_FG_GOLD) -# define CR_FG_BLUE CRIT_COLOR_NORMALIZE(CRIT_FG_BLUE) -# define CR_RESET CRIT_COLOR_NORMALIZE(CRIT_RESET) -# endif +# define CR_FG_BOLD CRIT_COLOR_NORMALIZE(CRIT_FG_BOLD) +# define CR_FG_RED CRIT_COLOR_NORMALIZE(CRIT_FG_RED) +# define CR_FG_GREEN CRIT_COLOR_NORMALIZE(CRIT_FG_GREEN) +# define CR_FG_GOLD CRIT_COLOR_NORMALIZE(CRIT_FG_GOLD) +# define CR_FG_BLUE CRIT_COLOR_NORMALIZE(CRIT_FG_BLUE) +# define CR_RESET CRIT_COLOR_NORMALIZE(CRIT_RESET) +#endif extern const struct criterion_prefix_data g_criterion_logging_prefixes[]; -# define CRITERION_PREFIX_DASHES (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_DASHES]) -# define CRITERION_PREFIX_EQUALS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_EQUALS]) -# define CRITERION_PREFIX_RUN (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_RUN ]) -# define CRITERION_PREFIX_SKIP (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_SKIP ]) -# define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS ]) -# define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL ]) -# define CRITERION_PREFIX_ERR (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_ERR ]) -# define CRITERION_PREFIX_WARN (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_WARN ]) +#define CRITERION_PREFIX_DASHES (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_DASHES]) +#define CRITERION_PREFIX_EQUALS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_EQUALS]) +#define CRITERION_PREFIX_RUN (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_RUN]) +#define CRITERION_PREFIX_SKIP (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_SKIP]) +#define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS]) +#define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL]) +#define CRITERION_PREFIX_ERR (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_ERR]) +#define CRITERION_PREFIX_WARN (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_WARN]) -# undef criterion_log -# undef criterion_info -# undef criterion_pinfo -# undef criterion_important -# undef criterion_pimportant -# undef criterion_perror +#undef criterion_log +#undef criterion_info +#undef criterion_pinfo +#undef criterion_important +#undef criterion_pimportant +#undef criterion_perror CR_API void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); @@ -93,13 +93,13 @@ CR_API void criterion_plog(enum criterion_logging_level level, const struct crit CR_FORMAT(printf, 2, 3) CR_API void criterion_log(enum criterion_logging_level level, const char *msg, ...); -# define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__) -# define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__) +#define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__) +#define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__) -# define criterion_pinfo(...) criterion_plog(CRITERION_INFO, __VA_ARGS__) -# define criterion_pimportant(...) criterion_plog(CRITERION_IMPORTANT, __VA_ARGS__) +#define criterion_pinfo(...) criterion_plog(CRITERION_INFO, __VA_ARGS__) +#define criterion_pimportant(...) criterion_plog(CRITERION_IMPORTANT, __VA_ARGS__) -# define criterion_perror(...) criterion_plog(CRITERION_IMPORTANT, CRITERION_PREFIX_ERR, __VA_ARGS__) +#define criterion_perror(...) criterion_plog(CRITERION_IMPORTANT, CRITERION_PREFIX_ERR, __VA_ARGS__) void cr_log_noformat(enum criterion_severity severity, const char *out); void criterion_log_noformat(enum criterion_severity severity, const char *msg); diff --git a/src/log/normal.c b/src/log/normal.c index dbb0763..552c3c7 100644 --- a/src/log/normal.c +++ b/src/log/normal.c @@ -56,12 +56,12 @@ static msg_t msg_test_generic = N_("%1$s::%2$s: %3$s\n"); static msg_t msg_test_other_crash = N_("%1$sWarning! The test `%2$s::%3$s` crashed during its setup or teardown.%4$s\n"); static msg_t msg_test_abnormal_exit = N_("%1$sWarning! The test `%2$s::%3$s` exited during its setup or teardown.%4$s\n"); static msg_t msg_pre_suite[] = N_s("Running %1$s%2$lu%3$s test from %4$s%5$s%6$s:\n", - "Running %1$s%2$lu%3$s tests from %4$s%5$s%6$s:\n"); + "Running %1$s%2$lu%3$s tests from %4$s%5$s%6$s:\n"); static msg_t msg_post_all = N_("%1$sSynthesis: Tested: %2$s%3$lu%4$s " - "| Passing: %5$s%6$lu%7$s " - "| Failing: %8$s%9$lu%10$s " - "| Crashing: %11$s%12$lu%13$s " - "%14$s\n"); + "| Passing: %5$s%6$lu%7$s " + "| Failing: %8$s%9$lu%10$s " + "| Crashing: %11$s%12$lu%13$s " + "%14$s\n"); #else static msg_t msg_pre_init = "%s::%s\n"; static msg_t msg_post_test_timed = "%s::%s: (%3.2fs)\n"; @@ -76,27 +76,29 @@ static msg_t msg_test_generic = "%s::%s: %s\n"; static msg_t msg_test_other_crash = "%sWarning! The test `%s::%s` crashed during its setup or teardown.%s\n"; static msg_t msg_test_abnormal_exit = "%sWarning! The test `%s::%s` exited during its setup or teardown.%s\n"; static msg_t msg_pre_suite[] = { "Running %s%lu%s test from %s%s%s:\n", - "Running %s%lu%s tests from %s%s%s:\n" }; + "Running %s%lu%s tests from %s%s%s:\n" }; static msg_t msg_post_all = "%sSynthesis: Tested: %s%lu%s " - "| Passing: %s%lu%s " - "| Failing: %s%lu%s " - "| Crashing: %s%lu%s " - "%s\n"; + "| Passing: %s%lu%s " + "| Failing: %s%lu%s " + "| Crashing: %s%lu%s " + "%s\n"; #endif -void normal_log_pre_all(CR_UNUSED struct criterion_test_set *set) { +void normal_log_pre_all(CR_UNUSED struct criterion_test_set *set) +{ criterion_pinfo(CRITERION_PREFIX_DASHES, _(msg_pre_all), VERSION); } -void normal_log_pre_init(struct criterion_suite *suite,struct criterion_test *test) { - if(test->data->disabled || (suite->data && suite->data->disabled)) { +void normal_log_pre_init(struct criterion_suite *suite, struct criterion_test *test) +{ + if (test->data->disabled || (suite->data && suite->data->disabled)) { criterion_pinfo(CRITERION_PREFIX_SKIP, _(msg_test_disabled), test->category, test->name); } else { criterion_pinfo(CRITERION_PREFIX_RUN, _(msg_pre_init), - test->category, - test->name); + test->category, + test->name); } if (test->data->description) @@ -104,17 +106,18 @@ void normal_log_pre_init(struct criterion_suite *suite,struct criterion_test *te test->data->description); } -void normal_log_post_test(struct criterion_test_stats *stats) { +void normal_log_post_test(struct criterion_test_stats *stats) +{ const char *format = msg_post_test_timed; - const enum criterion_logging_level level - = stats->test_status == CR_STATUS_FAILED ? CRITERION_IMPORTANT : CRITERION_INFO; - const struct criterion_prefix_data *prefix - = stats->test_status == CR_STATUS_FAILED ? CRITERION_PREFIX_FAIL : - CRITERION_PREFIX_PASS; + const enum criterion_logging_level level = + stats->test_status == CR_STATUS_FAILED ? CRITERION_IMPORTANT : CRITERION_INFO; + const struct criterion_prefix_data *prefix = + stats->test_status == CR_STATUS_FAILED ? CRITERION_PREFIX_FAIL + : CRITERION_PREFIX_PASS; - if(stats->test_status == CR_STATUS_SKIPPED) { - if(!stats->message) { + if (stats->test_status == CR_STATUS_SKIPPED) { + if (!stats->message) { criterion_pinfo(CRITERION_PREFIX_SKIP, _(msg_post_test_skip), stats->test->category, stats->test->name); @@ -132,22 +135,24 @@ void normal_log_post_test(struct criterion_test_stats *stats) { } } -void normal_log_post_all(struct criterion_global_stats *stats) { +void normal_log_post_all(struct criterion_global_stats *stats) +{ size_t tested = stats->nb_tests - stats->tests_skipped; char *tests_crashed_color = (stats->tests_crashed) ? CR_FG_RED : CR_RESET; char *tests_failed_color = (stats->tests_failed) ? CR_FG_RED : CR_RESET; criterion_pimportant(CRITERION_PREFIX_EQUALS, _(msg_post_all), - CR_FG_BOLD, - CR_FG_BLUE, (unsigned long) tested, CR_FG_BOLD, - CR_FG_GREEN, (unsigned long) stats->tests_passed, CR_FG_BOLD, - tests_failed_color, (unsigned long) stats->tests_failed, CR_FG_BOLD, - tests_crashed_color, (unsigned long) stats->tests_crashed, CR_FG_BOLD, - CR_RESET); + CR_FG_BOLD, + CR_FG_BLUE, (unsigned long) tested, CR_FG_BOLD, + CR_FG_GREEN, (unsigned long) stats->tests_passed, CR_FG_BOLD, + tests_failed_color, (unsigned long) stats->tests_failed, CR_FG_BOLD, + tests_crashed_color, (unsigned long) stats->tests_crashed, CR_FG_BOLD, + CR_RESET); } -void normal_log_assert(struct criterion_assert_stats *stats) { +void normal_log_assert(struct criterion_assert_stats *stats) +{ if (!stats->passed) { char *dup = strdup(*stats->message ? stats->message : ""); char *saveptr = NULL; @@ -156,8 +161,8 @@ void normal_log_assert(struct criterion_assert_stats *stats) { bool sf = criterion_options.short_filename; criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_assert_fail), - CR_FG_BOLD, sf ? basename_compat(stats->file) : stats->file, CR_RESET, - CR_FG_RED, stats->line, CR_RESET, + CR_FG_BOLD, sf ? basename_compat(stats->file) : stats->file, CR_RESET, + CR_FG_RED, stats->line, CR_RESET, line); while ((line = strtok_r(NULL, "\n", &saveptr))) @@ -166,41 +171,47 @@ void normal_log_assert(struct criterion_assert_stats *stats) { } } -void normal_log_test_crash(struct criterion_test_stats *stats) { +void normal_log_test_crash(struct criterion_test_stats *stats) +{ bool sf = criterion_options.short_filename; + criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_test_crash_line), - CR_FG_BOLD, sf ? basename_compat(stats->file) : stats->file, CR_RESET, - CR_FG_RED, stats->progress, CR_RESET); + CR_FG_BOLD, sf ? basename_compat(stats->file) : stats->file, CR_RESET, + CR_FG_RED, stats->progress, CR_RESET); criterion_pimportant(CRITERION_PREFIX_FAIL, _(msg_test_crash), stats->test->category, stats->test->name); } -void normal_log_other_crash(CR_UNUSED struct criterion_test_stats *stats) { +void normal_log_other_crash(CR_UNUSED struct criterion_test_stats *stats) +{ criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_test_other_crash), - CR_FG_BOLD, stats->test->category, stats->test->name, CR_RESET); + CR_FG_BOLD, stats->test->category, stats->test->name, CR_RESET); } -void normal_log_abnormal_exit(CR_UNUSED struct criterion_test_stats *stats) { +void normal_log_abnormal_exit(CR_UNUSED struct criterion_test_stats *stats) +{ criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_test_abnormal_exit), - CR_FG_BOLD, stats->test->category, stats->test->name, CR_RESET); + CR_FG_BOLD, stats->test->category, stats->test->name, CR_RESET); } -void normal_log_pre_suite(struct criterion_suite_set *set) { +void normal_log_pre_suite(struct criterion_suite_set *set) +{ criterion_pinfo(CRITERION_PREFIX_EQUALS, _s(msg_pre_suite[0], msg_pre_suite[1], set->tests->size), - CR_FG_BLUE, (unsigned long) set->tests->size, CR_RESET, - CR_FG_GOLD, set->suite.name, CR_RESET); + CR_FG_BLUE, (unsigned long) set->tests->size, CR_RESET, + CR_FG_GOLD, set->suite.name, CR_RESET); if (set->suite.data && set->suite.data->description) criterion_pinfo(CRITERION_PREFIX_DASHES, _(msg_desc), set->suite.data->description); } -void normal_log_theory_fail(struct criterion_theory_stats *stats) { +void normal_log_theory_fail(struct criterion_theory_stats *stats) +{ criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_theory_fail), stats->stats->test->category, @@ -208,7 +219,8 @@ void normal_log_theory_fail(struct criterion_theory_stats *stats) { stats->formatted_args); } -void normal_log_test_timeout(CR_UNUSED struct criterion_test_stats *stats) { +void normal_log_test_timeout(CR_UNUSED struct criterion_test_stats *stats) +{ criterion_pimportant(CRITERION_PREFIX_FAIL, _(msg_test_timeout), stats->test->category, @@ -216,8 +228,8 @@ void normal_log_test_timeout(CR_UNUSED struct criterion_test_stats *stats) { stats->elapsed_time); } -void normal_log_test_abort(CR_UNUSED struct criterion_test_stats *stats, const char *msg) { - +void normal_log_test_abort(CR_UNUSED struct criterion_test_stats *stats, const char *msg) +{ char *dup = strdup(msg); char *saveptr = NULL; char *line = strtok_r(dup, "\n", &saveptr); @@ -234,7 +246,8 @@ void normal_log_test_abort(CR_UNUSED struct criterion_test_stats *stats, const c free(dup); } -void normal_log_message(enum criterion_severity severity, const char *msg) { +void normal_log_message(enum criterion_severity severity, const char *msg) +{ char *dup = strdup(msg); char *saveptr = NULL; char *line = strtok_r(dup, "\n", &saveptr); @@ -243,7 +256,7 @@ void normal_log_message(enum criterion_severity severity, const char *msg) { if (*line != '\0') criterion_log_noformat(severity, line); } while ((line = strtok_r(NULL, "\n", &saveptr))); - free (dup); + free(dup); } struct criterion_logger normal_logging = { diff --git a/src/protocol/connect.c b/src/protocol/connect.c index 302fd62..13a76a2 100644 --- a/src/protocol/connect.c +++ b/src/protocol/connect.c @@ -33,6 +33,7 @@ int cri_proto_bind(const char *url) { int sock = nn_socket(AF_SP, NN_REP); + if (sock < 0) return -1; @@ -49,10 +50,11 @@ error: {} int cri_proto_connect(const char *url) { int sock = nn_socket(AF_SP, NN_REQ); + if (sock < 0) return -1; - if (nn_connect (sock, url) < 0) + if (nn_connect(sock, url) < 0) goto error; return sock; diff --git a/src/protocol/connect.h b/src/protocol/connect.h index c50d9ee..809bfaf 100644 --- a/src/protocol/connect.h +++ b/src/protocol/connect.h @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #ifndef CONNECT_H_ -# define CONNECT_H_ +#define CONNECT_H_ int cri_proto_bind(const char *url); int cri_proto_connect(const char *url); diff --git a/src/protocol/messages.c b/src/protocol/messages.c index 788d66e..b99ff58 100644 --- a/src/protocol/messages.c +++ b/src/protocol/messages.c @@ -28,7 +28,8 @@ #include "io/event.h" #include "io/asprintf.h" -int read_message(int sock, criterion_protocol_msg *message) { +int read_message(int sock, criterion_protocol_msg *message) +{ int res; unsigned char *buf = NULL; int read = res = nn_recv(sock, &buf, NN_MSG, 0); @@ -49,10 +50,12 @@ cleanup: return res; } -int write_message(int sock, const criterion_protocol_msg *message) { +int write_message(int sock, const criterion_protocol_msg *message) +{ int res = -1; size_t size; unsigned char *buf = NULL; + if (!pb_get_encoded_size(&size, criterion_protocol_msg_fields, message)) goto cleanup; @@ -79,7 +82,8 @@ const char *message_names[] = { [criterion_protocol_submessage_assert_tag] = "assert", }; -void cr_send_to_runner(const criterion_protocol_msg *message) { +void cr_send_to_runner(const criterion_protocol_msg *message) +{ if (write_message(g_client_socket, message) != 1) { criterion_perror("Could not write the \"%s\" message down the event pipe: %s.\n", message_names[message->data.which_value], @@ -112,8 +116,10 @@ void cr_send_to_runner(const criterion_protocol_msg *message) { nn_freemsg(buf); } -void send_ack(int sock, bool ok, const char *msg, ...) { +void send_ack(int sock, bool ok, const char *msg, ...) +{ criterion_protocol_ack ack; + ack.status_code = ok ? criterion_protocol_ack_status_OK : criterion_protocol_ack_status_ERROR; ack.message = NULL; @@ -148,6 +154,7 @@ void send_ack(int sock, bool ok, const char *msg, ...) { free(buf); } -void free_message(criterion_protocol_msg *msg) { +void free_message(criterion_protocol_msg *msg) +{ pb_release(criterion_protocol_msg_fields, msg); } diff --git a/src/protocol/messages.h b/src/protocol/messages.h index 9148d52..a3c141c 100644 --- a/src/protocol/messages.h +++ b/src/protocol/messages.h @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #ifndef MESSAGES_H_ -# define MESSAGES_H_ +#define MESSAGES_H_ -# include "criterion.pb.h" +#include "criterion.pb.h" int write_message(int sock, const criterion_protocol_msg *message); int read_message(int sock, criterion_protocol_msg *message); diff --git a/src/protocol/protocol.h b/src/protocol/protocol.h index d16526c..46313a4 100644 --- a/src/protocol/protocol.h +++ b/src/protocol/protocol.h @@ -22,15 +22,15 @@ * THE SOFTWARE. */ #ifndef PROTOCOL_H_ -# define PROTOCOL_H_ +#define PROTOCOL_H_ -# include -# include -# include -# include "criterion.pb.h" -# include "criterion/internal/preprocess.h" -# include "compat/process.h" -# include "compat/time.h" +#include +#include +#include +#include "criterion.pb.h" +#include "criterion/internal/preprocess.h" +#include "compat/process.h" +#include "compat/time.h" enum protocol_version { PROTOCOL_V1 = 1, @@ -38,13 +38,13 @@ enum protocol_version { extern volatile bool is_extern_worker; -# define criterion_message_set_id(Msg) \ - do { \ - if (is_extern_worker) { \ - (Msg).id.uid = (char *) criterion_current_test->name; \ - } else { \ - (Msg).id.pid = get_process_id(); \ - } \ +#define criterion_message_set_id(Msg) \ + do { \ + if (is_extern_worker) { \ + (Msg).id.uid = (char *) criterion_current_test->name; \ + } else { \ + (Msg).id.pid = get_process_id(); \ + } \ } while (0) /* *INDENT-OFF* - remove when https://github.com/uncrustify/uncrustify/issues/667 diff --git a/src/string/brz.c b/src/string/brz.c index 5c72efd..665dda5 100644 --- a/src/string/brz.c +++ b/src/string/brz.c @@ -27,18 +27,18 @@ #include #include -#define copy_glob(g) (g)->copy(g) -#define derive_glob(g, chr) (g)->derive(g,chr) +#define copy_glob(g) (g)->copy(g) +#define derive_glob(g, chr) (g)->derive(g, chr) static int matches(glob const *self, char const *string); static int is_true(glob const *self); static int is_false(glob const *self); -static int nullable_char(glob const* self); -static int nullable_or(glob const* self); -static int nullable_seq(glob const* self); -static int nullable_first(glob const* self); -static int nullable_not(glob const* self); +static int nullable_char(glob const *self); +static int nullable_or(glob const *self); +static int nullable_seq(glob const *self); +static int nullable_first(glob const *self); +static int nullable_not(glob const *self); static glob *derive_empty(glob const *self, char const chr); static glob *derive_blank(glob const *self, char const chr); @@ -56,8 +56,8 @@ static glob *copy_one(glob const *cpy); static glob *copy_two(glob const *cpy); #ifdef _DEBUG_BRZ_ -#define print_glob_v(g) do{printf(#g" "); (g)->print(g),puts("");}while(0) -#define print_glob(g) do{(g)->print(g);}while(0) +# define print_glob_v(g) do { printf(#g " "); (g)->print(g), puts(""); } while (0) +# define print_glob(g) do { (g)->print(g); } while (0) static void print_empty(glob const *self); static void print_blank(glob const *self); static void print_char(glob const *self); @@ -72,23 +72,24 @@ static void print_seq(glob const *self); static void print_not(glob const *self); #endif -void free_glob(glob *tmp) { - glob* first = (glob*)tmp->first; - glob* second = (glob*)tmp->second; - if (tmp->type != CHAR && tmp->type != CHARSET && first) { +void free_glob(glob *tmp) +{ + glob *first = (glob *) tmp->first; + glob *second = (glob *) tmp->second; + + if (tmp->type != CHAR && tmp->type != CHARSET && first) free_glob(first); - } else if (tmp->type == CHARSET) { + else if (tmp->type == CHARSET) free(tmp->cset); - } - if (second) { + if (second) free_glob(second); - } free(tmp); } +static glob *new_glob() +{ + glob *tmp = malloc(sizeof (glob)); -static glob *new_glob() { - glob* tmp = malloc(sizeof(glob)); if (tmp) { tmp->derive = NULL; tmp->nullable = NULL; @@ -96,15 +97,15 @@ static glob *new_glob() { tmp->second = NULL; tmp->matches = matches; tmp->type = 0; - } - else { + } else { fprintf(stderr, "Could not allocate glob object.\n"); exit(1); } return tmp; } -static int matches(glob const *self, char const *string) { +static int matches(glob const *self, char const *string) +{ if (strlen(string) == 0) { return self->nullable(self); } else { @@ -117,7 +118,7 @@ static int matches(glob const *self, char const *string) { #ifdef _DEBUG_BRZ_ print_glob_v(tmp); #endif - ret = tmp->matches(tmp,++string); + ret = tmp->matches(tmp, ++string); free_glob(tmp); return ret; } @@ -128,8 +129,10 @@ static int matches(glob const *self, char const *string) { * not nullable * no derivative */ -glob *glob_empty() { +glob *glob_empty() +{ glob *tmp = new_glob(); + tmp->type = EMPTY; tmp->nullable = is_false; tmp->derive = derive_empty; @@ -146,8 +149,10 @@ glob *glob_empty() { * is nullable * derivative is Empty set */ -glob *glob_blank() { +glob *glob_blank() +{ glob *tmp = new_glob(); + tmp->type = BLANK; tmp->nullable = is_true; tmp->derive = derive_blank; @@ -159,15 +164,16 @@ glob *glob_blank() { return tmp; } - /* * single chacacter * nullable for ? and * * derivative: Empty string if chr == c * Empty set otherwise */ -glob *glob_char(char const c) { +glob *glob_char(char const c) +{ glob *tmp = new_glob(); + tmp->type = CHAR; tmp->nullable = nullable_char; tmp->derive = derive_char; @@ -186,8 +192,10 @@ glob *glob_char(char const c) { * derivative: Empty string if chr in [..] or not in [!..] * Empty set otherwise */ -glob *glob_cset(char *cset) { +glob *glob_cset(char *cset) +{ glob *tmp = new_glob(); + tmp->type = CHARSET; tmp->nullable = is_false; tmp->derive = derive_cset; @@ -208,8 +216,9 @@ glob *glob_cset(char *cset) { * Optimization: * (1) E | Empty -> E */ -glob *glob_or(glob const *first, glob const *second) { - if (first->type == EMPTY){ +glob *glob_or(glob const *first, glob const *second) +{ + if (first->type == EMPTY) { return copy_glob(second); } else if (second->type == EMPTY) { return copy_glob(first); @@ -238,7 +247,8 @@ glob *glob_or(glob const *first, glob const *second) { * Optimization: * (1) E & Empty -> Empty */ -glob *glob_and(glob const *first, glob const *second) { +glob *glob_and(glob const *first, glob const *second) +{ if (first->type == EMPTY || second->type == EMPTY) { return glob_empty(); } else { @@ -258,8 +268,10 @@ glob *glob_and(glob const *first, glob const *second) { } } -glob *glob_star(glob const *pattern) { +glob *glob_star(glob const *pattern) +{ glob *tmp = new_glob(); + tmp->type = STAR; tmp->nullable = is_true; tmp->derive = derive_plus; @@ -273,7 +285,6 @@ glob *glob_star(glob const *pattern) { return tmp; } - /* * Repetition one or more * +(pat) @@ -281,8 +292,10 @@ glob *glob_star(glob const *pattern) { * derivative: der(pat) Star(pat) * */ -glob *glob_plus(glob const *pattern) { +glob *glob_plus(glob const *pattern) +{ glob *tmp = glob_star(pattern); + tmp->type = PLUS; tmp->nullable = nullable_first; #ifdef _DEBUG_BRZ_ @@ -298,7 +311,8 @@ glob *glob_plus(glob const *pattern) { * derivative: der(pat) * */ -glob *glob_at(glob const *pattern) { +glob *glob_at(glob const *pattern) +{ if (pattern->type == EMPTY) { return glob_empty(); } else if (pattern->type == BLANK) { @@ -315,7 +329,6 @@ glob *glob_at(glob const *pattern) { } } - /* * Repetition one or zero * ?(pat) @@ -323,8 +336,10 @@ glob *glob_at(glob const *pattern) { * derivative: der(pat) * */ -glob *glob_opt(glob const *pattern) { +glob *glob_opt(glob const *pattern) +{ glob *tmp = new_glob(); + tmp->type = OPT; tmp->nullable = is_true; tmp->derive = derive_at; @@ -345,8 +360,10 @@ glob *glob_opt(glob const *pattern) { * derivative: not der(pat) * */ -glob *glob_not(glob const *pattern) { +glob *glob_not(glob const *pattern) +{ glob *tmp = new_glob(); + tmp->type = NOT; tmp->nullable = nullable_not; tmp->derive = derive_not; @@ -370,10 +387,11 @@ glob *glob_not(glob const *pattern) { * (2) E Empty -> Empty * (3) Blank E -> E */ -glob *glob_seq(glob const *first, glob const *second) { +glob *glob_seq(glob const *first, glob const *second) +{ if (first->type == EMPTY || second->type == EMPTY) { return glob_empty(); - }else if(first->type == BLANK) { + } else if (first->type == BLANK) { return copy_glob(second); } else { glob *tmp = new_glob(); @@ -391,58 +409,68 @@ glob *glob_seq(glob const *first, glob const *second) { } } - -static int is_false(glob const *self) { - (void)(self); +static int is_false(glob const *self) +{ + (void) (self); return 0; } -static int is_true(glob const *self) { - (void)(self); +static int is_true(glob const *self) +{ + (void) (self); return 1; } -static int nullable_char(glob const* self) { - if (self->c == '?' || self->c == '*') { +static int nullable_char(glob const *self) +{ + if (self->c == '?' || self->c == '*') return 1; - } else { + else return 0; - } } -static int nullable_or(glob const* self) { +static int nullable_or(glob const *self) +{ glob const *first, *second; + first = self->first; second = self->second; return first->nullable(first) || second->nullable(second); } -static int nullable_seq(glob const* self) { +static int nullable_seq(glob const *self) +{ glob const *first, *second; + first = self->first; second = self->second; return first->nullable(first) && second->nullable(second); } -static int nullable_first(glob const* self) { +static int nullable_first(glob const *self) +{ glob const *first; + first = self->first; return first->nullable(first); } -static int nullable_not(glob const* self) { +static int nullable_not(glob const *self) +{ return !nullable_first(self); } -static glob *derive_empty(glob const *self, char const chr) { - (void)(chr); - (void)(self); +static glob *derive_empty(glob const *self, char const chr) +{ + (void) (chr); + (void) (self); return glob_empty(); } -static glob *derive_blank(glob const *self, char const chr) { - (void)(self); - (void)(chr); +static glob *derive_blank(glob const *self, char const chr) +{ + (void) (self); + (void) (chr); return glob_empty(); } @@ -457,13 +485,14 @@ static glob *derive_char(glob const *self, char const chr) return glob_empty(); } - -static glob *derive_cset(glob const *self, char const chr) { +static glob *derive_cset(glob const *self, char const chr) +{ /* Character class */ char *pat = self->cset; int match = 0, inverted = (*pat == '!'); char const *class = pat + inverted; unsigned char a = *class++; + /* * Iterate over each span in the character class. * A span is either a single character a, or a @@ -472,7 +501,7 @@ static glob *derive_cset(glob const *self, char const chr) { do { unsigned char b = a; - if (a == '\0') /* Malformed */ + if (a == '\0') /* Malformed */ return glob_empty(); if (class[0] == '-' && class[1] != ']') { @@ -497,34 +526,40 @@ static glob *derive_cset(glob const *self, char const chr) { return glob_blank(); } -static glob *derive_and(glob const *self, char const chr) { +static glob *derive_and(glob const *self, char const chr) +{ glob const *first, *second; + first = self->first; second = self->second; glob *d1 = derive_glob(first, chr); glob *d2 = derive_glob(second, chr); - glob* ret; + glob *ret; ret = glob_and(d1, d2); free_glob(d1); free_glob(d2); return ret; } -static glob *derive_or(glob const *self, char const chr) { +static glob *derive_or(glob const *self, char const chr) +{ glob const *first, *second; + first = self->first; second = self->second; glob *d1 = derive_glob(first, chr); glob *d2 = derive_glob(second, chr); - glob* ret = glob_or(d1, d2); + glob *ret = glob_or(d1, d2); free_glob(d1); free_glob(d2); return ret; } -static glob *derive_plus(glob const *self, char const chr) { +static glob *derive_plus(glob const *self, char const chr) +{ glob *ret; glob const *pat; + pat = self->pattern; glob *d = derive_glob(pat, chr); glob *s = glob_star(pat); @@ -535,12 +570,14 @@ static glob *derive_plus(glob const *self, char const chr) { return ret; } -static glob *derive_seq(glob const *self, char const chr) { +static glob *derive_seq(glob const *self, char const chr) +{ glob *ret; glob const *first, *second; + first = self->first; second = self->second; - if (first->nullable(first)) { // A nullable -> Or( Seq(d1, sec), d2) + if (first->nullable(first)) { /* A nullable -> Or( Seq(d1, sec), d2) */ glob *d1 = derive_glob(first, chr); glob *d2 = derive_glob(second, chr); glob *s = glob_seq(d1, second); @@ -548,7 +585,7 @@ static glob *derive_seq(glob const *self, char const chr) { free_glob(s); free_glob(d1); free_glob(d2); - } else { // A not nullable + } else { /* A not nullable */ glob *derive = derive_glob(first, chr); ret = glob_seq(derive, second); free_glob(derive); @@ -557,10 +594,10 @@ static glob *derive_seq(glob const *self, char const chr) { return ret; } - - -static glob *derive_at(glob const *self, char const chr) { +static glob *derive_at(glob const *self, char const chr) +{ glob const *pat; + pat = self->pattern; glob *d = derive_glob(pat, chr); glob *ret; @@ -569,8 +606,10 @@ static glob *derive_at(glob const *self, char const chr) { return ret; } -static glob *derive_not(glob const *self, char const chr) { +static glob *derive_not(glob const *self, char const chr) +{ glob const *pat; + pat = self->pattern; glob *d = derive_glob(pat, chr); glob *ret = glob_not(d); @@ -578,21 +617,24 @@ static glob *derive_not(glob const *self, char const chr) { return ret; } -static glob *copy_zero(glob const *cpy) { +static glob *copy_zero(glob const *cpy) +{ glob *tmp = new_glob(); + *tmp = *cpy; return tmp; } -static glob *copy_one(glob const *cpy) { +static glob *copy_one(glob const *cpy) +{ glob const *first = cpy->first; glob *tmp = new_glob(); + *tmp = *cpy; - if (cpy->type != CHARSET) { + if (cpy->type != CHARSET) tmp->first = copy_glob(first); - } else { + else tmp->cset = strdup(cpy->cset); - } return tmp; } @@ -601,40 +643,41 @@ static glob *copy_two(glob const *cpy) glob const *first = cpy->first; glob const *sec = cpy->second; glob *tmp = new_glob(); + *tmp = *cpy; tmp->first = copy_glob(first); tmp->second = copy_glob(sec); return tmp; } - #ifdef _DEBUG_BRZ_ static void print_empty(glob const *self) { - (void)(self); + (void) (self); printf("Empty"); } static void print_blank(glob const *self) { - (void)(self); + (void) (self); printf("Blank"); } static void print_char(glob const *self) { - printf("%c",self->c); + printf("%c", self->c); } static void print_cset(glob const *self) { - printf("[%s]",self->cset); + printf("[%s]", self->cset); } static void print_or(glob const *self) { glob const *first = self->first; glob const *sec = self->second; + printf("("); print_glob(first); printf(" | "); @@ -645,6 +688,7 @@ static void print_and(glob const *self) { glob const *first = self->first; glob const *sec = self->second; + printf("("); print_glob(first); printf(" & "); @@ -656,6 +700,7 @@ static void print_seq(glob const *self) { glob const *first = self->first; glob const *sec = self->second; + print_glob(first); printf(" . "); print_glob(sec); @@ -664,6 +709,7 @@ static void print_seq(glob const *self) static void print_star(glob const *self) { glob const *first = self->first; + printf("*("); print_glob(first); printf(")"); @@ -671,6 +717,7 @@ static void print_star(glob const *self) static void print_plus(glob const *self) { glob const *first = self->first; + printf("+("); print_glob(first); printf(")"); @@ -678,6 +725,7 @@ static void print_plus(glob const *self) static void print_at(glob const *self) { glob const *first = self->first; + printf("@("); print_glob(first); printf(")"); @@ -685,6 +733,7 @@ static void print_at(glob const *self) static void print_opt(glob const *self) { glob const *first = self->first; + printf("?("); print_glob(first); printf(")"); @@ -692,6 +741,7 @@ static void print_opt(glob const *self) static void print_not(glob const *self) { glob const *first = self->first; + printf("!("); print_glob(first); printf(")"); diff --git a/src/string/brz.h b/src/string/brz.h index 8400b03..31a407f 100644 --- a/src/string/brz.h +++ b/src/string/brz.h @@ -30,7 +30,7 @@ typedef struct stc_glob *(*copy_func)(struct stc_glob const *cpy); typedef void (*printFunc)(struct stc_glob const *self); typedef enum - {EMPTY = 0, BLANK, CHAR, CHARSET, OR, AND, STAR, PLUS, AT, OPT, SEQ, NOT}glob_type; +{ EMPTY = 0, BLANK, CHAR, CHARSET, OR, AND, STAR, PLUS, AT, OPT, SEQ, NOT } glob_type; typedef struct stc_glob { glob_type type; @@ -50,14 +50,14 @@ typedef struct stc_glob { union { struct stc_glob const *second; }; -}glob; +} glob; void free_glob(glob *tmp); glob *glob_empty(); glob *glob_blank(); glob *glob_char(char c); -glob *glob_cset(char* c); +glob *glob_cset(char *c); glob *glob_or(glob const *first, glob const *second); glob *glob_and(glob const *first, glob const *second); glob *glob_star(glob const *pattern); diff --git a/src/string/extglobmatch.c b/src/string/extglobmatch.c index f1edfe2..a958e42 100644 --- a/src/string/extglobmatch.c +++ b/src/string/extglobmatch.c @@ -30,67 +30,72 @@ #include "extglobmatch.h" #include "brz.h" -#define cat_one() do{ \ - if (atoms > 1) { \ - --atoms; \ - glob *b = *--frag; \ - glob *a = *--frag; \ - *frag++ = glob_seq(a,b); \ - free_glob(a); \ - free_glob(b); \ - } \ - } while(0) +#define cat_one() \ + do { \ + if (atoms > 1) { \ + --atoms; \ + glob *b = *--frag; \ + glob *a = *--frag; \ + *frag++ = glob_seq(a, b); \ + free_glob(a); \ + free_glob(b); \ + } \ + } while (0) -#define cat_all() do{ \ - while (--atoms > 0) { \ - glob *b = *--frag; \ - glob *a = *--frag; \ - *frag++ = glob_seq(a,b); \ - free_glob(a); \ - free_glob(b); \ - } \ - }while(0) +#define cat_all() \ + do { \ + while (--atoms > 0) { \ + glob *b = *--frag; \ + glob *a = *--frag; \ + *frag++ = glob_seq(a, b); \ + free_glob(a); \ + free_glob(b); \ + } \ + } while (0) -static glob* match_glob = NULL; +static glob *match_glob = NULL; -static void cleanup(glob **start, glob **end) { - while (start != end) - { +static void cleanup(glob **start, glob **end) +{ + while (start != end) { free_glob(*start); ++start; } } -static void print_error(char const c) { +static void print_error(char const c) +{ fprintf(stderr, "pattern error: Unexpected character '%c'\n", c); } -static glob* handle_operator(char op, glob const* g) +static glob *handle_operator(char op, glob const *g) { - glob* tmp = NULL; + glob *tmp = NULL; + switch (op) { case '!': tmp = glob_not(g); - break; + break; case '*': tmp = glob_star(g); - break; + break; case '+': tmp = glob_plus(g); - break; + break; case '@': tmp = glob_at(g); - break; + break; case '?': tmp = glob_opt(g); - break; + break; } assert(tmp); return tmp; } -#define push_frag(f) *frag++ = f -#define pop_frag() *--frag -#define ARRAY_SIZE 100 +#define push_frag(f) *frag ++ = f +#define pop_frag() *--frag +#define ARRAY_SIZE 100 -static glob *compile(char const *pat) { - glob *frags[ARRAY_SIZE]={0}; - glob **frag=frags; +static glob *compile(char const *pat) +{ + glob *frags[ARRAY_SIZE] = { 0 }; + glob **frag = frags; struct paren { int alter; int atoms; @@ -99,15 +104,16 @@ static glob *compile(char const *pat) { int alter = 0; int atoms = 0; + pa = paren; assert(pat); for (;;) { unsigned char p = *pat++; - if(!p) + if (!p) break; - switch(p) { + switch (p) { case '!': case '?': case '@': @@ -116,7 +122,7 @@ static glob *compile(char const *pat) { if (*pat != '(') goto character; if (pa >= paren + ARRAY_SIZE) { - fprintf(stderr,"pattern error: to many nested globs.\n"); + fprintf(stderr, "pattern error: to many nested globs.\n"); goto error; } cat_one(); @@ -136,85 +142,84 @@ static glob *compile(char const *pat) { goto error; case ')': { - glob *tmp, *a; - if (pa == paren || !atoms) { - print_error(p); - goto error; - } - --pa; - cat_all(); - a = pop_frag(); - tmp = handle_operator(pa->op, a); - free_glob(a); - push_frag(tmp); - - for (; alter > 0; --alter) { - glob *b = pop_frag(); - glob *a = pop_frag(); - if (pa->op == '!') - push_frag(glob_and(a, b)); - else - push_frag(glob_or(a, b)); - --atoms; - free_glob(a); - free_glob(b); - } - - atoms = pa->atoms; - alter = pa->alter; - atoms++; + glob *tmp, *a; + if (pa == paren || !atoms) { + print_error(p); + goto error; } - break; + --pa; + cat_all(); + a = pop_frag(); + tmp = handle_operator(pa->op, a); + free_glob(a); + push_frag(tmp); + + for (; alter > 0; --alter) { + glob *b = pop_frag(); + glob *a = pop_frag(); + if (pa->op == '!') + push_frag(glob_and(a, b)); + else + push_frag(glob_or(a, b)); + --atoms; + free_glob(a); + free_glob(b); + } + + atoms = pa->atoms; + alter = pa->alter; + atoms++; + } + break; case '[': { - char *strPat; - char const *end; - cat_one(); - end = strchr(pat, ']'); - if (!end) { - fprintf(stderr,"pattern error: Mismatching brackets.\n"); - goto error; - } - strPat = strdup(pat); - strPat[end-pat]='\0'; - push_frag(glob_cset(strPat)); - ++atoms; - free(strPat); - pat = end + 1; - break; + char *strPat; + char const *end; + cat_one(); + end = strchr(pat, ']'); + if (!end) { + fprintf(stderr, "pattern error: Mismatching brackets.\n"); + goto error; } + strPat = strdup(pat); + strPat[end - pat] = '\0'; + push_frag(glob_cset(strPat)); + ++atoms; + free(strPat); + pat = end + 1; + break; + } case '|': { - glob *a; - glob *tmp; - char op; - if (atoms == 0 || pa == paren) { - print_error(p); - goto error; - } - cat_all(); - a = pop_frag(); - op = (pa-1)->op; - tmp = handle_operator(op, a); - free_glob(a); - push_frag(tmp); - - ++alter; + glob *a; + glob *tmp; + char op; + if (atoms == 0 || pa == paren) { + print_error(p); + goto error; } - break; + cat_all(); + a = pop_frag(); + op = (pa - 1)->op; + tmp = handle_operator(op, a); + free_glob(a); + push_frag(tmp); + + ++alter; + } + break; case '\\': p = *pat++; - /* FALLTHROUGH */ + /* FALLTHROUGH */ default: /* literal character */ -character: cat_one(); - push_frag(glob_char(p)); - ++atoms; + character: cat_one(); + push_frag(glob_char(p)); + ++atoms; } - } if (pa != paren) { - fprintf(stderr,"pattern error: Mismatching parenthesis\n"); + fprintf(stderr, "pattern error: Mismatching parenthesis\n"); goto error; } @@ -227,35 +232,36 @@ error: return NULL; } - -int compile_pattern(char const* pattern){ +int compile_pattern(char const *pattern) +{ match_glob = compile(pattern); return match_glob ? 1 : 0; } -int match(char const* string){ +int match(char const *string) +{ return match_glob->matches(match_glob, string); } -void free_pattern(){ +void free_pattern() +{ free_glob(match_glob); } #ifdef _DEBUG_BRZ_ -void print_pattern() { +void print_pattern() +{ match_glob->print(match_glob); } int main(int argc, char *argv[]) { - if (argc < 3) - { - printf("usage: %s \"pattern\" \"string\"\n",argv[0]); + if (argc < 3) { + printf("usage: %s \"pattern\" \"string\"\n", argv[0]); return 1; } printf("argv: %s\n", argv[1]); - if(compile_pattern(argv[1])) - { + if (compile_pattern(argv[1])) { print_pattern(); puts(""); puts(""); diff --git a/src/string/extglobmatch.h b/src/string/extglobmatch.h index f186ddf..eaffdc7 100644 --- a/src/string/extglobmatch.h +++ b/src/string/extglobmatch.h @@ -24,8 +24,8 @@ #ifndef EXTGLOBMATCH_H #define EXTGLOBMATCH_H -int compile_pattern(char const* pattern); -int match(char const* string); +int compile_pattern(char const *pattern); +int match(char const *string); void free_pattern(); #endif /* end of include guard: EXTGLOBMATCH_H */ diff --git a/src/string/i18n.c b/src/string/i18n.c index c2bf667..1d721cd 100644 --- a/src/string/i18n.c +++ b/src/string/i18n.c @@ -2,13 +2,15 @@ #include "criterion/assert.h" #include "criterion/internal/asprintf-compat.h" -void init_i18n(void) { +void init_i18n(void) +{ #if ENABLE_NLS - bindtextdomain (PACKAGE, LOCALEDIR); + bindtextdomain(PACKAGE, LOCALEDIR); #endif } -char *cr_translate_assert_msg(int msg_index, ...) { +char *cr_translate_assert_msg(int msg_index, ...) +{ static char *messages[] = { [CRITERION_ASSERT_MSG_FAIL] = N_("The conditions for this assertion were not met."), [CRITERION_ASSERT_MSG_EXPR_FALSE] = N_("The expression %s is false."), @@ -33,10 +35,10 @@ char *cr_translate_assert_msg(int msg_index, ...) { [CRITERION_ASSERT_MSG_THROW] = "The statement `%s` did throw an instance of the `%s` exception.", [CRITERION_ASSERT_MSG_NO_THROW] = "The statement `%s` did not throw an instance of the `%s` exception.", #endif - }; va_list vl; + va_start(vl, msg_index); char *out; cr_vasprintf(&out, _(messages[msg_index]), vl); diff --git a/src/string/i18n.h b/src/string/i18n.h index 5198ec0..1c16fdc 100644 --- a/src/string/i18n.h +++ b/src/string/i18n.h @@ -22,23 +22,23 @@ * THE SOFTWARE. */ #ifndef I18N_H_ -# define I18N_H_ +#define I18N_H_ -# include "config.h" +#include "config.h" -# if !ENABLE_NLS -# define _(String) String -# define _s(String, Plural, Quantity) ((Quantity) == 1 ? String : Plural) -# else -# include -# define _(String) dgettext(PACKAGE, String) -# define _s(String, Plural, Quantity) \ - dngettext(PACKAGE, String, Plural, (Quantity)) -# endif +#if !ENABLE_NLS +# define _(String) String +# define _s(String, Plural, Quantity) ((Quantity) == 1 ? String : Plural) +#else +# include +# define _(String) dgettext(PACKAGE, String) +# define _s(String, Plural, Quantity) \ + dngettext(PACKAGE, String, Plural, (Quantity)) +#endif -// Used to mark string for gettext -# define N_(Str) Str -# define N_s(Str, Pl) {Str, Pl} +/* Used to mark string for gettext */ +#define N_(Str) Str +#define N_s(Str, Pl) { Str, Pl } void init_i18n(void); diff --git a/test/alloc.cc b/test/alloc.cc index 2d8366f..2374865 100644 --- a/test/alloc.cc +++ b/test/alloc.cc @@ -11,6 +11,7 @@ struct Obj { Test(alloc, object) { Obj *o = criterion::new_obj(42, 314); + cr_assert_not_null(o); cr_assert_eq(o->foo, 42); @@ -21,11 +22,12 @@ Test(alloc, object) { Test(alloc, array) { Obj *o = criterion::new_arr(3); + cr_assert_not_null(o); - new (&o[0]) Obj(1, 2); - new (&o[1]) Obj(2, 4); - new (&o[2]) Obj(3, 6); + new (&o[0])Obj(1, 2); + new (&o[1])Obj(2, 4); + new (&o[2])Obj(3, 6); for (int i = 0; i < 3; ++i) { cr_assert_eq(o[i].foo, i + 1); diff --git a/test/asprintf.c b/test/asprintf.c index f709bd0..5ad9ca3 100644 --- a/test/asprintf.c +++ b/test/asprintf.c @@ -24,27 +24,28 @@ struct format_test { union anyval *val; }; -# define VALUE(Fmt, Val) &(struct format_test) { .format = "%" #Fmt, .val = &(union anyval) { . Fmt = Val } } +#define VALUE(Fmt, Val) & (struct format_test) { .format = "%" #Fmt, .val = &(union anyval) { .Fmt = Val } } TheoryDataPoints(asprintf, valid) = { DataPoints(struct format_test *, - VALUE(c, 'a'), - VALUE(hd, 42), - VALUE(d, 42), - VALUE(ld, 42), - VALUE(lld, 42), - VALUE(hu, 42), - VALUE(u, 42), - VALUE(lu, 42), - VALUE(llu, 42), - VALUE(f, 3.14), - VALUE(s, "foo"), - VALUE(p, NULL), - ), + VALUE(c, 'a'), + VALUE(hd, 42), + VALUE(d, 42), + VALUE(ld, 42), + VALUE(lld, 42), + VALUE(hu, 42), + VALUE(u, 42), + VALUE(lu, 42), + VALUE(llu, 42), + VALUE(f, 3.14), + VALUE(s, "foo"), + VALUE(p, NULL), + ), }; Theory((struct format_test *fmt), asprintf, valid) { char expected[32]; + snprintf(expected, sizeof (expected), fmt->format, *fmt->val); char *actual; diff --git a/test/ordered-set.c b/test/ordered-set.c index 92a4d28..1c9ab1f 100644 --- a/test/ordered-set.c +++ b/test/ordered-set.c @@ -3,13 +3,17 @@ #include "criterion/criterion.h" #include "criterion/internal/ordered-set.h" -int compare_gt(void *a, void *b) { +int compare_gt(void *a, void *b) +{ int *ia = a, *ib = b; + return *ia == *ib ? 0 : (*ia > *ib ? -1 : 1); } -int compare_lt(void *a, void *b) { +int compare_lt(void *a, void *b) +{ int *ia = a, *ib = b; + return *ia == *ib ? 0 : (*ia < *ib ? -1 : 1); } diff --git a/test/redirect.cc b/test/redirect.cc index 1090556..279fad2 100644 --- a/test/redirect.cc +++ b/test/redirect.cc @@ -3,7 +3,7 @@ #include #include -// set a timeout for I/O tests +/* set a timeout for I/O tests */ TestSuite(redirect, .timeout = 1); #if __GNUC__ >= 5 @@ -21,22 +21,22 @@ Test(redirect, mock) { #endif Test(redirect, mock_c) { - std::FILE* fmock = cr_mock_file_size(4096); + std::FILE *fmock = cr_mock_file_size(4096); std::fprintf(fmock, "Hello"); std::fflush(fmock); std::rewind(fmock); - char contents[sizeof ("Hello")] = {0}; + char contents[sizeof ("Hello")] = { 0 }; fgets(contents, sizeof (contents), fmock); cr_assert_str_eq(contents, "Hello"); } Test(redirect, assertions) { - std::FILE* f1 = cr_mock_file_size(4096); - std::FILE* f2 = cr_mock_file_size(4096); - std::FILE* f3 = cr_mock_file_size(4096); + std::FILE *f1 = cr_mock_file_size(4096); + std::FILE *f2 = cr_mock_file_size(4096); + std::FILE *f3 = cr_mock_file_size(4096); fprintf(f1, "Foo"); fprintf(f2, "Foo"); @@ -76,7 +76,8 @@ Test(redirect, stderr_) { } Test(redirect, stdin_) { - auto& f_cin = criterion::get_redirected_cin(); + auto &f_cin = criterion::get_redirected_cin(); + f_cin << "Foo"; f_cin.close();