pazpar2  1.14.1
test_normalize.c
Go to the documentation of this file.
1 /* This file is part of Pazpar2.
2  Copyright (C) Index Data
3 
4 Pazpar2 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 Pazpar2 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 
24 #include <string.h>
25 #include <yaz/xmalloc.h>
26 #include <yaz/test.h>
27 
28 #include "normalize7bit.h"
29 
30 int test_normalize7bit_generic(const char *rm_chars, const char *input,
31  const char *expect_output)
32 {
33  int ret = 0;
34  char *tmp = xstrdup(input);
35  char *output = normalize7bit_generic(tmp, rm_chars);
36  if (!strcmp(expect_output, output))
37  ret = 1;
38  xfree(tmp);
39  return ret;
40 }
41 
42 int test_normalize7bit_mergekey(const char *input,
43  const char *expect_output)
44 {
45  int ret = 0;
46 
47  char *tmp = xstrdup(input);
48  char *output = normalize7bit_mergekey(tmp);
49  if (!strcmp(expect_output, output))
50  ret = 1;
51  xfree(tmp);
52  return ret;
53 }
54 
55 int main(int argc, char **argv)
56 {
57  YAZ_CHECK_INIT(argc, argv);
58  YAZ_CHECK_LOG();
59 
60  YAZ_CHECK(test_normalize7bit_generic("/; ", " how are you; ", "how are you"));
61  YAZ_CHECK(!test_normalize7bit_generic("/; ", " how are you; ", "how are youx"));
62 
63  YAZ_CHECK(test_normalize7bit_generic("/; "," ", ""));
64 
65  YAZ_CHECK(test_normalize7bit_mergekey("the art of computer", "the art of computer"));
66  YAZ_CHECK(test_normalize7bit_mergekey("The Art Of Computer", "the art of computer"));
67 
68  YAZ_CHECK_TERM;
69 }
70 
71 
72 
73 
74 /*
75  * Local variables:
76  * c-basic-offset: 4
77  * c-file-style: "Stroustrup"
78  * indent-tabs-mode: nil
79  * End:
80  * vim: shiftwidth=4 tabstop=8 expandtab
81  */
82 
char * normalize7bit_generic(char *str, const char *rm_chars)
removes leading whitespace.. Removes suffix cahrs in rm_chars
Definition: normalize7bit.c:36
char * normalize7bit_mergekey(char *buf)
Definition: normalize7bit.c:47
int test_normalize7bit_generic(const char *rm_chars, const char *input, const char *expect_output)
int main(int argc, char **argv)
int test_normalize7bit_mergekey(const char *input, const char *expect_output)