2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
10 #define TESTSTRING "test"
11 #define TESTSTRING2 "123456789"
12 #define TESTSTRING3 "0123456789"
13 #define TESTSTRING4 "a long test string"
19 char buf
[BUFSIZE
+1] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
21 /* first check strings shorter than buffer */
22 TEST((snprintf(buf
, BUFSIZE
, "%s", TESTSTRING
) == strlen(TESTSTRING
)));
23 TEST((buf
[strlen(TESTSTRING
)] == 0));
24 TEST((buf
[strlen(TESTSTRING
) + 1] == (char) 0xff));
26 /* now strings with length equal to buffer size - 1 */
27 TEST((snprintf(buf
, BUFSIZE
, "%s", TESTSTRING2
) == strlen(TESTSTRING2
)));
28 TEST((buf
[strlen(TESTSTRING2
)] == 0));
29 TEST((buf
[BUFSIZE
] == (char) 0xff));
31 /* now strings with length equal to buffer size (no zero byte written) */
32 TEST((snprintf(buf
, BUFSIZE
, "%s", TESTSTRING3
) == strlen(TESTSTRING3
)));
33 TEST((buf
[BUFSIZE
-1] == TESTSTRING3
[strlen(TESTSTRING3
)-1]));
34 TEST((buf
[BUFSIZE
] == (char) 0xff));
36 /* now strings longer than buffer size */
37 TEST((snprintf(buf
, BUFSIZE
, "%s", TESTSTRING4
) == strlen(TESTSTRING4
)));
38 TEST((buf
[BUFSIZE
-1] == TESTSTRING4
[BUFSIZE
-1]));
39 TEST((buf
[BUFSIZE
] == (char) 0xff));