-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
186 lines (170 loc) · 5.3 KB
/
main.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vtarasiu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/18 22:25:27 by vtarasiu #+# #+# */
/* Updated: 2019/07/20 19:19:39 by vtarasiu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftasm.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#define BOOL(x) ((x) ? "true" : "false")
int test_iswhat(const char *name, int (*orig)(int), int (*asm_f)(int))
{
int result;
int original;
int i;
int last_i;
int status;
status = 0;
i = 0;
while (i < 256)
{
last_i = i;
result = asm_f(i);
original = orig(i);
if (result != original)
status = dprintf(2, "%s test failed for %c (%#02x)\n", name, i, i);
if (i != last_i)
dprintf(2, " %s altered its argument. Expected %d, but got %d", name, last_i, i);
if (i % 100000000 == 0 && status == 0)
write(1, ".", 1);
i++;
}
return (status);
}
#define ZEROES "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
#define ZEROES2 ZEROES ZEROES ZEROES ZEROES ZEROES ZEROES ZEROES ZEROES ZEROES
static char g_dsts[][1024] =
{
"hello" ZEROES2,
"world" ZEROES2,
"" ZEROES2,
"\0" ZEROES2,
"NirJmaKUgaYttgXPugxfryCDyoFfFgKqEbNhUxCY" ZEROES2,
"lXBXGSZrbtFTnqcotTZS" ZEROES2,
"WruUrhtObnnHjkpKxbSYLpSpjwiOBNfIrtdEBGAN" ZEROES2,
"xEMMtJNTCcdNsdjCAYAaqXHZupdTWnIZACHUVOzeqXHZupdTWnIZACHUVOzeqXHZupdTWnIZAC"
"HUVOzeqXHZupdTWnIZACHUVOzeqXHZupdTWnIZACHUVOze" ZEROES2,
"qXHZupdTWnIZACHUVOze" ZEROES2,
"qkygGbeIawZMEPNasVYl" ZEROES2,
"HcTAsloEImmmWPDQEZPB" ZEROES2,
"yIcWvpujrllUvrrtspsC" ZEROES2,
"vjvkgKzOzVFEBDJlJAHeZkDHqeUcSVeshmNfRIHfvofhbymzljvKrrLpumPzJWgNpzIAASmvVc"
"AtrxHybiPNZIVXjjncZSFNswHSlktFfayGPNxijjwPupbFPbqYlsmpiJrmwHSNrOIAufgSyqpM"
"YNZyulNEovRuJdmvNeuafuPHzsjAcHKzNHZJGFVEcHLPlwQBkGmoYtoyODFMVMsOAUuhydXiPK"
"sRLJqRRvVisjSqLxdHvKwZZMoUGzkGjAiauesMrXHrDuOZVcFFFtEPKXEjuMQLdMHkPvdrwdbS"
"vvHZSLufAubUQtjVgMAVUlCOWQkTxwxurphdldBhPKvXmpbsVrcisCHYqxGuWoUXdSLyVQTqTh"
"VigvJlOgCruvmqWkslmaIczwLkmjxp" ZEROES2,
{0},
{0}
};
const char *g_srcs[] =
{
"" ZEROES2,
"vXVlOgkFshKmuuWvzHgh" ZEROES2,
"ZZxlhPEchyBGCYtOQIJv" ZEROES2,
"BSjYBygwrcWHrfkXAhre" ZEROES2,
"AnkQtobwcitdCUGJEpxt" ZEROES2,
"mgJhvVsalXrvmvzqpsVJ" ZEROES2,
"iJbzYfFwhIyGwrCsCQMm" ZEROES2,
"wpofbUadbwNNWNiwnhcn" ZEROES2,
"NrZerqfmtpIknJzSGzth" ZEROES2,
"AcqahVhiDJuaoCvgelLRBzuGhYkNoeNvuvtnnAPm" ZEROES2,
"AaAaAaAaAaAaAaAaAaAaA" ZEROES2,
"prUuGKULiXrpvvxSLAhA" ZEROES2,
"wsWfqiiKSCCmPLbytGGC" ZEROES2,
"oPyewHDoQixdrHteBNtYeKJMKDSLolbvJjOqSyLh" ZEROES2,
"spWYciyPBTUllIkqnhbH" ZEROES2,
"jiysNsTQDQJyUcBwFfER" ZEROES2,
"DPzunLDTJuIOnDseDNMB" ZEROES2,
"\0\0\0" ZEROES2,
"vvrOpWcGELOhwOTAqyFj" ZEROES2,
"hRqJFcyynensbqBAotwBZyUAxukJWmIIWbVQnCbx" ZEROES2,
"seHJDMCVBqrUZJJAPaDgcDrWlYVeUpUMEHRkpsehiuhmEQCQfahTACNfbnJfSjxgFBmAIaJUxa"
"RmrmDwZbgphhKgNcaqvKaSRajEbMxtlUhWzNDTJcGeRetD"
};
int test_strdup(void)
{
char *dupped;
char *odupped;
int i;
int status;
status = 0;
i = 0;
while (i < 13)
{
dupped = ft_strdup(g_dsts[i]);
odupped = strdup(g_dsts[i]);
if (!dupped || strcmp(dupped, odupped) != 0)
status = printf("strdup failed for %s:%s\n", g_dsts[i], dupped);
free(dupped);
free(odupped);
i++;
}
return (status);
}
int test_strlen(void)
{
size_t len;
size_t olen;
int i;
int status;
status = 0;
i = 0;
while (g_dsts[i])
{
len = ft_strlen(g_dsts[i]);
olen = strlen(g_dsts[i]);
if (len != olen)
status = printf("strlen fail. Expected %zu, got %zu\n", olen, len);
i++;
}
return (status);
}
int main(void)
{
printf("ft_isalnum() vs isalnum():\n");
if (test_iswhat("isalnum", isalnum, ft_isalnum) == 0)
printf(" OK\n");
printf("ft_isalpha() vs isalpha():\n");
if (test_iswhat("isalpha", isalpha, ft_isalpha) == 0)
printf(" OK\n");
printf("ft_isascii() vs isascii():\n");
if (test_iswhat("isascii", isascii, ft_isascii) == 0)
printf(" OK\n");
printf("ft_isdigit() vs isdigit():\n");
if (test_iswhat("isdigit", isdigit, ft_isdigit) == 0)
printf(" OK\n");
printf("ft_isprint() vs isprint():\n");
if (test_iswhat("isprint", isprint, ft_isprint) == 0)
printf(" OK\n");
printf("ft_tolower() vs tolower():\n");
if (test_iswhat("ft_tolower", tolower, ft_tolower) == 0)
printf(" OK\n");
printf("ft_toupper() vs toupper():\n");
if (test_iswhat("ft_toupper", toupper, ft_toupper) == 0)
printf(" OK\n");
printf("ft_strdup() (with strcat and strlen) vs strdup():\n");
if (test_strdup() == 0)
printf(" OK\n");
printf("ft_strlen() vs strlen():\n");
if (test_strdup() == 0)
printf(" OK\n");
printf("\nputs tests\n");
ft_puts("hello");
ft_puts("hello_world");
ft_puts("");
ft_puts("ls -l");
ft_puts("ls -l\n\n");
}