1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 2006 Carnegie Mellon University |
3 |
|
4 |
This program is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
8 |
|
9 |
This program is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
13 |
|
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, |
17 |
Boston, MA 02111-1307, USA. |
18 |
*//** |
19 |
@file |
20 |
CUnit tests for the ospath.c module. |
21 |
by John Pye. |
22 |
*/ |
23 |
|
24 |
#include <ascend/general/env.h> |
25 |
#include <test/common.h> |
26 |
|
27 |
/*-------------------------------- |
28 |
some simple test routines... |
29 |
*/ |
30 |
|
31 |
# define M(MSG) fprintf(stderr,"%s:%d: (%s) %s\n",__FILE__,__LINE__,__FUNCTION__,MSG);fflush(stderr) |
32 |
|
33 |
/* |
34 |
return NULL for unfound env vars, else point to a string that must not be |
35 |
modified by the caller, and may later be changed by a later call to getenv. |
36 |
*/ |
37 |
static char *my_getenv(const char *name){ |
38 |
if(strcmp(name,"MYHOME")==0){ |
39 |
return "/home/john"; |
40 |
}else if(strcmp(name,"MYBIN")==0){ |
41 |
return "/usr/local/bin"; |
42 |
} |
43 |
return NULL; |
44 |
} |
45 |
|
46 |
void test_subst(void){ |
47 |
char s1[]="$MYHOME/bitmaps"; |
48 |
char *r; |
49 |
|
50 |
M(s1); |
51 |
|
52 |
r = env_subst(s1,my_getenv); |
53 |
M(r); |
54 |
|
55 |
CU_TEST(strcmp(r,"/home/john/bitmaps")==0); |
56 |
ASC_FREE(r); |
57 |
|
58 |
/* TODO add lots more tests in here... */ |
59 |
|
60 |
/*assert(strcmp(r,"C:/msys/1.0/share/ascend/share")==0);*/ |
61 |
} |
62 |
|
63 |
/*===========================================================================*/ |
64 |
/* Registration information */ |
65 |
|
66 |
#define TESTS(T) \ |
67 |
T(subst) \ |
68 |
|
69 |
REGISTER_TESTS_SIMPLE(general_env, TESTS); |
70 |
|