Coverage for /Syzygy/pe/metadata.h

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%19190.C++source

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    :  // Declaration of a simple metadata class, which contains toolchain information
  16    :  // which will be embedded in the outputs produced by the toolchain. Every
  17    :  // output has one thing in common: it is has been produced from or with
  18    :  // respect to a given module, and it has been produced by a fixed version of
  19    :  // the toolchain.
  20    :  
  21    :  #ifndef SYZYGY_PE_METADATA_H_
  22    :  #define SYZYGY_PE_METADATA_H_
  23    :  
  24    :  #include "base/values.h"
  25    :  #include "base/time/time.h"
  26    :  #include "syzygy/block_graph/block_graph.h"
  27    :  #include "syzygy/core/serialization.h"
  28    :  #include "syzygy/pe/pe_file.h"
  29    :  #include "syzygy/version/syzygy_version.h"
  30    :  
  31    :  // Forward declaration.
  32    :  namespace core {
  33    :  class JSONFileWriter;
  34    :  }  // namespace core
  35    :  
  36    :  namespace pe {
  37    :  
  38    :  // Class encapsulating the metadata that is required for traceability and
  39    :  // consistency at every step in the toolchain.
  40    :  class Metadata {
  41    :   public:
  42    :  
  43    :    Metadata();
  44    :  
  45    :    // Initialize this metadata for a given module. Automatically infers
  46    :    // command-line, time, and toolchain version from the environment. Assumes
  47    :    // that the singleton base::CommandLine has already been initialized.
  48    :    bool Init(const PEFile::Signature& module_signature);
  49    :  
  50    :    // Confirms the metadata is consistent with the given module and current
  51    :    // toolchain version.
  52    :    bool IsConsistent(const PEFile::Signature& module_signature) const;
  53    :  
  54    :    // Functions for serialization to and from JSON.
  55    :    bool SaveToJSON(core::JSONFileWriter* json_file) const;
  56    :    bool LoadFromJSON(const base::DictionaryValue& metadata);
  57    :  
  58    :    // Functions for serialization to and from a block.
  59    :    bool SaveToBlock(block_graph::BlockGraph::Block* block) const;
  60    :    bool LoadFromBlock(const block_graph::BlockGraph::Block* block);
  61    :  
  62    :    // Functions for serialization to and from a PE file.
  63    :    bool LoadFromPE(const PEFile& pe_file);
  64    :  
  65    :    // Serialization functions.
  66    :    bool Save(core::OutArchive* out_archive) const;
  67    :    bool Load(core::InArchive* in_archive);
  68    :  
  69    :    // Comparison operators for serialization testing.
  70    :    // @{
  71    :    bool operator==(const Metadata& rhs) const;
  72  E :    bool operator!=(const Metadata& rhs) const { return !operator==(rhs); }
  73    :    // @}
  74    :  
  75    :    // Accessors.
  76    :    const std::string& command_line() const { return command_line_; }
  77    :    base::Time creation_time() const { return creation_time_; }
  78  E :    const version::SyzygyVersion& toolchain_version() const {
  79  E :      return toolchain_version_;
  80  E :    }
  81  E :    const PEFile::Signature& module_signature() const {
  82  E :      return module_signature_;
  83  E :    }
  84    :  
  85    :    // Mutators. These are mainly for explicit testing.
  86  E :    void set_command_line(const std::string& command_line) {
  87  E :      command_line_ = command_line;
  88  E :    }
  89  E :    void set_creation_time(const base::Time& creation_time) {
  90  E :      creation_time_ = creation_time;
  91  E :    }
  92  E :    void set_toolchain_version(const version::SyzygyVersion& toolchain_version) {
  93  E :      toolchain_version_ = toolchain_version;
  94  E :    }
  95  E :    void set_module_signature(const PEFile::Signature& module_signature) {
  96  E :      module_signature_ = module_signature;
  97  E :    }
  98    :  
  99    :   private:
 100    :    // The command-line that was used to produce the output.
 101    :    std::string command_line_;
 102    :    // The time the output was created.
 103    :    base::Time creation_time_;
 104    :    // The version of the toolchain that produced the output.
 105    :    version::SyzygyVersion toolchain_version_;
 106    :    // The original module from/for which the output was produced.
 107    :    PEFile::Signature module_signature_;
 108    :  
 109    :    DISALLOW_COPY_AND_ASSIGN(Metadata);
 110    :  };
 111    :  
 112    :  }  // namespace pe
 113    :  
 114    :  #endif  // SYZYGY_PE_METADATA_H_

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