3ead07779fbb18b9e8798c5cb05d9876751a7840
[idzebra-moved-to-github.git] / test / api / test_special_elements.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2010 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 #include "testlib.h"
23
24 const char *myrec[] = {
25         "<gils>\n"
26         "  <title>My title</title>\n"
27         "</gils>\n",
28         0};
29         
30 static void tst(int argc, char **argv)
31 {
32     zint hits;
33     ZEBRA_RES res;
34     const char * zebra_xml_sysno 
35         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\"/>\n";
36
37     const char * zebra_xml_meta 
38         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" base=\"Default\" type=\"grs.sgml\" rank=\"0\" size=\"41\" set=\"zebra::meta\"/>\n";
39
40     const char * zebra_xml_index_title_p
41         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:p\">\n"
42 "  <index name=\"title\" type=\"p\" seq=\"4\">my title</index>\n"
43 "</record>\n";
44
45     const char * zebra_xml_index_title_s
46         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:s\">\n"
47 "  <index name=\"title\" type=\"s\">my title</index>\n"
48 "</record>\n";
49
50     ZebraService zs = tl_start_up(0, argc, argv);
51     ZebraHandle zh = zebra_open(zs, 0);
52
53     YAZ_CHECK(tl_init_data(zh, myrec));
54
55     res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits);
56     YAZ_CHECK_EQ(res, ZEBRA_OK);
57     YAZ_CHECK_EQ(hits, 1);
58     
59     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
60                                         "mismatch"), ZEBRA_FAIL);
61     
62     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs,
63                                         myrec[0]), ZEBRA_OK);
64     
65     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
66                                         myrec[0]), ZEBRA_OK);
67     
68     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", 
69                                         yaz_oid_recsyn_sutrs,
70                                         "2"), ZEBRA_OK);
71     
72     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", 
73                                         yaz_oid_recsyn_xml,
74                                         zebra_xml_sysno), ZEBRA_OK);
75     
76     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml,
77                                         zebra_xml_meta), ZEBRA_OK);
78     
79     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p", 
80                                         yaz_oid_recsyn_xml,
81                                         zebra_xml_index_title_p), ZEBRA_OK);
82     
83     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:s", 
84                                         yaz_oid_recsyn_xml,
85                                         zebra_xml_index_title_s), ZEBRA_OK);
86     
87     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent", 
88                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
89     
90     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent", 
91                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
92     
93     YAZ_CHECK(tl_close_down(zh, zs));
94 }
95
96 TL_MAIN
97
98 /*
99  * Local variables:
100  * c-basic-offset: 4
101  * c-file-style: "Stroustrup"
102  * indent-tabs-mode: nil
103  * End:
104  * vim: shiftwidth=4 tabstop=8 expandtab
105  */
106