1 #include <gtest/gtest.h> 2 #include <string.h> 3 4 using namespace testing::ext; 5 6 constexpr size_t BUF_SIZE = 10; 7 constexpr size_t STR_SIZE = 128; 8 9 class StringStrchrTest : public testing::Test { SetUp()10 void SetUp() override {} TearDown()11 void TearDown() override {} 12 }; 13 14 /** 15 * @tc.name: strchr_001 16 * @tc.desc: Verify that when the null character '\0' is found in the given string, the strchr function can return a 17 * * pointer pointing to that null character. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(StringStrchrTest, strchr_001, TestSize.Level1) 21 { 22 char bufChar[BUF_SIZE]; 23 const char* s = "56789"; 24 memcpy(bufChar, s, strlen(s) + 1); 25 EXPECT_EQ(strchr(bufChar, '\0'), (bufChar + strlen(s))); 26 } 27 28 /** 29 * @tc.name: strchr_002 30 * @tc.desc: Verify that when searching for the character 'b' in the given string, the strchr function can return a 31 * * pointer to the first matching character 'b'. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(StringStrchrTest, strchr_002, TestSize.Level1) 35 { 36 char strChar[STR_SIZE]; 37 memset(strChar, 'b', sizeof(strChar) - 1); 38 strChar[sizeof(strChar) - 1] = '\0'; 39 for (size_t i = 0; i < sizeof(strChar) - 1; i++) { 40 EXPECT_TRUE(strchr(strChar, 'b') == &strChar[i]); 41 strChar[i] = 'c'; 42 } 43 }