iPXE
pixbuf_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  * Pixel buffer self-tests
00029  *
00030  */
00031 
00032 /* Forcibly enable assertions */
00033 #undef NDEBUG
00034 
00035 #include <assert.h>
00036 #include <ipxe/image.h>
00037 #include <ipxe/pixbuf.h>
00038 #include <ipxe/test.h>
00039 #include "pixbuf_test.h"
00040 
00041 /**
00042  * Report pixel buffer test result
00043  *
00044  * @v test              Pixel buffer test
00045  * @v file              Test code file
00046  * @v line              Test code line
00047  */
00048 void pixbuf_okx ( struct pixel_buffer_test *test, const char *file,
00049                   unsigned int line ) {
00050         struct pixel_buffer *pixbuf;
00051         int rc;
00052 
00053         /* Sanity check */
00054         assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
00055                  == test->len );
00056 
00057         /* Correct image data pointer */
00058         test->image->data = virt_to_user ( ( void * ) test->image->data );
00059 
00060         /* Check that image is detected as correct type */
00061         okx ( register_image ( test->image ) == 0, file, line );
00062         okx ( test->image->type == test->type, file, line );
00063 
00064         /* Check that a pixel buffer can be created from the image */
00065         okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
00066         if ( rc == 0 ) {
00067 
00068                 /* Check pixel buffer dimensions */
00069                 okx ( pixbuf->width == test->width, file, line );
00070                 okx ( pixbuf->height == test->height, file, line );
00071 
00072                 /* Check pixel buffer data */
00073                 okx ( pixbuf->len == test->len, file, line );
00074                 okx ( memcmp_user ( pixbuf->data, 0,
00075                                     virt_to_user ( test->data ), 0,
00076                                     test->len ) == 0, file, line );
00077 
00078                 pixbuf_put ( pixbuf );
00079         }
00080 
00081         /* Unregister image */
00082         unregister_image ( test->image );
00083 }