41 #define DATA(...) { __VA_ARGS__ } 44 #define LINES(...) { __VA_ARGS__ } 69 #define LINEBUF_TEST( name, DATA, LINES ) \ 70 static const char name ## _data[] = DATA; \ 71 static const char * name ## _lines[] = LINES; \ 72 static struct linebuf_test name = { \ 73 .data = name ## _data, \ 74 .len = ( sizeof ( name ## _data ) - 1 ), \ 75 .lines = name ## _lines, \ 76 .count = ( sizeof ( name ## _lines ) / \ 77 sizeof ( name ## _lines[0] ) ), \ 82 (
"HTTP/1.1 200 OK\r\n" 83 "Content-Length: 123\r\n" 84 "Content-Type: text/plain\r\n" 86 LINES (
"HTTP/1.1 200 OK",
87 "Content-Length: 123",
88 "Content-Type: text/plain",
93 (
"LF only\n" "CRLF\r\n" "\n" "\n" "\r\n" "\r\n" "CR only\r" ),
94 LINES (
"LF only",
"CRLF",
"",
"",
"",
"",
109 (
" multiple calls\r\nand so was this one\r" ),
110 LINES (
"This line was split across multiple calls",
NULL ) );
114 (
"\nbut not this one\r\n" ),
115 LINES (
"and so was this one",
"but not this one" ) );
124 (
"This line came after a zero-length call\r\n" ),
125 LINES (
"This line came after a zero-length call" ) );
129 (
"This\r\ntest\r\nincludes\r\n\r\nsome\0binary\0data\r\n" ),
140 const char *file,
unsigned int line ) {
143 memset ( linebuf, 0,
sizeof ( *linebuf ) );
146 #define linebuf_init_ok( linebuf ) \ 147 linebuf_init_okx ( linebuf, __FILE__, __LINE__ ) 159 const char *file,
unsigned int line ) {
161 size_t remaining =
test->len;
164 const char *expected;
172 for ( i = 0 ; i <
test->count ; i++ ) {
182 }
else if ( actual !=
NULL ) {
183 DBGC (
test,
"LINEBUF %p \"%s\" (consumed %d)\n",
186 DBGC (
test,
"LINEBUF %p unterminated (consumed %d)\n",
191 expected =
test->lines[i];
194 okx (
rc < 0, file, line );
195 okx ( remaining > 0, file, line );
198 okx (
len >= 0, file, line );
199 okx ( ( (
size_t )
len ) <= remaining, file, line );
202 if ( expected ==
NULL ) {
203 okx ( actual ==
NULL, file, line );
205 okx ( actual !=
NULL, file, line );
206 okx (
strcmp ( actual, expected ) == 0, file, line );
215 okx ( remaining == 0, file, line );
217 #define linebuf_consume_ok( test, linebuf ) \ 218 linebuf_consume_okx ( test, linebuf, __FILE__, __LINE__ ) 230 const char *file,
unsigned int line ) {
232 const char *expected;
236 actual = linebuf->
data;
237 for ( i = 0 ; i <
test->count ; i++ ) {
240 okx ( actual !=
NULL, file, line );
241 okx ( actual >= linebuf->
data, file, line );
242 expected =
test->lines[i];
245 okx (
strcmp ( actual, expected ) == 0, file, line );
248 actual += (
strlen ( actual ) + 1 );
249 okx ( actual <= ( linebuf->
data + linebuf->
len ), file, line );
252 #define linebuf_accumulated_ok( test, linebuf ) \ 253 linebuf_accumulated_okx ( test, linebuf, __FILE__, __LINE__ ) 263 const char *file,
unsigned int line ) {
269 #define linebuf_empty_ok( linebuf ) \ 270 linebuf_empty_okx ( linebuf, __FILE__, __LINE__ ) 280 unsigned int line ) {
288 #define linebuf_ok( test ) \ 289 linebuf_okx ( test, __FILE__, __LINE__ ) struct self_test linebuf_test __self_test
Line buffer self-test.
struct arbelprm_rc_send_wqe rc
static const char linebuf_failure[1]
Line buffer test expected failure indicator.
#define linebuf_init_ok(linebuf)
static void linebuf_empty_okx(struct line_buffer *linebuf, const char *file, unsigned int line)
Report line buffer emptying test result.
static void linebuf_consume_okx(struct linebuf_test *test, struct line_buffer *linebuf, const char *file, unsigned int line)
Report line buffer consumption test result.
Self-test infrastructure.
const char * name
Test set name.
size_t len
Length of raw data.
#define LINES(...)
Define inline lines.
#define LINEBUF_TEST(name, DATA, LINES)
Define a line buffer test.
#define linebuf_empty_ok(linebuf)
#define linebuf_consume_ok(test, linebuf)
#define okx(success, file, line)
Report test result.
static void linebuf_init_okx(struct line_buffer *linebuf, const char *file, unsigned int line)
Report line buffer initialisation test result.
void empty_line_buffer(struct line_buffer *linebuf)
Discard line buffer contents.
size_t len
Length of buffered data.
const void * data
Raw data.
static void linebuf_accumulated_okx(struct linebuf_test *test, struct line_buffer *linebuf, const char *file, unsigned int line)
Report line buffer accumulation test result.
char * strerror(int errno)
Retrieve string representation of error number.
static void linebuf_okx(struct linebuf_test *test, const char *file, unsigned int line)
Report line buffer combined test result.
unsigned int count
Number of expected lines.
size_t strlen(const char *src)
Get length of string.
char * buffered_line(struct line_buffer *linebuf)
Retrieve buffered-up line.
const char ** lines
Expected sequence of lines.
static void linebuf_test_exec(void)
Perform line buffer self-tests.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int strcmp(const char *first, const char *second)
Compare strings.
uint8_t data[48]
Additional event data.
int line_buffer(struct line_buffer *linebuf, const char *data, size_t len)
Buffer up received data by lines.
#define NULL
NULL pointer (VOID *)
void * memset(void *dest, int character, size_t len) __nonnull