From 287b59cfd3c8d1098b1a0bead9e2fae96b4f773d Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 22 Sep 2010 18:09:50 +0000 Subject: [PATCH] Temporarily added test program for burn_offst_source_new() --- Makefile.am | 4 ++ cdrskin/cdrskin_timestamp.h | 2 +- test/offst_source.c | 133 ++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 test/offst_source.c diff --git a/Makefile.am b/Makefile.am index 4fa005e..06a9515 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,6 +83,7 @@ install-exec-hook: ## Build test applications noinst_PROGRAMS = \ test/libburner \ + test/offst_source \ test/telltoc \ test/dewav \ test/fake_au \ @@ -97,6 +98,9 @@ LIBBURN_EXTRALIBS = $(LIBBURN_ARCH_LIBS) $(THREAD_LIBS) test_libburner_CPPFLAGS = -Ilibburn test_libburner_LDADD = $(libburn_libburn_la_OBJECTS) $(LIBBURN_EXTRALIBS) test_libburner_SOURCES = test/libburner.c +test_offst_source_CPPFLAGS = -Ilibburn +test_offst_source_LDADD = $(libburn_libburn_la_OBJECTS) $(LIBBURN_EXTRALIBS) +test_offst_source_SOURCES = test/offst_source.c test_telltoc_CPPFLAGS = -Ilibburn test_telltoc_LDADD = $(libburn_libburn_la_OBJECTS) $(LIBBURN_EXTRALIBS) test_telltoc_SOURCES = test/telltoc.c diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index 75bbd82..33dc038 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2010.09.22.175054" +#define Cdrskin_timestamP "2010.09.22.180921" diff --git a/test/offst_source.c b/test/offst_source.c new file mode 100644 index 0000000..3721694 --- /dev/null +++ b/test/offst_source.c @@ -0,0 +1,133 @@ + +/* + cc -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS -g -o test/offst_source test/offst_source.c -lburn +*/ + +#include "../libburn/libburn.h" + +/* Just everything from test/libburner.c */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static int create_original(struct burn_source **original, char *path, int flag) +{ + *original = burn_file_source_new(path, NULL); + if (*original == NULL) + return 0; + return 1; +} + + +static int set_up_offst_sources(struct burn_source *original, + struct burn_source *offsetters[], + int count, int flag) +{ + int i; + off_t start = 3, size = 10, gap = 7; + + for (i = 0; i < count; i++) { + offsetters[i] = burn_offst_source_new(original, + i > 0 ? offsetters[i - 1] : NULL, + start, size, 0); + if (offsetters[i] == NULL) + return 0; + printf("set_up_offst_sources: idx=%d, start=%d\n", + i, (int) start); + start += size + gap; + } + return 1; +} + + +static int consume_source(struct burn_source *src, int flag) +{ + int ret, count = 0; + unsigned char buf[1]; + + while (1) { + ret = src->read_xt(src, buf, 1); + if (ret < 0) { + printf("\n"); + fprintf(stderr, "consume_source: count=%d, ret=%d\n", + count, ret); + return 0; + } + if (ret == 0) + break; + printf("%u ", buf[0]); + count++; + } + printf(" count=%d\n", count); + return 1; +} + + +static int consume_all_sources(struct burn_source *offsetters[], + int count, int flag) +{ + int i, ret; + + for (i = 0; i < count; i++) { + printf("consume_source: idx=%d\n", i); + ret = consume_source(offsetters[i], 0); + if (ret <= 0) + return ret; + } + return 1; +} + + +static int free_all_sources(struct burn_source *original, + struct burn_source *offsetters[], + int count, int flag) +{ + int i; + + for (i = 0; i < count; i++) + burn_source_free(offsetters[i]); + burn_source_free(original); + return 1; +} + + +int main(int argc, char **argv) +{ + int ret; + char *path = "./README"; + struct burn_source *original = NULL, *offsetters[4]; + + if (argc > 1) + path = argv[1]; + + if (burn_initialize() == 0) + exit(1); + + ret = create_original(&original, path, 0); + if (ret <= 0) + exit(2); + + ret = set_up_offst_sources(original, offsetters, 4, 0); + if (ret <= 0) + exit(3); + + ret = consume_all_sources(offsetters, 4, 0); + if (ret <= 0) + exit(4); + + ret = free_all_sources(original, offsetters, 4, 0); + if (ret <= 0) + exit(5); + + burn_finish(); + exit(0); +} +