Loading...
Searching...
No Matches
cppunit_expect.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Jens Wetterich <jens@wetterich-net.de>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
16#ifndef CPPUNIT_EXPECT_H
17#define CPPUNIT_EXPECT_H
18#if __cplusplus >= 201103L || defined(DOXYGEN)
26#define EXPECT_EQ(expected, actual, msg) \
27 static_assert(std::is_integral<decltype(expected)>::value, \
28 "EXPECT_EQ requires an integral type "); \
29 if ((actual) != (expected)) { \
30 fail(); \
31 if (std::is_same<decltype(expected), bool>::value) { \
32 printf("Expected: %s, actual: %s\n" msg "\n", (expected) ? "true" : "false", \
33 (actual) ? "true" : "false"); \
34 } \
35 else if (std::is_unsigned<decltype(expected)>::value) { \
36 printf("Expected: %u, actual: %u\n" msg "\n", static_cast<unsigned>(expected), \
37 static_cast<unsigned>(actual)); \
38 } \
39 else { \
40 printf("Expected: %d, actual: %d\n" msg "\n", static_cast<int>(expected), \
41 static_cast<int>(actual)); \
42 } \
43 }
52#define EXPECT_STREQ(expected, actual, msg) \
53 auto expected_str = static_cast<const char*>(expected); \
54 auto actual_str = static_cast<const char*>(actual); \
55 if (strcmp(expected_str, actual_str) != 0) { \
56 fail(); \
57 printf(msg " not equal! Expected: %s, actual: %s\n", expected_str, actual_str); \
58 }
59#else
60#error This library needs C++11 and newer
61#endif
62#endif