File: cpl_msg-test.c

package info (click to toggle)
cpl 7.3.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,396 kB
  • sloc: ansic: 142,902; javascript: 6,382; sh: 4,452; makefile: 661
file content (137 lines) | stat: -rw-r--r-- 4,705 bytes parent folder | download | duplicates (3)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * This file is part of the ESO Common Pipeline Library
 * Copyright (C) 2001-2022 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */


/*-----------------------------------------------------------------------------
                                   Includes
 -----------------------------------------------------------------------------*/

#include "cpl_msg.h"
#include "cpl_test.h"
#include "cpl_memory.h"

#include <string.h>

/*-----------------------------------------------------------------------------
                                   Defines
 -----------------------------------------------------------------------------*/

#ifndef STR_LENGTH
#define STR_LENGTH 80
#endif

/*-----------------------------------------------------------------------------
                                  Main
 -----------------------------------------------------------------------------*/
int
main(void)
{
    char message[STR_LENGTH + 1];
    char toolong[CPL_MAX_MSG_LENGTH];
    char *verylongname = NULL;
    int verylongnamesize = 1024 * 1024;
    int nindent = 0;
    cpl_msg_severity loglevel = CPL_MSG_OFF;

    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);

    /* Insert tests below */

    /* Construct the null-terminated string of STR_LENGTH dots */
    (void)memset((void *)message, '.', STR_LENGTH);
    message[STR_LENGTH] = '\0';

    /* - and display it */
    cpl_msg_info(cpl_func, "Display a string of %d dots: %s", STR_LENGTH,
                 message);
    cpl_msg_info(cpl_func, "Domain is: %s", cpl_msg_get_domain());

    cpl_msg_indent_more();
    nindent++;
    cpl_msg_info(cpl_func, "hhu: %hhu\n", (unsigned char)-1);
    cpl_msg_indent_more();
    nindent++;
    cpl_msg_info(cpl_func, "hhd: %hhd\n", (char)-1);
    cpl_msg_indent_more();
    nindent++;
    cpl_msg_info(cpl_func, "zu: %zu\n", sizeof(size_t));
    cpl_msg_indent_more();
    nindent++;
    cpl_msg_info(cpl_func, "td: %td\n", (__func__) - (__func__ + 2));
    cpl_msg_indent_more();
    nindent++;
    cpl_msg_info(cpl_func, "llu: %llu\n", (unsigned long long)-1);
    cpl_msg_indent_more();
    nindent++;
    cpl_msg_info(cpl_func, "lld: %lld\n", (long long)-1);
    cpl_msg_indent_more();
    nindent++;

    /* Test a too long message */

    /* Construct the null-terminated string of STR_LENGTH dots */
    (void)memset((void *)toolong, '.', CPL_MAX_MSG_LENGTH - 1);
    toolong[CPL_MAX_MSG_LENGTH - 1] = '\0';

    cpl_msg_info(cpl_func, "Display a string of %d dots: %s",
                 CPL_MAX_MSG_LENGTH - 1, toolong);

    cpl_msg_set_time_on();

    for (; nindent; nindent--)
        cpl_msg_indent_less(); /* Undo the indenting */

    /* Construct a very long null-terminated string of 'A' characters */
    verylongname = (char *)cpl_malloc(verylongnamesize);
    cpl_test_nonnull(verylongname);
    (void)memset((void *)verylongname, 'A', verylongnamesize - 1);
    verylongname[verylongnamesize - 1] = '\0';

    loglevel = cpl_msg_get_level();
    cpl_msg_set_level(CPL_MSG_OFF);
    cpl_msg_debug(verylongname, "test for long component name");
    cpl_msg_set_level(loglevel);
    cpl_test_error(CPL_ERROR_NONE);
    cpl_msg_set_level(CPL_MSG_OFF);
    cpl_msg_info(verylongname, "test for long component name");
    cpl_msg_set_level(loglevel);
    cpl_msg_set_level(loglevel);
    cpl_test_error(CPL_ERROR_NONE);
    cpl_msg_set_level(CPL_MSG_OFF);
    cpl_msg_warning(verylongname, "test for long component name");
    cpl_msg_set_level(loglevel);
    cpl_test_error(CPL_ERROR_NONE);
    cpl_msg_set_level(CPL_MSG_OFF);
    cpl_msg_error(verylongname, "test for long component name");
    cpl_msg_set_level(loglevel);
    cpl_test_error(CPL_ERROR_NONE);

#ifdef CPL_MSG_TEST_DEPRECATED
    for (int i = 0; i < 1000; i++) {
        CPL_DIAG_PRAGMA_PUSH_IGN(-Wdeprecated-declarations);
        cpl_msg_progress(cpl_func, i, 1000, "test: %d/%d", i, 1000);
        CPL_DIAG_PRAGMA_POP;
    }
#endif

    cpl_free(verylongname);

    /* End of tests */
    return cpl_test_end(0);
}