Check standard %c insertion.
[AROS.git] / test / clib / sprintf.c
blob3c9563b437130031357a64588bab9cf878c69dca
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>
9 #include <proto/dos.h>
10 #include <aros/debug.h>
12 #define TESTNUMBER1 11
13 #define TESTNUMBER1STRLEN 2
14 #define TEST1RESULT "11"
15 #define TEST2RESULT "11"
16 #define TEST3RESULT "11"
18 #define TEST4CHAR -1
19 #define TEST4STRLEN 6
20 static const char TEST4RESULT[] = {-1, ' ', 'e', 't', 'c', '.', '\0'};
22 #define BUFSIZE 10
24 static void cleanbuffer(char * buf)
26 memset(buf, 0xff, BUFSIZE);
29 static int stringsame(const char *c1, const char *c2, int size)
31 int i;
32 for(i = 0; i < size; i++)
33 if (c1[i] != c2[i]) return 0;
34 return 1;
37 int main()
39 char buf[BUFSIZE], high_ch = TEST4CHAR;
40 int n1 = TESTNUMBER1;
41 long long n2 = TESTNUMBER1;
42 long long n3 = TESTNUMBER1;
44 /* check standard %d conversion */
45 cleanbuffer(buf);
46 TEST((sprintf(buf, "%d", n1) == TESTNUMBER1STRLEN));
47 TEST((stringsame(buf, TEST1RESULT, TESTNUMBER1STRLEN) == 1));
49 /* check standard %qd conversion */
50 cleanbuffer(buf);
51 TEST((sprintf(buf, "%qd", n2) == TESTNUMBER1STRLEN));
52 TEST((stringsame(buf, TEST2RESULT, TESTNUMBER1STRLEN) == 1));
54 /* check standard %lld conversion */
55 cleanbuffer(buf);
56 TEST((sprintf(buf, "%lld", n3) == TESTNUMBER1STRLEN));
57 TEST((stringsame(buf, TEST3RESULT, TESTNUMBER1STRLEN) == 1));
59 /* check standard %c insertion */
60 cleanbuffer(buf);
61 TEST((sprintf(buf, "%c etc.", high_ch) == TEST4STRLEN));
62 TEST((stringsame(buf, TEST4RESULT, TEST4STRLEN) == 1));
64 return OK;
67 void cleanup()