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  * Pixel buffer self-tests
29  *
30  */
31 
32 /* Forcibly enable assertions */
33 #undef NDEBUG
34 
35 #include <assert.h>
36 #include <ipxe/image.h>
37 #include <ipxe/pixbuf.h>
38 #include <ipxe/test.h>
39 #include "pixbuf_test.h"
40 
41 /**
42  * Report pixel buffer test result
43  *
44  * @v test		Pixel buffer test
45  * @v file		Test code file
46  * @v line		Test code line
47  */
pixbuf_okx(struct pixel_buffer_test * test,const char * file,unsigned int line)48 void pixbuf_okx ( struct pixel_buffer_test *test, const char *file,
49 		  unsigned int line ) {
50 	struct pixel_buffer *pixbuf;
51 	int rc;
52 
53 	/* Sanity check */
54 	assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
55 		 == test->len );
56 
57 	/* Correct image data pointer */
58 	test->image->data = virt_to_user ( ( void * ) test->image->data );
59 
60 	/* Check that image is detected as correct type */
61 	okx ( register_image ( test->image ) == 0, file, line );
62 	okx ( test->image->type == test->type, file, line );
63 
64 	/* Check that a pixel buffer can be created from the image */
65 	okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
66 	if ( rc == 0 ) {
67 
68 		/* Check pixel buffer dimensions */
69 		okx ( pixbuf->width == test->width, file, line );
70 		okx ( pixbuf->height == test->height, file, line );
71 
72 		/* Check pixel buffer data */
73 		okx ( pixbuf->len == test->len, file, line );
74 		okx ( memcmp_user ( pixbuf->data, 0,
75 				    virt_to_user ( test->data ), 0,
76 				    test->len ) == 0, file, line );
77 
78 		pixbuf_put ( pixbuf );
79 	}
80 
81 	/* Unregister image */
82 	unregister_image ( test->image );
83 }
84