ceph_shutdown(cmount);
}
+TEST(LibCephFS, OpenReadTruncate) {
+ struct ceph_mount_info *cmount;
+ ASSERT_EQ(0, ceph_create(&cmount, NULL));
+ ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+ ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+ ASSERT_EQ(0, ceph_mount(cmount, "/"));
+
+ auto path = "test_open_rdt_" + std::to_string(getpid());
+ int fd = ceph_open(cmount, path.c_str(), O_WRONLY|O_CREAT, 0666);
+ ASSERT_LE(0, fd);
+
+ auto data = std::string("hello world");
+ ASSERT_EQ(ceph_write(cmount, fd, data.c_str(), data.size(), 0), (int)data.size());
+ ASSERT_EQ(0, ceph_close(cmount, fd));
+
+ fd = ceph_open(cmount, path.c_str(), O_RDONLY, 0);
+ ASSERT_LE(0, fd);
+ ASSERT_EQ(ceph_ftruncate(cmount, fd, 0), -EBADF);
+ ASSERT_EQ(ceph_ftruncate(cmount, fd, 1), -EBADF);
+ ASSERT_EQ(0, ceph_close(cmount, fd));
+
+ ceph_shutdown(cmount);
+}
+
TEST(LibCephFS, OpenReadWrite) {
struct ceph_mount_info *cmount;
ASSERT_EQ(0, ceph_create(&cmount, NULL));