1 #include <gtest/gtest.h> 2 #include <string.h> 3 4 constexpr int BUF_SIZE = 10; 5 constexpr int BUF_SIZE_TWO = 14; 6 constexpr int BUF_SIZE_THREE = 15; 7 8 using namespace testing::ext; 9 10 class FortifyStrcpychkTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 extern "C" char* __strcpy_chk(char* dest, const char* src, size_t dst_len); 16 17 /** 18 * @tc.name: __strcpy_chk_001 19 * @tc.desc: Verify if the __strcpy_chk is functioning properly. 20 * @tc.type: FUNC 21 * */ 22 HWTEST_F(FortifyStrcpychkTest, __strcpy_chk_001, TestSize.Level1) 23 { 24 const char* srcChar = "012345678"; 25 char dstChar[BUF_SIZE]; 26 __strcpy_chk(dstChar, srcChar, BUF_SIZE); 27 EXPECT_STREQ("012345678", dstChar); 28 char dstChar2[BUF_SIZE_THREE]; 29 __strcpy_chk(dstChar2, srcChar, BUF_SIZE_THREE); 30 EXPECT_STREQ("012345678", dstChar2); 31 EXPECT_EQ('\0', dstChar2[BUF_SIZE_TWO]); 32 srcChar = nullptr; 33 }