Coverage for /Syzygy/grinder/find_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2013 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/grinder/find.h"
  16    :  
  17    :  #include "gtest/gtest.h"
  18    :  #include "syzygy/core/unittest_util.h"
  19    :  #include "syzygy/pe/unittest_util.h"
  20    :  
  21    :  namespace grinder {
  22    :  
  23    :  namespace {
  24    :  
  25    :  class GrinderFindTest: public testing::PELibUnitTest {
  26    :   public:
  27    :    GrinderFindTest()
  28    :        : bad_pe_path(L"nonexistent_pe_file.dll"),
  29  E :          self_path(testing::GetOutputRelativePath(L"grinder_unittests.exe")) {
  30  E :    }
  31    :  
  32    :    base::FilePath self_path;
  33    :    base::FilePath bad_pe_path;
  34    :  };
  35    :  
  36    :  }  // namespace
  37    :  
  38  E :  TEST_F(GrinderFindTest, PeFilesAreRelatedFailsBadTransformedPath) {
  39    :    EXPECT_FALSE(PeFilesAreRelated(
  40    :        bad_pe_path,
  41  E :        testing::GetExeTestDataRelativePath(testing::kTestDllName)));
  42  E :  }
  43    :  
  44  E :  TEST_F(GrinderFindTest, PeFilesAreRelatedFailsBadOriginalPath) {
  45    :    EXPECT_FALSE(PeFilesAreRelated(
  46    :        testing::GetExeTestDataRelativePath(
  47    :            testing::kCoverageInstrumentedTestDllName),
  48  E :        bad_pe_path));
  49  E :  }
  50    :  
  51  E :  TEST_F(GrinderFindTest, PeFilesAreRelatedFailsNoMetadata) {
  52    :    EXPECT_FALSE(PeFilesAreRelated(
  53    :        testing::GetExeTestDataRelativePath(testing::kTestDllName),
  54  E :        self_path));
  55  E :  }
  56    :  
  57  E :  TEST_F(GrinderFindTest, PeFilesAreRelatedFailsMismatchedPeFiles) {
  58    :    EXPECT_FALSE(PeFilesAreRelated(
  59    :        testing::GetExeTestDataRelativePath(
  60    :            testing::kCoverageInstrumentedTestDllName),
  61  E :        self_path));
  62  E :  }
  63    :  
  64  E :  TEST_F(GrinderFindTest, PeFilesAreRelatedWorks) {
  65    :    EXPECT_TRUE(PeFilesAreRelated(
  66    :        testing::GetExeTestDataRelativePath(
  67    :            testing::kCoverageInstrumentedTestDllName),
  68  E :        testing::GetOutputRelativePath(testing::kTestDllName)));
  69  E :  }
  70    :  
  71  E :  TEST_F(GrinderFindTest, FindOriginalPeFileFailsBadPath) {
  72  E :    base::FilePath path;
  73  E :    EXPECT_FALSE(FindOriginalPeFile(bad_pe_path, &path));
  74  E :    EXPECT_TRUE(path.empty());
  75  E :  }
  76    :  
  77  E :  TEST_F(GrinderFindTest, FindOriginalPeFileFailsNoMetadata) {
  78    :    // We provide a valid PE file as input, but a file that is not transformed.
  79    :    // This should fail because it contains no metadata.
  80  E :    base::FilePath path;
  81    :    EXPECT_FALSE(FindOriginalPeFile(
  82  E :        testing::GetOutputRelativePath(testing::kTestDllName), &path));
  83  E :    EXPECT_TRUE(path.empty());
  84  E :  }
  85    :  
  86  E :  TEST_F(GrinderFindTest, FindOriginalPeFileWorksWithHint) {
  87    :    base::FilePath expected_path = testing::GetOutputRelativePath(
  88  E :        testing::kTestDllName);
  89    :  
  90    :    // By default FindOriginalPeFile will want to find the test_dll.dll in the
  91    :    // test_data directory, not its copy in the output directory. However, by
  92    :    // providing it with that as a hint it should look there first.
  93  E :    base::FilePath path = expected_path;
  94    :    EXPECT_TRUE(FindOriginalPeFile(
  95    :        testing::GetExeTestDataRelativePath(
  96    :            testing::kCoverageInstrumentedTestDllName),
  97  E :        &path));
  98  E :    EXPECT_FALSE(path.empty());
  99    :  
 100  E :    EXPECT_SAME_FILE(expected_path, path);
 101  E :  }
 102    :  
 103  E :  TEST_F(GrinderFindTest, FindOriginalPeFileWorksWithoutHint) {
 104    :    // Even though we are searching for the module relative to the unittest
 105    :    // executable, we expect it to find the module relative to the original build
 106    :    // directory. There are not the same paths in the case of our coverage bot,
 107    :    // which copies things to another folder.
 108    :    base::FilePath expected_path = testing::GetOutputRelativePath(L"test_data")
 109  E :        .Append(testing::kTestDllName);
 110    :  
 111    :    // In this case we don't provide an explicit hint so it should find the
 112    :    // original test_dll.dll in the test_data directory.
 113  E :    base::FilePath path;
 114    :    EXPECT_TRUE(FindOriginalPeFile(
 115    :        testing::GetExeTestDataRelativePath(
 116    :            testing::kCoverageInstrumentedTestDllName),
 117  E :        &path));
 118  E :    EXPECT_FALSE(path.empty());
 119    :  
 120  E :    EXPECT_SAME_FILE(expected_path, path);
 121  E :  }
 122    :  
 123    :  }  // namespace grinder

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