1 #include <gtest/gtest.h> 2 #include <string.h> 3 4 using namespace testing::ext; 5 6 constexpr size_t SRC_SIZE = 1024; 7 constexpr size_t DST_SIZE = 1024; 8 constexpr size_t RAND_LEN = 512; 9 10 class StringStrcatTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: strcat_001 17 * @tc.desc: Verify the correctness of the strcat function for string concatenation, including validation of the lengths 18 * of the destination and source strings, handling of null terminators, and correctness of the concatenated 19 * string. 20 * @tc.type: FUNC 21 */ 22 HWTEST_F(StringStrcatTest, strcat_001, TestSize.Level1) 23 { 24 char dstChar[DST_SIZE], srcChar[SRC_SIZE]; 25 memset(dstChar, 'A', DST_SIZE); 26 dstChar[DST_SIZE - 1] = '\0'; 27 memset(srcChar, 'M', RAND_LEN); 28 srcChar[random() % RAND_LEN] = '\0'; 29 srcChar[RAND_LEN - 1] = '\0'; 30 EXPECT_TRUE(strcat(dstChar, srcChar) == dstChar); 31 }