GnuCash 2.4.99
test-load-example-account.c
00001 /***************************************************************************
00002  *            test-load-example-account.c
00003  *
00004  *  Thu Sep 29 22:52:32 2005
00005  *  Copyright  2005  GnuCash team
00006  ****************************************************************************/
00007 /*
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00021  *  02110-1301, USA.
00022  */
00023 
00024 #include "config.h"
00025 #include <glib.h>
00026 #include <libguile.h>
00027 #include <string.h>
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <unistd.h>
00033 #include <dirent.h>
00034 
00035 #include "gnc-module.h"
00036 #include "gnc-engine.h"
00037 #include "io-gncxml-v2.h"
00038 
00039 #include "io-example-account.h"
00040 
00041 #include "test-stuff.h"
00042 #include "test-engine-stuff.h"
00043 #include "test-file-stuff.h"
00044 
00045 static const gchar *da_ending = ".gnucash-xea";
00046 
00047 static void
00048 test_load_file(const char *filename)
00049 {
00050     GncExampleAccount *gea;
00051 
00052     gea = gnc_read_example_account(filename);
00053 
00054     if (gea != NULL)
00055     {
00056         success("example account load");
00057         gnc_destroy_example_account(gea);
00058     }
00059     else
00060     {
00061         failure_args("example account load", __FILE__, __LINE__, "for file %s",
00062                      filename);
00063     }
00064 }
00065 
00066 static void
00067 guile_main (void *closure, int argc, char **argv)
00068 {
00069     const char *location = g_getenv("GNC_ACCOUNT_PATH");
00070     GSList *list = NULL;
00071     GDir *ea_dir;
00072 
00073     if (!location)
00074     {
00075         location = "../../../../accounts/C";
00076     }
00077 
00078     gnc_module_system_init();
00079     gnc_module_load("gnucash/engine", 0);
00080 
00081     if ((ea_dir = g_dir_open(location, 0, NULL)) == NULL)
00082     {
00083         failure("unable to open ea directory");
00084     }
00085     else
00086     {
00087         const gchar *entry;
00088 
00089         while ((entry = g_dir_read_name(ea_dir)) != NULL)
00090         {
00091             if (g_str_has_suffix(entry, da_ending))
00092             {
00093                 gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
00094                 if (!g_file_test(to_open, G_FILE_TEST_IS_DIR))
00095                 {
00096                     test_load_file(to_open);
00097                 }
00098                 g_free(to_open);
00099             }
00100         }
00101     }
00102     g_dir_close(ea_dir);
00103 
00104     {
00105         list = gnc_load_example_account_list(location);
00106 
00107         do_test(list != NULL, "gnc_load_example_account_list");
00108 
00109         gnc_free_example_account_list(list);
00110     }
00111 
00112 
00113     print_test_results();
00114     exit(get_rv());
00115 }
00116 
00117 int
00118 main (int argc, char ** argv)
00119 {
00120     g_setenv ("GNC_UNINSTALLED", "1", TRUE);
00121     scm_boot_guile (argc, argv, guile_main, NULL);
00122     exit(get_rv());
00123 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines