5 static void check_all_len_0() {
6 buffer
*check
= buffer_init();
7 const char empty
[] = "";
10 unsigned char* check_res
;
12 force_assert(0 == li_to_base64_no_padding(NULL
, 0, NULL
, 0, BASE64_STANDARD
));
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));
21 unsigned char* check_res
;
23 force_assert(0 == li_to_base64_no_padding(NULL
, 0, NULL
, 0, BASE64_URL
));
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));
34 static void check_all_len_1() {
36 buffer
*check
= buffer_init();
38 for (c1
= 0; c1
< 256; ++c1
) {
40 unsigned char in
[] = { c1
};
41 char out
[2] = { 0, 0 };
42 unsigned char* check_res
;
44 force_assert(sizeof(out
) == li_to_base64_no_padding(out
, sizeof(out
), in
, sizeof(in
), BASE64_STANDARD
));
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
)));
53 unsigned char in
[] = { c1
};
54 char out
[2] = { 0, 0 };
55 unsigned char* check_res
;
57 force_assert(sizeof(out
) == li_to_base64_no_padding(out
, sizeof(out
), in
, sizeof(in
), BASE64_URL
));
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
)));
69 static void check_all_len_2() {
71 buffer
*check
= buffer_init();
73 for (c1
= 0; c1
< 256; ++c1
) for (c2
= 0; c2
< 256; ++c2
) {
75 unsigned char in
[] = { c1
, c2
};
76 char out
[3] = { 0, 0, 0 };
77 unsigned char* check_res
;
79 force_assert(sizeof(out
) == li_to_base64_no_padding(out
, sizeof(out
), in
, sizeof(in
), BASE64_STANDARD
));
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
)));
88 unsigned char in
[] = { c1
, c2
};
89 char out
[3] = { 0, 0, 0 };
90 unsigned char* check_res
;
92 force_assert(sizeof(out
) == li_to_base64_no_padding(out
, sizeof(out
), in
, sizeof(in
), BASE64_URL
));
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
)));
104 static void check_all_len_3() {
105 unsigned int c1
, c2
, c3
;
106 buffer
*check
= buffer_init();
108 for (c1
= 0; c1
< 256; ++c1
) for (c2
= 0; c2
< 256; ++c2
) for (c3
= 0; c3
< 256; ++c3
) {
110 unsigned char in
[] = { c1
, c2
, c3
};
111 char out
[4] = { 0, 0, 0, 0 };
112 unsigned char* check_res
;
114 force_assert(sizeof(out
) == li_to_base64_no_padding(out
, sizeof(out
), in
, sizeof(in
), BASE64_STANDARD
));
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
)));
123 unsigned char in
[] = { c1
, c2
, c3
};
124 char out
[4] = { 0, 0, 0, 0 };
125 unsigned char* check_res
;
127 force_assert(sizeof(out
) == li_to_base64_no_padding(out
, sizeof(out
), in
, sizeof(in
), BASE64_URL
));
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
)));