/*
The latest version of this library is available on GitHub;
https://github.com/sheredom/utest.h
*/
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
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 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.
For more information, please refer to <http://unlicense.org/>
*/
#ifndef SHEREDOM_UTEST_H_INCLUDED
#define SHEREDOM_UTEST_H_INCLUDED
#ifdef _MSC_VER
/*
Disable warning about not inlining 'inline' functions.
*/
#pragma warning(disable : 4710)
/*
Disable warning about inlining functions that are not marked 'inline'.
*/
#pragma warning(disable : 4711)
/*
Disable warning for alignment padding added
*/
#pragma warning(disable : 4820)
#if _MSC_VER > 1900
/*
Disable warning about preprocessor macros not being defined in MSVC headers.
*/
#pragma warning(disable : 4668)
/*
Disable warning about no function prototype given in MSVC headers.
*/
#pragma warning(disable : 4255)
/*
Disable warning about pointer or reference to potentially throwing function.
*/
#pragma warning(disable : 5039)
/*
Disable warning about macro expansion producing 'defined' has undefined
behavior.
*/
#pragma warning(disable : 5105)
#endif
#if _MSC_VER > 1930
/*
Disable warning about 'const' variable is not used.
*/
#pragma warning(disable : 5264)
#endif
#pragma warning(push, 1)
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1920)
typedef __int64 utest_int64_t;
typedef unsigned __int64 utest_uint64_t;
typedef unsigned __int32 utest_uint32_t;
#else
#include <stdint.h>
typedef int64_t utest_int64_t;
typedef uint64_t utest_uint64_t;
typedef uint32_t utest_uint32_t;
#endif
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#if defined(__cplusplus)
#if defined(_MSC_VER) && !defined(_CPPUNWIND)
/* We're on MSVC and the compiler is compiling without exception support! */
#elif !defined(_MSC_VER) && !defined(__EXCEPTIONS)
/* We're on a GCC/Clang compiler that doesn't have exception support! */
#else
#define UTEST_HAS_EXCEPTIONS 1
#endif
#endif
#if defined(UTEST_HAS_EXCEPTIONS)
#include <stdexcept>
#endif
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#if defined(__cplusplus)
#define UTEST_C_FUNC extern "C"
#else
#define UTEST_C_FUNC
#endif
#define UTEST_TEST_PASSED (0)
#define UTEST_TEST_FAILURE (1)
#define UTEST_TEST_SKIPPED (2)
#if defined(__TINYC__)
#define UTEST_ATTRIBUTE(a) __attribute((a))
#else
#define UTEST_ATTRIBUTE(a) __attribute__((a))
#endif
#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
#if defined(__MINGW64__) || defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#endif
#if defined(_WINDOWS_) || defined(_WINDOWS_H)
typedef LARGE_INTEGER utest_large_integer;
#else
// use old QueryPerformanceCounter definitions (not sure is this needed in some
// edge cases or not) on Win7 with VS2015 these extern declaration cause "second
// C linkage of overloaded function not allowed" error
typedef union {
struct {
unsigned long LowPart;
long HighPart;
} DUMMYSTRUCTNAME;
struct {
unsigned long LowPart;
long HighPart;
} u;
utest_int64_t QuadPart;
} utest_large_integer;
UTEST_C_FUNC __declspec(dllimport) int __stdcall QueryPerformanceCounter(
utest_large_integer *);
UTEST_C_FUNC __declspec(dllimport) int __stdcall QueryPerformanceFrequency(
utest_large_integer *);
#if defined(__MINGW64__) || defined(__MINGW32__)
#pragma GCC diagnostic pop
#endif
#endif
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__NetBSD__) || defined(__DragonFly__) || defined(__sun__) || \
defined(__HAIKU__)
/*
slightly obscure include here - we need to include glibc's features.h, but
we don't want to just include a header that might not be defined for other
c libraries like musl. Instead we include limits.h, which we know on all
glibc distributions includes features.h
*/
#include <limits.h>
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
#include <time.h>
#if ((2 < __GLIBC__) || ((2 == __GLIBC__) && (17 <= __GLIBC_MINOR__)))
/* glibc is version 2.17 or above, so we can just use clock_gettime */
#define UTEST_USE_CLOCKGETTIME
#else
#include <sys/syscall.h>
#include <unistd.h>
#endif
#else // Other libc implementations
#include <time.h>
#define UTEST_USE_CLOCKGETTIME
#endif
#elif defined(__APPLE__)
#include <time.h>
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1920)
#define UTEST_PRId64 "I64d"
#define UTEST_PRIu64 "I64u"
#else
#include <inttypes.h>
#define UTEST_PRId64 PRId64
#define UTEST_PRIu64 PRIu64
#endif
#if defined(__cplusplus)
#define UTEST_INLINE inline
#if defined(__clang__)
#define UTEST_INITIALIZER_BEGIN_DISABLE_WARNINGS \
_Pragma("clang diagnostic push")
|