2001-08-07 23:29:04 +00:00
|
|
|
#include <glib.h>
|
2003-02-22 08:15:53 +00:00
|
|
|
#include <libguile.h>
|
2001-08-07 23:29:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2003-06-27 02:54:11 +00:00
|
|
|
#include "qofsession.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"
|
|
|
|
|
#include "gnc-module.h"
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if(stat(to_remove, &buf) != -1)
|
|
|
|
|
{
|
|
|
|
|
unlink(to_remove);
|
|
|
|
|
}
|
|
|
|
|
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;
|
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
|
|
|
|
2002-03-01 07:53:07 +00:00
|
|
|
ignore_lock = (strcmp(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
|
|
|
|
2003-06-27 02:54:11 +00:00
|
|
|
qof_session_load_from_xml_file_v2(session);
|
2001-10-02 09:10:35 +00:00
|
|
|
|
2003-06-27 02:54:11 +00:00
|
|
|
book = qof_session_get_book (session);
|
2001-10-02 09:10:35 +00:00
|
|
|
|
2003-06-12 02:53:21 +00:00
|
|
|
do_test (xaccGroupGetBook (xaccGetAccountGroup (book)) == book,
|
2001-10-02 09:10:35 +00:00
|
|
|
"book and group don't match");
|
2001-08-07 23:29:04 +00:00
|
|
|
|
|
|
|
|
do_test_args(
|
2003-06-27 02:54:11 +00:00
|
|
|
qof_session_get_error(session) == ERR_BACKEND_NO_ERR,
|
2001-10-02 09:10:35 +00:00
|
|
|
"session load xml2", __FILE__, __LINE__, "%d for file %s",
|
2003-06-27 02:54:11 +00:00
|
|
|
qof_session_get_error(session), filename);
|
2001-08-07 23:29:04 +00:00
|
|
|
|
2003-06-27 02:54:11 +00:00
|
|
|
qof_session_destroy(session);
|
2001-08-07 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
2001-09-20 22:51:37 +00:00
|
|
|
static void
|
2003-02-22 08:15:53 +00:00
|
|
|
guile_main (void *closure, int argc, char **argv)
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
2002-02-28 08:31:32 +00:00
|
|
|
const char *location = getenv("GNC_TEST_FILES");
|
2001-08-07 23:29:04 +00:00
|
|
|
DIR *xml2_dir;
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2002-02-28 08:31:32 +00:00
|
|
|
if (!location)
|
|
|
|
|
{
|
|
|
|
|
location = "test-files/xml2";
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-20 22:51:37 +00:00
|
|
|
gnc_module_system_init();
|
|
|
|
|
gnc_module_load("gnucash/engine", 0);
|
|
|
|
|
|
2001-08-07 23:29:04 +00:00
|
|
|
xaccLogDisable();
|
|
|
|
|
|
|
|
|
|
if((xml2_dir = opendir(location)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
failure("unable to open xml2 directory");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
|
|
while((entry = readdir(xml2_dir)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(strstr(entry->d_name, ".gml2") != NULL)
|
|
|
|
|
{
|
|
|
|
|
struct stat file_info;
|
|
|
|
|
char *to_open = g_strdup_printf("%s/%s", location,
|
|
|
|
|
entry->d_name);
|
|
|
|
|
if(stat(to_open, &file_info) != 0)
|
|
|
|
|
{
|
|
|
|
|
failure("unable to stat file");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(!S_ISDIR(file_info.st_mode))
|
|
|
|
|
{
|
|
|
|
|
test_load_file(to_open);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_free(to_open);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-20 22:51:37 +00:00
|
|
|
|
2001-08-07 23:29:04 +00:00
|
|
|
closedir(xml2_dir);
|
2001-09-20 22:51:37 +00:00
|
|
|
|
2001-08-07 23:29:04 +00:00
|
|
|
print_test_results();
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-09-20 22:51:37 +00:00
|
|
|
|
|
|
|
|
int
|
2003-02-22 08:15:53 +00:00
|
|
|
main (int argc, char ** argv)
|
2001-10-03 10:07:45 +00:00
|
|
|
{
|
|
|
|
|
/* getchar (); */
|
|
|
|
|
|
2003-02-22 08:15:53 +00:00
|
|
|
scm_boot_guile(argc, argv, guile_main, NULL);
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2001-09-20 22:51:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|