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 <fcntl.h> 17#include <stdio.h> 18#include <stdlib.h> 19#include "functionalext.h" 20 21const int32_t PUTC_RET = 112; 22const int32_t CREAT_MODE = 666; 23 24/** 25 * @tc.name : putc_0100 26 * @tc.desc : Verify putc process success 27 * @tc.level : Level 0 28 */ 29void putc_0100(void) 30{ 31 int32_t ret = creat("putc_0100.txt", CREAT_MODE); 32 if (ret < 0) { 33 EXPECT_MT("pread_0100", ret, 0); 34 return; 35 } 36 FILE *fptr = fopen("putc_0100.txt", "w"); 37 if (!fptr) { 38 EXPECT_PTRNE("putc_0100", fptr, NULL); 39 return; 40 } 41 EXPECT_PTRNE("putc_0100", fptr, NULL); 42 EXPECT_EQ("putc_0100", putc('p', fptr), PUTC_RET); 43 ret = fclose(fptr); 44 EXPECT_EQ("putc_0100", ret, 0); 45 remove("putc_0100.txt"); 46} 47 48/** 49 * @tc.name : putc_0200 50 * @tc.desc : Verify putc process failed 51 * @tc.level : Level 2 52 */ 53void putc_0200(void) 54{ 55 int ret = creat("putc_0200.txt", CREAT_MODE); 56 if (ret < 0) { 57 EXPECT_MT("pread_0200", ret, 0); 58 return; 59 } 60 FILE *fptr = fopen("putc_0200.txt", "r"); 61 if (!fptr) { 62 EXPECT_PTRNE("putc_0200", fptr, NULL); 63 return; 64 } 65 EXPECT_EQ("putc_0200", putc('p', fptr), EOF); 66 ret = fclose(fptr); 67 EXPECT_EQ("putc_0100", ret, 0); 68 remove("putc_0200.txt"); 69} 70 71int main(void) 72{ 73 putc_0100(); 74 putc_0200(); 75 return t_status; 76} 77