d7d03a0749f1cc48807d6a98934b96d51fd57304
[idzebra-moved-to-github.git] / test / api / t16.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 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     ZebraService zs = tl_start_up(0, argc, argv);
46     ZebraHandle zh = zebra_open(zs, 0);
47
48     YAZ_CHECK(tl_init_data(zh, myrec));
49
50     res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits);
51     YAZ_CHECK_EQ(res, ZEBRA_OK);
52     YAZ_CHECK_EQ(hits, 1);
53     
54     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
55                                         "mismatch"), ZEBRA_FAIL);
56     
57     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs,
58                                         myrec[0]), ZEBRA_OK);
59     
60     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
61                                         myrec[0]), ZEBRA_OK);
62     
63     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", 
64                                         yaz_oid_recsyn_sutrs,
65                                         "2"), ZEBRA_OK);
66     
67     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", 
68                                         yaz_oid_recsyn_xml,
69                                         zebra_xml_sysno), ZEBRA_OK);
70     
71     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml,
72                                         zebra_xml_meta), ZEBRA_OK);
73     
74     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p", 
75                                         yaz_oid_recsyn_xml,
76                                         zebra_xml_index_title_p), ZEBRA_OK);
77     
78     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent", 
79                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
80     
81     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent", 
82                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
83     
84     YAZ_CHECK(tl_close_down(zh, zs));
85 }
86
87 TL_MAIN
88
89 /*
90  * Local variables:
91  * c-basic-offset: 4
92  * indent-tabs-mode: nil
93  * End:
94  * vim: shiftwidth=4 tabstop=8 expandtab
95  */
96