1 #include <gtest/gtest.h> 2 #include <string.h> 3 #define __FORTIFY_COMPILATION 4 #include <fortify/stdio.h> 5 6 using namespace testing::ext; 7 8 class FortifyFwritechkTest : public testing::Test { SetUp()9 void SetUp() override {} TearDown()10 void TearDown() override {} 11 }; 12 13 /** 14 * @tc.name: __fwrite_chk_001 15 * @tc.desc: Verify if the function is functioning properly. 16 * @tc.type: FUNC 17 * */ 18 HWTEST_F(FortifyFwritechkTest, __fwrite_chk_001, TestSize.Level1) 19 { 20 FILE* fptr = fopen("/data/fwritetest.txt", "w+"); 21 EXPECT_TRUE(fptr); 22 23 char buf[] = "fwritetest"; 24 int result = __fwrite_chk(buf, sizeof(char), strlen(buf), fptr, sizeof(buf)); 25 EXPECT_EQ(result, strlen(buf)); 26 27 fclose(fptr); 28 remove("/data/fwritetest.txt"); 29 }