summaryrefslogtreecommitdiff
path: root/test.c
blob: 4e7e1463d3cf438bc709fc4795c7ca6395193cd7 (plain) (blame)
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
/* cc -Irgo/include -L. -otest test.c -lrgo */

#include <assert.h>
#include <inttypes.h>
#include <rgo.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

int main(void) {
	fprintf(stderr,"rgo test\n");
	fprintf(stderr,"arch: %s\n",sus_archstr);
	fprintf(stderr,"fast: %s\n",rgo_fastimpl ? "yes" : "no");
	fprintf(stderr,"\n");
	{
#undef arrsz
#define arrsz rgo_typlit_usz(0x8)
		uint64_t arr0[arrsz] = {0x0};
		rgo_memfill(arr0,arrsz * sizeof (uint64_t),rgo_typlit_u8(0x0));
		fprintf(stderr,"arr0[0]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x0)]);
		fprintf(stderr,"arr0[1]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x1)]);
		fprintf(stderr,"arr0[2]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x2)]);
		fprintf(stderr,"arr0[3]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x3)]);
		fprintf(stderr,"arr0[4]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x4)]);
		fprintf(stderr,"arr0[5]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x5)]);
		fprintf(stderr,"arr0[6]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x6)]);
		assert(arr0[rgo_typlit_usz(0x0)] == rgo_typlit_u40(0x0));
		assert(arr0[rgo_typlit_usz(0x1)] == rgo_typlit_u40(0x0));
		assert(arr0[rgo_typlit_usz(0x2)] == rgo_typlit_u40(0x0));
		assert(arr0[rgo_typlit_usz(0x3)] == rgo_typlit_u40(0x0));
		assert(arr0[rgo_typlit_usz(0x4)] == rgo_typlit_u40(0x0));
		assert(arr0[rgo_typlit_usz(0x5)] == rgo_typlit_u40(0x0));
		assert(arr0[rgo_typlit_usz(0x6)] == rgo_typlit_u40(0x0));
		rgo_memfill(arr0,arrsz * sizeof (uint64_t),INT8_C(0x7F));
		fprintf(stderr,"arr0[0]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x0)]);
		fprintf(stderr,"arr0[1]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x1)]);
		fprintf(stderr,"arr0[2]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x2)]);
		fprintf(stderr,"arr0[3]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x3)]);
		fprintf(stderr,"arr0[4]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x4)]);
		fprintf(stderr,"arr0[5]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x5)]);
		fprintf(stderr,"arr0[6]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x6)]);
		assert(arr0[rgo_typlit_usz(0x0)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		assert(arr0[rgo_typlit_usz(0x1)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		assert(arr0[rgo_typlit_usz(0x2)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		assert(arr0[rgo_typlit_usz(0x3)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		assert(arr0[rgo_typlit_usz(0x4)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		assert(arr0[rgo_typlit_usz(0x5)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		assert(arr0[rgo_typlit_usz(0x6)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
		uint64_t arr1[arrsz] = {0x0};
		rgo_memcpy(arr0,arrsz * sizeof (uint64_t),arr1);
		fprintf(stderr,"arr1[0]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x0)]);
		fprintf(stderr,"arr1[1]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x1)]);
		fprintf(stderr,"arr1[2]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x2)]);
		fprintf(stderr,"arr1[3]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x3)]);
		fprintf(stderr,"arr1[4]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x4)]);
		fprintf(stderr,"arr1[5]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x5)]);
		fprintf(stderr,"arr1[6]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x6)]);
		assert(arr1[rgo_typlit_usz(0x0)] == arr0[rgo_typlit_usz(0x0)]);
		assert(arr1[rgo_typlit_usz(0x1)] == arr0[rgo_typlit_usz(0x1)]);
		assert(arr1[rgo_typlit_usz(0x2)] == arr0[rgo_typlit_usz(0x2)]);
		assert(arr1[rgo_typlit_usz(0x3)] == arr0[rgo_typlit_usz(0x3)]);
		assert(arr1[rgo_typlit_usz(0x4)] == arr0[rgo_typlit_usz(0x4)]);
		assert(arr1[rgo_typlit_usz(0x5)] == arr0[rgo_typlit_usz(0x5)]);
		assert(arr1[rgo_typlit_usz(0x6)] == arr0[rgo_typlit_usz(0x6)]);
		bool const eq = rgo_memeq(arr1,arrsz,arr0);
		fprintf(stderr,"eq:      %u\n",eq);
		assert(eq);
#undef arrsz
	}
	fprintf(stderr,"\n");
	{
		char const * str0 = "Hello there! General Kenobi?";
		fprintf(stderr,"str0:    \"%s\"\n",str0);
		size_t const strsz = rgo_strlen(str0);
		fprintf(stderr,"strsz:   %zX\n",strsz);
		assert(strsz == rgo_typlit_usz(0x1C));
	}
	fprintf(stderr,"\n");
	{
		char const * restrict str = "Oh my science!";
		fprintf(stderr,"str:     \"%s\"\n",str);
		size_t len = rgo_strlen(str);
		fprintf(stderr,"len:     %zX\n",len);
		size_t pos0 = rgo_fndchr(str,' ');
		size_t pos1 = rgo_fndbyte(str,len,(uint_least8_t)' ');
		fprintf(stderr,"pos0:    %zX\n",pos0);
		fprintf(stderr,"pos1:    %zX\n",pos1);
		assert(pos0 == rgo_typlit_usz(0x2));
		assert(pos1 == pos0);
		str += pos0 + rgo_typlit_usz(0x1);
		len = rgo_strlen(str);
		pos0 = rgo_fndchr(str,' ');
		pos1 = rgo_fndbyte(str,len,(uint_least8_t)' ');
		fprintf(stderr,"pos0:    %zX\n",pos0);
		fprintf(stderr,"pos1:    %zX\n",pos1);
		assert(pos0 == rgo_typlit_usz(0x2));
		assert(pos1 == pos0);
		str += pos0 + rgo_typlit_usz(0x1);
		len = rgo_strlen(str);
		pos0 = rgo_fndchr(str,' ');
		pos1 = rgo_fndbyte(str,len,(uint_least8_t)' ');
		fprintf(stderr,"pos0:    %zX\n",pos0);
		fprintf(stderr,"pos1:    %zX\n",pos1);
		assert(pos0 == (size_t)-0x1);
		assert(pos1 == pos0);
	}
	fprintf(stderr,"\n");
	{
		char const str0[] = "What's up, my guy?";
		fprintf(stderr,"str0:    \"%s\"\n",str0);
		char const str1[] = "What's up, my guy?";
		fprintf(stderr,"str1:    \"%s\"\n",str1);
		char const str2[] = "I don't know you!";
		fprintf(stderr,"str2:    \"%s\"\n",str2);
		bool const cmp0 = rgo_streq(str0,str1);
		bool const cmp1 = rgo_streq(str0,str2);
		bool const cmp2 = rgo_streq(str1,str2);
		fprintf(stderr,"cmp0:    %u\n",cmp0);
		fprintf(stderr,"cmp1:    %u\n",cmp1);
		fprintf(stderr,"cmp2:    %u\n",cmp2);
		assert(cmp0);
		assert(!cmp1);
		assert(!cmp2);
	}
	fprintf(stderr,"\n");
	{
		char const str0[] = "What in the world are you doing?";
		fprintf(stderr,"str0:    \"%s\"\n",str0);
		char str1[sizeof (str0)];
		assert(rgo_strcpy(str0,str1) == rgo_typlit_usz(0x20));
		fprintf(stderr,"str1:    \"%s\"\n",str1);
		assert(rgo_streq(str0,str1));
	}
	fprintf(stderr,"\n");
	{
		char const str0[]  = "Oej Moej Goejd";
		char const str1[]  = "Er jeg egentlig okay med AWP?";
		fprintf(stderr,"str0:    \"%s\"\n",str0);
		fprintf(stderr,"str1:    \"%s\"\n",str1);
		int_least8_t const cmp0    = rgo_strcmp(str0,str1);
		int_least8_t const cmp1    = rgo_strcmp(str0,str0);
		int_least8_t const cmp2    = rgo_strcmp(str1,str0);
		size_t const       leastsz = sizeof (str0) < sizeof (str1) ? sizeof (str0) : sizeof (str1);
		int_least8_t const cmp3    = rgo_memcmp(str0,leastsz,str1);
		int_least8_t const cmp4    = rgo_memcmp(str0,leastsz,str0);
		int_least8_t const cmp5    = rgo_memcmp(str1,leastsz,str0);
		fprintf(stderr,"cmp0:    %i\n",cmp0);
		fprintf(stderr,"cmp1:    %i\n",cmp1);
		fprintf(stderr,"cmp2:    %i\n",cmp2);
		fprintf(stderr,"cmp3:    %i\n",cmp3);
		fprintf(stderr,"cmp4:    %i\n",cmp4);
		fprintf(stderr,"cmp5:    %i\n",cmp5);
		assert(cmp0 >  rgo_typlit_s8(0x0));
		assert(cmp1 == rgo_typlit_s8(0x0));
		assert(cmp2 <  rgo_typlit_s8(0x0));
		assert(cmp3 >  rgo_typlit_s8(0x0));
		assert(cmp4 == rgo_typlit_s8(0x0));
		assert(cmp5 <  rgo_typlit_s8(0x0));
	}
	fprintf(stderr,"\n");
	printf("All tests have passed!\n");
}