GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-address.c
1 /*********************************************************************
2  * test-address.c
3  * object definition/initialization for Address
4  *
5  * Copyright (c) 2001 Derek Atkins <[email protected]>
6  * Copyright (c) 2005 Neil Williams <[email protected]>
7  *
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.
12  *
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.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, contact:
20  *
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 [email protected]
24  *
25  *********************************************************************/
26 
27 #include "config.h"
28 #include <glib.h>
29 #include "cashobjects.h"
30 #include "gncAddressP.h"
31 #include "test-stuff.h"
32 
33 static void
34 test_string_fcn (GncAddress *address, const char *message,
35  void (*set) (GncAddress *, const char *str),
36  const char * (*get)(const GncAddress *));
37 
38 static void
39 test_address (void)
40 {
41  QofInstance *ent;
42  GncAddress *address;
43  QofBook *book = qof_book_new ();
44 
45  ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL);
46  ent->e_type = "asdf";
47 
48  /* Test creation/destruction */
49  {
50  do_test (gncAddressCreate (NULL, NULL) == NULL, "address create NULL");
51 
52  address = gncAddressCreate (book, ent);
53  do_test (address != NULL, "address create");
54 
55  gncAddressBeginEdit (address);
56  gncAddressDestroy (address);
57  success ("create/destroy");
58  }
59 
60  /* Test setting routines */
61  {
62  address = gncAddressCreate (book, ent);
63  test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName);
64  test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1);
65  test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2);
66  test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3);
67  test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4);
68  test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone);
69  test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax);
70  test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail);
71  }
72 }
73 
74 static void
75 test_string_fcn (GncAddress *address, const char *message,
76  void (*set) (GncAddress *, const char *str),
77  const char * (*get)(const GncAddress *))
78 {
79  char const *str = get_random_string ();
80 
81  do_test (!gncAddressIsDirty (address), "test if start dirty");
82  set (address, str);
83  do_test (gncAddressIsDirty (address), "test dirty later");
84  do_test (g_strcmp0 (get (address), str) == 0, message);
85  gncAddressClearDirty (address);
86 }
87 
88 int
89 main (int argc, char **argv)
90 {
91  qof_init();
92  if (cashobjects_register())
93  {
94  test_address();
95  print_test_results();
96  }
97  qof_close();
98  return get_rv();
99 }
QofIdType e_type
Definition: qofinstance.h:69
QofBook * qof_book_new(void)
void qof_close(void)
Safely close down the Query Object Framework.
const GncGUID * guid_null(void)
void qof_init(void)
Initialise the Query Object Framework.