filename | src/test/testlxpaths.c |
changeset | 1283:2cbafe321d6f |
prev | 1205:a486ac64f34b |
next | 1296:30ecee61f811 |
author | nkeynes |
date | Sat Aug 04 08:46:28 2012 +1000 (11 years ago) |
permissions | -rw-r--r-- |
last change | Handle corner case in pvr2_run_slice when we've previously slightly overrun the end of the time slice |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Test cases for path helper functions
5 *
6 * Copyright (c) 2012 Nathan Keynes.
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 */
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <glib/gmem.h>
23 #include "lxpaths.h"
25 char *lxdream_get_global_config_path_value() { }
26 void log_message( void *ptr, int level, const gchar *source, const char *msg, ... ) { }
28 struct expanded_path_case_t {
29 const char *input;
30 const char *output;
31 };
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[] = {
36 {NULL, NULL},
37 {"", ""},
38 {"a", "a"},
39 {"$", "$"},
40 {"blah$", "blah$"},
41 {"\\$", "$"},
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"},
50 {NULL,NULL}
51 };
53 gboolean check_expanded_path( const char *input, const char *output )
54 {
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 );
59 g_free(result);
60 return FALSE;
61 } else {
62 return TRUE;
63 }
64 } else if( result == NULL ) {
65 printf( "Unexpected NULL result from get_expanded_path('%s'), expected '%s'\n", input, output );
66 return FALSE;
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 );
69 g_free(result);
70 return FALSE;
71 } else {
72 g_free(result);
73 return TRUE;
74 }
75 }
78 gboolean test_get_expanded_path()
79 {
80 int count, i;
81 int fails = 0;
83 for( i=0; env_vars[i] != NULL; i++ ) {
84 putenv(env_vars[i]);
85 }
86 for( i=0; unset_env_vars[i] != NULL; i++ ) {
87 unsetenv(unset_env_vars[i]);
88 }
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);
92 if( !success )
93 fails ++;
94 }
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 */
99 }
101 int main()
102 {
103 gboolean result = TRUE;
104 result = test_get_expanded_path() && result;
106 return result ? 0 : 1;
107 }
.