OTest2
A C++ testing framework
testmarkformatterios.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Ondrej Starek
3  *
4  * This file is part of OTest2
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <testmarkformatterios.h>
21 
22 #include <assert.h>
23 #include <iostream>
24 #include <sstream>
25 
26 #include <testmark.h>
27 
28 namespace OTest2 {
29 
31  std::ostream* os_,
32  const std::string& prefix_) :
33  os(os_),
34  prefix(prefix_) {
35  assert(os != nullptr);
36 
37 }
38 
40 
41 void TestMarkFormatterIOS::printLine(
42  const std::string& prefix_,
43  const std::string& label_,
44  const TestMark* mark_,
45  int indent_,
46  bool open_) {
47  std::ostringstream oss_;
48  oss_ << prefix << prefix_;
49  for(int i_(0); i_ < indent_; ++i_)
50  oss_ << " ";
51  if(open_) {
52  if(!label_.empty())
53  oss_ << label_ << ": ";
54  mark_->printOpen(*os, oss_.str());
55  }
56  else
57  mark_->printClose(*os, oss_.str());
58 }
59 
60 void TestMarkFormatterIOS::setTextForeground(
61  Color color_) {
62  /* -- default empty implementation */
63 }
64 
65 void TestMarkFormatterIOS::setTextStyle(
66  Style style_) {
67  /* -- default empty implementation */
68 }
69 
70 void TestMarkFormatterIOS::resetTextAttributes() {
71  /* -- default empty implementation */
72 }
73 
75  const std::string& label_,
76  const TestMark* mark_,
77  int indent_) {
78  printLine(" ", label_, mark_, indent_, true);
79 }
80 
82  const std::string& label_,
83  const TestMark* mark_,
84  int indent_) {
85  printLine(" ", label_, mark_, indent_, false);
86 }
87 
89  const std::string& label_,
90  const TestMark* mark_,
91  int indent_) {
92  setTextForeground(Color::RED);
93  printLine("- ", label_, mark_, indent_, true);
94  resetTextAttributes();
95 }
96 
98  const std::string& label_,
99  const TestMark* mark_,
100  int indent_) {
101  setTextForeground(Color::RED);
102  printLine("- ", label_, mark_, indent_, false);
103  resetTextAttributes();
104 }
105 
107  const std::string& label_,
108  const TestMark* mark_,
109  int indent_) {
110  setTextForeground(Color::GREEN);
111  printLine("+ ", label_, mark_, indent_, true);
112  resetTextAttributes();
113 }
114 
116  const std::string& label_,
117  const TestMark* mark_,
118  int indent_) {
119  setTextForeground(Color::GREEN);
120  printLine("+ ", label_, mark_, indent_, false);
121  resetTextAttributes();
122 }
123 
125  setTextStyle(Style::DIM);
126  *os << " ......... \n";
127  resetTextAttributes();
128 }
129 
130 } /* -- namespace OTest2 */
OTest2::TestMarkFormatterIOS::closeAdded
virtual void closeAdded(const std::string &label_, const TestMark *mark_, int indent_) override
Print closing of an added testmark.
Definition: testmarkformatterios.cpp:115
testmarkformatterios.h
OTest2::Style::DIM
@ DIM
OTest2::Style
Style
Style of shown text.
Definition: reporterattributes.h:44
OTest2::TestMarkFormatterIOS::printSeparator
virtual void printSeparator() override
Print separator (used for unchanged blocks)
Definition: testmarkformatterios.cpp:124
OTest2::TestMark::printOpen
void printOpen(std::ostream &os_, const std::string &prefix_) const
Print opening of the node into a stream.
Definition: testmark.cpp:120
OTest2::TestMarkFormatterIOS::openDeleted
virtual void openDeleted(const std::string &label_, const TestMark *mark_, int indent_) override
Print opening of a deleted testmark.
Definition: testmarkformatterios.cpp:88
OTest2::TestMarkFormatterIOS::openAdded
virtual void openAdded(const std::string &label_, const TestMark *mark_, int indent_) override
Print opening of an added testmark.
Definition: testmarkformatterios.cpp:106
OTest2::Color::GREEN
@ GREEN
OTest2::Color::RED
@ RED
OTest2::Color
Color
List of colors supported by the reporters.
Definition: reporterattributes.h:30
OTest2
Definition: assertbean.h:25
OTest2::TestMarkFormatterIOS::closeDeleted
virtual void closeDeleted(const std::string &label_, const TestMark *mark_, int indent_) override
Print closing of a deleted testmark.
Definition: testmarkformatterios.cpp:97
OTest2::TestMarkFormatterIOS::closeMark
virtual void closeMark(const std::string &label_, const TestMark *mark_, int indent_) override
Print closing of a testmark.
Definition: testmarkformatterios.cpp:81
OTest2::TestMark::printClose
void printClose(std::ostream &os_, const std::string &prefix_) const
Print closing of the node into a stream.
Definition: testmark.cpp:126
testmark.h
OTest2::TestMarkFormatterIOS::~TestMarkFormatterIOS
virtual ~TestMarkFormatterIOS()
Dtor.
OTest2::TestMarkFormatterIOS::openMark
virtual void openMark(const std::string &label_, const TestMark *mark_, int indent_) override
Print opening of a testmark.
Definition: testmarkformatterios.cpp:74
OTest2::TestMark
Generic interface of a test mark node.
Definition: testmark.h:41
OTest2::TestMarkFormatterIOS::TestMarkFormatterIOS
TestMarkFormatterIOS(const TestMarkFormatterIOS &)=delete