|
GnuCash 2.4.99
|
00001 /********************************************************************* 00002 * test-business.c 00003 * Test the business code. 00004 * 00005 * Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU> 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as 00009 * published by the Free Software Foundation; either version 2 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, contact: 00019 * 00020 * Free Software Foundation Voice: +1-617-542-5942 00021 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00022 * Boston, MA 02110-1301, USA gnu@gnu.org 00023 * 00024 *********************************************************************/ 00025 00026 #include "config.h" 00027 #include <glib.h> 00028 #include <libguile.h> 00029 00030 #include "qof.h" 00031 #include "gnc-module.h" 00032 00033 #include "gncBusiness.h" 00034 #include "test-stuff.h" 00035 00036 #define TEST_MODULE_NAME "business-test" 00037 #define TEST_MODULE_DESC "Test Business" 00038 00039 #if 0 00040 static GList * get_list (QofBook *, gboolean show_all); 00041 static const char * printable (gpointer obj); 00042 static void test_printable (const char *name, gpointer obj); 00043 static void test_get_list (QofBook *, const char *); 00044 00045 static GncBusinessObject bus_obj = 00046 { 00047 GNC_BUSINESS_VERSION, 00048 TEST_MODULE_NAME, 00049 TEST_MODULE_DESC, 00050 NULL, /* create */ 00051 NULL, /* destroy */ 00052 get_list, 00053 printable, 00054 }; 00055 00056 static void test_business (void) 00057 { 00058 /* Test the global registration and lookup functions */ 00059 { 00060 do_test (!gncBusinessRegister (NULL), "register NULL"); 00061 do_test (gncBusinessRegister (&bus_obj), "register test object"); 00062 do_test (!gncBusinessRegister (&bus_obj), "register test object again"); 00063 do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj, 00064 "lookup our installed object"); 00065 do_test (gncBusinessLookup ("snm98sn snml say dyikh9y9ha") == NULL, 00066 "lookup non-existant business object"); 00067 00068 do_test (!safe_strcmp (gncBusinessGetTypeLabel (TEST_MODULE_NAME), 00069 _(TEST_MODULE_DESC)), 00070 "test description return"); 00071 } 00072 00073 test_get_list ((QofBook*)1, TEST_MODULE_NAME); 00074 test_printable (TEST_MODULE_NAME, (gpointer)1); 00075 } 00076 00077 static GList * 00078 get_list (QofBook *book, gboolean show_all) 00079 { 00080 do_test (book != NULL, "get_list: NULL business"); 00081 success ("called get_list callback"); 00082 return ((GList *)1); 00083 } 00084 00085 static const char * 00086 printable (gpointer obj) 00087 { 00088 do_test (obj != NULL, "printable: object is NULL"); 00089 success ("called printable callback"); 00090 return ((const char *)obj); 00091 } 00092 00093 static void 00094 test_get_list (QofBook *book, const char *name) 00095 { 00096 GList *res; 00097 00098 do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL, 00099 "business: GetList: NULL, NULL, FALSE"); 00100 do_test (gncBusinessGetList (NULL, name, FALSE) == NULL, 00101 "business: GetList: NULL, mod_name, FALSE"); 00102 do_test (gncBusinessGetList (book, NULL, FALSE) == NULL, 00103 "business: GetList: book, NULL, FALSE"); 00104 res = gncBusinessGetList (book, name, FALSE); 00105 do_test (res != NULL, "business: GetList: book, mod_name, FALSE"); 00106 } 00107 00108 static void 00109 test_printable (const char *name, gpointer obj) 00110 { 00111 const char *res; 00112 00113 do_test (gncBusinessPrintable (NULL, NULL) == NULL, 00114 "business: Printable: NULL, NULL"); 00115 do_test (gncBusinessPrintable (NULL, obj) == NULL, 00116 "business: Printable: NULL, object"); 00117 do_test (gncBusinessPrintable (name, NULL) == NULL, 00118 "business: Printable: mod_name, NULL"); 00119 res = gncBusinessPrintable (name, obj); 00120 do_test (res != NULL, "business: Printable: mod_name, object"); 00121 } 00122 00123 static void 00124 main_helper (void *closure, int argc, char **argv) 00125 { 00126 gnc_module_load("gnucash/engine", 0); 00127 test_business(); 00128 print_test_results(); 00129 exit(get_rv()); 00130 } 00131 #endif 00132 00133 int 00134 main (int argc, char **argv) 00135 { 00136 g_setenv ("GNC_UNINSTALLED", "1", TRUE); 00137 // scm_boot_guile (argc, argv, main_helper, NULL); 00138 return get_rv(); 00139 }
1.7.4