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

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%38380.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 :    void SetUp() {
  42    :      header_block_ = block_graph_.AddBlock(BlockGraph::DATA_BLOCK,
  43    :                                            10,
  44  E :                                            "Header");
  45  E :      ASSERT_TRUE(header_block_ != NULL);
  46  E :    }
  47    :  
  48  E :    void AddMetadataBlock() {
  49    :      BlockGraph::Section* section = block_graph_.FindOrAddSection(
  50  E :          common::kSyzygyMetadataSectionName, kReadOnlyDataCharacteristics);
  51  E :      ASSERT_TRUE(section != NULL);
  52    :  
  53    :      BlockGraph::Block* block = block_graph_.AddBlock(
  54  E :          BlockGraph::DATA_BLOCK, 10, "Metadata");
  55  E :      ASSERT_TRUE(block != NULL);
  56  E :      block->set_section(section->id());
  57    :  
  58  E :      metadata_block_ = block;
  59  E :    }
  60    :  
  61    :    base::FilePath module_path_;
  62    :    testing::DummyTransformPolicy policy_;
  63    :    BlockGraph block_graph_;
  64    :    BlockGraph::Block* header_block_;
  65    :    BlockGraph::Block* metadata_block_;
  66    :  };
  67    :  
  68    :  }  // namespace
  69    :  
  70  E :  TEST_F(AddMetadataTransformTest, SucceedsWhenNoMetadata) {
  71  E :    AddMetadataTransform transform(module_path_);
  72    :    EXPECT_TRUE(ApplyBlockGraphTransform(
  73  E :        &transform, &policy_, &block_graph_, header_block_));
  74  E :    EXPECT_TRUE(transform.metadata_block() != NULL);
  75    :  
  76    :    // Expect the metadata to decode.
  77  E :    Metadata metadata;
  78  E :    EXPECT_TRUE(metadata.LoadFromBlock(transform.metadata_block()));
  79  E :    EXPECT_EQ(module_path_.value(), metadata.module_signature().path);
  80  E :  }
  81    :  
  82  E :  TEST_F(AddMetadataTransformTest, ReplaceSucceeds) {
  83  E :    AddMetadataTransform transform(module_path_);
  84  E :    AddMetadataBlock();
  85    :    EXPECT_TRUE(ApplyBlockGraphTransform(
  86  E :        &transform, &policy_, &block_graph_, header_block_));
  87  E :    EXPECT_EQ(metadata_block_, transform.metadata_block());
  88    :  
  89    :    // Expect the metadata to decode.
  90  E :    Metadata metadata;
  91  E :    EXPECT_TRUE(metadata.LoadFromBlock(transform.metadata_block()));
  92  E :    EXPECT_EQ(module_path_.value(), metadata.module_signature().path);
  93  E :  }
  94    :  
  95  E :  TEST_F(AddMetadataTransformTest, FailsIfMultipleMetadataBlocks) {
  96  E :    AddMetadataTransform transform(module_path_);
  97  E :    AddMetadataBlock();
  98  E :    AddMetadataBlock();
  99    :    EXPECT_FALSE(ApplyBlockGraphTransform(
 100  E :        &transform, &policy_, &block_graph_, header_block_));
 101  E :    EXPECT_EQ(NULL, transform.metadata_block());
 102  E :  }
 103    :  
 104    :  }  // namespace transforms
 105    :  }  // namespace pe

Coverage information generated Wed Dec 11 11:34:16 2013.