mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-18 14:42:24 +00:00
Exercise string parsing in the test framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
1a24895bfd
commit
a9946952b4
@ -1,6 +1,6 @@
|
|||||||
# The test cases for printf and integers have two purposes: they exercise
|
# The test cases for printf and integers have two purposes: they exercise
|
||||||
# the printf function family, and they exercise the passing of integers
|
# the printf function family, and they exercise the passing of integers
|
||||||
# through the test framework.
|
# and strings through the test framework.
|
||||||
|
|
||||||
printf "%d", 0
|
printf "%d", 0
|
||||||
printf_int:"%d":0:"0"
|
printf_int:"%d":0:"0"
|
||||||
@ -55,3 +55,44 @@ printf_int:"%d":-2147483648:"-2147483648"
|
|||||||
|
|
||||||
printf "%d", -0x80000000
|
printf "%d", -0x80000000
|
||||||
printf_int:"%d":-0x80000000:"-2147483648"
|
printf_int:"%d":-0x80000000:"-2147483648"
|
||||||
|
|
||||||
|
# The next few test cases exercise how the test framework handles special
|
||||||
|
# characters in strings.
|
||||||
|
printf "%c", SPACE, SPACE
|
||||||
|
printf_char2:"%c%c":SPACE_CHAR:SPACE_CHAR:" "
|
||||||
|
|
||||||
|
printf "%c", NEWLINE, SPACE
|
||||||
|
printf_char2:"%c%c":NEWLINE_CHAR:SPACE_CHAR:"\n "
|
||||||
|
|
||||||
|
printf "%c", DOUBLE QUOTE, SPACE
|
||||||
|
printf_char2:"%c%c":DOUBLE_QUOTE_CHAR:SPACE_CHAR:"\" "
|
||||||
|
|
||||||
|
printf "%c", COLON, SPACE
|
||||||
|
printf_char2:"%c%c":COLON_CHAR:SPACE_CHAR:"\: "
|
||||||
|
|
||||||
|
printf "%c", BACKSLASH, SPACE
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:SPACE_CHAR:"\\ "
|
||||||
|
|
||||||
|
printf "%c", SPACE, BACKSLASH
|
||||||
|
printf_char2:"%c%c":SPACE_CHAR:BACKSLASH_CHAR:" \\"
|
||||||
|
|
||||||
|
printf "%c%c", COLON, COLON
|
||||||
|
printf_char2:"%c%c":COLON_CHAR:COLON_CHAR:"\:\:"
|
||||||
|
|
||||||
|
printf "%c%c", COLON, NEWLINE
|
||||||
|
printf_char2:"%c%c":COLON_CHAR:NEWLINE_CHAR:"\:\n"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, NEWLINE
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:NEWLINE_CHAR:"\\\n"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, DOUBLE QUOTE
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:DOUBLE_QUOTE_CHAR:"\\\""
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, COLON
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:COLON_CHAR:"\\\:"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, BACKSLASH
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:BACKSLASH_CHAR:"\\\\"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, n
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:LOWERCASE_N_CHAR:"\\n"
|
||||||
|
@ -4,6 +4,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define NEWLINE_CHAR '\n'
|
||||||
|
#define SPACE_CHAR ' '
|
||||||
|
#define DOUBLE_QUOTE_CHAR '"'
|
||||||
|
#define COLON_CHAR ':'
|
||||||
|
#define BACKSLASH_CHAR '\\'
|
||||||
|
#define LOWERCASE_N_CHAR 'n'
|
||||||
/* END_HEADER */
|
/* END_HEADER */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
@ -23,3 +30,21 @@ exit:
|
|||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user