• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <string.h>
3 
4 using namespace testing::ext;
5 
6 constexpr size_t SRC_SIZE = 1024;
7 
8 class StringMemcpyTest : public testing::Test {
SetUp()9     void SetUp() override {}
TearDown()10     void TearDown() override {}
11 };
12 
13 /**
14  * @tc.name: memcpy_001
15  * @tc.desc: Verify that memcpy can accurately copy an entire string including the null terminator.
16  * @tc.type: FUNC
17  */
18 HWTEST_F(StringMemcpyTest, memcpy_001, TestSize.Level1)
19 {
20     char dst[] = "Hello, World!";
21     char src[SRC_SIZE];
22     memcpy(src, dst, sizeof(dst));
23     EXPECT_STREQ(src, dst);
24 }
25 
26 /**
27  * @tc.name: memcpy_002
28  * @tc.desc: Check if memcpy does not alter the source string when copying zero bytes.
29  * @tc.type: FUNC
30  */
31 HWTEST_F(StringMemcpyTest, memcpy_002, TestSize.Level1)
32 {
33     const char* dst = "Hello, World!";
34     char src[SRC_SIZE] = {};
35     memcpy(src, dst, 0);
36     EXPECT_STREQ(src, "");
37 }