RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
PartitioningOutputIteratorTest.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2024 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
22#include <cstdint>
23#include <utility>
24#include <vector>
25#include <gmock/gmock.h>
26#include <gtest/gtest.h>
27
28namespace rawspeed::rawpeed_test {
29
30namespace {
31
32template <typename T, typename U> struct TypeSpec {
33 using WideType = T;
34 using PartType = U;
35};
36
37template <typename T>
38class PartitioningOutputIteratorTest : public testing::Test {};
39
41
42template <typename WideType, typename PartType>
43std::pair<WideType, std::vector<PartType>> getInput() {
44 static_assert(sizeof(WideType) % sizeof(PartType) == 0);
45 // NOLINTNEXTLINE(bugprone-sizeof-expression)
46 constexpr int NumParts = sizeof(WideType) / sizeof(PartType);
47 WideType wide = 0;
48 std::vector<PartType> parts;
49 for (int i = 0; i != NumParts; ++i) {
50 auto part = static_cast<PartType>(-(1 + i));
51 parts.emplace_back(part);
52 auto bits = static_cast<WideType>(part) << (bitwidth<PartType>() * i);
53 wide |= bits;
54 }
55 return {wide, parts};
56}
57
59 auto [wide, partsTrue] =
61
62 std::vector<typename TypeParam::PartType> output;
63 output.reserve(partsTrue.size());
64 {
65 auto it = PartitioningOutputIterator(std::back_inserter(output));
66 *it = wide;
67 }
68
69 ASSERT_THAT(output, testing::SizeIs(testing::Eq(partsTrue.size())));
70 ASSERT_THAT(output, testing::ContainerEq(partsTrue));
71}
72
74
76 ::testing::Types<TypeSpec<uint8_t, uint8_t>,
77
79
82
86
89} // namespace
90} // namespace rawspeed::rawpeed_test
INSTANTIATE_TYPED_TEST_SUITE_P(PartitionedTo, PartitioningOutputIteratorTest, PartitionedPairTypes)
::testing::Types< TypeSpec< uint8_t, uint8_t >, TypeSpec< uint16_t, uint8_t >, TypeSpec< uint16_t, uint16_t >, TypeSpec< uint32_t, uint8_t >, TypeSpec< uint32_t, uint16_t >, TypeSpec< uint32_t, uint32_t >, TypeSpec< uint64_t, uint8_t >, TypeSpec< uint64_t, uint16_t >, TypeSpec< uint64_t, uint32_t >, TypeSpec< uint64_t, uint64_t > > PartitionedPairTypes
throw T(buf.data())
constexpr unsigned RAWSPEED_READNONE bitwidth(T unused={})
Definition Bit.h:43
PartitioningOutputIterator(T) -> PartitioningOutputIterator< T >