~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/business/business-core/test/test-business.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************
 
2
 * test-business.c
 
3
 * Test the business code.
 
4
 * 
 
5
 * Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
 
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       gnu@gnu.org
 
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
  GNC_BUSINESS_VERSION,
 
47
  TEST_MODULE_NAME,
 
48
  TEST_MODULE_DESC,
 
49
  NULL,                         /* create */
 
50
  NULL,                         /* destroy */
 
51
  get_list,
 
52
  printable,
 
53
};
 
54
 
 
55
static void test_business (void)
 
56
{
 
57
  /* Test the global registration and lookup functions */
 
58
  {
 
59
    do_test (!gncBusinessRegister (NULL), "register NULL");
 
60
    do_test (gncBusinessRegister (&bus_obj), "register test object");
 
61
    do_test (!gncBusinessRegister (&bus_obj), "register test object again");
 
62
    do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj,
 
63
             "lookup our installed object");
 
64
    do_test (gncBusinessLookup ("snm98sn snml say  dyikh9y9ha") == NULL,
 
65
             "lookup non-existant business object");
 
66
 
 
67
    do_test (!safe_strcmp (gncBusinessGetTypeLabel (TEST_MODULE_NAME),
 
68
                      _(TEST_MODULE_DESC)),
 
69
             "test description return");
 
70
  }
 
71
 
 
72
  test_get_list ((QofBook*)1, TEST_MODULE_NAME);
 
73
  test_printable (TEST_MODULE_NAME, (gpointer)1);
 
74
}
 
75
 
 
76
static GList *
 
77
get_list (QofBook *book, gboolean show_all)
 
78
{
 
79
  do_test (book != NULL, "get_list: NULL business");
 
80
  success ("called get_list callback");
 
81
  return ((GList *)1);
 
82
}
 
83
 
 
84
static const char *
 
85
printable (gpointer obj)
 
86
{
 
87
  do_test (obj != NULL, "printable: object is NULL");
 
88
  success ("called printable callback");
 
89
  return ((const char *)obj);
 
90
}
 
91
 
 
92
static void
 
93
test_get_list (QofBook *book, const char *name)
 
94
{
 
95
  GList *res;
 
96
 
 
97
  do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL,
 
98
           "business: GetList: NULL, NULL, FALSE");
 
99
  do_test (gncBusinessGetList (NULL, name, FALSE) == NULL,
 
100
           "business: GetList: NULL, mod_name, FALSE");
 
101
  do_test (gncBusinessGetList (book, NULL, FALSE) == NULL,
 
102
           "business: GetList: book, NULL, FALSE");
 
103
  res = gncBusinessGetList (book, name, FALSE);
 
104
  do_test (res != NULL, "business: GetList: book, mod_name, FALSE");
 
105
}
 
106
 
 
107
static void
 
108
test_printable (const char *name, gpointer obj)
 
109
{
 
110
  const char *res;
 
111
 
 
112
  do_test (gncBusinessPrintable (NULL, NULL) == NULL,
 
113
           "business: Printable: NULL, NULL");
 
114
  do_test (gncBusinessPrintable (NULL, obj) == NULL,
 
115
           "business: Printable: NULL, object");
 
116
  do_test (gncBusinessPrintable (name, NULL) == NULL,
 
117
           "business: Printable: mod_name, NULL");
 
118
  res = gncBusinessPrintable (name, obj);
 
119
  do_test (res != NULL, "business: Printable: mod_name, object");
 
120
}
 
121
 
 
122
static void
 
123
main_helper (void *closure, int argc, char **argv)
 
124
{
 
125
  gnc_module_load("gnucash/business-core", 0);
 
126
  test_business();
 
127
  print_test_results();
 
128
  exit(get_rv());
 
129
}
 
130
#endif
 
131
 
 
132
int
 
133
main (int argc, char **argv)
 
134
{
 
135
  //  scm_boot_guile (argc, argv, main_helper, NULL);
 
136
  return 0;
 
137
}