11c235774Smrg/*
21c235774Smrg * Copyright (c) 2023, Oracle and/or its affiliates.
31c235774Smrg *
41c235774Smrg * Permission is hereby granted, free of charge, to any person obtaining a
51c235774Smrg * copy of this software and associated documentation files (the "Software"),
61c235774Smrg * to deal in the Software without restriction, including without limitation
71c235774Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81c235774Smrg * and/or sell copies of the Software, and to permit persons to whom the
91c235774Smrg * Software is furnished to do so, subject to the following conditions:
101c235774Smrg *
111c235774Smrg * The above copyright notice and this permission notice (including the next
121c235774Smrg * paragraph) shall be included in all copies or substantial portions of the
131c235774Smrg * Software.
141c235774Smrg *
151c235774Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161c235774Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171c235774Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181c235774Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191c235774Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201c235774Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211c235774Smrg * DEALINGS IN THE SOFTWARE.
221c235774Smrg */
231c235774Smrg
241c235774Smrg#include "config.h"
251c235774Smrg
261c235774Smrg#include <X11/xpm.h>
271c235774Smrg#include <glib.h>
281c235774Smrg
291c235774Smrg/*
301c235774Smrg * XpmAttributesSize - report size of XpmAttributes structure
311c235774Smrg */
321c235774Smrg
331c235774Smrgstatic void
341c235774Smrgtest_XpmAttributesSize(void)
351c235774Smrg{
361c235774Smrg    int size = XpmAttributesSize();
371c235774Smrg    g_assert_cmpint(size, ==, sizeof(XpmAttributes));
381c235774Smrg}
391c235774Smrg
401c235774Smrg/*
411c235774Smrg * XpmGetErrorString - return string describing error code
421c235774Smrg */
431c235774Smrg
441c235774Smrgstatic void
451c235774Smrgtest_XpmGetErrorString(void)
461c235774Smrg{
471c235774Smrg    const char *es;
481c235774Smrg
491c235774Smrg#define TestErrorString(num, str) \
501c235774Smrg    es = XpmGetErrorString(num); \
511c235774Smrg    g_assert_nonnull(es); \
521c235774Smrg    g_assert_cmpstr(es, ==, str)
531c235774Smrg
541c235774Smrg    TestErrorString(XpmColorError, "XpmColorError");
551c235774Smrg    TestErrorString(XpmSuccess, "XpmSuccess");
561c235774Smrg    TestErrorString(XpmOpenFailed, "XpmOpenFailed");
571c235774Smrg    TestErrorString(XpmFileInvalid, "XpmFileInvalid");
581c235774Smrg    TestErrorString(XpmNoMemory, "XpmNoMemory");
591c235774Smrg    TestErrorString(XpmColorFailed, "XpmColorFailed");
601c235774Smrg    TestErrorString(128, "Invalid XpmError");
611c235774Smrg    TestErrorString(-42, "Invalid XpmError");
621c235774Smrg
631c235774Smrg#undef TestErrorString
641c235774Smrg}
651c235774Smrg
661c235774Smrg/*
671c235774Smrg * XpmLibraryVersion - report version of library
681c235774Smrg */
691c235774Smrg
701c235774Smrgstatic void
711c235774Smrgtest_XpmLibraryVersion(void)
721c235774Smrg{
731c235774Smrg    int version = XpmLibraryVersion();
741c235774Smrg    g_assert_cmpint(version, ==, XpmIncludeVersion);
751c235774Smrg}
761c235774Smrg
771c235774Smrgint
781c235774Smrgmain(int argc, char** argv)
791c235774Smrg{
801c235774Smrg    g_test_init(&argc, &argv, NULL);
8174835918Smrg    g_test_bug_base(PACKAGE_BUGREPORT);
821c235774Smrg
831c235774Smrg    g_test_add_func("/XpmMisc/XpmAttributesSize",
841c235774Smrg                    test_XpmAttributesSize);
851c235774Smrg    g_test_add_func("/XpmMisc/XpmGetErrorString",
861c235774Smrg                    test_XpmGetErrorString);
871c235774Smrg    g_test_add_func("/XpmMisc/XpmLibraryVersion",
881c235774Smrg                    test_XpmLibraryVersion);
891c235774Smrg
901c235774Smrg    return g_test_run();
911c235774Smrg}
92