[test] Update snprintf_ok() to use okx()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/52/head
Michael Brown 2016-04-12 11:45:58 +01:00
parent 597521ef53
commit 320488d0f9
1 changed files with 25 additions and 14 deletions

View File

@ -39,21 +39,32 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Report an snprintf() test result * Report an snprintf() test result
* *
* @v len Buffer length
* @v expected Expected result
* @v file Test code file
* @v line Test code line
* @v format Format string
* @v ... Arguments
*/ */
#define snprintf_ok( len, result, format, ... ) do { \ static void snprintf_okx ( size_t len, const char *expected, const char *file,
char actual[ (len) ]; \ unsigned int line, const char *fmt, ... ) {
const char expected[] = result; \ char actual[len];
size_t actual_len; \ size_t actual_len;
\ va_list args;
actual_len = snprintf ( actual, sizeof ( actual ), \
format, ##__VA_ARGS__ ); \ va_start ( args, fmt );
ok ( actual_len >= strlen ( result ) ); \ actual_len = vsnprintf ( actual, sizeof ( actual ), fmt, args );
ok ( strcmp ( actual, expected ) == 0 ); \ va_end ( args );
if ( strcmp ( actual, expected ) != 0 ) { \ okx ( actual_len >= strlen ( expected ), file, line );
DBG ( "SNPRINTF expected \"%s\", got \"%s\"\n", \ okx ( strcmp ( actual, expected ) == 0, file, line );
expected, actual ); \ if ( strcmp ( actual, expected ) != 0 ) {
} \ DBG ( "SNPRINTF expected \"%s\", got \"%s\"\n",
} while ( 0 ) expected, actual );
}
}
#define snprintf_ok( len, result, format, ... ) \
snprintf_okx ( len, result, __FILE__, __LINE__, format, \
##__VA_ARGS__ )
/** /**
* Perform vsprintf() self-tests * Perform vsprintf() self-tests