1 #include <gtest/gtest.h> 2 #include <stdio.h> 3 using namespace testing::ext; 4 5 class StdioFerrorunlockedTest : public testing::Test { SetUp()6 void SetUp() override {} TearDown()7 void TearDown() override {} 8 }; 9 10 /** 11 * @tc.name: ferror_unlocked_001 12 * @tc.desc: Verify that ferror_unlocked correctly detects errors during file reading and returns true when an 13 * error occurs. 14 * @tc.type: FUNC 15 **/ 16 HWTEST_F(StdioFerrorunlockedTest, ferror_unlocked_001, TestSize.Level1) 17 { 18 const char* dirName = "test_ferror_unlocked.txt"; 19 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; 20 int ret = mkdir(dirName, mode); 21 ASSERT_NE(-1, ret); 22 23 FILE* file = fopen("test_ferror_unlocked.txt", "r"); 24 ASSERT_NE(nullptr, file); 25 bool result = false; 26 char buffer[BUFSIZ]; 27 if (fgets(buffer, BUFSIZ, file) == nullptr) { 28 EXPECT_TRUE(ferror_unlocked(file)); 29 result = true; 30 } 31 EXPECT_TRUE(result); 32 fclose(file); 33 remove("test_ferror_unlocked.txt"); 34 }