11bedbe3fSmrg/*
200ca1914Smrg * Copyright (c) 2011, Oracle and/or its affiliates.
31bedbe3fSmrg *
41bedbe3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
51bedbe3fSmrg * copy of this software and associated documentation files (the "Software"),
61bedbe3fSmrg * to deal in the Software without restriction, including without limitation
71bedbe3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81bedbe3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
91bedbe3fSmrg * Software is furnished to do so, subject to the following conditions:
101bedbe3fSmrg *
111bedbe3fSmrg * The above copyright notice and this permission notice (including the next
121bedbe3fSmrg * paragraph) shall be included in all copies or substantial portions of the
131bedbe3fSmrg * Software.
141bedbe3fSmrg *
151bedbe3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161bedbe3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171bedbe3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181bedbe3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191bedbe3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201bedbe3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211bedbe3fSmrg * DEALINGS IN THE SOFTWARE.
221bedbe3fSmrg */
231bedbe3fSmrg
241bedbe3fSmrg/*
251bedbe3fSmrg  Simple test case for FSGetErrorText.
261bedbe3fSmrg  When run with arguments, prints messages for the given codes.
271bedbe3fSmrg  When run with no arguments, prints messages for known valid error codes
281bedbe3fSmrg  and some invalid codes.
291bedbe3fSmrg*/
301bedbe3fSmrg
311bedbe3fSmrg#include <stdio.h>
321bedbe3fSmrg#include <stdlib.h>
331bedbe3fSmrg#include <errno.h>
341bedbe3fSmrg#include <X11/fonts/FSlib.h>
351bedbe3fSmrg
361bedbe3fSmrgstatic int
371bedbe3fSmrgCheckErrorMessage(FSServer *srv, int code, const char *codestr)
381bedbe3fSmrg{
391bedbe3fSmrg    char buf[128] = "";
401bedbe3fSmrg
411bedbe3fSmrg    if (!FSGetErrorText(srv, code, buf, sizeof(buf))) {
421bedbe3fSmrg	fprintf(stderr, "FSGetErrorText(srv, %s (%d), buf, %d) failed",
431bedbe3fSmrg		codestr, code, (int) sizeof(buf));
441bedbe3fSmrg	return 0;
451bedbe3fSmrg    }
461bedbe3fSmrg
471bedbe3fSmrg    printf("FSGetErrorText for code %s (%d) returned:\n|%s|\n\n",
481bedbe3fSmrg	   codestr, code, buf);
491bedbe3fSmrg    return 1;
501bedbe3fSmrg}
511bedbe3fSmrg
521bedbe3fSmrg#define CheckNamedErrorMessage(s, e) \
531bedbe3fSmrg    CheckErrorMessage(s, e, #e)
541bedbe3fSmrg
551bedbe3fSmrgint main(int argc, char **argv)
561bedbe3fSmrg{
571bedbe3fSmrg    FSServer *srv = FSOpenServer(NULL);
581bedbe3fSmrg
591bedbe3fSmrg    if (srv == NULL) {
601bedbe3fSmrg	fprintf(stderr, "Failed to open fontserver connection to: %s\n"
611bedbe3fSmrg	"Aborting test. Make sure FONTSERVER is set to a valid xfs server.\n",
621bedbe3fSmrg		FSServerName(NULL));
631bedbe3fSmrg	exit(1);
641bedbe3fSmrg    }
651bedbe3fSmrg
661bedbe3fSmrg    if (argc > 1) {
671bedbe3fSmrg	int i;
681bedbe3fSmrg
691bedbe3fSmrg	for (i = 1; i < argc; i++) {
701bedbe3fSmrg	    int c;
711bedbe3fSmrg	    errno = 0;
721bedbe3fSmrg	    c = strtol(argv[i], NULL, 0);
731bedbe3fSmrg	    if (errno != 0) {
741bedbe3fSmrg		perror(argv[i]);
751bedbe3fSmrg		exit(1);
761bedbe3fSmrg	    }
771bedbe3fSmrg	    CheckErrorMessage (srv, c, "");
781bedbe3fSmrg	}
791bedbe3fSmrg	exit (0);
801bedbe3fSmrg    }
811bedbe3fSmrg
821bedbe3fSmrg    /* Default list to check if no arguments specified */
831bedbe3fSmrg    CheckNamedErrorMessage(srv, FSSuccess);
841bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadRequest);
851bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadFormat);
861bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadFont);
871bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadRange);
881bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadEventMask);
891bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadAccessContext);
901bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadIDChoice);
911bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadName);
921bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadResolution);
931bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadAlloc);
941bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadLength);
951bedbe3fSmrg    CheckNamedErrorMessage(srv, FSBadImplementation);
961bedbe3fSmrg    CheckErrorMessage (srv, 12, "<out of range value>");
971bedbe3fSmrg    CheckErrorMessage (srv, 256, "<out of range value>");
981bedbe3fSmrg    CheckErrorMessage (srv, 0xffff, "<out of range value>");
991bedbe3fSmrg
1001bedbe3fSmrg    exit(0);
1011bedbe3fSmrg}
102