Tizen 2.1 base
[external/enchant.git] / tests / test-enchantxx.cpp
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* enchant
3  * Copyright (C) 2003 Dom Lachowicz
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, Dom Lachowicz
21  * gives permission to link the code of this program with
22  * the non-LGPL Spelling Provider libraries (eg: a MSFT Office
23  * spell checker backend) and distribute linked combinations including
24  * the two. You must obey the GNU Lesser General Public License in all
25  * respects for all of the code used other than said providers. If you modify
26  * this file, you may extend this exception to your version of the
27  * file, but you are not obligated to do so. If you do not wish to
28  * do so, delete this exception statement from your version.
29  */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include "enchant.h"
35 #include "enchant++.h"
36
37 static void
38 enumerate_providers_fn (const char * const name,
39                         const char * const desc,
40                         const char * const file,
41                         void * ud)
42 {
43         printf ("%s: '%s' (%s)\n", name, desc, file);
44 }
45
46 static void
47 describe_dict (enchant::Dict * dict)
48 {
49         printf ("%s: %s '%s' (%s)\n", dict->get_lang().c_str(), dict->get_provider_name().c_str(), 
50                 dict->get_provider_desc().c_str(), dict->get_provider_file().c_str());
51 }
52
53 static void
54 run_dict_tests (enchant::Dict * dict)
55 {
56         std::vector<std::string> suggs;
57         size_t i, j;
58         
59         const char *check_checks[] = { "hello", "helllo" };
60         const char *sugg_checks[] = { "helllo", "taag" };
61         
62         for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
63                 {
64                         printf ("enchant_dict_check (%s): %d\n", check_checks[i],
65                                 dict->check (check_checks[i]) == false);
66                 }
67         
68         for (i = 0; i < (sizeof (sugg_checks) / sizeof (sugg_checks[0])); i++)
69                 {
70                         dict->suggest (sugg_checks[i], suggs);
71                         
72                         printf ("enchant_dict_suggest(%s): %d\n", sugg_checks[i], suggs.size());
73                         for (j = 0; j < suggs.size(); j++)
74                                 {
75                                         printf ("\t=>%s\n", suggs[j].c_str());
76                                 }
77                 }
78
79         printf ("Adding 'helllo' to session\n");
80         dict->add_to_session ("helllo");
81         for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
82                 {
83                         printf ("enchant_dict_check (%s): %d\n", check_checks[i],
84                                 dict->check (check_checks[i]) == false);
85                 }
86
87 #if 0
88         printf ("Adding 'helllo' to personal\n");
89         dict->add_to_pwl ("helllo");
90         for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
91                 {
92                         printf ("enchant_dict_check (%s): %d\n", check_checks[i],
93                                 dict->check (check_checks[i]) == false);
94                 }
95 #endif
96 }
97
98 int
99 main (int argc, char **argv)
100 {
101         enchant::Broker *broker;
102         enchant::Dict *dict;
103         
104         broker = enchant::Broker::instance ();
105         
106         try {
107                 dict = broker->request_dict ("en_US");
108                 describe_dict (dict);
109                 run_dict_tests (dict);          
110                 delete dict;
111
112                 // test personal wordlist dictionaries
113                 dict = broker->request_pwl_dict ("test.pwl");
114                 describe_dict (dict);
115                 run_dict_tests (dict);
116                 delete dict;
117         } catch (enchant::Exception & ex) {
118                 fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", ex.what());
119                 return 1;
120         }
121
122         broker->describe (enumerate_providers_fn);
123
124         return 0;
125 }