• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdlib.h>
17 #include "functionalext.h"
18 
19 /**
20  * @tc.name      : putenv_0100
21  * @tc.desc      : Add or change the environment variable test
22  * @tc.level     : Level 0
23  */
putenv_0100(void)24 void putenv_0100(void)
25 {
26     int ret = unsetenv("test");
27     EXPECT_EQ("putenv_0100", ret, CMPFLAG);
28 
29     ret = putenv("test=putenv_0100");
30     EXPECT_EQ("putenv_0100", ret, CMPFLAG);
31     char *test = getenv("test");
32     if (test) {
33         EXPECT_STREQ("putenv_0100", test, "putenv_0100");
34     } else {
35         EXPECT_PTRNE("putenv_0100", test, NULL);
36     }
37 
38     ret = putenv("test=putenv_new");
39     EXPECT_EQ("putenv_0100", ret, CMPFLAG);
40     test = getenv("test");
41     EXPECT_PTRNE("putenv_0100", test, NULL);
42     if (test) {
43         EXPECT_STREQ("putenv_0100", test, "putenv_new");
44     }
45     unsetenv("test");
46 }
47 
48 /**
49  * @tc.name      : putenv_0200
50  * @tc.desc      : Provide exception parameters, add or modify the environment variable test
51  * @tc.level     : Level 2
52  */
putenv_0200(void)53 void putenv_0200(void)
54 {
55     int ret = unsetenv("test");
56     EXPECT_EQ("putenv_0200", ret, CMPFLAG);
57 
58     ret = putenv("test");
59     EXPECT_EQ("putenv_0200", ret, CMPFLAG);
60     char *test = getenv("test");
61     if (!test) {
62         EXPECT_PTREQ("putenv_0200", test, NULL);
63     }
64 
65     ret = putenv("");
66     EXPECT_EQ("putenv_0200", ret, ERREXPECT);
67     unsetenv("test");
68 }
69 
main(void)70 int main(void)
71 {
72     putenv_0100();
73     putenv_0200();
74     return t_status;
75 }