FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairCaptureOutputNew.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "FairCaptureOutputNew.h"
9 
10 #include <gtest/gtest.h>
11 #include <iostream>
12 
13 FairCaptureOutputNew::FairCaptureOutputNew(bool captureStdErr, bool captureStdOut)
14  : fLineVector()
15  , fCaptureStdOut(captureStdOut)
16  , fCaptureStdErr(captureStdErr)
17 {}
18 
20 
22 {
23  if (fCaptureStdOut && fCaptureStdErr) {
24  std::cout << "Can't capture stdout and stderr at the same time." << std::endl;
25  exit(1);
26  }
27  if (fCaptureStdOut) {
28  // TODO: reimplement these tests via GTest function EXPECT_WRITE
29  // testing::internal::CaptureStdout();
30  }
31  if (fCaptureStdErr) {
32  // TODO: reimplement these tests via GTest function EXPECT_WRITE
33  // testing::internal::CaptureStderr();
34  }
35 }
36 
38 {
39  std::string tmpOutput;
40  if (fCaptureStdOut) {
41  // TODO: reimplement these tests via GTest function EXPECT_WRITE
42  // tmpOutput = testing::internal::GetCapturedStdout();
43  }
44  if (fCaptureStdErr) {
45  // TODO: reimplement these tests via GTest function EXPECT_WRITE
46  // tmpOutput = testing::internal::GetCapturedStderr();
47  }
48 
49  const std::string& sep = "\n";
50  std::size_t start = 0, end = 0;
51  while ((end = tmpOutput.find(sep, start)) != std::string::npos) {
52  fLineVector.push_back(tmpOutput.substr(start, end - start));
53  start = end + 1;
54  }
55 }
56 
57 std::string FairCaptureOutputNew::GetCaptureLine(int line) { return fLineVector[line]; }
58 
59 int FairCaptureOutputNew::GetNumberOfLines() { return fLineVector.size(); }
std::string GetCaptureLine(int line)
FairCaptureOutputNew(bool captureStdErr=false, bool captureStdOut=true)