2003-10-23 04:33:18 +00:00
|
|
|
/*********************************************************************
|
2005-11-02 03:32:36 +00:00
|
|
|
* test-address.c
|
|
|
|
|
* object definition/initialization for Address
|
2010-03-02 21:41:05 +00:00
|
|
|
*
|
2003-10-23 04:33:18 +00:00
|
|
|
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
2005-11-02 03:32:36 +00:00
|
|
|
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
2003-10-23 04:33:18 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, contact:
|
|
|
|
|
*
|
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942
|
2005-11-17 05:35:02 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org
|
2003-10-23 04:33:18 +00:00
|
|
|
*
|
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
2017-10-26 11:14:21 +02:00
|
|
|
#include <config.h>
|
2001-11-17 01:17:06 +00:00
|
|
|
#include <glib.h>
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "cashobjects.h"
|
|
|
|
|
#include "gncAddressP.h"
|
2001-11-17 01:17:06 +00:00
|
|
|
#include "test-stuff.h"
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_string_fcn (GncAddress *address, const char *message,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*set) (GncAddress *, const char *str),
|
|
|
|
|
const char * (*get)(const GncAddress *));
|
2001-11-17 01:17:06 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_address (void)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
QofInstance *ent;
|
|
|
|
|
GncAddress *address;
|
|
|
|
|
QofBook *book = qof_book_new ();
|
2001-11-17 01:17:06 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL);
|
|
|
|
|
ent->e_type = "asdf";
|
2003-10-19 15:45:30 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
/* Test creation/destruction */
|
|
|
|
|
{
|
|
|
|
|
do_test (gncAddressCreate (NULL, NULL) == NULL, "address create NULL");
|
2003-10-19 15:45:30 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
address = gncAddressCreate (book, ent);
|
|
|
|
|
do_test (address != NULL, "address create");
|
2001-11-17 01:17:06 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
gncAddressBeginEdit (address);
|
|
|
|
|
gncAddressDestroy (address);
|
|
|
|
|
success ("create/destroy");
|
|
|
|
|
}
|
2001-11-17 01:17:06 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
/* Test setting routines */
|
|
|
|
|
{
|
|
|
|
|
address = gncAddressCreate (book, ent);
|
|
|
|
|
test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName);
|
|
|
|
|
test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1);
|
|
|
|
|
test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2);
|
|
|
|
|
test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3);
|
|
|
|
|
test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4);
|
|
|
|
|
test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone);
|
|
|
|
|
test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax);
|
|
|
|
|
test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail);
|
|
|
|
|
}
|
2001-11-17 01:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_string_fcn (GncAddress *address, const char *message,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*set) (GncAddress *, const char *str),
|
|
|
|
|
const char * (*get)(const GncAddress *))
|
2001-11-17 01:17:06 +00:00
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
char const *str = get_random_string ();
|
2001-11-17 01:17:06 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
do_test (!gncAddressIsDirty (address), "test if start dirty");
|
|
|
|
|
set (address, str);
|
|
|
|
|
do_test (gncAddressIsDirty (address), "test dirty later");
|
2012-08-07 17:24:55 +00:00
|
|
|
do_test (g_strcmp0 (get (address), str) == 0, message);
|
2010-03-02 21:41:05 +00:00
|
|
|
gncAddressClearDirty (address);
|
2001-11-17 01:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
qof_init();
|
|
|
|
|
if (cashobjects_register())
|
|
|
|
|
{
|
|
|
|
|
test_address();
|
|
|
|
|
print_test_results();
|
|
|
|
|
}
|
|
|
|
|
qof_close();
|
2011-11-21 14:19:10 +00:00
|
|
|
return get_rv();
|
2001-11-17 01:17:06 +00:00
|
|
|
}
|