GnuCash 2.4.99
test-resolve-file-path.c
00001 /***************************************************************************
00002  *            test-resolve-file-path.c
00003  *
00004  *  Thu Sep 29 22:48:57 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 <stdlib.h>
00026 #include <string.h>
00027 
00028 #include <glib.h>
00029 #include "qof.h"
00030 #include "test-stuff.h"
00031 #include "gnc-filepath-utils.h"
00032 
00033 struct test_strings_struct
00034 {
00035     char *input;
00036     char *output;
00037     int prefix_home;
00038 };
00039 
00040 typedef struct test_strings_struct test_strings;
00041 
00042 test_strings strs[] =
00043 {
00044     {
00045         G_DIR_SEPARATOR_S ".gnucash" G_DIR_SEPARATOR_S "test-account-name",
00046         G_DIR_SEPARATOR_S ".gnucash" G_DIR_SEPARATOR_S "test-account-name", 1
00047     },
00048     {
00049         G_DIR_SEPARATOR_S "tmp" G_DIR_SEPARATOR_S "test-account-name2",
00050         G_DIR_SEPARATOR_S "tmp" G_DIR_SEPARATOR_S "test-account-name2", 0
00051     },
00052     /* TODO Figure out how to write tests that actually verify the relative
00053      * pathname resolution. The above tests only test absolut pathnames */
00054     { NULL, NULL, 0 },
00055 };
00056 
00057 int
00058 main(int argc, char **argv)
00059 {
00060     int i;
00061 
00062     qof_init();
00063 
00064     for (i = 0; strs[i].input != NULL; i++)
00065     {
00066         char *daout;
00067         char *dain;
00068         char *wantout;
00069 
00070         if (strs[i].prefix_home == 1)
00071         {
00072             dain = g_build_filename(g_get_home_dir(), strs[i].input,
00073                                     (gchar *)NULL);
00074             wantout = g_build_filename(g_get_home_dir(), strs[i].output,
00075                                        (gchar *)NULL);
00076         }
00077         else if (strs[i].prefix_home == 2)
00078         {
00079             dain = g_strdup(strs[i].input);
00080             wantout = g_build_filename(g_get_home_dir(), strs[i].output,
00081                                        (gchar *)NULL);
00082         }
00083         else
00084         {
00085             dain = g_strdup(strs[i].input);
00086             wantout = g_strdup(strs[i].output);
00087         }
00088 
00089         daout = gnc_resolve_file_path(dain);
00090         do_test_args(safe_strcmp(daout, wantout) == 0,
00091                      "gnc_resolve_file_path",
00092                      __FILE__, __LINE__,
00093                      "%s (%s) vs %s", daout, dain, wantout);
00094         g_free(dain);
00095         g_free(wantout);
00096         g_free(daout);
00097     }
00098     print_test_results();
00099     return get_rv();
00100 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines