Coverage for /Syzygy/pe/transforms/add_pdb_info_transform_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2012 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/pe/transforms/add_pdb_info_transform.h"
  16    :  
  17    :  #include "gtest/gtest.h"
  18    :  #include "syzygy/block_graph/typed_block.h"
  19    :  #include "syzygy/block_graph/unittest_util.h"
  20    :  #include "syzygy/core/unittest_util.h"
  21    :  #include "syzygy/pe/decomposer.h"
  22    :  #include "syzygy/pe/unittest_util.h"
  23    :  
  24    :  namespace pe {
  25    :  namespace transforms {
  26    :  
  27    :  using block_graph::TypedBlock;
  28    :  
  29    :  namespace {
  30    :  
  31  E :  const base::FilePath kPdbPath(L"dummy.pdb");
  32    :  const uint32 kPdbAge = 0;
  33    :  const GUID kPdbGuid = { 0x11111111, 0x2222, 0x3333,
  34    :                          { 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB } };
  35    :  
  36    :  class AddPdbInfoTransformTest : public testing::PELibUnitTest {
  37    :   public:
  38    :    AddPdbInfoTransformTest()
  39    :        : image_layout_(&block_graph_),
  40  E :          dos_header_block_(NULL) {
  41  E :      block_graph_.set_image_format(BlockGraph::PE_IMAGE);
  42  E :    }
  43    :  
  44    :    testing::DummyTransformPolicy policy_;
  45    :    ImageLayout image_layout_;
  46    :    BlockGraph block_graph_;
  47    :    BlockGraph::Block* dos_header_block_;
  48    :  };
  49    :  
  50    :  }  // namespace
  51    :  
  52  E :  TEST_F(AddPdbInfoTransformTest, UpdateExisting) {
  53  E :    PEFile pe_file;
  54  E :    ASSERT_TRUE(pe_file.Init(testing::GetExeRelativePath(testing::kTestDllName)));
  55    :  
  56  E :    Decomposer decomposer(pe_file);
  57  E :    ASSERT_TRUE(decomposer.Decompose(&image_layout_));
  58    :  
  59    :    dos_header_block_ = image_layout_.blocks.GetBlockByAddress(
  60  E :        core::RelativeAddress(0));
  61  E :    ASSERT_TRUE(dos_header_block_ != NULL);
  62    :  
  63  E :    AddPdbInfoTransform transform(kPdbPath, kPdbAge, kPdbGuid);
  64    :    EXPECT_TRUE(block_graph::ApplyBlockGraphTransform(
  65  E :        &transform, &policy_, &block_graph_, dos_header_block_));
  66    :  
  67    :    // TODO(chrisha): Create the image and the PDB in a temp directory and
  68    :    //     see if pe::FindPdbForModule can find it. If so, then so will the
  69    :    //     debug machinery.
  70  E :  }
  71    :  
  72  E :  TEST_F(AddPdbInfoTransformTest, CreateNew) {
  73    :    // Create some empty dummy headers and hook them up.
  74    :    dos_header_block_ = block_graph_.AddBlock(
  75  E :        BlockGraph::DATA_BLOCK, sizeof(IMAGE_DOS_HEADER), "Dos Header");
  76  E :    ASSERT_TRUE(dos_header_block_ != NULL);
  77  E :    dos_header_block_->AllocateData(sizeof(IMAGE_DOS_HEADER));
  78    :  
  79    :    BlockGraph::Block* nt_headers_block = block_graph_.AddBlock(
  80  E :        BlockGraph::DATA_BLOCK, sizeof(IMAGE_NT_HEADERS), "Nt Headers");
  81  E :    ASSERT_TRUE(nt_headers_block != NULL);
  82  E :    nt_headers_block->AllocateData(sizeof(IMAGE_NT_HEADERS));
  83    :  
  84    :    dos_header_block_->SetReference(
  85    :        offsetof(IMAGE_DOS_HEADER, e_lfanew),
  86    :        BlockGraph::Reference(BlockGraph::RELATIVE_REF,
  87    :                              sizeof(core::RelativeAddress),
  88    :                              nt_headers_block,
  89  E :                              0, 0));
  90    :  
  91    :  
  92  E :    AddPdbInfoTransform transform(kPdbPath, kPdbAge, kPdbGuid);
  93    :    EXPECT_TRUE(block_graph::ApplyBlockGraphTransform(
  94  E :        &transform, &policy_, &block_graph_, dos_header_block_));
  95  E :  }
  96    :  
  97    :  }  // namespace transforms
  98    :  }  // namespace pe

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