Coverage for /Syzygy/zap_timestamp/zap_timestamp_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%90900.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/zap_timestamp/zap_timestamp.h"
  16    :  
  17    :  #include "base/file_util.h"
  18    :  #include "base/scoped_temp_dir.h"
  19    :  #include "gtest/gtest.h"
  20    :  #include "syzygy/core/unittest_util.h"
  21    :  
  22    :  namespace zap_timestamp {
  23    :  
  24    :  namespace {
  25    :  
  26    :  // We don't bother with having specific data for the 'Coverage' case.
  27    :  #define TEST_DATA_PREFIX_0 L"syzygy\\zap_timestamp\\test_data\\"
  28    :  #ifdef NDEBUG
  29    :  #define TEST_DATA_PREFIX_1 L"Release\\"
  30    :  #else
  31    :  #define TEST_DATA_PREFIX_1 L"Debug\\"
  32    :  #endif
  33    :  #define TEST_DATA_PREFIX TEST_DATA_PREFIX_0 TEST_DATA_PREFIX_1
  34    :  
  35    :  struct RawPePdbPathPair {
  36    :    const wchar_t* pe_path;
  37    :    const wchar_t* pdb_path;
  38    :  };
  39    :  RawPePdbPathPair kRawTestPaths[] = {
  40    :      { TEST_DATA_PREFIX L"copy0\\test_dll.dll",
  41    :        TEST_DATA_PREFIX L"copy0\\test_dll.pdb" },
  42    :      { TEST_DATA_PREFIX L"copy1\\test_dll.dll",
  43    :        TEST_DATA_PREFIX L"copy1\\test_dll.pdb" },
  44    :      { TEST_DATA_PREFIX L"copy2\\test_dll.dll",
  45    :        TEST_DATA_PREFIX L"copy2\\test_dll.pdb" } };
  46    :  
  47    :  struct PePdbPathPair {
  48    :    FilePath pe_path;
  49    :    FilePath pdb_path;
  50    :  };
  51    :  
  52    :  class ZapTimestampTest : public testing::Test {
  53    :   public:
  54  E :    virtual void SetUp() OVERRIDE {
  55  E :      testing::Test::SetUp();
  56    :  
  57  E :      temp_dir_.CreateUniqueTempDir();
  58    :  
  59    :      // Get the full test data paths.
  60  E :      for (size_t i = 0; i < arraysize(kRawTestPaths); ++i) {
  61  E :        PePdbPathPair pair;
  62  E :        pair.pe_path = testing::GetSrcRelativePath(kRawTestPaths[i].pe_path);
  63  E :        pair.pdb_path = testing::GetSrcRelativePath(kRawTestPaths[i].pdb_path);
  64  E :        test_paths_.push_back(pair);
  65  E :      }
  66    :  
  67  E :      temp_pe_path_ = temp_dir_.path().Append(L"test_dll.dll");
  68  E :      temp_pdb_path_ = temp_dir_.path().Append(L"test_dll.pdb");
  69  E :    }
  70    :  
  71  E :    void CopyTestData(const FilePath& pe_path, const FilePath& pdb_path) {
  72  E :      ASSERT_TRUE(file_util::CopyFile(pe_path, temp_pe_path_));
  73  E :      ASSERT_TRUE(file_util::CopyFile(pdb_path, temp_pdb_path_));
  74  E :    }
  75    :  
  76  E :    void CopyTestData(size_t index) {
  77  E :      ASSERT_GT(test_paths_.size(), index);
  78  E :      ASSERT_NO_FATAL_FAILURE(CopyTestData(
  79    :          test_paths_[index].pe_path, test_paths_[index].pdb_path));
  80  E :    }
  81    :  
  82    :    ScopedTempDir temp_dir_;
  83    :    std::vector<PePdbPathPair> test_paths_;
  84    :  
  85    :    FilePath temp_pe_path_;
  86    :    FilePath temp_pdb_path_;
  87    :  };
  88    :  
  89    :  }  // namespace
  90    :  
  91  E :  TEST_F(ZapTimestampTest, InitFailsForNonExistentPath) {
  92  E :    ZapTimestamp zap;
  93  E :    EXPECT_FALSE(zap.Init(FilePath(L"nonexistent_pe_file.dll")));
  94  E :  }
  95    :  
  96  E :  TEST_F(ZapTimestampTest, InitFailsForMismatchedPeAndPdb) {
  97    :    ASSERT_NO_FATAL_FAILURE(CopyTestData(
  98  E :        test_paths_[0].pe_path, test_paths_[1].pdb_path));
  99  E :    ZapTimestamp zap;
 100  E :    EXPECT_FALSE(zap.Init(temp_pe_path_));
 101  E :  }
 102    :  
 103  E :  TEST_F(ZapTimestampTest, InitFailsWithMissingPdb) {
 104  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(0));
 105  E :    ASSERT_TRUE(file_util::Delete(temp_pdb_path_, false));
 106  E :    ZapTimestamp zap;
 107  E :    EXPECT_FALSE(zap.Init(temp_pe_path_));
 108  E :  }
 109    :  
 110  E :  TEST_F(ZapTimestampTest, InitAutoFindPdb) {
 111  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(0));
 112  E :    ZapTimestamp zap;
 113  E :    EXPECT_TRUE(zap.Init(temp_pe_path_));
 114  E :    EXPECT_EQ(temp_pdb_path_, zap.pdb_path());
 115  E :  }
 116    :  
 117  E :  TEST_F(ZapTimestampTest, InitExplicitPdb) {
 118  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(0));
 119  E :    ZapTimestamp zap;
 120  E :    EXPECT_TRUE(zap.Init(temp_pe_path_, temp_pdb_path_));
 121  E :  }
 122    :  
 123  E :  TEST_F(ZapTimestampTest, IsIdempotent) {
 124    :    // Zap the first set of the PE and PDB files.
 125  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(0));
 126  E :    ZapTimestamp zap0;
 127  E :    EXPECT_TRUE(zap0.Init(temp_pe_path_));
 128  E :    EXPECT_EQ(temp_pdb_path_, zap0.pdb_path());
 129  E :    EXPECT_TRUE(zap0.Zap(true, true));
 130    :  
 131    :    // Make a copy of the singly zapped files.
 132  E :    FilePath pe_path_0 = temp_dir_.path().Append(L"test_dll_0.dll");
 133  E :    FilePath pdb_path_0 = temp_dir_.path().Append(L"test_dll_0.pdb");
 134  E :    ASSERT_TRUE(file_util::CopyFile(temp_pe_path_, pe_path_0));
 135  E :    ASSERT_TRUE(file_util::CopyFile(temp_pdb_path_, pdb_path_0));
 136    :  
 137    :    // Zap them again.
 138  E :    ZapTimestamp zap1;
 139  E :    EXPECT_TRUE(zap1.Init(temp_pe_path_));
 140  E :    EXPECT_EQ(temp_pdb_path_, zap1.pdb_path());
 141  E :    EXPECT_TRUE(zap1.Zap(true, true));
 142    :  
 143    :    // The singly and doubly zapped files should be the same.
 144  E :    EXPECT_TRUE(file_util::ContentsEqual(temp_pe_path_, pe_path_0));
 145  E :    EXPECT_TRUE(file_util::ContentsEqual(temp_pdb_path_, pdb_path_0));
 146  E :  }
 147    :  
 148  E :  TEST_F(ZapTimestampTest, Succeeds) {
 149    :    // Zap the first set of the PE and PDB files.
 150  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(0));
 151  E :    ZapTimestamp zap0;
 152  E :    EXPECT_TRUE(zap0.Init(temp_pe_path_));
 153  E :    EXPECT_EQ(temp_pdb_path_, zap0.pdb_path());
 154  E :    EXPECT_TRUE(zap0.Zap(true, true));
 155    :  
 156    :    // Rename and move the PE and PDB file.
 157  E :    FilePath pe_path_0 = temp_dir_.path().Append(L"test_dll_0.dll");
 158  E :    FilePath pdb_path_0 = temp_dir_.path().Append(L"test_dll_0.pdb");
 159  E :    ASSERT_TRUE(file_util::Move(temp_pe_path_, pe_path_0));
 160  E :    ASSERT_TRUE(file_util::Move(temp_pdb_path_, pdb_path_0));
 161    :  
 162    :    // Zap the second set of the PE and PDB files.
 163  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(1));
 164  E :    ZapTimestamp zap1;
 165  E :    EXPECT_TRUE(zap1.Init(temp_pe_path_, temp_pdb_path_));
 166  E :    EXPECT_TRUE(zap1.Zap(true, true));
 167    :  
 168    :    // Rename and move the PE and PDB file.
 169  E :    FilePath pe_path_1 = temp_dir_.path().Append(L"test_dll_1.dll");
 170  E :    FilePath pdb_path_1 = temp_dir_.path().Append(L"test_dll_1.pdb");
 171  E :    ASSERT_TRUE(file_util::Move(temp_pe_path_, pe_path_1));
 172  E :    ASSERT_TRUE(file_util::Move(temp_pdb_path_, pdb_path_1));
 173    :  
 174    :    // Zap the third set of the PE and PDB files.
 175  E :    ASSERT_NO_FATAL_FAILURE(CopyTestData(2));
 176  E :    ZapTimestamp zap2;
 177  E :    EXPECT_TRUE(zap2.Init(temp_pe_path_, temp_pdb_path_));
 178  E :    EXPECT_TRUE(zap2.Zap(true, true));
 179    :  
 180    :    // The sets of zapped files should match.
 181  E :    EXPECT_TRUE(file_util::ContentsEqual(temp_pe_path_, pe_path_0));
 182  E :    EXPECT_TRUE(file_util::ContentsEqual(temp_pe_path_, pe_path_1));
 183  E :    EXPECT_TRUE(file_util::ContentsEqual(temp_pdb_path_, pdb_path_0));
 184  E :    EXPECT_TRUE(file_util::ContentsEqual(temp_pdb_path_, pdb_path_1));
 185  E :  }
 186    :  
 187    :  }  // namespace zap_timestamp

Coverage information generated Thu Mar 14 11:53:36 2013.