Allow use of Nettle as an alternative to gcrypt
[yaz-moved-to-github.git] / test / test_wrbuf.c
index fef37c8..278122b 100644 (file)
@@ -17,7 +17,7 @@
 static int sha1_test(WRBUF wr, const char *msg, const char *expect)
 {
     wrbuf_rewind(wr);
-#if HAVE_GCRYPT_H
+#if HAVE_GCRYPT_H || HAVE_NETTLE
     wrbuf_sha1_write(wr, msg, strlen(msg), 1);
     if (!strcmp(wrbuf_cstr(wr), expect))
         return 1;
@@ -36,7 +36,7 @@ static void *my_handler(void *arg)
     {
         char buf[100];
         sprintf(buf, "Hello world %d", i);
-#if HAVE_GCRYPT_H
+#if HAVE_GCRYPT_H || HAVE_NETTLE
         wrbuf_sha1_write(wr, buf, strlen(buf), 1);
 #endif
         wrbuf_rewind(wr);
@@ -126,7 +126,7 @@ static void tstwrbuf(void)
     wrbuf_insert(wr, 5, "abc", 3);
     YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234"));
 
-    YAZ_CHECK(sha1_test(wr, 
+    YAZ_CHECK(sha1_test(wr,
                         "Hello world\n",
                         "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d"));
 
@@ -136,10 +136,34 @@ static void tstwrbuf(void)
     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;
 }