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 wrbuf_sha1_write(wr, msg, strlen(msg), 1);
21 if (!strcmp(wrbuf_cstr(wr), expect))
27 static void *my_handler(void *arg)
29 WRBUF wr = wrbuf_alloc();
31 for (i = 0; i < 1000; i++)
34 sprintf(buf, "Hello world %d", i);
35 wrbuf_sha1_write(wr, buf, strlen(buf), 1);
43 static void thread_testing(void)
45 yaz_thread_t tid[NO_THREADS];
48 for (i = 0; i < NO_THREADS; i++)
50 tid[i] = yaz_thread_create(my_handler, 0);
52 for (i = 0; i < NO_THREADS; i++)
55 yaz_thread_join(tid + i, &return_data);
60 static void tstwrbuf(void)
76 for (step = 1; step < 65; step++)
82 for (j = 1; j<step; j++)
92 YAZ_CHECK(len == step * (step-1) / 2);
94 for (j = 1; j<step; j++)
97 YAZ_CHECK(cp[k] == i+1);
104 wrbuf_puts(wr, "1234");
105 wrbuf_insert(wr, 0, "abc", 3);
106 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "abc1234"));
109 wrbuf_puts(wr, "1234");
110 wrbuf_insert(wr, 1, "abc", 3);
111 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1abc234"));
114 wrbuf_puts(wr, "1234");
115 wrbuf_insert(wr, 4, "abc", 3);
116 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234abc"));
119 wrbuf_puts(wr, "1234");
120 wrbuf_insert(wr, 5, "abc", 3);
121 YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234"));
123 YAZ_CHECK(sha1_test(wr,
125 "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d"));
127 #if YAZ_POSIX_THREADS
133 static void tst_cstr(void)
136 WRBUF w = wrbuf_alloc();
137 for (i = 0; i < 8000; i++)
139 const char *cp = wrbuf_cstr(w);
140 YAZ_CHECK(strlen(cp) == i);
146 for (i = 0; i < 8000; i++)
148 const char *cp = wrbuf_cstr(w);
149 YAZ_CHECK(strlen(cp) == i);
156 int main (int argc, char **argv)
158 YAZ_CHECK_INIT(argc, argv);
167 * c-file-style: "Stroustrup"
168 * indent-tabs-mode: nil
170 * vim: shiftwidth=4 tabstop=8 expandtab