--- /dev/null
+/* Note: fmemopen, open_memstream require gnu99 standard instead of c99 */
+
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <check.h>
+
+#include "cutils/check/launcher.h"
+#include "cutils/array.h"
+
+#include "cbook/cbook.h"
+
+static void setup() {
+}
+
+static void teardown() {
+}
+
+static void reset() {
+ teardown();
+ setup();
+}
+
+static void print_line(line_t *line);
+static void print_line(line_t *line) {
+ if (!line) {
+ printf("DCL: (null)\n");
+ return;
+ }
+
+ printf("DCL ");
+ if (line->level)
+ for (int i = 0 ; i < line->level ; i++)
+ printf("\t");
+ printf("%i %s: type %i (size: %zu = %zu bytes)\n",
+ line->level,
+ line->name,
+ line->type,
+ line->size,
+ line->bytes
+ );
+}
+
+START(simple_read_book)
+ char book_content[] =
+ " DCL 1 book, \n"
+ " 2 titi CHAR(10), \n"
+ " *; \n";
+
+ book_t *book = new_book();
+ FILE *fbook = fmemopen((void*)book_content, strlen(book_content), "rb");
+
+ int ok = read_book(fbook, book);
+ if (!ok)
+ failure("Simple book failed to be read");
+
+ assert_str("Book name", "BOOK", book->name);
+ if (book->err_line || book->err_field || book->err_mess)
+ failure("Unexpected error at line %zu in field %s: %s\n",
+ book->err_line, book->err_field, book->err_mess);
+ assert_sz("Book size in bytes", 10, book->bytes);
+ assert_sz("Number of lines 1", 1, book->lines->count);
+ line_t *line = *((line_t **)(array_first(book->lines)));
+ assert_int("Type of line", CBOOK_FMT_CHAR, line->type);
+ assert_sz("Number of sub lines", 0, line->children->count);
+
+ fclose(fbook);
+END
+
+SRunner *test_pl1(SRunner *runner, int more) {
+ Suite *suite = suite_create("pl/1");
+
+ TCase *core = tcase_create("core");
+ tcase_add_checked_fixture(core, setup, teardown);
+
+ tcase_add_test(core, simple_read_book);
+ // ...
+
+ suite_add_tcase(suite, core);
+
+ if (!runner)
+ runner = srunner_create(suite);
+ else
+ srunner_add_suite(runner, suite);
+
+ if (more) {
+ Suite *suite = suite_create("pl/1 -- more (longer)");
+
+ TCase *tmore = tcase_create("more");
+ tcase_add_checked_fixture(tmore, setup, teardown);
+ // TODO
+
+ suite_add_tcase(suite, tmore);
+ srunner_add_suite(runner, suite);
+ }
+
+ return runner;
+}
+