1
/*********************************************************************
3
* Test the vendor object.
5
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
6
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
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.
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.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, contact:
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
25
*********************************************************************/
29
#include "gncInvoiceP.h"
30
#include "gncCustomerP.h"
32
#include "gncVendorP.h"
33
#include "test-stuff.h"
38
test_string_fcn (QofBook *book, const char *message,
39
void (*set) (GncVendor *, const char *str),
40
const char * (*get)(GncVendor *));
44
test_numeric_fcn (QofBook *book, const char *message,
45
void (*set) (GncVendor *, gnc_numeric),
46
gnc_numeric (*get)(GncVendor *));
50
test_bool_fcn (QofBook *book, const char *message,
51
void (*set) (GncVendor *, gboolean),
52
gboolean (*get) (GncVendor *));
56
test_gint_fcn (QofBook *book, const char *message,
57
void (*set) (GncVendor *, gint),
58
gint (*get) (GncVendor *));
69
session = qof_session_new();
71
qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
72
book = qof_session_get_book (session);
73
be = qof_book_get_backend(book);
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");
79
/* Test creation/destruction */
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,
87
gncVendorBeginEdit (vendor);
88
gncVendorDestroy (vendor);
89
success ("create/destroy");
92
/* Test setting/getting routines; does the active flag get set right? */
96
test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
97
test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
98
test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);
100
//test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);
102
//test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
103
test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);
105
do_test (gncVendorGetAddr (vendor) != NULL, "Addr");
108
vendor = gncVendorCreate (book); count++;
109
gncVendorSetGUID (vendor, &guid);
110
do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
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");
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");
128
const char *str = get_random_string();
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");
139
test_string_fcn (QofBook *book, const char *message,
140
void (*set) (GncVendor *, const char *str),
141
const char * (*get)(GncVendor *))
143
GncVendor *vendor = gncVendorCreate (book);
144
char const *str = get_random_string ();
146
do_test (!gncVendorIsDirty (vendor), "test if start dirty");
147
gncVendorBeginEdit (vendor);
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++;
158
test_numeric_fcn (QofBook *book, const char *message,
159
void (*set) (GncVendor *, gnc_numeric),
160
gnc_numeric (*get)(GncVendor *))
162
GncVendor *vendor = gncVendorCreate (book);
163
gnc_numeric num = gnc_numeric_create (17, 1);
165
do_test (!gncVendorIsDirty (vendor), "test if start dirty");
166
gncVendoryBeginEdit (vendor);
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++;
177
test_bool_fcn (QofBook *book, const char *message,
178
void (*set) (GncVendor *, gboolean),
179
gboolean (*get) (GncVendor *))
181
GncVendor *vendor = gncVendorCreate (book);
182
gboolean num = get_random_boolean ();
184
do_test (!gncVendorIsDirty (vendor), "test if start dirty");
185
gncVendorBeginEdit (vendor);
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++;
198
test_gint_fcn (QofBook *book, const char *message,
199
void (*set) (GncVendor *, gint),
200
gint (*get) (GncVendor *))
202
GncVendor *vendor = gncVendorCreate (book);
205
do_test (!gncVendorIsDirty (vendor), "test if start dirty");
206
gncVendorBeginEdit (vendor);
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++;
217
main (int argc, char **argv)
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");
225
print_test_results();