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

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%27270.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_size_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::HeapSizeEvent;
  29    :  using testing::Return;
  30    :  
  31    :  const HANDLE kLiveHeap = reinterpret_cast<HANDLE>(0x4197FC83);
  32    :  const HANDLE kTraceHeap = reinterpret_cast<HANDLE>(0xAB12CD34);
  33    :  const LPCVOID kLiveAlloc = reinterpret_cast<LPCVOID>(0x4820BC7A);
  34    :  const LPCVOID kTraceAlloc = reinterpret_cast<LPCVOID>(0xF1D97AE4);
  35    :  const DWORD kFlags = 1;
  36    :  const SIZE_T kSize = 100;
  37    :  
  38    :  class HeapSizeEventTest : public testing::Test {
  39    :   public:
  40  E :    HeapSizeEventTest()
  41    :        : heap_size_event_(kTraceHeap, kFlags, kTraceAlloc, kSize) {}
  42    :  
  43  E :    MOCK_METHOD3(FakeCall, SIZE_T(HANDLE, DWORD, LPCVOID));
  44    :  
  45  E :    void SetUp() override {
  46  E :      backdrop_.heap_map().AddMapping(kTraceHeap, kLiveHeap);
  47    :      backdrop_.alloc_map().AddMapping(const_cast<LPVOID>(kTraceAlloc),
  48  E :                                       const_cast<LPVOID>(kLiveAlloc));
  49    :  
  50    :      backdrop_.set_heap_size(
  51  E :          base::Bind(&HeapSizeEventTest::FakeCall, base::Unretained(this)));
  52  E :    }
  53    :  
  54    :   protected:
  55    :    HeapSizeEvent heap_size_event_;
  56    :    HeapBackdrop backdrop_;
  57    :  };
  58    :  
  59    :  }  // namespace
  60    :  
  61  E :  TEST_F(HeapSizeEventTest, TestSuccessCall) {
  62    :    EXPECT_CALL(*this, FakeCall(kLiveHeap, kFlags, kLiveAlloc))
  63  E :        .WillOnce(Return(kSize));
  64    :  
  65  E :    EXPECT_TRUE(heap_size_event_.Play(reinterpret_cast<void*>(&backdrop_)));
  66  E :  }
  67    :  
  68  E :  TEST_F(HeapSizeEventTest, TestFailCall) {
  69    :    EXPECT_CALL(*this, FakeCall(kLiveHeap, kFlags, kLiveAlloc))
  70  E :        .WillOnce(Return(kSize + 100));
  71    :  
  72  E :    EXPECT_FALSE(heap_size_event_.Play(reinterpret_cast<void*>(&backdrop_)));
  73  E :  }
  74    :  
  75  E :  TEST_F(HeapSizeEventTest, Equals) {
  76  E :    HeapSizeEvent e1(kTraceHeap, kFlags, kTraceAlloc, kSize);
  77  E :    HeapSizeEvent e2(kTraceHeap, kFlags, kTraceAlloc, kSize);
  78  E :    HeapSizeEvent e3(kTraceHeap, kFlags + 1, kTraceAlloc, kSize + 1);
  79  E :    EXPECT_TRUE(e1.Equals(&e1));
  80  E :    EXPECT_TRUE(e1.Equals(&e2));
  81  E :    EXPECT_FALSE(e1.Equals(&e3));
  82  E :    EXPECT_FALSE(e2.Equals(&e3));
  83  E :  }
  84    :  
  85  E :  TEST_F(HeapSizeEventTest, TestSerialization) {
  86  E :    testing::TestEventSerialization(heap_size_event_);
  87  E :  }
  88    :  
  89    :  }  // namespace events
  90    :  }  // namespace bard

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