1 #include <fcntl.h> 2 #include <gtest/gtest.h> 3 #include <string.h> 4 #include <unistd.h> 5 6 using namespace testing::ext; 7 8 class StdioGetwcharTest : public testing::Test { SetUp()9 void SetUp() override {} TearDown()10 void TearDown() override {} 11 }; 12 13 /** 14 * @tc.name: getwchar_001 15 * @tc.desc: Verify whether the read operation of this getwchar is normal. 16 * @tc.type: FUNC 17 * */ 18 HWTEST_F(StdioGetwcharTest, getwchar_001, TestSize.Level1) 19 { 20 pid_t pid; 21 pid = fork(); 22 ASSERT_LE(0, pid); 23 if (pid == 0) { 24 wint_t str; 25 int fd = open("/proc/version", O_RDONLY); 26 int orgFd = STDIN_FILENO; 27 dup2(fd, STDIN_FILENO); 28 str = getwchar(); 29 EXPECT_TRUE(str); 30 dup2(orgFd, STDIN_FILENO); 31 close(fd); 32 _exit(0); 33 } else { 34 waitpid(pid, nullptr, 0); 35 } 36 }