1 | //===-- sanitizer_region_test.cpp -----------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | #include "sanitizer_common/sanitizer_range.h" |
9 | |
10 | #include <algorithm> |
11 | |
12 | #include "gtest/gtest.h" |
13 | #include "sanitizer_common/sanitizer_common.h" |
14 | |
15 | namespace __sanitizer { |
16 | |
17 | class SanitizerCommon |
18 | : public testing::TestWithParam<std::tuple< |
19 | std::vector<Range>, std::vector<Range>, std::vector<Range>>> {}; |
20 | |
21 | TEST_P(SanitizerCommon, Intersect) { |
22 | { |
23 | InternalMmapVector<Range> output; |
24 | Intersect(std::get<0>(GetParam()), std::get<1>(GetParam()), output); |
25 | EXPECT_EQ(std::get<2>(GetParam()), |
26 | std::vector<Range>(output.begin(), output.end())); |
27 | } |
28 | { |
29 | InternalMmapVector<Range> output; |
30 | Intersect(std::get<1>(GetParam()), std::get<0>(GetParam()), output); |
31 | EXPECT_EQ(std::get<2>(GetParam()), |
32 | std::vector<Range>(output.begin(), output.end())); |
33 | } |
34 | } |
35 | |
36 | static void PrintTo(const Range &r, std::ostream *os) { |
37 | *os << "[" << r.begin << ", " << r.end << ")" ; |
38 | } |
39 | |
40 | static const std::tuple<std::vector<Range>, std::vector<Range>, |
41 | std::vector<Range>> |
42 | kTests[] = { |
43 | {{}, {}, {}}, |
44 | {{{100, 1000}}, {{5000, 10000}}, {}}, |
45 | {{{100, 1000}, {200, 2000}}, {{5000, 10000}, {6000, 11000}}, {}}, |
46 | {{{100, 1000}}, {{100, 1000}}, {{100, 1000}}}, |
47 | {{{100, 1000}}, {{50, 150}}, {{100, 150}}}, |
48 | {{{100, 1000}}, {{150, 250}}, {{150, 250}}}, |
49 | {{{100, 1000}, {100, 1000}}, {{100, 1000}}, {{100, 1000}}}, |
50 | {{{100, 1000}}, {{500, 1500}}, {{500, 1000}}}, |
51 | {{{100, 200}}, {{200, 300}, {1, 1000}}, {{100, 200}}}, |
52 | {{{100, 200}, {200, 300}}, {{100, 300}}, {{100, 300}}}, |
53 | {{{100, 200}, {200, 300}, {300, 400}}, {{150, 350}}, {{150, 350}}}, |
54 | {{{100, 200}, {300, 400}, {500, 600}}, |
55 | {{0, 1000}}, |
56 | {{100, 200}, {300, 400}, {500, 600}}}, |
57 | }; |
58 | |
59 | INSTANTIATE_TEST_SUITE_P(SanitizerCommonEmpty, SanitizerCommon, |
60 | testing::ValuesIn(kTests)); |
61 | |
62 | } // namespace __sanitizer |
63 | |