1 /* $Id: t16.c,v 1.3 2006-11-16 21:58:55 marc Exp $
2 Copyright (C) 1995-2006
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)
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\" set=\"zebra::meta::sysno\"/>\n";
91 const char * zebra_xml_index_title_p
92 = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:p/\">\n"
93 " <index name=\"title\" type=\"p\" seq=\"4\">my title</index>\n"
96 ZebraService zs = tl_start_up(0, argc, argv);
97 ZebraHandle zh = zebra_open(zs, 0);
99 YAZ_CHECK(tl_init_data(zh, myrec));
101 res = zebra_search_PQF(zh, "@attr 1=4 my", "default", &hits);
102 YAZ_CHECK_EQ(res, ZEBRA_OK);
103 YAZ_CHECK_EQ(hits, 1);
105 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_TEXT_XML,
106 "mismatch"), ZEBRA_FAIL);
108 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_SUTRS,
109 myrec[0]), ZEBRA_OK);
111 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_TEXT_XML,
112 myrec[0]), ZEBRA_OK);
114 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta::sysno", VAL_SUTRS,
117 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta::sysno", VAL_TEXT_XML,
118 zebra_xml_sysno), ZEBRA_OK);
120 /* YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data::index:title:p",
122 zebra_xml_index_title_p), ZEBRA_OK);
124 YAZ_CHECK(tl_close_down(zh, zs));
132 * indent-tabs-mode: nil
134 * vim: shiftwidth=4 tabstop=8 expandtab