comparison packages/language/c/libc/current/tests/stdlib/getenv.c @ 2:443894e2e912 ecos-v1_2_1-release

Block commit of eCos version 1.2.1
author jlarmour
date Tue, 11 May 1999 12:24:34 +0000
parents 3111d98ba7b3
children c38311975d4f
comparison
equal deleted inserted replaced
1:72f549f0d891 2:443894e2e912
20 // 20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released 21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998. 22 // September 30, 1998.
23 // 23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created 24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved.
26 // ------------------------------------------- 26 // -------------------------------------------
27 // 27 //
28 //####COPYRIGHTEND#### 28 //####COPYRIGHTEND####
29 //================================================================= 29 //=================================================================
30 //#####DESCRIPTIONBEGIN#### 30 //#####DESCRIPTIONBEGIN####
31 // 31 //
32 // Author(s): jlarmour@cygnus.co.uk 32 // Author(s): jlarmour
33 // Contributors: jlarmour@cygnus.co.uk 33 // Contributors: jlarmour
34 // Date: 1998/8/31 34 // Date: 1998/8/31
35 // Description: Contains testcode for C library getenv() function 35 // Description: Contains testcode for C library getenv() function
36 // 36 //
37 // 37 //
38 //####DESCRIPTIONEND#### 38 //####DESCRIPTIONEND####
68 #else 68 #else
69 (void)main(0, NULL); 69 (void)main(0, NULL);
70 #endif 70 #endif
71 } // cyg_package_start() 71 } // cyg_package_start()
72 72
73 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT)
73 static int 74 static int
74 my_strcmp(const char *s1, const char *s2) 75 my_strcmp(const char *s1, const char *s2)
75 { 76 {
76 for ( ; *s1 == *s2 ; s1++,s2++ ) 77 for ( ; *s1 == *s2 ; s1++,s2++ )
77 { 78 {
79 break; 80 break;
80 } // for 81 } // for
81 82
82 return (*s1 - *s2); 83 return (*s1 - *s2);
83 } // my_strcmp() 84 } // my_strcmp()
84 85 #endif
85 86
86 int 87 int
87 main( int argc, char *argv[] ) 88 main( int argc, char *argv[] )
88 { 89 {
89 #ifdef CYGPKG_LIBC 90 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT)
90 char *str; 91 char *str;
91 92
92 char *env1[] = { NULL }; 93 char *env1[] = { NULL };
93 char *env2[] = { "WIBBLE=fred", NULL }; 94 char *env2[] = { "WIBBLE=fred", NULL };
94 char *env3[] = { "PATH=/usr/local/bin:/usr/bin", 95 char *env3[] = { "PATH=/usr/local/bin:/usr/bin",
102 103
103 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " 104 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
104 "library getenv() function"); 105 "library getenv() function");
105 106
106 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) 107 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT)
108
107 // Check 1 109 // Check 1
110 str = getenv("ThisIsAVeryUnlikelyName");
111 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() default environ" );
112
113 // Check 2
108 environ = (char **)&env1; 114 environ = (char **)&env1;
109 str = getenv("wibble"); 115 str = getenv("wibble");
110 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() with empty environ" ); 116 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() with empty environ" );
111 117
112 // Check 2 118 // Check 3
113 environ = (char **)&env2; 119 environ = (char **)&env2;
114 str = getenv("WIBBLE"); 120 str = getenv("WIBBLE");
115 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "fred"), 121 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "fred"),
116 "Simple getenv()" ); 122 "Simple getenv()" );
117 123
118 // Check 3 124 // Check 4
119 str = getenv("wibble"); 125 str = getenv("wibble");
120 CYG_TEST_PASS_FAIL( str==NULL, 126 CYG_TEST_PASS_FAIL( str==NULL,
121 "Simple getenv() for something not in the " 127 "Simple getenv() for something not in the "
122 "environment" ); 128 "environment" );
123 129
124 // Check 4 130 // Check 5
125 environ = (char **)&env3; 131 environ = (char **)&env3;
126 str = getenv("PATH"); 132 str = getenv("PATH");
127 CYG_TEST_PASS_FAIL( (str!= NULL) && 133 CYG_TEST_PASS_FAIL( (str!= NULL) &&
128 !my_strcmp(str,"/usr/local/bin:/usr/bin"), 134 !my_strcmp(str,"/usr/local/bin:/usr/bin"),
129 "Multiple string environment" ); 135 "Multiple string environment" );
130 136
131 // Check 5 137 // Check 6
132 str = getenv("PATh"); 138 str = getenv("PATh");
133 CYG_TEST_PASS_FAIL( str==NULL, "getenv() for something not in the " 139 CYG_TEST_PASS_FAIL( str==NULL, "getenv() for something not in the "
134 "environment for multiple string environment" ); 140 "environment for multiple string environment" );
135 141
136 // Check 6 142 // Check 7
137 str = getenv("home"); 143 str = getenv("home");
138 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "hatstand"), 144 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "hatstand"),
139 "Case-sensitive environment names" ); 145 "Case-sensitive environment names" );
140 146
141 // Check 7 147 // Check 8
142 str = getenv("TEST"); 148 str = getenv("TEST");
143 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "1234=5678"), 149 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "1234=5678"),
144 "environment value containing '='" ); 150 "environment value containing '='" );
145 151
146 152
147 #else 153 #else
148 CYG_TEST_PASS("Testing is not applicable to this configuration"); 154 CYG_TEST_NA("Testing is not applicable to this configuration");
149 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) 155 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT)
150 156
151 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C " 157 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
152 "library getenv() function"); 158 "library getenv() function");
153 159