File: utest_tools.c

package info (click to toggle)
boxes 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,800 kB
  • sloc: ansic: 10,566; lex: 517; sh: 503; makefile: 309; yacc: 272; lisp: 78
file content (86 lines) | stat: -rw-r--r-- 2,224 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * boxes - Command line filter to draw/remove ASCII boxes around text
 * Copyright (c) 1999-2024 Thomas Jensen and the boxes contributors
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License, version 3, as published by the Free Software Foundation.
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */

/*
 * Helper functions for all the unit tests.
 */

#include "config.h"

#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>

#include <cmocka.h>
#include <stdio.h>

#include "utest_tools.h"



void assert_array_equal(int p_expected[], size_t *p_actual, size_t p_len_expected)
{
    if (p_expected == NULL && p_actual == NULL) {
        assert_int_equal(0, p_len_expected);
        return;
    }
    if (p_expected == NULL) {
        assert_null(p_actual);
        assert_int_equal(0, p_len_expected);
    }
    if (p_actual == NULL) {
        assert_null(p_expected);
        assert_int_equal(0, p_len_expected);
    }

    for (size_t i = 0; i < p_len_expected; i++) {
        assert_int_equal(p_expected[i], (int) p_actual[i]);
    }
}



void print_array_i(int p_array[], size_t p_len)
{
    if (p_array != NULL) {
        printf("[");
        for (size_t i = 0; i < p_len; i++) {
            printf("%d%s", p_array[i], i < p_len - 1 ? ", " : "");
        }
        printf("]\n");
    }
    else {
        printf("NULL\n");
    }
}



void print_array_s(size_t p_array[], size_t p_len)
{
    if (p_array != NULL) {
        printf("[");
        for (size_t i = 0; i < p_len; i++) {
            printf("%d%s", (int) p_array[i], i < p_len - 1 ? ", " : "");
        }
        printf("]\n");
    }
    else {
        printf("NULL\n");
    }
}


/* vim: set cindent sw=4: */