~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/business/business-core/test/test-vendor.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-vendor.c
 
3
 * Test the vendor object.
 
4
 * 
 
5
 * Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
 
6
 * Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU General Public License as
 
10
 * published by the Free Software Foundation; either version 2 of
 
11
 * the License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, contact:
 
20
 *
 
21
 * Free Software Foundation           Voice:  +1-617-542-5942
 
22
 * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
 
23
 * Boston, MA  02110-1301,  USA       gnu@gnu.org
 
24
 *
 
25
 *********************************************************************/
 
26
 
 
27
#include "config.h"
 
28
#include <glib.h>
 
29
#include "gncInvoiceP.h"
 
30
#include "gncCustomerP.h"
 
31
#include "gncJobP.h"
 
32
#include "gncVendorP.h"
 
33
#include "test-stuff.h"
 
34
 
 
35
static int count = 0;
 
36
 
 
37
static void
 
38
test_string_fcn (QofBook *book, const char *message,
 
39
                 void (*set) (GncVendor *, const char *str),
 
40
                 const char * (*get)(GncVendor *));
 
41
 
 
42
#if 0
 
43
static void
 
44
test_numeric_fcn (QofBook *book, const char *message,
 
45
                  void (*set) (GncVendor *, gnc_numeric),
 
46
                  gnc_numeric (*get)(GncVendor *));
 
47
#endif
 
48
 
 
49
static void
 
50
test_bool_fcn (QofBook *book, const char *message,
 
51
                  void (*set) (GncVendor *, gboolean),
 
52
                  gboolean (*get) (GncVendor *));
 
53
 
 
54
#if 0
 
55
static void
 
56
test_gint_fcn (QofBook *book, const char *message,
 
57
               void (*set) (GncVendor *, gint),
 
58
               gint (*get) (GncVendor *));
 
59
#endif
 
60
 
 
61
static void
 
62
test_vendor (void)
 
63
{
 
64
  QofBackend *be;
 
65
  QofSession *session;
 
66
  QofBook *book;
 
67
  GncVendor *vendor;
 
68
 
 
69
  session = qof_session_new();
 
70
  be = NULL;
 
71
  qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
 
72
  book = qof_session_get_book (session);
 
73
  be = qof_book_get_backend(book);
 
74
 
 
75
  /* The book *must* have a backend to pass the test of the 'dirty' flag */
 
76
  /* See the README file for details */
 
77
  do_test (be != NULL, "qsf backend could not be set");
 
78
 
 
79
  /* Test creation/destruction */
 
80
  {
 
81
    do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL");
 
82
    vendor = gncVendorCreate (book);
 
83
    do_test (vendor != NULL, "vendor create");
 
84
    do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book,
 
85
             "getbook");
 
86
 
 
87
    gncVendorBeginEdit (vendor);
 
88
    gncVendorDestroy (vendor);
 
89
    success ("create/destroy");
 
90
  }
 
91
 
 
92
  /* Test setting/getting routines; does the active flag get set right? */
 
93
  {
 
94
    GUID guid;
 
95
 
 
96
    test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
 
97
    test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
 
98
    test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);
 
99
 
 
100
    //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);
 
101
 
 
102
    //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
 
103
    test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);
 
104
 
 
105
    do_test (gncVendorGetAddr (vendor) != NULL, "Addr");
 
106
 
 
107
    guid_new (&guid);
 
108
    vendor = gncVendorCreate (book); count++;
 
109
    gncVendorSetGUID (vendor, &guid);
 
110
    do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
 
111
  }
 
112
#if 0
 
113
  {
 
114
    GList *list;
 
115
 
 
116
    list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE);
 
117
    do_test (list != NULL, "getList all");
 
118
    do_test (g_list_length (list) == count, "correct length: all");
 
119
    g_list_free (list);
 
120
 
 
121
    list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE);
 
122
    do_test (list != NULL, "getList active");
 
123
    do_test (g_list_length (list) == 1, "correct length: active");
 
124
    g_list_free (list);
 
125
  }
 
126
#endif
 
127
  {
 
128
    const char *str = get_random_string();
 
129
    const char *res;
 
130
 
 
131
    gncVendorSetName (vendor, str);
 
132
    res = qof_object_printable (GNC_ID_VENDOR, vendor);
 
133
    do_test (res != NULL, "Printable NULL?");
 
134
    do_test (safe_strcmp (str, res) == 0, "Printable equals");
 
135
  }    
 
136
}
 
137
 
 
138
static void
 
139
test_string_fcn (QofBook *book, const char *message,
 
140
                 void (*set) (GncVendor *, const char *str),
 
141
                 const char * (*get)(GncVendor *))
 
142
{
 
143
  GncVendor *vendor = gncVendorCreate (book);
 
144
  char const *str = get_random_string ();
 
145
 
 
146
  do_test (!gncVendorIsDirty (vendor), "test if start dirty");
 
147
  gncVendorBeginEdit (vendor);
 
148
  set (vendor, str);
 
149
  do_test (gncVendorIsDirty (vendor), "test dirty later");
 
150
  gncVendorCommitEdit (vendor);
 
151
  do_test (gncVendorIsDirty (vendor), "test dirty after commit");
 
152
  do_test (safe_strcmp (get (vendor), str) == 0, message);
 
153
  gncVendorSetActive (vendor, FALSE); count++;
 
154
}
 
155
 
 
156
#if 0
 
157
static void
 
158
test_numeric_fcn (QofBook *book, const char *message,
 
159
                  void (*set) (GncVendor *, gnc_numeric),
 
160
                  gnc_numeric (*get)(GncVendor *))
 
161
{
 
162
  GncVendor *vendor = gncVendorCreate (book);
 
163
  gnc_numeric num = gnc_numeric_create (17, 1);
 
164
 
 
165
  do_test (!gncVendorIsDirty (vendor), "test if start dirty");
 
166
  gncVendoryBeginEdit (vendor);
 
167
  set (vendor, num);
 
168
  do_test (gncVendorIsDirty (vendor), "test dirty later");
 
169
  gncVendorCommitEdit (vendor);
 
170
  do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
 
171
  do_test (gnc_numeric_equal (get (vendor), num), message);
 
172
  gncVendorSetActive (vendor, FALSE); count++;
 
173
}
 
174
#endif
 
175
 
 
176
static void
 
177
test_bool_fcn (QofBook *book, const char *message,
 
178
               void (*set) (GncVendor *, gboolean),
 
179
               gboolean (*get) (GncVendor *))
 
180
{
 
181
  GncVendor *vendor = gncVendorCreate (book);
 
182
  gboolean num = get_random_boolean ();
 
183
 
 
184
  do_test (!gncVendorIsDirty (vendor), "test if start dirty");
 
185
  gncVendorBeginEdit (vendor);
 
186
  set (vendor, FALSE);
 
187
  set (vendor, TRUE);
 
188
  set (vendor, num);
 
189
  do_test (gncVendorIsDirty (vendor), "test dirty later");
 
190
  gncVendorCommitEdit (vendor);
 
191
  do_test (gncVendorIsDirty (vendor), "test dirty after commit");
 
192
  do_test (get (vendor) == num, message);
 
193
  gncVendorSetActive (vendor, FALSE); count++;
 
194
}
 
195
 
 
196
#if 0
 
197
static void
 
198
test_gint_fcn (QofBook *book, const char *message,
 
199
               void (*set) (GncVendor *, gint),
 
200
               gint (*get) (GncVendor *))
 
201
{
 
202
  GncVendor *vendor = gncVendorCreate (book);
 
203
  gint num = 17;
 
204
 
 
205
  do_test (!gncVendorIsDirty (vendor), "test if start dirty");
 
206
  gncVendorBeginEdit (vendor);
 
207
  set (vendor, num);
 
208
  do_test (gncVendorIsDirty (vendor), "test dirty later");
 
209
  gncVendorCommitEdit (vendor);
 
210
  do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
 
211
  do_test (get (vendor) == num, message);
 
212
  gncVendorSetActive (vendor, FALSE); count++;
 
213
}
 
214
#endif
 
215
 
 
216
int
 
217
main (int argc, char **argv)
 
218
{
 
219
  qof_init();
 
220
  do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
 
221
  do_test (gncJobRegister (),  "Cannot register GncJob");
 
222
  do_test (gncCustomerRegister(), "Cannot register GncCustomer");
 
223
  do_test (gncVendorRegister(), "Cannot register GncVendor");           
 
224
  test_vendor();
 
225
  print_test_results();
 
226
  qof_close();
 
227
  return 0;
 
228
}