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: 97.4% 74 / 0 / 76
Functions: 100.0% 7 / 0 / 7
Branches: 76.7% 148 / 0 / 193

presentation/QuickRuleReview.cpp
Line Branch Exec Source
1 // Review before upload (Sprint 95 S95.3.10, SIEVE-REVIEW): part of
2 // QuickRulesBackend. Script-editor saves and restored versions show a
3 // block-level diff against the version on the server first; single-rule
4 // saves skip it (their rule sentence already shows the change).
5 #include "QuickRulesBackend.h"
6
7 #include "data/SieveBlockDiff.h"
8
9 #include <QFile>
10 #include <QFileInfo>
11 #include <QLoggingCategory>
12 #include <QSaveFile>
13 #include <QStringDecoder>
14
15 Q_DECLARE_LOGGING_CATEGORY(lcRulesBackend)
16
17 namespace {
18
19 10 QString kindName(Sieve::BlockChange::Kind kind) {
20
4/5
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 8 taken 2 times.
✓ Branch 2 → 13 taken 3 times.
✓ Branch 2 → 18 taken 1 time.
✗ Branch 2 → 23 not taken.
10 switch (kind) {
21 8 case Sieve::BlockChange::Kind::Changed: return QStringLiteral("changed");
22 4 case Sieve::BlockChange::Kind::Added: return QStringLiteral("added");
23 6 case Sieve::BlockChange::Kind::Removed: return QStringLiteral("removed");
24 2 case Sieve::BlockChange::Kind::Moved: return QStringLiteral("moved");
25 }
26 ✗ return {};
27 }
28
29 } // namespace
30
31 5 QVariantMap QuickRulesBackend::reviewMap(const QByteArray &before, const QByteArray &after) const {
32
1/1
✓ Branch 2 → 3 taken 5 times.
5 const Sieve::ScriptDiff diff = Sieve::diffScripts(before, after);
33 5 QStringList changed, added, removed, moved;
34 5 QVariantList changes;
35
2/2
✓ Branch 94 → 5 taken 10 times.
✓ Branch 94 → 95 taken 5 times.
15 for (const Sieve::BlockChange &change : diff.changes) {
36
3/3
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 9 times.
✓ Branch 7 → 9 taken 1 time.
10 const QString name = diff.wholeScript ? tr("Whole script") : change.name;
37 10 QVariantList lines;
38
2/2
✓ Branch 52 → 11 taken 117 times.
✓ Branch 52 → 53 taken 10 times.
127 for (const Sieve::DiffLine &line : change.lines)
39
3/5
✓ Branch 15 → 16 taken 88 times.
✓ Branch 15 → 19 taken 29 times.
✓ Branch 33 → 34 taken 117 times.
✗ Branch 214 → 215 not taken.
✗ Branch 214 → 216 not taken.
468 lines.append(QVariantMap{{QStringLiteral("op"), line.op == Sieve::DiffLine::Op::Same ? QStringLiteral(" ")
40
4/6
✓ Branch 19 → 20 taken 17 times.
✓ Branch 19 → 23 taken 12 times.
✓ Branch 46 → 47 taken 88 times.
✓ Branch 46 → 48 taken 29 times.
✗ Branch 210 → 211 not taken.
✗ Branch 210 → 212 not taken.
146 : line.op == Sieve::DiffLine::Op::Removed ? QStringLiteral("-")
41
4/6
✓ Branch 42 → 43 taken 12 times.
✓ Branch 42 → 44 taken 105 times.
✓ Branch 44 → 45 taken 17 times.
✓ Branch 44 → 46 taken 100 times.
✗ Branch 206 → 207 not taken.
✗ Branch 206 → 208 not taken.
117 : QStringLiteral("+")},
42
2/4
✓ Branch 37 → 38 taken 234 times.
✓ Branch 37 → 39 taken 117 times.
✗ Branch 195 → 196 not taken.
✗ Branch 195 → 197 not taken.
585 {QStringLiteral("text"), line.text}});
43
2/2
✓ Branch 56 → 57 taken 10 times.
✓ Branch 68 → 69 taken 10 times.
30 changes.append(QVariantMap{{QStringLiteral("kind"), kindName(change.kind)},
44 20 {QStringLiteral("name"), name},
45
2/4
✓ Branch 72 → 73 taken 30 times.
✓ Branch 72 → 74 taken 10 times.
✗ Branch 239 → 240 not taken.
✗ Branch 239 → 241 not taken.
50 {QStringLiteral("lines"), lines}});
46
4/5
✓ Branch 81 → 82 taken 4 times.
✓ Branch 81 → 84 taken 2 times.
✓ Branch 81 → 86 taken 3 times.
✓ Branch 81 → 88 taken 1 time.
✗ Branch 81 → 90 not taken.
10 switch (change.kind) {
47
1/1
✓ Branch 82 → 83 taken 4 times.
4 case Sieve::BlockChange::Kind::Changed: changed.append(name); break;
48
1/1
✓ Branch 84 → 85 taken 2 times.
2 case Sieve::BlockChange::Kind::Added: added.append(name); break;
49
1/1
✓ Branch 86 → 87 taken 3 times.
3 case Sieve::BlockChange::Kind::Removed: removed.append(name); break;
50
1/1
✓ Branch 88 → 89 taken 1 time.
1 case Sieve::BlockChange::Kind::Moved: moved.append(name); break;
51 }
52 10 }
53
9/15
✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 7 taken 10 times.
✓ Branch 10 → 11 taken 10 times.
✓ Branch 12 → 13 taken 10 times.
✓ Branch 12 → 14 taken 6 times.
✓ Branch 14 → 15 taken 10 times.
✓ Branch 14 → 16 taken 6 times.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 16 → 18 taken 10 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
32 const auto list = [](const QStringList &names) { return names.isEmpty() ? QStringLiteral("—") : names.join(QStringLiteral(", ")); };
54
5/5
✓ Branch 95 → 96 taken 5 times.
✓ Branch 96 → 97 taken 5 times.
✓ Branch 97 → 98 taken 5 times.
✓ Branch 98 → 99 taken 5 times.
✓ Branch 99 → 100 taken 5 times.
5 QString summary = tr("Changed: %1 · Added: %2 · Removed: %3").arg(list(changed), list(added), list(removed));
55
2/2
✓ Branch 105 → 106 taken 1 time.
✓ Branch 105 → 122 taken 4 times.
5 if (!moved.isEmpty())
56
5/5
✓ Branch 106 → 107 taken 1 time.
✓ Branch 108 → 109 taken 1 time.
✓ Branch 109 → 110 taken 1 time.
✓ Branch 113 → 114 taken 1 time.
✓ Branch 114 → 115 taken 1 time.
3 summary += QStringLiteral(" · ") + tr("Moved: %1").arg(list(moved));
57
2/2
✓ Branch 122 → 123 taken 1 time.
✓ Branch 122 → 134 taken 4 times.
5 if (diff.requireChanged)
58
3/3
✓ Branch 123 → 124 taken 1 time.
✓ Branch 127 → 128 taken 1 time.
✓ Branch 128 → 129 taken 1 time.
2 summary += QStringLiteral(" · ") + tr("Extensions changed");
59
7/7
✓ Branch 134 → 135 taken 5 times.
✓ Branch 138 → 139 taken 5 times.
✓ Branch 139 → 140 taken 5 times.
✓ Branch 141 → 142 taken 5 times.
✓ Branch 142 → 143 taken 5 times.
✓ Branch 146 → 136 taken 5 times.
✓ Branch 146 → 147 taken 5 times.
10 qCDebug(lcRulesBackend) << "Review:" << diff.changes.size() << "block changes";
60 10 return {{QStringLiteral("identical"), diff.identical()},
61 10 {QStringLiteral("wholeScript"), diff.wholeScript},
62
1/3
✗ Branch 160 → 161 not taken.
✓ Branch 160 → 162 taken 5 times.
✗ Branch 161 → 163 not taken.
10 {QStringLiteral("summary"), diff.identical() ? tr("Nothing changes.") : summary},
63
2/4
✓ Branch 170 → 171 taken 20 times.
✓ Branch 170 → 172 taken 5 times.
✗ Branch 326 → 327 not taken.
✗ Branch 326 → 328 not taken.
40 {QStringLiteral("changes"), changes}};
64 421 }
65
66 3 QVariantMap QuickRulesBackend::reviewScript(const QString &text) const {
67 3 const SieveSession *s = session();
68
3/4
✓ Branch 3 → 4 taken 3 times.
✓ Branch 4 → 5 taken 3 times.
✗ Branch 4 → 6 not taken.
✓ Branch 7 → 8 taken 3 times.
3 return reviewMap(s ? s->baseScript() : QByteArray(), text.toUtf8());
69 }
70
71 2 QVariantMap QuickRulesBackend::reviewVersion(const QString &id) {
72
1/1
✓ Branch 2 → 3 taken 2 times.
2 SieveSession *s = session();
73
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 17 taken 2 times.
2 if (!s)
74 ✗ return {{QStringLiteral("error"), tr("Rules can't be changed right now. Reload them and try again.")}};
75
1/1
✓ Branch 18 → 19 taken 2 times.
2 const QByteArray bytes = s->history().read(id);
76
2/2
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 34 taken 1 time.
2 if (bytes.isEmpty())
77
3/5
✓ Branch 24 → 25 taken 1 time.
✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 30 taken 1 time.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
3 return {{QStringLiteral("error"), tr("This version is no longer available.")}};
78
1/1
✓ Branch 35 → 36 taken 1 time.
1 return reviewMap(s->baseScript(), bytes);
79 4 }
80
81 // --- script files ---------------------------------------------------------------------
82
83 4 QVariantMap QuickRulesBackend::readScriptFile(const QUrl &file) const {
84
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 3 → 4 taken 4 times.
4 QFile in(file.toLocalFile());
85
3/3
✓ Branch 6 → 7 taken 4 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 27 taken 3 times.
4 if (!in.open(QIODevice::ReadOnly))
86
3/5
✓ Branch 15 → 16 taken 1 time.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 21 taken 1 time.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
6 return {{QStringLiteral("ok"), false}, {QStringLiteral("message"), tr("The file can't be read.")}};
87
3/3
✓ Branch 27 → 28 taken 3 times.
✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 48 taken 2 times.
3 if (in.size() > 1024 * 1024)
88
3/5
✓ Branch 36 → 37 taken 1 time.
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 1 time.
✗ Branch 154 → 155 not taken.
✗ Branch 154 → 156 not taken.
6 return {{QStringLiteral("ok"), false}, {QStringLiteral("message"), tr("The file is larger than 1 MB.")}};
89
1/1
✓ Branch 48 → 49 taken 2 times.
2 const QByteArray bytes = in.readAll();
90 2 QStringDecoder decoder(QStringDecoder::Utf8);
91
1/1
✓ Branch 50 → 51 taken 2 times.
2 const QString text = decoder(bytes);
92
2/2
✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 72 taken 1 time.
2 if (decoder.hasError())
93
3/5
✓ Branch 60 → 61 taken 1 time.
✓ Branch 64 → 65 taken 2 times.
✓ Branch 64 → 66 taken 1 time.
✗ Branch 181 → 182 not taken.
✗ Branch 181 → 183 not taken.
6 return {{QStringLiteral("ok"), false}, {QStringLiteral("message"), tr("The file is not UTF-8 text.")}};
94
7/7
✓ Branch 72 → 73 taken 1 time.
✓ Branch 76 → 77 taken 1 time.
✓ Branch 77 → 78 taken 1 time.
✓ Branch 79 → 80 taken 1 time.
✓ Branch 80 → 81 taken 1 time.
✓ Branch 84 → 74 taken 1 time.
✓ Branch 84 → 85 taken 1 time.
2 qCInfo(lcRulesBackend) << "Script file read:" << bytes.size() << "bytes";
95 4 return {{QStringLiteral("ok"), true}, {QStringLiteral("text"), text},
96
6/8
✓ Branch 96 → 97 taken 1 time.
✓ Branch 98 → 99 taken 1 time.
✓ Branch 99 → 100 taken 1 time.
✓ Branch 100 → 101 taken 1 time.
✓ Branch 104 → 105 taken 3 times.
✓ Branch 104 → 106 taken 1 time.
✗ Branch 212 → 213 not taken.
✗ Branch 212 → 214 not taken.
7 {QStringLiteral("message"), tr("Loaded „%1“. Save to review and upload it.").arg(QFileInfo(in).fileName())}};
97 21 }
98
99 2 QVariantMap QuickRulesBackend::writeScriptFile(const QUrl &file, const QString &text) const {
100
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 3 → 4 taken 2 times.
2 QSaveFile out(file.toLocalFile());
101
1/1
✓ Branch 5 → 6 taken 2 times.
2 const QByteArray bytes = text.toUtf8();
102
9/11
✓ Branch 7 → 8 taken 2 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 14 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 14 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 1 time.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 36 taken 1 time.
2 if (!out.open(QIODevice::WriteOnly) || out.write(bytes) != bytes.size() || !out.commit())
103
3/5
✓ Branch 24 → 25 taken 1 time.
✓ Branch 28 → 29 taken 2 times.
✓ Branch 28 → 30 taken 1 time.
✗ Branch 86 → 87 not taken.
✗ Branch 86 → 88 not taken.
6 return {{QStringLiteral("ok"), false}, {QStringLiteral("message"), tr("The file can't be written.")}};
104
7/7
✓ Branch 36 → 37 taken 1 time.
✓ Branch 40 → 41 taken 1 time.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 44 → 45 taken 1 time.
✓ Branch 48 → 38 taken 1 time.
✓ Branch 48 → 49 taken 1 time.
2 qCInfo(lcRulesBackend) << "Script file written:" << bytes.size() << "bytes";
105 2 return {{QStringLiteral("ok"), true},
106
7/9
✓ Branch 56 → 57 taken 1 time.
✓ Branch 58 → 59 taken 1 time.
✓ Branch 59 → 60 taken 1 time.
✓ Branch 60 → 61 taken 1 time.
✓ Branch 61 → 62 taken 1 time.
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 67 taken 1 time.
✗ Branch 117 → 118 not taken.
✗ Branch 117 → 119 not taken.
6 {QStringLiteral("message"), tr("Saved to „%1“.").arg(QFileInfo(file.toLocalFile()).fileName())}};
107 10 }
108