1 /* $Id: t16.c,v 1.1 2006-11-16 12:48:28 adam 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)
89 ZebraService zs = tl_start_up(0, argc, argv);
90 ZebraHandle zh = zebra_open(zs, 0);
92 YAZ_CHECK(tl_init_data(zh, myrec));
94 res = zebra_search_PQF(zh, "@attr 1=4 my", "default", &hits);
95 YAZ_CHECK_EQ(res, ZEBRA_OK);
96 YAZ_CHECK_EQ(hits, 1);
98 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_TEXT_XML,
101 YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", VAL_TEXT_XML,
102 "mismatch"), ZEBRA_FAIL);
104 YAZ_CHECK(tl_close_down(zh, zs));
112 * indent-tabs-mode: nil
114 * vim: shiftwidth=4 tabstop=8 expandtab