b92c8e93a4ac700743415e09d03fa2d228945c82
[pazpar2-moved-to-github.git] / src / test_normalize.c
1 /* $Id: test_normalize.c,v 1.1 2007-09-07 10:46:33 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #if HAVE_CONFIG_H
23 #include "cconfig.h"
24 #endif
25
26 #include <string.h>
27 #include <yaz/xmalloc.h>
28 #include <yaz/test.h>
29
30 #include "normalize7bit.h"
31
32 int test_normalize7bit_generic(const char *rm_chars, const char *input, 
33                                const char *expect_output)
34 {
35     int ret = 0;
36     char *tmp = xstrdup(input);
37     char *output = normalize7bit_generic(tmp, rm_chars);
38     if (!strcmp(expect_output, output))
39         ret = 1;
40     xfree(tmp);
41     return ret;
42 }
43
44 int test_normalize7bit_mergekey(int skiparticle, const char *input,
45                                 const char *expect_output)
46 {
47     int ret = 0;
48
49     char *tmp = xstrdup(input);
50     char *output = normalize7bit_mergekey(tmp, skiparticle);
51     if (!strcmp(expect_output, output))
52         ret = 1;
53     xfree(tmp);
54     return ret;
55 }
56
57 int main(int argc, char **argv)
58 {
59     YAZ_CHECK_INIT(argc, argv); 
60     YAZ_CHECK_LOG();
61
62     YAZ_CHECK(test_normalize7bit_generic("/; ", " how are you; ", "how are you"));
63     YAZ_CHECK(!test_normalize7bit_generic("/; ", " how are you; ", "how are youx"));
64  
65     YAZ_CHECK(test_normalize7bit_generic("/; "," ", ""));
66
67     YAZ_CHECK(test_normalize7bit_mergekey(0, "the art of computer", "the art of computer"));
68     YAZ_CHECK(test_normalize7bit_mergekey(1, "the art of computer", "art of computer"));
69
70     YAZ_CHECK(test_normalize7bit_mergekey(1, "The Art Of Computer", "art of computer"));
71    
72     YAZ_CHECK_TERM;
73 }
74
75
76
77
78 /*
79  * Local variables:
80  * c-basic-offset: 4
81  * indent-tabs-mode: nil
82  * End:
83  * vim: shiftwidth=4 tabstop=8 expandtab
84  */