Fixed compatibility of output.
[AROS.git] / test / clib / sprintf.c
blob1d6dbfaf38baf209b2b3964d111b152e50efabbc
1 /*
2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "test.h"
7 #include <stdio.h>
8 #include <string.h>
10 #define TESTNUMBER1 11
11 #define TESTNUMBER1STRLEN 2
12 #define TEST1RESULT "11"
13 #define TEST2RESULT "11"
14 #define TEST3RESULT "11"
16 #define TEST4CHAR -1
17 #define TEST4STRLEN 6
18 static const char TEST4RESULT[] = {-1, ' ', 'e', 't', 'c', '.', '\0'};
20 #define BUFSIZE 10
22 static void cleanbuffer(char * buf)
24 memset(buf, 0xff, BUFSIZE);
27 static int stringsame(const char *c1, const char *c2, int size)
29 int i;
30 for(i = 0; i < size; i++)
31 if (c1[i] != c2[i]) return 0;
32 return 1;
35 int main()
37 char buf[BUFSIZE], high_ch = TEST4CHAR;
38 int n1 = TESTNUMBER1;
39 long long n2 = TESTNUMBER1;
40 long long n3 = TESTNUMBER1;
42 /* check standard %d conversion */
43 cleanbuffer(buf);
44 TEST((sprintf(buf, "%d", n1) == TESTNUMBER1STRLEN));
45 TEST((stringsame(buf, TEST1RESULT, TESTNUMBER1STRLEN) == 1));
47 /* check standard %qd conversion */
48 cleanbuffer(buf);
49 TEST((sprintf(buf, "%qd", n2) == TESTNUMBER1STRLEN));
50 TEST((stringsame(buf, TEST2RESULT, TESTNUMBER1STRLEN) == 1));
52 /* check standard %lld conversion */
53 cleanbuffer(buf);
54 TEST((sprintf(buf, "%lld", n3) == TESTNUMBER1STRLEN));
55 TEST((stringsame(buf, TEST3RESULT, TESTNUMBER1STRLEN) == 1));
57 /* check standard %c insertion */
58 cleanbuffer(buf);
59 TEST((sprintf(buf, "%c etc.", high_ch) == TEST4STRLEN));
60 TEST((stringsame(buf, TEST4RESULT, TEST4STRLEN) == 1));
62 return OK;
65 void cleanup()