-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_suite
192 lines (118 loc) · 5.54 KB
/
test_suite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <limits.h>
#include <stdio.h>
#include "holberton.h"
/**
* main - test suite for printf
* run commands in bash
* $ gcc *c -o a.out; ./a.out > a
* $ gcc -DDEFINE'printf =_printf' *c -o b.out; ./b.out > b
* $ hexdump -C a > a_hexdump; hexdump -C b > b_hexdump
* $ diff a_hexdump b_hexdump
*
* example output:
* < 00000a80 3a 20 30 78 37 66 66 64 35 66 63 64 62 65 63 30 |: 0x7ffd5fcdbec0|
* ---
* > 00000a80 3a 20 30 78 37 66 66 65 30 37 36 63 33 37 30 30 |: 0x7ffe076c3700|
*
* $ hexdump -s 0xa70 -C a | head -n3
*
* example output:
* 00000a70 72 65 73 73 20 77 69 74 68 20 77 69 64 74 68 29 |ress with width)|
* 00000a80 3a 20 30 78 37 66 66 64 35 66 63 64 62 65 63 30 |: 0x7ffd5fcdbec0|
* 00000a90 2e 0a 74 65 73 74 35 33 28 27 2d 27 2c 20 77 69 |..test53('-', wi|
*
* There is a difference at test 52
*
* Return: Always 0
*/
int main(void)
{
int i = 12;
long int l = 12l;
short int h = 12;
int *n = NULL;
/*non spec printf conditions*/
printf("non spec printf conditions\n\n");
printf("test01(ptr string):String");
printf("test02([fwplf]format tags out of order):%+- 0#9.5lh+i.\n",1);
printf("test03([fwpf]format tags out of order):%+- 0#9.5+i.\n",1);
printf("test04([fwf]format tags out of order):%+- 0#9+i.\n", 1);
printf("test05([fplf]format tags out of order):%.5lh+- 0#i.\n",1);
printf("test06([flf]format tags out of order):%lh+- 0#i.\n",1);
printf("test07[fwpl](format tags in order no spec):%+- 0#9.5lh\n",1);
printf(NULL);
printf("\n\n");
/*string specifier conditions*/
printf("s and c specifier conditions\n\n");
printf("test10(string spec with all flags, width, prec): %+0 #-9.5s, %+0 #-9.5c.", "holberton", 'c');
/* printf("test11(string spec with wrong argument will seg fault):%s, %s, %s.\n", 1, 'c', &i);*/
printf("test12(string spec with -, width, prec): %-9.5s, %-9c.\n", "holberton", 'c');
printf("test13(string spec with width < prec and '-'): %-2.5s.\n", "holberton");
printf("test14(string spec with width, prec): %9.5s, %9c.\n", "holberton", 'c');
printf("test15(string spec with , all flags minus '-' width, prec): %+ #09.5s.\n", "holberton");
printf("test16(passing null to s, c): %s, %c.\n\n", n, n);
/*i and d specifier conditions*/
printf("i and d specifer conditions\n\n");
printf("test200(negative number with all flags):%+- 0#i.\n", -1);
printf("test201(positive number with all flags):%+- 0#d.\n", 1);
printf("test202(positive number with '+', ' '):%+ d.\n", 1);
printf("test203(positive number with' '):% d.\n", 1);
printf("test204('+', '0', with precision > width):%0+9.5d.\n", 1);
printf("test205('+', '0', with precision < width):%+05.9d.\n", 1);
printf("test206(' ', with precision > width):%- 9.5d.\n", 1);
printf("test207(length: long):%ld.\n", l);
printf("test208(length: short):%hd.\n", h);
printf("test209(' ', '0' with precision > width):%-0 9.5d.\n", 1);
printf("test210(considering null, spec d):%i.\n\n", n);
/*u specifer conditions*/
printf("u specifer conditions\n\n");
printf("test30(negative number with all flags):%+- 0#u.\n", -1);
printf("test31(positive number with all flags):%+- 0#u.\n", 1);
printf("test32(positive number with '+', ' '):%+ u.\n", 1);
printf("test33('0', with precision > width):%09.5u.\n", 1);
printf("test34( '-', '0', with precision < width):%-05.9u.\n", 1);
printf("test35('0','-' with precision > width):%-09.5u.\n", 1);
printf("test36(length: long):%lu.\n", l);
printf("test37(length: short):%hu.\n", h);
printf("test38(considering null, spec u):%u.\n\n", n);
/*o, x, X specifier conditions*/
printf("o, x, X specifer conditions\n\n");
printf("test30(negative number with all flags):%+- 0#o, %+- 0#x, %+- 0#X.\n", -1, -1, -1);
printf("test31(positive number with all flags):%+- 0#o, %+- 0#x, %+- 0#X.\n", 1, 1, 1);
printf("test32(positive number with '+', ' '):%+ o, %+ x, %+ X.\n", 1, 1, 1);
printf("test33('0', with precision > width):%09.5o, %09.5x %09.5.\n", 1, 1, 1);
printf("test34( '-', '0', with precision < width):%-05.9o, %-05.9x, %-05.9X.\n", 1, 1, 1);
printf("test35('0','-' with precision > width):%-09.5o, %-09.5x, %-09.5X.\n", 1, 1, 1);
printf("test36(length: long):%lo, %lx, %lX.\n", l, l, l);
printf("test37(length: short):%ho, %hx, %hX.\n", h, h, h);
printf("test38(consinder null, spec o, x, X):%o, %x, %X.\n\n", n, n, n);
/*binary specifier conditions*/
printf("b specifer conditions\n\n");
printf("test40(negative number with all flags):%+- 0#b.\n", -1);
printf("test41(positive number with all flags):%+- 0#b.\n", 1);
printf("test42(positive number with '+', ' '):%+ b", 1);
printf("test43('0', with precision > width):%09.5b.\n", 1);
printf("test44( '-', '0', with precision < width):%-05.9b.\n", 1);
printf("test45('0','-' with precision > width):%-09.5b.\n", 1);
printf("test46(length: long):%lb.\n", l);
printf("test47(length: short):%hb.\n", h);
printf("test48(considering null):%b.\n\n", n);
/*pointer specifier conditions*/
printf("p specifer conditions\n\n");
printf("test50(address number with all flags):%+- 0#9.5lhp.\n", &l);
printf("test51(address with '+', ' '):%+ 10p.\n", &l);
printf("test52(address with width):% 10p.\n", &l);
printf("test53('-', width):%-15p.\n", &l);
printf("test54(width):%15p.\n", &l);
printf("test55(consinder null, spec p):%p.\n\n", n);
/*printing % */
printf("printing %\n\n");
printf("test60 odd number of % % % % %\n");
printf("test61 even number of % % % % % %\n");
printf("test62 odd number with new line of % % % % %\n");
printf("test63 % % % % %");
printf("\n");
printf("%");
printf("\n\n");
return (0);
}