/* Copyright (c) 2017-2018, Alden Torres Copyright (c) 2017-2022, Arvid Norberg Copyright (c) 2017, Steven Siloti All rights reserved. You may use, distribute and modify this code under the terms of the BSD license, see LICENSE file. */ #include "libtorrent/config.hpp" #include "libtorrent/span.hpp" #include "test.hpp" #include "setup_transfer.hpp" #include #include using namespace lt; namespace { span f(span x) { return x; } span> g(span> x) { return x; } } // anonymous namespace TORRENT_TEST(span_vector) { std::vector v1 = {1,2,3,4}; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_vector_assignment) { std::vector v1 = {1,2,3,4}; span a; a = v1; TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_assignment) { char v1[] = {1,2,3,4}; span a2(v1); span a; a = a2; TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } namespace { void do_span_temp_vector(span a) { std::vector v1 = {1,2,3,4}; TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } } // anonymous namespace TORRENT_TEST(span_temp_vector) { do_span_temp_vector(std::vector{1,2,3,4}); } TORRENT_TEST(span_std_array) { std::array v1{{1,2,3,4}}; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_const_std_array) { std::array v1{{1,2,3,4}}; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_array) { char v1[] = {1,2,3,4}; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_string) { std::string v1 = "test"; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_const_array) { char const v1[] = {1,2,3,4}; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 4); } TORRENT_TEST(span_single_element) { char const v1 = 1; span a(v1); TEST_CHECK(a == f(v1)); TEST_CHECK(a.size() == 1); } TORRENT_TEST(span_of_spans) { std::vector v1 = {1,2,3,4}; span s1(v1); span> a(s1); TEST_CHECK(a == g(s1)); TEST_CHECK(a.size() == 1); TEST_CHECK(a[0].size() == 4); }