GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-dbi-business-stuff.c
1 /***************************************************************************
2  * test-dbi-business-stuff.c
3  *
4  * Tests saving and loading business objects to a dbi/sqlite3 db
5  *
6  * Copyright (C) 2010 Phil Longstaff <[email protected]>
7  ****************************************************************************/
8 
9 /*
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301, USA.
24  */
25 
26 #include "config.h"
27 #include "qof.h"
28 #include "cashobjects.h"
29 #include "test-engine-stuff.h"
30 #include "test-stuff.h"
31 #include "test-dbi-stuff.h"
32 #include "test-dbi-business-stuff.h"
33 #include <unittest-support.h>
34 
35 #include "Account.h"
36 #include "Split.h"
37 #include "Transaction.h"
38 #include "gnc-commodity.h"
39 #include "gncCustomer.h"
40 #include "gncInvoice.h"
41 #include "gncEmployee.h"
42 #include "gncVendor.h"
43 
44 G_GNUC_UNUSED static QofLogModule log_module = "test-dbi";
45 
46 static void
47 compare_single_customer( QofInstance* inst, gpointer user_data )
48 {
49  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
50  GncCustomer* cust_1 = GNC_CUSTOMER(inst);
51  GncCustomer* cust_2 = gncCustomerLookup( info->book_2, qof_instance_get_guid(inst) );
52 
53  if (!gncCustomerEqual( cust_1, cust_2 ))
54  {
55  info->result = FALSE;
56  }
57 }
58 
59 static void
60 compare_customers( QofBook* book_1, QofBook* book_2 )
61 {
62  do_compare( book_1, book_2, GNC_ID_CUSTOMER, compare_single_customer, "Customer lists match" );
63 }
64 
65 static void
66 compare_single_employee( QofInstance* inst, gpointer user_data )
67 {
68  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
69  GncEmployee* emp_1 = GNC_EMPLOYEE(inst);
70  GncEmployee* emp_2 = gncEmployeeLookup( info->book_2, qof_instance_get_guid(inst) );
71 
72  if (!gncEmployeeEqual( emp_1, emp_2 ))
73  {
74  info->result = FALSE;
75  }
76 }
77 
78 static void
79 compare_employees( QofBook* book_1, QofBook* book_2 )
80 {
81  do_compare( book_1, book_2, GNC_ID_EMPLOYEE, compare_single_employee, "Employee lists match" );
82 }
83 
84 static void
85 compare_single_invoice( QofInstance* inst, gpointer user_data )
86 {
87  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
88  GncInvoice* inv_1 = GNC_INVOICE(inst);
89  GncInvoice* inv_2 = gncInvoiceLookup( info->book_2, qof_instance_get_guid(inst) );
90 
91  if (!gncInvoiceEqual( inv_1, inv_2 ))
92  {
93  info->result = FALSE;
94  }
95 }
96 
97 static void
98 compare_invoices( QofBook* book_1, QofBook* book_2 )
99 {
100  do_compare( book_1, book_2, GNC_ID_INVOICE, compare_single_invoice, "Invoice lists match" );
101 }
102 
103 static void
104 compare_single_job( QofInstance* inst, gpointer user_data )
105 {
106  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
107  GncJob* job_1 = GNC_JOB(inst);
108  GncJob* job_2 = gncJobLookup( info->book_2, qof_instance_get_guid(inst) );
109 
110  if (!gncJobEqual( job_1, job_2 ))
111  {
112  info->result = FALSE;
113  }
114 }
115 
116 static void
117 compare_jobs( QofBook* book_1, QofBook* book_2 )
118 {
119  do_compare( book_1, book_2, GNC_ID_JOB, compare_single_job, "Job lists match" );
120 }
121 
122 static void
123 compare_single_vendor( QofInstance* inst, gpointer user_data )
124 {
125  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
126  GncVendor* vendor_1 = GNC_VENDOR(inst);
127  GncVendor* vendor_2 = gncVendorLookup( info->book_2, qof_instance_get_guid(inst) );
128 
129  if (!gncVendorEqual( vendor_1, vendor_2 ))
130  {
131  info->result = FALSE;
132  }
133 }
134 
135 static void
136 compare_vendors( QofBook* book_1, QofBook* book_2 )
137 {
138  do_compare( book_1, book_2, GNC_ID_VENDOR, compare_single_vendor, "Vendor lists match" );
139 }
140 
141 static void
142 compare_single_billterm( QofInstance* inst, gpointer user_data )
143 {
144  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
145  GncBillTerm* bt_1 = GNC_BILLTERM(inst);
146  GncBillTerm* bt_2 = gncBillTermLookup( info->book_2, qof_instance_get_guid(inst) );
147 
148  if (!gncBillTermEqual( bt_1, bt_2 ))
149  {
150  info->result = FALSE;
151  }
152 }
153 
154 static void
155 compare_billterms( QofBook* book_1, QofBook* book_2 )
156 {
157  do_compare( book_1, book_2, GNC_ID_BILLTERM, compare_single_billterm, "Billterms lists match" );
158 }
159 
160 static void
161 compare_single_taxtable( QofInstance* inst, gpointer user_data )
162 {
163  CompareInfoStruct* info = (CompareInfoStruct*)user_data;
164  GncTaxTable* tt_1 = GNC_TAXTABLE(inst);
165  GncTaxTable* tt_2 = gncTaxTableLookup( info->book_2, qof_instance_get_guid(inst) );
166 
167  if (!gncTaxTableEqual( tt_1, tt_2 ))
168  {
169  info->result = FALSE;
170  }
171 }
172 
173 static void
174 compare_taxtables( QofBook* book_1, QofBook* book_2 )
175 {
176  do_compare( book_1, book_2, GNC_ID_TAXTABLE, compare_single_taxtable, "TaxTable lists match" );
177 }
178 
179 void
180 compare_business_books( QofBook* book_1, QofBook* book_2 )
181 {
182  compare_billterms( book_1, book_2 );
183  compare_taxtables( book_1, book_2 );
184 
185  compare_customers( book_1, book_2 );
186  compare_employees( book_1, book_2 );
187  compare_invoices( book_1, book_2 );
188  compare_jobs( book_1, book_2 );
189  compare_vendors( book_1, book_2 );
190 }
191 
Core Customer Interface.
const GncGUID * qof_instance_get_guid(gconstpointer)
API for Transactions and Splits (journal entries)
gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b)
Definition: gncBillTerm.c:647
Account handling public routines.
Definition: gncJob.c:41
Business Invoice Interface.
gboolean gncCustomerEqual(const GncCustomer *a, const GncCustomer *b)
Definition: gncCustomer.c:741
Employee Interface.
gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b)
Definition: gncVendor.c:810
Vendor Interface.
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b)
Definition: gncInvoice.c:1926
API for Transactions and Splits (journal entries)
Commodity handling public routines.
const gchar * QofLogModule
Definition: qofid.h:89
gboolean gncEmployeeEqual(const GncEmployee *a, const GncEmployee *b)
Definition: gncEmployee.c:751