2005-11-02 03:32:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* test-load-example-account.c
|
|
|
|
|
*
|
|
|
|
|
* Thu Sep 29 22:52:32 2005
|
|
|
|
|
* Copyright 2005 GnuCash team
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
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 <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
2001-10-26 12:10:06 +00:00
|
|
|
#include "gnc-module.h"
|
2001-08-07 23:29:04 +00:00
|
|
|
#include "gnc-engine.h"
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "io-gncxml-v2.h"
|
2001-08-07 23:29:04 +00:00
|
|
|
|
|
|
|
|
#include "io-example-account.h"
|
|
|
|
|
|
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 const gchar *da_ending = ".gnucash-xea";
|
|
|
|
|
|
|
|
|
|
static void
|
2005-11-02 03:32:36 +00:00
|
|
|
test_load_file(QofBook *book, const char *filename)
|
2001-08-07 23:29:04 +00:00
|
|
|
{
|
|
|
|
|
GncExampleAccount *gea;
|
|
|
|
|
|
2001-11-24 12:10:42 +00:00
|
|
|
gea = gnc_read_example_account(book, filename);
|
2001-08-07 23:29:04 +00:00
|
|
|
|
|
|
|
|
if(gea != NULL)
|
|
|
|
|
{
|
|
|
|
|
success("example account load");
|
|
|
|
|
gnc_destroy_example_account(gea);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
failure_args("example account load", __FILE__, __LINE__, "for file %s",
|
|
|
|
|
filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-03 10:07:45 +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_ACCOUNT_PATH");
|
2001-10-03 10:07:45 +00:00
|
|
|
GSList *list = NULL;
|
2001-08-07 23:29:04 +00:00
|
|
|
DIR *ea_dir;
|
2005-11-02 03:32:36 +00:00
|
|
|
QofBook *book;
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2002-02-28 08:31:32 +00:00
|
|
|
if (!location)
|
|
|
|
|
{
|
2003-09-01 15:08:26 +00:00
|
|
|
location = "../../../../accounts/C";
|
2002-02-28 08:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
2001-10-03 10:07:45 +00:00
|
|
|
gnc_module_system_init();
|
|
|
|
|
gnc_module_load("gnucash/engine", 0);
|
|
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
book = qof_book_new ();
|
2001-08-07 23:29:04 +00:00
|
|
|
|
|
|
|
|
if((ea_dir = opendir(location)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
failure("unable to open ea directory");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
|
|
while((entry = readdir(ea_dir)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
struct stat file_info;
|
|
|
|
|
if(strstr(entry->d_name, da_ending) != NULL)
|
|
|
|
|
{
|
|
|
|
|
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))
|
|
|
|
|
{
|
2001-11-24 12:10:42 +00:00
|
|
|
test_load_file(book, to_open);
|
2001-08-07 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_free(to_open);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closedir(ea_dir);
|
|
|
|
|
|
|
|
|
|
{
|
2001-11-24 12:10:42 +00:00
|
|
|
list = gnc_load_example_account_list(book, location);
|
2001-08-07 23:29:04 +00:00
|
|
|
|
|
|
|
|
do_test(list != NULL, "gnc_load_example_account_list");
|
|
|
|
|
|
|
|
|
|
gnc_free_example_account_list(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print_test_results();
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-10-03 10:07:45 +00:00
|
|
|
|
|
|
|
|
int
|
2003-02-22 08:15:53 +00:00
|
|
|
main (int argc, char ** argv)
|
2001-10-03 10:07:45 +00:00
|
|
|
{
|
2003-02-22 08:15:53 +00:00
|
|
|
scm_boot_guile (argc, argv, guile_main, NULL);
|
2001-10-03 10:07:45 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|