Mercurial > nand-ecoscentric
comparison packages/language/c/libc/current/tests/stdlib/getenv.c @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 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 | |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //================================================================= | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): jlarmour@cygnus.co.uk | |
| 33 // Contributors: jlarmour@cygnus.co.uk | |
| 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 | |
| 73 static int | |
| 74 my_strcmp(const char *s1, const char *s2) | |
| 75 { | |
| 76 for ( ; *s1 == *s2 ; s1++,s2++ ) | |
| 77 { | |
| 78 if ( *s1 == '\0' ) | |
| 79 break; | |
| 80 } // for | |
| 81 | |
| 82 return (*s1 - *s2); | |
| 83 } // my_strcmp() | |
| 84 | |
| 85 | |
| 86 int | |
| 87 main( int argc, char *argv[] ) | |
| 88 { | |
| 89 #ifdef CYGPKG_LIBC | |
| 90 char *str; | |
| 91 | |
| 92 char *env1[] = { NULL }; | |
| 93 char *env2[] = { "WIBBLE=fred", NULL }; | |
| 94 char *env3[] = { "PATH=/usr/local/bin:/usr/bin", | |
| 95 "HOME=/home/fred", | |
| 96 "TEST=1234=5678", | |
| 97 "home=hatstand", | |
| 98 NULL }; | |
| 99 #endif | |
| 100 | |
| 101 CYG_TEST_INIT(); | |
| 102 | |
| 103 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " | |
| 104 "library getenv() function"); | |
| 105 | |
| 106 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) | |
| 107 // Check 1 | |
| 108 environ = (char **)&env1; | |
| 109 str = getenv("wibble"); | |
| 110 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() with empty environ" ); | |
| 111 | |
| 112 // Check 2 | |
| 113 environ = (char **)&env2; | |
| 114 str = getenv("WIBBLE"); | |
| 115 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "fred"), | |
| 116 "Simple getenv()" ); | |
| 117 | |
| 118 // Check 3 | |
| 119 str = getenv("wibble"); | |
| 120 CYG_TEST_PASS_FAIL( str==NULL, | |
| 121 "Simple getenv() for something not in the " | |
| 122 "environment" ); | |
| 123 | |
| 124 // Check 4 | |
| 125 environ = (char **)&env3; | |
| 126 str = getenv("PATH"); | |
| 127 CYG_TEST_PASS_FAIL( (str!= NULL) && | |
| 128 !my_strcmp(str,"/usr/local/bin:/usr/bin"), | |
| 129 "Multiple string environment" ); | |
| 130 | |
| 131 // Check 5 | |
| 132 str = getenv("PATh"); | |
| 133 CYG_TEST_PASS_FAIL( str==NULL, "getenv() for something not in the " | |
| 134 "environment for multiple string environment" ); | |
| 135 | |
| 136 // Check 6 | |
| 137 str = getenv("home"); | |
| 138 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "hatstand"), | |
| 139 "Case-sensitive environment names" ); | |
| 140 | |
| 141 // Check 7 | |
| 142 str = getenv("TEST"); | |
| 143 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "1234=5678"), | |
| 144 "environment value containing '='" ); | |
| 145 | |
| 146 | |
| 147 #else | |
| 148 CYG_TEST_PASS("Testing is not applicable to this configuration"); | |
| 149 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_ENVIRONMENT) | |
| 150 | |
| 151 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C " | |
| 152 "library getenv() function"); | |
| 153 | |
| 154 } // main() | |
| 155 | |
| 156 // EOF getenv.c |
