1 #include <cstdlib> 2 #include <errno.h> 3 #include <gtest/gtest.h> 4 #include <iostream> 5 6 using namespace testing::ext; 7 8 class StdioClearerrunlockedTest : public testing::Test { SetUp()9 void SetUp() override {} TearDown()10 void TearDown() override {} 11 }; 12 13 /** 14 * @tc.name: clearerr_unlocked_001 15 * @tc.desc: Test the usage of clearerr_unlocked to clear error indicators on a file stream, ensuring the stream 16 * is ready for further operations. 17 * @tc.type: FUNC 18 **/ 19 HWTEST_F(StdioClearerrunlockedTest, clearerr_unlocked_001, TestSize.Level1) 20 { 21 FILE* file; 22 int ch; 23 errno = 0; 24 file = fopen("/proc/version", "r"); 25 ASSERT_NE(nullptr, file); 26 while ((ch = fgetc(file)) != EOF) { 27 } 28 clearerr_unlocked(file); 29 EXPECT_EQ(0, errno); 30 fclose(file); 31 }