59b480740dfbe7d21fa1e8f82855d6c2a48215d5
[idzebra-moved-to-github.git] / test / api / t16.c
1 /* $Id: t16.c,v 1.14 2007-11-30 12:19:09 adam Exp $
2    Copyright (C) 1995-2007
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20
21 */
22
23 /** \brief test special element set names zebra:: and friends */
24
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     ZebraService zs = tl_start_up(0, argc, argv);
49     ZebraHandle zh = zebra_open(zs, 0);
50
51     YAZ_CHECK(tl_init_data(zh, myrec));
52
53     res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits);
54     YAZ_CHECK_EQ(res, ZEBRA_OK);
55     YAZ_CHECK_EQ(hits, 1);
56     
57     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
58                                         "mismatch"), ZEBRA_FAIL);
59     
60     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs,
61                                         myrec[0]), ZEBRA_OK);
62     
63     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
64                                         myrec[0]), ZEBRA_OK);
65     
66     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", 
67                                         yaz_oid_recsyn_sutrs,
68                                         "2"), ZEBRA_OK);
69     
70     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", 
71                                         yaz_oid_recsyn_xml,
72                                         zebra_xml_sysno), ZEBRA_OK);
73     
74     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml,
75                                         zebra_xml_meta), ZEBRA_OK);
76     
77     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p", 
78                                         yaz_oid_recsyn_xml,
79                                         zebra_xml_index_title_p), ZEBRA_OK);
80     
81     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent", 
82                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
83     
84     YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent", 
85                                         yaz_oid_recsyn_xml, ""), ZEBRA_OK);
86     
87     YAZ_CHECK(tl_close_down(zh, zs));
88 }
89
90 TL_MAIN
91
92 /*
93  * Local variables:
94  * c-basic-offset: 4
95  * indent-tabs-mode: nil
96  * End:
97  * vim: shiftwidth=4 tabstop=8 expandtab
98  */
99