• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Android Open Source Project
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 
15 #include "host-common/HostmemIdMapping.h"
16 
17 #include <gtest/gtest.h>
18 
19 using android::emulation::HostmemIdMapping;
20 
21 // Tests creation and destruction.
TEST(HostmemIdMapping,Basic)22 TEST(HostmemIdMapping, Basic) {
23     HostmemIdMapping m;
24 }
25 
26 // Tests basic operations on an entry: add, remove, get entry info
TEST(HostmemIdMapping,BasicEntry)27 TEST(HostmemIdMapping, BasicEntry) {
28     HostmemIdMapping m;
29     auto id = m.add(0, 1);
30     EXPECT_EQ(HostmemIdMapping::kInvalidHostmemId, id);
31     id = m.add(1, 0);
32     EXPECT_EQ(HostmemIdMapping::kInvalidHostmemId, id);
33     id = m.add(1, 2);
34     EXPECT_NE(HostmemIdMapping::kInvalidHostmemId, id);
35 
36     auto entry = m.get(id);
37     EXPECT_EQ(id, entry.id);
38     EXPECT_EQ(1, entry.hva);
39     EXPECT_EQ(2, entry.size);
40 
41     m.remove(id);
42 
43     entry = m.get(id);
44 
45     EXPECT_EQ(HostmemIdMapping::kInvalidHostmemId, entry.id);
46     EXPECT_EQ(0, entry.hva);
47     EXPECT_EQ(0, entry.size);
48 }
49 
50 // Tests the clear() method.
TEST(HostmemIdMapping,Clear)51 TEST(HostmemIdMapping, Clear) {
52     HostmemIdMapping m;
53     auto id1 = m.add(1, 2);
54     auto id2 = m.add(3, 4);
55 
56     m.clear();
57 
58     auto entry = m.get(id1);
59     EXPECT_EQ(HostmemIdMapping::kInvalidHostmemId, entry.id);
60     EXPECT_EQ(0, entry.hva);
61     EXPECT_EQ(0, entry.size);
62 
63     entry = m.get(id2);
64     EXPECT_EQ(HostmemIdMapping::kInvalidHostmemId, entry.id);
65     EXPECT_EQ(0, entry.hva);
66     EXPECT_EQ(0, entry.size);
67 }
68 
69