1 #include <fcntl.h> 2 #include <gtest/gtest.h> 3 #include <stdlib.h> 4 #include <sys/auxv.h> 5 #include <sys/uio.h> 6 #include <unistd.h> 7 8 using namespace testing::ext; 9 10 constexpr size_t BUF_SIZE = 2; 11 12 class UnistdReadlinkTest : public testing::Test { SetUp()13 void SetUp() override {} TearDown()14 void TearDown() override {} 15 }; 16 17 /** 18 * @tc.name: readlink_001 19 * @tc.desc: checking the behavior of the readlink function. 20 * @tc.type: FUNC 21 * */ 22 HWTEST_F(UnistdReadlinkTest, readlink_001, TestSize.Level1) 23 { 24 char buf[1]; 25 EXPECT_EQ(-1, readlink("/dev/null", buf, BUF_SIZE)); 26 } 27 28 /** 29 * @tc.name: readlink_002 30 * @tc.desc: Verify the correctness of the readlink function for symbolic link files in a specific path. 31 * @tc.type: FUNC 32 * */ 33 HWTEST_F(UnistdReadlinkTest, readlink_002, TestSize.Level1) 34 { 35 char path[PATH_MAX]; 36 size_t length = readlink("/dev/fd", path, sizeof(path)); 37 ASSERT_LT(0, length); 38 EXPECT_EQ("/proc/self/fd", std::string(path, length)); 39 }