The width digit was missing.
[AROS.git] / test / clib / snprintf.c
blobdf7c975f95e620d7ade80bf12449836553416a21
1 #include "test.h"
2 #include <stdio.h>
3 #include <string.h>
5 #define TESTSTRING "test"
6 #define TESTSTRING2 "123456789"
7 #define TESTSTRING3 "0123456789"
8 #define TESTSTRING4 "a long test string"
10 #define BUFSIZE 10
12 int main()
14 char buf[BUFSIZE+1] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
16 /* first check strings shorter than buffer */
17 TEST((snprintf(buf, BUFSIZE, "%s", TESTSTRING) == strlen(TESTSTRING)));
18 TEST((buf[strlen(TESTSTRING)] == 0));
19 TEST((buf[strlen(TESTSTRING) + 1] == (char) 0xff));
21 /* now strings with length equal to buffer size - 1 */
22 TEST((snprintf(buf, BUFSIZE, "%s", TESTSTRING2) == strlen(TESTSTRING2)));
23 TEST((buf[strlen(TESTSTRING2)] == 0));
24 TEST((buf[BUFSIZE] == (char) 0xff));
26 /* now strings with length equal to buffer size (no zero byte written) */
27 TEST((snprintf(buf, BUFSIZE, "%s", TESTSTRING3) == strlen(TESTSTRING3)));
28 TEST((buf[BUFSIZE-1] == TESTSTRING3[strlen(TESTSTRING3)-1]));
29 TEST((buf[BUFSIZE] == (char) 0xff));
31 /* now strings longer than buffer size */
32 TEST((snprintf(buf, BUFSIZE, "%s", TESTSTRING4) == strlen(TESTSTRING4)));
33 TEST((buf[BUFSIZE-1] == TESTSTRING4[BUFSIZE-1]));
34 TEST((buf[BUFSIZE] == (char) 0xff));
35 return OK;
38 void cleanup()