comparison packages/language/c/libc/stdlib/current/tests/getenv.c @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children e0c0827131d1
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
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 Red Hat eCos Public License
12 // Version 1.1 (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://www.redhat.com/
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 Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //=================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): jlarmour
35 // Contributors:
36 // Date: 2000-04-30
37 // Description: Contains testcode for C library getenv() function
38 //
39 //
40 //####DESCRIPTIONEND####
41
42 // INCLUDES
43
44 #include <stdlib.h> // Main header for stdlib functions
45 #include <cyg/infra/testcase.h> // Testcase API
46
47 // GLOBALS
48
49 extern char **environ; // Standard environment definition
50
51 // FUNCTIONS
52
53 static int
54 my_strcmp(const char *s1, const char *s2)
55 {
56 for ( ; *s1 == *s2 ; s1++,s2++ )
57 {
58 if ( *s1 == '\0' )
59 break;
60 } // for
61
62 return (*s1 - *s2);
63 } // my_strcmp()
64
65 int
66 main( int argc, char *argv[] )
67 {
68 char *str;
69
70 char *env1[] = { NULL };
71 char *env2[] = { "WIBBLE=fred", NULL };
72 char *env3[] = { "PATH=/usr/local/bin:/usr/bin",
73 "HOME=/home/fred",
74 "TEST=1234=5678",
75 "home=hatstand",
76 NULL };
77
78 CYG_TEST_INIT();
79
80 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
81 "library getenv() function");
82
83
84 // Check 1
85 str = getenv("ThisIsAVeryUnlikelyName");
86 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() default environ" );
87
88 // Check 2
89 environ = (char **)&env1;
90 str = getenv("wibble");
91 CYG_TEST_PASS_FAIL( str==NULL, "Simple getenv() with empty environ" );
92
93 // Check 3
94 environ = (char **)&env2;
95 str = getenv("WIBBLE");
96 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "fred"),
97 "Simple getenv()" );
98
99 // Check 4
100 str = getenv("wibble");
101 CYG_TEST_PASS_FAIL( str==NULL,
102 "Simple getenv() for something not in the "
103 "environment" );
104
105 // Check 5
106 environ = (char **)&env3;
107 str = getenv("PATH");
108 CYG_TEST_PASS_FAIL( (str!= NULL) &&
109 !my_strcmp(str,"/usr/local/bin:/usr/bin"),
110 "Multiple string environment" );
111
112 // Check 6
113 str = getenv("PATh");
114 CYG_TEST_PASS_FAIL( str==NULL, "getenv() for something not in the "
115 "environment for multiple string environment" );
116
117 // Check 7
118 str = getenv("home");
119 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "hatstand"),
120 "Case-sensitive environment names" );
121
122 // Check 8
123 str = getenv("TEST");
124 CYG_TEST_PASS_FAIL( (str != NULL) && !my_strcmp(str, "1234=5678"),
125 "environment value containing '='" );
126
127 // CYG_TEST_NA("Testing is not applicable to this configuration");
128
129 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
130 "library getenv() function");
131
132 } // main()
133
134 // EOF getenv.c