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