MailJDTourDownloadDocsQualityTestsCoverage

Which source lines and branches the tests execute. Lines 91.5 %, branches 75.0 % (minimum 85 % and 72 %). main @ 399ffe3d · 21 October 2026 · pipeline 7238.

GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 98.9% 89 / 0 / 90
Functions: 100.0% 15 / 0 / 15
Branches: 74.8% 80 / 0 / 107

data/ComposeDocumentFormat.cpp
Line Branch Exec Source
1 #include "ComposeDocumentFormat.h"
2
3 #include <QHash>
4 #include <QTextBlock>
5 #include <QTextCharFormat>
6 #include <QUrl>
7 #include <cmath>
8
9 namespace ComposeDocumentFormat {
10
11 71 const QList<FontFamily> &fontFamilies() {
12 static const QList<FontFamily> families{
13 5 {QStringLiteral("default"), QStringLiteral("Default"), QString(), QString()},
14 5 {QStringLiteral("sans"), QStringLiteral("Arial"), QStringLiteral("Arial"),
15 5 QStringLiteral("Arial, Helvetica, sans-serif")},
16 5 {QStringLiteral("verdana"), QStringLiteral("Verdana"), QStringLiteral("Verdana"),
17 5 QStringLiteral("Verdana, Geneva, sans-serif")},
18 5 {QStringLiteral("tahoma"), QStringLiteral("Tahoma"), QStringLiteral("Tahoma"),
19 5 QStringLiteral("Tahoma, Verdana, sans-serif")},
20 5 {QStringLiteral("trebuchet"), QStringLiteral("Trebuchet MS"), QStringLiteral("Trebuchet MS"),
21 5 QStringLiteral("'Trebuchet MS', Helvetica, sans-serif")},
22 5 {QStringLiteral("georgia"), QStringLiteral("Georgia"), QStringLiteral("Georgia"),
23 5 QStringLiteral("Georgia, 'Times New Roman', serif")},
24 5 {QStringLiteral("times"), QStringLiteral("Times New Roman"), QStringLiteral("Times New Roman"),
25 5 QStringLiteral("'Times New Roman', Times, serif")},
26 5 {QStringLiteral("mono"), QStringLiteral("Courier New"), QStringLiteral("Courier New"),
27 5 QStringLiteral("'Courier New', Consolas, monospace")},
28
5/10
✓ Branch 2 → 3 taken 5 times.
✓ Branch 2 → 132 taken 66 times.
✓ Branch 4 → 5 taken 5 times.
✗ Branch 4 → 132 not taken.
✓ Branch 99 → 100 taken 40 times.
✓ Branch 99 → 101 taken 5 times.
✗ Branch 135 → 136 not taken.
✗ Branch 135 → 137 not taken.
✗ Branch 303 → 304 not taken.
✗ Branch 303 → 305 not taken.
121 };
29 71 return families;
30 155 }
31
32 11956 const FontFamily *fontFamilyFor(const QString &familyOrKey) {
33
2/2
✓ Branch 3 → 4 taken 11885 times.
✓ Branch 3 → 5 taken 71 times.
11956 if (familyOrKey.isEmpty()) return nullptr;
34
3/3
✓ Branch 5 → 6 taken 71 times.
✓ Branch 27 → 8 taken 272 times.
✓ Branch 27 → 28 taken 5 times.
277 for (const FontFamily &family : fontFamilies()) {
35
5/6
✓ Branch 10 → 11 taken 272 times.
✗ Branch 10 → 13 not taken.
✓ Branch 12 → 13 taken 71 times.
✓ Branch 12 → 14 taken 201 times.
✓ Branch 15 → 16 taken 71 times.
✓ Branch 15 → 17 taken 201 times.
272 if (family.key.isEmpty() || family.family.isEmpty()) continue;
36
6/6
✓ Branch 18 → 19 taken 188 times.
✓ Branch 18 → 21 taken 13 times.
✓ Branch 20 → 21 taken 53 times.
✓ Branch 20 → 22 taken 135 times.
✓ Branch 23 → 24 taken 66 times.
✓ Branch 23 → 25 taken 135 times.
389 if (family.key.compare(familyOrKey, Qt::CaseInsensitive) == 0 ||
37 188 family.family.compare(familyOrKey, Qt::CaseInsensitive) == 0)
38 66 return &family;
39 }
40 5 return nullptr;
41 }
42
43 15029 QString mapForeignFontFamily(const QString &cssFamilies) {
44 // The first family decides; the fallbacks after it are the sender's
45 // stack, not a choice. System and generic defaults mean "no family".
46
2/2
✓ Branch 5 → 6 taken 15029 times.
✓ Branch 6 → 7 taken 15029 times.
15029 QString name = cssFamilies.section(QLatin1Char(','), 0, 0).trimmed();
47
7/10
✓ Branch 9 → 10 taken 748 times.
✓ Branch 9 → 19 taken 14281 times.
✓ Branch 12 → 13 taken 748 times.
✓ Branch 13 → 14 taken 748 times.
✗ Branch 13 → 18 not taken.
✓ Branch 16 → 17 taken 748 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 748 times.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 26 taken 15029 times.
15029 if (name.size() >= 2 && (name.startsWith(QLatin1Char('"')) || name.startsWith(QLatin1Char('\''))))
48 ✗ name = name.mid(1, name.size() - 2);
49
1/1
✓ Branch 26 → 27 taken 15029 times.
15029 const QString lower = name.toLower();
50 static const QHash<QString, QString> families{
51 27 {QStringLiteral("arial"), QStringLiteral("Arial")},
52 27 {QStringLiteral("helvetica"), QStringLiteral("Arial")},
53 27 {QStringLiteral("helvetica neue"), QStringLiteral("Arial")},
54 27 {QStringLiteral("calibri"), QStringLiteral("Arial")},
55 27 {QStringLiteral("aptos"), QStringLiteral("Arial")},
56 27 {QStringLiteral("liberation sans"), QStringLiteral("Arial")},
57 27 {QStringLiteral("verdana"), QStringLiteral("Verdana")},
58 27 {QStringLiteral("geneva"), QStringLiteral("Verdana")},
59 27 {QStringLiteral("tahoma"), QStringLiteral("Tahoma")},
60 27 {QStringLiteral("trebuchet ms"), QStringLiteral("Trebuchet MS")},
61 27 {QStringLiteral("trebuchet"), QStringLiteral("Trebuchet MS")},
62 27 {QStringLiteral("georgia"), QStringLiteral("Georgia")},
63 27 {QStringLiteral("cambria"), QStringLiteral("Georgia")},
64 27 {QStringLiteral("times new roman"), QStringLiteral("Times New Roman")},
65 27 {QStringLiteral("times"), QStringLiteral("Times New Roman")},
66 27 {QStringLiteral("liberation serif"), QStringLiteral("Times New Roman")},
67 27 {QStringLiteral("serif"), QStringLiteral("Times New Roman")},
68 27 {QStringLiteral("courier new"), QStringLiteral("Courier New")},
69 27 {QStringLiteral("courier"), QStringLiteral("Courier New")},
70 27 {QStringLiteral("consolas"), QStringLiteral("Courier New")},
71 27 {QStringLiteral("liberation mono"), QStringLiteral("Courier New")},
72 27 {QStringLiteral("monospace"), QStringLiteral("Courier New")},
73 27 {QStringLiteral("menlo"), QStringLiteral("Courier New")},
74
5/10
✓ Branch 27 → 28 taken 9 times.
✓ Branch 27 → 301 taken 15020 times.
✓ Branch 29 → 30 taken 9 times.
✗ Branch 29 → 301 not taken.
✓ Branch 202 → 203 taken 216 times.
✓ Branch 202 → 204 taken 9 times.
✗ Branch 318 → 319 not taken.
✗ Branch 318 → 320 not taken.
✗ Branch 615 → 616 not taken.
✗ Branch 615 → 617 not taken.
15281 {QStringLiteral("monaco"), QStringLiteral("Courier New")}};
75 30058 return families.value(lower);
76 15254 }
77
78 43537 int region(const QTextBlock &block) {
79
2/2
✓ Branch 2 → 3 taken 43537 times.
✓ Branch 3 → 4 taken 43537 times.
43537 return block.blockFormat().intProperty(RegionProperty);
80 }
81
82 31049 bool isCodeBlock(const QTextBlock &block) {
83
2/2
✓ Branch 2 → 3 taken 31049 times.
✓ Branch 3 → 4 taken 31049 times.
31049 return block.blockFormat().hasProperty(QTextFormat::BlockCodeFence);
84 }
85
86 32886 int quoteLevel(const QTextBlock &block) {
87
2/2
✓ Branch 2 → 3 taken 32886 times.
✓ Branch 3 → 4 taken 32886 times.
32886 return block.blockFormat().intProperty(QTextFormat::BlockQuoteLevel);
88 }
89
90 6731 bool isHorizontalRule(const QTextBlock &block) {
91
2/2
✓ Branch 2 → 3 taken 6731 times.
✓ Branch 3 → 4 taken 6731 times.
6731 return block.blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth);
92 }
93
94 44231 bool isInlineCode(const QTextCharFormat &format) {
95 44231 return format.boolProperty(CodeProperty);
96 }
97
98 49 static double luminance(const QColor &color) {
99 147 const auto channel = [](double value) {
100 147 value /= 255.0;
101
2/2
✓ Branch 2 → 3 taken 62 times.
✓ Branch 2 → 4 taken 85 times.
147 return value <= 0.03928 ? value / 12.92 : std::pow((value + 0.055) / 1.055, 2.4);
102 };
103 49 const QColor rgb = color.toRgb();
104 49 return 0.2126 * channel(rgb.red()) + 0.7152 * channel(rgb.green()) + 0.0722 * channel(rgb.blue());
105 }
106
107 // Grey-ish: no hue a reader would notice (HSL saturation below 15 %).
108 21 static bool greyish(const QColor &color) {
109
3/4
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 11 taken 16 times.
✓ Branch 7 → 8 taken 5 times.
✗ Branch 7 → 11 not taken.
26 return color.toHsl().hslSaturationF() < 0.15 || color.toHsl().lightnessF() < 0.08 ||
110
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 5 times.
26 color.toHsl().lightnessF() > 0.97;
111 }
112
113 36 bool isDefaultLikeTextColor(const QColor &color) {
114
4/6
✓ Branch 3 → 4 taken 36 times.
✗ Branch 3 → 9 not taken.
✓ Branch 5 → 6 taken 12 times.
✓ Branch 5 → 9 taken 24 times.
✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 9 not taken.
36 return color.isValid() && luminance(color) < 0.03 && greyish(color); // black … #2e2e2e
115 }
116
117 13 bool isDefaultLikeBackground(const QColor &color) {
118
6/8
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 11 not taken.
✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 10 not taken.
✓ Branch 7 → 8 taken 9 times.
✓ Branch 7 → 11 taken 4 times.
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 11 taken 5 times.
13 return color.isValid() && (color.alpha() == 0 || (luminance(color) > 0.85 && greyish(color))); // white … #f0f0f0
119 }
120
121 57 QString cssColor(const QColor &color) {
122
2/2
✓ Branch 3 → 4 taken 57 times.
✓ Branch 4 → 5 taken 57 times.
57 return color.toRgb().name(QColor::HexRgb).toLower();
123 }
124
125 4874 bool isAllowedLink(const QString &href) {
126
1/1
✓ Branch 2 → 3 taken 4874 times.
4874 const QUrl url(href, QUrl::StrictMode);
127
4/7
✓ Branch 3 → 4 taken 4874 times.
✓ Branch 4 → 5 taken 4874 times.
✗ Branch 4 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 4874 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 4874 times.
4874 if (!url.isValid() || href.size() > 2048) return false;
128
2/2
✓ Branch 11 → 12 taken 4874 times.
✓ Branch 12 → 13 taken 4874 times.
4874 const QString scheme = url.scheme().toLower();
129
3/3
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 23 taken 4858 times.
✓ Branch 18 → 19 taken 16 times.
4890 if (scheme == QLatin1String("mailto")) return !url.path().isEmpty();
130
8/11
✓ Branch 25 → 26 taken 4857 times.
✓ Branch 25 → 29 taken 1 time.
✓ Branch 28 → 29 taken 4850 times.
✓ Branch 28 → 34 taken 7 times.
✓ Branch 30 → 31 taken 4851 times.
✓ Branch 32 → 33 taken 4851 times.
✗ Branch 32 → 34 not taken.
✓ Branch 36 → 37 taken 4851 times.
✓ Branch 36 → 38 taken 7 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
9709 return (scheme == QLatin1String("http") || scheme == QLatin1String("https")) && !url.host().isEmpty();
131 4874 }
132
133 } // namespace ComposeDocumentFormat
134