Coverage for /Syzygy/kasko/testing/launch_python_process_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/kasko/testing/launch_python_process.h"
  16    :  
  17    :  #include "base/bind.h"
  18    :  #include "base/callback_helpers.h"
  19    :  #include "base/command_line.h"
  20    :  #include "base/files/file_path.h"
  21    :  #include "base/process/kill.h"
  22    :  #include "base/win/scoped_handle.h"
  23    :  #include "gtest/gtest.h"
  24    :  
  25    :  namespace kasko {
  26    :  namespace testing {
  27    :  
  28  E :  TEST(LaunchPythonProcessTest, BasicTest) {
  29  E :    base::CommandLine args(base::CommandLine::NO_PROGRAM);
  30  E :    base::Process process;
  31    :    process = LaunchPythonProcess(
  32  E :        base::FilePath(L"syzygy/kasko/testing/exit_with.py"), args);
  33  E :    ASSERT_TRUE(process.IsValid());
  34  E :    int exit_code = 0;
  35  E :    ASSERT_TRUE(process.WaitForExit(&exit_code));
  36  E :    ASSERT_EQ(0, exit_code);
  37    :  
  38    :    // Pass an argument.
  39  E :    args.AppendArg("2");
  40    :    process = LaunchPythonProcess(
  41  E :        base::FilePath(L"syzygy/kasko/testing/exit_with.py"), args);
  42  E :    ASSERT_TRUE(process.IsValid());
  43  E :    ASSERT_TRUE(process.WaitForExit(&exit_code));
  44  E :    ASSERT_EQ(2, exit_code);
  45    :  
  46    :    // Switches are treated differently than arguments by CommandLine, and proved
  47    :    // to be tricky in the implementation. Hence this test case with both a switch
  48    :    // and an argument.
  49  E :    args.AppendSwitch("-p 3");
  50    :    process = LaunchPythonProcess(
  51  E :        base::FilePath(L"syzygy/kasko/testing/exit_with.py"), args);
  52  E :    ASSERT_TRUE(process.IsValid());
  53  E :    ASSERT_TRUE(process.WaitForExit(&exit_code));
  54  E :    ASSERT_EQ(5, exit_code);
  55    :  
  56    :    // Set stdin to NULL, as the test launcher does in a parallel test mode.
  57    :    base::ScopedClosureRunner reset_stdin(
  58    :        base::Bind(base::IgnoreResult(&::SetStdHandle), STD_INPUT_HANDLE,
  59  E :                   ::GetStdHandle(STD_INPUT_HANDLE)));
  60  E :    ::SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
  61    :    process = LaunchPythonProcess(
  62  E :        base::FilePath(L"syzygy/kasko/testing/exit_with.py"), args);
  63  E :    ASSERT_TRUE(process.IsValid());
  64  E :    ASSERT_TRUE(process.WaitForExit(&exit_code));
  65  E :    ASSERT_EQ(5, exit_code);
  66  E :  }
  67    :  
  68    :  }  // namespace testing
  69    :  }  // namespace kasko

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