Renamed files for sort tests.
[idzebra-moved-to-github.git] / test / api / t10.c
index f333448..919dae0 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: t10.c,v 1.1 2004-10-28 10:37:15 heikki Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
-   Index Data Aps
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1995-2008 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -15,124 +12,61 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
-/** t10.c - test zv-rank */
+/* Creates a few result sets */
 
-#include <yaz/log.h>
-#include <yaz/pquery.h>
-#include <idzebra/api.h>
 #include "testlib.h"
-#include "rankingrecords.h"
-
-#define qry(zh,query,hits,string,score) \
-    RankingQuery(__LINE__,(zh),(query),(hits),(string),(score))
-
-struct tst {
-    char *schema;
-    char *hit1;
-    int score1;
-    char *hit2;
-    int score2;
-    char *hit3;
-    int score3;
-};
-
-
-
-struct tst tests[] = {
-    {"ntc-atn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"ntc-ntn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"ntc-btn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"ntc-apn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"ntc-npn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"ntc-bpn", "first title", 1000, "first title", 1000, "third title", 826 },
-
-    {"atc-atn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"atc-ntn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"atc-btn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"atc-apn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"atc-npn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"atc-bpn", "first title", 1000, "first title", 1000, "first title", 972 },
-
-    {"npc-atn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"npc-ntn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"npc-btn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"npc-apn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"npc-npn", "first title", 1000, "first title", 1000, "third title", 826 },
-    {"npc-bpn", "first title", 1000, "first title", 1000, "third title", 826 },
-
-    {"apc-atn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"apc-ntn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"apc-btn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"apc-apn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"apc-npn", "first title", 1000, "first title", 1000, "first title", 972 },
-    {"apc-bpn", "first title", 1000, "first title", 1000, "first title", 972 },
-
-    {0,0,0,0,0,0,0},
-};
-
-int main(int argc, char **argv)
+
+const char *myrec[] ={
+        "<t10>\n"
+        "  <title>My title</title>\n"
+        "</t10>\n",
+        0};
+
+static void tst(int argc, char **argv)
 {
-    int i;
-    char *addinfo;
-    ZebraService zs;
-    ZebraHandle zh;
-
-    yaz_log_init_file("t10.log");
-    /* yaz_log_init_level(LOG_ALL);  */
-
-    nmem_init ();
-    
-    zs = start_service("zebrazv.cfg"); 
-    zh = zebra_open (zs);
-    zebra_select_database(zh, "Default");
-    logf(LOG_LOG,"going to call init");
-    i=zebra_init(zh);
-    logf(LOG_LOG,"init returned %d",i);
-    if (i) {
-        printf("init failed with %d\n",i);
-        zebra_result(zh, &i, &addinfo);
-        printf("  Error %d   %s\n",i,addinfo);
-        exit(1);
-    }
-
-    zebra_begin_trans (zh, 1);
-    for (i = 0; recs[i]; i++)
-       zebra_add_record (zh, recs[i], strlen(recs[i]));
-    zebra_end_trans (zh);
-    zebra_commit (zh);
-  
-    // yaz_log_init_level(LOG_ALL); 
-
-    zebra_close(zh);
-
-
-    for (i=0; tests[i].schema; i++)
-    {
-        zh = zebra_open (zs);
-        zebra_select_database(zh, "Default");
-        zebra_set_resource(zh, "zvrank.weighting-scheme", tests[i].schema);
-        logf(LOG_LOG,"============%d: %s ============", i,tests[i].schema);
-
-        RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 the",
-                3, tests[i].hit1, tests[i].score1);
-        RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or foo bar",
-                3, tests[i].hit2, tests[i].score2);
-        RankingQuery( __LINE__, zh, 
-                "@attr 1=1016 @attr 2=102 @or @or the foo bar",
-                3, tests[i].hit3, tests[i].score3);
-
-        zebra_close(zh);
-    }
-    
-    zebra_stop (zs);
-
-    nmem_exit ();
-    xmalloc_trav ("x");
-    logf(LOG_LOG,"============ ALL TESTS PASSED OK ============");
-    exit (0);
+    ZebraService zs = tl_start_up("zebra10.cfg", argc, argv);
+    ZebraHandle zh = zebra_open(zs, 0);
+
+    YAZ_CHECK(tl_init_data(zh, myrec));
+
+    zebra_commit(zh);
+
+    // string attributes in search
+    YAZ_CHECK(tl_query(zh, "@attr 1=title my", 1));
+    YAZ_CHECK(tl_query(zh, "@attr 1=title my", 1));
+    YAZ_CHECK(tl_query(zh, "@attr 1=title titlex", 0));
+    YAZ_CHECK(tl_query(zh, "@attr 1=extra_title my", 1));
+
+    // numeric attributes with Bib-1 should produce an error
+    YAZ_CHECK(tl_query_x(zh, 
+                         "@attr 1=4 my", 0, 121));
+    YAZ_CHECK(tl_query_x(zh, 
+                         "@attr 1=7 my", 0, 121));
+    // private OID with incorrect use attribute
+    YAZ_CHECK(tl_query_x(zh, 
+                         "@attr 1.2.840.10003.3.1000.1000.1 1=4 my", 0, 114));
+    // private OID with OK use attribute
+    YAZ_CHECK(tl_query(zh, 
+                       "@attr 1.2.840.10003.3.1000.1000.1 1=7 my", 1));
+
+    YAZ_CHECK(tl_query(zh, 
+                       "@attr 1.2.840.10003.3.1000.1000.1 1=8 my", 1));
+
+    YAZ_CHECK(tl_close_down(zh, zs));
 }
+
+TL_MAIN
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+