• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <stdint.h>
3 #include <string.h>
4 
5 using namespace testing::ext;
6 
7 class StringMemchrTest : public testing::Test {
SetUp()8     void SetUp() override {}
TearDown()9     void TearDown() override {}
10 };
11 
12 /**
13  * @tc.name: memchr_001
14  * @tc.desc: Test the memchr function to verify if it correctly handles empty string input, and if the target character
15  *           does not exist in an empty string, returns nullptr.
16  * @tc.type: FUNC
17  */
18 HWTEST_F(StringMemchrTest, memchr_001, TestSize.Level1)
19 {
20     const char* sourceString = "";
21     const void* foundChar = memchr(sourceString, 'w', strlen(sourceString));
22     EXPECT_EQ(foundChar, nullptr);
23 }
24 
25 /**
26  * @tc.name: memchr_002
27  * @tc.desc: Test the memchr function to verify if it correctly handles the case where the maximum number of bytes to
28  *           search is 0 and returns nullptr.
29  * @tc.type: FUNC
30  */
31 HWTEST_F(StringMemchrTest, memchr_002, TestSize.Level1)
32 {
33     const char* sourceString = "Hello, world";
34     const void* foundChar = memchr(sourceString, 'w', 0);
35     EXPECT_EQ(foundChar, nullptr);
36 }
37 
38 /**
39  * @tc.name: memchr_003
40  * @tc.desc: Verify memchr ability to correctly search for a specified character in a given string and return the
41  *           correct result.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(StringMemchrTest, memchr_003, TestSize.Level1)
45 {
46     const char* sourceString = "Hello, world";
47     const void* foundChar = memchr(sourceString, 'w', strlen(sourceString));
48     ASSERT_NE(foundChar, nullptr);
49 }