iPXE
pixbuf_test.c
Go to the documentation of this file.
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 <string.h>
36 #include <assert.h>
37 #include <ipxe/image.h>
38 #include <ipxe/pixbuf.h>
39 #include <ipxe/test.h>
40 #include "pixbuf_test.h"
41 
42 /**
43  * Report pixel buffer test result
44  *
45  * @v test Pixel buffer test
46  * @v file Test code file
47  * @v line Test code line
48  */
49 void pixbuf_okx ( struct pixel_buffer_test *test, const char *file,
50  unsigned int line ) {
51  struct pixel_buffer *pixbuf;
52  int rc;
53 
54  /* Sanity check */
55  assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
56  == test->len );
57 
58  /* Check that image is detected as correct type */
59  okx ( register_image ( test->image ) == 0, file, line );
60  okx ( test->image->type == test->type, file, line );
61 
62  /* Check that a pixel buffer can be created from the image */
63  okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
64  if ( rc == 0 ) {
65 
66  /* Check pixel buffer dimensions */
67  okx ( pixbuf->width == test->width, file, line );
68  okx ( pixbuf->height == test->height, file, line );
69 
70  /* Check pixel buffer data */
71  okx ( pixbuf->len == test->len, file, line );
72  okx ( memcmp ( pixbuf->data, test->data, test->len ) == 0,
73  file, line );
74 
75  pixbuf_put ( pixbuf );
76  }
77 
78  /* Unregister image */
79  unregister_image ( test->image );
80 }
int image_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition: pixbuf.c:99
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned int height
Height.
Definition: pixbuf.h:22
Self-test infrastructure.
Pixel buffer.
size_t len
Total length.
Definition: pixbuf.h:28
#define okx(success, file, line)
Report test result.
Definition: test.h:44
Assertions.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
Executable images.
uint32_t * data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
Definition: pixbuf.h:24
int register_image(struct image *image)
Register executable image.
Definition: image.c:314
A pixel buffer.
Definition: pixbuf.h:16
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:357
void pixbuf_okx(struct pixel_buffer_test *test, const char *file, unsigned int line)
Report pixel buffer test result.
Definition: pixbuf_test.c:49
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
String functions.
A pixel buffer test.
Definition: pixbuf_test.h:12
static int test
Definition: epic100.c:73
unsigned int width
Width.
Definition: pixbuf.h:20