1 #include <gtest/gtest.h> 2 #include <stdio.h> 3 4 using namespace testing::ext; 5 6 class StdioPerrorTest : public testing::Test { SetUp()7 void SetUp() override {} TearDown()8 void TearDown() override {} 9 }; 10 11 /** 12 * @tc.name: perror_001 13 * @tc.desc: Verify if its output meets expectations. 14 * @tc.type: FUNC 15 * */ 16 HWTEST_F(StdioPerrorTest, perror_001, TestSize.Level1) 17 { 18 FILE* file = fopen("failedOpenFile.txt", "r"); 19 EXPECT_EQ(file, nullptr); 20 testing::internal::CaptureStderr(); 21 perror("test perror success"); 22 std::string out = testing::internal::GetCapturedStderr(); 23 const char* perr = "test perror success: No such file or directory\n"; 24 EXPECT_STREQ(perr, out.c_str()); 25 }