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

Tests for string functions. More...

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

Data Structures

struct  wctype_testcase_t
 data structure for wctype_* function test cases More...
 
struct  ftowcs_testcase_t
 data type for test_ftowcs() test cases More...
 
struct  wcstof_testcase_t
 data structure for test_wcstof() test cases More...
 
struct  atoui64_testcase_t
 data type for test_atoui64() test cases More...
 
struct  sprint_status_testcase_t
 data type for test_sprint_status() test cases More...
 

Macros

#define RUN_WCTYPE_TESTCASES(FUNC, CASES)   _run_wctype_testcases(sizeof(CASES)/sizeof(wctype_testcase_t),CASES,FUNC);
 helper macro to run wctype_* test cases More...
 
#define WCSTOF_EPSILON   0.0000001
 margin of error for wcstof() tests
 

Functions

void _run_wctype_testcases (UINTN count, wctype_testcase_t *cases, BOOLEAN(*func)(CHAR16 *))
 Runs given test cases against given wctype_* function. More...
 
void test_wctype_int ()
 Makes sure wctype_int() works. More...
 
void test_wctype_float ()
 Makes sure wctype_float() works. More...
 
void test_ftowcs ()
 Makes sure ftowcs() works. More...
 
void test_ftowcs_boundaries ()
 Makes sure ftowcs() errors out if input exceeds value boundaries. More...
 
void test_wcstof ()
 Makes sure wcstof() works. More...
 
void test_atoui64 ()
 Makes sure atoui64() works. More...
 
void test_sprint_status ()
 Makes sure sprint_status() works. More...
 
void test_memsprintf ()
 Makes sure memsprintf() tracks the pool memory it reserves. More...
 
void test_split_string ()
 Makes sure split_string() works. More...
 
BOOLEAN run_string_tests ()
 Test runner for this group. More...
 

Variables

wctype_testcase_t wctype_floatint_testcases []
 common testcases for test_wctype_int() and test_wctype_float() More...
 
wctype_testcase_t wctype_int_testcases []
 testcases specific to test_wctype_int() More...
 
wctype_testcase_t wctype_float_testcases []
 testcases specific to test_wctype_float() More...
 
ftowcs_testcase_t ftowcs_testcases []
 test cases for test_ftowcs() More...
 
wcstof_testcase_t wcstof_testcases []
 test cases for test_wcstof() More...
 
atoui64_testcase_t atoui64_testcases []
 test cases for test_atoui64() More...
 
sprint_status_testcase_t sprint_status_testcases []
 test cases for test_sprint_status() More...
 

Detailed Description

Tests for string functions.

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

Macro Definition Documentation

◆ RUN_WCTYPE_TESTCASES

#define RUN_WCTYPE_TESTCASES (   FUNC,
  CASES 
)    _run_wctype_testcases(sizeof(CASES)/sizeof(wctype_testcase_t),CASES,FUNC);

helper macro to run wctype_* test cases

Parameters
FUNCthe function to test inputs against
CASESthe test cases to run

Function Documentation

◆ _run_wctype_testcases()

void _run_wctype_testcases ( UINTN  count,
wctype_testcase_t cases,
BOOLEAN(*)(CHAR16 *)  func 
)

Runs given test cases against given wctype_* function.

Parameters
countthe number of test cases
casesthe test cases
functhe function to test inputs against

◆ test_wctype_int()

void test_wctype_int ( )

Makes sure wctype_int() works.

Test:

wctype_int() should fail NULL, empty strings and non-numeric strings

wctype_int() should pass positive and negative integers

wctype_int() should fail decimal numbers

◆ test_wctype_float()

void test_wctype_float ( )

Makes sure wctype_float() works.

Test:

wctype_float() should fail NULL, empty strings and non-numeric strings

wctype_float() should pass positive and negative integers

wctype_float() should pass positive and negative decimal numbers

wctype_float() should fail invalid number-like strings similar to decimals

◆ test_ftowcs()

void test_ftowcs ( )

Makes sure ftowcs() works.

Test:

ftowcs() rounds positive and negative values to 2 decimals with "half away from zero"

ftowcs() always zero-pads to 2 decimals

◆ test_ftowcs_boundaries()

void test_ftowcs_boundaries ( )

Makes sure ftowcs() errors out if input exceeds value boundaries.

Test:
ftowcs() logs an error when trying to convert very low or very high numbers

◆ test_wcstof()

void test_wcstof ( )

Makes sure wcstof() works.

Test:
_wcstof() parses a numeric string into a double value

◆ test_atoui64()

void test_atoui64 ( )

Makes sure atoui64() works.

Test:
atoui64() parses integer strings from 0 to 2^64-1

◆ test_sprint_status()

void test_sprint_status ( )

Makes sure sprint_status() works.

Test:

sprint_status() includes the given function's name in the result

sprint_status() includes the raw EFI_STATUS code in the result

sprint_status() converts EFI_STATUS codes to readable messages in the result

◆ test_memsprintf()

void test_memsprintf ( )

Makes sure memsprintf() tracks the pool memory it reserves.

Test:
each call to memsprintf() should add exactly 1 tracked pool memory entry, regardless of how many arguments were passed.

◆ test_split_string()

void test_split_string ( )

Makes sure split_string() works.

Test:

split_string() returns 0 entries and writes NULL when requested to split a NULL string

split_string() splits a string by the given delimiter into the correct parts

split_string() includes empty string parts between delimiters

split_string() returns 1 entry and outputs the input string as array when requested to split an empty string

◆ run_string_tests()

BOOLEAN run_string_tests ( )

Test runner for this group.

Gets called via the generated test runner.

Returns
whether the test group was executed

Variable Documentation

◆ wctype_floatint_testcases

wctype_testcase_t wctype_floatint_testcases[]
Initial value:
={
{FALSE,NULL},
{FALSE,L""},
{FALSE,L"-a"},
{FALSE,L"-"},
{FALSE,L"1a"},
{FALSE,L"-1a"},
{TRUE, L"1"},
{TRUE, L"1123"},
{TRUE, L"-1123"},
{FALSE,L"-1123a"},
{FALSE,L"abcd12"}
}

common testcases for test_wctype_int() and test_wctype_float()

◆ wctype_int_testcases

wctype_testcase_t wctype_int_testcases[]
Initial value:
={
{FALSE,L"1.0"},
}

testcases specific to test_wctype_int()

◆ wctype_float_testcases

wctype_testcase_t wctype_float_testcases[]
Initial value:
={
{TRUE, L"1.1"},
{TRUE, L"-1.1"},
{TRUE, L"0.123456789"},
{TRUE, L"-99999999.9"},
{FALSE,L"1.1.1"},
{FALSE,L"1."}
}

testcases specific to test_wctype_float()

◆ ftowcs_testcases

ftowcs_testcase_t ftowcs_testcases[]
Initial value:
=
{
{L"-1000000000.00",-1000000000.00},
{L"-999999999.99",-999999999.99},
{L"-123456789.01",-123456789.012},
{L"-10.00",-10.001},
{L"-10.00",-10.000},
{L"-10.00",-9.999},
{L"-10.00",-9.995001},
{L"-9.99",-9.9949},
{L"-9.00",-9.0},
{L"-0.51",-0.51},
{L"-0.50",-0.5},
{L"-0.49",-0.49},
{L"-0.00",-0.001},
{L"0.00",0.0},
{L"0.00",0.001},
{L"0.45",0.449},
{L"0.45",0.45},
{L"10.00",9.999},
{L"10.00",10.00},
{L"99999.99",99999.99},
{L"100000.00",100000.00},
{L"999999999.99",999999999.99},
{L"1000000000.00",1000000000.00},
}

test cases for test_ftowcs()

◆ wcstof_testcases

wcstof_testcase_t wcstof_testcases[]
Initial value:
=
{
{1.2,L"1.2"},
{-3.1,L"-3.1"},
{4321.987,L"4321.987"},
{654321.654,L"654321.654"},
{87654321.321,L"87654321.321"},
{123456789.0123,L"123456789.0123"}
}

test cases for test_wcstof()

◆ atoui64_testcases

atoui64_testcase_t atoui64_testcases[]
Initial value:
=
{
{0,"0"},
{12,"12"},
{4294967295,"4294967295"},
{4294967296,"4294967296"},
{4294967297,"4294967297"},
{9223372036854775807,"9223372036854775807"},
{9223372036854775808u,"9223372036854775808"},
{9223372036854775809u,"9223372036854775809"},
{18446744073709551614u,"18446744073709551614"},
{18446744073709551615u,"18446744073709551615"},
}

test cases for test_atoui64()

◆ sprint_status_testcases

sprint_status_testcase_t sprint_status_testcases[]
Initial value:
=
{
{EFI_UNSUPPORTED, L"case1",L"case1() returned status 3 (Unsupported)"},
{EFI_INVALID_PARAMETER,L"case2",L"case2() returned status 2 (Invalid Parameter)"},
}

test cases for test_sprint_status()