From: Adam Dickmeiss Date: Wed, 16 Apr 2008 09:49:39 +0000 (+0200) Subject: Re-organized test files. X-Git-Tag: v2.0.30~8 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=965cbd297cf8de73cfe01d55983b8161ae7cf67e Re-organized test files. --- diff --git a/test/api/.gitignore b/test/api/.gitignore index 031d5e1..2ca133e 100644 --- a/test/api/.gitignore +++ b/test/api/.gitignore @@ -2,8 +2,21 @@ .libs Makefile Makefile.in -t[0-9] -t[0-9][0-9] +test_rank +test_resources +test_update_record +test_start_stop +test_result_sets +test_insert_fetch +test_search +test_trunc +test_sort_set +test_create_databases +test_icu_indexing +test_private_attset +test_scan +test_special_elements +test_zebra_fork test_safari test_sortindex *.mf diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 2ada879..1f83bdb 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -2,38 +2,40 @@ noinst_PROGRAMS = testclient testclient_SOURCES = testclient.c -check_PROGRAMS = t0 t1 t2 t3 t4 t5 t6 t7 t8 \ - t9 t10 t11 t12 t13 t14 t15 t16 t17 \ +check_PROGRAMS = test_start_stop test_result_sets \ + test_insert_fetch test_search test_trunc test_sort_set \ + test_rank test_private_attset \ + test_scan test_create_databases test_resources test_update_record \ + test_zebra_fork test_special_elements test_icu_indexing \ test_sortindex test_safari TESTS = $(check_PROGRAMS) -EXTRA_DIST=zebra.cfg zebra6.cfg zebra8.cfg zebra10.cfg zebra15.cfg \ - t10.att t10.abs zebra17.cfg t17.idx \ +EXTRA_DIST=zebra.cfg test_trunc.cfg test_private_attset.cfg \ + private_attset.att private_attset.abs \ + test_zebra_fork.cfg \ + test_icu_indexing.cfg test_icu_indexing.idx \ test_safari.cfg test_sortindex.cfg noinst_LIBRARIES = libtestlib.a libtestlib_a_SOURCES = testlib.c testlib.h -t0_SOURCES = t0.c -t1_SOURCES = t1.c -t2_SOURCES = t2.c -t3_SOURCES = t3.c -t4_SOURCES = t4.c -t5_SOURCES = t5.c -t6_SOURCES = t6.c -t7_SOURCES = t7.c -t8_SOURCES = t8.c -t9_SOURCES = t9.c rankingrecords.h -t10_SOURCES = t10.c -t11_SOURCES = t11.c -t12_SOURCES = t12.c -t13_SOURCES = t13.c -t14_SOURCES = t14.c -t15_SOURCES = t15.c -t16_SOURCES = t16.c -t17_SOURCES = t17.c +test_start_stop_SOURCES = test_start_stop.c +test_result_sets_SOURCES = test_result_sets.c +test_insert_fetch_SOURCES = test_insert_fetch.c +test_search_SOURCES = test_search.c +test_trunc_SOURCES = test_trunc.c +test_sort_set_SOURCES = test_sort_set.c +test_rank_SOURCES = test_rank.c +test_private_attset_SOURCES = test_private_attset.c +test_scan_SOURCES = test_scan.c +test_create_databases_SOURCES = test_create_databases.c +test_resouces_SOURCES = test_resouces.c +test_update_record_SOURCES = test_update_record.c +test_zebra_fork_SOURCES = test_zebra_fork.c +test_special_elements_SOURCES = test_special_elements.c +test_icu_indexing_SOURCES = test_icu_indexing.c test_sortindex_SOURCES = test_sortindex.c test_safari_SOURCES = test_safari.c testlib.c diff --git a/test/api/private_attset.abs b/test/api/private_attset.abs new file mode 100644 index 0000000..9cc1033 --- /dev/null +++ b/test/api/private_attset.abs @@ -0,0 +1,12 @@ +# This is the abstract syntax (and most of the top-level profile info) +# for GILS version 2. +# + +name my_private_attset +attset private_attset.att + +esetname F @ + +systag sysno none + +elm title title title:w,extra_title:w diff --git a/test/api/private_attset.att b/test/api/private_attset.att new file mode 100644 index 0000000..05b0a37 --- /dev/null +++ b/test/api/private_attset.att @@ -0,0 +1,6 @@ +# Bib-1 Attribute Set +name private_attset +reference 1.2.840.10003.3.1000.1000.1 + +att 7 title +att 8 extra_title diff --git a/test/api/rankingrecords.h b/test/api/rankingrecords.h deleted file mode 100644 index 611d9fc..0000000 --- a/test/api/rankingrecords.h +++ /dev/null @@ -1,60 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** rankingrecords.h - some test data for t9, and t10 */ - -const char *recs[] = { - "\n" - " The first title\n" - " \n" - " The first common word is the: the the the \n" - " The second common word is word \n" - " but all have the foo bar \n" - " \n" - "\n", - - "\n" - " The second title\n" - " \n" - " The first common word is the: the \n" - " The second common word is foo: foo foo \n" - " but all have the foo bar \n" - " \n" - "\n", - - "\n" - " The third title\n" - " \n" - " The first common word is the: the \n" - " The third common word is bar: bar \n" - " but all have the foo bar \n" - " \n" - "\n", - - 0 }; - - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/test/api/t0.c b/test/api/t0.c deleted file mode 100644 index f126253..0000000 --- a/test/api/t0.c +++ /dev/null @@ -1,37 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** t0 - test zebra_start .. */ - -#include "testlib.h" - -static void tst(int argc, char **argv) -{ - YAZ_CHECK(!zebra_start("xxxxpoiasdfasfd.cfg")); /* should fail */ -} - -TL_MAIN -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/test/api/t1.c b/test/api/t1.c deleted file mode 100644 index ec33957..0000000 --- a/test/api/t1.c +++ /dev/null @@ -1,42 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** t1 - just start and stop */ - -#include -#include "testlib.h" - -static void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - 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 - */ - diff --git a/test/api/t10.abs b/test/api/t10.abs deleted file mode 100644 index 3b0e2f1..0000000 --- a/test/api/t10.abs +++ /dev/null @@ -1,12 +0,0 @@ -# This is the abstract syntax (and most of the top-level profile info) -# for GILS version 2. -# - -name t10 -attset t10.att - -esetname F @ - -systag sysno none - -elm title title title:w,extra_title:w diff --git a/test/api/t10.att b/test/api/t10.att deleted file mode 100644 index 1cd51c1..0000000 --- a/test/api/t10.att +++ /dev/null @@ -1,6 +0,0 @@ -# Bib-1 Attribute Set -name t10 -reference 1.2.840.10003.3.1000.1000.1 - -att 7 title -att 8 extra_title diff --git a/test/api/t10.c b/test/api/t10.c deleted file mode 100644 index 919dae0..0000000 --- a/test/api/t10.c +++ /dev/null @@ -1,72 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/* Creates a few result sets */ - -#include "testlib.h" - -const char *myrec[] ={ - "\n" - " My title\n" - "\n", - 0}; - -static void tst(int argc, char **argv) -{ - 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 - */ - diff --git a/test/api/t11.c b/test/api/t11.c deleted file mode 100644 index f6038dc..0000000 --- a/test/api/t11.c +++ /dev/null @@ -1,171 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** testing of scan */ -#include "testlib.h" - -const char *myrec[] = { - "\na b\n\n", - "\nc d\n\n", - "\ne f\n\n" , - 0} ; - -static void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(zh); - - YAZ_CHECK(tl_init_data(zh, myrec)); - - /* - int tl_scan - ( - ZebraHandle zh, const char *query, - int pos, int num, - int exp_pos, int exp_num, int exp_partial, - const char **exp_entries - ) - */ - - - { - /* bad string use attrite, bug #647 */ - YAZ_CHECK(tl_scan(zh, "@attr 1=bad 0", 1, 1, 1, 1, 0, 0)); - } - - { - /* bad numeric use attributes, bug #647 */ - YAZ_CHECK(tl_scan(zh, "@attr 1=1234 0", 1, 1, 1, 1, 0, 0)); - } - - { - /* scan before. nothing must be returned */ - const char *ent[] = { "a", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 1, 1, 1, 1, 0, ent)); - } - - { - /* scan after. nothing must be returned */ - const char *ent[] = { 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 m", 1, 1, 1, 0, 1, ent)); - } - - { - const char *ent[] = { "a", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", 1, 1, 1, 1, 0, ent)); - } - - { - const char *ent[] = { "b", "c", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent)); - } - - { - const char *ent[] = { "b", "c", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent)); - } - - { - const char *ent[] = { "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 e", 1, 3, 1, 2, 1, ent)); - } - - { - const char *ent[] = { "c", "d", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -1, 2, -1, 2, 0, ent)); - } - - { - const char *ent[] = { "d", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 1, -2, 1, 0, ent)); - } - - { - const char *ent[] = { "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -4, 1, -4, 1, 0, ent)); - } - - { - const char *ent[] = { "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -5, 1, -5, 0, 1, ent)); - } - - { - const char *ent[] = { "d", "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 3, -2, 3, 0, ent)); - } - - { - const char *ent[] = { "d", "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 4, -2, 3, 1, ent)); - } - - { - const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 2, 100, 1, 6, 1, ent)); - } - - { - const char *ent[] = { "b", "c", "d", "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 0, 100, 0, 5, 1, ent)); - } - - { - const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 10, 100, 1, 6, 1, ent)); - } - - { - const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 22, 10, 1, 0, 1, ent)); - } - - { - const char *ent[] = { 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=4 z", -22, 10, -22, 0, 1, ent)); - } - - { - const char *ent[] = { "c", "d", 0 }; - - YAZ_CHECK(tl_query(zh, "@attr 1=4 c", 1)); - - /* must fail, because x is not a result set */ - YAZ_CHECK(tl_scan(zh, "@attr 8=x @attr 1=4 a", 1, 3, 0, 0, 0, 0)); - - /* bug 1114 */ - YAZ_CHECK(tl_scan(zh, "@attr 8=rsetname @attr 1=4 0", - 1, 20, 1, 2, 1, ent)); - - } - 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 - */ - diff --git a/test/api/t12.c b/test/api/t12.c deleted file mode 100644 index 4250aa1..0000000 --- a/test/api/t12.c +++ /dev/null @@ -1,86 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** Create many databases */ - -#include "testlib.h" - -static void tst(int argc, char **argv) -{ - int i; - int no_db = 140; - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - YAZ_CHECK(zebra_init(zh) == ZEBRA_OK); - zebra_close(zh); - - zh = zebra_open(zs, 0); - YAZ_CHECK(zh); - - YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK); - - for (i = 0; ititle %d\n", i); - zebra_add_record (zh, rec_buf, strlen(rec_buf)); - - } - YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); - - zebra_close(zh); - zh = zebra_open(zs, 0); - YAZ_CHECK(zh); - for (i = 0; i<=no_db; i++) - { - char dbstr[20]; - char querystr[50]; - sprintf(dbstr, "%d", i); - YAZ_CHECK(zebra_select_database(zh, dbstr) == ZEBRA_OK); - - sprintf(querystr, "@attr 1=4 %d", i); - if (i == no_db) - { - YAZ_CHECK(tl_query_x(zh, querystr, 0, 109)); - } - else - { - YAZ_CHECK(tl_query(zh, querystr, 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 - */ - diff --git a/test/api/t13.c b/test/api/t13.c deleted file mode 100644 index 47e38ef..0000000 --- a/test/api/t13.c +++ /dev/null @@ -1,123 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** test resources */ -#include -#include -#include "testlib.h" -#include - -static void tst_res(void) -{ - Res default_res; /* default resources */ - Res temp_res; /* temporary resources */ - ZebraService zs; - ZebraHandle zh; - const char *val; - int i; - - default_res = res_open(0, 0); /* completely empty */ - YAZ_CHECK(default_res); - - res_set(default_res, "name1", "value1"); - - temp_res = res_open(0, 0); /* completely empty */ - YAZ_CHECK(temp_res); - - zs = zebra_start_res(0, default_res, temp_res); - YAZ_CHECK(zs); - - zh = zebra_open(zs, 0); - YAZ_CHECK(zh); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - - /* run this a few times so we can see leaks easier */ - for (i = 0; i<10; i++) - { - /* we should find the name1 from default_res */ - val = zebra_get_resource(zh, "name1", 0); - YAZ_CHECK(val && !strcmp(val, "value1")); - - /* make local override */ - res_set(temp_res, "name1", "value2"); - res_set(temp_res, "name4", "value4"); - - /* we should find the name1 from temp_res */ - val = zebra_get_resource(zh, "name1", 0); - YAZ_CHECK(val && !strcmp(val, "value2")); - - val = zebra_get_resource(zh, "name4", 0); - YAZ_CHECK(val && !strcmp(val, "value4")); - - res_clear(temp_res); - } - zebra_close(zh); - zebra_stop(zs); - - res_close(temp_res); - res_close(default_res); -} - -static void tst_no_config(void) -{ - static char *xml_buf = "myx"; - ZebraService zs; - ZebraHandle zh; - zint sysno = 0; - - zs = zebra_start_res(0, 0, 0); - YAZ_CHECK(zs); - - zh = zebra_open(zs, 0); - YAZ_CHECK(zh); - - YAZ_CHECK_EQ(zebra_select_database(zh, "Default"), ZEBRA_OK); - - YAZ_CHECK_EQ(zebra_init(zh), ZEBRA_OK); - - zebra_set_resource(zh, "profilePath", "${srcdir:-.}/../../tab"); - - YAZ_CHECK_EQ(zebra_update_record(zh /* handle */, - action_insert, - "grs.sgml" /* record type */, - &sysno, 0 /* match */, - 0 /* fname */, - xml_buf, strlen(xml_buf)), - ZEBRA_OK); - - zebra_close(zh); - zebra_stop(zs); -} - -static void tst(int argc, char **argv) -{ - tst_res(); - tst_no_config(); -} - -TL_MAIN -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/test/api/t14.c b/test/api/t14.c deleted file mode 100644 index 4449c39..0000000 --- a/test/api/t14.c +++ /dev/null @@ -1,80 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include "testlib.h" - -static void create_search_drop(ZebraHandle zh) -{ - const char *rec = "some"; - const char *opaque_id = "9"; - - YAZ_CHECK(zebra_create_database (zh, "Default") == ZEBRA_OK); - - /* bug #447 */ - YAZ_CHECK(zebra_update_record( - zh, action_update, - 0 /* record type */, - 0 /* sysno */, - opaque_id, - 0 /* fname */, - rec, strlen(rec)) - == ZEBRA_OK); /* insert really */ - - YAZ_CHECK(zebra_update_record( - zh, action_update, - 0 /* record type */, - 0 /* sysno */, - opaque_id, - 0 /* fname */, - rec, strlen(rec)) - == ZEBRA_OK); /* replace really */ - - YAZ_CHECK(tl_query(zh, "@attr 1=4 some", 1)); - - zebra_drop_database(zh, "Default"); - - YAZ_CHECK(tl_query_x(zh, "@attr 1=4 some", 0, 109)); - -} - -static void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up("zebra.cfg", argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - - zebra_init(zh); - - create_search_drop(zh); - /* bug #447 */ - create_search_drop(zh); - - 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 - */ - diff --git a/test/api/t15.c b/test/api/t15.c deleted file mode 100644 index b0e93ad..0000000 --- a/test/api/t15.c +++ /dev/null @@ -1,154 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#if HAVE_SYS_STAT_H -#include -#endif -#if HAVE_SYS_TYPES_H -#include -#endif -#if HAVE_UNISTD_H -#include -#endif -#if HAVE_SYS_WAIT_H -#include -#endif -#if HAVE_SYS_UTSNAME_H -#include -#endif - -#include - -#include "testlib.h" - -static void update_process(ZebraService zs, int iter) -{ - int i; - for (i = 0; i= hits_max); - if (hits < hits_max) - printf("i=%d hits=%lld hits_max=%lld\n", i, hits, hits_max); - hits_max = hits; - zebra_close(zh); - } -} - -static pid_t fork_service(ZebraService zs, int iter, - void (*f)(ZebraService zs, int iter)) -{ - pid_t pid = fork(); - - YAZ_CHECK(pid != -1); - if (pid) - return pid; - - (*f)(zs, iter); - YAZ_CHECK_TERM; -} - -static void tst(int argc, char **argv) -{ - ZebraService zs; - ZebraHandle zh; - - mkdir("register", 0775); - mkdir("shadow", 0775); - - zs = tl_start_up("zebra15.cfg", argc, argv); - YAZ_CHECK(zs); - - zh = zebra_open(zs, 0); - YAZ_CHECK(zh); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - - zebra_init(zh); - - YAZ_CHECK(zebra_create_database (zh, "Default") == ZEBRA_OK); - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - zebra_close(zh); - - update_process(zs, 1); - -#if HAVE_SYS_WAIT_H -#if HAVE_UNISTD_H -#if HAVE_SYS_UTSNAME_H - - if (1) - { - int tst_with_fork = 1; - int status[3]; - pid_t pids[3]; - struct utsname s; - uname(&s); - if (!strcmp(s.sysname, "FreeBSD")) - tst_with_fork = 0; - - yaz_log(YLOG_LOG, "s.sysname=%s tst_with_fork=%d", s.sysname, - tst_with_fork); - if (tst_with_fork) - { - pids[0] = fork_service(zs, 200, search_process); - pids[1] = fork_service(zs, 20, update_process); - pids[2] = fork_service(zs, 20, update_process); - waitpid(pids[0], &status[0], 0); - YAZ_CHECK(status[0] == 0); - waitpid(pids[1], &status[1], 0); - YAZ_CHECK(status[1] == 0); - waitpid(pids[2], &status[2], 0); - YAZ_CHECK(status[2] == 0); - } - } -#endif -#endif -#endif - YAZ_CHECK(tl_close_down(0, zs)); -} - -TL_MAIN -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/test/api/t16.c b/test/api/t16.c deleted file mode 100644 index d7d03a0..0000000 --- a/test/api/t16.c +++ /dev/null @@ -1,96 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** \brief test special element set names zebra:: and friends */ - -#include "testlib.h" - -const char *myrec[] = { - "\n" - " My title\n" - "\n", - 0}; - -static void tst(int argc, char **argv) -{ - zint hits; - ZEBRA_RES res; - const char * zebra_xml_sysno - = "\n"; - - const char * zebra_xml_meta - = "\n"; - - const char * zebra_xml_index_title_p - = "\n" -" my title\n" -"\n"; - - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, myrec)); - - res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits); - YAZ_CHECK_EQ(res, ZEBRA_OK); - YAZ_CHECK_EQ(hits, 1); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, - "mismatch"), ZEBRA_FAIL); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs, - myrec[0]), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, - myrec[0]), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", - yaz_oid_recsyn_sutrs, - "2"), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", - yaz_oid_recsyn_xml, - zebra_xml_sysno), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml, - zebra_xml_meta), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p", - yaz_oid_recsyn_xml, - zebra_xml_index_title_p), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent", - yaz_oid_recsyn_xml, ""), ZEBRA_OK); - - YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent", - yaz_oid_recsyn_xml, ""), ZEBRA_OK); - - 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 - */ - diff --git a/test/api/t17.c b/test/api/t17.c deleted file mode 100644 index 1c1cc3c..0000000 --- a/test/api/t17.c +++ /dev/null @@ -1,141 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** \file - \brief tests ICU enabled maps -*/ -#include -#include "testlib.h" - -/* utf-8 sequences for some characters */ -#define char_ae "\xc3\xa6" -#define char_AE "\xc3\x86" - -#define char_oslash "\xc3\xb8" -#define char_Oslash "\xc3\x98" - -#define char_aring "\xc3\xa5" -#define char_Aring "\xc3\x85" - -#define char_comb_ring_above "\xcc\x8a" - -#define char_aring1 "a" char_comb_ring_above -#define char_Aring1 "A" char_comb_ring_above - -const char *myrec[] = { - "\nMy computer\n\n", - "\nMy x computer\n\n", - "\nMy computer x\n\n" , - "\n" char_ae "\n\n" , - "\nB" char_aring "d\n" - "זיהוי סדר הארועים בסיפור המרד הגדול מאת צביה בן-שלום 提示:直接点击数据库名称,将进入单库检索 Ngày xửa ngày xưa D.W. all wet\n\n" , - 0} ; - -static void tst(int argc, char **argv) -{ -#if YAZ_HAVE_ICU - ZebraService zs = tl_start_up("zebra17.cfg", argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, myrec)); - - /* simple term */ - YAZ_CHECK(tl_query(zh, "@attr 1=title notfound", 0)); - - YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3)); - - YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 5=1 comput", 3)); - - YAZ_CHECK(tl_query(zh, "@attr 1=title .computer.", 3)); - - YAZ_CHECK(tl_query(zh, "@attr 1=title x", 2)); - - YAZ_CHECK(tl_query(zh, "@attr 1=title my", 3)); - - YAZ_CHECK(tl_query(zh, "@attr 1=title mY", 3)); - - YAZ_CHECK(tl_query(zh, char_ae, 1)); - YAZ_CHECK(tl_query(zh, char_AE, 1)); - - YAZ_CHECK(tl_query(zh, "b" char_aring "d", 1)); - YAZ_CHECK(tl_query(zh, "B" char_Aring "D", 1)); - YAZ_CHECK(tl_query(zh, "b" char_aring1 "d", 1)); - YAZ_CHECK(tl_query(zh, "B" char_Aring1 "D", 1)); - - /* Abstract searches . Chinese mostly */ - YAZ_CHECK(tl_query(zh, "@attr 1=abstract בן", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract צביה", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract הגדול", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract בסיפור", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract בסיפ", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract 点", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract wet", 1)); - - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 בסיפ", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 סיפ", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 בסי", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 בס", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 ב", 1)); - - /* phrase search */ - YAZ_CHECK(tl_query(zh, "@attr 1=title {my computer}", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=1 {my computer}", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=title {computer x}", 1)); - - /* complete-subfield search */ - YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=2 {my computer}", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=2 {my}", 0)); - - /* always matches */ - YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {}", 5)); - YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 2=103 {}", 5)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 2=103 {}", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 2=103 {does not match}", 1)); - - /* scan */ - { /* word search */ - const char *ent[] = { char_ae, "B" char_aring "d", "computer", - "My", "x", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=title 0", 1, 10, 1, 5, 1, ent)); - } - - { /* word search */ - const char *ent[] = { "My", "x", 0 }; - YAZ_CHECK(tl_scan(zh, "@attr 1=title cp", 1, 10, 1, 2, 1, ent)); - } - - { /* phrase search */ - const char *ent[] = { char_ae, "B" char_aring "d", "My computer" }; - YAZ_CHECK(tl_scan(zh, "@attr 1=title @attr 6=2 0", 1, 3, 1, 3, 0, ent)); - } - - YAZ_CHECK(tl_close_down(zh, zs)); -#endif -} - -TL_MAIN - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/test/api/t17.idx b/test/api/t17.idx deleted file mode 100644 index 710003d..0000000 --- a/test/api/t17.idx +++ /dev/null @@ -1,30 +0,0 @@ -# Zebra indexes as referred to from the *.abs-files. -# - -# Traditional word index -# Used if completenss is 'incomplete field' (@attr 6=1) and -# structure is word/phrase/word-list/free-form-text/document-text -index w -completeness 0 -position 1 -alwaysmatches 1 -firstinfield 1 -# simplechain dummy -icuchain words-icu.xml -debug 1 - -# Phrase index -# Used if completeness is 'complete {sub}field' (@attr 6=2, @attr 6=1) -# and structure is word/phrase/word-list/free-form-text/document-text -index p -completeness 1 -icuchain phrases-icu.xml -# debug 1 - -# Sort register -sort s -completeness 1 -charmap string.chr - -# Staticrank (uncomment to enable) -#staticrank r diff --git a/test/api/t2.c b/test/api/t2.c deleted file mode 100644 index d55a782..0000000 --- a/test/api/t2.c +++ /dev/null @@ -1,53 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include "testlib.h" - -const char *myrec[] = { - "\n" - " My title\n" - "\n", - 0}; - -void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, myrec)); - YAZ_CHECK(tl_query(zh, "@attr 1=title my", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 my", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=title nope", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 nope", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 2=103 dummy", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=103 dummy", 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 - */ - diff --git a/test/api/t3.c b/test/api/t3.c deleted file mode 100644 index 6f5ef02..0000000 --- a/test/api/t3.c +++ /dev/null @@ -1,93 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/* Creates a few result sets */ - -#include "testlib.h" - -const char *myrec[] ={ - "\n" - " My title\n" - "\n", - 0}; - -static void tst(int argc, char **argv) -{ - int i; - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, myrec)); - - for (i = 0; i<4; i++) - { - char setname[20]; - char *setnamep = setname; - int status; - ODR odr_input = odr_createmem (ODR_DECODE); - ODR odr_output = odr_createmem (ODR_ENCODE); - YAZ_PQF_Parser parser = yaz_pqf_create(); - Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, - "@attr 1=4 my"); - zint hits; - if (zebra_begin_trans (zh, 1) != ZEBRA_OK) - { - fprintf(stderr, "zebra_begin_trans failed\n"); - exit(1); - } - if (zebra_begin_trans (zh, 0) != ZEBRA_OK) - { - fprintf(stderr, "zebra_begin_trans failed\n"); - exit(1); - } - - sprintf(setname, "s%d", i+1); - zebra_search_RPN (zh, odr_input, query, setname, &hits); - - if (zebra_end_trans (zh) != ZEBRA_OK) - { - fprintf(stderr, "zebra_end_trans failed\n"); - exit(1); - } - if (zebra_end_trans (zh) != ZEBRA_OK) - { - fprintf(stderr, "zebra_end_trans failed\n"); - exit(1); - } - yaz_pqf_destroy(parser); - zebra_deleteResultSet(zh, Z_DeleteRequest_list, - 1, &setnamep, &status); - odr_destroy(odr_input); - odr_destroy(odr_output); - } - zebra_commit(zh); - - 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 - */ - diff --git a/test/api/t4.c b/test/api/t4.c deleted file mode 100644 index de48f89..0000000 --- a/test/api/t4.c +++ /dev/null @@ -1,136 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/* t4 - insert a small pile of records, search and fetch them */ - -#include "testlib.h" - -const char *myrec[] = { - "\n" - " My title\n" - "\n", - 0}; - -#define NUMBER_TO_FETCH_MAX 1000 - -static void tst(int argc, char **argv) -{ - int i; - int number_to_be_inserted = 5; - int number_to_fetch = 5; - - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, myrec)); - - YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK); - - for (i = 0; i< number_to_be_inserted-1; i++) - { /* -1 since already inserted one in init_data */ - zebra_add_record(zh, myrec[0], strlen(myrec[0])); - } - YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); - - zebra_close(zh); - zebra_stop(zs); - - zs = tl_zebra_start(""); - zh = zebra_open(zs, 0); - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - zebra_set_resource(zh, "sortmax", "3"); /* make small sort boundary */ - - for (i = 0; i<2; i++) - { - ZEBRA_RES ret; - ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX]; - char setname[20]; - int j; - ODR odr_input = odr_createmem(ODR_DECODE); - ODR odr_output = odr_createmem(ODR_DECODE); - YAZ_PQF_Parser parser = yaz_pqf_create(); - Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my"); - zint hits; - - sprintf(setname, "s%d", i+1); - ret = zebra_search_RPN(zh, odr_input, query, setname, &hits); - if (ret != ZEBRA_OK) - { - int code = zebra_errCode(zh); - yaz_log(YLOG_WARN, "Unexpected error code=%d", code); - exit(1); - } - if (hits != number_to_be_inserted) - { - yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT - "(should be %d)", hits, number_to_be_inserted); - exit(1); - } - - yaz_pqf_destroy(parser); - - odr_destroy(odr_input); - - YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK); - - for (j = 0; j < number_to_fetch; j++) - retrievalRecord[j].position = j+1; - - ret = zebra_records_retrieve(zh, odr_output, setname, 0, - yaz_oid_recsyn_xml, number_to_fetch, - retrievalRecord); - if (ret != ZEBRA_OK) - { - int code = zebra_errCode(zh); - yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d", - code); - exit(1); - } - - for (j = 0; j < number_to_fetch; j++) - { - if (!retrievalRecord[j].buf) - { - yaz_log(YLOG_FATAL, "No record buf at position %d", j); - exit(1); - } - if (!retrievalRecord[j].len) - { - yaz_log(YLOG_FATAL, "No record len at position %d", j); - exit(1); - } - } - odr_destroy(odr_output); - - YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); - } - zebra_commit(zh); - 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 - */ - diff --git a/test/api/t5.c b/test/api/t5.c deleted file mode 100644 index 0379cb5..0000000 --- a/test/api/t5.c +++ /dev/null @@ -1,268 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** \file - \brief test various search attributes */ -#include -#include "testlib.h" - -const char *myrec[] = { - "\nMy title\n\n", - "\nMy x title\n\n", - "\nMy title x\n\n" , - 0} ; - -static void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, myrec)); - - /* simple term */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 notfound", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 title", 3)); - tl_fetch_compare(zh, 1, "zebra::facet::title:w", yaz_oid_recsyn_sutrs, - "term 3 3: my\n" - "term 3 3: title\n" - "term 2 2: x\n"); - - /* trunc right */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=1 titl", 3)); - - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=1 x", 2)); - tl_fetch_compare(zh, 1, "zebra::facet::title:w", yaz_oid_recsyn_sutrs, - "term 2 2: my\n" - "term 2 2: title\n" - "term 2 2: x\n"); - - /* trunc left */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 titl", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 le", 3)); - - /* trunc left&right */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 titl", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 le", 3)); - - /* trunc none */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 titl", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 le", 0)); - - /* trunc: process # in term */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 titl", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 #le", 3)); - - /* trunc: re-1 */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 titl", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 .*le", 3)); - - /* trunc: re-2 */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titl", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titlx", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titlxx", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 .*le", 3)); - - /* trunc: CCL #=. ?=.* (?[0-9] = n times .) */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 titl", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 tit#e", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?le", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?1le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?2le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?3le", 3)); - - /* trunc: * = .* ! = . and right truncate */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 titl", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 tit!e", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 *le", 3)); - - /* trunc: * = .* ! = . and do not truncate */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 titl", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 tit!e", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 le", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 *le", 3)); - - /* string relations, < */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 0", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 my", 0)); - - /* string relations, <= */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 my", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 mn", 0)); - - /* = */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=3 my", 3)); - - /* string relations, >= */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 x", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 tu", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 title", 3)); - - /* string relations, > */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 x", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 tu", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 title", 2)); - - /* always-matches relation */ - YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {ym}", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=103 {x my}", 3)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=1 @attr 2=103 {x my}", 0, 114)); - - /* and searches */ - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 x", 0)); - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 notfound", 0)); - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 notfound", 0)); - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 x", 2)); - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 my", 2)); - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 x", 2)); - YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 my", 3)); - - /* or searches */ - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 x", 2)); - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 notfound", 2)); - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 notfound", 0)); - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 x", 2)); - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 my", 3)); - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 x", 3)); - YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 my", 3)); - - /* not searches */ - /* bug 619 */ - YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 x", 0)); - YAZ_CHECK(tl_query(zh, "@not @attr 1=4 x @attr 1=4 x", 0)); - YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 x", 1)); - YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 notfound", 3)); - YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 notfound", 0)); - - /* phrase searches */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 my", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=1 {my x}", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 {x my}", 0)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x title}", 1)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 {my title}", 2)); - - /* and-list searches */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {x my}", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my x}", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my my}", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {e x}", 0)); - - /* or-list searches */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {x my}", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my x}", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my my}", 3)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {e x}", 2)); - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=106 {e x}", 2)); - - /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 2 k 2 my x", 2)); - - /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 2 k 2 x my", 0)); - - /* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 0 2 k 2 x my", 2)); - - /* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 3 k 2 my x", 1)); - - /* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 1 2 1 3 k 2 my x", 1)); - - /* Non-indexed numeric use, but specified in bib1.att (bug #1142) */ - YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 @attr 14=0 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 @attr 14=1 x", 0, 0)); - /* Non-indexed numeric use and unspecified in bib1.att */ - YAZ_CHECK(tl_query_x(zh, "@attr 1=999 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 14=1 x", 0, 114)); - /* Non-indexed string use attribute */ - YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf @attr 14=0 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf @attr 14=1 x", 0, 0)); - - /* provoke unsupported use attribute */ - YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=1 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=6 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=105 x", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=109 123", 0, 114)); - YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.840.10003.3.1 @attr 1=999 x", - 0, 114)); - /* provoke unsupported attribute set */ - YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=1 x", 0, 121)); - YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=6 x", 0, - 121)); - YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=105 x", 0, - 121)); - YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=109 123", - 0, 121)); - - /* provoke unsupported relation */ - YAZ_CHECK(tl_query_x(zh, "@attr 1=4 @attr 2=6 x", 0, 117)); - YAZ_CHECK(tl_query_x(zh, "@attr 1=1016 @attr 2=6 @attr 4=109 x", 0, 114)); - - /* position , phrase searches */ - YAZ_CHECK(tl_query(zh, "@attr 3=1 title", 0)); - YAZ_CHECK(tl_query(zh, "@attr 3=1 my", 3)); - - YAZ_CHECK(tl_query(zh, "@attr 3=1 {my title}", 2)); - YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {my title}", 2)); - - YAZ_CHECK(tl_query(zh, "@attr 3=1 {title my}", 0)); - YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {title my}", 0)); - - YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {title my}", 0)); - - /* position , or-list */ - YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title my}", 3)); - YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title x}", 0)); - - /* position, and-list */ - YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title my}", 0)); - YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title x}", 0)); - YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 my", 3)); - - 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 - */ - diff --git a/test/api/t6.c b/test/api/t6.c deleted file mode 100644 index 4d509eb..0000000 --- a/test/api/t6.c +++ /dev/null @@ -1,96 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** t6.c Insert a number of randomly generated words */ - -#include "testlib.h" - -static void tst(int argc, char **argv) -{ - int i; - ZebraService zs = tl_start_up("zebra6.cfg", argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - srand(17); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - zebra_init(zh); - zebra_close(zh); - - for (i = 0; i<10; i++) - { - int l; - - zh = zebra_open (zs, 0); - YAZ_CHECK(zh); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - - YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK); - - for (l = 0; l<100; l++) - { - char rec_buf[5120]; - int j; - *rec_buf = '\0'; - strcat(rec_buf, ""); - if (i == 0) - { - sprintf(rec_buf + strlen(rec_buf), "aaa"); - } - else - { - j = (rand() & 15) + 1; - while (--j >= 0) - { - int c = 65 + (rand() & 15); - sprintf(rec_buf + strlen(rec_buf), "%c", c); - } - } - strcat(rec_buf, ""); - j = rand() & 31; - sprintf(rec_buf + strlen(rec_buf), "%d", j); - strcat(rec_buf, ""); - zebra_add_record (zh, rec_buf, strlen(rec_buf)); - } - YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); - zebra_close(zh); - } - zh = zebra_open(zs, 0); - YAZ_CHECK(zh); - - YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); - - zebra_set_resource(zh, "trunclimit", "2"); - - /* check massive truncation: bug #281 */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 z", -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 - */ - diff --git a/test/api/t7.c b/test/api/t7.c deleted file mode 100644 index ab8557f..0000000 --- a/test/api/t7.c +++ /dev/null @@ -1,88 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** t7.c sorting */ - -#include "testlib.h" -#include - -const char *recs[] = { - "\n" - " My title\n" - "\n", - 0}; - -static void tst(int argc, char **argv) -{ - const char *setname1 = "set1"; - const char *setname2 = "set2"; - const char *setname3 = "set3"; - int status; - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open (zs, 0); - ODR odr_input = odr_createmem (ODR_DECODE); - ODR odr_output = odr_createmem (ODR_ENCODE); - YAZ_PQF_Parser parser = yaz_pqf_create(); - Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my"); - Z_SortKeySpecList *spec = yaz_sort_spec (odr_output, "1=4 \n" - " My title\n" - " test record with single coordset, negatives\n" - " \n" - " -120 \n" - " -102 \n" - " 49 \n" - " 31 \n" - " " - "\n", - - "\n" - " Another title\n" - " second test with two coord sets\n" - " \n" - " -120 \n" - " -102 \n" - " 49 \n" - " 31 \n" - " " - " \n" - " -125 \n" - " -108 \n" - " 41 \n" - " 25 \n" - " " - "\n", - 0}; - - -static void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up("zebra8.cfg", argc, argv); - ZebraHandle zh = zebra_open (zs, 0); - - YAZ_CHECK(tl_init_data(zh, recs)); - - /* couple of simple queries just to see that we have indexed the stuff */ - YAZ_CHECK(tl_query(zh, "@attr 1=4 title", 2)); - - /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/ - /* 4=109: numeric string */ - /* 2=3: equal 2=1: less, 2=4: greater or equal 2=5 greater */ - - /* N>=25, search attributes work */ - YAZ_CHECK(tl_query(zh, "@attr 2=4 @attr gils 1=2040 @attr 4=109 25", 2)); - - /* N>49, search attributes work */ - YAZ_CHECK(tl_query(zh, "@attr 2=5 @attr gils 1=2040 @attr 4=109 49", 0)); - - /* N>=49, search attributes work */ - YAZ_CHECK(tl_query(zh, "@attr 2=4 @attr gils 1=2040 @attr 4=109 49", 2)); - - /* N>48, search attributes work */ - YAZ_CHECK(tl_query(zh, "@attr 2=5 @attr gils 1=2040 @attr 4=109 48", 2)); - - /* N<48, search attributes work */ - YAZ_CHECK(tl_query(zh, "@attr 2=1 @attr gils 1=2040 @attr 4=109 48", 1)); - - /* N<=48, search attributes work */ - YAZ_CHECK(tl_query(zh, "@attr 2=2 @attr gils 1=2040 @attr 4=109 48", 1)); - - /* N=41, get rec1 only */ - YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 41", 1)); - - /* N=49, get both records */ - YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 49", 2)); - - /* W=-120 get both records */ - YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120", 2)); - - /* W<-122 get only rec1 */ - YAZ_CHECK(tl_query(zh, "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ", 1)); - - /* N=41 and N=49 get only rec2 */ - YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ", 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 - */ - diff --git a/test/api/t9.c b/test/api/t9.c deleted file mode 100644 index fa3a1e3..0000000 --- a/test/api/t9.c +++ /dev/null @@ -1,50 +0,0 @@ -/* 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 -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -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 this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** t9.c - test rank-1 */ - -#include "testlib.h" - -#include "rankingrecords.h" - -static void tst(int argc, char **argv) -{ - ZebraService zs = tl_start_up(0, argc, argv); - ZebraHandle zh = zebra_open(zs, 0); - - YAZ_CHECK(tl_init_data(zh, recs)); - - YAZ_CHECK(tl_ranking_query(zh, "@attr 1=4 @attr 2=102 the", - 3, "first title", 936 )); - - YAZ_CHECK(tl_ranking_query(zh, "@attr 1=62 @attr 2=102 foo", - 3, "second title", 850 )); - - 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 - */ - diff --git a/test/api/test_create_databases.c b/test/api/test_create_databases.c new file mode 100644 index 0000000..4250aa1 --- /dev/null +++ b/test/api/test_create_databases.c @@ -0,0 +1,86 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** Create many databases */ + +#include "testlib.h" + +static void tst(int argc, char **argv) +{ + int i; + int no_db = 140; + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + YAZ_CHECK(zebra_init(zh) == ZEBRA_OK); + zebra_close(zh); + + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + + YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK); + + for (i = 0; ititle %d\n", i); + zebra_add_record (zh, rec_buf, strlen(rec_buf)); + + } + YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); + + zebra_close(zh); + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + for (i = 0; i<=no_db; i++) + { + char dbstr[20]; + char querystr[50]; + sprintf(dbstr, "%d", i); + YAZ_CHECK(zebra_select_database(zh, dbstr) == ZEBRA_OK); + + sprintf(querystr, "@attr 1=4 %d", i); + if (i == no_db) + { + YAZ_CHECK(tl_query_x(zh, querystr, 0, 109)); + } + else + { + YAZ_CHECK(tl_query(zh, querystr, 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 + */ + diff --git a/test/api/test_icu_indexing.c b/test/api/test_icu_indexing.c new file mode 100644 index 0000000..e2e73b6 --- /dev/null +++ b/test/api/test_icu_indexing.c @@ -0,0 +1,141 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** \file + \brief tests ICU enabled maps +*/ +#include +#include "testlib.h" + +/* utf-8 sequences for some characters */ +#define char_ae "\xc3\xa6" +#define char_AE "\xc3\x86" + +#define char_oslash "\xc3\xb8" +#define char_Oslash "\xc3\x98" + +#define char_aring "\xc3\xa5" +#define char_Aring "\xc3\x85" + +#define char_comb_ring_above "\xcc\x8a" + +#define char_aring1 "a" char_comb_ring_above +#define char_Aring1 "A" char_comb_ring_above + +const char *myrec[] = { + "\nMy computer\n\n", + "\nMy x computer\n\n", + "\nMy computer x\n\n" , + "\n" char_ae "\n\n" , + "\nB" char_aring "d\n" + "זיהוי סדר הארועים בסיפור המרד הגדול מאת צביה בן-שלום 提示:直接点击数据库名称,将进入单库检索 Ngày xửa ngày xưa D.W. all wet\n\n" , + 0} ; + +static void tst(int argc, char **argv) +{ +#if YAZ_HAVE_ICU + ZebraService zs = tl_start_up("test_icu_indexing.cfg", argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(tl_init_data(zh, myrec)); + + /* simple term */ + YAZ_CHECK(tl_query(zh, "@attr 1=title notfound", 0)); + + YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3)); + + YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 5=1 comput", 3)); + + YAZ_CHECK(tl_query(zh, "@attr 1=title .computer.", 3)); + + YAZ_CHECK(tl_query(zh, "@attr 1=title x", 2)); + + YAZ_CHECK(tl_query(zh, "@attr 1=title my", 3)); + + YAZ_CHECK(tl_query(zh, "@attr 1=title mY", 3)); + + YAZ_CHECK(tl_query(zh, char_ae, 1)); + YAZ_CHECK(tl_query(zh, char_AE, 1)); + + YAZ_CHECK(tl_query(zh, "b" char_aring "d", 1)); + YAZ_CHECK(tl_query(zh, "B" char_Aring "D", 1)); + YAZ_CHECK(tl_query(zh, "b" char_aring1 "d", 1)); + YAZ_CHECK(tl_query(zh, "B" char_Aring1 "D", 1)); + + /* Abstract searches . Chinese mostly */ + YAZ_CHECK(tl_query(zh, "@attr 1=abstract בן", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract צביה", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract הגדול", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract בסיפור", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract בסיפ", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract 点", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract wet", 1)); + + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 בסיפ", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 סיפ", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 בסי", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 בס", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 ב", 1)); + + /* phrase search */ + YAZ_CHECK(tl_query(zh, "@attr 1=title {my computer}", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=1 {my computer}", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=title {computer x}", 1)); + + /* complete-subfield search */ + YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=2 {my computer}", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=2 {my}", 0)); + + /* always matches */ + YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {}", 5)); + YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 2=103 {}", 5)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 2=103 {}", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 2=103 {does not match}", 1)); + + /* scan */ + { /* word search */ + const char *ent[] = { char_ae, "B" char_aring "d", "computer", + "My", "x", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=title 0", 1, 10, 1, 5, 1, ent)); + } + + { /* word search */ + const char *ent[] = { "My", "x", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=title cp", 1, 10, 1, 2, 1, ent)); + } + + { /* phrase search */ + const char *ent[] = { char_ae, "B" char_aring "d", "My computer" }; + YAZ_CHECK(tl_scan(zh, "@attr 1=title @attr 6=2 0", 1, 3, 1, 3, 0, ent)); + } + + YAZ_CHECK(tl_close_down(zh, zs)); +#endif +} + +TL_MAIN + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/test/api/test_icu_indexing.cfg b/test/api/test_icu_indexing.cfg new file mode 100644 index 0000000..5279737 --- /dev/null +++ b/test/api/test_icu_indexing.cfg @@ -0,0 +1,14 @@ +profilepath: ${srcdir:-.}:${srcdir:-.}/../../tab +modulePath: ../../index/.libs + +attset: bib1.att +attset: explain.att + +recordType: grs.xml + +index: test_icu_indexing.idx + +isam: b + +encoding: utf-8 + diff --git a/test/api/test_icu_indexing.idx b/test/api/test_icu_indexing.idx new file mode 100644 index 0000000..710003d --- /dev/null +++ b/test/api/test_icu_indexing.idx @@ -0,0 +1,30 @@ +# Zebra indexes as referred to from the *.abs-files. +# + +# Traditional word index +# Used if completenss is 'incomplete field' (@attr 6=1) and +# structure is word/phrase/word-list/free-form-text/document-text +index w +completeness 0 +position 1 +alwaysmatches 1 +firstinfield 1 +# simplechain dummy +icuchain words-icu.xml +debug 1 + +# Phrase index +# Used if completeness is 'complete {sub}field' (@attr 6=2, @attr 6=1) +# and structure is word/phrase/word-list/free-form-text/document-text +index p +completeness 1 +icuchain phrases-icu.xml +# debug 1 + +# Sort register +sort s +completeness 1 +charmap string.chr + +# Staticrank (uncomment to enable) +#staticrank r diff --git a/test/api/test_insert_fetch.c b/test/api/test_insert_fetch.c new file mode 100644 index 0000000..57a0807 --- /dev/null +++ b/test/api/test_insert_fetch.c @@ -0,0 +1,136 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* insert a small pile of records, search and fetch them */ + +#include "testlib.h" + +const char *myrec[] = { + "\n" + " My title\n" + "\n", + 0}; + +#define NUMBER_TO_FETCH_MAX 1000 + +static void tst(int argc, char **argv) +{ + int i; + int number_to_be_inserted = 5; + int number_to_fetch = 5; + + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(tl_init_data(zh, myrec)); + + YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK); + + for (i = 0; i< number_to_be_inserted-1; i++) + { /* -1 since already inserted one in init_data */ + zebra_add_record(zh, myrec[0], strlen(myrec[0])); + } + YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); + + zebra_close(zh); + zebra_stop(zs); + + zs = tl_zebra_start(""); + zh = zebra_open(zs, 0); + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + zebra_set_resource(zh, "sortmax", "3"); /* make small sort boundary */ + + for (i = 0; i<2; i++) + { + ZEBRA_RES ret; + ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX]; + char setname[20]; + int j; + ODR odr_input = odr_createmem(ODR_DECODE); + ODR odr_output = odr_createmem(ODR_DECODE); + YAZ_PQF_Parser parser = yaz_pqf_create(); + Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my"); + zint hits; + + sprintf(setname, "s%d", i+1); + ret = zebra_search_RPN(zh, odr_input, query, setname, &hits); + if (ret != ZEBRA_OK) + { + int code = zebra_errCode(zh); + yaz_log(YLOG_WARN, "Unexpected error code=%d", code); + exit(1); + } + if (hits != number_to_be_inserted) + { + yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT + "(should be %d)", hits, number_to_be_inserted); + exit(1); + } + + yaz_pqf_destroy(parser); + + odr_destroy(odr_input); + + YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK); + + for (j = 0; j < number_to_fetch; j++) + retrievalRecord[j].position = j+1; + + ret = zebra_records_retrieve(zh, odr_output, setname, 0, + yaz_oid_recsyn_xml, number_to_fetch, + retrievalRecord); + if (ret != ZEBRA_OK) + { + int code = zebra_errCode(zh); + yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d", + code); + exit(1); + } + + for (j = 0; j < number_to_fetch; j++) + { + if (!retrievalRecord[j].buf) + { + yaz_log(YLOG_FATAL, "No record buf at position %d", j); + exit(1); + } + if (!retrievalRecord[j].len) + { + yaz_log(YLOG_FATAL, "No record len at position %d", j); + exit(1); + } + } + odr_destroy(odr_output); + + YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); + } + zebra_commit(zh); + 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 + */ + diff --git a/test/api/test_private_attset.c b/test/api/test_private_attset.c new file mode 100644 index 0000000..079b3e1 --- /dev/null +++ b/test/api/test_private_attset.c @@ -0,0 +1,70 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "testlib.h" + +const char *myrec[] ={ + "\n" + " My title\n" + "\n", + 0}; + +static void tst(int argc, char **argv) +{ + ZebraService zs = tl_start_up("test_private_attset.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 + */ + diff --git a/test/api/test_private_attset.cfg b/test/api/test_private_attset.cfg new file mode 100644 index 0000000..d09667c --- /dev/null +++ b/test/api/test_private_attset.cfg @@ -0,0 +1,8 @@ +profilepath: ${srcdir:-.}:${srcdir:-.}/../../tab + +attset: private_attset.att + +recordType: grs.sgml + + + diff --git a/test/api/test_rank.c b/test/api/test_rank.c new file mode 100644 index 0000000..a67c54f --- /dev/null +++ b/test/api/test_rank.c @@ -0,0 +1,76 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "testlib.h" + +const char *recs[] = { + "\n" + " The first title\n" + " \n" + " The first common word is the: the the the \n" + " The second common word is word \n" + " but all have the foo bar \n" + " \n" + "\n", + + "\n" + " The second title\n" + " \n" + " The first common word is the: the \n" + " The second common word is foo: foo foo \n" + " but all have the foo bar \n" + " \n" + "\n", + + "\n" + " The third title\n" + " \n" + " The first common word is the: the \n" + " The third common word is bar: bar \n" + " but all have the foo bar \n" + " \n" + "\n", + + 0 }; + +static void tst(int argc, char **argv) +{ + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(tl_init_data(zh, recs)); + + YAZ_CHECK(tl_ranking_query(zh, "@attr 1=4 @attr 2=102 the", + 3, "first title", 936 )); + + YAZ_CHECK(tl_ranking_query(zh, "@attr 1=62 @attr 2=102 foo", + 3, "second title", 850 )); + + 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 + */ + diff --git a/test/api/test_resources.c b/test/api/test_resources.c new file mode 100644 index 0000000..47e38ef --- /dev/null +++ b/test/api/test_resources.c @@ -0,0 +1,123 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** test resources */ +#include +#include +#include "testlib.h" +#include + +static void tst_res(void) +{ + Res default_res; /* default resources */ + Res temp_res; /* temporary resources */ + ZebraService zs; + ZebraHandle zh; + const char *val; + int i; + + default_res = res_open(0, 0); /* completely empty */ + YAZ_CHECK(default_res); + + res_set(default_res, "name1", "value1"); + + temp_res = res_open(0, 0); /* completely empty */ + YAZ_CHECK(temp_res); + + zs = zebra_start_res(0, default_res, temp_res); + YAZ_CHECK(zs); + + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + + /* run this a few times so we can see leaks easier */ + for (i = 0; i<10; i++) + { + /* we should find the name1 from default_res */ + val = zebra_get_resource(zh, "name1", 0); + YAZ_CHECK(val && !strcmp(val, "value1")); + + /* make local override */ + res_set(temp_res, "name1", "value2"); + res_set(temp_res, "name4", "value4"); + + /* we should find the name1 from temp_res */ + val = zebra_get_resource(zh, "name1", 0); + YAZ_CHECK(val && !strcmp(val, "value2")); + + val = zebra_get_resource(zh, "name4", 0); + YAZ_CHECK(val && !strcmp(val, "value4")); + + res_clear(temp_res); + } + zebra_close(zh); + zebra_stop(zs); + + res_close(temp_res); + res_close(default_res); +} + +static void tst_no_config(void) +{ + static char *xml_buf = "myx"; + ZebraService zs; + ZebraHandle zh; + zint sysno = 0; + + zs = zebra_start_res(0, 0, 0); + YAZ_CHECK(zs); + + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + + YAZ_CHECK_EQ(zebra_select_database(zh, "Default"), ZEBRA_OK); + + YAZ_CHECK_EQ(zebra_init(zh), ZEBRA_OK); + + zebra_set_resource(zh, "profilePath", "${srcdir:-.}/../../tab"); + + YAZ_CHECK_EQ(zebra_update_record(zh /* handle */, + action_insert, + "grs.sgml" /* record type */, + &sysno, 0 /* match */, + 0 /* fname */, + xml_buf, strlen(xml_buf)), + ZEBRA_OK); + + zebra_close(zh); + zebra_stop(zs); +} + +static void tst(int argc, char **argv) +{ + tst_res(); + tst_no_config(); +} + +TL_MAIN +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/test/api/test_result_sets.c b/test/api/test_result_sets.c new file mode 100644 index 0000000..6f5ef02 --- /dev/null +++ b/test/api/test_result_sets.c @@ -0,0 +1,93 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* Creates a few result sets */ + +#include "testlib.h" + +const char *myrec[] ={ + "\n" + " My title\n" + "\n", + 0}; + +static void tst(int argc, char **argv) +{ + int i; + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(tl_init_data(zh, myrec)); + + for (i = 0; i<4; i++) + { + char setname[20]; + char *setnamep = setname; + int status; + ODR odr_input = odr_createmem (ODR_DECODE); + ODR odr_output = odr_createmem (ODR_ENCODE); + YAZ_PQF_Parser parser = yaz_pqf_create(); + Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, + "@attr 1=4 my"); + zint hits; + if (zebra_begin_trans (zh, 1) != ZEBRA_OK) + { + fprintf(stderr, "zebra_begin_trans failed\n"); + exit(1); + } + if (zebra_begin_trans (zh, 0) != ZEBRA_OK) + { + fprintf(stderr, "zebra_begin_trans failed\n"); + exit(1); + } + + sprintf(setname, "s%d", i+1); + zebra_search_RPN (zh, odr_input, query, setname, &hits); + + if (zebra_end_trans (zh) != ZEBRA_OK) + { + fprintf(stderr, "zebra_end_trans failed\n"); + exit(1); + } + if (zebra_end_trans (zh) != ZEBRA_OK) + { + fprintf(stderr, "zebra_end_trans failed\n"); + exit(1); + } + yaz_pqf_destroy(parser); + zebra_deleteResultSet(zh, Z_DeleteRequest_list, + 1, &setnamep, &status); + odr_destroy(odr_input); + odr_destroy(odr_output); + } + zebra_commit(zh); + + 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 + */ + diff --git a/test/api/test_scan.c b/test/api/test_scan.c new file mode 100644 index 0000000..f6038dc --- /dev/null +++ b/test/api/test_scan.c @@ -0,0 +1,171 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** testing of scan */ +#include "testlib.h" + +const char *myrec[] = { + "\na b\n\n", + "\nc d\n\n", + "\ne f\n\n" , + 0} ; + +static void tst(int argc, char **argv) +{ + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(zh); + + YAZ_CHECK(tl_init_data(zh, myrec)); + + /* + int tl_scan + ( + ZebraHandle zh, const char *query, + int pos, int num, + int exp_pos, int exp_num, int exp_partial, + const char **exp_entries + ) + */ + + + { + /* bad string use attrite, bug #647 */ + YAZ_CHECK(tl_scan(zh, "@attr 1=bad 0", 1, 1, 1, 1, 0, 0)); + } + + { + /* bad numeric use attributes, bug #647 */ + YAZ_CHECK(tl_scan(zh, "@attr 1=1234 0", 1, 1, 1, 1, 0, 0)); + } + + { + /* scan before. nothing must be returned */ + const char *ent[] = { "a", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 1, 1, 1, 1, 0, ent)); + } + + { + /* scan after. nothing must be returned */ + const char *ent[] = { 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 m", 1, 1, 1, 0, 1, ent)); + } + + { + const char *ent[] = { "a", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", 1, 1, 1, 1, 0, ent)); + } + + { + const char *ent[] = { "b", "c", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent)); + } + + { + const char *ent[] = { "b", "c", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent)); + } + + { + const char *ent[] = { "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 e", 1, 3, 1, 2, 1, ent)); + } + + { + const char *ent[] = { "c", "d", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -1, 2, -1, 2, 0, ent)); + } + + { + const char *ent[] = { "d", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 1, -2, 1, 0, ent)); + } + + { + const char *ent[] = { "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -4, 1, -4, 1, 0, ent)); + } + + { + const char *ent[] = { "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -5, 1, -5, 0, 1, ent)); + } + + { + const char *ent[] = { "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 3, -2, 3, 0, ent)); + } + + { + const char *ent[] = { "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 4, -2, 3, 1, ent)); + } + + { + const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 2, 100, 1, 6, 1, ent)); + } + + { + const char *ent[] = { "b", "c", "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 0, 100, 0, 5, 1, ent)); + } + + { + const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 10, 100, 1, 6, 1, ent)); + } + + { + const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 22, 10, 1, 0, 1, ent)); + } + + { + const char *ent[] = { 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 z", -22, 10, -22, 0, 1, ent)); + } + + { + const char *ent[] = { "c", "d", 0 }; + + YAZ_CHECK(tl_query(zh, "@attr 1=4 c", 1)); + + /* must fail, because x is not a result set */ + YAZ_CHECK(tl_scan(zh, "@attr 8=x @attr 1=4 a", 1, 3, 0, 0, 0, 0)); + + /* bug 1114 */ + YAZ_CHECK(tl_scan(zh, "@attr 8=rsetname @attr 1=4 0", + 1, 20, 1, 2, 1, ent)); + + } + 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 + */ + diff --git a/test/api/test_search.c b/test/api/test_search.c new file mode 100644 index 0000000..54fe529 --- /dev/null +++ b/test/api/test_search.c @@ -0,0 +1,329 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** \file + \brief test various search attributes */ +#include +#include "testlib.h" + +const char *myrec[] = { + "\nMy title\n" + " test record with single coordset, negatives\n" + " \n" + " -120 \n" + " -102 \n" + " 49 \n" + " 31 \n" + " " + "\n", + "\nMy x title\n" + " second test with two coord sets\n" + " \n" + " -120 \n" + " -102 \n" + " 49 \n" + " 31 \n" + " " + " \n" + " -125 \n" + " -108 \n" + " 41 \n" + " 25 \n" + " " + "\n", + "\nMy title x\n\n" , + 0} ; + +static void tst(int argc, char **argv) +{ + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(tl_init_data(zh, myrec)); + + /* simple term */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 notfound", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 title", 3)); + tl_fetch_compare(zh, 1, "zebra::facet::title:w", yaz_oid_recsyn_sutrs, + "term 3 3: my\n" + "term 3 3: title\n" + "term 2 2: x\n"); + + /* trunc right */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=1 titl", 3)); + + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=1 x", 2)); + tl_fetch_compare(zh, 1, "zebra::facet::title:w", yaz_oid_recsyn_sutrs, + "term 2 2: my\n" + "term 2 2: title\n" + "term 2 2: x\n"); + + /* trunc left */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 titl", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 le", 3)); + + /* trunc left&right */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 titl", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 le", 3)); + + /* trunc none */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 titl", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 le", 0)); + + /* trunc: process # in term */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 titl", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 #le", 3)); + + /* trunc: re-1 */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 titl", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 .*le", 3)); + + /* trunc: re-2 */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titl", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titlx", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titlxx", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 .*le", 3)); + + /* trunc: CCL #=. ?=.* (?[0-9] = n times .) */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 titl", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 tit#e", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?le", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?1le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?2le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?3le", 3)); + + /* trunc: * = .* ! = . and right truncate */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 titl", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 tit!e", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 *le", 3)); + + /* trunc: * = .* ! = . and do not truncate */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 titl", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 tit!e", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 le", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 *le", 3)); + + /* string relations, < */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 0", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 my", 0)); + + /* string relations, <= */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 my", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 mn", 0)); + + /* = */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=3 my", 3)); + + /* string relations, >= */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 x", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 tu", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 title", 3)); + + /* string relations, > */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 x", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 tu", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 title", 2)); + + /* always-matches relation */ + YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {ym}", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=103 {x my}", 3)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=1 @attr 2=103 {x my}", 0, 114)); + + /* and searches */ + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 x", 0)); + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 notfound", 0)); + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 notfound", 0)); + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 x", 2)); + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 my", 2)); + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 x", 2)); + YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 my", 3)); + + /* or searches */ + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 x", 2)); + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 notfound", 2)); + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 notfound", 0)); + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 x", 2)); + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 my", 3)); + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 x", 3)); + YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 my", 3)); + + /* not searches */ + /* bug 619 */ + YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 x", 0)); + YAZ_CHECK(tl_query(zh, "@not @attr 1=4 x @attr 1=4 x", 0)); + YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 x", 1)); + YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 notfound", 3)); + YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 notfound", 0)); + + /* phrase searches */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 my", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=1 {my x}", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 {x my}", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x title}", 1)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 {my title}", 2)); + + /* and-list searches */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {x my}", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my x}", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my my}", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {e x}", 0)); + + /* or-list searches */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {x my}", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my x}", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my my}", 3)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {e x}", 2)); + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=106 {e x}", 2)); + + /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 2 k 2 my x", 2)); + + /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 2 k 2 x my", 0)); + + /* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 0 2 k 2 x my", 2)); + + /* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 3 k 2 my x", 1)); + + /* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 1 2 1 3 k 2 my x", 1)); + + /* Non-indexed numeric use, but specified in bib1.att (bug #1142) */ + YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 @attr 14=0 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 @attr 14=1 x", 0, 0)); + /* Non-indexed numeric use and unspecified in bib1.att */ + YAZ_CHECK(tl_query_x(zh, "@attr 1=999 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 14=1 x", 0, 114)); + /* Non-indexed string use attribute */ + YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf @attr 14=0 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf @attr 14=1 x", 0, 0)); + + /* provoke unsupported use attribute */ + YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=1 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=6 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=105 x", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=109 123", 0, 114)); + YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.840.10003.3.1 @attr 1=999 x", + 0, 114)); + /* provoke unsupported attribute set */ + YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=1 x", 0, 121)); + YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=6 x", 0, + 121)); + YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=105 x", 0, + 121)); + YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=109 123", + 0, 121)); + + /* provoke unsupported relation */ + YAZ_CHECK(tl_query_x(zh, "@attr 1=4 @attr 2=6 x", 0, 117)); + YAZ_CHECK(tl_query_x(zh, "@attr 1=1016 @attr 2=6 @attr 4=109 x", 0, 114)); + + /* position , phrase searches */ + YAZ_CHECK(tl_query(zh, "@attr 3=1 title", 0)); + YAZ_CHECK(tl_query(zh, "@attr 3=1 my", 3)); + + YAZ_CHECK(tl_query(zh, "@attr 3=1 {my title}", 2)); + YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {my title}", 2)); + + YAZ_CHECK(tl_query(zh, "@attr 3=1 {title my}", 0)); + YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {title my}", 0)); + + YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {title my}", 0)); + + /* position , or-list */ + YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title my}", 3)); + YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title x}", 0)); + + /* position, and-list */ + YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title my}", 0)); + YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title x}", 0)); + YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 my", 3)); + + + /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/ + /* 4=109: numeric string */ + /* 2=3: equal 2=1: less, 2=4: greater or equal 2=5 greater */ + + /* N>=25, search attributes work */ + YAZ_CHECK(tl_query(zh, "@attr 2=4 @attr gils 1=2040 @attr 4=109 25", 2)); + + /* N>49, search attributes work */ + YAZ_CHECK(tl_query(zh, "@attr 2=5 @attr gils 1=2040 @attr 4=109 49", 0)); + + /* N>=49, search attributes work */ + YAZ_CHECK(tl_query(zh, "@attr 2=4 @attr gils 1=2040 @attr 4=109 49", 2)); + + /* N>48, search attributes work */ + YAZ_CHECK(tl_query(zh, "@attr 2=5 @attr gils 1=2040 @attr 4=109 48", 2)); + + /* N<48, search attributes work */ + YAZ_CHECK(tl_query(zh, "@attr 2=1 @attr gils 1=2040 @attr 4=109 48", 1)); + + /* N<=48, search attributes work */ + YAZ_CHECK(tl_query(zh, "@attr 2=2 @attr gils 1=2040 @attr 4=109 48", 1)); + + /* N=41, get rec1 only */ + YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 41", 1)); + + /* N=49, get both records */ + YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 49", 2)); + + /* W=-120 get both records */ + YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120", 2)); + + /* W<-122 get only rec1 */ + YAZ_CHECK(tl_query(zh, "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ", 1)); + + /* N=41 and N=49 get only rec2 */ + YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ", 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 + */ + diff --git a/test/api/test_sort_set.c b/test/api/test_sort_set.c new file mode 100644 index 0000000..3a9cb27 --- /dev/null +++ b/test/api/test_sort_set.c @@ -0,0 +1,86 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "testlib.h" +#include + +const char *recs[] = { + "\n" + " My title\n" + "\n", + 0}; + +static void tst(int argc, char **argv) +{ + const char *setname1 = "set1"; + const char *setname2 = "set2"; + const char *setname3 = "set3"; + int status; + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs, 0); + ODR odr_input = odr_createmem (ODR_DECODE); + ODR odr_output = odr_createmem (ODR_ENCODE); + YAZ_PQF_Parser parser = yaz_pqf_create(); + Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my"); + Z_SortKeySpecList *spec = yaz_sort_spec (odr_output, "1=4 \n" + " My title\n" + "\n", + 0}; + +static void tst(int argc, char **argv) +{ + zint hits; + ZEBRA_RES res; + const char * zebra_xml_sysno + = "\n"; + + const char * zebra_xml_meta + = "\n"; + + const char * zebra_xml_index_title_p + = "\n" +" my title\n" +"\n"; + + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(tl_init_data(zh, myrec)); + + res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits); + YAZ_CHECK_EQ(res, ZEBRA_OK); + YAZ_CHECK_EQ(hits, 1); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, + "mismatch"), ZEBRA_FAIL); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs, + myrec[0]), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, + myrec[0]), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", + yaz_oid_recsyn_sutrs, + "2"), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", + yaz_oid_recsyn_xml, + zebra_xml_sysno), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml, + zebra_xml_meta), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p", + yaz_oid_recsyn_xml, + zebra_xml_index_title_p), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent", + yaz_oid_recsyn_xml, ""), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent", + yaz_oid_recsyn_xml, ""), ZEBRA_OK); + + 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 + */ + diff --git a/test/api/test_start_stop.c b/test/api/test_start_stop.c new file mode 100644 index 0000000..0cffb0c --- /dev/null +++ b/test/api/test_start_stop.c @@ -0,0 +1,51 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include +#include "testlib.h" + +static void tst(int argc, char **argv) +{ + YAZ_CHECK(!zebra_start("xxxxpoiasdfasfd.cfg")); /* should fail */ + + { + ZebraService zs = tl_start_up(0, argc, argv); + ZebraHandle zh = 0; + YAZ_CHECK(zs); + + if (zs) + { + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + } + + 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 + */ + diff --git a/test/api/test_trunc.c b/test/api/test_trunc.c new file mode 100644 index 0000000..6ae5c7a --- /dev/null +++ b/test/api/test_trunc.c @@ -0,0 +1,96 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* Insert a number of randomly generated words and truncate */ + +#include "testlib.h" + +static void tst(int argc, char **argv) +{ + int i; + ZebraService zs = tl_start_up("test_trunc.cfg", argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + srand(17); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + zebra_init(zh); + zebra_close(zh); + + for (i = 0; i<10; i++) + { + int l; + + zh = zebra_open (zs, 0); + YAZ_CHECK(zh); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + + YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK); + + for (l = 0; l<100; l++) + { + char rec_buf[5120]; + int j; + *rec_buf = '\0'; + strcat(rec_buf, ""); + if (i == 0) + { + sprintf(rec_buf + strlen(rec_buf), "aaa"); + } + else + { + j = (rand() & 15) + 1; + while (--j >= 0) + { + int c = 65 + (rand() & 15); + sprintf(rec_buf + strlen(rec_buf), "%c", c); + } + } + strcat(rec_buf, ""); + j = rand() & 31; + sprintf(rec_buf + strlen(rec_buf), "%d", j); + strcat(rec_buf, ""); + zebra_add_record (zh, rec_buf, strlen(rec_buf)); + } + YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK); + zebra_close(zh); + } + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + + zebra_set_resource(zh, "trunclimit", "2"); + + /* check massive truncation: bug #281 */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 z", -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 + */ + diff --git a/test/api/test_trunc.cfg b/test/api/test_trunc.cfg new file mode 100644 index 0000000..ac415e2 --- /dev/null +++ b/test/api/test_trunc.cfg @@ -0,0 +1,9 @@ +profilepath: ${srcdir:-.}/../../tab + +attset: bib1.att + +recordType: grs.sgml + +isam: b + +recordId: (bib1,identifier-standard) diff --git a/test/api/test_update_record.c b/test/api/test_update_record.c new file mode 100644 index 0000000..4449c39 --- /dev/null +++ b/test/api/test_update_record.c @@ -0,0 +1,80 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "testlib.h" + +static void create_search_drop(ZebraHandle zh) +{ + const char *rec = "some"; + const char *opaque_id = "9"; + + YAZ_CHECK(zebra_create_database (zh, "Default") == ZEBRA_OK); + + /* bug #447 */ + YAZ_CHECK(zebra_update_record( + zh, action_update, + 0 /* record type */, + 0 /* sysno */, + opaque_id, + 0 /* fname */, + rec, strlen(rec)) + == ZEBRA_OK); /* insert really */ + + YAZ_CHECK(zebra_update_record( + zh, action_update, + 0 /* record type */, + 0 /* sysno */, + opaque_id, + 0 /* fname */, + rec, strlen(rec)) + == ZEBRA_OK); /* replace really */ + + YAZ_CHECK(tl_query(zh, "@attr 1=4 some", 1)); + + zebra_drop_database(zh, "Default"); + + YAZ_CHECK(tl_query_x(zh, "@attr 1=4 some", 0, 109)); + +} + +static void tst(int argc, char **argv) +{ + ZebraService zs = tl_start_up("zebra.cfg", argc, argv); + ZebraHandle zh = zebra_open(zs, 0); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + + zebra_init(zh); + + create_search_drop(zh); + /* bug #447 */ + create_search_drop(zh); + + 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 + */ + diff --git a/test/api/test_zebra_fork.c b/test/api/test_zebra_fork.c new file mode 100644 index 0000000..6f4ccf6 --- /dev/null +++ b/test/api/test_zebra_fork.c @@ -0,0 +1,154 @@ +/* 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_SYS_WAIT_H +#include +#endif +#if HAVE_SYS_UTSNAME_H +#include +#endif + +#include + +#include "testlib.h" + +static void update_process(ZebraService zs, int iter) +{ + int i; + for (i = 0; i= hits_max); + if (hits < hits_max) + printf("i=%d hits=%lld hits_max=%lld\n", i, hits, hits_max); + hits_max = hits; + zebra_close(zh); + } +} + +static pid_t fork_service(ZebraService zs, int iter, + void (*f)(ZebraService zs, int iter)) +{ + pid_t pid = fork(); + + YAZ_CHECK(pid != -1); + if (pid) + return pid; + + (*f)(zs, iter); + YAZ_CHECK_TERM; +} + +static void tst(int argc, char **argv) +{ + ZebraService zs; + ZebraHandle zh; + + mkdir("register", 0775); + mkdir("shadow", 0775); + + zs = tl_start_up("test_zebra_fork.cfg", argc, argv); + YAZ_CHECK(zs); + + zh = zebra_open(zs, 0); + YAZ_CHECK(zh); + + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + + zebra_init(zh); + + YAZ_CHECK(zebra_create_database (zh, "Default") == ZEBRA_OK); + YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK); + zebra_close(zh); + + update_process(zs, 1); + +#if HAVE_SYS_WAIT_H +#if HAVE_UNISTD_H +#if HAVE_SYS_UTSNAME_H + + if (1) + { + int tst_with_fork = 1; + int status[3]; + pid_t pids[3]; + struct utsname s; + uname(&s); + if (!strcmp(s.sysname, "FreeBSD")) + tst_with_fork = 0; + + yaz_log(YLOG_LOG, "s.sysname=%s tst_with_fork=%d", s.sysname, + tst_with_fork); + if (tst_with_fork) + { + pids[0] = fork_service(zs, 200, search_process); + pids[1] = fork_service(zs, 20, update_process); + pids[2] = fork_service(zs, 20, update_process); + waitpid(pids[0], &status[0], 0); + YAZ_CHECK(status[0] == 0); + waitpid(pids[1], &status[1], 0); + YAZ_CHECK(status[1] == 0); + waitpid(pids[2], &status[2], 0); + YAZ_CHECK(status[2] == 0); + } + } +#endif +#endif +#endif + YAZ_CHECK(tl_close_down(0, zs)); +} + +TL_MAIN +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/test/api/test_zebra_fork.cfg b/test/api/test_zebra_fork.cfg new file mode 100644 index 0000000..b830a80 --- /dev/null +++ b/test/api/test_zebra_fork.cfg @@ -0,0 +1,10 @@ +profilepath: ${srcdir:-.}/../../tab + +attset: bib1.att + +recordType: grs.sgml + +isam: b + +register: register:100M +shadow: shadow:100M diff --git a/test/api/zebra.cfg b/test/api/zebra.cfg index 703a24e..3a1549f 100644 --- a/test/api/zebra.cfg +++ b/test/api/zebra.cfg @@ -1,6 +1,7 @@ profilepath: ${srcdir:-.}/../../tab attset: bib1.att +attset: gils.att attset: explain.att recordType: grs.sgml diff --git a/test/api/zebra10.cfg b/test/api/zebra10.cfg deleted file mode 100644 index 1453230..0000000 --- a/test/api/zebra10.cfg +++ /dev/null @@ -1,8 +0,0 @@ -profilepath: ${srcdir:-.}:${srcdir:-.}/../../tab - -attset: t10.att - -recordType: grs.sgml - - - diff --git a/test/api/zebra15.cfg b/test/api/zebra15.cfg deleted file mode 100644 index b830a80..0000000 --- a/test/api/zebra15.cfg +++ /dev/null @@ -1,10 +0,0 @@ -profilepath: ${srcdir:-.}/../../tab - -attset: bib1.att - -recordType: grs.sgml - -isam: b - -register: register:100M -shadow: shadow:100M diff --git a/test/api/zebra17.cfg b/test/api/zebra17.cfg deleted file mode 100644 index a48e23a..0000000 --- a/test/api/zebra17.cfg +++ /dev/null @@ -1,14 +0,0 @@ -profilepath: ${srcdir:-.}:${srcdir:-.}/../../tab -modulePath: ../../index/.libs - -attset: bib1.att -attset: explain.att - -recordType: grs.xml - -index: t17.idx - -isam: b - -encoding: utf-8 - diff --git a/test/api/zebra6.cfg b/test/api/zebra6.cfg deleted file mode 100644 index ac415e2..0000000 --- a/test/api/zebra6.cfg +++ /dev/null @@ -1,9 +0,0 @@ -profilepath: ${srcdir:-.}/../../tab - -attset: bib1.att - -recordType: grs.sgml - -isam: b - -recordId: (bib1,identifier-standard) diff --git a/test/api/zebra8.cfg b/test/api/zebra8.cfg deleted file mode 100644 index e36c55f..0000000 --- a/test/api/zebra8.cfg +++ /dev/null @@ -1,9 +0,0 @@ -profilepath: ${srcdir:-.}/../../tab - -attset: bib1.att -attset: gils.att - -recordType: grs.sgml - -isam: b -