2005-11-02 03:32:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* test-load-xml2.c
|
|
|
|
|
*
|
|
|
|
|
* Fri Oct 7 20:51:46 2005
|
|
|
|
|
* Copyright 2005 Neil Williams
|
|
|
|
|
* linux@codehelp.co.uk
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
* 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, write to the Free Software
|
2005-11-17 05:35:02 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301, USA.
|
2005-11-02 03:32:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2003-08-09 19:24:05 +00:00
|
|
|
/* @file test-load-xml2.c
|
2005-11-02 03:32:36 +00:00
|
|
|
* @brief test the loading of a version-2 gnucash XML file
|
2003-08-09 19:24:05 +00:00
|
|
|
*/
|
|
|
|
|
|
2006-09-05 18:00:11 +00:00
|
|
|
#include "config.h"
|
2001-08-07 23:29:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <string.h>
|
2006-02-16 03:34:59 +00:00
|
|
|
#include <glib.h>
|
2006-02-16 06:06:25 +00:00
|
|
|
#include <glib-object.h>
|
2007-01-21 16:38:42 +00:00
|
|
|
#include <glib/gstdio.h>
|
2006-02-16 03:34:59 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "cashobjects.h"
|
2001-11-24 12:10:42 +00:00
|
|
|
#include "Group.h"
|
2001-08-07 23:29:04 +00:00
|
|
|
#include "TransLog.h"
|
2001-09-20 22:51:37 +00:00
|
|
|
#include "gnc-engine.h"
|
2003-08-09 19:24:05 +00:00
|
|
|
#include "gnc-backend-file.h"
|
2001-09-20 22:51:37 +00:00
|
|
|
#include "io-gncxml-v2.h"
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2001-08-18 20:33:51 +00:00
|
|
|
#include "test-stuff.h"
|
|
|
|
|
#include "test-engine-stuff.h"
|
|
|
|
|
#include "test-file-stuff.h"
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2007-01-15 20:27:58 +00:00
|
|
|
#define GNC_LIB_NAME "gncmod-backend-file"
|
2005-11-02 03:32:36 +00:00
|
|
|
|
2001-08-07 23:29:04 +00:00
|
|
|
static void
|
|
|
|
|
remove_files_pattern(const char *begining, const char *ending)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_locks(const char *filename)
|
|
|
|
|
{
|
|
|
|
|
struct stat buf;
|
|
|
|
|
char *to_remove;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
to_remove = g_strdup_printf("%s.LCK", filename);
|
2007-01-21 16:38:42 +00:00
|
|
|
if(g_stat(to_remove, &buf) != -1)
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
2007-01-21 16:38:42 +00:00
|
|
|
g_unlink(to_remove);
|
2001-08-07 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
g_free(to_remove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_files_pattern(filename, ".LCK");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_load_file(const char *filename)
|
|
|
|
|
{
|
2003-06-27 02:54:11 +00:00
|
|
|
QofSession *session;
|
|
|
|
|
QofBook *book;
|
2005-11-02 03:32:36 +00:00
|
|
|
AccountGroup *grp;
|
2002-03-01 07:53:07 +00:00
|
|
|
gboolean ignore_lock;
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2003-06-27 02:54:11 +00:00
|
|
|
session = qof_session_new();
|
2001-08-07 23:29:04 +00:00
|
|
|
|
|
|
|
|
remove_locks(filename);
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2007-01-21 22:11:34 +00:00
|
|
|
ignore_lock = (safe_strcmp(g_getenv("SRCDIR"), ".") != 0);
|
2003-06-27 02:54:11 +00:00
|
|
|
qof_session_begin(session, filename, ignore_lock, FALSE);
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
qof_session_load(session, NULL);
|
2003-06-27 02:54:11 +00:00
|
|
|
book = qof_session_get_book (session);
|
2001-10-02 09:10:35 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
grp = xaccGetAccountGroup(book);
|
|
|
|
|
do_test (xaccGroupGetBook (grp) == book,
|
2001-10-02 09:10:35 +00:00
|
|
|
"book and group don't match");
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2006-05-05 13:02:30 +00:00
|
|
|
do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR,
|
|
|
|
|
"session load xml2", __FILE__, __LINE__,
|
|
|
|
|
"qof error=%d for file [%s]",
|
|
|
|
|
qof_session_get_error(session), filename);
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
qof_session_end(session);
|
2001-08-07 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
int
|
|
|
|
|
main (int argc, char ** argv)
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
2007-01-21 22:11:34 +00:00
|
|
|
const char *location = g_getenv("GNC_TEST_FILES");
|
2007-01-20 18:37:35 +00:00
|
|
|
GDir *xml2_dir;
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2006-02-16 06:06:25 +00:00
|
|
|
g_type_init();
|
2006-02-16 03:34:59 +00:00
|
|
|
qof_init();
|
|
|
|
|
cashobjects_register();
|
2006-06-03 14:51:10 +00:00
|
|
|
do_test(qof_load_backend_library ("../.libs/", GNC_LIB_NAME),
|
2006-02-16 03:34:59 +00:00
|
|
|
" loading gnc-backend-file GModule failed");
|
2005-11-02 03:32:36 +00:00
|
|
|
|
2002-02-28 08:31:32 +00:00
|
|
|
if (!location)
|
|
|
|
|
{
|
2003-09-01 15:08:26 +00:00
|
|
|
location = "test-files/xml2";
|
2002-02-28 08:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
2001-08-07 23:29:04 +00:00
|
|
|
xaccLogDisable();
|
|
|
|
|
|
2007-01-20 18:37:35 +00:00
|
|
|
if((xml2_dir = g_dir_open(location, 0, NULL)) == NULL)
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
|
|
|
|
failure("unable to open xml2 directory");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-01-20 18:37:35 +00:00
|
|
|
const gchar *entry;
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2007-01-20 18:37:35 +00:00
|
|
|
while((entry = g_dir_read_name(xml2_dir)) != NULL)
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
2007-01-20 18:37:35 +00:00
|
|
|
if(g_str_has_suffix(entry, ".gml2"))
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
2007-01-20 18:37:35 +00:00
|
|
|
gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
|
|
|
|
|
if(!g_file_test(to_open, G_FILE_TEST_IS_DIR))
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
2007-01-20 18:37:35 +00:00
|
|
|
test_load_file(to_open);
|
2001-08-07 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
g_free(to_open);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-20 22:51:37 +00:00
|
|
|
|
2007-01-20 18:37:35 +00:00
|
|
|
g_dir_close(xml2_dir);
|
2001-09-20 22:51:37 +00:00
|
|
|
|
2001-08-07 23:29:04 +00:00
|
|
|
print_test_results();
|
2005-11-02 03:32:36 +00:00
|
|
|
qof_close();
|
2007-01-15 20:28:01 +00:00
|
|
|
exit(get_rv());
|
2001-09-20 22:51:37 +00:00
|
|
|
}
|