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 "functionalext.h"
17 #include "filepath_util.h"
18
19 /**
20 * @tc.name : fputc_0100
21 * @tc.desc : Verify that a character can be written to the file
22 * @tc.level : level 0.
23 */
fputc_0100(void)24 void fputc_0100(void)
25 {
26 char path[PATH_MAX] = {0};
27 FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path);
28 FILE *fptr = fopen(path, "w");
29 int Exit = fputc('a', fptr);
30 EXPECT_EQ("fputc_0100", Exit, 97);
31 fclose(fptr);
32 }
33
34 /**
35 * @tc.name : fputc_0200
36 * @tc.desc : Verify that a character cannot be written to the file
37 * @tc.level : level 2.
38 */
fputc_0200(void)39 void fputc_0200(void)
40 {
41 char path[PATH_MAX] = {0};
42 FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path);
43 FILE *fptr = fopen(path, "r");
44 int Exit = fputc('a', fptr);
45 EXPECT_EQ("fputc_0200", Exit, EOF);
46 fclose(fptr);
47 remove(path);
48 }
49
main(void)50 int main(void)
51 {
52 fputc_0100();
53 fputc_0200();
54 return t_status;
55 }