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