d4898442290f739b30f3c798530992c8dd5a2829
[idzebra-moved-to-github.git] / test / api / test_special_elements.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 2004-2013 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 /** \brief test special element set names zebra:: and friends */
21
22 #if HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include "testlib.h"
26
27 const char *myrec[] = {
28         "<gils>\n"
29         "  <title>My title</title>\n"
30         "</gils>\n",
31         0};
32
33 static void tst(int argc, char **argv)
34 {
35     zint hits;
36     ZEBRA_RES res;
37     const char * zebra_xml_sysno
38         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\"/>\n";
39
40     const char * zebra_xml_meta
41         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" base=\"Default\" type=\"grs.sgml\" rank=\"0\" size=\"41\" set=\"zebra::meta\"/>\n";
42
43     const char * zebra_xml_index_title_p
44         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:p\">\n"
45 "  <index name=\"title\" type=\"p\" seq=\"4\">my title</index>\n"
46 "</record>\n";
47
48     const char * zebra_xml_index_title_s
49         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:s\">\n"
50 "  <index name=\"title\" type=\"s\">my title</index>\n"
51 "</record>\n";
52
53     ZebraService zs = tl_start_up(0, argc, argv);
54     ZebraHandle zh = zebra_open(zs, 0);
55
56     YAZ_CHECK(tl_init_data(zh, myrec));
57
58     res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits);
59     YAZ_CHECK_EQ(res, ZEBRA_OK);
60     YAZ_CHECK_EQ(hits, 1);
61
62     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
63                                         "mismatch"), ZEBRA_FAIL);
64
65     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs,
66                                         myrec[0]), ZEBRA_OK);
67
68     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
69                                         myrec[0]), ZEBRA_OK);
70
71     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno",
72                                         yaz_oid_recsyn_sutrs,
73                                         "2"), ZEBRA_OK);
74
75     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno",
76                                         yaz_oid_recsyn_xml,
77                                         zebra_xml_sysno), ZEBRA_OK);
78
79     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml,
80                                         zebra_xml_meta), ZEBRA_OK);
81
82     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p",
83                                         yaz_oid_recsyn_xml,
84                                         zebra_xml_index_title_p), ZEBRA_OK);
85
86     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:s",
87                                         yaz_oid_recsyn_xml,
88                                         zebra_xml_index_title_s), ZEBRA_OK);
89
90     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent",
91                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
92
93     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent",
94                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
95
96     YAZ_CHECK(tl_close_down(zh, zs));
97 }
98
99 TL_MAIN
100
101 /*
102  * Local variables:
103  * c-basic-offset: 4
104  * c-file-style: "Stroustrup"
105  * indent-tabs-mode: nil
106  * End:
107  * vim: shiftwidth=4 tabstop=8 expandtab
108  */
109