Debian Codegraph @

utest/utest_tools.c

raw
1 /*
2 * boxes - Command line filter to draw/remove ASCII boxes around text
3 * Copyright (c) 1999-2024 Thomas Jensen and the boxes contributors
4 *
5 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
6 * License, version 3, as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
8 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
9 * details.
10 * You should have received a copy of the GNU General Public License along with this program.
11 * If not, see <https://www.gnu.org/licenses/>.
12 *
13 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
14 */
15
16 /*
17 * Helper functions for all the unit tests.
18 */
19
20 #include "config.h"
21
22 #include <setjmp.h>
23 #include <stdarg.h>
24 #include <stddef.h>
25
26 #include <cmocka.h>
27 #include <stdio.h>
28
29 #include "utest_tools.h"
30
31
32
33 void assert_array_equal(int p_expected[], size_t *p_actual, size_t p_len_expected)
34 {
35 if (p_expected == NULL && p_actual == NULL) {
36 assert_int_equal(0, p_len_expected);
37 return;
38 }
39 if (p_expected == NULL) {
40 assert_null(p_actual);
41 assert_int_equal(0, p_len_expected);
42 }
43 if (p_actual == NULL) {
44 assert_null(p_expected);
45 assert_int_equal(0, p_len_expected);
46 }
47
48 for (size_t i = 0; i < p_len_expected; i++) {
49 assert_int_equal(p_expected[i], (int) p_actual[i]);
50 }
51 }
52
53
54
55 void print_array_i(int p_array[], size_t p_len)
56 {
57 if (p_array != NULL) {
58 printf("[");
59 for (size_t i = 0; i < p_len; i++) {
60 printf("%d%s", p_array[i], i < p_len - 1 ? ", " : "");
61 }
62 printf("]\n");
63 }
64 else {
65 printf("NULL\n");
66 }
67 }
68
69
70
71 void print_array_s(size_t p_array[], size_t p_len)
72 {
73 if (p_array != NULL) {
74 printf("[");
75 for (size_t i = 0; i < p_len; i++) {
76 printf("%d%s", (int) p_array[i], i < p_len - 1 ? ", " : "");
77 }
78 printf("]\n");
79 }
80 else {
81 printf("NULL\n");
82 }
83 }
84
85
86 /* vim: set cindent sw=4: */