GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-load-example-account.c
1 /***************************************************************************
2  * test-load-example-account.c
3  *
4  * Thu Sep 29 22:52:32 2005
5  * Copyright 2005 GnuCash team
6  ****************************************************************************/
7 /*
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301, USA.
22  */
23 
24 #include "config.h"
25 #include <glib.h>
26 #include <libguile.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <unistd.h>
33 #include <dirent.h>
34 
35 #include "gnc-module.h"
36 #include "gnc-engine.h"
37 #include "io-gncxml-v2.h"
38 
39 #include "io-example-account.h"
40 
41 #include "test-stuff.h"
42 #include "test-engine-stuff.h"
43 #include "test-file-stuff.h"
44 
45 static const gchar *da_ending = ".gnucash-xea";
46 
47 static void
48 test_load_file(const char *filename)
49 {
50  GncExampleAccount *gea;
51 
52  gea = gnc_read_example_account(filename);
53 
54  if (gea != NULL)
55  {
56  success("example account load");
57  gnc_destroy_example_account(gea);
58  }
59  else
60  {
61  failure_args("example account load", __FILE__, __LINE__, "for file %s",
62  filename);
63  }
64 }
65 
66 static void
67 guile_main (void *closure, int argc, char **argv)
68 {
69  const char *location = g_getenv("GNC_ACCOUNT_PATH");
70  GSList *list = NULL;
71  GDir *ea_dir;
72 
73  if (!location)
74  {
75  location = "../../../../accounts/C";
76  }
77 
78  gnc_module_system_init();
79  gnc_module_load("gnucash/engine", 0);
80 
81  if ((ea_dir = g_dir_open(location, 0, NULL)) == NULL)
82  {
83  failure("unable to open ea directory");
84  }
85  else
86  {
87  const gchar *entry;
88 
89  while ((entry = g_dir_read_name(ea_dir)) != NULL)
90  {
91  if (g_str_has_suffix(entry, da_ending))
92  {
93  gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
94  if (!g_file_test(to_open, G_FILE_TEST_IS_DIR))
95  {
96  test_load_file(to_open);
97  }
98  g_free(to_open);
99  }
100  }
101  }
102  g_dir_close(ea_dir);
103 
104  {
105  list = gnc_load_example_account_list(location);
106 
107  do_test(list != NULL, "gnc_load_example_account_list");
108 
109  gnc_free_example_account_list(list);
110  }
111 
112 
113  print_test_results();
114  exit(get_rv());
115 }
116 
117 int
118 main (int argc, char ** argv)
119 {
120  g_setenv ("GNC_UNINSTALLED", "1", TRUE);
121  scm_boot_guile (argc, argv, guile_main, NULL);
122  exit(get_rv());
123 }
api for GnuCash version 2 XML-based file format
All type declarations for the whole Gnucash engine.