2021-03-12 14:44:21 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2024-01-01 08:19:59 +00:00
|
|
|
// Copyright 2013-2024 by Wilson Snyder. This program is free software; you can
|
2021-03-12 14:44:21 +00:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
#ifndef TEST_CHECK_H_
|
|
|
|
#define TEST_CHECK_H_
|
|
|
|
|
2023-12-20 00:22:54 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2021-03-12 16:25:42 +00:00
|
|
|
extern int errors;
|
2021-03-12 14:44:21 +00:00
|
|
|
|
|
|
|
#ifdef TEST_VERBOSE
|
2021-03-12 17:37:26 +00:00
|
|
|
static const bool verbose = true;
|
2021-03-12 14:44:21 +00:00
|
|
|
#else
|
2021-03-12 17:37:26 +00:00
|
|
|
static const bool verbose = false;
|
2021-03-12 14:44:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
|
|
|
|
// Use cout to avoid issues with %d/%lx etc
|
2021-03-12 16:25:42 +00:00
|
|
|
#define TEST_CHECK(got, exp, test) \
|
2021-03-12 17:37:26 +00:00
|
|
|
do { \
|
|
|
|
if (!(test)) { \
|
|
|
|
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ \
|
|
|
|
<< ": GOT = " << (got) << " EXP = " << (exp) << std::endl; \
|
|
|
|
++errors; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2021-03-12 16:25:42 +00:00
|
|
|
#define TEST_CHECK_EQ(got, exp) TEST_CHECK(got, exp, ((got) == (exp)));
|
2021-03-12 17:37:26 +00:00
|
|
|
#define TEST_CHECK_NE(got, exp) TEST_CHECK(got, exp, ((got) != (exp)));
|
2022-09-15 01:10:19 +00:00
|
|
|
#define TEST_CHECK_CSTR(got, exp) TEST_CHECK(got, exp, 0 == std::strcmp((got), (exp)));
|
2021-03-12 17:37:26 +00:00
|
|
|
|
|
|
|
#define TEST_CHECK_HEX_EQ(got, exp) \
|
|
|
|
do { \
|
|
|
|
if ((got) != (exp)) { \
|
|
|
|
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
|
|
|
|
<< ": GOT=" << (got) << " EXP=" << (exp) << std::endl; \
|
|
|
|
++errors; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define TEST_CHECK_HEX_NE(got, exp) \
|
|
|
|
do { \
|
|
|
|
if ((got) == (exp)) { \
|
|
|
|
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
|
|
|
|
<< ": GOT=" << (got) << " EXP!=" << (exp) << std::endl; \
|
|
|
|
++errors; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2021-05-07 11:17:54 +00:00
|
|
|
#define TEST_CHECK_Z(got) \
|
|
|
|
do { \
|
|
|
|
if ((got)) { \
|
|
|
|
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
|
|
|
|
<< ": GOT!= NULL EXP=NULL" << std::endl; \
|
|
|
|
++errors; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2021-03-12 17:37:26 +00:00
|
|
|
#define TEST_CHECK_NZ(got) \
|
|
|
|
do { \
|
|
|
|
if (!(got)) { \
|
|
|
|
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
|
|
|
|
<< ": GOT= NULL EXP!=NULL" << std::endl; \
|
|
|
|
++errors; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2023-10-25 00:46:20 +00:00
|
|
|
#define TEST_CHECK_REAL_EQ(got, exp, delta) \
|
|
|
|
do { \
|
|
|
|
if (std::fabs(got - exp) > delta) { \
|
|
|
|
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::showpoint \
|
|
|
|
<< ": GOT=" << (got) << " EXP=" << (exp) << " +/- " << (delta) \
|
|
|
|
<< std::endl; \
|
|
|
|
++errors; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2021-03-12 17:37:26 +00:00
|
|
|
//======================================================================
|
2021-03-12 14:44:21 +00:00
|
|
|
|
|
|
|
#define TEST_VERBOSE_PRINTF(format, ...) \
|
|
|
|
do { \
|
|
|
|
if (verbose) printf(format, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#endif // Guard
|