filename | src/test/testlxpaths.c |
changeset | 1205:a486ac64f34b |
next | 1283:2cbafe321d6f |
author | nkeynes |
date | Tue Feb 28 18:22:52 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Add a GL-only video driver for android usage (since the Java code is responsible for creating the context) |
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() { }
27 struct expanded_path_case_t {
28 const char *input;
29 const char *output;
30 };
32 char *env_vars[] = { "TEST1=quux", "TEST2=${BLAH}", "TEST3=", "2=3", "TEST_HOME=/home/foo", NULL };
33 const char *unset_env_vars[] = { "PATH_TEST", "1", NULL };
34 struct expanded_path_case_t expanded_path_cases[] = {
35 {NULL, NULL},
36 {"", ""},
37 {"a", "a"},
38 {"$", "$"},
39 {"blah$", "blah$"},
40 {"\\$", "$"},
41 {"foo\\${TEST}\\n\\\\r", "foo${TEST}n\\r"},
42 {"/home/user/.lxdreamrc", "/home/user/.lxdreamrc"},
43 {"${TEST_HOME}/.lxdreamrc", "/home/foo/.lxdreamrc"},
44 {"$TEST_HOME/bar", "/home/foo/bar"},
45 {"/home/$TEST1/blah", "/home/quux/blah"},
46 {"/tmp/${TEST2}/abcd", "/tmp/${BLAH}/abcd"},
47 {"$TEST1$TEST2$TEST3$1$2", "quux${BLAH}3"},
48 {NULL,NULL}
49 };
51 gboolean check_expanded_path( const char *input, const char *output )
52 {
53 char * result = get_expanded_path(input);
54 if( output == NULL ) {
55 if( result != NULL ) {
56 printf( "Unexpected non-null result from get_expanded_path(NULL), got '%s'\n", result );
57 g_free(result);
58 return FALSE;
59 } else {
60 return TRUE;
61 }
62 } else if( result == NULL ) {
63 printf( "Unexpected NULL result from get_expanded_path('%s'), expected '%s'\n", input, output );
64 return FALSE;
65 } else if( strcmp(result, output) != 0 ) {
66 printf( "Unexpected result from get_expanded_path('%s'), expected '%s' but was '%s'\n", input, output, result );
67 g_free(result);
68 return FALSE;
69 } else {
70 g_free(result);
71 return TRUE;
72 }
73 }
76 gboolean test_get_expanded_path()
77 {
78 int count, i;
79 int fails = 0;
81 for( i=0; env_vars[i] != NULL; i++ ) {
82 putenv(env_vars[i]);
83 }
84 for( i=0; unset_env_vars[i] != NULL; i++ ) {
85 unsetenv(unset_env_vars[i]);
86 }
88 for( count=0; expanded_path_cases[count].input != NULL || count == 0; count++ ) {
89 gboolean success = check_expanded_path(expanded_path_cases[count].input, expanded_path_cases[count].output);
90 if( !success )
91 fails ++;
92 }
93 printf( "get_expanded_path: %d/%d (%s)\n", (count-fails), count, (fails == 0 ? "OK" : "ERROR"));
94 return fails == 0 ? TRUE : FALSE;
96 /* FIXME: Should probably restore the env state, but doesn't matter at the moment */
97 }
99 int main()
100 {
101 gboolean result = TRUE;
102 result = test_get_expanded_path() && result;
104 return result ? 0 : 1;
105 }
.