1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <sal/config.h>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
18 #include <o3tl/array_view.hxx>
22 class Test
: public CppUnit::TestFixture
{
24 CPPUNIT_TEST_SUITE(Test
);
25 CPPUNIT_TEST(testOperations
);
26 CPPUNIT_TEST_SUITE_END();
29 void testOperations() {
30 int const some_data
[] { 1, 2, 3 };
31 o3tl::array_view
<int const> v(some_data
);
33 CPPUNIT_ASSERT_EQUAL(1, *v
.begin());
35 o3tl::array_view
<int>::difference_type(3), v
.end() - v
.begin());
36 CPPUNIT_ASSERT_EQUAL(1, *v
.cbegin());
38 o3tl::array_view
<int>::difference_type(3), v
.cend() - v
.cbegin());
39 CPPUNIT_ASSERT_EQUAL(3, *v
.rbegin());
41 o3tl::array_view
<int>::difference_type(3), v
.rend() - v
.rbegin());
42 CPPUNIT_ASSERT_EQUAL(3, *v
.crbegin());
44 o3tl::array_view
<int>::difference_type(3), v
.crend() - v
.crbegin());
45 CPPUNIT_ASSERT_EQUAL(o3tl::array_view
<int>::size_type(3), v
.size());
46 CPPUNIT_ASSERT_EQUAL(o3tl::array_view
<int>::size_type(3), v
.length());
47 CPPUNIT_ASSERT_EQUAL(o3tl::array_view
<int>::npos
- 1, v
.max_size());
48 CPPUNIT_ASSERT(!v
.empty());
49 CPPUNIT_ASSERT_EQUAL(2, v
[1]);
51 v
.at(o3tl::array_view
<int>::npos
);
52 CPPUNIT_FAIL("missing exception");
53 } catch (std::out_of_range
&) {}
54 CPPUNIT_ASSERT_EQUAL(1, v
.at(0));
55 CPPUNIT_ASSERT_EQUAL(3, v
.at(2));
58 CPPUNIT_FAIL("missing exception");
59 } catch (std::out_of_range
&) {}
60 CPPUNIT_ASSERT_EQUAL(1, v
.front());
61 CPPUNIT_ASSERT_EQUAL(3, v
.back());
62 CPPUNIT_ASSERT_EQUAL(1, *v
.data());
64 int const d1
[] { 1, 2 };
65 int const d2
[] { 3, 4, 5, 6 };
66 o3tl::array_view
<int const> v1( d1
);
67 o3tl::array_view
<int const> v2( d2
);
69 CPPUNIT_ASSERT_EQUAL(o3tl::array_view
<int>::size_type(4), v1
.size());
70 CPPUNIT_ASSERT_EQUAL(o3tl::array_view
<int>::size_type(2), v2
.size());
74 o3tl::array_view
<int> v1(d1
);
75 o3tl::array_view
<int const> v2
;
76 v2
= v1
; // the special operator=
81 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */