UEFIStarter
a simple UEFI framework
Functions | Variables
asserts.h File Reference

General assertions for tests. More...

#include <Uefi.h>
#include <Library/UefiLib.h>

Go to the source code of this file.

Functions

BOOLEAN assert_true (BOOLEAN actual, CHAR16 *message)
 Asserts a boolean value is true. More...
 
BOOLEAN assert_false (BOOLEAN actual, CHAR16 *message)
 Asserts a boolean value is false. More...
 
BOOLEAN assert_intn_equals (INTN expected, INTN actual, CHAR16 *message)
 Asserts an integer value equals an expected value. More...
 
BOOLEAN assert_intn_greater_than_or_equal_to (INTN expected, INTN actual, CHAR16 *message)
 Asserts an integer value is >=expectation. More...
 
BOOLEAN assert_intn_less_than_or_equal_to (INTN expected, INTN actual, CHAR16 *message)
 Asserts an integer value is <=expectation. More...
 
BOOLEAN assert_intn_in_closed_interval (INTN min, INTN max, INTN actual, CHAR16 *message)
 Asserts an integer value is within an interval: min <= input <= max. More...
 
BOOLEAN assert_uint64_equals (UINT64 expected, UINT64 actual, CHAR16 *message)
 Asserts a UINT64 equals an expected value. More...
 
BOOLEAN assert_double_near (double expected, double epsilon, double actual, CHAR16 *message)
 Asserts a double value is within an epsilon radius around an expected value. More...
 
BOOLEAN assert_double_greater_than (double threshold, double actual, CHAR16 *message)
 Asserts a double value is >expectation. More...
 
BOOLEAN assert_double_greater_than_or_equal_to (double threshold, double actual, CHAR16 *message)
 Asserts a double value is >=expectation. More...
 
BOOLEAN assert_double_less_than (double threshold, double actual, CHAR16 *message)
 Asserts a double value is <expectation. More...
 
BOOLEAN assert_double_less_than_or_equal_to (double threshold, double actual, CHAR16 *message)
 Asserts a double value is <=expectation. More...
 
BOOLEAN assert_null (void *actual, CHAR16 *message)
 Asserts a pointer is NULL. More...
 
BOOLEAN assert_not_null (void *actual, CHAR16 *message)
 Asserts a pointer is anything but NULL. More...
 
BOOLEAN assert_uint8_array (UINTN size, UINT8 *expected, UINT8 *actual, CHAR16 *message)
 Asserts an array of UINT8 values matches an expected array's values. More...
 
BOOLEAN assert_wcstr_equals (CHAR16 *expected, CHAR16 *actual, CHAR16 *message)
 Asserts a string equals an expected string. More...
 
BOOLEAN assert_pixel (EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected, EFI_GRAPHICS_OUTPUT_BLT_PIXEL actual, CHAR16 *message)
 Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL equals an expected pixel. More...
 
BOOLEAN assert_pixel_values (UINT8 red, UINT8 green, UINT8 blue, UINT8 reserved, EFI_GRAPHICS_OUTPUT_BLT_PIXEL actual, CHAR16 *message)
 Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL has expected channel values. More...
 
BOOLEAN assert_pixel_near (EFI_GRAPHICS_OUTPUT_BLT_PIXEL expected, INTN epsilon, EFI_GRAPHICS_OUTPUT_BLT_PIXEL actual, CHAR16 *message)
 Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL equals an expected pixel or the difference is within a given radius. More...
 
BOOLEAN assert_pixel_values_near (UINT8 red, UINT8 green, UINT8 blue, UINT8 reserved, INTN epsilon, EFI_GRAPHICS_OUTPUT_BLT_PIXEL actual, CHAR16 *message)
 Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL has expected channel values or the difference is within a given radius. More...
 

Variables

BOOLEAN invert_next_assert
 Inverts the next executed assertion: failure becomes success and vice versa. More...
 

Detailed Description

General assertions for tests.

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

Function Documentation

◆ assert_true()

BOOLEAN assert_true ( BOOLEAN  actual,
CHAR16 *  message 
)

Asserts a boolean value is true.

Parameters
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_false()

BOOLEAN assert_false ( BOOLEAN  actual,
CHAR16 *  message 
)

Asserts a boolean value is false.

Parameters
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_intn_equals()

BOOLEAN assert_intn_equals ( INTN  expected,
INTN  actual,
CHAR16 *  message 
)

Asserts an integer value equals an expected value.

Parameters
expectedthe expected value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_intn_greater_than_or_equal_to()

BOOLEAN assert_intn_greater_than_or_equal_to ( INTN  expected,
INTN  actual,
CHAR16 *  message 
)

Asserts an integer value is >=expectation.

Parameters
expectedthe expected value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_intn_less_than_or_equal_to()

BOOLEAN assert_intn_less_than_or_equal_to ( INTN  expected,
INTN  actual,
CHAR16 *  message 
)

Asserts an integer value is <=expectation.

Parameters
expectedthe expected value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_intn_in_closed_interval()

BOOLEAN assert_intn_in_closed_interval ( INTN  min,
INTN  max,
INTN  actual,
CHAR16 *  message 
)

Asserts an integer value is within an interval: min <= input <= max.

Parameters
minthe smallest allowed value
maxthe largest allowed value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_uint64_equals()

BOOLEAN assert_uint64_equals ( UINT64  expected,
UINT64  actual,
CHAR16 *  message 
)

Asserts a UINT64 equals an expected value.

Parameters
expectedthe expected value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_double_near()

BOOLEAN assert_double_near ( double  expected,
double  epsilon,
double  actual,
CHAR16 *  message 
)

Asserts a double value is within an epsilon radius around an expected value.

To be exact this must hold true: expected-epsilon <= actual <= expected+epsilon

Parameters
expectedthe expected value
epsilonthe highest absolute difference allowed
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_double_greater_than()

BOOLEAN assert_double_greater_than ( double  threshold,
double  actual,
CHAR16 *  message 
)

Asserts a double value is >expectation.

Parameters
thresholdthe threshold the checked value must be higher than
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_double_greater_than_or_equal_to()

BOOLEAN assert_double_greater_than_or_equal_to ( double  threshold,
double  actual,
CHAR16 *  message 
)

Asserts a double value is >=expectation.

Parameters
thresholdthe lowest allowed value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_double_less_than()

BOOLEAN assert_double_less_than ( double  threshold,
double  actual,
CHAR16 *  message 
)

Asserts a double value is <expectation.

Parameters
thresholdthe threshold the checked value must be lower than
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_double_less_than_or_equal_to()

BOOLEAN assert_double_less_than_or_equal_to ( double  threshold,
double  actual,
CHAR16 *  message 
)

Asserts a double value is <=expectation.

Parameters
thresholdthe highest allowed value
actualthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_null()

BOOLEAN assert_null ( void *  actual,
CHAR16 *  message 
)

Asserts a pointer is NULL.

Parameters
actualthe pointer to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_not_null()

BOOLEAN assert_not_null ( void *  actual,
CHAR16 *  message 
)

Asserts a pointer is anything but NULL.

Parameters
actualthe pointer to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_uint8_array()

BOOLEAN assert_uint8_array ( UINTN  size,
UINT8 *  expected,
UINT8 *  actual,
CHAR16 *  message 
)

Asserts an array of UINT8 values matches an expected array's values.

Parameters
sizethe expected array size
expectedthe expected values
actualthe values to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_wcstr_equals()

BOOLEAN assert_wcstr_equals ( CHAR16 *  expected,
CHAR16 *  actual,
CHAR16 *  message 
)

Asserts a string equals an expected string.

Parameters
expectedthe expected string
actualthe string to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_pixel()

BOOLEAN assert_pixel ( EFI_GRAPHICS_OUTPUT_BLT_PIXEL  exp,
EFI_GRAPHICS_OUTPUT_BLT_PIXEL  act,
CHAR16 *  message 
)

Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL equals an expected pixel.

This also checks the .Reserved channel.

Parameters
expthe expected pixel
actthe pixel to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_pixel_values()

BOOLEAN assert_pixel_values ( UINT8  red,
UINT8  green,
UINT8  blue,
UINT8  reserved,
EFI_GRAPHICS_OUTPUT_BLT_PIXEL  act,
CHAR16 *  message 
)

Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL has expected channel values.

Parameters
redthe expected red color value
greenthe expected green color value
bluethe expected blue color value
reservedthe expected reserved color value
actthe value to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_pixel_near()

BOOLEAN assert_pixel_near ( EFI_GRAPHICS_OUTPUT_BLT_PIXEL  exp,
INTN  epsilon,
EFI_GRAPHICS_OUTPUT_BLT_PIXEL  act,
CHAR16 *  message 
)

Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL equals an expected pixel or the difference is within a given radius.

The difference between two pixels is calculated as the sum of absolute differences in each channel.

This also checks the .Reserved channel.

Parameters
expthe expected pixel
epsilonthe highest absolute differences sum allowed
actthe pixel to check
messagean error message to include on failure
Returns
whether the assertion passed

◆ assert_pixel_values_near()

BOOLEAN assert_pixel_values_near ( UINT8  red,
UINT8  green,
UINT8  blue,
UINT8  reserved,
INTN  epsilon,
EFI_GRAPHICS_OUTPUT_BLT_PIXEL  act,
CHAR16 *  message 
)

Asserts an EFI_GRAPHICS_OUTPUT_BLT_PIXEL has expected channel values or the difference is within a given radius.

The difference between two pixels is calculated as the sum of absolute differences in each channel.

Parameters
redthe expected red color value
greenthe expected green color value
bluethe expected blue color value
reservedthe expected reserved color value
epsilonthe highest absolute differences sum over all color channels allowed
actthe pixel to check
messagean error message to include on failure
Returns
whether the assertion passed

Variable Documentation

◆ invert_next_assert

BOOLEAN invert_next_assert

Inverts the next executed assertion: failure becomes success and vice versa.

This automatically gets reset to FALSE after one assertion, regardless of its result.