Data URI tests.
More...
#include <string.h>
#include <ipxe/uri.h>
#include <ipxe/datauri.h>
#include <ipxe/test.h>
Go to the source code of this file.
|
| | FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) |
| static void | datauri_okx (const char *uristring, const void *expected, size_t expected_len, const char *file, unsigned int line) |
| | Report result of data URI test.
|
| static void | datauri_fail_okx (const char *uristring, const char *file, unsigned int line) |
| | Report result of data URI failure test.
|
| static void | datauri_test_exec (void) |
| | Perform data URI self-test.
|
Data URI tests.
Definition in file datauri_test.c.
◆ DATA
◆ datauri_ok
| #define datauri_ok |
( |
| uristring, |
|
|
| EXPECTED ) |
Value:do { \
datauri_okx ( uristring, expected, sizeof ( expected ), \
__FILE__, __LINE__ ); \
} while ( 0 )
#define EXPECTED(...)
Define inline expected result point.
Definition at line 79 of file datauri_test.c.
79#define datauri_ok( uristring, EXPECTED ) do { \
80 static const uint8_t expected[] = EXPECTED; \
81 datauri_okx ( uristring, expected, sizeof ( expected ), \
82 __FILE__, __LINE__ ); \
83 } while ( 0 )
Referenced by datauri_test_exec().
◆ datauri_fail_ok
| #define datauri_fail_ok |
( |
| uristring | ) |
|
Value:
static void datauri_fail_okx(const char *uristring, const char *file, unsigned int line)
Report result of data URI failure test.
Definition at line 115 of file datauri_test.c.
115#define datauri_fail_ok( uristring ) \
116 datauri_fail_okx ( uristring, __FILE__, __LINE__ )
Referenced by datauri_test_exec().
◆ FILE_LICENCE()
| FILE_LICENCE |
( |
GPL2_OR_LATER_OR_UBDL | | ) |
|
◆ datauri_okx()
| void datauri_okx |
( |
const char * | uristring, |
|
|
const void * | expected, |
|
|
size_t | expected_len, |
|
|
const char * | file, |
|
|
unsigned int | line ) |
|
static |
Report result of data URI test.
- Parameters
-
| uristring | URI string |
| expected | Expected parsed data |
| expected_len | Length of expected parsed data |
| file | Test code file |
| line | Test code line |
Definition at line 52 of file datauri_test.c.
54 {
58
59
65
66
69
70
72 okx (
len >= 0, file, line );
73 okx ( ( (
size_t )
len ) == expected_len, file, line );
74 okx (
memcmp ( actual, expected, expected_len ) == 0, file, line );
75
76
78}
#define NULL
NULL pointer (VOID *).
int datauri_parse(struct uri *uri, void *buf)
Parse data URI.
static size_t datauri_max_len(struct uri *uri)
Get maximum length of parsed data URI.
int strcmp(const char *first, const char *second)
Compare strings.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
size_t strlen(const char *src)
Get length of string.
A Uniform Resource Identifier.
const char * scheme
Scheme.
const char * opaque
Opaque part.
#define okx(success, file, line)
Report test result.
struct uri * parse_uri(const char *uri_string)
Parse URI.
static void uri_put(struct uri *uri)
Decrement URI reference count.
References datauri_max_len(), datauri_parse(), len, memcmp(), NULL, okx, uri::opaque, parse_uri(), uri::scheme, strcmp(), strlen(), and uri_put().
◆ datauri_fail_okx()
| void datauri_fail_okx |
( |
const char * | uristring, |
|
|
const char * | file, |
|
|
unsigned int | line ) |
|
static |
Report result of data URI failure test.
- Parameters
-
| uristring | URI string |
| file | Test code file |
| line | Test code line |
Definition at line 92 of file datauri_test.c.
93 {
97
98
104
105
107
108
110 okx (
len < 0, file, line );
111
112
114}
References datauri_max_len(), datauri_parse(), len, NULL, okx, uri::opaque, parse_uri(), uri::scheme, strcmp(), strlen(), and uri_put().
◆ datauri_test_exec()
| void datauri_test_exec |
( |
void | | ) |
|
|
static |
Perform data URI self-test.
Definition at line 122 of file datauri_test.c.
122 {
123
124
128
129
131 DATA (
'h',
'e',
'l',
'l',
'o',
' ',
'w',
'o',
'r',
'l',
132 'd', '!' ) );
134 DATA (
's',
'i',
'm',
'p',
'l',
'e' ) );
135 datauri_ok (
"data:text/plain;charset=US-ASCII;base64,ZW5jb2RlZA==",
136 DATA (
'e',
'n',
'c',
'o',
'd',
'e',
'd' ) );
137 datauri_ok (
"data:application/octet-string;base64,d2l0aABudWw=",
138 DATA (
'w',
'i',
't',
'h', 0x00,
'n',
'u',
'l' ) );
139
140
143}
#define DATA(...)
Define inline data.
#define DATA(...)
Define inline data.
#define datauri_ok(uristring, EXPECTED)
#define datauri_fail_ok(uristring)
References DATA, datauri_fail_ok, and datauri_ok.
◆ __self_test
Initial value: = {
.name = "datauri",
}
static void datauri_test_exec(void)
Perform data URI self-test.
Data URI self-test.
Definition at line 146 of file datauri_test.c.
146 {
147 .name = "datauri",
149};