Fix windows uninstall does not remove start menu shortcuts YAZ-860
[yaz-moved-to-github.git] / test / test_libstemmer.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 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     int rc = 0;
24     UErrorCode status;
25     const char *result;
26
27     icu_utf16_from_utf8_cstr(src, to_stem, &status);
28     yaz_stemmer_stem(stemmer, dst, src, &status);
29     if (status == U_ZERO_ERROR) {
30         icu_utf16_to_utf8(dst8, dst, &status);
31         result = icu_buf_utf8_to_cstr(dst8);
32         rc = strcmp(result, expected) == 0;
33     }
34     icu_buf_utf8_destroy(dst8);
35     icu_buf_utf16_destroy(src);
36     icu_buf_utf16_destroy(dst);
37     return rc;
38 }
39
40
41 static void tst(void)
42 {
43     UErrorCode status;
44     //== U_ZERO_ERROR;
45     yaz_stemmer_p stemmer = yaz_stemmer_create("en", "porter", &status);
46     YAZ_CHECK(stemmer);
47
48     /* fail  */
49     YAZ_CHECK(test_stemmer_stem(stemmer, "beer", "water") == 0 );
50
51     /* Same */
52     YAZ_CHECK(test_stemmer_stem(stemmer, "adadwwr", "adadwwr"));
53
54     /* Remove S */
55     YAZ_CHECK(test_stemmer_stem(stemmer, "beers", "beer"));
56     YAZ_CHECK(test_stemmer_stem(stemmer, "persons", "person"));
57
58     /* Remove s and ing  */
59     YAZ_CHECK(test_stemmer_stem(stemmer, "runs", "run"));
60     YAZ_CHECK(test_stemmer_stem(stemmer, "running", "run"));
61
62     yaz_stemmer_destroy(stemmer);
63 }
64 #endif
65
66 int main (int argc, char **argv)
67 {
68     YAZ_CHECK_INIT(argc, argv);
69 #if YAZ_HAVE_ICU
70     tst();
71 #endif
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