Bump version to 6.4.7.2.M8
[LibreOffice.git] / o3tl / qa / test-span.cxx
blob26eedfc219381a881a64dedcd21e26a0e407280c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <cstddef>
13 #include <utility>
15 #include <cppunit/TestAssert.h>
16 #include <cppunit/TestFixture.h>
17 #include <cppunit/extensions/HelperMacros.h>
19 #include <o3tl/span.hxx>
21 namespace {
23 class Test: public CppUnit::TestFixture {
24 private:
25 CPPUNIT_TEST_SUITE(Test);
26 CPPUNIT_TEST(testOperations);
27 CPPUNIT_TEST_SUITE_END();
30 void testOperations() {
31 int const some_data[] { 1, 2, 3 };
32 o3tl::span<int const> v(some_data);
34 CPPUNIT_ASSERT_EQUAL(1, *v.begin());
35 CPPUNIT_ASSERT_EQUAL(
36 o3tl::span<int>::difference_type(3), v.end() - v.begin());
37 CPPUNIT_ASSERT_EQUAL(3, *v.rbegin());
38 CPPUNIT_ASSERT_EQUAL(
39 o3tl::span<int>::difference_type(3), v.rend() - v.rbegin());
40 CPPUNIT_ASSERT_EQUAL(std::size_t(3), v.size());
41 CPPUNIT_ASSERT(!v.empty());
42 CPPUNIT_ASSERT_EQUAL(2, v[1]);
43 CPPUNIT_ASSERT_EQUAL(1, *v.data());
45 int const d1[] { 1, 2 };
46 int const d2[] { 3, 4, 5, 6 };
47 o3tl::span<int const> v1( d1 );
48 o3tl::span<int const> v2( d2 );
49 std::swap(v1, v2);
50 CPPUNIT_ASSERT_EQUAL(std::size_t(4), v1.size());
51 CPPUNIT_ASSERT_EQUAL(std::size_t(2), v2.size());
56 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
60 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */