#include <folly/FileUtil.h>
#include <folly/detail/FileUtilDetail.h>
+#include <folly/experimental/TestUtil.h>
#include <deque>
class IovecBuffers {
public:
explicit IovecBuffers(std::initializer_list<size_t> sizes);
+ explicit IovecBuffers(std::vector<size_t> sizes);
std::vector<iovec> iov() const { return iov_; } // yes, make a copy
std::string join() const { return folly::join("", buffers_); }
}
}
+IovecBuffers::IovecBuffers(std::vector<size_t> sizes) {
+ iov_.reserve(sizes.size());
+ for (auto s : sizes) {
+ buffers_.push_back(std::string(s, '\0'));
+ }
+ for (auto& b : buffers_) {
+ iovec iov;
+ iov.iov_base = &b[0];
+ iov.iov_len = b.size();
+ iov_.push_back(iov);
+ }
+}
+
size_t IovecBuffers::size() const {
size_t s = 0;
for (auto& b : buffers_) {
}
}
+TEST(FileUtilTest2, wrapv) {
+ TemporaryFile tempFile("file-util-test");
+ std::vector<size_t> sizes;
+ size_t sum = 0;
+ for (int32_t i = 0; i < 1500; ++i) {
+ sizes.push_back(i % 3 + 1);
+ sum += sizes.back();
+ }
+ IovecBuffers buf(sizes);
+ ASSERT_EQ(sum, buf.size());
+ auto iov = buf.iov();
+ EXPECT_EQ(sum, wrapvFull(writev, tempFile.fd(), iov.data(), iov.size()));
+}
+
#if FOLLY_HAVE_PREADV
TEST_F(FileUtilTest, preadv) {
for (auto& p : readers_) {