iPXE
Data Structures | Defines | Functions
pixbuf_test.h File Reference
#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/image.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  pixel_buffer_test
 A pixel buffer test. More...

Defines

#define PIX(_name, _type, _file, _width, _height, _data)
 Define a pixel buffer test.
#define pixbuf_ok(test)   pixbuf_okx ( test, __FILE__, __LINE__ )
 Report pixel buffer test result.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void pixbuf_okx (struct pixel_buffer_test *test, const char *file, unsigned int line)
 Report pixel buffer test result.

Define Documentation

#define PIX (   _name,
  _type,
  _file,
  _width,
  _height,
  _data 
)
Value:
static const char _name ## __file[] = _file;                    \
        static const uint32_t _name ## __data[] = _data;                \
        static struct image _name ## __image = {                        \
                .refcnt = REF_INIT ( ref_no_free ),                     \
                .name = #_name,                                         \
                .data = ( userptr_t ) ( _name ## __file ),              \
                .len = sizeof ( _name ## __file ),                      \
        };                                                              \
        static struct pixel_buffer_test _name = {                       \
                .type = _type,                                          \
                .image = & _name ## __image,                            \
                .data = _name ## __data,                                \
                .len = sizeof ( _name ## __data ),                      \
                .width = _width,                                        \
                .height = _height,                                      \
        };

Define a pixel buffer test.

Parameters:
_nameTest name
_typeTest image file type
_fileTest image file data
_widthExpected pixel buffer width
_heightExpected pixel buffer height
_dataExpected pixel buffer data
Return values:
testPixel buffer test

Definition at line 38 of file pixbuf_test.h.

#define pixbuf_ok (   test)    pixbuf_okx ( test, __FILE__, __LINE__ )

Report pixel buffer test result.

Parameters:
testPixel buffer test

Definition at line 64 of file pixbuf_test.h.

Referenced by png_test_exec(), and pnm_test_exec().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void pixbuf_okx ( struct pixel_buffer_test test,
const char *  file,
unsigned int  line 
)

Report pixel buffer test result.

Parameters:
testPixel buffer test
fileTest code file
lineTest code line

Definition at line 48 of file pixbuf_test.c.

References assert, pixel_buffer_test::data, pixel_buffer::data, image::data, pixel_buffer::height, pixel_buffer_test::height, pixel_buffer_test::image, image_pixbuf(), pixel_buffer_test::len, pixel_buffer::len, memcmp_user(), okx, rc, register_image(), pixel_buffer_test::type, image::type, unregister_image(), virt_to_user(), pixel_buffer::width, and pixel_buffer_test::width.

                                      {
        struct pixel_buffer *pixbuf;
        int rc;

        /* Sanity check */
        assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
                 == test->len );

        /* Correct image data pointer */
        test->image->data = virt_to_user ( ( void * ) test->image->data );

        /* Check that image is detected as correct type */
        okx ( register_image ( test->image ) == 0, file, line );
        okx ( test->image->type == test->type, file, line );

        /* Check that a pixel buffer can be created from the image */
        okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
        if ( rc == 0 ) {

                /* Check pixel buffer dimensions */
                okx ( pixbuf->width == test->width, file, line );
                okx ( pixbuf->height == test->height, file, line );

                /* Check pixel buffer data */
                okx ( pixbuf->len == test->len, file, line );
                okx ( memcmp_user ( pixbuf->data, 0,
                                    virt_to_user ( test->data ), 0,
                                    test->len ) == 0, file, line );

                pixbuf_put ( pixbuf );
        }

        /* Unregister image */
        unregister_image ( test->image );
}