Coverage for /Syzygy/bard/events/heap_destroy_event_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%36360.C++test

Line-by-line coverage:

   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/events/heap_destroy_event.h"
  16    :  
  17    :  #include "gmock/gmock.h"
  18    :  #include "gtest/gtest.h"
  19    :  #include "syzygy/bard/unittest_util.h"
  20    :  #include "syzygy/bard/backdrops/heap_backdrop.h"
  21    :  
  22    :  namespace bard {
  23    :  namespace events {
  24    :  
  25    :  namespace {
  26    :  
  27    :  using bard::backdrops::HeapBackdrop;
  28    :  using bard::events::HeapDestroyEvent;
  29    :  using testing::Return;
  30    :  
  31    :  const HANDLE kLiveHeap = reinterpret_cast<HANDLE>(0x4197FC83);
  32    :  const HANDLE kTraceHeap = reinterpret_cast<HANDLE>(0xAB12CD34);
  33    :  
  34    :  class HeapDestroyEventTest : public testing::Test {
  35    :   public:
  36  E :    MOCK_METHOD1(FakeCall, BOOL(HANDLE));
  37    :  
  38  E :    void SetUp() override {
  39  E :      backdrop_.heap_map().AddMapping(kTraceHeap, kLiveHeap);
  40    :  
  41    :      backdrop_.set_heap_destroy(
  42  E :          base::Bind(&HeapDestroyEventTest::FakeCall, base::Unretained(this)));
  43  E :    }
  44    :  
  45    :   protected:
  46    :    HeapBackdrop backdrop_;
  47    :  };
  48    :  
  49    :  }  // namespace
  50    :  
  51  E :  TEST_F(HeapDestroyEventTest, TestSuccessCall) {
  52  E :    HeapDestroyEvent heap_destroy_event(kTraceHeap, true);
  53    :  
  54  E :    EXPECT_CALL(*this, FakeCall(kLiveHeap)).WillOnce(Return(true));
  55    :  
  56  E :    EXPECT_TRUE(heap_destroy_event.Play(reinterpret_cast<void*>(&backdrop_)));
  57    :  
  58    :    testing::CheckTraceLiveMapNotContain(backdrop_.heap_map(),
  59    :                                         kTraceHeap,
  60  E :                                         kLiveHeap);
  61  E :  }
  62    :  
  63  E :  TEST_F(HeapDestroyEventTest, TestFailCall) {
  64  E :    HeapDestroyEvent heap_destroy_event(kTraceHeap, false);
  65    :  
  66  E :    EXPECT_CALL(*this, FakeCall(kLiveHeap)).WillOnce(Return(false));
  67    :  
  68  E :    EXPECT_TRUE(heap_destroy_event.Play(reinterpret_cast<void*>(&backdrop_)));
  69    :  
  70    :    testing::CheckTraceLiveMapContains(backdrop_.heap_map(),
  71    :                                       kTraceHeap,
  72  E :                                       kLiveHeap);
  73  E :  }
  74    :  
  75  E :  TEST_F(HeapDestroyEventTest, TestInconsistentReturn) {
  76  E :    HeapDestroyEvent heap_destroy_event(kTraceHeap, false);
  77    :  
  78  E :    EXPECT_CALL(*this, FakeCall(kLiveHeap)).WillOnce(Return(true));
  79    :  
  80  E :    EXPECT_FALSE(heap_destroy_event.Play(reinterpret_cast<void*>(&backdrop_)));
  81    :  
  82    :    testing::CheckTraceLiveMapContains(backdrop_.heap_map(),
  83    :                                       kTraceHeap,
  84  E :                                       kLiveHeap);
  85  E :  }
  86    :  
  87  E :  TEST_F(HeapDestroyEventTest, Equals) {
  88  E :    HeapDestroyEvent e1(kTraceHeap, false);
  89  E :    HeapDestroyEvent e2(kTraceHeap, false);
  90  E :    HeapDestroyEvent e3(kTraceHeap, true);
  91  E :    EXPECT_TRUE(e1.Equals(&e1));
  92  E :    EXPECT_TRUE(e1.Equals(&e2));
  93  E :    EXPECT_FALSE(e1.Equals(&e3));
  94  E :    EXPECT_FALSE(e2.Equals(&e3));
  95  E :  }
  96    :  
  97  E :  TEST_F(HeapDestroyEventTest, TestSerialization) {
  98  E :    HeapDestroyEvent heap_destroy_event(kTraceHeap, true);
  99  E :    testing::TestEventSerialization(heap_destroy_event);
 100  E :  }
 101    :  
 102    :  }  // namespace events
 103    :  }  // namespace bard

Coverage information generated Thu Jan 14 17:40:38 2016.