RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
CameraSensorInfoTest.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2009-2014 Klaus Post
5 Copyright (C) 2016 Roman Lebedev
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
23#include <algorithm>
24#include <cstdlib>
25#include <iostream>
26#include <limits>
27#include <memory>
28#include <tuple>
29#include <vector>
30#include <gmock/gmock.h>
31#include <gtest/gtest.h>
32
34using std::unique_ptr;
35
36namespace rawspeed_test {
37
38namespace {
39
40std::vector<int> ISOList(6);
41
43 : public ::testing::TestWithParam<std::tuple<int, int>> {
44protected:
46 : mBlackLevel(std::rand()), // NOLINT(cert-msc50-cpp): do not need
47 // crypto-level randomness
48 mWhiteLevel(std::rand()), // NOLINT(cert-msc50-cpp): do not need
49 // crypto-level randomness
51 std::rand(), // NOLINT(cert-msc50-cpp): do not need crypto-level
52 // randomness
53 std::rand(), // NOLINT(cert-msc50-cpp): do not need crypto-level
54 // randomness
55 std::rand(), // NOLINT(cert-msc50-cpp): do not need crypto-level
56 // randomness
57 std::rand() // NOLINT(cert-msc50-cpp): do not need crypto-level
58 // randomness
59 }) {}
60 virtual void SetUp() final {
61 mMinIso = std::get<0>(GetParam());
62 mMaxIso = std::get<1>(GetParam());
63 }
64
65 void checkHelper(const CameraSensorInfo& csi) {
66 ASSERT_EQ(csi.mBlackLevel, mBlackLevel);
67 ASSERT_EQ(csi.mWhiteLevel, mWhiteLevel);
68 ASSERT_EQ(csi.mMinIso, mMinIso);
69 ASSERT_EQ(csi.mMaxIso, mMaxIso);
71 }
72
74 ASSERT_EQ(a.mBlackLevel, b.mBlackLevel);
75 ASSERT_EQ(a.mWhiteLevel, b.mWhiteLevel);
76 ASSERT_EQ(a.mMinIso, b.mMinIso);
77 ASSERT_EQ(a.mMaxIso, b.mMaxIso);
79 }
80
83 int mMinIso{-1};
84 int mMaxIso{-1};
85 std::vector<int> mBlackLevelSeparate;
86};
87
89 testing::Combine(testing::ValuesIn(ISOList), // min iso
90 testing::ValuesIn(ISOList) // max iso
91 ));
92
94 ASSERT_NO_THROW({
95 CameraSensorInfo Info(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
96 mBlackLevelSeparate);
97 });
98
99 ASSERT_NO_THROW({
100 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(
101 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
102 });
103}
104
106 {
107 const CameraSensorInfo Info(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
108 mBlackLevelSeparate);
109
110 checkHelper(Info);
111 }
112
113 {
114 const unique_ptr<const CameraSensorInfo> Info(new CameraSensorInfo(
115 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
116
117 checkHelper(*Info);
118 }
119}
120
121TEST_P(CameraSensorInfoTestDumb, AssignmentConstructor) {
122 ASSERT_NO_THROW({
123 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
124 mBlackLevelSeparate);
125 CameraSensorInfo Info(InfoOrig);
126 });
127
128 ASSERT_NO_THROW({
129 const unique_ptr<const CameraSensorInfo> InfoOrig(new CameraSensorInfo(
130 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
131 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(*InfoOrig));
132 });
133
134 ASSERT_NO_THROW({
135 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
136 mBlackLevelSeparate);
137 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(InfoOrig));
138 });
139
140 ASSERT_NO_THROW({
141 const unique_ptr<const CameraSensorInfo> InfoOrig(new CameraSensorInfo(
142 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
143 CameraSensorInfo Info(*InfoOrig);
144 });
145}
146
147TEST_P(CameraSensorInfoTestDumb, AssignmentConstructorGetters) {
148 {
149 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
150 mBlackLevelSeparate);
151 CameraSensorInfo Info(InfoOrig);
152
153 checkHelper(Info);
154 checkHelper(Info, InfoOrig);
155 }
156
157 {
158 const unique_ptr<const CameraSensorInfo> InfoOrig(new CameraSensorInfo(
159 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
160 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(*InfoOrig));
161
162 checkHelper(*Info);
163 checkHelper(*Info, *InfoOrig);
164 }
165
166 {
167 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
168 mBlackLevelSeparate);
169 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(InfoOrig));
170
171 checkHelper(*Info);
172 checkHelper(*Info, InfoOrig);
173 }
174
175 {
176 const unique_ptr<const CameraSensorInfo> InfoOrig(new CameraSensorInfo(
177 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
178 CameraSensorInfo Info(*InfoOrig);
179
180 checkHelper(Info);
181 checkHelper(Info, *InfoOrig);
182 }
183}
184
186 ASSERT_NO_THROW({
187 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
188 mBlackLevelSeparate);
189 CameraSensorInfo Info(0, 0, 0, 0, {0});
190
191 Info = InfoOrig;
192 });
193
194 ASSERT_NO_THROW({
195 const unique_ptr<const CameraSensorInfo> InfoOrig(new CameraSensorInfo(
196 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
197 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(0, 0, 0, 0, {0}));
198
199 *Info = *InfoOrig;
200 });
201
202 ASSERT_NO_THROW({
203 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
204 mBlackLevelSeparate);
205 unique_ptr<CameraSensorInfo> Info(new CameraSensorInfo(0, 0, 0, 0, {0}));
206
207 *Info = InfoOrig;
208 });
209
210 ASSERT_NO_THROW({
211 const unique_ptr<const CameraSensorInfo> InfoOrig(new CameraSensorInfo(
212 mBlackLevel, mWhiteLevel, mMinIso, mMaxIso, mBlackLevelSeparate));
213 CameraSensorInfo Info(0, 0, 0, 0, {0});
214
215 Info = *InfoOrig;
216 });
217}
218
219TEST_P(CameraSensorInfoTestDumb, AssignmentGetters) {
220 ASSERT_NO_THROW({
221 const CameraSensorInfo InfoOrig(mBlackLevel, mWhiteLevel, mMinIso, mMaxIso,
222 mBlackLevelSeparate);
223 CameraSensorInfo Info(0, 0, 0, 0, {0});
224
225 Info = InfoOrig;
226
227 checkHelper(Info);
228 checkHelper(Info, InfoOrig);
229 });
230}
231
232// --------------------------------------------------------
233
234struct IsoExpectationsT final {
236 int Iso;
240
241 friend std::ostream& operator<<(std::ostream& os,
242 const IsoExpectationsT& obj) {
243 return os << "min ISO: " << obj.mMinIso << "; test iso: " << obj.Iso
244 << ", max ISO: " << obj.mMaxIso
245 << "; is iso within: " << obj.isIsoWithin
246 << "; is default: " << obj.isDefault;
247 }
248};
249
251 IsoExpectationsT{0, 0, 0, true, true},
252
253 IsoExpectationsT{100, 0, 200, false, false},
254 IsoExpectationsT{100, 99, 200, false, false},
255 IsoExpectationsT{100, 100, 200, true, false},
256 IsoExpectationsT{100, 160, 200, true, false},
257 IsoExpectationsT{100, 200, 200, true, false},
258 IsoExpectationsT{100, 201, 200, false, false},
259 IsoExpectationsT{100, std::numeric_limits<int>::max(), 200, false, false},
260
261 // if max iso == 0, every iso which is >= min iso is within.
262 IsoExpectationsT{100, 0, 0, false, false},
263 IsoExpectationsT{100, 99, 0, false, false},
264 IsoExpectationsT{100, 100, 0, true, false},
265 IsoExpectationsT{100, std::numeric_limits<int>::max(), 0, true, false},
266};
267
268class CameraSensorInfoTest : public ::testing::TestWithParam<IsoExpectationsT> {
269protected:
271 : data(IsoExpectationsT{-1, -1, -1, false, false}),
272 mBlackLevel(std::rand()), // NOLINT(cert-msc50-cpp): do not need
273 // crypto-level randomness
274 mWhiteLevel(std::rand()), // NOLINT(cert-msc50-cpp): do not need
275 // crypto-level randomness
277 std::rand(), // NOLINT(cert-msc50-cpp): do not need crypto-level
278 // randomness
279 std::rand(), // NOLINT(cert-msc50-cpp): do not need crypto-level
280 // randomness
281 std::rand(), // NOLINT(cert-msc50-cpp): do not need crypto-level
282 // randomness
283 std::rand() // NOLINT(cert-msc50-cpp): do not need crypto-level
284 // randomness
285 }) {}
286 virtual void SetUp() final { data = GetParam(); }
287
289
292 std::vector<int> mBlackLevelSeparate;
293};
294
296 testing::ValuesIn(CameraSensorIsoInfos));
297
299 CameraSensorInfo Info(mBlackLevel, mWhiteLevel, data.mMinIso, data.mMaxIso,
300 mBlackLevelSeparate);
301
302 ASSERT_NO_THROW({
303 if (data.isDefault)
304 ASSERT_TRUE(Info.isDefault());
305 else
306 ASSERT_FALSE(Info.isDefault());
307 });
308}
309
311 CameraSensorInfo Info(mBlackLevel, mWhiteLevel, data.mMinIso, data.mMaxIso,
312 mBlackLevelSeparate);
313
314 ASSERT_NO_THROW({
315 if (data.isIsoWithin)
316 ASSERT_TRUE(Info.isIsoWithin(data.Iso));
317 else
318 ASSERT_FALSE(Info.isIsoWithin(data.Iso));
319 });
320}
321
322} // namespace
323
324} // namespace rawspeed_test
325
326int main(int argc, char** argv) {
327 rawspeed_test::ISOList.push_back(0);
328
329 int n = {25};
330 std::generate(rawspeed_test::ISOList.begin() + 1,
331 rawspeed_test::ISOList.end(), [&n] { return n *= 4; });
332
333 std::srand(2016122923);
334
335 testing::InitGoogleMock(&argc, argv);
336 return RUN_ALL_TESTS();
337}
INSTANTIATE_TEST_SUITE_P(MD5Test, MD5Test, ::testing::ValuesIn(testCases))
TEST_P(MD5Test, CheckTestCaseSet)
Definition MD5Test.cpp:388
bool RAWSPEED_READONLY isIsoWithin(int iso) const
bool RAWSPEED_READONLY isDefault() const
std::vector< int > mBlackLevelSeparate
int main()
friend std::ostream & operator<<(std::ostream &os, const IsoExpectationsT &obj)