1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #include "gtest/gtest.h"
18 
19 #include <utility>
20 
21 #include "berberis/base/exec_region.h"
22 #include "berberis/base/exec_region_anonymous.h"
23 
24 namespace berberis {
25 
26 namespace {
27 
TEST(ExecRegion,Move)28 TEST(ExecRegion, Move) {
29   ExecRegion exec = ExecRegionAnonymousFactory::Create(1);
30   const uint8_t* begin = exec.begin();
31   const uint8_t* end = exec.end();
32 
33   ExecRegion other_exec = std::move(exec);
34 
35   EXPECT_EQ(other_exec.begin(), begin);
36   EXPECT_EQ(other_exec.end(), end);
37 
38   EXPECT_EQ(exec.begin(), nullptr);
39   EXPECT_EQ(exec.end(), nullptr);
40 
41   other_exec.Free();
42 }
43 
TEST(ExecRegion,SelfMove)44 TEST(ExecRegion, SelfMove) {
45   ExecRegion exec = ExecRegionAnonymousFactory::Create(1);
46   const uint8_t* begin = exec.begin();
47   const uint8_t* end = exec.end();
48 
49 #pragma clang diagnostic push
50 #pragma clang diagnostic ignored "-Wself-move"
51   exec = std::move(exec);
52 #pragma clang diagnostic pop
53 
54   EXPECT_EQ(exec.begin(), begin);
55   EXPECT_EQ(exec.end(), end);
56 
57   exec.Free();
58 }
59 
60 }  // namespace
61 
62 }  // namespace berberis
63