1 #include <gtest/gtest.h> 2 #include <string.h> 3 4 constexpr int MAX_SIZE = 1024; 5 constexpr int SUB_NUM = 1; 6 constexpr int DIV_NUM = 2; 7 8 using namespace testing::ext; 9 10 class StringStrdupTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: bcopy_001 17 * @tc.desc: Verify bcopy functionality is normal 18 * @tc.type: FUNC 19 * */ 20 HWTEST_F(StringStrdupTest, bcopy_001, TestSize.Level1) 21 { 22 char srcChar[MAX_SIZE + SUB_NUM], dstChar[MAX_SIZE + SUB_NUM]; 23 for (int i = 0; i < MAX_SIZE; i++) { 24 memset(srcChar, 'A', MAX_SIZE / DIV_NUM); 25 memset(srcChar + MAX_SIZE / DIV_NUM, 'a', MAX_SIZE / DIV_NUM); 26 memcpy(dstChar, srcChar, MAX_SIZE); 27 28 size_t obj = random() % MAX_SIZE; 29 size_t pos = random() % (MAX_SIZE - obj); 30 memcpy(dstChar + pos, srcChar, obj); 31 bcopy(srcChar, srcChar + pos, obj); 32 int result = memcmp(srcChar, dstChar, MAX_SIZE); 33 EXPECT_EQ(0, result); 34 } 35 }