GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utest-Entry.c
1 /********************************************************************
2  * utest-Entry.c: GLib g_test test suite for gncEntry. *
3  * Copyright 2014 Geert Janssens <[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 "../gncEntry.h"
28 
29 static const gchar *suitename = "/engine/gncEntry";
30 void test_suite_gncEntry ( 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 }
51 
52 static void
53 teardown( Fixture *fixture, gconstpointer pData )
54 {
55  xaccAccountBeginEdit(fixture->account);
56  xaccAccountDestroy(fixture->account);
57  gnc_commodity_destroy(fixture->commodity);
58 
59  qof_book_destroy( fixture->book );
60 }
61 
62 
63 static void
64 test_entry_basics ( Fixture *fixture, gconstpointer pData )
65 {
66  Timespec ts1 = timespec_now(), ts2;
67  const char *desc = "Test description with éà unicode chars";
68  const char *action = "Test action with éà unicode chars";
69  const char *note = "Test note with éà unicode chars";
70  gnc_numeric quantity = {500000, 100};
71  gboolean is_cn = FALSE;
72 
73  GncEntry *entry = gncEntryCreate(fixture->book);
74  g_assert(entry);
75 
76  g_test_message( "Test basic setters/getters" );
77  g_test_message( " Date" );
78  gncEntrySetDate (entry, ts1);
79  ts2 = gncEntryGetDate (entry);
80  g_assert(timespec_equal (&ts2, &ts1));
81  g_test_message( " DateEntered" );
82  gncEntrySetDateEntered (entry, ts1);
83  ts2 = gncEntryGetDateEntered (entry);
84  g_assert(timespec_equal (&ts2, &ts1));
85  g_test_message( " Description" );
86  gncEntrySetDescription (entry, desc);
87  g_assert(g_strcmp0 (gncEntryGetDescription (entry), desc) == 0);
88  g_test_message( " Action" );
89  gncEntrySetAction (entry, action);
90  g_assert(g_strcmp0 (gncEntryGetAction (entry), action) == 0);
91  g_test_message( " Notes" );
92  gncEntrySetNotes (entry, note);
93  g_assert(g_strcmp0 (gncEntryGetNotes (entry), note) == 0);
94  g_test_message( " Quantity" );
95  gncEntrySetQuantity (entry, quantity);
96  g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), quantity));
97  g_test_message( " DocQuantity (with is_cn = FALSE)" );
98  gncEntrySetDocQuantity (entry, quantity, is_cn);
99  g_assert(gnc_numeric_eq (gncEntryGetDocQuantity (entry, is_cn), quantity));
100  g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), quantity));
101  g_test_message( " DocQuantity (with is_cn = TRUE)");
102  is_cn = TRUE;
103  gncEntrySetDocQuantity (entry, quantity, is_cn);
104  g_assert(gnc_numeric_eq (gncEntryGetDocQuantity (entry, is_cn), quantity));
105  g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), gnc_numeric_neg (quantity)));
106  g_test_message( " InvAccount" );
107  gncEntrySetInvAccount (entry, fixture->account);
108  g_assert(gncEntryGetInvAccount (entry) == fixture->account);
109 
110 }
111 
112 void
113 test_suite_gncEntry ( void )
114 {
115  GNC_TEST_ADD( suitename, "basics", Fixture, NULL, setup, test_entry_basics, teardown );
116 }
void gncEntrySetQuantity(GncEntry *entry, gnc_numeric quantity)
Definition: gncEntry.c:552
void gncEntrySetDate(GncEntry *entry, Timespec date)
Definition: gncEntry.c:481
gnc_numeric gnc_numeric_neg(gnc_numeric a)
QofBook * qof_book_new(void)
gboolean timespec_equal(const Timespec *ta, const Timespec *tb)
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
Timespec gncEntryGetDate(const GncEntry *entry)
Definition: gncEntry.c:878
void gncEntrySetDocQuantity(GncEntry *entry, gnc_numeric quantity, gboolean is_cn)
Definition: gncEntry.c:563
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)
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
Timespec timespec_now(void)
gnc_numeric gncEntryGetQuantity(const GncEntry *entry)
Definition: gncEntry.c:919
Account * xaccMallocAccount(QofBook *book)
Definition: Account.c:1083
gnc_numeric gncEntryGetDocQuantity(const GncEntry *entry, gboolean is_cn)
Definition: gncEntry.c:925
void gnc_commodity_destroy(gnc_commodity *cm)
void qof_book_destroy(QofBook *book)
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Definition: Account.c:2389