Coverage for /Syzygy/refinery/analyzers/analysis_runner_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2015 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/refinery/analyzers/analysis_runner.h"
  16    :  
  17    :  #include "gmock/gmock.h"
  18    :  #include "gtest/gtest.h"
  19    :  #include "syzygy/minidump/minidump.h"
  20    :  #include "syzygy/refinery/analyzers/analyzer.h"
  21    :  #include "syzygy/refinery/process_state/process_state.h"
  22    :  
  23    :  namespace refinery {
  24    :  
  25    :  namespace {
  26    :  
  27    :  using testing::_;
  28    :  using testing::Return;
  29    :  
  30    :  static const char kMockAnalyzerName[] = "MockAnalyzer";
  31    :  
  32    :  class MockAnalyzer : public Analyzer {
  33    :   public:
  34  E :    const char* name() const { return kMockAnalyzerName; }
  35    :  
  36    :    MOCK_METHOD2(Analyze,
  37    :                 AnalysisResult(const minidump::Minidump& minidump,
  38  E :                                ProcessState* process_state));
  39    :  };
  40    :  
  41    :  // Creates a mock analyzer that has an expectation it will be called once.
  42    :  MockAnalyzer* CreateMockAnalyzer(ProcessState* process_state,
  43  E :                                   Analyzer::AnalysisResult result) {
  44  E :    MockAnalyzer* analyzer = new MockAnalyzer();
  45    :    EXPECT_CALL(*analyzer, Analyze(_, process_state))
  46    :        .Times(1)
  47  E :        .WillOnce(Return(result));
  48  E :    return analyzer;
  49  E :  }
  50    :  
  51    :  }  // namespace
  52    :  
  53  E :  TEST(AnalysisRunnerTest, BasicSuccessTest) {
  54  E :    minidump::Minidump minidump;
  55  E :    ProcessState process_state;
  56    :  
  57    :    // A runner with 2 analyzers that should run and succeed.
  58  E :    AnalysisRunner runner;
  59  E :    for (size_t i = 0; i < 2; ++i) {
  60    :      scoped_ptr<MockAnalyzer> analyzer(
  61  E :          CreateMockAnalyzer(&process_state, Analyzer::ANALYSIS_COMPLETE));
  62  E :      runner.AddAnalyzer(analyzer.Pass());
  63  E :    }
  64    :  
  65    :    // Analyze.
  66    :    ASSERT_EQ(Analyzer::ANALYSIS_COMPLETE,
  67  E :              runner.Analyze(minidump, &process_state));
  68  E :  }
  69    :  
  70  E :  TEST(AnalysisRunnerTest, BasicErrorTest) {
  71  E :    minidump::Minidump minidump;
  72  E :    ProcessState process_state;
  73    :  
  74    :    // A runner with 1 analyzer that should run and return an error.
  75  E :    AnalysisRunner runner;
  76    :    scoped_ptr<MockAnalyzer> analyzer(
  77  E :        CreateMockAnalyzer(&process_state, Analyzer::ANALYSIS_ERROR));
  78  E :    runner.AddAnalyzer(analyzer.Pass());
  79    :  
  80    :    // Analyze.
  81  E :    ASSERT_EQ(Analyzer::ANALYSIS_ERROR, runner.Analyze(minidump, &process_state));
  82  E :  }
  83    :  
  84    :  }  // namespace refinery

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