Cleaned the test programs a bit, used routines in testlib
[idzebra-moved-to-github.git] / test / api / t10.c
1 /* $Id: t10.c,v 1.2 2004-10-28 15:24:36 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /** t10.c - test zv-rank */
24
25 #include <yaz/log.h>
26 #include <yaz/pquery.h>
27 #include <idzebra/api.h>
28 #include <assert.h>
29 #include "testlib.h"
30 #include "rankingrecords.h"
31
32 #define qry(zh,query,hits,string,score) \
33     RankingQuery(__LINE__,(zh),(query),(hits),(string),(score))
34
35 struct tst {
36     char *schema;
37     char *hit1;
38     int score1;
39     char *hit2;
40     int score2;
41     char *hit3;
42     int score3;
43 };
44
45
46
47 struct tst tests[] = {
48     {"ntc-atn", "first title", 1000, "first title", 1000, "third title", 826 },
49     {"ntc-ntn", "first title", 1000, "first title", 1000, "third title", 826 },
50     {"ntc-btn", "first title", 1000, "first title", 1000, "third title", 826 },
51     {"ntc-apn", "first title", 1000, "first title", 1000, "third title", 826 },
52     {"ntc-npn", "first title", 1000, "first title", 1000, "third title", 826 },
53     {"ntc-bpn", "first title", 1000, "first title", 1000, "third title", 826 },
54
55     {"atc-atn", "first title", 1000, "first title", 1000, "first title", 972 },
56     {"atc-ntn", "first title", 1000, "first title", 1000, "first title", 972 },
57     {"atc-btn", "first title", 1000, "first title", 1000, "first title", 972 },
58     {"atc-apn", "first title", 1000, "first title", 1000, "first title", 972 },
59     {"atc-npn", "first title", 1000, "first title", 1000, "first title", 972 },
60     {"atc-bpn", "first title", 1000, "first title", 1000, "first title", 972 },
61
62     {"npc-atn", "first title", 1000, "first title", 1000, "third title", 826 },
63     {"npc-ntn", "first title", 1000, "first title", 1000, "third title", 826 },
64     {"npc-btn", "first title", 1000, "first title", 1000, "third title", 826 },
65     {"npc-apn", "first title", 1000, "first title", 1000, "third title", 826 },
66     {"npc-npn", "first title", 1000, "first title", 1000, "third title", 826 },
67     {"npc-bpn", "first title", 1000, "first title", 1000, "third title", 826 },
68
69     {"apc-atn", "first title", 1000, "first title", 1000, "first title", 972 },
70     {"apc-ntn", "first title", 1000, "first title", 1000, "first title", 972 },
71     {"apc-btn", "first title", 1000, "first title", 1000, "first title", 972 },
72     {"apc-apn", "first title", 1000, "first title", 1000, "first title", 972 },
73     {"apc-npn", "first title", 1000, "first title", 1000, "first title", 972 },
74     {"apc-bpn", "first title", 1000, "first title", 1000, "first title", 972 },
75
76     {0,0,0,0,0,0,0},
77 };
78
79 int main(int argc, char **argv)
80 {
81     int i;
82     ZebraService zs;
83     ZebraHandle zh;
84
85     yaz_log_init_file("t10.log");
86     /* yaz_log_init_level(LOG_ALL);  */
87
88     nmem_init ();
89     
90     zs = start_service("zebrazv.cfg"); 
91     assert(zs);
92     zh = zebra_open (zs);
93   
94     init_data(zh, recs);
95
96     zebra_close(zh);
97
98
99     for (i=0; tests[i].schema; i++)
100     {
101         zh = zebra_open (zs);
102         zebra_select_database(zh, "Default");
103         zebra_set_resource(zh, "zvrank.weighting-scheme", tests[i].schema);
104         logf(LOG_LOG,"============%d: %s ============", i,tests[i].schema);
105
106         RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 the",
107                 3, tests[i].hit1, tests[i].score1);
108         RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or foo bar",
109                 3, tests[i].hit2, tests[i].score2);
110         RankingQuery( __LINE__, zh, 
111                 "@attr 1=1016 @attr 2=102 @or @or the foo bar",
112                 3, tests[i].hit3, tests[i].score3);
113
114         zebra_close(zh);
115     }
116     
117     zebra_stop (zs);
118
119     nmem_exit ();
120     xmalloc_trav ("x");
121     logf(LOG_LOG,"============ ALL TESTS PASSED OK ============");
122     exit(0);
123 }