Update doc/common
[yaz-moved-to-github.git] / test / test_oid.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 #if HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include <yaz/test.h>
13 #include <yaz/log.h>
14 #include <yaz/oid_db.h>
15
16 static void tst(void)
17 {
18     char oid_buf[OID_STR_MAX];
19     const char *n;
20     yaz_oid_db_t db;
21     const Odr_oid *c_oid;
22     Odr_oid *oid;
23     NMEM nmem = nmem_create();
24     ODR odr = odr_createmem(ODR_ENCODE);
25
26     db = yaz_oid_std();
27     YAZ_CHECK(db);
28
29     c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "Bib-1");
30     YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
31
32     c_oid = yaz_string_to_oid(db, CLASS_GENERAL, "Bib-1");
33     YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
34
35     c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "unknown");
36     YAZ_CHECK(c_oid == 0);
37
38     oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "1.2.840.10003.3.1", nmem);
39     YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
40
41     oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "unknown", nmem);
42     YAZ_CHECK(oid == 0);
43
44     oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "1.2.840.10003.3.1", odr);
45     YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
46
47     oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "unknown", odr);
48     YAZ_CHECK(oid == 0);
49
50     n = yaz_oid_to_string(db, yaz_oid_attset_bib_1, 0);
51     YAZ_CHECK(n && !strcmp(n, "Bib-1"));
52
53     n = oid_name_to_dotstring(CLASS_ATTSET, "Bib-1", oid_buf);
54     YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.3.1"));
55
56     n = oid_name_to_dotstring(CLASS_DIAGSET, "Bib-1", oid_buf);
57     YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.4.1"));
58
59     n = oid_name_to_dotstring(CLASS_DIAGSET, "unknown", oid_buf);
60     YAZ_CHECK(!n);
61
62     n = oid_name_to_dotstring(CLASS_DIAGSET, "1.2.840.10003.3.1", oid_buf);
63     YAZ_CHECK(!n);
64
65     nmem_destroy(nmem);
66     odr_destroy(odr);
67 }
68
69
70 int main (int argc, char **argv)
71 {
72     YAZ_CHECK_INIT(argc, argv);
73     YAZ_CHECK_LOG();
74     tst();
75     YAZ_CHECK_TERM;
76 }
77
78 /*
79  * Local variables:
80  * c-basic-offset: 4
81  * c-file-style: "Stroustrup"
82  * indent-tabs-mode: nil
83  * End:
84  * vim: shiftwidth=4 tabstop=8 expandtab
85  */
86