#include "../kit/input_stream.h" #include "../kit/file.h" #define KIT_TEST_FILE input_stream #include "../kit/test.h" TEST("input stream wrap string") { char foo[] = "test"; char bar[] = "test"; str_t foo_ref = { .size = sizeof(foo) - 1, .values = foo }; str_t bar_ref = { .size = sizeof(bar) - 1, .values = bar }; is_handle_t in = is_wrap_string(foo_ref, NULL); char buf[4]; str_t buf_ref = { .size = sizeof(buf), .values = buf }; REQUIRE_EQ(IS_READ(in, buf_ref), buf_ref.size); REQUIRE(AR_EQUAL(foo_ref, bar_ref)); REQUIRE(AR_EQUAL(buf_ref, bar_ref)); is_destroy(in); } TEST("input stream wrap file") { char foo[] = "test"; char bar[] = "test"; FILE *f = fopen("_kit_temp", "wb"); fwrite(foo, 1, 4, f); fclose(f); f = fopen("_kit_temp", "rb"); is_handle_t in = is_wrap_file(f, NULL); REQUIRE_EQ(IS_READ(in, SZ(bar)), SZ(bar).size); REQUIRE(AR_EQUAL(SZ(foo), SZ(bar))); is_destroy(in); fclose(f); file_remove(SZ("_kit_temp")); } #undef KIT_TEST_FILE