4 * Test cases for path helper functions
6 * Copyright (c) 2012 Nathan Keynes.
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.
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.
25 char *lxdream_get_global_config_path_value() { return NULL; }
26 void log_message( void *ptr, int level, const gchar *source, const char *msg, ... ) { }
28 struct expanded_path_case_t {
33 char *env_vars[] = { "TEST1=quux", "TEST2=${BLAH}", "TEST3=", "2=3", "TEST_HOME=/home/foo", NULL };
34 const char *unset_env_vars[] = { "PATH_TEST", "1", NULL };
35 struct expanded_path_case_t expanded_path_cases[] = {
42 {"foo\\${TEST}\\n\\\\r", "foo${TEST}n\\r"},
43 {"/home/user/.lxdreamrc", "/home/user/.lxdreamrc"},
44 {"${TEST_HOME}/.lxdreamrc", "/home/foo/.lxdreamrc"},
45 {"$TEST_HOME/bar", "/home/foo/bar"},
46 {"/home/$TEST1/blah", "/home/quux/blah"},
47 {"/tmp/${TEST2}/abcd", "/tmp/${BLAH}/abcd"},
48 {"$TEST1$TEST2$TEST3$1$2", "quux${BLAH}3"},
49 {"\"/home/foo\"", "/home/foo"},
53 gboolean check_expanded_path( const char *input, const char *output )
55 char * result = get_expanded_path(input);
56 if( output == NULL ) {
57 if( result != NULL ) {
58 printf( "Unexpected non-null result from get_expanded_path(NULL), got '%s'\n", result );
64 } else if( result == NULL ) {
65 printf( "Unexpected NULL result from get_expanded_path('%s'), expected '%s'\n", input, output );
67 } else if( strcmp(result, output) != 0 ) {
68 printf( "Unexpected result from get_expanded_path('%s'), expected '%s' but was '%s'\n", input, output, result );
78 gboolean test_get_expanded_path()
83 for( i=0; env_vars[i] != NULL; i++ ) {
86 for( i=0; unset_env_vars[i] != NULL; i++ ) {
87 unsetenv(unset_env_vars[i]);
90 for( count=0; expanded_path_cases[count].input != NULL || count == 0; count++ ) {
91 gboolean success = check_expanded_path(expanded_path_cases[count].input, expanded_path_cases[count].output);
95 printf( "get_expanded_path: %d/%d (%s)\n", (count-fails), count, (fails == 0 ? "OK" : "ERROR"));
96 return fails == 0 ? TRUE : FALSE;
98 /* FIXME: Should probably restore the env state, but doesn't matter at the moment */
103 gboolean result = TRUE;
104 result = test_get_expanded_path() && result;
106 return result ? 0 : 1;
.