GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-resolve-file-path.c
1 /***************************************************************************
2  * test-resolve-file-path.c
3  *
4  * Thu Sep 29 22:48:57 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 <stdlib.h>
26 #include <string.h>
27 
28 #include <glib.h>
29 #include "qof.h"
30 #include "test-stuff.h"
31 #include "gnc-filepath-utils.h"
32 
34 {
35  char *input;
36  char *output;
37  int prefix_home;
38 };
39 
40 typedef struct test_strings_struct test_strings;
41 
42 test_strings strs[] =
43 {
44  {
45  G_DIR_SEPARATOR_S ".gnucash" G_DIR_SEPARATOR_S "test-account-name",
46  G_DIR_SEPARATOR_S ".gnucash" G_DIR_SEPARATOR_S "test-account-name", 1
47  },
48  {
49  G_DIR_SEPARATOR_S "tmp" G_DIR_SEPARATOR_S "test-account-name2",
50  G_DIR_SEPARATOR_S "tmp" G_DIR_SEPARATOR_S "test-account-name2", 0
51  },
52  /* TODO Figure out how to write tests that actually verify the relative
53  * pathname resolution. The above tests only test absolut pathnames */
54  { NULL, NULL, 0 },
55 };
56 
57 int
58 main(int argc, char **argv)
59 {
60  int i;
61 
62  qof_init();
63 
64  for (i = 0; strs[i].input != NULL; i++)
65  {
66  char *daout;
67  char *dain;
68  char *wantout;
69 
70  if (strs[i].prefix_home == 1)
71  {
72  dain = g_build_filename(g_get_home_dir(), strs[i].input,
73  (gchar *)NULL);
74  wantout = g_build_filename(g_get_home_dir(), strs[i].output,
75  (gchar *)NULL);
76  }
77  else if (strs[i].prefix_home == 2)
78  {
79  dain = g_strdup(strs[i].input);
80  wantout = g_build_filename(g_get_home_dir(), strs[i].output,
81  (gchar *)NULL);
82  }
83  else
84  {
85  dain = g_strdup(strs[i].input);
86  wantout = g_strdup(strs[i].output);
87  }
88 
89  daout = gnc_resolve_file_path(dain);
90  do_test_args(g_strcmp0(daout, wantout) == 0,
91  "gnc_resolve_file_path",
92  __FILE__, __LINE__,
93  "%s (%s) vs %s", daout, dain, wantout);
94  g_free(dain);
95  g_free(wantout);
96  g_free(daout);
97  }
98  print_test_results();
99  return get_rv();
100 }
gchar * gnc_resolve_file_path(const gchar *filefrag)
Create an absolute path when given a relative path; otherwise return the argument.
File path resolution utility functions.
void qof_init(void)
Initialise the Query Object Framework.