1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
13 #include <yaz/wrbuf.h>
14 #include <yaz/thread_create.h>
17 static int sha1_test(WRBUF wr, const char *msg, const char *expect)
20 #if HAVE_GCRYPT_H || HAVE_NETTLE
21 wrbuf_sha1_write(wr, msg, strlen(msg), 1);
22 if (!strcmp(wrbuf_cstr(wr), expect))
31 static void *my_handler(void *arg)
33 WRBUF wr = wrbuf_alloc();
35 for (i = 0; i < 1000; i++)
38 sprintf(buf, "Hello world %d", i);
39 #if HAVE_GCRYPT_H || HAVE_NETTLE
40 wrbuf_sha1_write(wr, buf, strlen(buf), 1);
49 static void thread_testing(void)
51 yaz_thread_t tid[NO_THREADS];
54 for (i = 0; i < NO_THREADS; i++)
56 tid[i] = yaz_thread_create(my_handler, 0);
58 for (i = 0; i < NO_THREADS; i++)
61 yaz_thread_join(tid + i, &return_data);
66 static void tstwrbuf(void)
82 for (step = 1; step < 65; step++)
88 for (j = 1; j<step; j++)
98 YAZ_CHECK(len == step * (step-1) / 2);
100 for (j = 1; j<step; j++)
101 for (i = 0; i<j; i++)
103 YAZ_CHECK(cp[k] == i+1);
110 wrbuf_puts(wr, "1234");
111 wrbuf_insert(wr, 0, "abc", 3);
112 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "abc1234"));
115 wrbuf_puts(wr, "1234");
116 wrbuf_insert(wr, 1, "abc", 3);
117 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1abc234"));
120 wrbuf_puts(wr, "1234");
121 wrbuf_insert(wr, 4, "abc", 3);
122 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234abc"));
125 wrbuf_puts(wr, "1234");
126 wrbuf_insert(wr, 5, "abc", 3);
127 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234"));
129 YAZ_CHECK(sha1_test(wr,
131 "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d"));
133 #if YAZ_POSIX_THREADS
139 static void tst_cstr(void)
142 WRBUF w = wrbuf_alloc();
143 for (i = 0; i < 8000; i++)
145 const char *cp = wrbuf_cstr(w);
146 YAZ_CHECK(strlen(cp) == i);
152 for (i = 0; i < 8000; i++)
154 const char *cp = wrbuf_cstr(w);
155 YAZ_CHECK(strlen(cp) == i);
162 int main (int argc, char **argv)
164 YAZ_CHECK_INIT(argc, argv);
173 * c-file-style: "Stroustrup"
174 * indent-tabs-mode: nil
176 * vim: shiftwidth=4 tabstop=8 expandtab