30 #include <qofinstance-p.h>
32 #include "cashobjects.h"
33 #include "gncCustomerP.h"
34 #include "gncInvoiceP.h"
36 #include "test-stuff.h"
41 test_string_fcn (
QofBook *book,
const char *message,
46 test_numeric_fcn (
QofBook *book,
const char *message,
51 test_bool_fcn (
QofBook *book,
const char *message,
65 do_test (gncCustomerCreate (NULL) == NULL,
"customer create NULL");
66 customer = gncCustomerCreate (book);
67 do_test (customer != NULL,
"customer create");
68 do_test (gncCustomerGetBook (customer) == book,
"getbook");
70 gncCustomerBeginEdit (customer);
71 gncCustomerDestroy (customer);
72 success (
"create/destroy");
79 test_string_fcn (book,
"Id", gncCustomerSetID, gncCustomerGetID);
80 test_string_fcn (book,
"Name", gncCustomerSetName, gncCustomerGetName);
81 test_string_fcn (book,
"Notes", gncCustomerSetNotes, gncCustomerGetNotes);
85 test_numeric_fcn (book,
"Discount", gncCustomerSetDiscount, gncCustomerGetDiscount);
86 test_numeric_fcn (book,
"Credit", gncCustomerSetCredit, gncCustomerGetCredit);
88 test_bool_fcn (book,
"Active", gncCustomerSetActive, gncCustomerGetActive);
90 do_test (gncCustomerGetAddr (customer) != NULL,
"Addr");
91 do_test (gncCustomerGetShipAddr (customer) != NULL,
"ShipAddr");
94 customer = gncCustomerCreate (book);
96 gncCustomerSetGUID (customer, &guid);
103 do_test (list != NULL,
"getList all");
104 do_test (g_list_length (list) == count,
"correct length: all");
108 do_test (list != NULL,
"getList active");
109 do_test (g_list_length (list) == 1,
"correct length: active");
113 const char *str = get_random_string();
117 gncCustomerBeginEdit(customer);
118 gncCustomerSetName (customer, str);
119 gncCustomerCommitEdit(customer);
121 do_test (res != NULL,
"Printable NULL?");
122 do_test (g_strcmp0 (str, res) == 0,
"Printable equals");
125 do_test (gncCustomerGetJoblist (customer, TRUE) == NULL,
"joblist empty");
132 do_test (gncCustomerLookup (book, guid) == customer,
"Entity Table");
140 test_string_fcn (
QofBook *book,
const char *message,
145 char const *str = get_random_string ();
147 do_test (!gncCustomerIsDirty (customer),
"test if start dirty");
148 gncCustomerBeginEdit (customer);
151 do_test (gncCustomerIsDirty (customer),
"test dirty later");
152 gncCustomerCommitEdit (customer);
159 do_test (g_strcmp0 (
get (customer), str) == 0, message);
160 gncCustomerSetActive (customer, FALSE);
165 test_numeric_fcn (
QofBook *book,
const char *message,
172 do_test (!gncCustomerIsDirty (customer),
"test if start dirty");
173 gncCustomerBeginEdit (customer);
176 do_test (gncCustomerIsDirty (customer),
"test dirty later");
177 gncCustomerCommitEdit (customer);
185 gncCustomerSetActive (customer, FALSE);
190 test_bool_fcn (
QofBook *book,
const char *message,
195 gboolean num = get_random_boolean ();
197 do_test (!gncCustomerIsDirty (customer),
"test if start dirty");
198 gncCustomerBeginEdit (customer);
199 set (customer, FALSE);
200 set (customer, TRUE);
203 do_test (gncCustomerIsDirty (customer),
"test dirty later");
204 gncCustomerCommitEdit (customer);
211 do_test (
get (customer) == num, message);
212 gncCustomerSetActive (customer, FALSE);
217 main (
int argc,
char **argv)
220 do_test (cashobjects_register(),
"Cannot register cash objects");
224 do_test (gncInvoiceRegister(),
"Cannot register GncInvoice");
225 do_test (gncJobRegister (),
"Cannot register GncJob");
226 do_test (gncCustomerRegister(),
"Cannot register GncCustomer");
229 print_test_results();
void guid_replace(GncGUID *guid)
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
QofBook * qof_book_new(void)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
#define gncCustomerGetGUID(x)
void qof_close(void)
Safely close down the Query Object Framework.
GList * gncBusinessGetList(QofBook *book, QofIdTypeConst type_name, gboolean all_including_inactive)
const char * qof_object_printable(QofIdTypeConst type_name, gpointer instance)
void qof_init(void)
Initialise the Query Object Framework.
void qof_book_destroy(QofBook *book)