aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-15 20:57:55 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-15 20:57:55 +0200
commite60288d595ec405c5d416e5da54b516e65f8a8c5 (patch)
treed88aaa4352658be717b463ca60c05d85b41d1cd0 /tests
parent00110918072f77e0e5705e93ad91207f1bd0d873 (diff)
downloadeclat-e60288d595ec405c5d416e5da54b516e65f8a8c5.tar.gz
eclat-e60288d595ec405c5d416e5da54b516e65f8a8c5.tar.bz2
Implement direct and reverse map lookups.
Not all maps support reverse lookups generically (for example, gdbm does not), therefore introduce a new "bidi" (bi-directional) map, which is a compound of two maps, each one used for a particular lookup direction. * lib/Makefile.am (maps): List all maps here. * lib/bidimap.c: New file. Implementation of a bi-directional map. * lib/filemap.c: Update to the changes in API. Implement reverse lookup. * lib/gdbmmap.c: Update to the changes in API. * lib/nullmap.c: Likewise. * lib/seqmap.c: Likewise. * lib/ldapmap.c: Update to the changes in API. Implement reverse lookup. New configuration keywords: reverse-filter, reverse-attr. * lib/libeclat.h (eclat_map_drv) <map_get>: Change signature, take search direction as a new argument. (eclat_map_get): Likewise. (eclat_map) <eclat_map_bad_dir>: New status code. (MAP_DIR, MAP_REV): New macros. (eclat_map_name_split): New function. (eclat_map_drv_bidi): New extern. * lib/map.c (eclat_map_get): Change signature, take search direction as a new argument. Pass new keyword to the "key" translation: "dir". (eclat_map_strerror): Handle new status code. (eclat_map_name_split): New function. * src/eclat.c (main): Register eclat_map_drv_bidi. * src/util.c (translate_ids): Use eclat_map_name_split to obtain direction code from the map name. (translate_resource_ids): Use direct lookups. * tests/Makefile.am: Add new testcases. * tests/testsuite.at: Likewise. * tests/bidimap.at: New testcase. * tests/filemap.at: Test reverse lookups.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/bidimap.at58
-rw-r--r--tests/filemap.at15
-rw-r--r--tests/testsuite.at1
4 files changed, 75 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d12342..0a302a6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,6 +42,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
TESTSUITE_AT = \
allocate-address.at\
associate-address.at\
+ bidimap.at\
create-snapshot.at\
decode.at\
delete-snapshot.at\
diff --git a/tests/bidimap.at b/tests/bidimap.at
new file mode 100644
index 0000000..ed3b6b9
--- /dev/null
+++ b/tests/bidimap.at
@@ -0,0 +1,58 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat 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 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([bidi])
+AT_KEYWORDS([map bidimap])
+
+AT_DATA([test.conf],
+[map dir {
+ type file;
+ file "dir.txt";
+}
+
+map rev {
+ type file;
+ file "rev.txt";
+};
+
+map inst {
+ type bidi;
+ direct-map dir;
+ reverse-map rev;
+}
+])
+
+AT_DATA([dir.txt],
+[db:i-feed1234
+web:i-deadbeef
+])
+
+AT_DATA([rev.txt],
+[i-deadbeef:web
+i-feed1234:db
+])
+
+AT_CHECK([eclat --config-file test.conf --test-map inst:0 db],
+[0],
+[i-feed1234
+])
+
+AT_CHECK([eclat --config-file test.conf --test-map inst:1 i-feed1234],
+[0],
+[db
+])
+
+AT_CLEANUP
diff --git a/tests/filemap.at b/tests/filemap.at
index b84da7c..52c5e83 100644
--- a/tests/filemap.at
+++ b/tests/filemap.at
@@ -35,4 +35,19 @@ AT_CHECK([eclat --config-file test.conf --test-map file dbserv],
[i-deadbeef
])
+AT_CHECK([eclat --config-file test.conf --test-map file:rev i-feed1234],
+[0],
+[web
+])
+
+AT_CHECK([eclat --config-file test.conf --test-map file:rev i-12345678],
+[0],
+[dbserver
+])
+
+AT_CHECK([eclat --config-file test.conf --test-map file:rev i-deadbeef],
+[0],
+[dbserv
+])
+
AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 65e1d99..35640e8 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -83,5 +83,6 @@ m4_include([nullmap.at])
m4_include([filemap.at])
m4_include([gdbmmap.at])
m4_include([seqmap.at])
+m4_include([bidimap.at])
# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.