1 #include <fnmatch.h> 2 #include <gtest/gtest.h> 3 #include <sys/stat.h> 4 using namespace testing::ext; 5 6 class RegexFnmatchTest : public testing::Test { SetUp()7 void SetUp() override {} TearDown()8 void TearDown() override {} 9 }; 10 11 /** 12 * @tc.name: fnmatch_001 13 * @tc.desc: Ensure that the fnmatch() function correctly matches the given string against the specified pattern. 14 * @tc.type: FUNC 15 **/ 16 HWTEST_F(RegexFnmatchTest, fnmatch_001, TestSize.Level1) 17 { 18 const char* dirname = "test_fnmatch.txt"; 19 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; 20 ASSERT_NE(-1, mkdir(dirname, mode)); 21 22 const char* pattern = "*.txt"; 23 const char* string = "/test_fnmatch.txt"; 24 int result = fnmatch(pattern, string, 0); 25 EXPECT_EQ(0, result); 26 27 remove("test_fnmatch.txt"); 28 } 29 30 /** 31 * @tc.name: fnmatch_002 32 * @tc.desc: Confirm that the fnmatch function correctly identifies that the given pattern does not match the 33 * specified input string. 34 * @tc.type: FUNC 35 **/ 36 HWTEST_F(RegexFnmatchTest, fnmatch_002, TestSize.Level1) 37 { 38 const char* pattern = "*.txt"; 39 const char* string = " "; 40 int result = fnmatch(pattern, string, 0); 41 EXPECT_EQ(FNM_NOMATCH, result); 42 }