Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / gil / test / image_view / collection.cpp
1 //
2 // Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #include <boost/gil/image.hpp>
9 #include <boost/gil/image_view.hpp>
10 #include <boost/gil/typedefs.hpp>
11
12 #include <boost/core/lightweight_test.hpp>
13
14 namespace gil = boost::gil;
15
16 gil::gray8_pixel_t const gray128(128);
17 gil::gray8_pixel_t const gray255(255);
18
19 void test_begin()
20 {
21     gil::gray8_image_t image(2, 2, gray255);
22     auto view = gil::view(image);
23     BOOST_TEST(*view.begin() == gray255);
24 }
25
26 void test_end()
27 {
28     gil::gray8_image_t::view_t view;
29     BOOST_TEST(view.begin() == view.end());
30 }
31
32 void test_rbegin()
33 {
34     gil::gray8_image_t image(2, 2, gray255);
35     auto view = gil::view(image);
36     view(1,1) = gray128;
37     BOOST_TEST(*view.rbegin() == gray128);
38 }
39
40 void test_rend()
41 {
42     gil::gray8_image_t::view_t view;
43     BOOST_TEST(view.rbegin() == view.rend());
44 }
45
46 void test_front()
47 {
48     gil::gray8_image_t image(2, 2, gray255);
49     auto view = gil::view(image);
50     BOOST_TEST(view.front() == gray255);
51 }
52
53 void test_back()
54 {
55     gil::gray8_image_t image(2, 2, gray255);
56     auto view = gil::view(image);
57     BOOST_TEST(view.back() == gray255);
58 }
59
60 void test_empty()
61 {
62     gil::gray8_image_t::view_t view;
63     BOOST_TEST(view.empty());
64
65     gil::gray8_image_t image(2, 2);
66     view = gil::view(image);
67     BOOST_TEST(!view.empty());
68 }
69
70 void test_size()
71 {
72     gil::gray8_image_t::view_t view;
73     BOOST_TEST_EQ(view.size(), 0);
74
75     gil::gray8_image_t image(2, 2);
76     view = gil::view(image);
77     BOOST_TEST_EQ(view.size(), 4);
78 }
79
80 void test_swap()
81 {
82     gil::gray8_image_t::view_t view1;
83     gil::gray8_image_t::view_t view2;
84
85     gil::gray8_image_t image(2, 2);
86     view1 = gil::view(image);
87     view1.swap(view2);
88
89     BOOST_TEST(view1.empty());
90     BOOST_TEST(!view2.empty());
91 }
92
93 int main()
94 {
95     // Collection
96     test_begin();
97     test_end();
98     test_size();
99     test_empty();
100     test_swap();
101
102     // ForwardCollection
103     test_front();
104
105     // ReversibleCollection
106     test_rbegin();
107     test_rend();
108     test_back();
109
110     return boost::report_errors();
111 }