GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utest-Invoice.c
1 /********************************************************************
2  * test_qofbook.c: GLib g_test test suite for qofbook. *
3  * Copyright 2012 Christian Stimming <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA [email protected] *
21 \********************************************************************/
22 #include "config.h"
23 #include <string.h>
24 #include <glib.h>
25 #include <qof.h>
26 #include <unittest-support.h>
27 #include "../gncInvoice.h"
28 
29 static const gchar *suitename = "/engine/gncInvoice";
30 void test_suite_gncInvoice ( void );
31 
32 typedef struct
33 {
34  QofBook *book;
35  Account *account;
36  GncOwner owner;
37  GncCustomer *customer;
38  gnc_commodity *commodity;
39 } Fixture;
40 
41 static void
42 setup( Fixture *fixture, gconstpointer pData )
43 {
44  fixture->book = qof_book_new();
45 
46  fixture->account = xaccMallocAccount(fixture->book);
47  fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100);
48  xaccAccountSetCommodity(fixture->account, fixture->commodity);
49 
50  fixture->customer = gncCustomerCreate(fixture->book);
51  gncOwnerInitCustomer(&fixture->owner, fixture->customer);
52 }
53 
54 static void
55 teardown( Fixture *fixture, gconstpointer pData )
56 {
57  gncCustomerBeginEdit(fixture->customer);
58  gncCustomerDestroy(fixture->customer);
59 
60  xaccAccountBeginEdit(fixture->account);
61  xaccAccountDestroy(fixture->account);
62  gnc_commodity_destroy(fixture->commodity);
63 
64  qof_book_destroy( fixture->book );
65 }
66 
67 
68 static void
69 test_invoice_post ( Fixture *fixture, gconstpointer pData )
70 {
71  GncInvoice *invoice = gncInvoiceCreate(fixture->book);
72  Timespec ts1 = timespec_now(), ts2 = ts1;
73  g_assert(invoice);
74  g_assert(!gncInvoiceGetIsCreditNote(invoice));
75  g_assert(gncInvoiceGetActive(invoice));
76  g_assert(gncInvoiceGetPostedAcc(invoice) == NULL);
77 
78  gncInvoiceSetCurrency(invoice, fixture->commodity);
79 
80  gncInvoiceSetOwner(invoice, &fixture->owner);
81 
82  g_test_message( "Will now post the invoice" );
83  g_assert(!gncInvoiceIsPosted(invoice));
84  gncInvoicePostToAccount(invoice, fixture->account, &ts1, &ts2, "memo", TRUE, FALSE);
85  g_assert(gncInvoiceIsPosted(invoice));
86 
87  gncInvoiceUnpost(invoice, TRUE);
88  g_assert(!gncInvoiceIsPosted(invoice));
89 }
90 
91 void
92 test_suite_gncInvoice ( void )
93 {
94  GNC_TEST_ADD( suitename, "post", Fixture, NULL, setup, test_invoice_post, teardown );
95 }
QofBook * qof_book_new(void)
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
void xaccAccountDestroy(Account *acc)
Definition: Account.c:1400
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Transaction * gncInvoicePostToAccount(GncInvoice *invoice, Account *acc, Timespec *post_date, Timespec *due_date, const char *memo, gboolean accumulatesplits, gboolean autopay)
Definition: gncInvoice.c:1363
gboolean gncInvoiceUnpost(GncInvoice *invoice, gboolean reset_tax_tables)
Definition: gncInvoice.c:1621
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
Timespec timespec_now(void)
Account * xaccMallocAccount(QofBook *book)
Definition: Account.c:1083
void gnc_commodity_destroy(gnc_commodity *cm)
void qof_book_destroy(QofBook *book)
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Definition: Account.c:2389