1 : // Copyright 2015 Google Inc. All Rights Reserved.
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 "syzygy/bard/trace_live_map.h"
16 :
17 : #include "gtest/gtest.h"
18 : #include "syzygy/bard/unittest_util.h"
19 :
20 : namespace bard {
21 :
22 E : TEST(TraceLiveMapTest, TestMapping) {
23 E : TraceLiveMap<void*> trace_live_map;
24 E : EXPECT_TRUE(trace_live_map.Empty());
25 :
26 E : void* trace = reinterpret_cast<void*>(0xAB11CD22);
27 E : void* extra_trace = reinterpret_cast<void*>(0x13213221);
28 E : void* live = reinterpret_cast<void*>(0xCC9437A2);
29 E : void* extra_live = reinterpret_cast<void*>(0xABBAABBA);
30 :
31 E : EXPECT_TRUE(trace_live_map.AddMapping(trace, live));
32 E : EXPECT_FALSE(trace_live_map.AddMapping(trace, extra_live));
33 E : EXPECT_FALSE(trace_live_map.AddMapping(extra_trace, live));
34 E : testing::CheckTraceLiveMapContains(trace_live_map, trace, live);
35 E : EXPECT_FALSE(trace_live_map.Empty());
36 :
37 E : EXPECT_TRUE(trace_live_map.RemoveMapping(trace, live));
38 E : testing::CheckTraceLiveMapNotContain(trace_live_map, trace, live);
39 :
40 E : EXPECT_FALSE(trace_live_map.RemoveMapping(trace, live));
41 :
42 E : EXPECT_TRUE(trace_live_map.AddMapping(trace, live));
43 E : testing::CheckTraceLiveMapContains(trace_live_map, trace, live);
44 E : trace_live_map.Clear();
45 E : testing::CheckTraceLiveMapNotContain(trace_live_map, trace, live);
46 E : }
47 :
48 : } // namespace bard
|