diff options
| -rw-r--r-- | src/config.cpp | 19 | ||||
| -rw-r--r-- | tests/test_config.cpp | 29 |
2 files changed, 46 insertions, 2 deletions
diff --git a/src/config.cpp b/src/config.cpp index b54d5c6..4f5831c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -19,6 +19,9 @@ #include "config.h" #include "mailsync.h" +// For kMinZoom/kMaxZoom. The bounds live with the widget that enforces them, +// so this reports the same numbers rather than keeping a second copy. +#include "messageview.h" #include <QFileInfo> #include <QSettings> @@ -76,8 +79,8 @@ void Config::load(const QString &path) // Absent is fine and silent: the default is 1.0. Present but unparseable // is a problem, since the user asked for something and is not getting it. - // The range check lives in MessageView::clampZoom(), the one place that - // knows what the web view can render. + // The range is enforced by MessageView::clampZoom(), the one place that + // knows what the web view can render; out of range is reported below. // Empty is treated as unset rather than as "a query named nothing". const QString startup = settings.value(QStringLiteral("startup_query")).toString().trimmed(); @@ -92,6 +95,18 @@ void Config::load(const QString &path) const double value = zoom.toString().toDouble(&ok); if (ok) { m_messageZoom = value; + // Reported, not clamped: MessageView::clampZoom() owns the bounds + // and already stops this reaching the web view, so clamping here + // too would be a second copy of the range, free to drift from the + // first. What was missing is the report. The value parses, so + // nothing ever said the 500 in the file is not what is on screen. + if (value < MessageView::kMinZoom || value > MessageView::kMaxZoom) { + addProblem(QStringLiteral("Message zoom %1 is outside %2 to %3; " + "using the nearest allowed value.") + .arg(value) + .arg(MessageView::kMinZoom) + .arg(MessageView::kMaxZoom)); + } } else { addProblem(QStringLiteral("Message zoom '%1' is not a number; " "using the default.") diff --git a/tests/test_config.cpp b/tests/test_config.cpp index ec630d4..7e0d6fb 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -46,6 +46,7 @@ private slots: void unknownStartupQueryFallsBackAndReports(); void generalSectionKeysAreActuallyRead(); void messageZoomDefaultsAndValidates(); + void messageZoomOutOfRangeIsReported(); void completionOnFocusDefaultsToFalse(); void completionOnFocusIsActuallyRead(); void markReadDelayDefaultsToTwoSeconds(); @@ -478,6 +479,34 @@ void TestConfig::messageZoomDefaultsAndValidates() } } +void TestConfig::messageZoomOutOfRangeIsReported() +{ + // MessageView::clampZoom() already stops an out-of-range value from + // reaching the web view, so this is not about the render. It is about the + // silence: the key parses, so nothing ever told the user that the 500 they + // wrote is not what they are looking at. Not clamped here, because + // clampZoom() owns the bounds and two copies would drift. + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral("[general]\n" + "message_zoom=500\n"))); + QCOMPARE(config.problems().size(), 1); + QVERIFY(config.problems().first().contains(QStringLiteral("500"))); + + QTemporaryDir dir2; + Config small; + small.load(writeIni(dir2, QStringLiteral("[general]\n" + "message_zoom=0.1\n"))); + QCOMPARE(small.problems().size(), 1); + + // In range stays silent. + QTemporaryDir dir3; + Config ok; + ok.load(writeIni(dir3, QStringLiteral("[general]\n" + "message_zoom=3.0\n"))); + QVERIFY(ok.problems().isEmpty()); +} + void TestConfig::completionOnFocusDefaultsToFalse() { QTemporaryDir dir; |
