Skip to content

Commit 9e9508f

Browse files
author
Christian Feldmann
committed
Add some pretty printers for Googletest. This really helps to find the errors if a check fails.
1 parent e1cdd5a commit 9e9508f

File tree

11 files changed

+285
-42
lines changed

11 files changed

+285
-42
lines changed

YUViewLib/src/statistics/StatisticsDataPainting.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,11 @@ void paintVector(QPainter *painter,
147147
const int headSize =
148148
(zoomFactor >= STATISTICS_DRAW_VALUES_ZOOM && !vector.scaleToZoom) ? 8 : zoomFactor / 2;
149149

150-
if (vector.arrowHead != stats::StatisticsType::ArrowHead::none)
150+
if (vector.arrowHead != stats::ArrowHead::none)
151151
{
152152
// We draw an arrow head. This means that we will have to draw a shortened line
153-
const int shorten = (vector.arrowHead == stats::StatisticsType::ArrowHead::arrow)
154-
? headSize * 2
155-
: headSize * 0.5;
153+
const int shorten =
154+
(vector.arrowHead == stats::ArrowHead::arrow) ? headSize * 2 : headSize * 0.5;
156155

157156
if (std::sqrt(vx * vx * zoomFactor * zoomFactor + vy * vy * zoomFactor * zoomFactor) >
158157
shorten)
@@ -169,7 +168,7 @@ void paintVector(QPainter *painter,
169168
// Draw the not shortened line
170169
painter->drawLine(x1, y1, x2, y2);
171170

172-
if (vector.arrowHead == stats::StatisticsType::ArrowHead::arrow)
171+
if (vector.arrowHead == stats::ArrowHead::arrow)
173172
{
174173
// Save the painter state, translate to the arrow tip, rotate the painter and draw the
175174
// normal triangle.
@@ -185,7 +184,7 @@ void paintVector(QPainter *painter,
185184
// Restore. Revert translation/rotation of the painter.
186185
painter->restore();
187186
}
188-
else if (vector.arrowHead == stats::StatisticsType::ArrowHead::circle)
187+
else if (vector.arrowHead == stats::ArrowHead::circle)
189188
painter->drawEllipse(x2 - headSize / 2, y2 - headSize / 2, headSize, headSize);
190189
}
191190

@@ -591,11 +590,11 @@ void stats::paintStatisticsData(QPainter *painter,
591590
: zoomFactor / 2;
592591

593592
const auto &arrowHead = it->vectorDataOptions->arrowHead;
594-
if (arrowHead != StatisticsType::ArrowHead::none)
593+
if (arrowHead != ArrowHead::none)
595594
{
596595
// We draw an arrow head. This means that we will have to draw a shortened line
597596
const int shorten =
598-
(arrowHead == StatisticsType::ArrowHead::arrow) ? headSize * 2 : headSize * 0.5;
597+
(arrowHead == ArrowHead::arrow) ? headSize * 2 : headSize * 0.5;
599598
if (std::sqrt(vx * vx * zoomFactor * zoomFactor +
600599
vy * vy * zoomFactor * zoomFactor) > shorten)
601600
{
@@ -611,7 +610,7 @@ void stats::paintStatisticsData(QPainter *painter,
611610
// Draw the not shortened line
612611
painter->drawLine(x1, y1, x2, y2);
613612

614-
if (arrowHead == StatisticsType::ArrowHead::arrow)
613+
if (arrowHead == ArrowHead::arrow)
615614
{
616615
// Save the painter state, translate to the arrow tip, rotate the painter and draw
617616
// the normal triangle.
@@ -628,7 +627,7 @@ void stats::paintStatisticsData(QPainter *painter,
628627
// Restore. Revert translation/rotation of the painter.
629628
painter->restore();
630629
}
631-
else if (arrowHead == StatisticsType::ArrowHead::circle)
630+
else if (arrowHead == ArrowHead::circle)
632631
painter->drawEllipse(x2 - headSize / 2, y2 - headSize / 2, headSize, headSize);
633632
}
634633

@@ -915,11 +914,11 @@ void stats::paintStatisticsData(QPainter *painter,
915914
: zoomFactor / 2;
916915

917916
const auto &arrowHead = it->vectorDataOptions->arrowHead;
918-
if (arrowHead != StatisticsType::ArrowHead::none)
917+
if (arrowHead != ArrowHead::none)
919918
{
920919
// We draw an arrow head. This means that we will have to draw a shortened line
921920
const int shorten =
922-
(arrowHead == StatisticsType::ArrowHead::arrow) ? headSize * 2 : headSize * 0.5;
921+
(arrowHead == ArrowHead::arrow) ? headSize * 2 : headSize * 0.5;
923922
if (std::sqrt(vx * vx * zoomFactor * zoomFactor +
924923
vy * vy * zoomFactor * zoomFactor) > shorten)
925924
{
@@ -935,7 +934,7 @@ void stats::paintStatisticsData(QPainter *painter,
935934
// Draw the not shortened line
936935
painter->drawLine(center_x, center_y, head_x, head_y);
937936

938-
if (arrowHead == StatisticsType::ArrowHead::arrow)
937+
if (arrowHead == ArrowHead::arrow)
939938
{
940939
// Save the painter state, translate to the arrow tip, rotate the painter and draw
941940
// the normal triangle.
@@ -952,7 +951,7 @@ void stats::paintStatisticsData(QPainter *painter,
952951
// Restore. Revert translation/rotation of the painter.
953952
painter->restore();
954953
}
955-
else if (arrowHead == StatisticsType::ArrowHead::circle)
954+
else if (arrowHead == ArrowHead::circle)
956955
painter->drawEllipse(
957956
head_x - headSize / 2, head_y - headSize / 2, headSize, headSize);
958957
}

YUViewLib/src/statistics/StatisticsFileCSV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void StatisticsFileCSV::readHeaderFromFile(StatisticsData &statisticsData)
405405
{
406406
type->vectorDataOptions = StatisticsType::VectorDataOptions();
407407
if (rowItemList[4] == "line")
408-
type->vectorDataOptions->arrowHead = StatisticsType::ArrowHead::none;
408+
type->vectorDataOptions->arrowHead = ArrowHead::none;
409409
}
410410
}
411411
}

YUViewLib/src/statistics/StatisticsType.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,27 @@ enum class Pattern
4949
DashDotDot
5050
};
5151

52+
constexpr EnumMapper<Pattern, 5> PatternMapper = {
53+
std::make_pair(Pattern::Solid, "Solid"),
54+
std::make_pair(Pattern::Dash, "Dash"),
55+
std::make_pair(Pattern::Dot, "Dot"),
56+
std::make_pair(Pattern::DashDot, "DashDot"),
57+
std::make_pair(Pattern::DashDotDot, "DashDotDot")};
58+
5259
const std::vector<Pattern> AllPatterns = {
5360
Pattern::Solid, Pattern::Dash, Pattern::Dot, Pattern::DashDot, Pattern::DashDotDot};
5461

62+
enum class ArrowHead
63+
{
64+
arrow,
65+
circle,
66+
none
67+
};
68+
69+
constexpr EnumMapper<ArrowHead, 5> ArrowHeadMapper = {std::make_pair(ArrowHead::arrow, "arrow"),
70+
std::make_pair(ArrowHead::circle, "circle"),
71+
std::make_pair(ArrowHead::none, "none")};
72+
5573
struct LineDrawStyle
5674
{
5775
Color color{};
@@ -92,13 +110,6 @@ class StatisticsType
92110

93111
std::optional<ValueDataOptions> valueDataOptions;
94112

95-
enum class ArrowHead
96-
{
97-
arrow,
98-
circle,
99-
none
100-
};
101-
102113
struct VectorDataOptions
103114
{
104115
modified<bool> render{true};

YUViewLib/src/statistics/StatisticsTypePlaylistHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ void addModifiedValuesToElement(YUViewDomElement
7979
options->colorMapper->savePlaylist(element);
8080
}
8181

82-
std::vector<StatisticsType::ArrowHead> AllArrowHeads = {StatisticsType::ArrowHead::arrow,
83-
StatisticsType::ArrowHead::circle,
84-
StatisticsType::ArrowHead::none};
82+
std::vector<ArrowHead> AllArrowHeads = {ArrowHead::arrow,
83+
ArrowHead::circle,
84+
ArrowHead::none};
8585

8686
void addModifiedValuesToElement(YUViewDomElement &element,
8787
const std::optional<StatisticsType::VectorDataOptions> &options)

YUViewLib/src/ui/Statisticsstylecontrol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void StatisticsStyleControl::on_checkBoxVectorScaleToZoom_stateChanged(int arg1)
436436

437437
void StatisticsStyleControl::on_comboBoxVectorHeadStyle_currentIndexChanged(int index)
438438
{
439-
this->currentItem->vectorDataOptions->arrowHead = (stats::StatisticsType::ArrowHead)(index);
439+
this->currentItem->vectorDataOptions->arrowHead = (stats::ArrowHead)(index);
440440
emit StyleChanged();
441441
}
442442

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#pragma once
34+
35+
#include <common/Color.h>
36+
#include <common/Modified.h>
37+
#include <common/Typedef.h>
38+
39+
void PrintTo(const bool &flag, std::ostream *os)
40+
{
41+
*os << (flag ? "True" : "False");
42+
}
43+
44+
template <typename T> void PrintTo(const Range<T> &range, std::ostream *os)
45+
{
46+
*os << "(" << range.min << "," << range.max << ")";
47+
}
48+
49+
template <typename T> void PrintTo(const modified<T> &value, std::ostream *os)
50+
{
51+
if (value.wasModified())
52+
*os << "*";
53+
PrintTo(*value, os);
54+
}
55+
56+
void PrintTo(const Color &color, std::ostream *os)
57+
{
58+
*os << "RGBA(" << color.R() << "," << color.G() << "," << color.B() << "," << color.A() << ")";
59+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#pragma once
34+
35+
#include "Common.h"
36+
37+
#include <statistics/ColorMapper.h>
38+
#include <statistics/StatisticsType.h>
39+
40+
namespace stats
41+
{
42+
43+
namespace color
44+
{
45+
46+
void PrintTo(const ColorMap &colorMap, std::ostream *os)
47+
{
48+
*os << "ColorMapper: {";
49+
for (const auto &[value, color] : colorMap)
50+
{
51+
*os << "Value " << value << " ";
52+
PrintTo(color, os);
53+
*os << " ";
54+
}
55+
*os << "}";
56+
}
57+
58+
void PrintTo(const ColorMapper &colorMapper, std::ostream *os)
59+
{
60+
*os << "ColorMapper: {";
61+
62+
*os << "MappingType " << MappingTypeMapper.getName(colorMapper.mappingType);
63+
*os << " valueRange ";
64+
PrintTo(colorMapper.valueRange, os);
65+
*os << " gradientColorStart ";
66+
PrintTo(colorMapper.gradientColorStart, os);
67+
*os << " gradientColorEnd ";
68+
PrintTo(colorMapper.gradientColorEnd, os);
69+
*os << " colorMap ";
70+
PrintTo(colorMapper.colorMap, os);
71+
*os << " colorMapOther ";
72+
PrintTo(colorMapper.colorMapOther, os);
73+
*os << " predefinedType " << PredefinedTypeMapper.getName(colorMapper.predefinedType);
74+
75+
*os << "}";
76+
}
77+
78+
} // namespace color
79+
80+
void PrintTo(const LineDrawStyle &style, std::ostream *os)
81+
{
82+
*os << "LineDrawStyle: {";
83+
84+
*os << "color ";
85+
PrintTo(style.color, os);
86+
*os << " width " << style.width;
87+
*os << " pattern " << PatternMapper.getName(style.pattern);
88+
89+
*os << "}";
90+
}
91+
92+
void PrintTo(const StatisticsType::ValueDataOptions &options, std::ostream *os)
93+
{
94+
*os << "ValueDataOptions: {";
95+
96+
*os << "Render ";
97+
PrintTo(options.render, os);
98+
*os << " ScaleToBlockSize ";
99+
PrintTo(options.scaleToBlockSize, os);
100+
*os << " ColorMapper ";
101+
PrintTo(options.colorMapper, os);
102+
103+
*os << "}";
104+
}
105+
106+
void PrintTo(const StatisticsType::VectorDataOptions &options, std::ostream *os)
107+
{
108+
*os << "VectorDataOptions: {";
109+
110+
*os << "render ";
111+
PrintTo(options.render, os);
112+
*os << " renderDataValues ";
113+
PrintTo(options.renderDataValues, os);
114+
*os << " scaleToZoom ";
115+
PrintTo(options.scaleToZoom, os);
116+
*os << " style ";
117+
PrintTo(options.style, os);
118+
*os << " scale ";
119+
PrintTo(options.scale, os);
120+
*os << " mapToColor ";
121+
PrintTo(options.mapToColor, os);
122+
*os << " arrowHead " << ArrowHeadMapper.getName(options.arrowHead);
123+
124+
*os << "}";
125+
}
126+
127+
void PrintTo(const StatisticsType::GridOptions &options, std::ostream *os)
128+
{
129+
*os << "GridOptions: {";
130+
131+
*os << "render ";
132+
PrintTo(options.render, os);
133+
*os << " style ";
134+
PrintTo(options.style, os);
135+
*os << " scaleToZoom ";
136+
PrintTo(options.scaleToZoom, os);
137+
138+
*os << "}";
139+
}
140+
141+
void PrintTo(const StatisticsType &type, std::ostream *os)
142+
{
143+
*os << "StatisticsType: {";
144+
*os << "TypeID " << type.getTypeID();
145+
*os << " Name " << type.getTypeName();
146+
*os << " Description " << type.getDescription();
147+
148+
*os << " Render ";
149+
PrintTo(type.render, os);
150+
*os << " AlphaFactor ";
151+
PrintTo(type.alphaFactor, os);
152+
153+
if (type.valueDataOptions)
154+
PrintTo(type.valueDataOptions.value(), os);
155+
if (type.vectorDataOptions)
156+
PrintTo(type.vectorDataOptions.value(), os);
157+
PrintTo(type.gridOptions, os);
158+
159+
*os << "}";
160+
}
161+
162+
} // namespace stats

0 commit comments

Comments
 (0)