|
0
|
1 //================================================================= |
|
|
2 // |
|
|
3 // getenv.c |
|
|
4 // |
|
|
5 // Testcase for C library getenv() |
|
|
6 // |
|
|
7 //================================================================= |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): jlarmour |
|
|
33 // Contributors: jlarmour |
|
0
|
34 // Date: 1998/8/31 |
|
|
35 // Description: Contains testcode for C library getenv() function |
|
|
36 // |
|
|
37 // |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 |
|
|
40 // Declarations for test system: |
|
|
41 // |
|
|
42 // TESTCASE_TYPE=CYG_TEST_MODULE |
|
|
43 |
|
|
44 |
|
|
45 // CONFIGURATION |
|
|
46 |
|
|
47 #include <pkgconf/libc.h> // Configuration header |
|
|
48 |
|
|
49 // INCLUDES |
|
|
50 |
|
|
51 #include <stdlib.h> // Main header for stdlib functions |
|
|
52 #include <cyg/infra/testcase.h> // Testcase API |
|
|
53 #include <sys/cstartup.h> // C library initialisation |
|
|
54 |
|
|
55 // GLOBALS |
|
|
56 |
|
|
57 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) |
|
|
58 extern char **environ; // Standard environment definition |
|
|
59 #endif |
|
|
60 |
|
|
61 // FUNCTIONS |
|
|
62 |
|
|
63 externC void |
|
|
64 cyg_package_start( void ) |
|
|
65 { |
|
|
66 #ifdef CYGPKG_LIBC |
|
|
67 cyg_iso_c_start(); |
|
|
68 #else |
|
|
69 (void)main(0, NULL); |
|
|
70 #endif |
|
|
71 } // cyg_package_start() |
|
|
72 |
|
2
|
73 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) |
|
0
|
74 static int |
|
|
75 my_strcmp(const char *s1, const char *s2) |
|
|
76 { |
|
|
77 for ( ; *s1 == *s2 ; s1++,s2++ ) |
|
|
78 { |
|
|
79 if ( *s1 == '\0' ) |
|
|
80 break; |
|
|
81 } // for |
|
|
82 |
|
|
83 return (*s1 - *s2); |
|
|
84 } // my_strcmp() |
|
2
|
85 #endif |
|
0
|
86 |
|
|
87 int |
|
|
88 main( int argc, char *argv[] ) |
|
|
89 { |
|
2
|
90 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) |
|
0
|
91 char *str; |
|
|
92 |
|
|
93 char *env1[] = { NULL }; |
|
|
94 char *env2[] = { "WIBBLE=fred", NULL }; |
|
|
95 char *env3[] = { "PATH=/usr/local/bin:/usr/bin", |
|
|
96 "HOME=/home/fred", |
|
|
97 "TEST=1234=5678", |
|
|
98 "home=hatstand", |
|
|
99 NULL }; |
|
|
100 #endif |
|
|
101 |
|
|
102 CYG_TEST_INIT(); |
|
|
103 |
|
|
104 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " |
|
|
105 "library getenv() function"); |
|
|
106 |
|
|
107 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) |
|
2
|
108 |
|
0
|
109 // Check 1 |
|
2
|
110 str = getenv("ThisIsAVeryUnlikelyName"); |
|
|
111 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() default environ" ); |
|
|
112 |
|
|
113 // Check 2 |
|
0
|
114 environ = (char **)&env1; |
|
|
115 str = getenv("wibble"); |
|
|
116 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() with empty environ" ); |
|
|
117 |
|
2
|
118 // Check 3 |
|
0
|
119 environ = (char **)&env2; |
|
|
120 str = getenv("WIBBLE"); |
|
|
121 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "fred"), |
|
|
122 "Simple getenv()" ); |
|
|
123 |
|
2
|
124 // Check 4 |
|
0
|
125 str = getenv("wibble"); |
|
|
126 CYG_TEST_PASS_FAIL( str==NULL, |
|
|
127 "Simple getenv() for something not in the " |
|
|
128 "environment" ); |
|
|
129 |
|
2
|
130 // Check 5 |
|
0
|
131 environ = (char **)&env3; |
|
|
132 str = getenv("PATH"); |
|
|
133 CYG_TEST_PASS_FAIL( (str!= NULL) && |
|
|
134 !my_strcmp(str,"/usr/local/bin:/usr/bin"), |
|
|
135 "Multiple string environment" ); |
|
|
136 |
|
2
|
137 // Check 6 |
|
0
|
138 str = getenv("PATh"); |
|
|
139 CYG_TEST_PASS_FAIL( str==NULL, "getenv() for something not in the " |
|
|
140 "environment for multiple string environment" ); |
|
|
141 |
|
2
|
142 // Check 7 |
|
0
|
143 str = getenv("home"); |
|
|
144 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "hatstand"), |
|
|
145 "Case-sensitive environment names" ); |
|
|
146 |
|
2
|
147 // Check 8 |
|
0
|
148 str = getenv("TEST"); |
|
|
149 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "1234=5678"), |
|
|
150 "environment value containing '='" ); |
|
|
151 |
|
|
152 |
|
|
153 #else |
|
2
|
154 CYG_TEST_NA("Testing is not applicable to this configuration"); |
|
0
|
155 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) |
|
|
156 |
|
|
157 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C " |
|
|
158 "library getenv() function"); |
|
|
159 |
|
|
160 } // main() |
|
|
161 |
|
|
162 // EOF getenv.c |