2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "gtest/gtest.h"
18 #include "mir/ShapeRange.h"
27 int32_t actual_length;
30 template <typename... Args>
31 explicit ParamType(int32_t actual_len, Args &&... args)
32 : actual_length(actual_len), shape({static_cast<int32_t>(args)...})
37 class ShapeIteratorTest : public ::testing::TestWithParam<ParamType>
41 TEST_P(ShapeIteratorTest, ElementCount)
43 Shape sh(GetParam().shape);
53 ASSERT_EQ(cnt, GetParam().actual_length);
56 std::vector<ParamType> test_data{ParamType{6, 1, 2, 3}, ParamType{16, 2, 2, 4},
57 ParamType{1, 1, 1, 1, 1, 1}, ParamType{5, 5, 1, 1, 1, 1, 1}};
59 INSTANTIATE_TEST_CASE_P(SimpleInput, ShapeIteratorTest, ::testing::ValuesIn(test_data));
61 TEST(ShapeRange, Contains)
65 Shape shape{static_cast<int32_t>(h), static_cast<int32_t>(w)};
66 ShapeRange range(shape);
67 Index index{0, 0, 0, 0};
68 for (int32_t row = -2; row < h + 1; ++row)
69 for (int32_t col = -2; col < w + 1; ++col)
72 if (row < 0 || row >= h || col < 0 || col >= w)
73 ASSERT_FALSE(range.contains(idx));
75 ASSERT_TRUE(range.contains(idx));