1 //===-- sanitizer_region_test.cpp -----------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
8 #include "sanitizer_common/sanitizer_range.h"
12 #include "gtest/gtest.h"
13 #include "sanitizer_common/sanitizer_common.h"
15 namespace __sanitizer
{
18 : public testing::TestWithParam
<std::tuple
<
19 std::vector
<Range
>, std::vector
<Range
>, std::vector
<Range
>>> {};
21 TEST_P(SanitizerCommon
, Intersect
) {
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()));
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()));
36 static void PrintTo(const Range
&r
, std::ostream
*os
) {
37 *os
<< "[" << r
.begin
<< ", " << r
.end
<< ")";
40 static const std::tuple
<std::vector
<Range
>, std::vector
<Range
>,
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}},
56 {{100, 200}, {300, 400}, {500, 600}}},
59 INSTANTIATE_TEST_SUITE_P(SanitizerCommonEmpty
, SanitizerCommon
,
60 testing::ValuesIn(kTests
));
62 } // namespace __sanitizer