GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-business.c
1 /*********************************************************************
2  * test-business.c
3  * Test the business code.
4  *
5  * Copyright (c) 2001 Derek Atkins <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, contact:
19  *
20  * Free Software Foundation Voice: +1-617-542-5942
21  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
22  * Boston, MA 02110-1301, USA [email protected]
23  *
24  *********************************************************************/
25 
26 #include "config.h"
27 #include <glib.h>
28 #include <libguile.h>
29 
30 #include "qof.h"
31 #include "gnc-module.h"
32 
33 #include "gncBusiness.h"
34 #include "test-stuff.h"
35 
36 #define TEST_MODULE_NAME "business-test"
37 #define TEST_MODULE_DESC "Test Business"
38 
39 #if 0
40 static GList * get_list (QofBook *, gboolean show_all);
41 static const char * printable (gpointer obj);
42 static void test_printable (const char *name, gpointer obj);
43 static void test_get_list (QofBook *, const char *);
44 
45 static GncBusinessObject bus_obj =
46 {
47  GNC_BUSINESS_VERSION,
48  TEST_MODULE_NAME,
49  TEST_MODULE_DESC,
50  NULL, /* create */
51  NULL, /* destroy */
52  get_list,
53  printable,
54 };
55 
56 static void test_business (void)
57 {
58  /* Test the global registration and lookup functions */
59  {
60  do_test (!gncBusinessRegister (NULL), "register NULL");
61  do_test (gncBusinessRegister (&bus_obj), "register test object");
62  do_test (!gncBusinessRegister (&bus_obj), "register test object again");
63  do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj,
64  "lookup our installed object");
65  do_test (gncBusinessLookup ("snm98sn snml say dyikh9y9ha") == NULL,
66  "lookup non-existant business object");
67 
68  do_test (!g_strcmp0 (gncBusinessGetTypeLabel (TEST_MODULE_NAME),
69  _(TEST_MODULE_DESC)),
70  "test description return");
71  }
72 
73  test_get_list ((QofBook*)1, TEST_MODULE_NAME);
74  test_printable (TEST_MODULE_NAME, (gpointer)1);
75 }
76 
77 static GList *
78 get_list (QofBook *book, gboolean show_all)
79 {
80  do_test (book != NULL, "get_list: NULL business");
81  success ("called get_list callback");
82  return ((GList *)1);
83 }
84 
85 static const char *
86 printable (gpointer obj)
87 {
88  do_test (obj != NULL, "printable: object is NULL");
89  success ("called printable callback");
90  return ((const char *)obj);
91 }
92 
93 static void
94 test_get_list (QofBook *book, const char *name)
95 {
96  GList *res;
97 
98  do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL,
99  "business: GetList: NULL, NULL, FALSE");
100  do_test (gncBusinessGetList (NULL, name, FALSE) == NULL,
101  "business: GetList: NULL, mod_name, FALSE");
102  do_test (gncBusinessGetList (book, NULL, FALSE) == NULL,
103  "business: GetList: book, NULL, FALSE");
104  res = gncBusinessGetList (book, name, FALSE);
105  do_test (res != NULL, "business: GetList: book, mod_name, FALSE");
106 }
107 
108 static void
109 test_printable (const char *name, gpointer obj)
110 {
111  const char *res;
112 
113  do_test (gncBusinessPrintable (NULL, NULL) == NULL,
114  "business: Printable: NULL, NULL");
115  do_test (gncBusinessPrintable (NULL, obj) == NULL,
116  "business: Printable: NULL, object");
117  do_test (gncBusinessPrintable (name, NULL) == NULL,
118  "business: Printable: mod_name, NULL");
119  res = gncBusinessPrintable (name, obj);
120  do_test (res != NULL, "business: Printable: mod_name, object");
121 }
122 
123 static void
124 main_helper (void *closure, int argc, char **argv)
125 {
126  gnc_module_load("gnucash/engine", 0);
127  test_business();
128  print_test_results();
129  exit(get_rv());
130 }
131 #endif
132 
133 int
134 main (int argc, char **argv)
135 {
136  g_setenv ("GNC_UNINSTALLED", "1", TRUE);
137  // scm_boot_guile (argc, argv, main_helper, NULL);
138  return get_rv();
139 }
GList * gncBusinessGetList(QofBook *book, QofIdTypeConst type_name, gboolean all_including_inactive)