• 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 <unistd.h>
17 #include <errno.h>
18 #include <limits.h>
19 #include <string.h>
20 #include "functionalext.h"
21 
22 // Manual test result
23 char *manual = "/data/tests/libc-test/src/functionalext/supplement/unistd";
24 // hdc shell test result
25 char *hdc_auto = "/";
26 
27 /*
28  * @tc.name      : getcwd_0100
29  * @tc.desc      : Verify that the absolute path of the current working directory can be obtained
30  *                 (parameters are valid)
31  * @tc.level     : Level 0
32  */
getcwd_0100(void)33 void getcwd_0100(void)
34 {
35     char *result;
36     char buf[200];
37     result = getcwd(buf, sizeof(buf));
38 
39     if (!(strcmp(result, manual) ^ strcmp(result, hdc_auto))) {
40         t_error("%s getcwd failed, except result is %s when manual or %s when hdc test\n", __func__, manual, hdc_auto);
41     }
42 }
43 
44 /*
45  * @tc.name      : getcwd_0200
46  * @tc.desc      : Verify that the absolute path of the current working directory can be obtained (parameter is NULL)
47  * @tc.level     : Level 1
48  */
getcwd_0200(void)49 void getcwd_0200(void)
50 {
51     char *result;
52     result = getcwd(NULL, 200);
53     if (!(strcmp(result, manual) ^ strcmp(result, hdc_auto))) {
54         t_error("%s getcwd failed, except result is %s when manual or %s when hdc test\n", __func__, manual, hdc_auto);
55     }
56 }
57 
58 /*
59  * @tc.name      : getcwd_0300
60  * @tc.desc      : Verify that the absolute path of the current working directory cannot be obtained (parameter is 0)
61  * @tc.level     : Level 2
62  */
getcwd_0300(void)63 void getcwd_0300(void)
64 {
65     char *result;
66     char buf[200];
67     result = getcwd(buf, 0);
68     if (result) {
69         t_error("%s getcwd should failed, the result should be null\n", __func__);
70     }
71 }
72 
main(int argc,char * argv[])73 int main(int argc, char *argv[])
74 {
75     getcwd_0100();
76     getcwd_0200();
77     getcwd_0300();
78     return t_status;
79 }