Coverage for /Syzygy/pe/pdb_info_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2012 Google Inc.
   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  E :    const FilePath test_dll(testing::GetExeRelativePath(kDllName));
  49  E :    const FilePath test_dll_pdb(testing::GetExeRelativePath(kDllPdbName));
  50    :  
  51  E :    PdbInfo pdb_info;
  52  E :    EXPECT_TRUE(pdb_info.Init(test_dll));
  53    :  
  54    :    pdb::PdbInfoHeader70 pdb_header;
  55  E :    ASSERT_TRUE(pdb::ReadPdbHeader(test_dll_pdb, &pdb_header));
  56    :  
  57  E :    EXPECT_TRUE(pdb_info.IsConsistent(pdb_header));
  58  E :  }
  59    :  
  60  E :  TEST_F(PdbInfoTest, BuildFromCvInfoPdb70) {
  61  E :    const char kPath[] = "C:\\foo\\foo.pdb";
  62  E :    const GUID kSignature = { 0xdeadbeef, 0xf00d, 0xcafe,
  63  E :        { 'c', 'u', 't', 'e', 'c', 'a', 't', 's' } };
  64    :  
  65  E :    std::vector<unsigned char> data;
  66  E :    CvInfoPdb70* cv_info_pdb = CreateCvInfoPdb70(kPath, &data);
  67  E :    cv_info_pdb->cv_signature = 0xdeadbeef;
  68  E :    cv_info_pdb->pdb_age = 2;
  69  E :    cv_info_pdb->signature = kSignature;
  70    :  
  71  E :    PdbInfo pdb_info;
  72  E :    EXPECT_TRUE(pdb_info.Init(*cv_info_pdb));
  73    :  
  74  E :    pdb::PdbInfoHeader70 pdb_header = {};
  75  E :    pdb_header.pdb_age = cv_info_pdb->pdb_age;
  76  E :    pdb_header.signature = cv_info_pdb->signature;
  77    :  
  78  E :    EXPECT_TRUE(pdb_info.IsConsistent(pdb_header));
  79    :  
  80    :    // An older PBD is not consistent with a newer image.
  81  E :    pdb_header.pdb_age = cv_info_pdb->pdb_age - 1;
  82  E :    EXPECT_FALSE(pdb_info.IsConsistent(pdb_header));
  83    :  
  84    :    // If the PDB age is newer than the image, we are consistent.
  85  E :    pdb_header.pdb_age = cv_info_pdb->pdb_age + 1;
  86  E :    EXPECT_TRUE(pdb_info.IsConsistent(pdb_header));
  87  E :  }
  88    :  
  89    :  }  // namespace pe

Coverage information generated Thu Sep 06 11:30:46 2012.