[infiniband] Use "%d" as format specifier for LIDs
[ipxe.git] / src / tests / pnm_test.c
1 /*
2 * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 /** @file
27 *
28 * PNM self-tests
29 *
30 */
31
32 /* Forcibly enable assertions */
33 #undef NDEBUG
34
35 #include <string.h>
36 #include <assert.h>
37 #include <ipxe/pixbuf.h>
38 #include <ipxe/pnm.h>
39 #include <ipxe/test.h>
40 #include "pixbuf_test.h"
41
42 /** Define inline pixel data */
43 #define DATA(...) { __VA_ARGS__ }
44
45 /** PBM ASCII example (from Wikipedia) */
46 PIX ( pbm_ascii, &pnm_image_type,
47 "P1\n"
48 "# This is an example bitmap of the letter \"J\"\n"
49 "6 10\n"
50 "0 0 0 0 1 0\n"
51 "0 0 0 0 1 0\n"
52 "0 0 0 0 1 0\n"
53 "0 0 0 0 1 0\n"
54 "0 0 0 0 1 0\n"
55 "0 0 0 0 1 0\n"
56 "1 0 0 0 1 0\n"
57 "0 1 1 1 0 0\n"
58 "0 0 0 0 0 0\n"
59 "0 0 0 0 0 0\n",
60 6, 10,
61 DATA ( 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
62 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
63 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
64 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
65 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
66 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
67 0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
68 0xffffff, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff,
69 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
70 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
71
72 /** PGM ASCII example (from Wikipedia) */
73 PIX ( pgm_ascii, &pnm_image_type,
74 "P2\n"
75 "# Shows the word \"FEEP\" (example from Netpbm man page on PGM)\n"
76 "24 7\n"
77 "15\n"
78 "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
79 "0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0\n"
80 "0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0\n"
81 "0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0\n"
82 "0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0\n"
83 "0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0\n"
84 "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
85 , 24, 7,
86 DATA ( 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
87 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
88 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
89 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
90 0x000000, 0x333333, 0x333333, 0x333333, 0x333333, 0x000000,
91 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
92 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
93 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
94 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
95 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
96 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
97 0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x000000,
98 0x000000, 0x333333, 0x333333, 0x333333, 0x000000, 0x000000,
99 0x000000, 0x777777, 0x777777, 0x777777, 0x000000, 0x000000,
100 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000, 0x000000,
101 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
102 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
103 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
104 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
105 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
106 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
107 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
108 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
109 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
110 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
111 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
112 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
113 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
114
115 /** PPM ASCII example (from Wikipedia) */
116 PIX ( ppm_ascii, &pnm_image_type,
117 "P3\n"
118 "# The P3 means colors are in ASCII, then 3 columns and 2 rows,\n"
119 "# then 255 for max color, then RGB triplets\n"
120 "3 2\n"
121 "255\n"
122 "255 0 0 0 255 0 0 0 255\n"
123 "255 255 0 255 255 255 0 0 0\n",
124 3, 2,
125 DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
126
127 /** PBM ASCII with no space between pixel values */
128 PIX ( pbm_ascii_no_space, &pnm_image_type,
129 "P1\n"
130 "3 3\n"
131 "001\n"
132 "010\n"
133 "111\n",
134 3, 3,
135 DATA ( 0xffffff, 0xffffff, 0x000000, 0xffffff, 0x000000, 0xffffff,
136 0x000000, 0x000000, 0x000000 ) );
137
138 /** PBM binary example (converted from Wikipedia) */
139 PIX ( pbm_binary, &pnm_image_type,
140 DATA ( 0x50, 0x34, 0x0a, 0x23, 0x20, 0x43, 0x52, 0x45, 0x41, 0x54, 0x4f,
141 0x52, 0x3a, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x20, 0x50, 0x4e, 0x4d,
142 0x20, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x20, 0x56, 0x65, 0x72,
143 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x2e, 0x31, 0x0a, 0x36, 0x20,
144 0x31, 0x30, 0x0a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x70,
145 0x00, 0x00 ),
146 6, 10,
147 DATA ( 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
148 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
149 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
150 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
151 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
152 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
153 0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
154 0xffffff, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff,
155 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
156 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
157
158 /** PGM binary example (converted from Wikipedia) */
159 PIX ( pgm_binary, &pnm_image_type,
160 DATA ( 0x50, 0x35, 0x0a, 0x32, 0x34, 0x20, 0x37, 0x0a, 0x31, 0x35, 0x0a,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x07, 0x07,
164 0x07, 0x07, 0x00, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x0f,
165 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
166 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x0f, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x03, 0x03, 0x00,
168 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x0b, 0x0b, 0x0b,
169 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x03, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
172 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x00,
173 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 0x00, 0x00, 0x00 ),
177 24, 7,
178 DATA ( 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
179 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
180 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
181 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
182 0x000000, 0x333333, 0x333333, 0x333333, 0x333333, 0x000000,
183 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
184 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
185 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
186 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
187 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
188 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
189 0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x000000,
190 0x000000, 0x333333, 0x333333, 0x333333, 0x000000, 0x000000,
191 0x000000, 0x777777, 0x777777, 0x777777, 0x000000, 0x000000,
192 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000, 0x000000,
193 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
194 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
195 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
196 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
197 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
198 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
199 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
200 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
201 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
202 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
203 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
204 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
205 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
206
207 /** PPM binary example (converted from Wikipedia) */
208 PIX ( ppm_binary, &pnm_image_type,
209 DATA ( 0x50, 0x36, 0x0a, 0x33, 0x20, 0x32, 0x0a, 0x32, 0x35, 0x35, 0x0a,
210 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
211 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 ),
212 3, 2,
213 DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
214
215 /**
216 * Perform PNM self-test
217 *
218 */
219 static void pnm_test_exec ( void ) {
220
221 pixbuf_ok ( &pbm_ascii );
222 pixbuf_ok ( &pgm_ascii );
223 pixbuf_ok ( &ppm_ascii );
224 pixbuf_ok ( &pbm_ascii_no_space );
225 pixbuf_ok ( &pbm_binary );
226 pixbuf_ok ( &pgm_binary );
227 pixbuf_ok ( &ppm_binary );
228 }
229
230 /** PNM self-test */
231 struct self_test pnm_test __self_test = {
232 .name = "pnm",
233 .exec = pnm_test_exec,
234 };