IDZEBRA  2.2.7
tstcharmap.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <charmap.h>
24 #include <yaz/test.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 /* use env srcdir as base directory - or current directory if unset */
29 const char *get_srcdir(void)
30 {
31  const char *srcdir = getenv("srcdir");
32  if (!srcdir || ! *srcdir)
33  srcdir=".";
34  return srcdir;
35 
36 }
37 
38 void tst_string(chrmaptab tab, const char *input, int value) {
39  const char **output;
40  const char *from = input;
41  int len = strlen(from);
42  output = chr_map_input_x(tab, &from, &len, 0);
43  YAZ_CHECK_EQ(0, len);
44  YAZ_CHECK(output);
45  if (output)
46  {
47  YAZ_CHECK(*output);
48  YAZ_CHECK_EQ(value, output[0][0]);
49  }
50 }
51 
52 void tst_latin1(void)
53 {
54  /* open existing map chrmaptab.chr */
55  chrmaptab tab = chrmaptab_create(get_srcdir() /* tabpath */,
56  "tstcharmap.chr" /* file */,
57  0 /* tabroot */ );
58  YAZ_CHECK(tab);
59  tst_string(tab, "b", 16);
60  tst_string(tab, "æ", 42);
61  tst_string(tab, "Æ", 42);
62  chrmaptab_destroy(tab);
63 }
64 
65 void tst_utf8(void)
66 {
67  /* open existing map chrmaptab.chr */
68  chrmaptab tab = chrmaptab_create(get_srcdir() /* tabpath */,
69  "tstcharmap_utf8.chr" /* file */,
70  0 /* tabroot */ );
71  YAZ_CHECK(tab);
72  tst_string(tab, "b", 16);
73  tst_string(tab, "æ", 42);
74  tst_string(tab, "Æ", 42);
75  chrmaptab_destroy(tab);
76 }
77 
78 void tst2(void)
79 {
80  /* open non-existing nonexist.chr */
81  chrmaptab tab = chrmaptab_create(get_srcdir() /* tabpath */,
82  "nonexist.chr" /* file */,
83  0 /* tabroot */ );
84  YAZ_CHECK(!tab);
85  chrmaptab_destroy(tab);
86 }
87 
88 void tst3(void)
89 {
90  /* open empty emptycharmap.chrr */
91  chrmaptab tab = chrmaptab_create(get_srcdir() /* tabpath */,
92  "emptycharmap.chr" /* file */,
93  0 /* tabroot */ );
94  YAZ_CHECK(!tab);
95  chrmaptab_destroy(tab);
96 }
97 
98 int main(int argc, char **argv)
99 {
100  YAZ_CHECK_INIT(argc, argv);
101  YAZ_CHECK_LOG();
102 
103  tst_latin1();
104  tst_utf8();
105  tst2();
106  tst3();
107 
108  YAZ_CHECK_TERM;
109 }
110 
111 /*
112  * Local variables:
113  * c-basic-offset: 4
114  * c-file-style: "Stroustrup"
115  * indent-tabs-mode: nil
116  * End:
117  * vim: shiftwidth=4 tabstop=8 expandtab
118  */
119 
void chrmaptab_destroy(chrmaptab tab)
Definition: charmap.c:748
chrmaptab chrmaptab_create(const char *tabpath, const char *name, const char *tabroot)
Definition: charmap.c:513
const char ** chr_map_input_x(chrmaptab t, const char **from, int *len, int first)
Definition: charmap.c:184
void tst_utf8(void)
Definition: tstcharmap.c:65
void tst3(void)
Definition: tstcharmap.c:88
int main(int argc, char **argv)
Definition: tstcharmap.c:98
void tst2(void)
Definition: tstcharmap.c:78
void tst_latin1(void)
Definition: tstcharmap.c:52
const char * get_srcdir(void)
Definition: tstcharmap.c:29
void tst_string(chrmaptab tab, const char *input, int value)
Definition: tstcharmap.c:38