1 #include <gtest/gtest.h> 2 #include <string.h> 3 4 using namespace testing::ext; 5 6 constexpr size_t FOUND_LEN = 5; 7 8 class StringStrcspnTest : public testing::Test { SetUp()9 void SetUp() override {} TearDown()10 void TearDown() override {} 11 }; 12 13 /** 14 * @tc.name: strcspn_001 15 * @tc.desc: Verify the correctness of the strcspn function in searching for a specified set of characters within a 16 * given string, including validation of the returned matching position. 17 * @tc.type: FUNC 18 */ 19 HWTEST_F(StringStrcspnTest, strcspn_001, TestSize.Level1) 20 { 21 const char* str1 = "Hello,world!"; 22 const char* str2 = " ,!"; 23 size_t count = strcspn(str1, str2); 24 EXPECT_EQ(count, FOUND_LEN); 25 } 26 27 /** 28 * @tc.name: strcspn_002 29 * @tc.desc: Verify that when no characters from the specified character set are found in the source string, the strcspn 30 * function will return the length of the source string. 31 * @tc.type: FUNC 32 */ 33 HWTEST_F(StringStrcspnTest, strcspn_002, TestSize.Level1) 34 { 35 const char* str1 = "Hello,world!"; 36 const char* str2 = "xyz"; 37 size_t count = strcspn(str1, str2); 38 EXPECT_EQ(count, strlen(str1)); 39 }