File: check_compat.h

package info (click to toggle)
libtoxcore 0.2.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,992 kB
  • sloc: ansic: 70,235; cpp: 14,770; sh: 1,576; python: 649; makefile: 255; perl: 39
file content (59 lines) | stat: -rw-r--r-- 3,568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
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
#ifndef C_TOXCORE_AUTO_TESTS_CHECK_COMPAT_H
#define C_TOXCORE_AUTO_TESTS_CHECK_COMPAT_H

#include "../toxcore/ccompat.h"

#include <stdio.h>
#include <stdlib.h>

#ifndef ck_assert
#define ck_assert(ok)                                                         \
    do {                                                                      \
        if (!(ok)) {                                                          \
            fprintf(stderr, "%s:%d: failed `%s'\n", __FILE__, __LINE__, #ok); \
            exit(7);                                                          \
        }                                                                     \
    } while (0)

#define ck_assert_msg(ok, ...)                                                \
    do {                                                                      \
        if (!(ok)) {                                                          \
            fprintf(stderr, "%s:%d: failed `%s': ", __FILE__, __LINE__, #ok); \
            fprintf(stderr, __VA_ARGS__);                                     \
            fprintf(stderr, "\n");                                            \
            exit(7);                                                          \
        }                                                                     \
    } while (0)

#define ck_assert_int_eq(a, b)                                                                   \
    do {                                                                                         \
        const int32_t _a = (a);                                                                  \
        const int32_t _b = (b);                                                                  \
        if (_a != _b) {                                                                          \
            fprintf(stderr, "%s:%d: failed `%s == %s` (%d != %d)\n", __FILE__, __LINE__, #a, #b, \
                _a, _b);                                                                         \
            exit(7);                                                                             \
        }                                                                                        \
    } while (0)

#define ck_assert_uint_eq(a, b)                                                                  \
    do {                                                                                         \
        const uint32_t _a = (a);                                                                 \
        const uint32_t _b = (b);                                                                 \
        if (_a != _b) {                                                                          \
            fprintf(stderr, "%s:%d: failed `%s == %s` (%u != %u)\n", __FILE__, __LINE__, #a, #b, \
                _a, _b);                                                                         \
            exit(7);                                                                             \
        }                                                                                        \
    } while (0)

#define ck_abort_msg(...)                               \
    do {                                                \
        fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
        fprintf(stderr, __VA_ARGS__);                   \
        fprintf(stderr, "\n");                          \
        exit(7);                                        \
    } while (0)
#endif

#endif // C_TOXCORE_AUTO_TESTS_CHECK_COMPAT_H