creole/c_test/creole.c

105 lines
2.0 KiB
C
Raw Normal View History

2023-02-05 06:44:37 -05:00
#include "greatest.h"
GREATEST_MAIN_DEFS();
2023-02-07 12:48:28 -05:00
#include "../creole.c"
2023-02-05 06:44:37 -05:00
/**************************************************************************
2023-02-06 23:38:39 -05:00
* Reader
2023-02-05 06:44:37 -05:00
*************************************************************************/
#define reader_lit(r, s) do { \
r.p = (unsigned char *)s; \
r.left = sizeof(s) - 1; \
} while(0)
TEST reader_test_basic(struct creole_reader *r) {
size_t i = 0;
unsigned char *s = r->p;
size_t len = r->left;
for (i = 0; i < len; i++) {
ASSERT_EQ(read_eof(r), 0);
ASSERT_EQ(read(r), s[i]);
}
for (i = 0; i < 5; i++) {
ASSERT_EQ(read_eof(r), 1);
ASSERT_EQ(read(r), -1);
}
PASS();
}
SUITE(reader) {
struct creole_reader r = {0};
reader_lit(r, "abcdefg");
RUN_TEST1(reader_test_basic, &r);
reader_lit(r, "");
RUN_TEST1(reader_test_basic, &r);
}
2023-02-07 00:25:30 -05:00
#if 0
2023-02-06 23:38:39 -05:00
TEST encode_decode_byte_seq(struct seq *s) {
unsigned char buf[7];
struct creole_reader r = {0};
struct word w;
creole_word i = 0;
for (;;) {
ASSERT_EQ(creole_encode(i, s->encode_to, s->high_bits,
buf), 1);
r.p = buf;
r.left = s->encode_to;
ASSERT_EQ(decode_seq(&r, &w), 1);
ASSERT_EQ(w.len, s->encode_to);
ASSERT_EQ(w.high_bits, s->high_bits);
ASSERT_EQ(w.word, i);
if (i == s->max)
break;
i++;
}
PASS();
}
SUITE(pseudo_utf8_encode_all) {
struct seq s;
s.max = 0x7F;
s.encode_to = 1;
s.high_bits = 0;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
for (s.high_bits = 0; s.high_bits < 16; s.high_bits++) {
s.max = 0x7F;
s.encode_to = 2;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
s.max = 0xFFF;
s.encode_to = 3;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
s.max = 0x1FFFF;
s.encode_to = 4;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
s.max = 0x3FFFFF;
s.encode_to = 5;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
s.max = 0x7FFFFFF;
s.encode_to = 6;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
s.max = 0xFFFFFFFF;
s.encode_to = 7;
2023-02-07 00:25:30 -05:00
RUN_TEST1(encode_decode_byte_seq, &s);
2023-02-06 23:38:39 -05:00
}
}
2023-02-07 00:25:30 -05:00
#endif
2023-02-06 23:38:39 -05:00
2023-02-05 06:44:37 -05:00
int main(int argc, char *argv[]) {
GREATEST_MAIN_BEGIN();
RUN_SUITE(reader);
GREATEST_MAIN_END();
}