creole/c_test/creole.c

45 lines
910 B
C

#include "greatest.h"
GREATEST_MAIN_DEFS();
#include "../creole.c"
/**************************************************************************
* Reader
*************************************************************************/
#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);
}
int main(int argc, char *argv[]) {
GREATEST_MAIN_BEGIN();
RUN_SUITE(reader);
GREATEST_MAIN_END();
}