2022-12-03 22:38:14 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "mbedtls/platform.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2022-12-03 23:50:05 +01:00
|
|
|
|
|
|
|
#define NEWLINE_CHAR '\n'
|
|
|
|
#define SPACE_CHAR ' '
|
|
|
|
#define DOUBLE_QUOTE_CHAR '"'
|
|
|
|
#define COLON_CHAR ':'
|
|
|
|
#define BACKSLASH_CHAR '\\'
|
|
|
|
#define LOWERCASE_N_CHAR 'n'
|
2022-12-03 22:38:14 +01:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void printf_int(char *format, int x, char *result)
|
|
|
|
{
|
|
|
|
char *output = NULL;
|
|
|
|
const size_t n = strlen(result);
|
|
|
|
|
|
|
|
/* Nominal case: buffer just large enough */
|
|
|
|
ASSERT_ALLOC(output, n + 1);
|
|
|
|
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, x));
|
|
|
|
ASSERT_COMPARE(result, n + 1, output, n + 1);
|
|
|
|
mbedtls_free(output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_free(output);
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2022-12-03 23:50:05 +01:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void printf_char2(char *format, int arg1, int arg2, char *result)
|
|
|
|
{
|
|
|
|
char *output = NULL;
|
|
|
|
const size_t n = strlen(result);
|
|
|
|
|
|
|
|
/* Nominal case: buffer just large enough */
|
|
|
|
ASSERT_ALLOC(output, n + 1);
|
|
|
|
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, arg1, arg2));
|
|
|
|
ASSERT_COMPARE(result, n + 1, output, n + 1);
|
|
|
|
mbedtls_free(output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_free(output);
|
|
|
|
}
|
|
|
|
/* END_CASE */
|