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

Tests for the command line parameter parser. More...

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <UEFIStarter/core.h>
#include <UEFIStarter/tests/tests.h>

Data Structures

struct  cmdline_args_testcase_t
 data type for command-line argument parser testcase More...
 
struct  validate_range_testcase_t
 data type for command-line argument validator testcases More...
 

Functions

BOOLEAN validate_int (cmdline_value_t val)
 A validator function for integers, used in tests. More...
 
void EFIAPI do_parse_parameters_testcase (cmdline_args_testcase_t *testcase, cmdline_argument_t *list, UINTN count,...)
 Runs an individual testcase. More...
 
void test_parse_parameters ()
 Makes sure the command-line parser works. More...
 
void test_validate_ranges ()
 Makes sure the double and uint64 range validators work. More...
 
BOOLEAN run_cmdline_tests ()
 Test runner for this group. More...
 

Variables

cmdline_argument_t cmdline_args_list []
 A list of arguments, used in tests. More...
 
cmdline_argument_group_t cmdline_args_group
 An argument group, used in tests. More...
 
cmdline_args_testcase_t cmdline_args_testcases []
 testcases for test_parse_parameters() More...
 
validate_range_testcase_t double_range_testcases []
 double test cases for test_validate_ranges More...
 
validate_range_testcase_t uint64_range_testcases []
 UINT64 test cases for test_validate_ranges. More...
 

Detailed Description

Tests for the command line parameter parser.

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

Function Documentation

◆ validate_int()

BOOLEAN validate_int ( cmdline_value_t  val)

A validator function for integers, used in tests.

Parameters
valthe value to validate
Returns
whether the value is valid

◆ do_parse_parameters_testcase()

void EFIAPI do_parse_parameters_testcase ( cmdline_args_testcase_t testcase,
cmdline_argument_t list,
UINTN  count,
  ... 
)

Runs an individual testcase.

This currently doesn't really support multiple argument groups, the vararg setup is just there to convert the argument group to VA_LIST for parse_parameters().

Parameters
testcasethe testcase to run
listthe parsed argument's data
countthe number of argument groups passed
...the list of argument groups (as cmdline_argument_group_t *)

◆ test_parse_parameters()

void test_parse_parameters ( )

Makes sure the command-line parser works.

Test:

not passing any parameters is OK

passing a parameter value a validator deems invalid results in parse failure

passing all valid values results in parse success

passing negative numbers to unsigned integer parameters results in parse failure

can supply logging parameters on command-line

◆ test_validate_ranges()

void test_validate_ranges ( )

Makes sure the double and uint64 range validators work.

Test:

validate_double_range() and validate_uint64_range allow values only if they're in the closed interval between minimum and maximum

validate_double_range() and validate_uint64_range still work if minimum=maximum

◆ run_cmdline_tests()

BOOLEAN run_cmdline_tests ( )

Test runner for this group.

Gets called via the generated test runner.

Returns
whether the test group was executed

Variable Documentation

◆ cmdline_args_list

cmdline_argument_t cmdline_args_list[]
Initial value:
=
{
{{uint64:0}, ARG_BOOL, NULL, L"-bool", L"some boolean"},
{{uint64:12}, ARG_INT, validate_int,L"-int", L"some integer"},
{{dbl:2.5}, ARG_DOUBLE,NULL, L"-double",L"some double"},
{{wcstr:L"foo"},ARG_STRING,NULL, L"-string",L"some string"},
}
boolean
Definition: cmdline.h:22
integer
Definition: cmdline.h:23
UTF-16 string.
Definition: cmdline.h:25
double
Definition: cmdline.h:24
BOOLEAN validate_int(cmdline_value_t val)
A validator function for integers, used in tests.
Definition: cmdline.c:24

A list of arguments, used in tests.

◆ cmdline_args_group

cmdline_argument_group_t cmdline_args_group
Initial value:
=
{
NULL,
}
model for one command line argument
Definition: cmdline.h:41
cmdline_argument_t cmdline_args_list[]
A list of arguments, used in tests.
Definition: cmdline.c:32

An argument group, used in tests.

◆ cmdline_args_testcases

cmdline_args_testcase_t cmdline_args_testcases[]
Initial value:
=
{
{L"empty list", TRUE, 0,12, 2.5, L"foo",NULL},
{L"disable logging", TRUE, 0,12, 2.5, L"foo",L"-no-log "},
{L"negative uint64 1",FALSE,0,12, 2.5, L"foo",L"-int -1 -no-log"},
{L"negative uint64 2",FALSE,0,12, 2.5, L"foo",L"-int -2 -no-log"},
{L"failing validator",FALSE,0,23, 2.5, L"foo",L"-int 23"},
{L"passing all", TRUE, 1,22,-12.98766,L"bar",L"-double -12.98766 -int 22 -string bar -bool"},
}

testcases for test_parse_parameters()

◆ double_range_testcases

validate_range_testcase_t double_range_testcases[]
Initial value:
=
{
{L"below", FALSE,{dbl:-10.0}, {dbl:-5.0}, {dbl:5.0}},
{L"min", TRUE, {dbl:-5.0}, {dbl:-5.0}, {dbl:5.0}},
{L"between",TRUE, {dbl:-123.0},{dbl:-124.0},{dbl:-122.0}},
{L"max", TRUE, {dbl:5.0}, {dbl:-5.0}, {dbl:5.0}},
{L"above", FALSE,{dbl:1.0}, {dbl:1.2}, {dbl:1.3}},
{L"at", TRUE, {dbl:12.3}, {dbl:12.3}, {dbl:12.3}},
}

double test cases for test_validate_ranges

◆ uint64_range_testcases

validate_range_testcase_t uint64_range_testcases[]
Initial value:
=
{
{L"below", FALSE,{uint64:1}, {uint64:5}, {uint64:10}},
{L"min", TRUE, {uint64:2}, {uint64:2}, {uint64:6}},
{L"between",TRUE, {uint64:50},{uint64:10},{uint64:100}},
{L"max", TRUE, {uint64:15},{uint64:5}, {uint64:15}},
{L"above", FALSE,{uint64:3}, {uint64:1}, {uint64:2}},
{L"at", TRUE, {uint64:12},{uint64:12},{uint64:12}},
}

UINT64 test cases for test_validate_ranges.