Mods to tests to avoid clang warnings
[yaz-moved-to-github.git] / test / test_libstemmer.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 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 #include <string.h>
12
13 #include <yaz/test.h>
14
15 #if YAZ_HAVE_ICU
16 #include <yaz/stemmer.h>
17
18 int test_stemmer_stem(yaz_stemmer_p stemmer, const char* to_stem, const char *expected) 
19 {
20     struct icu_buf_utf16 *src  = icu_buf_utf16_create(0);
21     struct icu_buf_utf16 *dst  = icu_buf_utf16_create(0);
22     struct icu_buf_utf8  *dst8 = icu_buf_utf8_create(0);
23
24     UErrorCode status; 
25     const char *result;
26     icu_utf16_from_utf8_cstr(src, to_stem, &status);
27     yaz_stemmer_stem(stemmer, dst, src, &status); 
28     /* Assume fail */
29     int rc = 0;
30     if (status == U_ZERO_ERROR) {
31         icu_utf16_to_utf8(dst8, dst, &status);
32         result = icu_buf_utf8_to_cstr(dst8);
33         rc = strcmp(result, expected) == 0;
34     }
35     icu_buf_utf8_destroy(dst8);
36     icu_buf_utf16_destroy(src);
37     icu_buf_utf16_destroy(dst);
38     return rc;
39 }
40
41
42 static void tst(void)
43 {
44     UErrorCode status;
45     //== U_ZERO_ERROR; 
46     yaz_stemmer_p stemmer = yaz_stemmer_create("en", "porter", &status);
47     YAZ_CHECK(stemmer); 
48
49     /* fail  */
50     YAZ_CHECK(test_stemmer_stem(stemmer, "beer", "water") == 0 ); 
51
52     /* Same */
53     YAZ_CHECK(test_stemmer_stem(stemmer, "adadwwr", "adadwwr")); 
54
55     /* Remove S */
56     YAZ_CHECK(test_stemmer_stem(stemmer, "beers", "beer")); 
57     YAZ_CHECK(test_stemmer_stem(stemmer, "persons", "person")); 
58
59     /* Remove s and ing  */
60     YAZ_CHECK(test_stemmer_stem(stemmer, "runs", "run")); 
61     YAZ_CHECK(test_stemmer_stem(stemmer, "running", "run")); 
62
63     yaz_stemmer_destroy(stemmer);
64 }
65 #endif
66
67 int main (int argc, char **argv)
68 {
69     YAZ_CHECK_INIT(argc, argv);
70 #if YAZ_HAVE_ICU
71     tst();
72 #endif
73     YAZ_CHECK_TERM;
74 }
75
76 /*
77  * Local variables:
78  * c-basic-offset: 4
79  * c-file-style: "Stroustrup"
80  * indent-tabs-mode: nil
81  * End:
82  * vim: shiftwidth=4 tabstop=8 expandtab
83  */
84