2003-10-22 23:33:18 -05:00
|
|
|
/*********************************************************************
|
|
|
|
* test-business.c
|
|
|
|
* Test the business code.
|
2010-03-02 15:41:05 -06:00
|
|
|
*
|
2003-10-22 23:33:18 -05:00
|
|
|
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*
|
|
|
|
* 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-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org
|
2003-10-22 23:33:18 -05:00
|
|
|
*
|
|
|
|
*********************************************************************/
|
|
|
|
|
2006-09-05 13:00:11 -05:00
|
|
|
#include "config.h"
|
2001-11-16 19:17:06 -06:00
|
|
|
#include <glib.h>
|
2003-02-22 02:15:53 -06:00
|
|
|
#include <libguile.h>
|
2001-11-16 19:17:06 -06:00
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
#include "qof.h"
|
2001-11-16 19:17:06 -06:00
|
|
|
#include "gnc-module.h"
|
|
|
|
|
|
|
|
#include "gncBusiness.h"
|
|
|
|
#include "test-stuff.h"
|
|
|
|
|
|
|
|
#define TEST_MODULE_NAME "business-test"
|
|
|
|
#define TEST_MODULE_DESC "Test Business"
|
|
|
|
|
2002-02-03 14:01:08 -06:00
|
|
|
#if 0
|
2003-10-17 00:15:56 -05:00
|
|
|
static GList * get_list (QofBook *, gboolean show_all);
|
2001-11-16 19:17:06 -06:00
|
|
|
static const char * printable (gpointer obj);
|
2001-11-24 23:34:34 -06:00
|
|
|
static void test_printable (const char *name, gpointer obj);
|
2003-10-17 00:15:56 -05:00
|
|
|
static void test_get_list (QofBook *, const char *);
|
2001-11-16 19:17:06 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
static GncBusinessObject bus_obj =
|
|
|
|
{
|
|
|
|
GNC_BUSINESS_VERSION,
|
|
|
|
TEST_MODULE_NAME,
|
|
|
|
TEST_MODULE_DESC,
|
|
|
|
NULL, /* create */
|
|
|
|
NULL, /* destroy */
|
|
|
|
get_list,
|
|
|
|
printable,
|
2001-11-16 19:17:06 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static void test_business (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Test the global registration and lookup functions */
|
|
|
|
{
|
|
|
|
do_test (!gncBusinessRegister (NULL), "register NULL");
|
|
|
|
do_test (gncBusinessRegister (&bus_obj), "register test object");
|
|
|
|
do_test (!gncBusinessRegister (&bus_obj), "register test object again");
|
|
|
|
do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj,
|
|
|
|
"lookup our installed object");
|
|
|
|
do_test (gncBusinessLookup ("snm98sn snml say dyikh9y9ha") == NULL,
|
|
|
|
"lookup non-existant business object");
|
|
|
|
|
|
|
|
do_test (!safe_strcmp (gncBusinessGetTypeLabel (TEST_MODULE_NAME),
|
|
|
|
_(TEST_MODULE_DESC)),
|
|
|
|
"test description return");
|
|
|
|
}
|
|
|
|
|
|
|
|
test_get_list ((QofBook*)1, TEST_MODULE_NAME);
|
|
|
|
test_printable (TEST_MODULE_NAME, (gpointer)1);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
2003-10-17 00:15:56 -05:00
|
|
|
get_list (QofBook *book, gboolean show_all)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
do_test (book != NULL, "get_list: NULL business");
|
|
|
|
success ("called get_list callback");
|
|
|
|
return ((GList *)1);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
printable (gpointer obj)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
do_test (obj != NULL, "printable: object is NULL");
|
|
|
|
success ("called printable callback");
|
|
|
|
return ((const char *)obj);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-17 00:15:56 -05:00
|
|
|
test_get_list (QofBook *book, const char *name)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GList *res;
|
|
|
|
|
|
|
|
do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL,
|
|
|
|
"business: GetList: NULL, NULL, FALSE");
|
|
|
|
do_test (gncBusinessGetList (NULL, name, FALSE) == NULL,
|
|
|
|
"business: GetList: NULL, mod_name, FALSE");
|
|
|
|
do_test (gncBusinessGetList (book, NULL, FALSE) == NULL,
|
|
|
|
"business: GetList: book, NULL, FALSE");
|
|
|
|
res = gncBusinessGetList (book, name, FALSE);
|
|
|
|
do_test (res != NULL, "business: GetList: book, mod_name, FALSE");
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-24 23:34:34 -06:00
|
|
|
test_printable (const char *name, gpointer obj)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
const char *res;
|
|
|
|
|
|
|
|
do_test (gncBusinessPrintable (NULL, NULL) == NULL,
|
|
|
|
"business: Printable: NULL, NULL");
|
|
|
|
do_test (gncBusinessPrintable (NULL, obj) == NULL,
|
|
|
|
"business: Printable: NULL, object");
|
|
|
|
do_test (gncBusinessPrintable (name, NULL) == NULL,
|
|
|
|
"business: Printable: mod_name, NULL");
|
|
|
|
res = gncBusinessPrintable (name, obj);
|
|
|
|
do_test (res != NULL, "business: Printable: mod_name, object");
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-22 02:15:53 -06:00
|
|
|
main_helper (void *closure, int argc, char **argv)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2011-11-21 04:40:17 -06:00
|
|
|
gnc_module_load("gnucash/engine", 0);
|
2010-03-02 15:41:05 -06:00
|
|
|
test_business();
|
|
|
|
print_test_results();
|
|
|
|
exit(get_rv());
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
2002-02-03 14:01:08 -06:00
|
|
|
#endif
|
2001-11-16 19:17:06 -06:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2011-12-02 16:00:18 -06:00
|
|
|
g_setenv ("GNC_UNINSTALLED", "1", TRUE);
|
|
|
|
// scm_boot_guile (argc, argv, main_helper, NULL);
|
2011-11-21 08:19:10 -06:00
|
|
|
return get_rv();
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|