• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <fcntl.h>
2 #include <gtest/gtest.h>
3 
4 using namespace testing::ext;
5 
6 class FortifyOpenChkTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 /**
12  * @tc.name: __open_chk_001
13  * @tc.desc: Verify that the file can be opened and closed properly when using the __open_chk function to open the file.
14  * @tc.type: FUNC
15  */
16 HWTEST_F(FortifyOpenChkTest, __open_chk_001, TestSize.Level1)
17 {
18     int file = open("test.txt", O_RDONLY | O_CREAT, 0644);
19     close(file);
20     int fd = __open_chk("test.txt", O_RDONLY);
21     ASSERT_NE(fd, -1);
22     close(fd);
23     EXPECT_EQ(0, remove("test.txt"));
24 }