1 // Copyright 2016 The Android Open Source Project
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
17 #include "anbox/common/type_traits.h"
19 #include <gtest/gtest.h>
22 // Miscellenaous helper declarations for unit-tests using the GoogleTest
27 // RangesMatch is a useful template used to compare the content of two
28 // ranges at runtime. Usage is simply:
30 // EXPECT_TRUE(RangesMatch(range1, range2);
32 // Where |range1| and |range2| must have the same item type, and size.
33 template <typename Range1,
35 typename = common::enable_if_c<common::is_range<Range1>::value &&
36 common::is_range<Range2>::value>>
37 inline ::testing::AssertionResult RangesMatch(const Range1& expected,
38 const Range2& actual) {
39 const auto expectedSize =
40 std::distance(std::begin(expected), std::end(expected));
41 const auto actualSize = std::distance(std::begin(actual), std::end(actual));
42 if (actualSize != expectedSize) {
43 return ::testing::AssertionFailure()
44 << "actual range size " << actualSize << " != expected size "
48 auto itExp = std::begin(expected);
49 for (const auto& act : actual) {
51 const auto index = std::distance(std::begin(expected), itExp);
52 return ::testing::AssertionFailure()
53 << "range[" << index << "] (" << act << ") != expected["
54 << index << "] (" << *itExp << ")";
59 return ::testing::AssertionSuccess();
61 } // namespace testing