Skip to content
代码片段 群组 项目
提交 c6a8bf0f 编辑于 作者: Bence Szépkúti's avatar Bence Szépkúti
浏览文件

Test handling of format macros defined in debug.h

上级 12210526
No related branches found
No related tags found
无相关合并请求
# printf_int_expr expects a smuggled string expression as its first parameter
printf "%" MBEDTLS_PRINTF_SIZET, 0
printf_int_expr:(uintptr_t) "%" MBEDTLS_PRINTF_SIZET:sizeof(size_t):0:"0"
printf "%" MBEDTLS_PRINTF_LONGLONG, 0
printf_int_expr:(uintptr_t) "%" MBEDTLS_PRINTF_LONGLONG:sizeof(long long):0:"0"
Debug print msg (threshold 1, level 0)
debug_print_msg_threshold:1:0:"MyFile":999:"MyFile(0999)\: Text message, 2 == 2\n"
......
......@@ -53,6 +53,34 @@ static void string_debug(void *data, int level, const char *file, int line, cons
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
void printf_int_expr(intmax_t smuggle_format_expr, /* TODO: teach test framework about string expressions */
intmax_t sizeof_x, intmax_t x, char *result)
{
const char *format = (char *) ((uintptr_t) smuggle_format_expr);
char *output = NULL;
const size_t n = strlen(result);
/* Nominal case: buffer just large enough */
TEST_CALLOC(output, n + 1);
if ((size_t) sizeof_x <= sizeof(int)) { // Any smaller integers would be promoted to an int due to calling a vararg function
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, (int) x));
} else if (sizeof_x == sizeof(long)) {
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, (long) x));
} else if (sizeof_x == sizeof(long long)) {
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, (long long) x));
} else {
TEST_FAIL(
"sizeof_x <= sizeof(int) || sizeof_x == sizeof(long) || sizeof_x == sizeof(long long)");
}
TEST_MEMORY_COMPARE(result, n + 1, output, n + 1);
exit:
mbedtls_free(output);
output = NULL;
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_TLS_C */
void debug_print_msg_threshold(int threshold, int level, char *file,
int line, char *result_str)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册