summaryrefslogtreecommitdiff
path: root/xc/unsupported/test/suspex/testcases/fnt_hp/fnt_err.c
blob: 140a50ba73c843a033d3a4093c34424e35812fca (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* $XConsortium$ */

/******************************************************************************/
/*                                                                            */
/*  (c) Copyright Hewlett-Packard Company, 1993, Fort Collins, Colorado       */
/*                                                                            */
/*                            All Rights Reserved                             */
/*                                                                            */
/*  Permission to use, copy, modify, and distribute this software and its     */
/*  documentation for any purpose and without fee is hereby granted,          */
/*  provided that the above copyright notices appear in all copies and that   */
/*  both the copyright notices and this permission notice appear in           */
/*  supporting documentation, and that the name of Hewlett-Packard not be     */
/*  used in advertising or publicity pertaining to distribution of the        */
/*  software without specific, written prior permission.                      */
/*                                                                            */
/*  HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS         */
/*  SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Hewlett-Packard    */
/*  shall not be liable for errors contained herein or direct, indirect,      */
/*  special, incidental or consequential damages in connection with the       */
/*  furnishing, performance or use of this software.                          */
/*                                                                            */
/******************************************************************************/

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/PEX5/PEXlib.h>
#include <misc.h>

Window local_win;

void font_errors(Display *display, Window window)
    {
    PEXLookupTable lut;

    XSynchronize(display, True);

    _hppex_stderr_print("font name doesn't exist\n");
    {
	PEXFont font = PEXLoadFont(display, "foo");

	_hppex_stderr_print("unload null font\n");
	PEXUnloadFont(display, font);
    }

    lut = PEXCreateLookupTable(display, window, PEXLUTTextFont);
 
    _hppex_stderr_print("unload non-font resource\n");
    PEXUnloadFont(display, lut);

    _hppex_stderr_print("query non-font resource\n");
    PEXQueryFont(display, lut);

    {
	unsigned long count;
	char **names = PEXListFonts(display, "*", 1, &count);
	PEXFont font = PEXLoadFont(display, *names);
	PEXTextFontEntry entry, *ret;
	int table_type;

	XFree(names);

	entry.count = 1;
	entry.fonts = &font;
	PEXSetTableEntries(display, lut, 1, 1, PEXLUTTextFont,
			   &entry);

	PEXUnloadFont(display, font);

	_hppex_stderr_print("unload same font twice\n");
	PEXUnloadFont(display, font);

	PEXGetTableEntries(display, lut, 1, 1, PEXSetValue,
			   &table_type, (PEXPointer *)&ret);

	_hppex_stderr_print("pass bogus pointer to unload\n");
	PEXUnloadFont(display, (PEXFont)ret);
	_hppex_stderr_print("unload already freed font\n");
	PEXUnloadFont(display, *ret->fonts);

	PEXFreeTableEntries(PEXLUTTextFont, 1, ret);
    }

    /*
      QueryTextExtent, QueryEncodedTextExtent
    */
    {
	unsigned long count;
	char **names = PEXListFonts(display, "*", 1, &count);
	PEXFont font = PEXLoadFont(display, *names);
	PEXTextExtent *extent;
	PEXStringData text;

	text.ch = "foo";
	text.length = strlen(text.ch);

	/*
	  bad resource id
	*/
	_hppex_stderr_print("null resource id\n");
	extent = PEXQueryTextExtents(display, 0, 1, PEXPathRight,
				     1.0, 0.0, 0.01,
				     PEXHAlignNormal, PEXVAlignNormal,
				     1, &text);
	_hppex_stderr_print("non-LUT resource id\n");
	extent = PEXQueryTextExtents(display, font, 1, PEXPathRight,
				     1.0, 0.0, 0.01,
				     PEXHAlignNormal, PEXVAlignNormal,
				     1, &text);

	/*
	  bad path
	*/
	_hppex_stderr_print("bad text path -1\n");
	extent = PEXQueryTextExtents(display, lut, 1, -1,
				     1.0, 0.0, 0.01,
				     PEXHAlignNormal, PEXVAlignNormal,
				     1, &text);
	_hppex_stderr_print("bad text path 4\n");
	extent = PEXQueryTextExtents(display, lut, 1, 4,
				     1.0, 0.0, 0.01,
				     PEXHAlignNormal, PEXVAlignNormal,
				     1, &text);

	/*
	  bad horizontal alignment
	*/
	_hppex_stderr_print("bad horizontal alignment -1\n");
	extent = PEXQueryTextExtents(display, lut, 1, PEXPathRight,
				     1.0, 0.0, 0.01,
				     -1, PEXVAlignNormal,
				     1, &text);
	_hppex_stderr_print("bad horizontal alignment 4\n");
	extent = PEXQueryTextExtents(display, lut, 1, PEXPathRight,
				     1.0, 0.0, 0.01,
				     4, PEXVAlignNormal,
				     1, &text);

	/*
	  bad vertical alignment
	*/
	_hppex_stderr_print("bad vertical alignment -1\n");
	extent = PEXQueryTextExtents(display, lut, 1, PEXPathRight,
				     1.0, 0.0, 0.01,
				     PEXHAlignNormal, -1,
				     1, &text);
	_hppex_stderr_print("bad vertical alignment 6\n");
	extent = PEXQueryTextExtents(display, lut, 1, PEXPathRight,
				     1.0, 0.0, 0.01,
				     PEXHAlignNormal, 6,
				     1, &text);
    }
}

void inquire_test_params(char *test_name, 
			 int  *num_images, 
			 int  *supported_modes, 
			 char *win_title)
    {
    strcpy(test_name, "fnt_err");
    *num_images      = 1;
    *supported_modes = NON_OC_MODE;

    strcpy(win_title, "fnt_err");
    }

void misc_setup(Display *dpy, Window window, PEXRenderer renderer,
		int cur_image)
    {
    local_win = window;
    _hppex_set_stderr("fnt_err.stderr", "fnt_err");
    }

void execute_test(Display *dpy, XID resourceID, 
	       PEXOCRequestType req_type, int cur_image)
    {
    describe_test("\nPEX Text and Font Errors \n\n");
    describe_test("  The stderr file (only printed with the -v option) will contain\n");
    describe_test("  error condition descriptions followed by the trapped error\n");
    describe_test("  print out.\n\n");
    fflush(stdout);

    font_errors(dpy, local_win);
    }

void testproc(Display *dpy, Window window, int cur_image)
    {
    file_testproc("fnt_err.stderr", "fnt_err");
    }