1351c53db3f2f9e80fb923ae59e380b729ab2d14
[idzebra-moved-to-github.git] / test / xslt / xslt3.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 #include <stdio.h>
21 #include "testlib.h"
22
23 static void tst(int argc, char **argv)
24 {
25     char path[256];
26     char profile_path[256];
27     char record_buf[20000];
28     const char *records_array[] = {
29         record_buf, 0
30     };
31     FILE *f;
32     size_t r;
33
34     ZebraService zs = tl_start_up(0, argc, argv);
35     ZebraHandle  zh = zebra_open(zs, 0);
36
37     tl_check_filter(zs, "alvis");
38
39     YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
40     
41     zebra_init(zh);
42
43     sprintf(profile_path, "%s:%s/../../tab", 
44             tl_get_srcdir(), tl_get_srcdir());
45     zebra_set_resource(zh, "profilePath", profile_path);
46
47     zebra_set_resource(zh, "recordType", "alvis.marcschema-one.xml");
48
49     sprintf(path, "%.200s/marc-one.xml", tl_get_srcdir());
50     f = fopen(path, "rb");
51     if (!f)
52     {
53         yaz_log(YLOG_FATAL|YLOG_ERRNO, "Cannot open %s", path);
54         exit(1);
55     }
56     r = fread(record_buf, 1, sizeof(record_buf)-1, f);
57     if (r < 2 || r == sizeof(record_buf)-1)
58     {
59         yaz_log(YLOG_FATAL, "Bad size of %s", path);
60         exit(1);
61     }
62     fclose(f);
63
64     record_buf[r] = '\0';
65
66     /* index this one record */
67     YAZ_CHECK(tl_init_data(zh, records_array));
68
69     /* only get hits from first record .. */
70     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
71     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
72     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
73
74     
75     /* index one more time to see that we don't get dups, since
76      index.xsl has a record ID associated with them */
77     zebra_add_record(zh, record_buf, strlen(record_buf));
78
79     /* only get hits from first record .. */
80     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
81     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
82     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
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  * c-file-style: "Stroustrup"
93  * indent-tabs-mode: nil
94  * End:
95  * vim: shiftwidth=4 tabstop=8 expandtab
96  */
97