From 813b245533765d9ff66d35f0d28fdbfc5ba03bcb Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 24 Jun 2007 19:27:11 +0000 Subject: [PATCH] Implemented oid_name_to_dotstring. Added test for OID API. --- include/yaz/oid_db.h | 13 +++++++- src/oid_db.c | 12 +++++++- test/Makefile.am | 5 +-- test/tst_oid.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 test/tst_oid.c diff --git a/include/yaz/oid_db.h b/include/yaz/oid_db.h index c216c33..5913f4a 100644 --- a/include/yaz/oid_db.h +++ b/include/yaz/oid_db.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: oid_db.h,v 1.8 2007-05-08 08:22:35 adam Exp $ */ +/* $Id: oid_db.h,v 1.9 2007-06-24 19:27:11 adam Exp $ */ /** * \file oid_db.h @@ -129,6 +129,17 @@ YAZ_EXPORT const char *yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *buf); + +/** \brief maps named from standard database to dot notation + \param oclass class of string (enum oid_class) + \param name named OID + \param oid_buf buffer for result (must be of size OID_STR_MAX) + \returns OID string or NULL if name is not registered in database +*/ +YAZ_EXPORT +char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf); + + /** \brief traverses OIDs in a database \param oid_db OID database \param func function to be called for each OID diff --git a/src/oid_db.c b/src/oid_db.c index 8318018..2ea139d 100644 --- a/src/oid_db.c +++ b/src/oid_db.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: oid_db.c,v 1.8 2007-05-08 08:22:36 adam Exp $ + * $Id: oid_db.c,v 1.9 2007-06-24 19:27:12 adam Exp $ */ /** @@ -107,6 +107,16 @@ const char *yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *b return oid_oid_to_dotstring(oid, buf); } + +char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf) +{ + const Odr_oid *oid = yaz_string_to_oid(yaz_oid_std(), oclass, name); + if (oid) + return oid_oid_to_dotstring(oid, oid_buf); + return 0; +} + + int yaz_oid_is_iso2709(const Odr_oid *oid) { if (oid_oidlen(oid) == 6 && oid[0] == 1 && oid[1] == 2 diff --git a/test/Makefile.am b/test/Makefile.am index bf32645..8fcdc41 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,11 +1,11 @@ ## Copyright (C) 1995-2007, Index Data ApS ## All rights reserved. -## $Id: Makefile.am,v 1.34 2007-04-10 14:42:31 adam Exp $ +## $Id: Makefile.am,v 1.35 2007-06-24 19:27:12 adam Exp $ check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \ tst_comstack tst_filepath tst_record_conv tst_retrieval tst_tpath \ - tst_timing tst_query_charset + tst_timing tst_query_charset tst_oid check_SCRIPTS = tstcql.sh tstmarciso.sh tstmarcxml.sh tstmarccol.sh TESTS = $(check_PROGRAMS) $(check_SCRIPTS) @@ -58,6 +58,7 @@ tstxmlquery_SOURCES = tstxmlquery.c tstpquery_SOURCES = tstpquery.c tst_comstack_SOURCES = tst_comstack.c tst_filepath_SOURCES = tst_filepath.c +tst_oid_SOURCES = tst_oid.c tst_record_conv_SOURCES = tst_record_conv.c tst_retrieval_SOURCES = tst_retrieval.c tst_tpath_SOURCES = tst_tpath.c diff --git a/test/tst_oid.c b/test/tst_oid.c new file mode 100644 index 0000000..fb23b7e --- /dev/null +++ b/test/tst_oid.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 1995-2007, Index Data ApS + * See the file LICENSE for details. + * + * $Id: tst_oid.c,v 1.1 2007-06-24 19:27:12 adam Exp $ + */ + +#include +#include + +#include +#include +#include + +static void tst(void) +{ + char oid_buf[OID_STR_MAX]; + const char *n; + yaz_oid_db_t db; + const Odr_oid *c_oid; + Odr_oid *oid; + NMEM nmem = nmem_create(); + ODR odr = odr_createmem(ODR_ENCODE); + + db = yaz_oid_std(); + YAZ_CHECK(db); + + c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "Bib-1"); + YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0); + + c_oid = yaz_string_to_oid(db, CLASS_GENERAL, "Bib-1"); + YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0); + + c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "unknown"); + YAZ_CHECK(c_oid == 0); + + oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "1.2.840.10003.3.1", nmem); + YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1)); + + oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "unknown", nmem); + YAZ_CHECK(oid == 0); + + oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "1.2.840.10003.3.1", odr); + YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1)); + + oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "unknown", odr); + YAZ_CHECK(oid == 0); + + n = yaz_oid_to_string(db, yaz_oid_attset_bib_1, 0); + YAZ_CHECK(n && !strcmp(n, "Bib-1")); + + n = oid_name_to_dotstring(CLASS_ATTSET, "Bib-1", oid_buf); + YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.3.1")); + + n = oid_name_to_dotstring(CLASS_DIAGSET, "Bib-1", oid_buf); + YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.4.1")); + + n = oid_name_to_dotstring(CLASS_DIAGSET, "unknown", oid_buf); + YAZ_CHECK(!n); + + n = oid_name_to_dotstring(CLASS_DIAGSET, "1.2.840.10003.3.1", oid_buf); + YAZ_CHECK(!n); + + nmem_destroy(nmem); + odr_destroy(odr); +} + + +int main (int argc, char **argv) +{ + YAZ_CHECK_INIT(argc, argv); + YAZ_CHECK_LOG(); + tst(); + YAZ_CHECK_TERM; +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + -- 1.7.10.4