50 unsigned int line,
const char *
fmt, ... ) {
56 actual_len =
vsnprintf ( actual,
sizeof ( actual ),
fmt, args );
58 okx ( actual_len >=
strlen ( expected ), file, line );
59 okx (
strcmp ( actual, expected ) == 0, file, line );
60 if (
strcmp ( actual, expected ) != 0 ) {
61 DBG (
"SNPRINTF expected \"%s\", got \"%s\"\n",
65 #define snprintf_ok( len, result, format, ... ) \ 66 snprintf_okx ( len, result, __FILE__, __LINE__, format, \ 84 snprintf_ok ( 16,
"abc",
"%lc%lc%lc", L
'a', L
'b', L
'c' );
85 snprintf_ok ( 16,
"Hello world",
"%s %s",
"Hello",
"world" );
86 snprintf_ok ( 16,
"Goodbye world",
"%ls %s", L
"Goodbye",
"world" );
87 snprintf_ok ( 16,
"0x1234abcd",
"%p", ( (
void * ) 0x1234abcd ) );
92 snprintf_ok ( 16,
"9876abcd",
"%lx", 0x9876abcdUL );
93 snprintf_ok ( 16,
"1234 5678",
"%04llx %04llx", 0x1234ULL, 0x5678ULL );
105 snprintf_ok ( 64,
"DBG 0x1234 thingy at 0x0003f0c0+0x5c\n",
106 "DBG %p %s at %#08lx+%#zx\n", ( (
void * ) 0x1234 ),
107 "thingy", 0x3f0c0UL, ( (
size_t ) 0x5c ) );
108 snprintf_ok ( 64,
"PCI 00:1f.3",
"PCI %02x:%02x.%x", 0x00, 0x1f, 0x03 );
109 snprintf_ok ( 64,
"Region [1000000,3f000000)",
"Region [%llx,%llx)",
110 0x1000000ULL, 0x3f000000ULL );
static void snprintf_okx(size_t len, const char *expected, const char *file, unsigned int line, const char *fmt,...)
Report an snprintf() test result.
Self-test infrastructure.
const char * name
Test set name.
#define okx(success, file, line)
Report test result.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
size_t strlen(const char *src)
Get length of string.
struct self_test vsprintf_test __self_test
vsprintf() self-test
__builtin_va_list va_list
int strcmp(const char *first, const char *second)
Compare strings.
static void vsprintf_test_exec(void)
Perform vsprintf() self-tests.
#define snprintf_ok(len, result, format,...)
int ssize_t const char * fmt
#define va_start(ap, last)
#define DBG(...)
Print a debugging message.
#define NULL
NULL pointer (VOID *)
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.