X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_wrbuf.c;h=a0046efc28f5d1b1a01e93c8297da46cc2ff1d9a;hp=644f52a6c9bd303b77e8fed5ba82e345f511900c;hb=5e0171c5568e93a00cad52e4187b9b28e8bacbf1;hpb=473824797f568578dc17d7242551cb2f7ccef46c diff --git a/test/test_wrbuf.c b/test/test_wrbuf.c index 644f52a..a0046ef 100644 --- a/test/test_wrbuf.c +++ b/test/test_wrbuf.c @@ -11,8 +11,58 @@ #include #include +#include #include +static int sha1_test(WRBUF wr, const char *msg, const char *expect) +{ + wrbuf_rewind(wr); +#if HAVE_GCRYPT_H + wrbuf_sha1_write(wr, msg, strlen(msg), 1); + if (!strcmp(wrbuf_cstr(wr), expect)) + return 1; + return 0; +#else + return 1; +#endif +} + +#if YAZ_POSIX_THREADS +static void *my_handler(void *arg) +{ + WRBUF wr = wrbuf_alloc(); + int i; + for (i = 0; i < 1000; i++) + { + char buf[100]; + sprintf(buf, "Hello world %d", i); +#if HAVE_GCRYPT_H + wrbuf_sha1_write(wr, buf, strlen(buf), 1); +#endif + wrbuf_rewind(wr); + } + wrbuf_destroy(wr); + return 0; +} + +#define NO_THREADS 10 +static void thread_testing(void) +{ + yaz_thread_t tid[NO_THREADS]; + int i; + + for (i = 0; i < NO_THREADS; i++) + { + tid[i] = yaz_thread_create(my_handler, 0); + } + for (i = 0; i < NO_THREADS; i++) + { + void *return_data; + yaz_thread_join(tid + i, &return_data); + } +} +#endif + static void tstwrbuf(void) { int step; @@ -76,13 +126,44 @@ static void tstwrbuf(void) wrbuf_insert(wr, 5, "abc", 3); YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234")); + YAZ_CHECK(sha1_test(wr, + "Hello world\n", + "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d")); + +#if YAZ_POSIX_THREADS + thread_testing(); +#endif wrbuf_destroy(wr); } +static void tst_cstr(void) +{ + int i; + WRBUF w = wrbuf_alloc(); + for (i = 0; i < 8000; i++) + { + const char *cp = wrbuf_cstr(w); + YAZ_CHECK(strlen(cp) == i); + wrbuf_putc(w, 'a'); + } + wrbuf_destroy(w); + + w = wrbuf_alloc(); + for (i = 0; i < 8000; i++) + { + const char *cp = wrbuf_cstr(w); + YAZ_CHECK(strlen(cp) == i); + wrbuf_puts(w, "a"); + } + wrbuf_destroy(w); + +} + int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); tstwrbuf(); + tst_cstr(); YAZ_CHECK_TERM; }