• 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 <stdio.h>
17 #include "functionalext.h"
18 
19 const int SIZE = 97;
20 
21 /**
22  * @tc.name      : getc_unlocked_0100
23  * @tc.desc      : The parameter is valid, and the specified character can be obtained.
24  * @tc.level     : Level 0
25  */
getc_unlocked_0100(void)26 void getc_unlocked_0100(void)
27 {
28     const char *ptr = "getc_unlockedtest.txt";
29     FILE *fptr = fopen(ptr, "wr+");
30     EXPECT_TRUE("getc_unlocked_0100", fptr != NULL);
31     const char *wstr = "a";
32     fwrite(wstr, sizeof(char), strlen(wstr), fptr);
33     fseek(fptr, 0, SEEK_SET);
34     int ret = getc_unlocked(fptr);
35     EXPECT_EQ("getc_unlocked_0100", ret, SIZE);
36     fclose(fptr);
37     remove(ptr);
38     fptr = NULL;
39     ptr = NULL;
40 }
41 
42 /**
43  * @tc.name      : getc_unlocked_0200
44  * @tc.desc      : The parameter f is invalid, and the specified character cannot be obtained.
45  * @tc.level     : Level 2
46  */
getc_unlocked_0200(void)47 void getc_unlocked_0200(void)
48 {
49     const char *ptr = "getc_unlockedtest.txt";
50     FILE *fptr = fopen(ptr, "wr+");
51     EXPECT_TRUE("getc_unlocked_0200", fptr != NULL);
52     fclose(fptr);
53     fptr = fopen(ptr, "r");
54     EXPECT_TRUE("getc_unlocked_0200", fptr != NULL);
55     int ret = getc_unlocked(fptr);
56     EXPECT_EQ("getc_unlocked_0200", ret, EOF);
57     fclose(fptr);
58     remove(ptr);
59     fptr = NULL;
60     ptr = NULL;
61 }
62 
main(int argc,char * argv[])63 int main(int argc, char *argv[])
64 {
65     getc_unlocked_0100();
66     getc_unlocked_0200();
67     return t_status;
68 }