Added sqlite3 bookmarks
[mdictionary] / src / bookmarks / sql3 / src / test.c
1 /*******************************************************************************
2 This file is part of WhiteStork.
3
4 WhiteStork is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 WhiteStork is distributed in the hope that it will be useful, 
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License 
15 along with WhiteStork; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18 Copyright 2006 ComArch S.A.
19 *******************************************************************************/
20 #include <gmodule.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <dictionary_engine.h>
24
25
26 getting_additional get_functions; // additinal functions for concrete module (e.g. XDXF)
27
28 void print_list(GArray* list, gchar* pattern, gpointer user_data, EngineStatus error) {
29         printf((gchar*)user_data,pattern);
30         int i = 0;
31         while(g_array_index(list, gchar*, i) != NULL) 
32         {
33                 printf("  %d. : %s\n",i+1,g_array_index(list, gchar*, i));
34                 i++;
35         }
36         printf("--------------------------------------------------\n");
37 }
38
39 void print_translation(gchar* translation, gchar* word, gpointer user_data, EngineStatus error) {
40         printf((gchar*)user_data,word);
41         printf("%s\n\nTRANSLATION ENDS.\n",translation);
42 }
43
44 void caching_progress(gdouble value, gpointer user_data, EngineStatus error) {
45         printf((gchar*)user_data,value);
46 }
47
48 int main(int argc, char** argv) 
49 {
50         char* nameApp = "StarDictEngine test: ";
51         printf("%sStarting test program of module: dictionary_engine.\n",nameApp);
52
53         
54         gchar* current_directory = g_get_current_dir();
55         printf("%sCurrent directory: %s\n",nameApp,current_directory);
56         gchar* library_to_path = g_strconcat(current_directory, "/ws_bookmark.so", NULL);
57         printf("%sEngine library should be in location:\n\t%s\n",nameApp,library_to_path);
58         
59         GModule *library = g_module_open(library_to_path, G_MODULE_BIND_LAZY);
60         if(!library) {
61                 printf("%sLoading module failed. \nReason: %s\n",nameApp,g_module_error());
62                 return 1;               
63         };
64         
65         //dict_eng_module_get_global_functions(library,get_functions);
66         g_module_symbol ( (library),_GLOBAL_FUNCTIONS_NAME_, (gpointer)&get_functions);
67         if(get_functions == NULL) {
68                 printf("%sLoading function failed\n",nameApp);
69                 return 2;
70         }
71         else printf("%sLoading function OK\n",nameApp);
72
73         EngineModule module = get_functions();
74         printf("Module description: %s\n",dict_eng_module_get_description(module));
75         Engine* sd;
76
77         gboolean is_compatible = dict_eng_module_check(module,"/home/str/whitestork/engines/bookmark/ws_bookmarks");
78         if(is_compatible == TRUE)
79         {
80                 printf("Location is compatible with enigne!\n");
81         }
82         else {
83                 printf("Location is not compatible with enigne!\n");
84                 return 1;
85         }
86
87         //printf("%sCheck OK. Module description: %s\n", nameApp, dict_eng_module_get_description(module));
88
89         //xdxf = dict_eng_module_create_ext(module, "/home/lukasz/MyDocs/repo/WhiteStork/trunk/engine/bin" , ENGINE_CREATE, caching_progress, "Current progress of caching is: %0.2f.\n", 0.03 );
90         //home/stranger/whitestork/engine0.2/
91 //      xdxf = dict_eng_module_create(module, "/home/stranger/whitestork/engine0.2/" , ENGINE_NO);
92 //      dict_eng_set_callback(xdxf, ENGINE_PROGRESS_CACHING, caching_progress, "Current progress of caching is: %0.2f.\n");
93 //      dict_eng_set_progress_seed(xdxf, ENGINE_PROGRESS_CACHING, 0.02);
94
95 /*      if(dict_eng_is_optimized(xdxf) == FALSE)
96         {
97                 printf("Dictionary has no cache!\nCreating cache file....\n");
98                 dict_eng_optimize(xdxf);
99         }
100         else {
101                 printf("Dictionary has already cache file!\n");
102         }*/
103         sd = dict_eng_module_create(module,
104              "/home/str/whitestork/engines/bookmark/ws_bookmarks" ,
105              ENGINE_CREATE);
106         printf("Lokacja: %s\n",dict_eng_get_location(sd));
107
108         dict_eng_set_callback(sd,
109                               ENGINE_WORD_LIST_SIGNAL,
110                               print_list,
111                               "Word list matches to pattern: %s\n"
112                              );
113         dict_eng_set_callback(sd,
114                               ENGINE_WORD_TRANSLATION_SIGNAL ,
115                               print_translation,
116                               "Translation for word\'%s\':\n");
117         
118         dict_eng_search_word_list(sd,"12");
119         //dict_eng_search_word_translation(sd,"1 word");
120         
121         dict_eng_remove_word(sd, "stranger");
122         dict_eng_remove_word(sd, "gandzia");
123         dict_eng_remove_word(sd, "lukas");
124         dict_eng_add_word(sd, "stranger", "autor pluginu tego wlasnie to jest!");
125         dict_eng_add_word(sd, "gandzia", "rulez");
126         dict_eng_add_word(sd, "lukas", "pawlik");
127         dict_eng_remove_word(sd, "stranger");
128
129         dict_eng_search_word_translation(sd,"stranger");
130         
131         dict_eng_add_word(sd, "stranger", "autor pluginu tego wlasnie to jest!");
132         dict_eng_search_word_translation(sd,"stranger");
133         dict_eng_search_word_list(sd,"gandzia");
134
135         printf("Lang FROM:%s\n",dict_eng_get_lang_from(sd));
136         printf("  Lang TO:%s\n",dict_eng_get_lang_to(sd));
137         printf("    Title:%s\n",dict_eng_get_title(sd));
138         printf("Icon path:%s\n",dict_eng_get_icon_path(sd));
139         
140         dict_eng_destroy(sd);
141         printf("%sClosed.\n",nameApp);  
142         return 0;
143 }
144