0792a10e2f9d97c8d1655b6d805c8a4dbdd638a6
[lttng-ust.git] / tests / unit / ust-utils / ust-utils-common.h
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
3 *
4 * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
5 */
6
7 #include "tap.h"
8
9 #define NUM_TESTS 60
10
11 static
12 void test_ust_stringify(void)
13 {
14 ok(strcmp(lttng_ust_stringify(1), "1") == 0, "lttng_ust_stringify - literal integer");
15 ok(strcmp(lttng_ust_stringify(random_identifier), "random_identifier") == 0, "lttng_ust_stringify - identifier");
16 }
17
18 #define ok_is_signed(_type) \
19 ok(lttng_ust_is_signed_type(_type) == true, "lttng_ust_is_signed_type - '" lttng_ust_stringify(_type) "' is signed")
20
21 #define ok_is_unsigned(_type) \
22 ok(lttng_ust_is_signed_type(_type) == false, "lttng_ust_is_signed_type - '" lttng_ust_stringify(_type) "' is unsigned")
23
24 static
25 void test_ust_is_signed(void)
26 {
27 /*
28 * Signed types
29 */
30
31 ok_is_signed(signed char);
32 ok_is_signed(short);
33 ok_is_signed(int);
34 ok_is_signed(long);
35 ok_is_signed(long long);
36 ok_is_signed(float);
37 ok_is_signed(double);
38 ok_is_signed(long double);
39
40 ok_is_signed(int8_t);
41 ok_is_signed(int16_t);
42 ok_is_signed(int32_t);
43 ok_is_signed(int64_t);
44 ok_is_signed(intmax_t);
45
46 ok_is_signed(ssize_t);
47 ok_is_signed(ptrdiff_t);
48 ok_is_signed(intptr_t);
49
50 /*
51 * Unsigned types
52 */
53
54 ok_is_unsigned(unsigned char);
55 ok_is_unsigned(unsigned short);
56 ok_is_unsigned(unsigned int);
57 ok_is_unsigned(unsigned long);
58 ok_is_unsigned(unsigned long long);
59
60 ok_is_unsigned(uint8_t);
61 ok_is_unsigned(uint16_t);
62 ok_is_unsigned(uint32_t);
63 ok_is_unsigned(uint64_t);
64 ok_is_unsigned(uintmax_t);
65
66 ok_is_unsigned(bool);
67 ok_is_unsigned(size_t);
68
69 ok_is_unsigned(void *);
70 }
71
72
73 #define ok_is_integer_type(_type) \
74 ok(lttng_ust_is_integer_type(_type) == true, "lttng_ust_is_integer_type - '" lttng_ust_stringify(_type) "' is an integer")
75
76 #define ok_is_not_integer_type(_type) \
77 ok(lttng_ust_is_integer_type(_type) == false, "lttng_ust_is_integer_type - '" lttng_ust_stringify(_type) "' is not an integer")
78
79 static
80 void test_ust_is_integer_type(void)
81 {
82 ok_is_integer_type(char);
83 ok_is_integer_type(short);
84 ok_is_integer_type(int);
85 ok_is_integer_type(long);
86 ok_is_integer_type(long long);
87
88 ok_is_integer_type(signed char);
89 ok_is_integer_type(signed short);
90 ok_is_integer_type(signed int);
91 ok_is_integer_type(signed long);
92 ok_is_integer_type(signed long long);
93
94 ok_is_integer_type(unsigned char);
95 ok_is_integer_type(unsigned short);
96 ok_is_integer_type(unsigned int);
97 ok_is_integer_type(unsigned long);
98 ok_is_integer_type(unsigned long long);
99
100 ok_is_integer_type(int8_t);
101 ok_is_integer_type(int16_t);
102 ok_is_integer_type(int32_t);
103 ok_is_integer_type(int64_t);
104 ok_is_integer_type(intmax_t);
105
106 ok_is_integer_type(uint8_t);
107 ok_is_integer_type(uint16_t);
108 ok_is_integer_type(uint32_t);
109 ok_is_integer_type(uint64_t);
110 ok_is_integer_type(uintmax_t);
111
112 ok_is_not_integer_type(float);
113 ok_is_not_integer_type(double);
114 ok_is_not_integer_type(long double);
115
116 ok_is_not_integer_type(void *);
117 }
118
119 int main(void)
120 {
121 plan_tests(NUM_TESTS);
122
123 test_ust_stringify();
124 test_ust_is_signed();
125 test_ust_is_integer_type();
126
127 return exit_status();
128 }
This page took 0.03477 seconds and 3 git commands to generate.