summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhoon Vishwanathan <vidhu2366@gmail.com>2013-07-21 17:36:41 +0000
committerVidhoon Vishwanathan <vidhu2366@gmail.com>2013-07-21 17:36:41 +0000
commit91cd5e1d957d01f08c8f8b7329e3b1a50ec25e1c (patch)
tree88fed41ae3e1e45f9e4a6e58a5b77304d90acad0
parent08fb46250e56f097ddf1e5f3a5d0be8921700cb5 (diff)
downloadenchant-gsoc2013cdict.tar.gz
[COMPDICT] Tests for Composite Dictionarygsoc2013cdict
This patch creates basic tests for composite dictionary and also include Makefile changes for compilation of new tests to make them run ready. Signed-off-by: Vidhoon Viswanathan <vidhu2366@gmail.com> git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/branches/gsoc2013cdict@33285 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/test-enchant-composite.c280
2 files changed, 286 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0980415..403a1e2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,7 +11,7 @@ else
cxx_progs =
endif
-noinst_PROGRAMS = test-enchant $(cxx_progs)
+noinst_PROGRAMS = test-enchant test-enchant-composite $(cxx_progs)
bin_PROGRAMS= enchant-lsmod enchant
test_enchant_SOURCES = test-enchant.c
@@ -19,6 +19,11 @@ test_enchant_LDFLAGS =
test_enchant_DEPENDENCIES = $(DEPS)
test_enchant_LDADD = $(ldadd)
+test_enchant_composite_SOURCES = test-enchant-composite.c
+test_enchant_composite_LDFLAGS =
+test_enchant_composite_DEPENDENCIES = $(DEPS)
+test_enchant_composite_LDADD = $(ldadd)
+
enchant_SOURCES = enchant-ispell.c
enchant_LDFLAGS =
enchant_DEPENDENCIES = $(DEPS)
diff --git a/tests/test-enchant-composite.c b/tests/test-enchant-composite.c
new file mode 100644
index 0000000..0350ce8
--- /dev/null
+++ b/tests/test-enchant-composite.c
@@ -0,0 +1,280 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* enchant
+ * Copyright (C) 2003 Dom Lachowicz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02110-1301, USA.
+ *
+ * In addition, as a special exception, Dom Lachowicz
+ * gives permission to link the code of this program with
+ * the non-LGPL Spelling Provider libraries (eg: a MSFT Office
+ * spell checker backend) and distribute linked combinations including
+ * the two. You must obey the GNU Lesser General Public License in all
+ * respects for all of the code used other than said providers. If you modify
+ * this file, you may extend this exception to your version of the
+ * file, but you are not obligated to do so. If you do not wish to
+ * do so, delete this exception statement from your version.
+ */
+#include<stdio.h>
+#include<glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "enchant.h"
+#include "composite_provider.h"
+
+
+void test1()
+{
+ //test string
+ char tc[]="abcd";
+ const char * err;
+
+ //create a broker to use
+ EnchantBroker *broker = enchant_broker_init ();
+
+ //create a normal dictionary to benchmark results
+ EnchantDict *eng_dict = enchant_broker_request_dict(broker,"en_US");
+
+ if(!eng_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+
+ //create a composite dictionary Eng,Fr
+ EnchantDict *cdict = enchant_broker_request_composite_dict(broker,"en_US:fr_FR:");
+ if(!cdict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+
+ g_assert(enchant_dict_check(eng_dict,tc,strlen(tc)) == enchant_dict_check(cdict, tc, strlen(tc)));
+
+ printf("test1 complete\n");
+//cleanup
+ g_free(broker);
+ g_free(eng_dict);
+ g_free(cdict);
+}
+
+void test2()
+{
+ //test string
+ char tc[]="indien";
+ const char * err;
+
+ //create a broker to use
+ EnchantBroker *broker = enchant_broker_init ();
+
+ //create a normal dictionary for en_US
+ EnchantDict *eng_dict = enchant_broker_request_dict(broker,"en_US");
+
+ if(!eng_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+ //create a normal dictionary for fr_FR
+ EnchantDict *fr_dict = enchant_broker_request_dict(broker,"fr_FR");
+
+ if(!fr_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for fr_FR: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for fr_FR\n");
+ return;
+ }
+
+ //create a composite dictionary Eng,Fr
+ EnchantDict *cdict = enchant_broker_request_composite_dict(broker,"en_US:fr_FR:");
+ if(!cdict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+
+ g_assert(enchant_dict_check(eng_dict,tc,strlen(tc)) != enchant_dict_check(cdict, tc, strlen(tc)));
+
+ g_assert(enchant_dict_check(fr_dict,tc,strlen(tc)) == enchant_dict_check(cdict, tc, strlen(tc)));
+
+ printf("test2 complete\n");
+//cleanup
+ g_free(broker);
+ g_free(eng_dict);
+ g_free(fr_dict);
+ g_free(cdict);
+}
+
+void test3()
+{
+ //test string
+ char tc[]="‘abcdefghijklmnop";
+ const char * err;
+ char **sug_eng, **sug_fr, **sug_comp;
+ int n_sug_eng,n_sug_fr,n_sug_comp;
+
+ //create a broker to use
+ EnchantBroker *broker = enchant_broker_init ();
+
+ //create a normal dictionary for en_US
+ EnchantDict *eng_dict = enchant_broker_request_dict(broker,"en_US");
+
+ if(!eng_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+ //create a normal dictionary for fr_FR
+ EnchantDict *fr_dict = enchant_broker_request_dict(broker,"fr_FR");
+
+ if(!fr_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for fr_FR: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for fr_FR\n");
+ return;
+ }
+
+ //create a composite dictionary Eng,Fr
+ EnchantDict *cdict = enchant_broker_request_composite_dict(broker,"en_US:fr_FR:");
+ if(!cdict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+
+ sug_eng = enchant_dict_suggest(eng_dict,tc,strlen(tc),&n_sug_eng);
+ sug_fr = enchant_dict_suggest(fr_dict,tc,strlen(tc),&n_sug_fr);
+ sug_comp = enchant_dict_suggest(cdict,tc,strlen(tc),&n_sug_comp);
+
+//just asserting the number of suggestions to begin with
+ g_assert_cmpint(n_sug_eng, ==,0);
+ g_assert_cmpint(n_sug_fr, ==,0);
+ g_assert_cmpint(n_sug_comp, ==,0);
+
+ printf("test3 complete\n");
+//cleanup
+ g_free(broker);
+ g_free(eng_dict);
+ g_free(fr_dict);
+ g_free(cdict);
+}
+
+void test6()
+{
+ //test string
+ char tc[]="‘teh";
+ const char * err;
+ char **sug_eng, **sug_fr, **sug_comp;
+ int n_sug_eng,n_sug_fr,n_sug_comp;
+
+ //create a broker to use
+ EnchantBroker *broker = enchant_broker_init ();
+
+ //create a normal dictionary for en_US
+ EnchantDict *eng_dict = enchant_broker_request_dict(broker,"en_US");
+
+ if(!eng_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+ //create a normal dictionary for fr_FR
+ EnchantDict *fr_dict = enchant_broker_request_dict(broker,"fr_FR");
+
+ if(!fr_dict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for fr_FR: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for fr_FR\n");
+ return;
+ }
+
+ //create a composite dictionary Eng,Fr
+ EnchantDict *cdict = enchant_broker_request_composite_dict(broker,"en_US:fr_FR:");
+ if(!cdict)
+ {
+ err = enchant_broker_get_error (broker);
+ if (err)
+ fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
+ else
+ fprintf (stderr, "Couldn't create dictionary for en_US\n");
+ return;
+ }
+ sug_eng = enchant_dict_suggest(eng_dict,tc,strlen(tc),&n_sug_eng);
+ sug_fr = enchant_dict_suggest(fr_dict,tc,strlen(tc),&n_sug_fr);
+ sug_comp = enchant_dict_suggest(cdict,tc,strlen(tc),&n_sug_comp);
+
+//just asserting the number of suggestions to begin with
+ g_assert_cmpint(n_sug_comp, ==, n_sug_eng+n_sug_fr);
+
+ printf("test6 complete\n");
+//cleanup
+ g_free(broker);
+ g_free(eng_dict);
+ g_free(cdict);
+
+}
+
+
+int main(int argc, char **argv)
+{
+
+ g_test_init(&argc,&argv,NULL);
+ g_test_add_func("/test1",test1);
+ g_test_add_func("/test2",test2);
+ g_test_add_func("/test3",test3);
+ g_test_add_func("/test6",test6);
+ g_test_run();
+
+return 0;
+}
+