1 /* $Id: t16.c,v 1.9 2007-01-15 15:10:20 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 /** \brief test special element set names zebra:: and friends */
27 const char *myrec[] = {
29 " <title>My title</title>\n"
33 #define NUMBER_TO_FETCH_MAX 1000
35 static ZEBRA_RES fetch_first(ZebraHandle zh, const char *element_set,
36 oid_value format, ODR odr,
37 const char **rec_buf, size_t *rec_len)
39 ZebraRetrievalRecord retrievalRecord[1];
40 Z_RecordComposition *comp;
43 retrievalRecord[0].position = 1; /* get from this position */
45 yaz_set_esn(&comp, element_set, odr->mem);
47 res = zebra_records_retrieve(zh, odr, "default", comp, format, 1,
51 int code = zebra_errCode(zh);
52 yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d",
57 *rec_buf = retrievalRecord[0].buf;
58 *rec_len = retrievalRecord[0].len;
63 static ZEBRA_RES fetch_first_compare(ZebraHandle zh, const char *element_set,
64 oid_value format, const char *cmp_rec)
66 const char *rec_buf = 0;
68 ODR odr = odr_createmem(ODR_ENCODE);
69 ZEBRA_RES res = fetch_first(zh, element_set, format, odr,
73 if (strlen(cmp_rec) != rec_len)
75 else if (memcmp(cmp_rec, rec_buf, rec_len))
84 static void tst(int argc, char **argv)
88 const char * zebra_xml_sysno
89 = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\"/>\n";
91 const char * zebra_xml_meta
92 = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" base=\"Default\" type=\"grs.sgml\" rank=\"0\" size=\"41\" set=\"zebra::meta\"/>\n";
94 const char * zebra_xml_index_title_p
95 = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:p/\">\n"
96 " <index name=\"title\" type=\"p\" seq=\"4\">my title</index>\n"
99 ZebraService zs = tl_start_up(0, argc, argv);
100 ZebraHandle zh = zebra_open(zs, 0);
102 YAZ_CHECK(tl_init_data(zh, myrec));
104 res = zebra_search_PQF(zh, "@attr 1=4 my", "default", &hits);
105 YAZ_CHECK_EQ(res, ZEBRA_OK);
106 YAZ_CHECK_EQ(hits, 1);
108 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_TEXT_XML,
109 "mismatch"), ZEBRA_FAIL);
111 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_SUTRS,
112 myrec[0]), ZEBRA_OK);
114 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_TEXT_XML,
115 myrec[0]), ZEBRA_OK);
117 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta::sysno", VAL_SUTRS,
120 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta::sysno", VAL_TEXT_XML,
121 zebra_xml_sysno), ZEBRA_OK);
123 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta", VAL_TEXT_XML,
124 zebra_xml_meta), ZEBRA_OK);
126 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::index::title:p",
128 zebra_xml_index_title_p), ZEBRA_OK);
130 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::nonexistent",
131 VAL_TEXT_XML, ""), ZEBRA_OK);
133 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::index::nonexistent",
134 VAL_TEXT_XML, ""), ZEBRA_OK);
136 YAZ_CHECK(tl_close_down(zh, zs));
144 * indent-tabs-mode: nil
146 * vim: shiftwidth=4 tabstop=8 expandtab