Compare commits

...
Sign in to create a new pull request.

85 commits

Author SHA1 Message Date
5b0f2b1290 create nanomsg sockets in /var/lib by default 2016-09-27 21:20:37 -04:00
Snaipe
69a05ded6d doc: Fixed wrong usage of parameterized test arrays 2016-09-27 18:52:48 +02:00
Snaipe
4e0ee1a319 theories: Fixed leak in theory context destruction 2016-09-24 21:16:35 +02:00
Snaipe
932b943cd2 cli: Fixed --no-early-exit falling through to --use-ascii 2016-09-24 21:14:49 +02:00
Snaipe
faaae85b80 cram,osx: Fixed mismatch in getopt diagnostic 2016-09-24 20:32:12 +02:00
Snaipe
182a66bc43 ubsan: Fixed shift overflow on signed int 2016-09-24 14:16:14 +02:00
Snaipe
e0ea52e60d cram: Added test for invalid CLI flags 2016-09-24 14:08:15 +02:00
Snaipe
f8107d221e params: Fixed unknown flags implying --crash. Fixes #166 2016-09-24 14:01:48 +02:00
Snaipe
2d6959d777 contrib: Added autotools skeleton 2016-09-24 00:51:49 +02:00
Snaipe
12691f094c travis: Use the default python installation for cram 2016-09-23 17:23:24 +02:00
Snaipe
20d8b5a4fd authors: Added AUTHORS file 2016-09-22 13:03:40 +02:00
Snaipe
20a9da7c18 changelog: Added the parameter change to the custom logger provider API 2016-09-21 13:57:25 +02:00
Snaipe
4093cfa0d6 context: Inherit criterion_options in the test sandbox. Fixes #164. 2016-09-21 13:49:19 +02:00
Snaipe
a9df7911d6 release: Prepare a release candidate for 2.3.0 2016-09-19 00:21:17 +02:00
Snaipe
e864f3dbf2 boxfort,windows: Fixed arena mapping errors. Fixes #149. 2016-09-18 21:45:57 +02:00
Snaipe
e9ef474878 doc: Added note regarding abort in hooks. Addresses partially #163 2016-09-17 12:30:34 +02:00
Snaipe
bf23bb82de boxfort: Fixed hangs on windows 2016-09-16 20:22:46 +02:00
Snaipe
4c15e137bc boxfort: Updated for compilation issues 2016-09-16 19:21:18 +02:00
Snaipe
56c5fea2fc debug: Fixed debugger value passed to boxfort 2016-09-16 17:28:09 +02:00
Snaipe
66556c8cdb debug: Added support for --debug=idle. Fixes #154. 2016-09-16 17:15:47 +02:00
Snaipe
0507dfcf50 licence: Added missing license header on io/output.c 2016-09-14 11:50:15 +02:00
Snaipe
301d143ea4 elf,section: Fixed section code interpreting all empty names as the current executable
This was causing crashes with eglibc which visits the loaded vdso with
an empty dlpi_name.
2016-09-14 01:23:08 +02:00
Snaipe
c48ffae4de mach-o,section: Fixed compilation errors 2016-09-14 00:47:29 +02:00
Snaipe
731991fc18 hooks: Append diffs with tee rather than overwrite them 2016-09-13 23:38:49 +02:00
Snaipe
1c11db55ae section: Added deep section inspection.
This allows loaded dynamic libraries to further provide default hooks,
suites, or even tests.

Fixes #160.
2016-09-13 23:35:57 +02:00
Snaipe
8c840a8fd2 boxfort: Fixed windows builds 2016-09-13 13:21:40 +02:00
Snaipe
6d5fe5a6e1 dyncall: Fixed -fPIC warnings on windows and CXX requirement
Fixes #159.
2016-09-13 12:56:20 +02:00
Kevin Locke
ba2c09e192 section: Close FD in open_module_self on error
If open_module_map encounters an error, open_module_self would return 0
while leaving the file descriptor open.  Since close_module does not
validate the state of the mod_handle, callers can't know whether to call
close_module when this occurs.

Resolve this by closing the file descriptor before returning so that
mod_handle is never partially open.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-09-12 21:03:30 -06:00
Kevin Locke
7581417dfa section: Call close_module for open_module_self
Commit a3df2ab abstracted the section handling into several functions.
For ELF, the newly created open_module_self opens a file descriptor to
the executable file which should be closed from close_module.  The
close_module call is missing in report.c and runner.c, causing EMFILE
errors during test runs when the available file descriptors are
exhausted.  This commit fixes the issue.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-09-12 20:53:08 -06:00
Snaipe
39c14abdcc boxfort: Updated submodule 2016-09-11 21:09:57 +02:00
Snaipe
696e648efe i18n: Fixed remaining positional arguments in non-localized strings 2016-09-10 13:03:27 +02:00
Snaipe
0d2521b279 travis,stylecheck: Fixed missing fi error 2016-09-10 11:12:10 +02:00
Kevin Locke
07c380d6b7 asserts: Add assertions for wide strings
This commit creates _wcs_ variants of the _str_ assertions for operating
on wchar_t * instead of char *.  The assertions are useful for programs
using wchar_t strings, particularly on Windows where use of the wide
character version of the Windows API is encouraged by Microsoft.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-09-10 08:48:30 +02:00
Snaipe
59ed78c4a2 githooks: Fixed precommit hook not producing good patches 2016-09-10 08:47:37 +02:00
Snaipe
ca965d3db9 section,elf: Fixed missing ElfW definition on FreeBSD. Fixes #156 2016-09-10 08:47:24 +02:00
Snaipe
bb61aef765 version,readme: Fixed broken version badge 2016-09-07 10:43:08 +02:00
ailu
1e28ad1277 fix: set criterion_options.debug to CR_DBG_NATIVE
criterion_options.debug was not set if no argument was given. According
to the docs the native debugger should used, so this member has to be
set to CR_DBG_NATIVE
2016-09-06 22:01:03 +02:00
Snaipe
cfd3212a4a sample,asserts: Fixed wrong usage of cr_assert_arr_eq_cmp in C++ 2016-09-06 20:56:42 +02:00
Snaipe
c5bfe03733 section: Resolve /proc/self/exe for compatibility with introspection tools like valgrind 2016-09-06 20:03:36 +02:00
Snaipe
fc2cf1f9d2 version: bumped version to 2.3.0-dev 2016-09-06 19:11:16 +02:00
Snaipe
c99827489a bumpversion: include rc & dev suffixes 2016-09-06 19:08:03 +02:00
Snaipe
d83dbb60cf Revert "cmake: Build libcriterion.so as an executable PIE"
This reverts commit 8959dfa83f.
2016-09-06 18:23:04 +02:00
Snaipe
fcc3d92d5d version: Fixed reported version 2016-09-06 18:23:04 +02:00
ailu
44849f9ea4 doc: fixed debug-transport arguments 2016-09-06 18:11:03 +02:00
Snaipe
50d0a20e5e travis: Fixed spurious fi as reported 2016-09-06 18:08:27 +02:00
Snaipe
02bb993419 po: Updated line counts 2016-09-06 18:03:41 +02:00
Snaipe
8959dfa83f cmake: Build libcriterion.so as an executable PIE 2016-09-06 18:02:38 +02:00
Snaipe
b29e662432 contributing: Added bit on commit messages 2016-09-06 11:02:08 +02:00
Snaipe
d886913438 cram: Fixed line counts 2016-09-06 10:50:28 +02:00
Snaipe
c299b8dd85 style: Fixed (A) Op (B) formatting taking 'Op' as a function rather than an operator 2016-09-06 10:49:10 +02:00
Snaipe
314c15fd9b travis,style: Only run the style check on PRs 2016-09-05 22:47:19 +02:00
Snaipe
64c0e1f501 contributing: Updated to reflect the style check 2016-09-05 22:24:25 +02:00
Snaipe
fff1d0a168 style: Make uncrustify silent 2016-09-05 22:13:23 +02:00
Snaipe
f32a46694a style: Use 'internal' rather than '<internal>' for API macro implementations 2016-09-05 22:09:25 +02:00
Snaipe
48650f965c travis: Added style check 2016-09-05 22:04:34 +02:00
Snaipe
d2a4124b87 style: Added and enforce uncrustify config 2016-09-05 21:32:57 +02:00
Snaipe
ec7cbe2a18 style: disable indent for delicate places 2016-09-05 20:45:46 +02:00
Snaipe
f72ffff3ca style: ignore style for coroutine macros 2016-09-05 15:12:25 +02:00
Snaipe
033bac0c5e style: disable indent for delicate places 2016-09-05 14:36:00 +02:00
Snaipe
bae428393a cmake: Fixed missing include 2016-09-05 13:50:02 +02:00
Snaipe
8d8731053d cram: Updated tests for cr_skip_test() strings 2016-09-05 10:22:03 +02:00
Snaipe
bd4760582f timeout: Fixed --timeout always overriding 2016-09-05 10:20:23 +02:00
ailu
fbbfcb6d61 added gdb and coverage how to
check side note of #127, addition to #114
2016-09-05 10:08:52 +02:00
ailu
91250fed74 Fixed output of skipped tests 2016-09-05 10:04:10 +02:00
Snaipe
205b9a4444 cmake: Cleaned up definitions and default flags a bit 2016-09-04 22:21:20 +02:00
Snaipe
0b191be52a cram: Fixed tests for --timeout 2016-09-04 21:55:19 +02:00
Snaipe
4e1a877c66 cli: Added --timeout flag 2016-09-04 21:06:25 +02:00
Snaipe
e7ab23d67a style: removed extra semicolons 2016-09-04 20:50:58 +02:00
Snaipe
9a68415eb2 cram: Fixed tests to account for time 2016-09-04 12:19:56 +02:00
Snaipe
553869aa5c cmake: Fixed uninstall rule not removing symlinks 2016-09-04 11:35:26 +02:00
Snaipe
bbd5fab174 cmake: Added uninstall rule 2016-09-04 11:27:21 +02:00
Snaipe
da7df99bff cli: Fixed unused variable error 2016-09-04 11:25:41 +02:00
Snaipe
24f0d34eda cli: Fixed leak with dbg parameter parsing 2016-09-04 11:10:40 +02:00
Snaipe
0a0574cb59 cli: Fixed handling of bad arguments 2016-09-04 11:08:39 +02:00
Snaipe
f0cfc6d18d cli: Fixed parsing for --debug-transport 2016-09-04 11:08:10 +02:00
Snaipe
7aa0b1c5ce runtime: Fixed timestamps not being reported. Fixes #116 2016-09-04 10:38:05 +02:00
Snaipe
63d0bc8a4e boxfort: Updated for PID mismatch fix in debug mode 2016-09-04 09:38:14 +02:00
ailu
7143118b5c api: added cr_skip_test()
Added cr_skip_test to skip a test during runtime. Also merged the old
disable system with the new one. All skipped tests are printed by
normal_log_post_suite(), so there is no need for a logger function for
runtime skipepd tests.
Fixes #131.
2016-09-03 23:06:35 +02:00
Snaipe
a3df2ab9a4 section: introspect sections without linker extensions. Fixes #91 2016-09-03 21:55:32 +02:00
Snaipe
8882c7d9cc api,logging: Fixed placement of CR_FORMAT attribute on cr_log 2016-09-03 18:55:09 +02:00
Snaipe
32fea80b7d api: Don't use free directly with cr_asprintf. Fixes #87 2016-09-03 08:33:34 -07:00
Snaipe
9b88f244b6 travis: Added timeout to ctest 2016-09-03 16:52:08 +02:00
Snaipe
0d10c7d6c5 travis: remove Release builds as they are the same as RelWithDebInfo optimization-wise 2016-09-03 16:51:36 +02:00
Snaipe
d6b95f93b6 cram: Fixed MSYS2 expanding patterns as paths 2016-09-03 16:48:46 +02:00
Snaipe
8b62ac51b0 Merge branch 'features/boxfort-sandboxing' into bleeding
Fixes #132, fixes #129, fixes #85
2016-09-03 16:44:12 +02:00
182 changed files with 6288 additions and 4115 deletions

View file

@ -1,6 +1,25 @@
[bumpversion]
current_version = 2.2.2
current_version = 2.3.0-rc1
commit = False
parse = ^
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+) # minimum 'N.N.N'
(?:
-(?P<prerel>\w+) # 'rc' = release candidate, 'dev' = dev branch
(?:
(?P<prerelversion>\d+)
)?
)?
serialize =
{major}.{minor}.{patch}-{prerel}{prerelversion}
{major}.{minor}.{patch}-{prerel}
{major}.{minor}.{patch}
[bumpversion:part:prerel]
optional_value = release
values =
dev
rc
release
[bumpversion:file:.cmake/Modules/Properties.cmake]

View file

@ -5,6 +5,7 @@
include(CheckPrototypeDefinition)
include(CheckLibraryExists)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(PackageUtils)
# Check for packages
@ -23,13 +24,25 @@ endif ()
check_function_exists(strtok_s HAVE_STRTOK_S)
check_function_exists(strtok_r HAVE_STRTOK_R)
check_library_exists (rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
check_library_exists (anl getaddrinfo_a "" HAVE_GETADDRINFO_A)
check_function_exists(funopen HAVE_FUNOPEN)
check_function_exists(fopencookie HAVE_FOPENCOOKIE)
check_function_exists(open_memstream HAVE_OPEN_MEMSTREAM)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_RT)
if (HAVE_CLOCK_GETTIME_RT AND NOT HAVE_LIBRT)
set (HAVE_LIBRT 1)
endif ()
if (NOT HAVE_CLOCK_GETTIME_RT)
check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
else ()
set (HAVE_CLOCK_GETTIME "${HAVE_CLOCK_GETTIME_RT}" CACHE INTERNAL "Have symbol clock_gettime")
endif ()
check_symbol_exists(CLOCK_MONOTONIC_RAW "time.h" HAVE_CLOCK_MONOTONIC_RAW)
# Check for C++11
if (LANG_CXX)

View file

@ -28,6 +28,7 @@ set(ENV{CRITERION_ALWAYS_SUCCEED} "1")
set(ENV{CRITERION_SHORT_FILENAME} "1")
set(ENV{CRITERION_JOBS} "1")
set(ENV{CRITERION_DISABLE_TIME_MEASUREMENTS} "1")
set(ENV{MSYS2_ARG_CONV_EXCL} "--filter=")
if (WIN32)
if (ENV{MINGW} STREQUAL "")
@ -49,7 +50,7 @@ if ("$ENV{TRAVIS}" STREQUAL "true")
execute_process (COMMAND cram -v ${CRAM_OPTS} "${CRAM_PATH}" TIMEOUT 60 RESULT_VARIABLE RES)
else ()
if ("$ENV{PYTHON_BIN}" STREQUAL "")
set (PYTHON "python3")
set (PYTHON "python")
else ()
set (PYTHON "$ENV{PYTHON_BIN}")
endif ()

View file

@ -2,9 +2,9 @@
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the LICENSE file distributed with Criterion.
set (PROJECT_VERSION "2.2.1")
set (PROJECT_VERSION "2.3.0-rc1")
set (PROJECT_SOVERSION 3)
set (PROJECT_SONAME 3.0.0)
set (PROJECT_SONAME 3.1.0)
set (LOCALEDIR_REL "share/locale")
set (LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${LOCALEDIR_REL}")
@ -21,14 +21,17 @@ set (CMAKE_CXX_FLAGS_DEFAULT "${CMAKE_CXX_FLAGS}")
if (MSVC)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
add_definitions (-D_CRT_SECURE_NO_WARNINGS=1)
add_definitions (-DVC_EXTRALEAN)
add_definitions (-DWIN32_LEAN_AND_MEAN)
add_definitions (-D_WIN32_WINNT=0x600)
else ()
if (WIN32)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-no-undefined")
endif ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99 -fvisibility=hidden")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=gnu99 -fvisibility=hidden")
if (CMAKE_CXX_COMPILER_WORKS)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -g ${CXX11_FLAG} -fvisibility=hidden")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ${CXX11_FLAG} -fvisibility=hidden")
endif ()
endif ()

View file

@ -1,23 +1,19 @@
set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt")
if(NOT EXISTS ${MANIFEST})
message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'")
message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'")
endif()
file(STRINGS ${MANIFEST} files)
foreach(file ${files})
if(EXISTS ${file})
message(STATUS "Removing file: '${file}'")
exec_program(
${CMAKE_COMMAND} ARGS "-E remove ${file}"
OUTPUT_VARIABLE stdout
RETURN_VALUE result
)
if(NOT "${result}" STREQUAL 0)
message(FATAL_ERROR "Failed to remove file: '${file}'.")
endif()
else()
MESSAGE(STATUS "File '${file}' does not exist.")
endif()
endforeach(file)
message(STATUS "Removing file: '${file}'")
exec_program(
${CMAKE_COMMAND} ARGS "-E remove ${file}"
OUTPUT_VARIABLE stdout
RETURN_VALUE result
)
if (NOT "${result}" STREQUAL 0)
message(FATAL_ERROR "Failed to remove file: '${file}'.")
endif ()
endforeach ()

View file

@ -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"
}

4
.githooks/install.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
rm -Rf .git/hooks
ln -s ../.githooks .git/hooks

171
.githooks/pre-commit Executable file
View file

@ -0,0 +1,171 @@
#!/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"
diff="/tmp/$prefix-$suffix.diff"
# 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" -q -c "$CONFIG" -f "$file" $language_option | \
git --no-pager diff --color=always --no-index -- "$file" - | \
tail -n +3 | \
sed -e "1s|--- a/$file_escaped_source|--- \"a/$file_escaped_target\"|" \
-e "2s|+++ b/-|+++ \"b/$file_escaped_target\"|" | \
tee -a "$diff" | \
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" >> "$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 "$diff"
rm -f "$diff"
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

View file

@ -2,21 +2,12 @@ language: c
sudo: false
addons:
apt:
sources:
- deadsnakes
packages:
- python3.5
_anchors:
- &gcc49-packages
apt:
sources:
- ubuntu-toolchain-r-test
- deadsnakes
packages:
- python3.5
- gcc-4.9
- g++-4.9
- gobjc-4.9
@ -24,6 +15,42 @@ _anchors:
matrix:
include:
# Style check
- compiler: uncrustify
language: cpp
before_install:
- if [[ "$TRAVIS_PULL_REQUEST" == false ]]; then exit 0; fi
- |
git clone https://github.com/uncrustify/uncrustify /tmp/uncrustify &&
pushd /tmp/uncrustify &&
git checkout -q 7ae7af9d3483f5f92766ec41bb3ba3efe4747494 &&
mkdir build && cd build &&
CC=gcc CXX=g++ cmake -DCMAKE_INSTALL_PREFIX=$HOME .. &&
make -j4 && make install &&
export PATH="$PATH:$HOME/bin" &&
popd
- >
export SOURCES=$(find src include test samples \( \
-type f \( \
-iname "*.c" -or \
-iname "*.h" -or \
-iname "*.cc" -or \
-iname "*.hxx" \
\) -and -not \
-iname "*.pb.*" \))
- export STYLE_OK=true
script:
- >
for f in $SOURCES; do
if ! uncrustify -q --check -c .uncrustify.cfg $f; then
uncrustify -q -c .uncrustify.cfg -f $f | git --no-pager diff --no-index --color=always $f -
export STYLE_OK=false
fi
done
- $STYLE_OK
after_success:
- echo "Style check passed."
# Linux Debug, GCC 4.9
- compiler: gcc-4.9
addons: *gcc49-packages
@ -31,11 +58,6 @@ matrix:
CONFIGURATION: Debug
GCOV: gcov-4.9
COVERAGE: "ON"
# Linux Release, GCC 4.9
- compiler: gcc-4.9
addons: *gcc49-packages
env:
CONFIGURATION: Release
# Linux RelWithDebInfo, GCC 4.9
- compiler: gcc-4.9
addons: *gcc49-packages
@ -45,9 +67,6 @@ matrix:
# Linux Debug, GCC 4.6
- compiler: gcc
env: CONFIGURATION=Debug TESTS=OFF
# Linux Release, GCC 4.6
- compiler: gcc
env: CONFIGURATION=Release TESTS=OFF
# Linux RelWithDebInfo, GCC 4.6
- compiler: gcc
env:
@ -66,10 +85,6 @@ matrix:
CONFIGURATION: Debug
GCOV: gcov-4.9
COVERAGE: "ON"
# OSX Release, GCC 4.9
- os: osx
compiler: gcc-4.9
env: CONFIGURATION=Release
# OSX RelWithDebInfo, GCC 4.9
- os: osx
compiler: gcc-4.9
@ -79,11 +94,6 @@ matrix:
compiler: clang
env:
CONFIGURATION: Debug
# OSX Release, Clang
- os: osx
compiler: clang
env:
CONFIGURATION: Release
# OSX RelWithDebInfo, Clang
- os: osx
compiler: clang
@ -98,16 +108,9 @@ before_install:
- |
if [ "${TESTS:-ON}" = "ON" ]; then
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
travis_retry brew install python3
export PATH="$(python3 -m site --user-base)/bin:$PATH"
export PYTHON_BIN="python3"
travis_retry pip3 install cram==0.7
else
travis_retry curl -LO https://bootstrap.pypa.io/get-pip.py
travis_retry python3.5 get-pip.py --user
export PYTHON_BIN="python3.5"
travis_retry pip3 install --user cram==0.7
export PATH="$(python -m site --user-base)/bin:$PATH"
fi
travis_retry pip install --user cram==0.7
fi
- export CXX=${CC/gcc/g++}; export CXX=${CXX/clang/clang++}
- $CC --version
@ -127,7 +130,7 @@ script:
- |
if [ "${TESTS:-ON}" = "ON" ]; then
TERM=dumb cmake --build . --target criterion_tests -- -j4
ctest --output-on-failure -j4
ctest --output-on-failure -j4 --timeout=20
else
TERM=dumb cmake --build . -- -j4
fi

239
.uncrustify.cfg Normal file
View file

@ -0,0 +1,239 @@
#
# 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 compare Op # typical (A) Op (B) macro scenarios
set func_call_user _ N_ # gettext macros
set attribute CR_FORMAT CR_API CR_PURE CR_INLINE

14
AUTHORS Normal file
View file

@ -0,0 +1,14 @@
Maintainer:
* Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
Contributors:
* Adeel "am11" Mujahid <adeelbm@outlook.com>
* Matthias "ailu" Günzel <a1lu@arcor.de>
* Ben "blinskey" Linskey <ben@benlinskey.com>
* "kaidowei" <kaidowei@users.noreply.github.com>
* Howard "hppritcha" Pritchard <howardp@lanl.gov>
* Kevin "kevinoid" Locke <kevin@kevinlocke.name>
* László "MrAnno" Várady <laszlo.varady@balabit.com>
* "offa" <bm-dev@yandex.com>

View file

@ -39,6 +39,7 @@ cr_add_subproject (csptr PATH dependencies/libcsptr
cr_add_subproject (dyncall_s PATH dependencies/dyncall
OPTS
-DLANG_CXX=${LANG_CXX}
"-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} ${PIC_C_FLAGS} ${VISI_C_FLAGS}"
CMAKE IF THEORIES)
@ -113,7 +114,7 @@ cr_link_subproject(criterion wingetopt STATIC)
cr_link_subproject(criterion boxfort STATIC)
cr_link_libraries(criterion pthread IF NOT WIN32)
cr_link_libraries(criterion rt IF HAVE_CLOCK_GETTIME)
cr_link_libraries(criterion rt IF HAVE_LIBRT)
# Required by nanomsg
cr_link_libraries(criterion anl IF HAVE_GETADDRINFO_A)
@ -132,6 +133,10 @@ if (COVERALLS)
)
endif()
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
)
if (CTESTS)
enable_testing()
add_custom_target(criterion_tests)

View file

@ -7,18 +7,39 @@ be merged.
## General
* Use 4 (four) spaces for indentation.
* No trailing whitespaces.
* 80 chars column limit.
* Try to respect a 80 chars column limit. Not mandatory, but appreciated.
* No trash files. Trash files are by-products of the compilation process, or
generated files that does not need to be under version control.
* Pull requests must pass the style check. See "Passing the style check" section below.
* Pull requests must compile and work properly.
* Pull requests must pass all tests.
* Pull requests must be mergeable automatically.
* Pull requests must be mergeable without conflicts.
* Number of commits in a pull request should be kept to one commit and all
additional commits must be squashed.
* You may have more than one commit in a pull request if the commits are
separate changes, otherwise squash them.
* Keep your commit messages simple and concise. Good commit messages start
with a verb ('Add', 'Fix', ...).
* Commit messages should follow the format `topic: message`, e.g. `cli: Added --foo flag`.
In cases where multiple topics are relevant, use a comma-separated list of topics, e.g.
`api,float: Fixed printf format specifiers for long double`
## Passing the style check
This project use an automated style checking process for pull requests defined as
an uncrustify configuration file named `.uncrustify.cfg`.
To ease the development process, a pre-commit hook is installable by running
`.githooks/install.sh` from the project root directory. This pre-commit hook
checks for style, outputs a diff of the changes that need to be done, and
produces a patch to fix them automatically.
As the automatic style checker is bound to have errors, parts of the code
that make the checker fail because of their tricky grammar (e.g. Duff devices)
may be enclosed by `/* *INDENT-OFF* */` and `/* *INDENT-ON* */` to disable
the style checker on the region. Note that this feature should be used
*exceptionally*, and that the maintainer will always have the last word regarding
stylistic choices that cannot pass the style check.
## Translations

View file

@ -1,3 +1,38 @@
2018-09-18 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
* criterion: version 2.3.0
* Addition: added German translation files (Matthias "ailu" Günzel).
* Addition: added a pkg-config file.
* Addition: allow tests to be skipped with cr_skip_test() (Matthias "ailu" Günzel).
* Addition: assertions on wide-strings are now available (Kevin "kevinoid" Locke).
* Addition: crash-mode with --crash to raise a trap when an assertion fails for debugging purposes (Matthias "ailu" Günzel).
* Addition: debugging mode with --debug.
* Addition: global test timeout with --timeout.
* Addition: header files in the public API now have doxygen documentation (Matthias "ailu" Günzel).
* Addition: test filtering now works on windows.
* Addition: user logging API with cr_log, cr_log_info, cr_log_warning, and cr_log_error.
* Breaking: dropped support for MinGW, use MinGW-w64.
* Breaking: dropped support for Windows XP, use Windows 7 and later.
* Breaking: log_pre_init and log_pre_test in the internal logger API now takes an additional parameter.
* Breaking: the SOVERSION now follows the SONAME major independently of the project version.
* Change: --pattern has been renamed to --filter.
* Change: removed dependency on PCRE for filtering (Matthias "ailu" Günzel).
* Change: sections of all loaded shared modules are now inspected for tests and hooks.
* Change: setting .exit_code = 0 now enforces the exit code of the test to be 0.
* Change: string assertions now print the contents of string parameters ("kaidowei").
* Change: tests are no longer executed in parallel on windows by default to mitigate a nanomsg bug (see https://github.com/Snaipe/Criterion/issues/118).
* Change: xml reports now includes elapsed times ("kaidowei").
* Deprecation: --no-early-exit is now a no-op and should no longer be used.
* Deprecation: internal logging API is no longer public, fallbacks to the new logging API.
* Fix: fail-fast now works correctly.
* Fix: fixed FindCriterion.cmake with the correct package name (László "MrAnno" Várady).
* Fix: position-independent executables now work.
* Fix: string assertions no longer crash with a NULL parameter ("kaidowei").
* Fix: the data pipe no longer gets corrupted when running a large quantity of assertions in parallel.
* Fix: using dmalloc on tests now works.
* Fix: using the GOLD linker rather than BFD now works.
* Fix: using the musl C library now works.
2016-06-20 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
* criterion: version 2.2.2

View file

@ -6,7 +6,7 @@
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/Snaipe/Criterion?svg=true&branch=bleeding)](https://ci.appveyor.com/project/Snaipe/Criterion/branch/bleeding)
[![Coverage Status](https://img.shields.io/codecov/c/github/Snaipe/Criterion/bleeding.svg)](https://codecov.io/github/Snaipe/Criterion?branch=bleeding)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/Snaipe/Criterion/blob/master/LICENSE)
[![Version](https://img.shields.io/badge/version-v2.2.1-blue.svg?style=flat)](https://github.com/Snaipe/Criterion/releases)
[![Version](https://img.shields.io/badge/version-v2.3.0--rc1-blue.svg?style=flat)](https://github.com/Snaipe/Criterion/releases)
A dead-simple, yet extensible, C and C++ unit testing framework.
@ -78,6 +78,7 @@ Sample tests can be found in the [sample directory][samples].
### Misc
* [autotools skeleton for projects with criterion tests][autotools]
* [CMake find module for Criterion][find-module]
## Credits
@ -97,6 +98,7 @@ Logo made by [Paul Bouigue](http://www.cargocollective.com/pbouigue)
[sample-signal]: ./samples/signal.c
[sample-report]: ./samples/report.c
[autotools]: ./dev/autotools
[find-module]: ./dev/FindCriterion.cmake
[irc-chan]: http://webchat.freenode.net/?channels=%23criterion&uio=MTY9dHJ1ZSYyPXRydWUmOT10cnVlJjExPTE5NQ4e

View file

@ -1,4 +1,4 @@
version: 2.2.2_b{build}-{branch}
version: 2.3.0-rc1_b{build}-{branch}
os: Visual Studio 2015

@ -1 +1 @@
Subproject commit 666fdd42d7552d0144db0ef27f49cf9c3fb19999
Subproject commit 9f7ba3716c800a53639c9fe68fd453296f982c99

@ -1 +1 @@
Subproject commit 180a5b77ff95a17991afdc6e9be3501eca99ad36
Subproject commit 51e79a84fd91881d7424b28271c6dda4e0d97c11

14
dev/autotools/Makefile.am Normal file
View file

@ -0,0 +1,14 @@
# use the provided wrapper script to output things properly
LOG_COMPILER = $(top_srcdir)/build-aux/criterion-tap-test
# use the TAP log driver
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/build-aux/tap-driver.sh
check_PROGRAMS = criterion_tests
criterion_tests_SOURCES = simple.c
criterion_tests_LDFLAGS = -lcriterion
TESTS = criterion_tests
EXTRA_DIST = $(TESTS)

27
dev/autotools/README.md Normal file
View file

@ -0,0 +1,27 @@
# Autotools skeleton
This is a project skeleton that uses criterion tests with the TAP test driver.
## Running the tests
The default setup assumes that criterion is installed on your system.
```
$ ./autogen.sh
$ mkdir build && cd build
$ ../configure
$ make check
```
## License
The project skeleton is licensed under the [wtfpl](http://www.wtfpl.net). Do
whatever you want with it.
### License clause
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://www.wtfpl.net/ for more details.

17
dev/autotools/autogen.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh -e
# copy TAP driver into build-aux
automake_ver=$(automake --version | \grep -E -o '[0-9]\.[0-9]{2}')
mkdir -p build-aux
cp -f /usr/share/automake-$automake_ver/tap-driver.sh build-aux
# create criterion TAP log compiler
# this is necessary to print TAP (and only TAP) on the standard output,
# and always exit with 0 to let the TAP driver handle errors itself.
echo >build-aux/criterion-tap-test """#!/bin/sh
\$1 -Otap:- --always-succeed 2>&1 >/dev/null
"""
chmod +x build-aux/criterion-tap-test
autoreconf -vi

View file

@ -0,0 +1,15 @@
AC_INIT([Criterion Autotools Tests], [1.0], [your@email.com])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_CHECK_LIB([criterion], [criterion_initialize], [], [
AC_MSG_ERROR([unable to find Criterion])
], [])
AC_PROG_AWK
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_REQUIRE_AUX_FILE([tap-driver.sh])
AC_OUTPUT

9
dev/autotools/simple.c Normal file
View file

@ -0,0 +1,9 @@
#include <criterion/criterion.h>
Test(misc, failing) {
cr_assert(0);
}
Test(misc, passing) {
cr_assert(1);
}

View file

@ -29,6 +29,11 @@ String Assertions
.. doxygengroup:: StringAsserts
Wide String Assertions
----------------------
.. doxygengroup:: WideStringAsserts
Array Assertions
-----------------

View file

@ -54,7 +54,7 @@ copyright = u'2015-2016, Franklin "Snaipe" Mathieu'
# built documents.
#
# The short X.Y version.
version = '2.2.2'
version = '2.3.0-rc1'
# The full version, including alpha/beta/rc tags.
release = version

61
doc/debug.rst Normal file
View file

@ -0,0 +1,61 @@
Debugging and Coverage information
==================================
.. _gdb-ref:
Debugging with GDB
------------------
In one terminal do:
.. code-block:: bash
$ ./simple.c.bin --debug
Process simple.c.bin created; pid = 20803
Listening on port 1234
In another terminal connect to this debug session:
.. code-block:: bash
$ gdb -q ./test
Reading symbols from ./test...done.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x00007ffff7dd9d90 in _start() from target:/lib64/ld-linux-x86-64.so.2
(gdb) continue
...
[Inferior 1 (process 25269) exited normally]
(gdb) q
After ``continue`` the first test is run:
.. code-block:: bash
Remote debugging from host 127.0.0.1
[RUN ] misc::failing
[----] /media/data/devel/Criterion/samples/simple.c:4: Assertion failed: The expression 0 is false.
[FAIL] misc::failing: (0,00s)
Child exited with status 0
And a new process is created for the next test:
.. code-block:: bash
Process /media/data/devel/Criterion/build/samples/simple.c.bin created; pid = 26414
Listening on port 1234
Connect your remote debugger to this test with ``remote target localhost:1234``
and run the test with ``continue``
To use a different port use ``--debug --debug-transport=<protocol>:<port>``
.. _coverage-ref:
Coverage of Criterion tests
---------------------------
To use gcov, you have to compile your tests with the two GCC Options
``-fprofile-arcs`` and ``ftest-coverage``.

View file

@ -17,9 +17,17 @@ A report hook can be declared using the ``ReportHook`` macro:
The macro takes a Phase parameter that indicates the phase at which the function
shall be run. Valid phases are described below.
**Note**: there are no guarantees regarding the order of execution of report hooks
on the same phase. In other words, all report hooks of a specific phase could
be executed in any order.
.. note::
There are no guarantees regarding the order of execution of report hooks
on the same phase. In other words, all report hooks of a specific phase could
be executed in any order.
.. note::
Aborting the runner with any means (abort(), exit(), cr_assert(), ...) is
unsupported. If you need to abort the runner, you need to iterate all
subsequent tests and set their `disabled` field to 1.
Testing Phases
--------------

View file

@ -15,4 +15,5 @@ Criterion
parameterized
theories
internal
debug
faq

View file

@ -39,6 +39,10 @@ identifier format.
``Type`` is the compound type of the generated array. ``params`` and ``nb_params``
are the pointer and the length of the generated array, respectively.
.. note::
The parameter array must be reachable after the function returns -- as
such, local arrays must be declared with `static` or dynamically allocated.
Passing multiple parameters
---------------------------
@ -57,7 +61,7 @@ easily use a struct to hold the context as a workaround:
};
ParameterizedTestParameters(suite_name, test_name) {
struct my_params params[] = {
static struct my_params params[] = {
// parameter set
};
@ -74,7 +78,7 @@ C++ users can also use a simpler syntax before returning an array of parameters:
.. code-block:: c++
ParameterizedTestParameters(suite_name, test_name) {
struct my_params params[] = {
static struct my_params params[] = {
// parameter set
};

View file

@ -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
@ -39,6 +39,13 @@ CR_BEGIN_C_API
*/
CR_API CR_NORETURN void criterion_abort_test(void);
/**
* Aborts the current test, marking it as skipped.
*
* This function does not return.
*/
CR_API CR_NORETURN void criterion_skip_test(const char *format, ...);
/**
* Continues the current test.
*

View file

@ -26,16 +26,16 @@
* @brief Test intern memory managment
*****************************************************************************/
#ifndef CRITERION_ALLOC_H_
# define CRITERION_ALLOC_H_
#define CRITERION_ALLOC_H_
# ifdef __cplusplus
# include <memory>
# include <cstddef>
#ifdef __cplusplus
# include <memory>
# include <cstddef>
using std::size_t;
# else
# include <stddef.h>
# endif
# include "internal/common.h"
#else
# include <stddef.h>
#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 <type_traits>
#ifdef __cplusplus
# include <type_traits>
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 <typename T, typename... Params>
T *new_obj(Params... params)
{
T *obj = static_cast<T *>(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<typename T, typename... Params>
T* new_obj(Params... params) {
T* obj = static_cast<T*>(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 T>
typename std::enable_if<std::is_fundamental<T>::value>::type*
new_arr(size_t len) {
void *ptr = cr_malloc(sizeof (size_t) + sizeof (T) * len);
*(reinterpret_cast<size_t*>(ptr)) = len;
T* arr = reinterpret_cast<T*>(reinterpret_cast<size_t*>(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 T>
typename std::enable_if<std::is_fundamental<T>::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<typename T>
T* new_arr(size_t len) {
void *ptr = cr_malloc(sizeof (size_t) + sizeof (T) * len);
*(reinterpret_cast<size_t*>(ptr)) = len;
*(reinterpret_cast<size_t *>(ptr)) = len;
T *arr = reinterpret_cast<T *>(reinterpret_cast<size_t *>(ptr) + 1);
return arr;
}
T* arr = reinterpret_cast<T*>(reinterpret_cast<size_t*>(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 <typename T>
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<typename T>
void delete_obj(T* ptr) {
ptr->~T();
cr_free(ptr);
}
*(reinterpret_cast<size_t *>(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<typename T>
void delete_arr(typename std::enable_if<std::is_fundamental<T>::value>::type* ptr) {
cr_free(ptr);
}
T *arr = reinterpret_cast<T *>(reinterpret_cast<size_t *>(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<typename T>
void delete_arr(T* ptr) {
size_t *ptr_ = reinterpret_cast<size_t*>(ptr);
size_t len = *(ptr_ - 1);
T* arr = reinterpret_cast<T*>(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 <typename T>
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<typename T>
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 <typename T>
void delete_arr(typename std::enable_if<std::is_fundamental<T>::value>::type *ptr)
{
cr_free(ptr);
}
template<typename U>
struct rebind {
typedef allocator<U> 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 <typename T>
void delete_arr(T *ptr)
{
size_t *ptr_ = reinterpret_cast<size_t *>(ptr);
size_t len = *(ptr_ - 1);
T *arr = reinterpret_cast<T *>(ptr_);
inline explicit allocator() {}
inline ~allocator() {}
inline explicit allocator(allocator const&) {}
template<typename U>
inline explicit allocator(allocator<U> 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 <typename T>
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<void>::const_pointer = 0) {
return reinterpret_cast<pointer>(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 <typename U>
struct rebind {
typedef allocator<U> other;
};
inline explicit allocator() {}
inline ~allocator() {}
inline explicit allocator(allocator const &) {}
template <typename U>
inline explicit allocator(allocator<U> 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<void>::const_pointer = 0)
{
return reinterpret_cast<pointer>(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_ */

View file

@ -27,11 +27,11 @@
* @brief Assertion API
*****************************************************************************/
#ifndef CRITERION_ASSERT_H_
# define CRITERION_ASSERT_H_
#define CRITERION_ASSERT_H_
# ifdef __cplusplus
# include <algorithm>
# endif
#ifdef __cplusplus
# include <algorithm>
#endif
/**
* @defgroup BaseAsserts Base assertions
@ -49,7 +49,15 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_fail(FormatString, ...) <internal>
#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.
@ -62,7 +70,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_fail(FormatString, ...) <internal>
#define cr_expect_fail(FormatString, ...) internal
/**
* Passes if Condition is true
@ -78,7 +86,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert(Condition, FormatString, ...) <internal>
#define cr_assert(Condition, FormatString, ...) internal
/**
* Passes if Condition is true
@ -93,7 +101,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect(Condition, FormatString, ...) <internal>
#define cr_expect(Condition, FormatString, ...) internal
/**
* Passes if Condition is false
@ -109,7 +117,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_not(Condition, FormatString, ...) <internal>
#define cr_assert_not(Condition, FormatString, ...) internal
/**
* Passes if Condition is false
@ -124,7 +132,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_not(Condition, FormatString, ...) <internal>
#define cr_expect_not(Condition, FormatString, ...) internal
/**@}*/
@ -150,7 +158,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_eq(Actual, Expected, FormatString, ...) <internal>
#define cr_assert_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is equal to Expected
@ -168,7 +176,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_eq(Actual, Expected, FormatString, ...) <internal>
#define cr_expect_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is not equal to Unexpected
@ -187,7 +195,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_neq(Actual, Unexpected, FormatString, ...) <internal>
#define cr_assert_neq(Actual, Unexpected, FormatString, ...) internal
/**
* Passes if Actual is not equal to Unexpected
@ -205,7 +213,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_neq(Actual, Unexpected, FormatString, ...) <internal>
#define cr_expect_neq(Actual, Unexpected, FormatString, ...) internal
/**
* Passes if Actual is less than Reference
@ -224,7 +232,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_lt(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_lt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is less than Reference
@ -242,7 +250,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_lt(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_lt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is less or equal to Reference
@ -261,7 +269,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_leq(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_leq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is less or equal to Reference
@ -279,7 +287,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_leq(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_leq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is greater than Reference
@ -298,7 +306,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_gt(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_gt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is greater than Reference
@ -316,7 +324,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_gt(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_gt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is greater or equal to Reference
@ -335,7 +343,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_geq(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_geq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is greater or equal to Reference
@ -353,7 +361,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_geq(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_geq(Actual, Reference, FormatString, ...) internal
/**@}*/
@ -376,7 +384,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_null(Value, FormatString, ...) <internal>
#define cr_assert_null(Value, FormatString, ...) internal
/**
* Passes if Value is NULL
@ -391,7 +399,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_null(Value, FormatString, ...) <internal>
#define cr_expect_null(Value, FormatString, ...) internal
/**
* Passes if Value is not NULL
@ -407,7 +415,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_not_null(Value, FormatString, ...) <internal>
#define cr_assert_not_null(Value, FormatString, ...) internal
/**
* Passes if Value is not NULL
@ -422,7 +430,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_not_null(Value, FormatString, ...) <internal>
#define cr_expect_not_null(Value, FormatString, ...) internal
/**@}*/
@ -449,7 +457,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_float_eq(Actual, Expected, Epsilon, FormatString, ...) <internal>
#define cr_assert_float_eq(Actual, Expected, Epsilon, FormatString, ...) internal
/**
* Passes if Actual is equal to Expected with a tolerance of Epsilon
@ -468,7 +476,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_float_eq(Actual, Expected, Epsilon, FormatString, ...) <internal>
#define cr_expect_float_eq(Actual, Expected, Epsilon, FormatString, ...) internal
/**
* Passes if Actual is not equal to Unexpected with a tolerance of Epsilon
@ -488,7 +496,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) <internal>
#define cr_assert_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) internal
/**
* Passes if Actual is not equal to Unexpected with a tolerance of Epsilon
@ -507,7 +515,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) <internal>
#define cr_expect_float_neq(Actual, Unexpected, Epsilon, FormatString, ...) internal
/**@}*/
@ -538,7 +546,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_empty(Value, FormatString, ...) <internal>
#define cr_assert_str_empty(Value, FormatString, ...) internal
/**
* Passes if Value is an empty string
@ -555,7 +563,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_empty(Value, FormatString, ...) <internal>
#define cr_expect_str_empty(Value, FormatString, ...) internal
/**
* Passes if Value is not an empty string
@ -573,7 +581,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_not_empty(Value, FormatString, ...) <internal>
#define cr_assert_str_not_empty(Value, FormatString, ...) internal
/**
* Passes if Value is not an empty string
@ -590,7 +598,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_not_empty(Value, FormatString, ...) <internal>
#define cr_expect_str_not_empty(Value, FormatString, ...) internal
/**
* Passes if Actual is lexicographically equal to Expected
@ -607,7 +615,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_eq(Actual, Expected, FormatString, ...) <internal>
#define cr_assert_str_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is lexicographically equal to Expected
@ -623,7 +631,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_eq(Actual, Expected, FormatString, ...) <internal>
#define cr_expect_str_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is not lexicographically equal to Unexpected
@ -640,7 +648,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_neq(Actual, Unexpected, FormatString, ...) <internal>
#define cr_assert_str_neq(Actual, Unexpected, FormatString, ...) internal
/**
* Passes if Actual is not lexicographically equal to Unexpected
@ -656,7 +664,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_neq(Actual, Unexpected, FormatString, ...) <internal>
#define cr_expect_str_neq(Actual, Unexpected, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less than Reference
@ -673,7 +681,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_lt(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_str_lt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less than Reference
@ -689,7 +697,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_lt(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_str_lt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less or equal to Reference
@ -706,7 +714,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_leq(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_str_leq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less or equal to Reference
@ -722,7 +730,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_leq(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_str_leq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater than Reference
@ -739,7 +747,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_gt(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_str_gt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater than Reference
@ -755,7 +763,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_gt(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_str_gt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater or equal to Reference
@ -772,7 +780,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_str_geq(Actual, Reference, FormatString, ...) <internal>
#define cr_assert_str_geq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater or equal to Reference
@ -788,7 +796,289 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_str_geq(Actual, Reference, FormatString, ...) <internal>
#define cr_expect_str_geq(Actual, Reference, FormatString, ...) internal
/**@}*/
/**
* @defgroup WideStringAsserts Wide String Assertions
*
* @note
* These macros are meant to deal with *native* wide character strings, i.e.
* wchar_t arrays. Most of them won't work on ``std::wstring`` in C++, with
* some exceptions -- for ``std::wstring``, you should use regular comparison
* assertions.
*
* @{
*/
/**
* Passes if Value is an empty wide string
*
* Passes if Value is an empty wide string.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @note Also works on std::wstring.
*
* @param[in] Value Wide string to test
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_empty(Value, FormatString, ...) internal
/**
* Passes if Value is an empty wide string
*
* Passes if Value is an empty wide string.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @note Also works on std::wstring.
*
* @param[in] Value Wide string to test
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_empty(Value, FormatString, ...) internal
/**
* Passes if Value is not an empty wide string
*
* Passes if Value is not an empty wide string.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @note Also works on std::string.
*
* @param[in] Value Wide string to test
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_not_empty(Value, FormatString, ...) internal
/**
* Passes if Value is not an empty wide string
*
* Passes if Value is not an empty wide string.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @note Also works on std::string.
*
* @param[in] Value Wide string to test
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_not_empty(Value, FormatString, ...) internal
/**
* Passes if Actual is lexicographically equal to Expected
*
* Passes if Actual is lexicographically equal to Expected.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Expected Expected wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is lexicographically equal to Expected
*
* Passes if Actual is lexicographically equal to Expected.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Expected Expected wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is not lexicographically equal to Unexpected
*
* Passes if Actual is not lexicographically equal to Unexpected.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Unexpected Unexpected wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_neq(Actual, Unexpected, FormatString, ...) internal
/**
* Passes if Actual is not lexicographically equal to Unexpected
*
* Passes if Actual is not lexicographically equal to Unexpected.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Unexpected Unexpected wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_neq(Actual, Unexpected, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less than Reference
*
* Passes if Actual is lexicographically less than Reference.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_lt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less than Reference
*
* Passes if Actual is lexicographically less than Reference.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_lt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less or equal to Reference
*
* Passes if Actual is lexicographically less or equal to Reference.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_leq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically less or equal to Reference
*
* Passes if Actual is lexicographically less or equal to Reference.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_leq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater than Reference
*
* Passes if Actual is lexicographically greater than Reference.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_gt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater than Reference
*
* Passes if Actual is lexicographically greater than Reference.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_gt(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater or equal to Reference
*
* Passes if Actual is lexicographically greater or equal to Reference.
* Otherwise the test is marked as failure and the execution of the function
* is aborted.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_assert_wcs_geq(Actual, Reference, FormatString, ...) internal
/**
* Passes if Actual is lexicographically greater or equal to Reference
*
* Passes if Actual is lexicographically greater or equal to Reference.
* Otherwise the test is marked as failure but the execution will continue.
*
* The optional (non-wide) string is printed on failure.
*
* @param[in] Actual Wide string to test
* @param[in] Reference Reference wide string
* @param[in] FormatString (optional) printf-like format string
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
#define cr_expect_wcs_geq(Actual, Reference, FormatString, ...) internal
/**@}*/
@ -815,7 +1105,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_eq(Actual, Expected, FormatString, ...) <internal>
#define cr_assert_arr_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is byte-to-byte equal to Expected
@ -834,7 +1124,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_eq(Actual, Expected, FormatString, ...) <internal>
#define cr_expect_arr_eq(Actual, Expected, FormatString, ...) internal
/**
* Passes if Actual is not byte-to-byte equal to Expected
@ -855,7 +1145,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_neq(Actual, Unexpected, Size, FormatString, ...) <internal>
#define cr_assert_arr_neq(Actual, Unexpected, Size, FormatString, ...) internal
/**
* Passes if Actual is not byte-to-byte equal to Unexpected
@ -875,7 +1165,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_neq(Actual, Unexpected, Size, FormatString, ...) <internal>
#define cr_expect_arr_neq(Actual, Unexpected, Size, FormatString, ...) internal
/**@}*/
@ -910,7 +1200,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) <internal>
#define cr_assert_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively equal to Expected (C++ / GNU C99 only)
@ -934,7 +1224,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) <internal>
#define cr_expect_arr_eq_cmp(Actual, Expected, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is not comparatively equal to Unexpected (C++ / GNU C99
@ -960,7 +1250,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) <internal>
#define cr_assert_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is not comparatively equal to Unexpected (C++ / GNU C99
@ -985,7 +1275,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) <internal>
#define cr_expect_arr_neq_cmp(Actual, Unexpected, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively less than Reference (C++ / GNU C99 only)
@ -1010,7 +1300,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#define cr_assert_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively less than Reference (C++ / GNU C99 only)
@ -1034,7 +1324,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_lt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#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
@ -1060,7 +1350,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#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
@ -1085,7 +1375,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#define cr_expect_arr_leq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively greater than Reference (C++ / GNU C99 only)
@ -1110,7 +1400,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#define cr_assert_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively greater than Reference (C++ / GNU C99 only)
@ -1134,7 +1424,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#define cr_expect_arr_gt_cmp(Actual, Reference, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively greater or equal to Reference (C++ / GNU
@ -1160,7 +1450,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#define cr_assert_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) internal
/**
* Passes if Actual is comparatively greater or equal to Reference (C++ / GNU
@ -1185,11 +1475,11 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) <internal>
#define cr_expect_arr_geq_cmp(Actual, Reference, Size, Cmp, FormatString, ...) internal
/**@}*/
# ifdef __cplusplus
#ifdef __cplusplus
/**
* @defgroup ExceptionAsserts Exception asserts
@ -1216,7 +1506,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_throw(Statement, Exception, FormatString, ...) <internal>
# define cr_assert_throw(Statement, Exception, FormatString, ...) internal
/**
* Passes if Statement throws an instance of Exception (C++ only)
@ -1234,7 +1524,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_throw(Statement, Exception, FormatString, ...) <internal>
# define cr_expect_throw(Statement, Exception, FormatString, ...) internal
/**
* Passes if Statement does not throws an instance of Exception (C++ only)
@ -1253,7 +1543,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_no_throw(Statement, Exception, FormatString, ...) <internal>
# define cr_assert_no_throw(Statement, Exception, FormatString, ...) internal
/**
* Passes if Statement does not throws an instance of Exception (C++ only)
@ -1271,7 +1561,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_no_throw(Statement, Exception, FormatString, ...) <internal>
# define cr_expect_no_throw(Statement, Exception, FormatString, ...) internal
/**
* Passes if Statement throws any kind of exception (C++ only)
@ -1289,7 +1579,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_any_throw(Statement, FormatString, ...) <internal>
# define cr_assert_any_throw(Statement, FormatString, ...) internal
/**
* Passes if Statement throws any kind of exception (C++ only)
@ -1306,7 +1596,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_any_throw(Statement, FormatString, ...) <internal>
# define cr_expect_any_throw(Statement, FormatString, ...) internal
/**
* Passes if Statement does not throws any kind of exception (C++ only)
@ -1324,7 +1614,7 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_assert_none_throw(Statement, FormatString, ...) <internal>
# define cr_assert_none_throw(Statement, FormatString, ...) internal
/**
* Passes if Statement does not throws any kind of exception (C++ only)
@ -1341,23 +1631,23 @@
* @param[in] ... (optional) format string parameters
*
*****************************************************************************/
# define cr_expect_none_throw(Statement, FormatString, ...) <internal>
# 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) \
@ -1367,25 +1657,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_ */

View file

@ -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, ...) <internal>
#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, ...) <internal>
#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_ */

View file

@ -0,0 +1,48 @@
/*
* The MIT License (MIT)
*
* Copyright © 2015-2016 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CRITERION_EMBEDDED_H_
#define CRITERION_EMBEDDED_H_
typedef signed long long int cr_ssize;
typedef unsigned long long int cr_size;
typedef unsigned char cr_byte;
typedef int cr_err;
typedef struct cr_io_ctx cr_io_ctx;
struct cr_embed_vtable {
cr_err (*init)(struct cr_io_ctx *ctx);
cr_ssize (*send)(const cr_byte *buf, cr_size size);
cr_ssize (*recv)(cr_byte *buf, cr_size size);
cr_err (*term)(struct cr_io_ctx *ctx);
};
struct cr_embed_properties {
struct cr_embed_vtable vtable;
struct cr_io_ctx *ctx;
};
int cr_embed_init(struct cr_embed_properties *props);
int cr_embed_term(struct cr_embed_properties *props);
#endif /* !CRITERION_EMBEDDED_H_ */

View file

@ -22,15 +22,15 @@
* THE SOFTWARE.
*/
#ifndef CRITERION_EVENT_H_
# define CRITERION_EVENT_H_
#define CRITERION_EVENT_H_
# ifdef __cplusplus
# include <cstddef>
# else
# include <stddef.h>
# endif
# include "internal/common.h"
# include "stats.h"
#ifdef __cplusplus
# include <cstddef>
#else
# include <stddef.h>
#endif
#include "internal/common.h"
#include "stats.h"
CR_BEGIN_C_API

View file

@ -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_ */

View file

@ -22,21 +22,22 @@
* THE SOFTWARE.
*/
#ifndef CRITERION_ASPRINTF_COMPAT_H_
# define CRITERION_ASPRINTF_COMPAT_H_
#define CRITERION_ASPRINTF_COMPAT_H_
# ifdef __cplusplus
# include <cstdarg>
# else
# include <stdarg.h>
# endif
#ifdef __cplusplus
# include <cstdarg>
#else
# include <stdarg.h>
#endif
# include "common.h"
#include "common.h"
CR_BEGIN_C_API
CR_FORMAT(printf, 2, 3)
CR_API int cr_asprintf(char **strp, const char *fmt, ...);
CR_API int cr_vasprintf(char **strp, const char *fmt, va_list ap);
CR_API void cr_asprintf_free(char *buf);
CR_END_C_API

File diff suppressed because it is too large Load diff

View file

@ -22,139 +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_PREFIX __first
# define CR_SECTION_END_PREFIX __last
# 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_PREFIX __start
# define CR_SECTION_END_PREFIX __stop
# 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_PREFIX __start
# define CR_SECTION_END_PREFIX __stop
# 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
# define CR_SECTION_START_(Name) CR_MAKE_IDENTIFIER_(CR_SECTION_START_PREFIX, Name)
# define CR_SECTION_END_(Name) CR_MAKE_IDENTIFIER_(CR_SECTION_END_PREFIX, Name)
#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
# define CR_SECTION_START(Name) g_ ## Name ## _section_start
# define CR_SECTION_END(Name) g_ ## Name ## _section_end
#ifdef _WIN32
# define CR_SIZE_T_FORMAT "%Iu"
#else
# define CR_SIZE_T_FORMAT "%zu"
#endif
# define CR_DECL_SECTION_LIMITS(Type, Name) CR_DECL_SECTION_LIMITS_(Type, Name)
# define CR_DECL_SECTION_LIMITS_(Type, Name) \
extern Type CR_SECTION_START_(Name) CR_SECTION_START_SUFFIX(#Name); \
extern Type CR_SECTION_END_(Name) CR_SECTION_END_SUFFIX(#Name)
#ifdef __GNUC__
# define CR_FORMAT(Archetype, Index, Ftc) CR_ATTRIBUTE(format(Archetype, Index, Ftc))
#else
# define CR_FORMAT(Archetype, Index, Ftc)
#endif
# define CR_IMPL_SECTION_LIMITS(Type, Name) \
Type *const CR_SECTION_START(Name) = &CR_SECTION_START_(Name); \
Type *const CR_SECTION_END(Name) = &CR_SECTION_END_(Name)
# 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 __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_ */

View file

@ -22,14 +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
#endif /* !CRITERION_INTERNAL_DEPRECATION_H_ */

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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 <typename T>
constexpr criterion_test_params(std::vector<T, criterion::allocator<T>>& vec,
void (*cleanup)(criterion_test_params *) = nullptr)
: size(sizeof (T))
, params(&vec[0])
, length(vec.size())
, cleanup(cleanup)
constexpr criterion_test_params(std::vector<T, criterion::allocator<T> > &vec,
void(*cleanup)(criterion_test_params *) = nullptr)
: size(sizeof (T)),
params(&vec[0]),
length(vec.size()),
cleanup(cleanup)
{}
template <typename T, unsigned int N>
constexpr criterion_test_params(T (&arr)[N],
void (*cleanup)(criterion_test_params *) = nullptr)
: size(sizeof (arr[0]))
, params(static_cast<void*>(&arr))
, length(N)
, cleanup(cleanup)
void(*cleanup)(criterion_test_params *) = nullptr)
: size(sizeof (arr[0])),
params(static_cast<void *>(&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_ */

View file

@ -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_ */

View file

@ -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_ */

View file

@ -22,140 +22,162 @@
* THE SOFTWARE.
*/
#ifndef CRITERION_INTERNAL_STDIO_FILEBUF_HXX_
# define CRITERION_INTERNAL_STDIO_FILEBUF_HXX_
#define CRITERION_INTERNAL_STDIO_FILEBUF_HXX_
# include <fstream>
#include <fstream>
/* *INDENT-OFF* */
namespace criterion { namespace internal {
/* *INDENT-ON* */
template <typename CharT, typename Traits = std::char_traits<CharT>>
class stdio_sync_filebuf : public std::basic_streambuf<CharT, Traits> {
public:
typedef Traits traits;
typedef std::basic_filebuf<CharT, Traits> super;
typedef typename Traits::int_type int_type;
typedef typename Traits::pos_type pos_type;
typedef typename Traits::off_type off_type;
template <typename CharT, typename Traits = std::char_traits<CharT> >
class stdio_sync_filebuf : public std::basic_streambuf<CharT, Traits> {
public:
typedef Traits traits;
typedef std::basic_filebuf<CharT, Traits> 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<char>::int_type
stdio_sync_filebuf<char>::syncgetc() {
return std::getc(file);
return ret;
}
template <>
inline stdio_sync_filebuf<char>::int_type
stdio_sync_filebuf<char>::syncungetc(stdio_sync_filebuf<char>::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<char>::int_type
stdio_sync_filebuf<char>::syncputc(stdio_sync_filebuf<char>::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<char>::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<char>::int_type
stdio_sync_filebuf<char>::syncgetc()
{
return std::getc(file);
}
template <>
inline std::streamsize
stdio_sync_filebuf<char>::xsputn(const char *s, std::streamsize n) {
return std::fwrite(s, 1, n, file);
}
template <>
inline stdio_sync_filebuf<char>::int_type
stdio_sync_filebuf<char>::syncungetc(stdio_sync_filebuf<char>::int_type c)
{
return std::ungetc(c, file);
}
template <>
inline stdio_sync_filebuf<char>::int_type
stdio_sync_filebuf<char>::syncputc(stdio_sync_filebuf<char>::int_type c)
{
return std::putc(c, file);
}
template <>
inline std::streamsize
stdio_sync_filebuf<char>::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<char>::xsputn(const char *s, std::streamsize n)
{
return std::fwrite(s, 1, n, file);
}
/* *INDENT-OFF* */
}}
/* *INDENT-ON* */
#endif /* !CRITERION_INTERNAL_STDIO_FILEBUF_HXX_ */

View file

@ -22,112 +22,120 @@
* THE SOFTWARE.
*/
#ifndef CRITERION_INTERNAL_STREAM_HXX_
# define CRITERION_INTERNAL_STREAM_HXX_
#define CRITERION_INTERNAL_STREAM_HXX_
# include <fstream>
# include <cstdio>
# include <memory>
#include <fstream>
#include <cstdio>
#include <memory>
# include "stdio_filebuf.hxx"
#include "stdio_filebuf.hxx"
/* *INDENT-OFF* */
namespace criterion { namespace internal {
/* *INDENT-ON* */
template <typename CharT, typename Super>
class stream_mixin : public Super {
template <typename CharT, typename Super>
class stream_mixin : public Super {
public:
stream_mixin(FILE* f)
: Super()
, fbuf(new stdio_sync_filebuf<CharT>(f))
, file(f)
{
std::ios::rdbuf(&*fbuf);
}
stream_mixin(FILE *f)
: Super(),
fbuf(new stdio_sync_filebuf<CharT>(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<stdio_sync_filebuf<CharT>> fbuf;
std::FILE* file;
};
private:
std::shared_ptr<stdio_sync_filebuf<CharT> > fbuf;
std::FILE *file;
};
template <typename CharT>
class basic_ofstream : public stream_mixin<CharT, std::basic_ofstream<CharT>> {
typedef stream_mixin<CharT, std::basic_ofstream<CharT>> super;
public:
basic_ofstream(FILE* f)
: super(f)
{}
template <typename CharT>
class basic_ofstream : public stream_mixin<CharT, std::basic_ofstream<CharT> > {
typedef stream_mixin<CharT, std::basic_ofstream<CharT> > 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 <typename CharT>
class basic_ifstream : public stream_mixin<CharT, std::basic_ifstream<CharT>> {
typedef stream_mixin<CharT, std::basic_ifstream<CharT>> super;
public:
basic_ifstream(FILE* f)
: super(f)
{}
template <typename CharT>
class basic_ifstream : public stream_mixin<CharT, std::basic_ifstream<CharT> > {
typedef stream_mixin<CharT, std::basic_ifstream<CharT> > 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 <typename CharT>
class basic_fstream : public stream_mixin<CharT, std::basic_fstream<CharT>> {
typedef stream_mixin<CharT, std::basic_fstream<CharT>> super;
public:
basic_fstream(FILE* f)
: super(f)
{}
template <typename CharT>
class basic_fstream : public stream_mixin<CharT, std::basic_fstream<CharT> > {
typedef stream_mixin<CharT, std::basic_fstream<CharT> > 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<char>& call(std::FILE* f) {
static std::unique_ptr<basic_ofstream<char>> stream;
struct get_redirected_out_stream_ {
static inline basic_ofstream<char> &call(std::FILE *f)
{
static std::unique_ptr<basic_ofstream<char> > stream;
if (!stream)
stream.reset(new basic_ofstream<char>(f));
return *stream;
}
if (!stream)
stream.reset(new basic_ofstream<char>(f));
return *stream;
}
};
};
struct get_redirected_in_stream_ {
static inline basic_ifstream<char> &call(std::FILE *f)
{
static std::unique_ptr<basic_ifstream<char> > stream;
struct get_redirected_in_stream_ {
static inline basic_ifstream<char>& call(std::FILE* f) {
static std::unique_ptr<basic_ifstream<char>> stream;
if (!stream)
stream.reset(new basic_ifstream<char>(f));
return *stream;
}
};
if (!stream)
stream.reset(new basic_ifstream<char>(f));
return *stream;
}
};
/* *INDENT-OFF* */
}}
/* *INDENT-ON* */
#endif /* !CRITERION_INTERNAL_STREAM_HXX_ */

View file

@ -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 <Foundation/Foundation.h>
# endif
#ifdef __OBJC__
# import <Foundation/Foundation.h>
#endif
# ifdef __cplusplus
# include <exception>
# endif
#ifdef __cplusplus
# include <exception>
#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_ */

View file

@ -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 <cstddef>
#ifdef __cplusplus
# include <cstddef>
using std::size_t;
# else
# include <stddef.h>
# endif
#else
# include <stddef.h>
#endif
# ifdef __cplusplus
#ifdef __cplusplus
template <typename... T>
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<Type*>(&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<Type *>(&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_ */

View file

@ -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
@ -48,8 +48,6 @@ enum criterion_severity {
CR_LOG_ERROR,
};
CR_FORMAT(printf, 2, 3)
/**
* Prints a log message
*
@ -60,6 +58,7 @@ CR_FORMAT(printf, 2, 3)
* @param[in] ... Additional arguments depending on msg
*
*****************************************************************************/
CR_FORMAT(printf, 2, 3)
CR_API void cr_log(enum criterion_severity severity, const char *msg, ...);
/**
@ -72,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
@ -84,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
@ -96,13 +95,13 @@ 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);
void (*log_pre_suite )(struct criterion_suite_set *set);
void (*log_pre_init )(struct criterion_test *test);
void (*log_pre_test )(struct criterion_test *test);
void (*log_pre_init )(struct criterion_suite *suite, struct criterion_test *test);
void (*log_pre_test )(struct criterion_suite *suite, struct criterion_test *test);
void (*log_assert )(struct criterion_assert_stats *stats);
void (*log_theory_fail )(struct criterion_theory_stats *stats);
void (*log_test_timeout )(struct criterion_test_stats *stats);
@ -121,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 <sstream>
#ifdef __cplusplus
# include <sstream>
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_ */

View file

@ -26,11 +26,11 @@
* @brief criterion options
*****************************************************************************/
#ifndef CRITERION_OPTIONS_H_
# define CRITERION_OPTIONS_H_
#define CRITERION_OPTIONS_H_
# include <stdbool.h>
# include "logging.h"
# include "internal/common.h"
#include <stdbool.h>
#include "logging.h"
#include "internal/common.h"
enum criterion_debugger {
/**
@ -38,6 +38,13 @@ enum criterion_debugger {
*/
CR_DBG_NONE,
/**
* Run the test suspended, without a debugger, and print its PID.
*
* Allows external debuggers to attach.
*/
CR_DBG_IDLE,
/**
* Run the test with a debugging server compatible with the compiler
* it was built with.
@ -61,7 +68,6 @@ enum criterion_debugger {
};
struct criterion_options {
/**
* The current logging threshold.
*
@ -165,6 +171,15 @@ struct criterion_options {
* default: 1234
*/
unsigned debug_port;
/**
* The default timeout for each test when none is specified, in seconds.
*
* If the value is non-positive, no timeout is applied.
*
* default: 0
*/
double timeout;
};
CR_BEGIN_C_API

View file

@ -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.

View file

@ -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, ...) <internal>
#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) <internal>
#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) <internal>
#define cr_make_param_array(Type, Array, Len, Cleanup) internal
/** @} */
# ifdef __cplusplus
# include <vector>
#ifdef __cplusplus
# include <vector>
namespace criterion {
/**
* Represents a C++ dynamic parameter list for a parameter generator.
*
* @ingroup ParameterizedBase
*
* @param T The type of the parameter.
*/
template <typename T>
using parameters = std::vector<T, criterion::allocator<T>>;
namespace criterion
{
/**
* Represents a C++ dynamic parameter list for a parameter generator.
*
* @ingroup ParameterizedBase
*
* @param T The type of the parameter.
*/
template <typename T>
using parameters = std::vector<T, criterion::allocator<T> >;
}
# endif
#endif
# include "internal/parameterized.h"
#include "internal/parameterized.h"
#endif /* !CRITERION_PARAMETERIZED_H_ */

View file

@ -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 <cstdio>
# else
# include <stdio.h>
# endif
#ifdef __cplusplus
# include <cstdio>
#else
# include <stdio.h>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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, ...) <internal>
#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<char> ofstream;
typedef internal::basic_ifstream<char> ifstream;
typedef internal::basic_fstream<char> fstream;
typedef internal::basic_ofstream<char> ofstream;
typedef internal::basic_ifstream<char> ifstream;
typedef internal::basic_fstream<char> 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_ */

View file

@ -26,9 +26,16 @@
* @brief Test stats
*****************************************************************************/
#ifndef CRITERION_STATS_H_
# define CRITERION_STATS_H_
#define CRITERION_STATS_H_
# include "types.h"
#include "types.h"
#include "internal/deprecation.h"
enum criterion_test_status {
CR_STATUS_PASSED = 0,
CR_STATUS_FAILED = 1,
CR_STATUS_SKIPPED = 2,
};
struct criterion_assert_stats {
const char *message;
@ -42,7 +49,8 @@ struct criterion_assert_stats {
struct criterion_test_stats {
struct criterion_test *test;
struct criterion_assert_stats *asserts;
bool failed;
bool CR_DEPRECATED_MEMBER(failed);
enum criterion_test_status test_status;
int passed_asserts;
int failed_asserts;
int signal;
@ -52,6 +60,7 @@ struct criterion_test_stats {
bool crashed;
unsigned progress;
const char *file;
const char *message;
struct criterion_test_stats *next;
};

View file

@ -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, ...) <internal>
#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_ */

View file

@ -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 <cstddef>
# include <vector>
#include "alloc.h"
#ifdef __cplusplus
# include <cstddef>
# include <vector>
using std::size_t;
# else
# include <stdbool.h>
# include <stddef.h>
# endif
# include "internal/common.h"
#else
# include <stdbool.h>
# include <stddef.h>
#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.
@ -132,7 +132,7 @@ struct criterion_test_extra_data {
int exit_code;
/**
* If `true`, disables the test.
* If `true`, skips the test.
*
* The test will still appear in the test list, but will be marked as
* skipped and will not be executed.

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Criterion \n"
"Report-Msgid-Bugs-To: franklinmathieu+criterion@gmail.com\n"
"POT-Creation-Date: 2016-08-08 15:38+0200\n"
"POT-Creation-Date: 2016-09-16 11:24+0200\n"
"PO-Revision-Date: 2016-02-12 11:12+0100\n"
"Last-Translator: <a1lu@arcor.de>\n"
"Language-Team: German\n"
@ -28,7 +28,7 @@ msgstr "Criterion v%s\n"
msgid " %s\n"
msgstr " %s\n"
#: src/log/normal.c:46 src/log/normal.c:48
#: src/log/normal.c:46
#, c-format
msgid "%1$s::%2$s\n"
msgstr "%1$s::%2$s\n"
@ -38,6 +38,11 @@ msgstr "%1$s::%2$s\n"
msgid "%1$s::%2$s: (%3$3.2fs)\n"
msgstr "%1$s::%2$s: (%3$3.2fs)\n"
#: src/log/normal.c:48
#, c-format
msgid "%1$s::%2$s: Test was skipped\n"
msgstr "%1$s::%2$s: Test wurde übersprungen\n"
#: src/log/normal.c:49
#, c-format
msgid "%1$s::%2$s: Test is disabled\n"
@ -45,43 +50,38 @@ msgstr "%1$s::%2$s: Test ist deaktiviert\n"
#: src/log/normal.c:50
#, c-format
msgid "%1$s::%2$s: Suite is disabled\n"
msgstr "%1$s::%2$s: Suite ist deaktiviert\n"
#: src/log/normal.c:51
#, c-format
msgid "%1$s%2$s%3$s:%4$s%5$d%6$s: Assertion failed: %7$s\n"
msgstr "%1$s%2$s%3$s:%4$s%5$d%6$s: Fehlerhafte Behauptung: %7$s\n"
#: src/log/normal.c:52
#: src/log/normal.c:51
#, c-format
msgid " Theory %1$s::%2$s failed with the following parameters: (%3$s)\n"
msgstr ""
" Hypothese %1$s::%2$s schlug fehl mit den folgenden Parametern: (%3$s)\n"
#: src/log/normal.c:53
#: src/log/normal.c:52
#, c-format
msgid "%1$s::%2$s: Timed out. (%3$3.2fs)\n"
msgstr "%1$s::%2$s: Außerhalb der Vorgabezeit. (%3$3.2fs)\n"
#: src/log/normal.c:54
#: src/log/normal.c:53
#, c-format
msgid "%1$s%2$s%3$s:%4$s%5$u%6$s: Unexpected signal caught below this line!\n"
msgstr ""
"%1$s%2$s%3$s:%4$s%5$u%6$s: Unerwartetes Signal gefangen unterhalb dieser "
"Zeile!\n"
#: src/log/normal.c:55
#: src/log/normal.c:54
#, c-format
msgid "%1$s::%2$s: CRASH!\n"
msgstr "%1$s::%2$s: ABSTURZ!\n"
#: src/log/normal.c:56
#: src/log/normal.c:55
#, c-format
msgid "%1$s::%2$s: %3$s\n"
msgstr "%1$s::%2$s: %3$s\n"
#: src/log/normal.c:57
#: src/log/normal.c:56
#, c-format
msgid ""
"%1$sWarning! The test `%2$s::%3$s` crashed during its setup or teardown."
@ -90,7 +90,7 @@ msgstr ""
"%1$sWarnung! Der Test `%2$s::%3$s` ist abgestürzt während der "
"Initialisierung oder Beendung %4$s\n"
#: src/log/normal.c:58
#: src/log/normal.c:57
#, c-format
msgid ""
"%1$sWarning! The test `%2$s::%3$s` exited during its setup or teardown.%4$s\n"
@ -98,14 +98,14 @@ msgstr ""
"%1$sWarnung! Der Test `%2$s::%3$s` hat sich beendet während der "
"Initialisierung oder Beendung.%4$s\n"
#: src/log/normal.c:59
#: src/log/normal.c:58
#, c-format
msgid "Running %1$s%2$lu%3$s test from %4$s%5$s%6$s:\n"
msgid_plural "Running %1$s%2$lu%3$s tests from %4$s%5$s%6$s:\n"
msgstr[0] "Führe %1$s%2$lu%3$s Test durch von %4$s%5$s%6$s:\n"
msgstr[1] "Führe %1$s%2$lu%3$s Tests durch von %4$s%5$s%6$s:\n"
#: src/log/normal.c:61
#: src/log/normal.c:60
#, c-format
msgid ""
"%1$sSynthesis: Tested: %2$s%3$lu%4$s | Passing: %5$s%6$lu%7$s | Failing: %8$s"
@ -114,41 +114,41 @@ msgstr ""
"%1$sSynthese: Getestet: %2$s%3$lu%4$s | Bestanden: %5$s%6$lu%7$s | Fehler: "
"%8$s%9$lu%10$s | Abstürze: %11$s%12$lu%13$s %14$s\n"
#: src/string/i18n.c:13
#: src/string/i18n.c:15
msgid "The conditions for this assertion were not met."
msgstr "Die Bedingung für diesen Behauptung wurden nicht erfüllt"
#: src/string/i18n.c:14
#: src/string/i18n.c:16
#, c-format
msgid "The expression %s is false."
msgstr "Der Ausdruck %s ist falsch."
#: src/string/i18n.c:15
#: src/string/i18n.c:17
#, c-format
msgid "%s is null."
msgstr "%s ist null."
#: src/string/i18n.c:16
#: src/string/i18n.c:18
#, c-format
msgid "%s is not null."
msgstr "%s ist nicht null."
#: src/string/i18n.c:17
#: src/string/i18n.c:19
#, c-format
msgid "%s is empty."
msgstr "%s ist leer."
#: src/string/i18n.c:18
#: src/string/i18n.c:20
#, c-format
msgid "The statement `%s` did not throw any exception."
msgstr "Die Anweisung `%s` hat keine Ausnahme geworfen."
#: src/string/i18n.c:19
#: src/string/i18n.c:21
#, c-format
msgid "The statement `%s` threw some exception."
msgstr "Die Anweisung `%s` hat Ausnahmen geworfen."
#: src/string/i18n.c:22
#: src/string/i18n.c:24
#, c-format
msgid ""
"The expression (as strings) %1$s is false: actual=`%2$s` expected=`%3$s`."
@ -156,32 +156,32 @@ msgstr ""
"Der Ausdruck (als Zeichenkette) %1$s ist falsch: tatsächlich=`%2$s` "
"erwartet=`%3$s`."
#: src/string/i18n.c:23
#: src/string/i18n.c:25
#, c-format
msgid "%1$s (`%2$s`) is not empty."
msgstr "%1$s (`%2$s`) ist nicht leer."
#: src/string/i18n.c:24
#: src/string/i18n.c:26
#, c-format
msgid "The file contents of %1$s does not match the string \"%2$s\"."
msgstr "Der Inhalt der Datei %1$s ist nicht gleich der Zeichenkette \"%2$s\"."
#: src/string/i18n.c:25
#: src/string/i18n.c:27
#, c-format
msgid "The file contents of %1$s does not match the contents of %2$s."
msgstr "Der Inhalt der Datei %1$s ist nicht gleich dem Inhalt von %2$s."
#: src/string/i18n.c:26
#: src/string/i18n.c:28
#, c-format
msgid "The statement `%1$s` did throw an instance of the `%2$s` exception."
msgstr "Die Anweisung `%1$s` hat eine Instanz der Ausname `%2$s` geworfen."
#: src/string/i18n.c:27
#: src/string/i18n.c:29
#, c-format
msgid "The statement `%1$s` did not throw an instance of the `%2$s` exception."
msgstr "Die Anweisung `%1$s` hat keine Instanz der Ausname `%2$s` geworfen."
#: src/core/runner.c:62
#: src/core/runner.c:68
#, c-format
msgid ""
"%1$sWarning! Criterion has detected that it is running under valgrind, but "
@ -192,13 +192,13 @@ msgstr ""
"die Anzahl an Aufträgen wurde explizit festgelegt. Die Berichte können "
"verwirrend sein!%2$s\n"
#: src/io/output.c:13
#: src/io/output.c:36
#, c-format
msgid "Could not open the file @ `%1$s` for %2$s reporting: %3$s.\n"
msgstr ""
"Konnte die Datei `%1$s` nicht für die Berichte von %2$s öffnen: %3$s.\n"
#: src/io/output.c:14
#: src/io/output.c:37
#, c-format
msgid "Writing %1$s report in `%2$s`.\n"
msgstr "Schreibe Bericht von %1$s nach `%2$s`.\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: criterion 2.0.0\n"
"Report-Msgid-Bugs-To: franklinmathieu+criterion@gmail.com\n"
"POT-Creation-Date: 2016-08-08 15:38+0200\n"
"POT-Creation-Date: 2016-09-16 11:24+0200\n"
"PO-Revision-Date: 2015-04-03 17:58+0200\n"
"Last-Translator: <franklinmathieu@gmail.com>\n"
"Language-Team: French\n"
@ -28,16 +28,21 @@ msgstr "Criterion v%s\n"
msgid " %s\n"
msgstr " %s\n"
#: src/log/normal.c:46 src/log/normal.c:48
#: src/log/normal.c:46
#, c-format
msgid "%1$s::%2$s\n"
msgstr "%1$s::%2$s\n"
#: src/log/normal.c:47
#, fuzzy, c-format
#, c-format
msgid "%1$s::%2$s: (%3$3.2fs)\n"
msgstr "%1$s::%2$s: (%3$3.2fs)\n"
#: src/log/normal.c:48
#, c-format
msgid "%1$s::%2$s: Test was skipped\n"
msgstr "%1$s::%2$s: Le test a été sauté\n"
#: src/log/normal.c:49
#, c-format
msgid "%1$s::%2$s: Test is disabled\n"
@ -45,43 +50,38 @@ msgstr "%1$s::%2$s: Le test est désactivé\n"
#: src/log/normal.c:50
#, c-format
msgid "%1$s::%2$s: Suite is disabled\n"
msgstr "%1$s::%2$s: La suite est désactivée\n"
#: src/log/normal.c:51
#, c-format
msgid "%1$s%2$s%3$s:%4$s%5$d%6$s: Assertion failed: %7$s\n"
msgstr "%1$s%2$s%3$s:%4$s%5$d%6$s: Échec d'assertion: %7$s\n"
#: src/log/normal.c:52
#: src/log/normal.c:51
#, fuzzy, c-format
msgid " Theory %1$s::%2$s failed with the following parameters: (%3$s)\n"
msgstr ""
" La théorie %1$s::%2$s a échoué avec les paramètres suivants: (%3$s)\n"
#: src/log/normal.c:53
#: src/log/normal.c:52
#, fuzzy, c-format
msgid "%1$s::%2$s: Timed out. (%3$3.2fs)\n"
msgstr "%1$s::%2$s: Délai expiré. (%3$3.2fs)\n"
#: src/log/normal.c:54
#: src/log/normal.c:53
#, c-format
msgid "%1$s%2$s%3$s:%4$s%5$u%6$s: Unexpected signal caught below this line!\n"
msgstr ""
"%1$s%2$s%3$s:%4$s%5$u%6$s: Un signal inattendu a été reçu après cette "
"ligne!\n"
#: src/log/normal.c:55
#: src/log/normal.c:54
#, c-format
msgid "%1$s::%2$s: CRASH!\n"
msgstr "%1$s::%2$s: PLANTAGE!\n"
#: src/log/normal.c:56
#: src/log/normal.c:55
#, fuzzy, c-format
msgid "%1$s::%2$s: %3$s\n"
msgstr "%1$s::%2$s: (%3$3.2fs)\n"
#: src/log/normal.c:57
#: src/log/normal.c:56
#, fuzzy, c-format
msgid ""
"%1$sWarning! The test `%2$s::%3$s` crashed during its setup or teardown."
@ -90,7 +90,7 @@ msgstr ""
"%1$sAttention! Le test `%2$s::%3$s` a planté pendant son initialisation ou "
"sa finalisation.%4$s\n"
#: src/log/normal.c:58
#: src/log/normal.c:57
#, fuzzy, c-format
msgid ""
"%1$sWarning! The test `%2$s::%3$s` exited during its setup or teardown.%4$s\n"
@ -98,14 +98,14 @@ msgstr ""
"%1$sAttention! Le test `%2$s::%3$s` a quitté pendant son initialisation ou "
"sa finalisation.%4$s\n"
#: src/log/normal.c:59
#: src/log/normal.c:58
#, c-format
msgid "Running %1$s%2$lu%3$s test from %4$s%5$s%6$s:\n"
msgid_plural "Running %1$s%2$lu%3$s tests from %4$s%5$s%6$s:\n"
msgstr[0] "Lancement de %1$s%2$lu%3$s test dans %4$s%5$s%6$s:\n"
msgstr[1] "Lancement de %1$s%2$lu%3$s tests dans %4$s%5$s%6$s:\n"
#: src/log/normal.c:61
#: src/log/normal.c:60
#, c-format
msgid ""
"%1$sSynthesis: Tested: %2$s%3$lu%4$s | Passing: %5$s%6$lu%7$s | Failing: %8$s"
@ -114,41 +114,41 @@ msgstr ""
"%1$sSynthèse: Testés: %2$s%3$lu%4$s | Validés: %5$s%6$lu%7$s | Échoués: %8$s"
"%9$lu%10$s | Plantages: %11$s%12$lu%13$s %14$s\n"
#: src/string/i18n.c:13
#: src/string/i18n.c:15
msgid "The conditions for this assertion were not met."
msgstr "Les conditions de cette assertion n'ont pas été remplies."
#: src/string/i18n.c:14
#: src/string/i18n.c:16
#, c-format
msgid "The expression %s is false."
msgstr "L'expression %s est fausse."
#: src/string/i18n.c:15
#: src/string/i18n.c:17
#, c-format
msgid "%s is null."
msgstr "%s est nul."
#: src/string/i18n.c:16
#: src/string/i18n.c:18
#, c-format
msgid "%s is not null."
msgstr "%s n'est pas nul."
#: src/string/i18n.c:17
#: src/string/i18n.c:19
#, c-format
msgid "%s is empty."
msgstr "%s est vide."
#: src/string/i18n.c:18
#: src/string/i18n.c:20
#, fuzzy, c-format
msgid "The statement `%s` did not throw any exception."
msgstr "L'instruction `%s` n'a pas levé d'exception."
#: src/string/i18n.c:19
#: src/string/i18n.c:21
#, fuzzy, c-format
msgid "The statement `%s` threw some exception."
msgstr "L'instruction `%1$s` a levé une exception."
#: src/string/i18n.c:22
#: src/string/i18n.c:24
#, c-format
msgid ""
"The expression (as strings) %1$s is false: actual=`%2$s` expected=`%3$s`."
@ -156,34 +156,34 @@ msgstr ""
"L'expression (en tant que chaînes de caractères) %1$s est fausse: actuel=`"
"%2$s` attendu=`%3$s`."
#: src/string/i18n.c:23
#: src/string/i18n.c:25
#, c-format
msgid "%1$s (`%2$s`) is not empty."
msgstr "%1$s (`%2$s`) n'est pas vide."
#: src/string/i18n.c:24
#: src/string/i18n.c:26
#, c-format
msgid "The file contents of %1$s does not match the string \"%2$s\"."
msgstr ""
"Le contenu du fichier %1$s ne correspond pas à la chaine de caractères \"%2$s"
"\"."
#: src/string/i18n.c:25
#: src/string/i18n.c:27
#, fuzzy, c-format
msgid "The file contents of %1$s does not match the contents of %2$s."
msgstr "Le contenu du fichier %1$s ne correspond pas au contenu de %2$s."
#: src/string/i18n.c:26
#: src/string/i18n.c:28
#, c-format
msgid "The statement `%1$s` did throw an instance of the `%2$s` exception."
msgstr "L'instruction `%1$s` a levé une instance de l'exception `%2$s`."
#: src/string/i18n.c:27
#: src/string/i18n.c:29
#, c-format
msgid "The statement `%1$s` did not throw an instance of the `%2$s` exception."
msgstr "L'instruction `%1$s` n'a pas levé d'instance de l'exception `%2$s`."
#: src/core/runner.c:62
#: src/core/runner.c:68
#, c-format
msgid ""
"%1$sWarning! Criterion has detected that it is running under valgrind, but "
@ -194,13 +194,13 @@ msgstr ""
"nombre de tâches est explicitement défini. Les rapports d'erreur risquent "
"d'être déroutants!%2$s\n"
#: src/io/output.c:13
#: src/io/output.c:36
#, fuzzy, c-format
msgid "Could not open the file @ `%1$s` for %2$s reporting: %3$s.\n"
msgstr ""
"Impossible d'ouvrir le fichier `%1$s` pour faire le rapport %2$s: %3$s.\n"
#: src/io/output.c:14
#: src/io/output.c:37
#, c-format
msgid "Writing %1$s report in `%2$s`.\n"
msgstr "Écriture du rapport %1$s dans `%2$s`.\n"

View file

@ -23,6 +23,7 @@ set(SAMPLES
redirect.c
parameterized.c
log.c
skip.c
)
if (CMAKE_CXX_COMPILER_WORKS)
@ -38,6 +39,7 @@ if (CMAKE_CXX_COMPILER_WORKS)
redirect.cc
parameterized.cc
log.cc
skip.cc
)
endif ()
@ -48,7 +50,6 @@ if (THEORIES)
endif ()
endif ()
add_custom_target(criterion_samples)
add_dependencies(criterion_tests criterion_samples)

View file

@ -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) {
@ -34,6 +34,22 @@ Test(asserts, string) {
cr_assert_str_leq("hello", "hello");
}
Test(asserts, wstring) {
cr_assert_wcs_empty(L"");
cr_assert_wcs_not_empty(L"foo");
cr_assert_wcs_eq(L"hello", L"hello");
cr_assert_wcs_neq(L"hello", L"olleh");
cr_assert_wcs_gt(L"hello", L"hell");
cr_assert_wcs_geq(L"hello", L"hell");
cr_assert_wcs_geq(L"hello", L"hello");
cr_assert_wcs_lt(L"hell", L"hello");
cr_assert_wcs_leq(L"hell", L"hello");
cr_assert_wcs_leq(L"hello", L"hello");
}
Test(asserts, native) {
cr_assert_eq(1, 1);
cr_assert_neq(1, 2);
@ -57,27 +73,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
}

View file

@ -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) {
@ -37,6 +37,22 @@ Test(asserts, string) {
cr_assert_str_leq("hello", "hello");
}
Test(asserts, wstring) {
cr_assert_wcs_empty(L"");
cr_assert_wcs_not_empty(L"foo");
cr_assert_wcs_eq(L"hello", L"hello");
cr_assert_wcs_neq(L"hello", L"olleh");
cr_assert_wcs_gt(L"hello", L"hell");
cr_assert_wcs_geq(L"hello", L"hell");
cr_assert_wcs_geq(L"hello", L"hello");
cr_assert_wcs_lt(L"hell", L"hello");
cr_assert_wcs_leq(L"hell", L"hello");
cr_assert_wcs_leq(L"hello", L"hello");
}
Test(asserts, native) {
cr_assert_eq(1, 1);
cr_assert_neq(1, 2);
@ -59,24 +75,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) {
return *a == *b ? 0 : (*a < *b ? -1 : 1);
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<dummy_struct, 2> cpparr1 = {{{4, 2}, {2, 4}}};
/* 1. (recommended): use std::array and cr_assert_eq */
std::array<dummy_struct, 2> cpparr1 = { { { 4, 2 }, { 2, 4 } } };
std::array<dummy_struct, 2> 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,25 +103,25 @@ 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_cmp(&s1, &s2, 2, eq_dummy);
/* 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);
}
Test(asserts, exception) {

View file

@ -1,11 +1,13 @@
#include <criterion/criterion.h>
#include <stdio.h>
void setup(void) {
void setup(void)
{
puts("Runs before the test");
}
void teardown(void) {
void teardown(void)
{
puts("Runs after the test");
}

View file

@ -1,11 +1,13 @@
#include <criterion/criterion.h>
#include <stdio.h>
void setup(void) {
void setup(void)
{
puts("Runs before the test");
}
void teardown(void) {
void teardown(void)
{
puts("Runs after the test");
}

View file

@ -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;
}

View file

@ -1,9 +1,11 @@
#include <criterion/criterion.h>
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) {
}

View file

@ -1,9 +1,11 @@
#include <criterion/criterion.h>
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) {
}

View file

@ -1,7 +1,7 @@
#include <criterion/parameterized.h>
#include <stdio.h>
// 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) };

View file

@ -1,6 +1,6 @@
#include <criterion/parameterized.h>
// 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<T> allocator may be used with STL containers to
// allocate objects with the functions described above.
/* the criterion::allocator<T> 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<double, decltype(criterion::free)> d;
std::unique_ptr<double, decltype (criterion::free)> 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<double>(4)));
params.push_back(parameter_tuple_dyn(5, new_obj<double>(6)));
// A criterion::parameters<T> can be returned in place of a
// criterion_test_params.
/* A criterion::parameters<T> 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);
}

View file

@ -4,9 +4,10 @@
#include <stdio.h>
#include <ctype.h>
// 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);

View file

@ -5,9 +5,10 @@
#include <iostream>
#include <cctype>
// 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();

View file

@ -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 <windows.h>
#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);

View file

@ -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 <windows.h>
#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);

10
samples/skip.c Normal file
View file

@ -0,0 +1,10 @@
#include <criterion/criterion.h>
Test(misc, skipping) {
cr_skip_test();
cr_assert_fail("We want to skip before failing");
}
Test(misc, message) {
cr_skip_test("Skips may take %s", "printf-like messages");
}

10
samples/skip.cc Normal file
View file

@ -0,0 +1,10 @@
#include <criterion/criterion.h>
Test(misc, skipping) {
cr_skip_test();
cr_assert_fail("We want to skip before failing");
}
Test(misc, message) {
cr_skip_test("Skips may take %s", "printf-like messages");
}

View file

@ -1,18 +1,28 @@
#include <criterion/criterion.h>
#include <stdexcept>
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) {
}

View file

@ -13,7 +13,8 @@ Test(exit, unexpected_exit) {
exit(127);
}
void do_exit (void) {
void do_exit(void)
{
exit(127);
}

View file

@ -13,7 +13,8 @@ Test(exit, unexpected_exit) {
exit(127);
}
void do_exit (void) {
void do_exit(void)
{
exit(127);
}

View file

@ -1,8 +1,8 @@
#include <criterion/criterion.h>
// 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);

View file

@ -1,7 +1,9 @@
#include <criterion/criterion.h>
void crash(void) {
void crash(void)
{
int *i = NULL;
*i = 42;
}

View file

@ -1,7 +1,9 @@
#include <criterion/criterion.h>
void crash(void) {
void crash(void)
{
int *i = NULL;
*i = 42;
}

View file

@ -1,19 +1,19 @@
#ifdef _MSC_VER
#pragma warning(disable : 4090)
# pragma warning(disable : 4090)
#endif
#include <criterion/theories.h>
// 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();
}

View file

@ -1,21 +1,21 @@
#ifdef _MSC_VER
#pragma warning(disable : 4090)
# pragma warning(disable : 4090)
#endif
#include <criterion/theories.h>
// 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();
}

View file

@ -1,19 +1,21 @@
#ifdef _MSC_VER
#pragma warning(disable : 4090)
# pragma warning(disable : 4090)
#endif
#include <criterion/theories.h>
#include <limits.h>
# 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();
}

View file

@ -1,5 +1,5 @@
#ifdef _MSC_VER
#pragma warning(disable : 4090)
# pragma warning(disable : 4090)
#endif
#include <criterion/theories.h>
@ -9,15 +9,17 @@
# include <limits.h>
#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();
}

View file

@ -2,7 +2,7 @@
#ifdef _WIN32
# include <windows.h>
# define sleep(x) Sleep(x * 1000)
# define sleep(x) Sleep(x * 1000)
#else
# include <unistd.h>
#endif

View file

@ -22,21 +22,13 @@
* THE SOFTWARE.
*/
#ifndef COMMON_H_
# define COMMON_H_
#define COMMON_H_
# include <stdio.h>
# include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
# include "criterion/internal/common.h"
#include "criterion/internal/common.h"
#ifdef __GNUC__
# define INLINE __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
# define INLINE __forceinline
#else
# define INLINE
#endif
# define DEF(X, Y) ((X) ? (X) : (Y))
#define DEF(X, Y) ((X) ? (X) : (Y))
#endif /* !COMMON_H_ */

View file

@ -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);
}

View file

@ -22,10 +22,10 @@
* THE SOFTWARE.
*/
#ifndef COMPAT_ALLOC_H_
# define COMPAT_ALLOC_H_
#define COMPAT_ALLOC_H_
# include <boxfort.h>
# include "criterion/alloc.h"
#include <boxfort.h>
#include "criterion/alloc.h"
void cri_alloc_init(void);
void cri_alloc_term(void);

View file

@ -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;

View file

@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#ifndef BASENAME_H_
# define BASENAME_H_
#define BASENAME_H_
const char *basename_compat(const char *str);

View file

@ -22,50 +22,46 @@
* THE SOFTWARE.
*/
#ifndef INTERNAL_H_
# define INTERNAL_H_
#define INTERNAL_H_
# if defined(_WIN32) && !defined(__CYGWIN__)
# define VC_EXTRALEAN
# define WIN32_LEAN_AND_MEAN
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# include <windows.h>
#if defined (_WIN32) && !defined (__CYGWIN__)
# include <windows.h>
# 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 <io.h>
# if defined(MINGW_DEFINE_OFF_T) && (defined(__MINGW32__) || defined(__MINGW64__))
# undef off_t
# undef off64_t
# endif
# include <fcntl.h>
# include <winnt.h>
# include <stdint.h>
# include <signal.h>
# else
# include <fcntl.h>
# include <signal.h>
# include <sys/param.h>
# include <sys/wait.h>
# include <unistd.h>
# ifdef BSD
# include <sys/types.h>
# define off64_t cr_off64
# endif
# include <io.h>
# if defined (MINGW_DEFINE_OFF_T) && (defined (__MINGW32__) || defined (__MINGW64__))
# undef off_t
# undef off64_t
# endif
# include <fcntl.h>
# include <winnt.h>
# include <stdint.h>
# include <signal.h>
#else
# include <fcntl.h>
# include <signal.h>
# include <sys/param.h>
# include <sys/wait.h>
# include <unistd.h>
# ifdef BSD
# include <sys/types.h>
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
# include <sys/sysctl.h>
# endif
# include <sys/sysctl.h>
# endif
#endif
# include "posix.h"
#include "posix.h"
#endif /* !INTERNAL_H_ */

View file

@ -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);

View file

@ -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);

View file

@ -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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@ -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
}

View file

@ -22,9 +22,9 @@
* THE SOFTWARE.
*/
#ifndef CR_OFF_T_DEFINED
# define CR_OFF_T_DEFINED
#define CR_OFF_T_DEFINED
# include <stdint.h>
#include <stdint.h>
typedef int32_t cr_off32;
typedef int64_t cr_off64;

View file

@ -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

View file

@ -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";

View file

@ -22,12 +22,12 @@
* THE SOFTWARE.
*/
#ifndef PIPE_H_
# define PIPE_H_
#define PIPE_H_
# include <stdio.h>
# include <stdlib.h>
# include "common.h"
# include "log/logging.h"
#include <stdio.h>
#include <stdlib.h>
#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);
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;

Some files were not shown because too many files have changed in this diff Show more