UEFIStarter
a simple UEFI framework
Data Structures | Macros | Functions | Variables
graphics.c File Reference

Tests for graphics functions. More...

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <math.h>
#include <UEFIStarter/core.h>
#include <UEFIStarter/graphics.h>
#include <UEFIStarter/tests/tests.h>

Data Structures

struct  parse_image_data_testcase_t
 data type for netpbm image parser tests More...
 
union  contents_buffer_t
 helper data type for easier access to file_contents_t's memory content More...
 
struct  rotation_testcase_t
 data type for image rotation testcases More...
 

Macros

#define RUN_PARSE_IMAGE_TESTS(TYPE)
 shortcut macro to quickly run a netpbm test case More...
 
#define B   {0,0,0,0}
 helper macro to quickly create black pixel data
 
#define W   {255,255,255,0}
 helper macro to quickly create white pixel data
 

Functions

static file_contents_tassemble_file_contents (unsigned int size, char *data)
 internal: assembles a file_contents_t structure manually More...
 
void do_parse_image_test (parse_image_data_testcase_t *testcase, image_t *(*parser)(file_contents_t *))
 Runs an individual netpbm test case. More...
 
void test_parse_ppm_image_data ()
 Makes sure parse_ppm_image_data() works. More...
 
void test_parse_pgm_image_data ()
 Makes sure parse_pgm_image_data() works. More...
 
void test_parse_pbm_image_data ()
 Makes sure parse_pbm_image_data() works. More...
 
static void _do_rotation_checks (image_t *image, INTN r, INTN dx, INTN dy, CHAR16 *msg_prefix)
 internal: checks a rotated image at 9 specific pixels to see if it was rotated correctly. More...
 
void test_rotate_image ()
 Makes sure rotate_image() works. More...
 
void test_interpolate_4px ()
 Makes sure interpolate_4px works. More...
 
void test_interpolate_2px ()
 Makes sure interpolate_2px() works. More...
 
static glyph_list_t_get_parse_glyphs_font ()
 internal: creates a glyph list for use in tests. More...
 
void test_parse_glyphs ()
 Makes sure parse_glyphs() works. More...
 
void test_draw_text ()
 Makes sure draw_text() works. More...
 
BOOLEAN run_graphics_tests ()
 Test runner for this group. More...
 

Variables

static contents_buffer_t _file_contents_buffer
 internal image data buffer for netpbm parser tests
 
char ppm_data [] ={0x50,0x36,0x0a,0x23,0x20,0x78,0x0a,0x32,0x20,0x33,0x0a,0x32,0x35,0x35,0x0a,0xed,0x1c,0x24,0xff,0xf2,0x00,0x00,0xa2,0xe8,0xb5,0xe6,0x1d,0x00,0x00,0x00,0xff,0xff,0xff}
 the PPM image data to parse for tests
 
EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_ppm_pixels []
 the PPM image's expected pixels More...
 
parse_image_data_testcase_t ppm_testcases []
 the test case for the PPM parser test More...
 
char pgm_data [] ={0x50,0x35,0x0a,0x23,0x0a,0x32,0x20,0x32,0x0a,0x32,0x35,0x35,0x0a,0x00,0x7f,0xff,0xc3}
 the PGM image data to parse for tests
 
EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_pgm_pixels []
 the PGM image's expected pixels More...
 
parse_image_data_testcase_t pgm_testcases []
 the test case for the PGM parser test More...
 
char pbm_data [] ={0x50,0x34,0x0a,0x23,0x23,0x0a,0x31,0x37,0x20,0x32,0x0a,0xf2,0x1b,0xff,0x90,0xde,0x7f}
 the PBM image data to parse for tests
 
EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_pbm_pixels [] ={B,B,B,B,W,W,B,W,W,W,W,B,B,W,B,B,B,B,W,W,B,W,W,W,W,B,B,W,B,B,B,B,W,W}
 the PBM image's expected pixels
 
parse_image_data_testcase_t pbm_testcases []
 the test case for the PBM parse test More...
 
rotation_testcase_t rotation_testcases []
 test cases for test_rotate_image() More...
 
EFI_GRAPHICS_OUTPUT_BLT_PIXEL rotation_color_yarp ={200,150,30,0}
 "on" color for rotation tests
 
EFI_GRAPHICS_OUTPUT_BLT_PIXEL rotation_color_narp ={80,240,110,0}
 "off" color for rotation tests
 
static EFI_GRAPHICS_OUTPUT_BLT_PIXEL _interpolation_data [] ={{0,0,0,0},{0,0,255,0},{123,5,0,0},{0,255,0,0},{255,0,0,0},{50,200,164,0}}
 test data for pixel interpolation
 

Detailed Description

Tests for graphics functions.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter

Macro Definition Documentation

◆ RUN_PARSE_IMAGE_TESTS

#define RUN_PARSE_IMAGE_TESTS (   TYPE)
Value:
INTN tc, count; \
count=sizeof(TYPE ## _testcases)/sizeof(parse_image_data_testcase_t); \
for(tc=0;tc<count;tc++) \
do_parse_image_test(TYPE ## _testcases+tc,parse_ ## TYPE ## _image_data);
void do_parse_image_test(parse_image_data_testcase_t *testcase, image_t *(*parser)(file_contents_t *))
Runs an individual netpbm test case.
Definition: graphics.c:72
data type for netpbm image parser tests
Definition: graphics.c:28

shortcut macro to quickly run a netpbm test case

Parameters
TYPEthe image format to test ("ppm", "pgm" or "pbm")

Function Documentation

◆ assemble_file_contents()

static file_contents_t* assemble_file_contents ( unsigned int  size,
char *  data 
)
static

internal: assembles a file_contents_t structure manually

Parameters
sizethe content length, in bytes
datathe content data
Returns
the file_contents_t structure

◆ do_parse_image_test()

void do_parse_image_test ( parse_image_data_testcase_t testcase,
image_t *(*)(file_contents_t *)  parser 
)

Runs an individual netpbm test case.

Parameters
testcasethe test case to run
parserthe parser function to test

◆ test_parse_ppm_image_data()

void test_parse_ppm_image_data ( )

Makes sure parse_ppm_image_data() works.

Test:
parse_ppm_image_data() reads correct dimensions and pixel values

◆ test_parse_pgm_image_data()

void test_parse_pgm_image_data ( )

Makes sure parse_pgm_image_data() works.

Test:
parse_pgm_image_data() reads correct dimensions and pixel values

◆ test_parse_pbm_image_data()

void test_parse_pbm_image_data ( )

Makes sure parse_pbm_image_data() works.

Test:
parse_pbm_image_data() reads correct dimensions and pixel values

◆ _do_rotation_checks()

static void _do_rotation_checks ( image_t image,
INTN  r,
INTN  dx,
INTN  dy,
CHAR16 *  msg_prefix 
)
static

internal: checks a rotated image at 9 specific pixels to see if it was rotated correctly.

Here's an example image being rotated. The original image is on the left, the result after rotating by 90° clockwise on the right:

...........         ...........
.         .         .         .
.         .         .         .
.    *****.   ==>   .    *    .
.         .         .    *    .
...........         .....*.....
 original             90° CW

The rotated images are tested at 9 points. These points are in a 3x3 grid, with the center pixel in the middle of the image. The center point is the center of a new coordinate system, with x going right and y going down. Test points are marked with °:

...........
.         .
.  ° ° °  .
.  ° ° °  . --> x
.  ° ° °  .
...........
     |
     V
     y

Thus, the top left point is at coordinates (-1,-1), the center left point at (-1,0) and so on.

Because of the contents of the original and rotated image the tests work by asserting that:

  1. the center point always has the foreground color
  2. a specific test point has the foreground color (+- a small margin)
  3. the other 7 test points have the background color.

The coordinates to expect a foreground color pixel at are passed in parameters "dx" and "dy".

The scale of the 3x3 grid can be adjusted with the "r" parameter.

Parameters
imagethe rotated image to check
rthe distance scale to use for checks, in pixels
dxthe horizontal direction to expect change in
dythe vertical direction to expect change in
msg_prefixa description of what's being tested, to include in error messages

◆ test_rotate_image()

void test_rotate_image ( )

Makes sure rotate_image() works.

The _do_rotation_checks() function documentation illustrates how this is asserted.

Test:
rotate_image() rotates images clockwise for positive angles and counter-clockwise for negative angles

◆ test_interpolate_4px()

void test_interpolate_4px ( )

Makes sure interpolate_4px works.

Test:

interpolate_4px() handles all 4 corners correctly

interpolate_4px() handles all 5 mid points correctly

interpolate_4px() handles arbitrary points correctly

◆ test_interpolate_2px()

void test_interpolate_2px ( )

Makes sure interpolate_2px() works.

Test:

interpolate_2px() uses second pixel for ratio 1.0

interpolate_2px() handles arbitrary points correctly

◆ _get_parse_glyphs_font()

static glyph_list_t* _get_parse_glyphs_font ( )
static

internal: creates a glyph list for use in tests.

Returns
a list of glyphs

◆ test_parse_glyphs()

void test_parse_glyphs ( )

Makes sure parse_glyphs() works.

Test:

parse_glyphs() initializes the glyph list correctly

parse_glyphs() splits an input text of 4 characters into 4 glyphs

parse_glyphs() reads glyphs correctly when given a multiline input string

◆ test_draw_text()

void test_draw_text ( )

Makes sure draw_text() works.

Test:

draw_text() writes text at the correct position

draw_text() blends semi-transparent glyphs onto background

◆ run_graphics_tests()

BOOLEAN run_graphics_tests ( )

Test runner for this group.

Gets called via the generated test runner.

Returns
whether the test group was executed

Variable Documentation

◆ expected_ppm_pixels

EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_ppm_pixels[]
Initial value:
=
{
{36,28,237,0},
{0,242,255,0},
{232,162,0,0},
{29,230,181,0},
{0,0,0,0},
{255,255,255,0},
}

the PPM image's expected pixels

◆ ppm_testcases

parse_image_data_testcase_t ppm_testcases[]
Initial value:
=
{
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_ppm_pixels[]
the PPM image&#39;s expected pixels
Definition: graphics.c:108
char ppm_data[]
the PPM image data to parse for tests
Definition: graphics.c:105

the test case for the PPM parser test

◆ expected_pgm_pixels

EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_pgm_pixels[]
Initial value:
={
{0,0,0,0},
{127,127,127,0},
{255,255,255,0},
{195,195,195,0},
}

the PGM image's expected pixels

◆ pgm_testcases

parse_image_data_testcase_t pgm_testcases[]
Initial value:
=
{
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_pgm_pixels[]
the PGM image&#39;s expected pixels
Definition: graphics.c:141
char pgm_data[]
the PGM image data to parse for tests
Definition: graphics.c:138

the test case for the PGM parser test

◆ pbm_testcases

parse_image_data_testcase_t pbm_testcases[]
Initial value:
=
{
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected_pbm_pixels[]
the PBM image&#39;s expected pixels
Definition: graphics.c:174
char pbm_data[]
the PBM image data to parse for tests
Definition: graphics.c:168

the test case for the PBM parse test

◆ rotation_testcases

rotation_testcase_t rotation_testcases[]
Initial value:
=
{
{ 0.0000, 1, 0},
{ 0.7854, 1, 1},
{ 1.5708, 0, 1},
{ 2.3562,-1, 1},
{ 3.1416,-1, 0},
{ 3.9270,-1,-1},
{ 4.7124, 0,-1},
{ 5.4978, 1,-1},
{ 6.2832, 1, 0},
{-2.3562,-1,-1},
}

test cases for test_rotate_image()