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

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%40400.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_metadata_transform.h"
  16    :  
  17    :  #include "gtest/gtest.h"
  18    :  #include "syzygy/block_graph/unittest_util.h"
  19    :  #include "syzygy/common/defs.h"
  20    :  #include "syzygy/core/unittest_util.h"
  21    :  #include "syzygy/pe/metadata.h"
  22    :  #include "syzygy/pe/pe_utils.h"
  23    :  #include "syzygy/pe/unittest_util.h"
  24    :  
  25    :  namespace pe {
  26    :  namespace transforms {
  27    :  
  28    :  using block_graph::BlockGraph;
  29    :  using block_graph::ApplyBlockGraphTransform;
  30    :  
  31    :  namespace {
  32    :  
  33    :  class AddMetadataTransformTest : public testing::PELibUnitTest {
  34    :   public:
  35    :    AddMetadataTransformTest()
  36    :        : module_path_(testing::GetExeRelativePath(testing::kTestDllName)),
  37    :          header_block_(NULL),
  38  E :          metadata_block_(NULL) {
  39  E :    }
  40    :  
  41  E :    virtual void SetUp() override {
  42  E :      testing::PELibUnitTest::SetUp();
  43    :  
  44  E :      block_graph_.set_image_format(BlockGraph::PE_IMAGE);
  45    :      header_block_ = block_graph_.AddBlock(BlockGraph::DATA_BLOCK,
  46    :                                            10,
  47  E :                                            "Header");
  48  E :      ASSERT_TRUE(header_block_ != NULL);
  49  E :    }
  50    :  
  51  E :    void AddMetadataBlock() {
  52    :      BlockGraph::Section* section = block_graph_.FindOrAddSection(
  53  E :          common::kSyzygyMetadataSectionName, kReadOnlyDataCharacteristics);
  54  E :      ASSERT_TRUE(section != NULL);
  55    :  
  56    :      BlockGraph::Block* block = block_graph_.AddBlock(
  57  E :          BlockGraph::DATA_BLOCK, 10, "Metadata");
  58  E :      ASSERT_TRUE(block != NULL);
  59  E :      block->set_section(section->id());
  60    :  
  61  E :      metadata_block_ = block;
  62  E :    }
  63    :  
  64    :    base::FilePath module_path_;
  65    :    testing::DummyTransformPolicy policy_;
  66    :    BlockGraph block_graph_;
  67    :    BlockGraph::Block* header_block_;
  68    :    BlockGraph::Block* metadata_block_;
  69    :  };
  70    :  
  71    :  }  // namespace
  72    :  
  73  E :  TEST_F(AddMetadataTransformTest, SucceedsWhenNoMetadata) {
  74  E :    AddMetadataTransform transform(module_path_);
  75    :    EXPECT_TRUE(ApplyBlockGraphTransform(
  76  E :        &transform, &policy_, &block_graph_, header_block_));
  77  E :    EXPECT_TRUE(transform.metadata_block() != NULL);
  78    :  
  79    :    // Expect the metadata to decode.
  80  E :    Metadata metadata;
  81  E :    EXPECT_TRUE(metadata.LoadFromBlock(transform.metadata_block()));
  82  E :    EXPECT_EQ(module_path_.value(), metadata.module_signature().path);
  83  E :  }
  84    :  
  85  E :  TEST_F(AddMetadataTransformTest, ReplaceSucceeds) {
  86  E :    AddMetadataTransform transform(module_path_);
  87  E :    AddMetadataBlock();
  88    :    EXPECT_TRUE(ApplyBlockGraphTransform(
  89  E :        &transform, &policy_, &block_graph_, header_block_));
  90  E :    EXPECT_EQ(metadata_block_, transform.metadata_block());
  91    :  
  92    :    // Expect the metadata to decode.
  93  E :    Metadata metadata;
  94  E :    EXPECT_TRUE(metadata.LoadFromBlock(transform.metadata_block()));
  95  E :    EXPECT_EQ(module_path_.value(), metadata.module_signature().path);
  96  E :  }
  97    :  
  98  E :  TEST_F(AddMetadataTransformTest, FailsIfMultipleMetadataBlocks) {
  99  E :    AddMetadataTransform transform(module_path_);
 100  E :    AddMetadataBlock();
 101  E :    AddMetadataBlock();
 102    :    EXPECT_FALSE(ApplyBlockGraphTransform(
 103  E :        &transform, &policy_, &block_graph_, header_block_));
 104  E :    EXPECT_EQ(NULL, transform.metadata_block());
 105  E :  }
 106    :  
 107    :  }  // namespace transforms
 108    :  }  // namespace pe

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