X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Ftest_solr.c;h=6b156a288a17c68ac6f867f9b369dc9d72f2b4f4;hb=f05461c79b402d35bb6ca5feb75a848f4a5a3c7d;hp=b3290244f3c04a4dae120cb3cc08a07f2ed90b17;hpb=33a39e24078032c9f726cacdf32c092fa0fe878d;p=yaz-moved-to-github.git
diff --git a/test/test_solr.c b/test/test_solr.c
index b329024..6b156a2 100644
--- a/test/test_solr.c
+++ b/test/test_solr.c
@@ -1,5 +1,5 @@
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) 1995-2013 Index Data
* See the file LICENSE for details.
*/
#if HAVE_CONFIG_H
@@ -39,7 +39,7 @@ int compare_solr_req(ODR odr, Z_SRW_PDU *sr,
{
int len = 0;
char *buf = odr_getbuf(odr, &len, 0);
-
+
if (buf)
{
if (len == strlen(expect) && !memcmp(buf, expect, len))
@@ -56,7 +56,7 @@ int compare_solr_req(ODR odr, Z_SRW_PDU *sr,
}
#endif
-void tst(void)
+void tst_encoding(void)
{
#if YAZ_HAVE_XML2
ODR odr = odr_createmem(ODR_ENCODE);
@@ -64,7 +64,7 @@ void tst(void)
{
Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
"1.2");
-
+
YAZ_CHECK(compare_solr_req(
odr, sr, 0,
"GET Default/select? HTTP/1.1\r\n"
@@ -87,7 +87,7 @@ void tst(void)
{
Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
"1.2");
-
+
sr->u.request->query_type = Z_SRW_query_type_cql;
sr->u.request->query.cql = "title:solr";
sr->u.request->startRecord = odr_intdup(odr, 3);
@@ -105,13 +105,13 @@ void tst(void)
{
Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
"1.2");
-
+
sr->u.request->query_type = Z_SRW_query_type_cql;
sr->u.request->query.cql = "title:solr";
sr->u.request->startRecord = odr_intdup(odr, 3);
sr->u.request->maximumRecords = odr_intdup(odr, 10);
sr->u.request->facetList = yaz_pqf_parse_facet_list(
- odr, "@attr 1=date @attr 2=0, @attr 1=title @attr 3=17");
+ odr, "@attr 1=date @attr 2=0, @attr 1=title_exact @attr 3=17");
YAZ_CHECK(compare_solr_req(
odr, sr, 0,
@@ -129,13 +129,214 @@ void tst(void)
#endif
}
+
+int check_response(ODR o, const char *content, Z_SRW_searchRetrieveResponse **p)
+{
+ int r;
+ Z_GDU *gdu;
+ Z_SRW_PDU *sr_p;
+ char *http_response = odr_malloc(o, strlen(content) + 300);
+
+ strcpy(http_response,
+ "HTTP/1.1 200 OK\r\n"
+ "Last-Modified: Wed, 13 Apr 2011 08:30:59 GMT\r\n"
+ "ETag: \"MjcyMWE5M2JiNDgwMDAwMFNvbHI=\"\r\n"
+ "Content-Type: text/xml; charset=utf-8\r\n");
+ sprintf(http_response + strlen(http_response),
+ "Content-Length: %d\r\n\r\n", (int) strlen(content));
+ strcat(http_response, content);
+
+ odr_setbuf(o, http_response, strlen(http_response), 0);
+
+ r = z_GDU(o, &gdu, 0, 0);
+ if (!r || gdu->which != Z_GDU_HTTP_Response)
+ return 0;
+ r = yaz_solr_decode_response(o, gdu->u.HTTP_Response, &sr_p);
+ if (r)
+ return 0;
+ if (sr_p->which != Z_SRW_searchRetrieve_response)
+ return 0;
+ *p = sr_p->u.response;
+ return 1;
+}
+
+void tst_decoding(void)
+{
+#if YAZ_HAVE_XML2
+ ODR odr = odr_createmem(ODR_DECODE);
+ Z_SRW_searchRetrieveResponse *response;
+
+ YAZ_CHECK(check_response(
+ odr,
+ "\n"
+ "\n"
+ "0"
+ "1"
+ "0@attr 1=title solr"
+ "0"
+ "\n"
+ "\n", &response));
+ YAZ_CHECK_EQ(*response->numberOfRecords, 91);
+ YAZ_CHECK_EQ(response->num_records, 0);
+ YAZ_CHECK(response->records == 0);
+ YAZ_CHECK_EQ(response->num_diagnostics, 0);
+ YAZ_CHECK(response->diagnostics == 0);
+ YAZ_CHECK(response->nextRecordPosition == 0);
+ YAZ_CHECK(response->facetList == 0);
+
+ odr_reset(odr);
+
+ YAZ_CHECK(
+ check_response(
+ odr,
+ ""
+ ""
+ "02"
+ "true"
+ "10"
+ "@attr 1=title solr"
+ "5"
+ "date"
+ "1"
+ ""
+ "Alenius, Hans,"
+ "1937-"
+ ""
+ "1969"
+ " 73857731 "
+ " 73857731 "
+ "book"
+ "book"
+ ""
+ "20 cm."
+ "140, (1) p."
+ "illus."
+ ""
+ ""
+ ""
+ "1969."
+ "Norstedt,"
+ "Stockholm,"
+ "PhotographyArtistic"
+ "Photography, Artistic."
+ "PhotographyArtistic"
+ "(OCoLC)36247690"
+ "Solring.Solring."
+ ""
+ ""
+ "Solring."
+ ""
+ ""
+ ""
+ "50000000004"
+ "44"
+ "3"
+ "", &response));
+#if HAVE_LONG_LONG
+ YAZ_CHECK(*response->numberOfRecords == 91000000000LL);
+#endif
+ YAZ_CHECK_EQ(response->num_records, 1);
+ YAZ_CHECK(response->records);
+ if (response->records)
+ {
+ const char *doc =
+ "Alenius, Hans,"
+ "1937-"
+ ""
+ "1969"
+ " 73857731 "
+ " 73857731 "
+ "book"
+ "book"
+ ""
+ "20 cm."
+ "140, (1) p."
+ "illus."
+ ""
+ ""
+ ""
+ "1969."
+ "Norstedt,"
+ "Stockholm,"
+ "PhotographyArtistic"
+ "Photography, Artistic."
+ "PhotographyArtistic"
+ "(OCoLC)36247690"
+ "Solring.Solring."
+ ""
+ ""
+ "Solring."
+ "";
+
+ Z_SRW_record *record = response->records;
+
+ YAZ_CHECK(record->recordData_len == strlen(doc) &&
+ !memcmp(record->recordData_buf, doc, record->recordData_len));
+ }
+ YAZ_CHECK_EQ(response->num_diagnostics, 0);
+ YAZ_CHECK(response->diagnostics == 0);
+ YAZ_CHECK(response->nextRecordPosition == 0);
+
+ YAZ_CHECK(response->facetList);
+ if (response->facetList)
+ {
+ Z_FacetList *facetList = response->facetList;
+
+ YAZ_CHECK(facetList->num == 1);
+ if (facetList->num == 1)
+ {
+ Z_FacetField *facetField = facetList->elements[0];
+ int i;
+
+ YAZ_CHECK(facetField->num_terms == 5);
+ if (facetField->num_terms == 5)
+ {
+ for (i = 0; i < facetField->num_terms; i++)
+ {
+ YAZ_CHECK(
+ facetField->terms[i] &&
+ facetField->terms[i]->term &&
+ facetField->terms[i]->term->which == Z_Term_general);
+ }
+#if HAVE_LONG_LONG
+ YAZ_CHECK(*facetField->terms[0]->count == 5000000000LL);
+#endif
+ YAZ_CHECK(facetField->terms[0]->term->u.general->len == 4
+ && !memcmp(facetField->terms[0]->term->u.general->buf,
+ "1978", 4));
+ YAZ_CHECK(*facetField->terms[1]->count == 4);
+ YAZ_CHECK(facetField->terms[1]->term->u.general->len == 4
+ && !memcmp(facetField->terms[1]->term->u.general->buf,
+ "1983", 4));
+ YAZ_CHECK(*facetField->terms[2]->count == 4);
+ YAZ_CHECK(facetField->terms[2]->term->u.general->len == 4
+ && !memcmp(facetField->terms[2]->term->u.general->buf,
+ "1987", 4));
+ YAZ_CHECK(*facetField->terms[3]->count == 4);
+ YAZ_CHECK(facetField->terms[3]->term->u.general->len == 4
+ && !memcmp(facetField->terms[3]->term->u.general->buf,
+ "1988", 4));
+ YAZ_CHECK(*facetField->terms[4]->count == 3);
+ YAZ_CHECK(facetField->terms[4]->term->u.general->len == 4
+ && !memcmp(facetField->terms[4]->term->u.general->buf,
+ "2003", 4));
+ }
+ }
+ }
+
+ odr_reset(odr);
+
+ odr_destroy(odr);
+#endif
+}
int main(int argc, char **argv)
{
YAZ_CHECK_INIT(argc, argv);
#if YAZ_HAVE_XML2
LIBXML_TEST_VERSION;
#endif
- tst();
+ tst_encoding();
+ tst_decoding();
YAZ_CHECK_TERM;
}