New test: test_zgdu
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 30 Apr 2013 09:25:15 +0000 (11:25 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 30 Apr 2013 09:25:15 +0000 (11:25 +0200)
Mostly to demonstrate how to decode HTTP response from a memory
buffer.

test/.gitignore
test/Makefile.am
test/test_zgdu.c [new file with mode: 0644]

index 43f14b5..e93ecbd 100644 (file)
@@ -42,6 +42,7 @@ test_libstemmer
 test_rpn2solr
 test_shared_ptr
 test_solr
+test_zgdu
 *.log
 *.o
 *~
index 7800bee..163f09f 100644 (file)
@@ -11,7 +11,7 @@ check_PROGRAMS = test_ccl test_comstack test_cql2ccl \
  test_record_conv test_rpn2cql test_rpn2solr test_retrieval \
  test_shared_ptr test_soap1 test_soap2 test_solr test_sortspec \
  test_timing test_tpath test_wrbuf \
- test_xmalloc test_xml_include test_xmlquery
+ test_xmalloc test_xml_include test_xmlquery test_zgdu
 
 check_SCRIPTS = test_marc.sh test_marccol.sh test_cql2xcql.sh \
        test_cql2pqf.sh test_icu.sh
@@ -98,3 +98,4 @@ test_file_glob_SOURCES = test_file_glob.c
 test_shared_ptr_SOURCES = test_shared_ptr.c
 test_libstemmer_SOURCES = test_libstemmer.c
 test_embed_record_SOURCES = test_embed_record.c
+test_zgdu_SOURCES = test_zgdu.c
diff --git a/test/test_zgdu.c b/test/test_zgdu.c
new file mode 100644 (file)
index 0000000..4298d3e
--- /dev/null
@@ -0,0 +1,60 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2013 Index Data
+ * See the file LICENSE for details.
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <yaz/test.h>
+#include <yaz/comstack.h>
+#include <yaz/tcpip.h>
+#include <yaz/zgdu.h>
+
+static void tst_http_response(void)
+{
+    {
+        /* response, content  */
+        const char *http_buf =
+            /*123456789012345678 */
+            "HTTP/1.1 200 OK\r\n"
+            "Content-Length: 2\r\n"
+            "\r\n"
+            "12";
+
+        int r;
+        Z_GDU *zgdu;
+        ODR odr = odr_createmem(ODR_DECODE);
+        odr_setbuf(odr, (char *) http_buf, strlen(http_buf), 0);
+        r = z_GDU(odr, &zgdu, 0, 0);
+        YAZ_CHECK(r);
+        if (r)
+        {
+            YAZ_CHECK_EQ(zgdu->which, Z_GDU_HTTP_Response);
+        }
+        odr_destroy(odr);
+    }
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst_http_response();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+