• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <string.h>
3 
4 constexpr int STR_SIZE_ONE = 10;
5 constexpr int STR_SIZE_TWO = 14;
6 constexpr int STR_SIZE_THREE = 15;
7 
8 using namespace testing::ext;
9 
10 class StringStrncpyTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: strncpy_001
17  * @tc.desc: Verify that it functions normally
18  * @tc.type: FUNC
19  * */
20 HWTEST_F(StringStrncpyTest, strncpy_001, TestSize.Level1)
21 {
22     const char* srcChar = "012345678";
23     char dstChar[STR_SIZE_ONE];
24 
25     strncpy(dstChar, srcChar, STR_SIZE_ONE);
26     EXPECT_STREQ("012345678", dstChar);
27 
28     char dstChar2[STR_SIZE_THREE];
29 
30     strncpy(dstChar2, srcChar, STR_SIZE_THREE);
31     EXPECT_STREQ("012345678", dstChar2);
32     EXPECT_EQ('\0', dstChar2[STR_SIZE_TWO]);
33 
34     srcChar = nullptr;
35 }