Annotation of embedaddon/lighttpd/src/test_base64.c, revision 1.1.1.1
1.1 misho 1: #include "first.h"
2:
3: #include "base64.h"
4:
5: static void check_all_len_0() {
6: buffer *check = buffer_init();
7: const char empty[] = "";
8:
9: {
10: unsigned char* check_res;
11:
12: force_assert(0 == li_to_base64_no_padding(NULL, 0, NULL, 0, BASE64_STANDARD));
13:
14: buffer_reset(check);
15: check_res = buffer_append_base64_decode(check, NULL, 0, BASE64_STANDARD);
16: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
17: force_assert(buffer_is_equal_string(check, empty, 0));
18: }
19:
20: {
21: unsigned char* check_res;
22:
23: force_assert(0 == li_to_base64_no_padding(NULL, 0, NULL, 0, BASE64_URL));
24:
25: buffer_reset(check);
26: check_res = buffer_append_base64_decode(check, NULL, 0, BASE64_URL);
27: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
28: force_assert(buffer_is_equal_string(check, empty, 0));
29: }
30:
31: buffer_free(check);
32: }
33:
34: static void check_all_len_1() {
35: unsigned int c1;
36: buffer *check = buffer_init();
37:
38: for (c1 = 0; c1 < 256; ++c1) {
39: {
40: unsigned char in[] = { c1 };
41: char out[2] = { 0, 0 };
42: unsigned char* check_res;
43:
44: force_assert(sizeof(out) == li_to_base64_no_padding(out, sizeof(out), in, sizeof(in), BASE64_STANDARD));
45:
46: buffer_reset(check);
47: check_res = buffer_append_base64_decode(check, out, sizeof(out), BASE64_STANDARD);
48: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
49: force_assert(buffer_is_equal_string(check, (const char*) in, sizeof(in)));
50: }
51:
52: {
53: unsigned char in[] = { c1 };
54: char out[2] = { 0, 0 };
55: unsigned char* check_res;
56:
57: force_assert(sizeof(out) == li_to_base64_no_padding(out, sizeof(out), in, sizeof(in), BASE64_URL));
58:
59: buffer_reset(check);
60: check_res = buffer_append_base64_decode(check, out, sizeof(out), BASE64_URL);
61: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
62: force_assert(buffer_is_equal_string(check, (const char*) in, sizeof(in)));
63: }
64: }
65:
66: buffer_free(check);
67: }
68:
69: static void check_all_len_2() {
70: unsigned int c1, c2;
71: buffer *check = buffer_init();
72:
73: for (c1 = 0; c1 < 256; ++c1) for (c2 = 0; c2 < 256; ++c2) {
74: {
75: unsigned char in[] = { c1, c2 };
76: char out[3] = { 0, 0, 0 };
77: unsigned char* check_res;
78:
79: force_assert(sizeof(out) == li_to_base64_no_padding(out, sizeof(out), in, sizeof(in), BASE64_STANDARD));
80:
81: buffer_reset(check);
82: check_res = buffer_append_base64_decode(check, out, sizeof(out), BASE64_STANDARD);
83: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
84: force_assert(buffer_is_equal_string(check, (const char*) in, sizeof(in)));
85: }
86:
87: {
88: unsigned char in[] = { c1, c2 };
89: char out[3] = { 0, 0, 0 };
90: unsigned char* check_res;
91:
92: force_assert(sizeof(out) == li_to_base64_no_padding(out, sizeof(out), in, sizeof(in), BASE64_URL));
93:
94: buffer_reset(check);
95: check_res = buffer_append_base64_decode(check, out, sizeof(out), BASE64_URL);
96: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
97: force_assert(buffer_is_equal_string(check, (const char*) in, sizeof(in)));
98: }
99: }
100:
101: buffer_free(check);
102: }
103:
104: static void check_all_len_3() {
105: unsigned int c1, c2, c3;
106: buffer *check = buffer_init();
107:
108: for (c1 = 0; c1 < 256; ++c1) for (c2 = 0; c2 < 256; ++c2) for (c3 = 0; c3 < 256; ++c3) {
109: {
110: unsigned char in[] = { c1, c2, c3 };
111: char out[4] = { 0, 0, 0, 0 };
112: unsigned char* check_res;
113:
114: force_assert(sizeof(out) == li_to_base64_no_padding(out, sizeof(out), in, sizeof(in), BASE64_STANDARD));
115:
116: buffer_reset(check);
117: check_res = buffer_append_base64_decode(check, out, sizeof(out), BASE64_STANDARD);
118: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
119: force_assert(buffer_is_equal_string(check, (const char*) in, sizeof(in)));
120: }
121:
122: {
123: unsigned char in[] = { c1, c2, c3 };
124: char out[4] = { 0, 0, 0, 0 };
125: unsigned char* check_res;
126:
127: force_assert(sizeof(out) == li_to_base64_no_padding(out, sizeof(out), in, sizeof(in), BASE64_URL));
128:
129: buffer_reset(check);
130: check_res = buffer_append_base64_decode(check, out, sizeof(out), BASE64_URL);
131: force_assert((check_res != NULL) && (check_res == (unsigned char*) check->ptr));
132: force_assert(buffer_is_equal_string(check, (const char*) in, sizeof(in)));
133: }
134: }
135:
136: buffer_free(check);
137: }
138:
139: int main() {
140: check_all_len_0();
141: check_all_len_1();
142: check_all_len_2();
143: check_all_len_3();
144:
145: return 0;
146: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>