pitrou commented on code in PR #13354:
URL: https://github.com/apache/arrow/pull/13354#discussion_r894287163
##########
cpp/src/arrow/util/io_util_test.cc:
##########
@@ -159,6 +170,282 @@ TEST(WinErrorFromStatus, Basics) {
}
#endif
+class TestFileDescriptor : public ::testing::Test {
+ public:
+ Result<int> NewFileDescriptor() {
+ // Make a new fd by dup'ing C stdout (why not?)
+ int new_fd = dup(1);
+ if (new_fd < 0) {
+ return IOErrorFromErrno(errno, "Failed to dup() C stdout");
+ }
+ return new_fd;
+ }
+
+ void AssertValidFileDescriptor(int fd) {
+ ASSERT_FALSE(FileIsClosed(fd)) << "Not a valid file descriptor: " << fd;
+ }
+
+ void AssertInvalidFileDescriptor(int fd) {
+ ASSERT_TRUE(FileIsClosed(fd)) << "Unexpectedly valid file descriptor: " <<
fd;
+ }
+};
+
+TEST_F(TestFileDescriptor, Basics) {
+ int new_fd, new_fd2;
+
+ // Default initialization
+ FileDescriptor a;
+ ASSERT_EQ(a.fd(), -1);
+ ASSERT_TRUE(a.closed());
+ ASSERT_OK(a.Close());
+ ASSERT_OK(a.Close());
+
+ // Assignment
+ ASSERT_OK_AND_ASSIGN(new_fd, NewFileDescriptor());
+ AssertValidFileDescriptor(new_fd);
+ a = FileDescriptor(new_fd);
+ ASSERT_FALSE(a.closed());
+ ASSERT_GT(a.fd(), 2);
Review Comment:
At least CI is passing :-) We can relax if we encounter a failure IMHO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]