1 /*
2 Copyright 2013-2014 EditShare, 2013-2015 Skytechnology sp. z o.o.
3
4 This file is part of LizardFS.
5
6 LizardFS is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3.
9
10 LizardFS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "common/platform.h"
20 #include "mount/client/iovec_traits.h"
21
22 #include <gtest/gtest.h>
23
TEST(IoVecTraits,MemcpyAndCopy)24 TEST(IoVecTraits, MemcpyAndCopy) {
25 char buf[] = "abcdefghijklmnopqrstuvwxyz";
26 char out[512] = {0};
27 std::vector<struct iovec> iov{{out, 1}, {out + 1, 2}, {out, 0}, {out + 1, 0}, {out + 3, 3}, {out + 6, 11}, {nullptr, 0}};
28 memcpyIoVec(iov.data(), iov.size(), buf, 9);
29
30 ASSERT_EQ(std::string(out), "abcdefghi");
31
32 std::vector<struct iovec> iov2{{out + 128, 2}, {out + 130, 1}, {nullptr, 0}, {out + 131, 4}, {out + 135, 16}};
33 ssize_t ret = copyIoVec(iov2.data(), iov2.size(), iov.data(), iov.size());
34 ASSERT_EQ(ret, 17);
35 ASSERT_EQ(std::string(out + 128), std::string(out));
36 }
37