Debian Codegraph @

test/XpmMisc.c

raw
1 /*
2 * Copyright (c) 2023, Oracle and/or its affiliates.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "config.h"
25
26 #include <X11/xpm.h>
27 #include <glib.h>
28
29 /*
30 * XpmAttributesSize - report size of XpmAttributes structure
31 */
32
33 static void
34 test_XpmAttributesSize(void)
35 {
36 int size = XpmAttributesSize();
37 g_assert_cmpint(size, ==, sizeof(XpmAttributes));
38 }
39
40 /*
41 * XpmGetErrorString - return string describing error code
42 */
43
44 static void
45 test_XpmGetErrorString(void)
46 {
47 const char *es;
48
49 #define TestErrorString(num, str) \
50 es = XpmGetErrorString(num); \
51 g_assert_nonnull(es); \
52 g_assert_cmpstr(es, ==, str)
53
54 TestErrorString(XpmColorError, "XpmColorError");
55 TestErrorString(XpmSuccess, "XpmSuccess");
56 TestErrorString(XpmOpenFailed, "XpmOpenFailed");
57 TestErrorString(XpmFileInvalid, "XpmFileInvalid");
58 TestErrorString(XpmNoMemory, "XpmNoMemory");
59 TestErrorString(XpmColorFailed, "XpmColorFailed");
60 TestErrorString(128, "Invalid XpmError");
61 TestErrorString(-42, "Invalid XpmError");
62
63 #undef TestErrorString
64 }
65
66 /*
67 * XpmLibraryVersion - report version of library
68 */
69
70 static void
71 test_XpmLibraryVersion(void)
72 {
73 int version = XpmLibraryVersion();
74 g_assert_cmpint(version, ==, XpmIncludeVersion);
75 }
76
77 int
78 main(int argc, char** argv)
79 {
80 g_test_init(&argc, &argv, NULL);
81 g_test_bug_base(PACKAGE_BUGREPORT);
82
83 g_test_add_func("/XpmMisc/XpmAttributesSize",
84 test_XpmAttributesSize);
85 g_test_add_func("/XpmMisc/XpmGetErrorString",
86 test_XpmGetErrorString);
87 g_test_add_func("/XpmMisc/XpmLibraryVersion",
88 test_XpmLibraryVersion);
89
90 return g_test_run();
91 }