1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003 Dom Lachowicz
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.
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.
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.
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.
35 #include "enchant++.h"
38 enumerate_providers_fn (const char * const name,
39 const char * const desc,
40 const char * const file,
43 printf ("%s: '%s' (%s)\n", name, desc, file);
47 describe_dict (enchant::Dict * dict)
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());
54 run_dict_tests (enchant::Dict * dict)
56 std::vector<std::string> suggs;
59 const char *check_checks[] = { "hello", "helllo" };
60 const char *sugg_checks[] = { "helllo", "taag" };
62 for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
64 printf ("enchant_dict_check (%s): %d\n", check_checks[i],
65 dict->check (check_checks[i]) == false);
68 for (i = 0; i < (sizeof (sugg_checks) / sizeof (sugg_checks[0])); i++)
70 dict->suggest (sugg_checks[i], suggs);
72 printf ("enchant_dict_suggest(%s): %d\n", sugg_checks[i], suggs.size());
73 for (j = 0; j < suggs.size(); j++)
75 printf ("\t=>%s\n", suggs[j].c_str());
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++)
83 printf ("enchant_dict_check (%s): %d\n", check_checks[i],
84 dict->check (check_checks[i]) == false);
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++)
92 printf ("enchant_dict_check (%s): %d\n", check_checks[i],
93 dict->check (check_checks[i]) == false);
99 main (int argc, char **argv)
101 enchant::Broker *broker;
104 broker = enchant::Broker::instance ();
107 dict = broker->request_dict ("en_US");
108 describe_dict (dict);
109 run_dict_tests (dict);
112 // test personal wordlist dictionaries
113 dict = broker->request_pwl_dict ("test.pwl");
114 describe_dict (dict);
115 run_dict_tests (dict);
117 } catch (enchant::Exception & ex) {
118 fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", ex.what());
122 broker->describe (enumerate_providers_fn);