iPXE
pnm_test.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /** @file
00027  *
00028  * PNM self-tests
00029  *
00030  */
00031 
00032 /* Forcibly enable assertions */
00033 #undef NDEBUG
00034 
00035 #include <string.h>
00036 #include <assert.h>
00037 #include <ipxe/pixbuf.h>
00038 #include <ipxe/pnm.h>
00039 #include <ipxe/test.h>
00040 #include "pixbuf_test.h"
00041 
00042 /** Define inline pixel data */
00043 #define DATA(...) { __VA_ARGS__ }
00044 
00045 /** PBM ASCII example (from Wikipedia) */
00046 PIX ( pbm_ascii, &pnm_image_type,
00047       "P1\n"
00048       "# This is an example bitmap of the letter \"J\"\n"
00049       "6 10\n"
00050       "0 0 0 0 1 0\n"
00051       "0 0 0 0 1 0\n"
00052       "0 0 0 0 1 0\n"
00053       "0 0 0 0 1 0\n"
00054       "0 0 0 0 1 0\n"
00055       "0 0 0 0 1 0\n"
00056       "1 0 0 0 1 0\n"
00057       "0 1 1 1 0 0\n"
00058       "0 0 0 0 0 0\n"
00059       "0 0 0 0 0 0\n",
00060       6, 10,
00061       DATA ( 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00062              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00063              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00064              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00065              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00066              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00067              0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00068              0xffffff, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff,
00069              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
00070              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
00071 
00072 /** PGM ASCII example (from Wikipedia) */
00073 PIX ( pgm_ascii, &pnm_image_type,
00074       "P2\n"
00075       "# Shows the word \"FEEP\" (example from Netpbm man page on PGM)\n"
00076       "24 7\n"
00077       "15\n"
00078       "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"
00079       "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"
00080       "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"
00081       "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"
00082       "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"
00083       "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"
00084       "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"
00085       , 24, 7,
00086       DATA ( 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00087              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00088              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00089              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00090              0x000000, 0x333333, 0x333333, 0x333333, 0x333333, 0x000000,
00091              0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
00092              0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
00093              0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
00094              0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
00095              0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
00096              0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
00097              0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x000000,
00098              0x000000, 0x333333, 0x333333, 0x333333, 0x000000, 0x000000,
00099              0x000000, 0x777777, 0x777777, 0x777777, 0x000000, 0x000000,
00100              0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000, 0x000000,
00101              0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
00102              0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
00103              0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
00104              0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
00105              0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
00106              0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
00107              0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
00108              0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
00109              0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
00110              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00111              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00112              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00113              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
00114 
00115 /** PPM ASCII example (from Wikipedia) */
00116 PIX ( ppm_ascii, &pnm_image_type,
00117       "P3\n"
00118       "# The P3 means colors are in ASCII, then 3 columns and 2 rows,\n"
00119       "# then 255 for max color, then RGB triplets\n"
00120       "3 2\n"
00121       "255\n"
00122       "255   0   0     0 255   0     0   0 255\n"
00123       "255 255   0   255 255 255     0   0   0\n",
00124       3, 2,
00125       DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
00126 
00127 /** PBM ASCII with no space between pixel values */
00128 PIX ( pbm_ascii_no_space, &pnm_image_type,
00129       "P1\n"
00130       "3 3\n"
00131       "001\n"
00132       "010\n"
00133       "111\n",
00134       3, 3,
00135       DATA ( 0xffffff, 0xffffff, 0x000000, 0xffffff, 0x000000, 0xffffff,
00136              0x000000, 0x000000, 0x000000 ) );
00137 
00138 /** PBM binary example (converted from Wikipedia) */
00139 PIX ( pbm_binary, &pnm_image_type,
00140       DATA ( 0x50, 0x34, 0x0a, 0x23, 0x20, 0x43, 0x52, 0x45, 0x41, 0x54, 0x4f,
00141              0x52, 0x3a, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x20, 0x50, 0x4e, 0x4d,
00142              0x20, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x20, 0x56, 0x65, 0x72,
00143              0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x2e, 0x31, 0x0a, 0x36, 0x20,
00144              0x31, 0x30, 0x0a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x70,
00145              0x00, 0x00 ),
00146       6, 10,
00147       DATA ( 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00148              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00149              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00150              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00151              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00152              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00153              0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
00154              0xffffff, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff,
00155              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
00156              0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
00157 
00158 /** PGM binary example (converted from Wikipedia) */
00159 PIX ( pgm_binary, &pnm_image_type,
00160       DATA ( 0x50, 0x35, 0x0a, 0x32, 0x34, 0x20, 0x37, 0x0a, 0x31, 0x35, 0x0a,
00161              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00162              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00163              0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x07, 0x07,
00164              0x07, 0x07, 0x00, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x0f,
00165              0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
00166              0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00,
00167              0x00, 0x0f, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x03, 0x03, 0x00,
00168              0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x0b, 0x0b, 0x0b,
00169              0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x03, 0x00,
00170              0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
00171              0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
00172              0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x00,
00173              0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
00174              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00175              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00176              0x00, 0x00, 0x00 ),
00177       24, 7,
00178       DATA ( 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00179              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00180              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00181              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00182              0x000000, 0x333333, 0x333333, 0x333333, 0x333333, 0x000000,
00183              0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
00184              0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
00185              0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
00186              0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
00187              0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
00188              0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
00189              0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x000000,
00190              0x000000, 0x333333, 0x333333, 0x333333, 0x000000, 0x000000,
00191              0x000000, 0x777777, 0x777777, 0x777777, 0x000000, 0x000000,
00192              0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000, 0x000000,
00193              0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
00194              0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
00195              0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
00196              0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
00197              0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
00198              0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
00199              0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
00200              0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
00201              0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
00202              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00203              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00204              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
00205              0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
00206 
00207 /** PPM binary example (converted from Wikipedia) */
00208 PIX ( ppm_binary, &pnm_image_type,
00209       DATA ( 0x50, 0x36, 0x0a, 0x33, 0x20, 0x32, 0x0a, 0x32, 0x35, 0x35, 0x0a,
00210              0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
00211              0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 ),
00212       3, 2,
00213       DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
00214 
00215 /**
00216  * Perform PNM self-test
00217  *
00218  */
00219 static void pnm_test_exec ( void ) {
00220 
00221         pixbuf_ok ( &pbm_ascii );
00222         pixbuf_ok ( &pgm_ascii );
00223         pixbuf_ok ( &ppm_ascii );
00224         pixbuf_ok ( &pbm_ascii_no_space );
00225         pixbuf_ok ( &pbm_binary );
00226         pixbuf_ok ( &pgm_binary );
00227         pixbuf_ok ( &ppm_binary );
00228 }
00229 
00230 /** PNM self-test */
00231 struct self_test pnm_test __self_test = {
00232         .name = "pnm",
00233         .exec = pnm_test_exec,
00234 };