Coverage for /Syzygy/pe/pdb_info_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%37370.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    :  #include "syzygy/pe/pdb_info.h"
  15    :  
  16    :  #include "gtest/gtest.h"
  17    :  #include "syzygy/core/unittest_util.h"
  18    :  #include "syzygy/pdb/pdb_util.h"
  19    :  #include "syzygy/pe/unittest_util.h"
  20    :  
  21    :  namespace pe {
  22    :  
  23    :  namespace {
  24    :  
  25    :  class PdbInfoTest: public testing::PELibUnitTest {
  26    :    // Insert your customizations here.
  27    :  };
  28    :  
  29    :  // Creates a buffer that can be interpreted as a CvInfoPdb70 struct.
  30    :  CvInfoPdb70* CreateCvInfoPdb70(const char* path,
  31  E :                                 std::vector<unsigned char>* data) {
  32  E :    size_t cv_len = sizeof(CvInfoPdb70);
  33  E :    size_t path_len = ::strlen(path);
  34  E :    size_t data_len = cv_len + path_len;
  35    :  
  36  E :    data->clear();
  37  E :    data->resize(data_len, 0);
  38    :  
  39  E :    CvInfoPdb70* cv_info_pdb = reinterpret_cast<CvInfoPdb70*>(&data->at(0));
  40  E :    ::strcpy(cv_info_pdb->pdb_file_name, path);
  41    :  
  42  E :    return cv_info_pdb;
  43  E :  }
  44    :  
  45    :  }  // namespace
  46    :  
  47  E :  TEST_F(PdbInfoTest, TestDllAndPdbAreConsistent) {
  48    :    const base::FilePath test_dll(
  49  E :        testing::GetExeRelativePath(testing::kTestDllName));
  50    :    const base::FilePath test_dll_pdb(testing::GetExeRelativePath(
  51  E :        testing::kTestDllPdbName));
  52    :  
  53  E :    PdbInfo pdb_info;
  54  E :    EXPECT_TRUE(pdb_info.Init(test_dll));
  55    :  
  56    :    pdb::PdbInfoHeader70 pdb_header;
  57  E :    ASSERT_TRUE(pdb::ReadPdbHeader(test_dll_pdb, &pdb_header));
  58    :  
  59  E :    EXPECT_TRUE(pdb_info.IsConsistent(pdb_header));
  60  E :  }
  61    :  
  62  E :  TEST_F(PdbInfoTest, BuildFromCvInfoPdb70) {
  63  E :    const char kPath[] = "C:\\foo\\foo.pdb";
  64    :    const GUID kSignature = { 0xdeadbeef, 0xf00d, 0xcafe,
  65  E :        { 'c', 'u', 't', 'e', 'c', 'a', 't', 's' } };
  66    :  
  67  E :    std::vector<unsigned char> data;
  68  E :    CvInfoPdb70* cv_info_pdb = CreateCvInfoPdb70(kPath, &data);
  69  E :    cv_info_pdb->cv_signature = 0xdeadbeef;
  70  E :    cv_info_pdb->pdb_age = 2;
  71  E :    cv_info_pdb->signature = kSignature;
  72    :  
  73  E :    PdbInfo pdb_info;
  74  E :    EXPECT_TRUE(pdb_info.Init(*cv_info_pdb));
  75    :  
  76  E :    pdb::PdbInfoHeader70 pdb_header = {};
  77  E :    pdb_header.pdb_age = cv_info_pdb->pdb_age;
  78  E :    pdb_header.signature = cv_info_pdb->signature;
  79    :  
  80  E :    EXPECT_TRUE(pdb_info.IsConsistent(pdb_header));
  81    :  
  82    :    // An older PBD is not consistent with a newer image.
  83  E :    pdb_header.pdb_age = cv_info_pdb->pdb_age - 1;
  84  E :    EXPECT_FALSE(pdb_info.IsConsistent(pdb_header));
  85    :  
  86    :    // If the PDB age is newer than the image, we are consistent.
  87  E :    pdb_header.pdb_age = cv_info_pdb->pdb_age + 1;
  88  E :    EXPECT_TRUE(pdb_info.IsConsistent(pdb_header));
  89  E :  }
  90    :  
  91    :  }  // namespace pe

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