Bookmark BDB and XDXF engine has been cleaned from some bugs.
[mdictionary] / src / bookmarks / bdb / 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\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 = "BerkeleyDB Bookmark Engine 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* bm;
76
77         gboolean is_compatible = dict_eng_module_check(module,"/home/str/whitestork/engines/berkeleyBookmark/data");
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         bm = dict_eng_module_create(module,
88              "/home/str/whitestork/engines/berkeleyBookmark/data" ,
89              ENGINE_CREATE);
90         printf("Lokalizacja: %s\n",dict_eng_get_location(bm));
91
92         dict_eng_set_callback(bm,
93                               ENGINE_WORD_LIST_SIGNAL,
94                               print_list,
95                               "Word list matches to pattern: %s\n"
96                              );
97         dict_eng_set_callback(bm,
98                               ENGINE_WORD_TRANSLATION_SIGNAL ,
99                               print_translation,
100                               "Translation for word: \'%s\':\n");
101         
102         dict_eng_add_word(bm, "stranger", "translation number 1");
103         dict_eng_add_word(bm, "stranger", "translation number 2");
104         dict_eng_add_word(bm, "stranger", "translation number 3");
105         dict_eng_add_word(bm, "str", "translation number 1 shorter");
106         dict_eng_add_word(bm, "gandzia", "rulez forever!");
107         dict_eng_search_word_list(bm,"*");
108
109         //dict_eng_remove_word(bm, "stranger");
110         //dict_eng_search_word_list(bm,"*");
111
112         dict_eng_search_word_translation(bm,"stranger");
113
114         //dict_eng_remove_word(bm, "stranger");
115         //dict_eng_add_word(bm, "stranger", "author of the plugin you are using now!");
116         //dict_eng_add_word(bm, "stranger", "author of the plugin you are using now!");
117         //dict_eng_add_word(bm, "stranger", "He knows gandzia.");
118         //dict_eng_add_word(bm, "stranger", "He knows gandzia. 2 ");
119         //dict_eng_add_word(bm, "stranger", "He knows gandzia. 3");
120         //dict_eng_destroy(bm);
121         //dict_eng_add_word(bm, "gandzia", "super girl!");
122         //dict_eng_add_word(bm, "stranger", "He knows gandzia.");
123         //dict_eng_search_word_list(bm,"*");
124         //dict_eng_search_word_list(bm,"f");
125         //dict_eng_search_word_list(bm,"s");
126         //dict_eng_search_word_translation(sd,"1 word");
127         dict_eng_destroy(bm);
128         return 0;
129
130
131
132         dict_eng_remove_word(bm, "stranger");
133         dict_eng_remove_word(bm, "gandzia");
134         dict_eng_remove_word(bm, "lukas");
135         dict_eng_add_word(bm, "stranger", "autor pluginu tego wlasnie to jest!");
136         dict_eng_add_word(bm, "gandzia", "rulez");
137         dict_eng_add_word(bm, "lukas", "pawlik");
138         dict_eng_remove_word(bm, "stranger");
139
140         dict_eng_search_word_translation(bm,"stranger");
141         
142         dict_eng_add_word(bm, "stranger", "autor pluginu tego wlasnie to jest!");
143         dict_eng_search_word_translation(bm,"stranger");
144         dict_eng_search_word_list(bm,"gandzia");
145
146         printf("Lang FROM:%s\n",dict_eng_get_lang_from(bm));
147         printf("  Lang TO:%s\n",dict_eng_get_lang_to(bm));
148         printf("    Title:%s\n",dict_eng_get_title(bm));
149         printf("Icon path:%s\n",dict_eng_get_icon_path(bm));
150         
151         dict_eng_destroy(bm);
152         printf("%sClosed.\n",nameApp);  
153         return 0;
154 }
155