RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
RangeTest.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2017 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; withexpected even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "adt/Range.h"
22#include <ostream>
23#include <set>
24#include <tuple>
25#include <gtest/gtest.h>
26
27using rawspeed::Range;
28
29namespace rawspeed {
30
31template <typename T>
32::std::ostream& operator<<(::std::ostream& os, const Range<T>& r) {
33 if (r.begin() == r.end())
34 return os << "(" << r.begin() << ".." << r.begin() << ")";
35 return os << "[" << r.begin() << ".." << r.end() - 1 << "]";
36}
37
38} // namespace rawspeed
39
40namespace rawspeed_test {
41
42// NOLINTNEXTLINE(google-build-namespaces)
43namespace {
44
45template <typename T>
46[[maybe_unused]]
47::testing::AssertionResult RangeContains(const char* range_expr,
48 const char* pos_expr,
49 const Range<T>& r, const T& pos) {
50 if (RangeContains(r, r.end()))
51 return ::testing::AssertionFailure() << "Range does contain it's end()!";
52
53 if (RangeContains(r, pos))
54 return ::testing::AssertionSuccess();
55
56 return ::testing::AssertionFailure()
57 << "Range " << range_expr << " " << r << " does not contain "
58 << pos_expr << " (" << pos << ")";
59}
60
61template <typename T>
62[[maybe_unused]]
63::testing::AssertionResult RangeDoesntContain(const char* range_expr,
64 const char* pos_expr,
65 const Range<T>& r, const T& pos) {
66 if (RangeContains(r, r.end()))
67 return ::testing::AssertionFailure() << "Range does contain it's end()!";
68
69 if (!RangeContains(r, pos))
70 return ::testing::AssertionSuccess();
71
72 return ::testing::AssertionFailure()
73 << "Range " << range_expr << " " << r << " contains " << pos_expr
74 << " (" << pos << ")";
75}
76
77template <typename T>
78[[maybe_unused]]
79::testing::AssertionResult RangesOverlap(const char* m_expr, const char* n_expr,
80 const T& lhs, const T& rhs) {
81 if (!RangesOverlap(lhs, lhs) || !RangesOverlap(rhs, rhs))
82 return ::testing::AssertionFailure() << "Ranges don't self-overlap!";
83
84 if (RangesOverlap(lhs, rhs) && RangesOverlap(rhs, lhs))
85 return ::testing::AssertionSuccess();
86
87 return ::testing::AssertionFailure()
88 << "Ranges " << m_expr << " and " << n_expr << " (" << lhs << " and "
89 << rhs << ") do not overlap.";
90}
91
92template <typename T>
93[[maybe_unused]]
94::testing::AssertionResult RangesDontOverlap(const char* m_expr,
95 const char* n_expr, const T& lhs,
96 const T& rhs) {
97 if (!RangesOverlap(lhs, lhs) || !RangesOverlap(rhs, rhs))
98 return ::testing::AssertionFailure() << "Ranges don't self-overlap!";
99
100 if (!RangesOverlap(lhs, rhs) && !RangesOverlap(rhs, lhs))
101 return ::testing::AssertionSuccess();
102
103 return ::testing::AssertionFailure()
104 << "Ranges " << m_expr << " and " << n_expr << " (" << lhs << " and "
105 << rhs << ") do overlap.";
106}
107
108using twoRangesType = std::tuple<int, unsigned, int, unsigned>;
109class TwoRangesTest : public ::testing::TestWithParam<twoRangesType> {
110protected:
111 TwoRangesTest() = default;
112 virtual void SetUp() {
113 r0 = Range<int>(std::get<0>(GetParam()), std::get<1>(GetParam()));
114 r1 = Range<int>(std::get<2>(GetParam()), std::get<3>(GetParam()));
115 }
116
119};
121 testing::Combine(testing::Range(0, 3),
122 testing::Range(0U, 3U),
123 testing::Range(0, 3),
124 testing::Range(0U, 3U)));
125
126const std::set<twoRangesType> AllOverlapped{
127 std::make_tuple(0, 0, 0, 0), std::make_tuple(0, 0, 0, 1),
128 std::make_tuple(0, 0, 0, 2), std::make_tuple(0, 1, 0, 0),
129 std::make_tuple(0, 1, 0, 1), std::make_tuple(0, 1, 0, 2),
130 std::make_tuple(0, 2, 0, 0), std::make_tuple(0, 2, 0, 1),
131 std::make_tuple(0, 2, 0, 2), std::make_tuple(0, 2, 1, 0),
132 std::make_tuple(0, 2, 1, 1), std::make_tuple(0, 2, 1, 2),
133 std::make_tuple(1, 0, 0, 2), std::make_tuple(1, 0, 1, 0),
134 std::make_tuple(1, 0, 1, 1), std::make_tuple(1, 0, 1, 2),
135 std::make_tuple(1, 1, 0, 2), std::make_tuple(1, 1, 1, 0),
136 std::make_tuple(1, 1, 1, 1), std::make_tuple(1, 1, 1, 2),
137 std::make_tuple(1, 2, 0, 2), std::make_tuple(1, 2, 1, 0),
138 std::make_tuple(1, 2, 1, 1), std::make_tuple(1, 2, 1, 2),
139 std::make_tuple(1, 2, 2, 0), std::make_tuple(1, 2, 2, 1),
140 std::make_tuple(1, 2, 2, 2), std::make_tuple(2, 0, 1, 2),
141 std::make_tuple(2, 0, 2, 0), std::make_tuple(2, 0, 2, 1),
142 std::make_tuple(2, 0, 2, 2), std::make_tuple(2, 1, 1, 2),
143 std::make_tuple(2, 1, 2, 0), std::make_tuple(2, 1, 2, 1),
144 std::make_tuple(2, 1, 2, 2), std::make_tuple(2, 2, 1, 2),
145 std::make_tuple(2, 2, 2, 0), std::make_tuple(2, 2, 2, 1),
146 std::make_tuple(2, 2, 2, 2),
147};
148
149} // namespace
150
151} // namespace rawspeed_test
INSTANTIATE_TEST_SUITE_P(MD5Test, MD5Test, ::testing::ValuesIn(testCases))
constexpr T RAWSPEED_READNONE end() const
Definition Range.h:45
constexpr T RAWSPEED_READNONE begin() const
Definition Range.h:43
::testing::AssertionResult RangeDoesntContain(const char *range_expr, const char *pos_expr, const Range< T > &r, const T &pos)
Definition RangeTest.h:63
const std::set< twoRangesType > AllOverlapped
Definition RangeTest.h:126
std::tuple< int, unsigned, int, unsigned > twoRangesType
Definition RangeTest.h:108
::testing::AssertionResult RangesDontOverlap(const char *m_expr, const char *n_expr, const T &lhs, const T &rhs)
Definition RangeTest.h:94
::testing::AssertionResult RangesOverlap(const char *m_expr, const char *n_expr, const T &lhs, const T &rhs)
Definition RangeTest.h:79
::testing::AssertionResult RangeContains(const char *range_expr, const char *pos_expr, const Range< T > &r, const T &pos)
Definition RangeTest.h:47
static inline ::std::ostream & operator<<(::std::ostream &os, const T &b)