GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-qif.c
1 /*
2  * test-qif.c -- Test the QIF Import routines.
3  *
4  * Created by: Derek Atkins <[email protected]>
5  * Copyright (c) 2003 Derek Atkins <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, contact:
19  *
20  * Free Software Foundation Voice: +1-617-542-5942
21  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
22  * Boston, MA 02110-1301, USA [email protected]
23  */
24 
25 #include <glib.h>
26 #include <libguile.h>
27 
28 #include "gnc-module.h"
29 #include "qif-import.h"
30 #include "qif-import-p.h" /* Let's test some internal stuff, too */
31 
32 #include "test-stuff.h"
33 
34 /* XXX */
35 extern void qif_object_init(void);
36 
37 static QifContext
38 test_qif_load_file(QifContext ctx, const char *filename,
39  gint txn_count, gint acct_count, gboolean needs_acct)
40 {
41  QifContext file;
42 
43  printf("qif loading \"%s\"...\n", filename);
44  file = qif_file_new(ctx, filename);
45  do_test(file != NULL, "failed to read file");
46  if (!file) return NULL;
47 
48  do_test(qif_object_list_count(file, QIF_O_TXN) == txn_count,
49  "Transaction count didn't match");
50  do_test(qif_object_map_count(file, QIF_O_ACCOUNT) == acct_count,
51  "Account count didn't match");
52  do_test(qif_file_needs_account(file) == needs_acct,
53  "Needs account flad didn't match");
54 
55  return file;
56 }
57 
58 static void
59 test_qif(void)
60 {
61  QifContext ctx, file;
62  char *filename;
63  const char *location = g_getenv("GNC_TEST_FILES");
64  int i;
65 
66  ctx = qif_context_new();
67  do_test(ctx != NULL, "failed to create the qif context");
68  if (!ctx) return;
69 
70  if (!location)
71  location = "test-files";
72 
73  for (i = 0; i < 1; i++)
74  {
75  filename = g_strdup_printf("%s/%s", location, "test-1-bank-txn.qif");
76  file = test_qif_load_file(ctx, filename, 1, 0, TRUE);
77  g_free(filename);
78  if (!file) continue;
79 
80  if (qif_file_needs_account(file))
81  qif_file_set_default_account(file, "test-1-bank-txn");
82 
83  do_test(qif_file_needs_account(file) == FALSE,
84  "'Needs account' flag not cleared properly");
85 
86  do_test(qif_file_parse(file, NULL) == QIF_E_OK,
87  "file failed to parse.");
88  }
89 
90  qif_context_destroy(ctx);
91 
92  success("QIF test successful");
93 }
94 
95 static void
96 main_helper(void *closure, int argc, char **argv)
97 {
98  qif_object_init(); /* XXX:FIXME */
99  test_qif();
100  print_test_results();
101  exit(get_rv());
102 }
103 
104 int
105 main(int argc, char **argv)
106 {
107  scm_boot_guile(argc, argv, main_helper, NULL);
108  return 0;
109 }
110