gui: real RTL + no-download-logic checks; split into velox-gui-lib
Follow-up hardening after a review noted the RTL "check" verified nothing (a .ts stub that no test loads), matching a session-wide pattern of checks written against what should be true rather than what would break. - Split the non-main() code into velox-gui-lib (STATIC) so tests link the real widgets/models, not a reimplementation. - tst_rtl: builds the real MainWindow, flips layoutDirection, asserts the direction propagates to the central widget AND that the offline-banner QHBoxLayout actually mirrors (label x-position LTR vs RTL differs by >100px). Verified it fails when the banner is pinned LtR. - gui_no_download_logic: a ctest that greps gui/src for curl_*/pwrite/ sqlite/QSqlDatabase/QNetworkAccessManager and fails on a hit — CLAUDE.md §3 as an executable check. Verified it fails when a curl_ token is added. - Still uncovered (noted, not claimed): that the translation catalogue loads and the right context/strings resolve at runtime. Not covered here because the files are PKG/QA-owned: tools/bootstrap.sh ships a package name that does not exist on 26.04 (libqt6svg6-dev; the real one is qt6-svg-dev), and --check validates pkg-config outcomes rather than the apt names it would install. Both, plus the same name in AGENT-PKG-QA.md and the README, are written up apply-ready in gui/docs/pkg-qa-requests-m1.md. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Ne28kx4VreeBWZv82Nksd
This commit is contained in:
@@ -1,22 +1,44 @@
|
||||
# GUI unit tests. Lane GUI.
|
||||
#
|
||||
# CLAUDE.md §5: a feature with no test does not exist. The model is the piece with real
|
||||
# logic that can be tested headless — the progress patch must be a narrow dataChanged and
|
||||
# must never reset the model (docs/03-gui-spec.md §1).
|
||||
# CLAUDE.md §5: a feature with no test does not exist. Each test below has a concrete
|
||||
# failure it catches — that is the bar, not "it runs green".
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Test)
|
||||
|
||||
# tst_downloadtablemodel — the model's logic, headless.
|
||||
# Red when: a progress patch widens past the value columns, a reset slips into
|
||||
# applyProgress, applyProgress starts synthesizing rows for unknown ids, or add/remove
|
||||
# stops emitting rowsInserted/rowsRemoved.
|
||||
add_executable(tst_downloadtablemodel
|
||||
tst_downloadtablemodel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/models/DownloadTableModel.cpp
|
||||
)
|
||||
|
||||
target_include_directories(tst_downloadtablemodel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src)
|
||||
target_compile_features(tst_downloadtablemodel PRIVATE cxx_std_23)
|
||||
target_compile_options(tst_downloadtablemodel PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
target_link_libraries(tst_downloadtablemodel PRIVATE Qt6::Core Qt6::Test)
|
||||
|
||||
add_test(NAME gui_downloadtablemodel COMMAND tst_downloadtablemodel)
|
||||
set_tests_properties(gui_downloadtablemodel PROPERTIES LABELS "gui")
|
||||
|
||||
# tst_rtl — the real RTL check the GUI DoD asks for (the .ts stub alone verifies nothing).
|
||||
# Red when: the main window stops propagating Qt::RightToLeft to its children, or the
|
||||
# offline-banner layout is pinned so it does not mirror under RTL.
|
||||
add_executable(tst_rtl tst_rtl.cpp)
|
||||
target_compile_features(tst_rtl PRIVATE cxx_std_23)
|
||||
target_compile_options(tst_rtl PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
target_link_libraries(tst_rtl PRIVATE velox-gui-lib Qt6::Widgets Qt6::Test)
|
||||
add_test(NAME gui_rtl COMMAND tst_rtl)
|
||||
set_tests_properties(gui_rtl PROPERTIES
|
||||
LABELS "gui"
|
||||
ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
|
||||
|
||||
# gui_no_download_logic — CLAUDE.md §3 as an executable check, not a hope.
|
||||
# Red when: a download-logic token (curl, raw pwrite, sqlite, QSqlDatabase) appears
|
||||
# under gui/src. grep exits 0 only when it finds a match, so a hit fails the test.
|
||||
add_test(NAME gui_no_download_logic
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DGUI_SRC=${CMAKE_CURRENT_SOURCE_DIR}/../src
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/no_download_logic.cmake)
|
||||
set_tests_properties(gui_no_download_logic PROPERTIES LABELS "gui")
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Fails if any download-logic token appears under gui/src. Run as a ctest (see
|
||||
# tests/CMakeLists.txt). CLAUDE.md §3: "A grep for curl|pwrite|sqlite in gui/ must come
|
||||
# back empty."
|
||||
#
|
||||
# Invoked with -DGUI_SRC=<abs path to gui/src>.
|
||||
|
||||
if(NOT DEFINED GUI_SRC)
|
||||
message(FATAL_ERROR "GUI_SRC not set")
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE sources "${GUI_SRC}/*.cpp" "${GUI_SRC}/*.hpp")
|
||||
|
||||
# Word-ish boundaries so this file's own prose and e.g. "curly" do not trip it, and so a
|
||||
# comment mentioning the rule is fine but a real call is not.
|
||||
set(forbidden
|
||||
"curl_[a-z_]+" # libcurl
|
||||
"\\bpwrite\\b" # raw positioned writes — the transfer path, not the GUI
|
||||
"sqlite3?_[a-z_]+" # sqlite C API
|
||||
"QSqlDatabase" # or via Qt
|
||||
"QNetworkAccessManager" # the GUI talks to the daemon over QLocalSocket, nothing else
|
||||
)
|
||||
|
||||
set(hits "")
|
||||
foreach(file ${sources})
|
||||
file(STRINGS "${file}" matched REGEX "(curl_[a-z_]+|\\bpwrite\\b|sqlite3?_[a-z_]+|QSqlDatabase|QNetworkAccessManager)")
|
||||
foreach(line ${matched})
|
||||
string(STRIP "${line}" line)
|
||||
list(APPEND hits "${file}: ${line}")
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
list(LENGTH hits n)
|
||||
if(n GREATER 0)
|
||||
string(REPLACE ";" "\n " pretty "${hits}")
|
||||
message(FATAL_ERROR
|
||||
"download-logic token(s) found under gui/src — CLAUDE.md §3:\n ${pretty}")
|
||||
endif()
|
||||
|
||||
message(STATUS "gui/src is clean of download-logic tokens (${forbidden})")
|
||||
@@ -0,0 +1,70 @@
|
||||
// RTL layout test. Lane GUI.
|
||||
//
|
||||
// The GUI DoD asks for "a stub Arabic .ts proves the RTL layout survives". A .ts file on
|
||||
// its own proves nothing — this is the check with teeth: build the real main window, flip
|
||||
// the layout direction, and assert (a) the direction propagates to the children and
|
||||
// (b) a layout we own actually mirrors, by comparing a widget's position LTR vs RTL.
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QtTest>
|
||||
|
||||
#include "mainwindow/MainWindow.hpp"
|
||||
#include "rpc/RpcClient.hpp"
|
||||
|
||||
using velox::gui::MainWindow;
|
||||
|
||||
namespace {
|
||||
|
||||
int settledLeftOf(QWidget *w) {
|
||||
QCoreApplication::processEvents();
|
||||
QTest::qWait(30);
|
||||
QCoreApplication::processEvents();
|
||||
return w->mapTo(w->window(), QPoint(0, 0)).x();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class TstRtl : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void directionPropagatesAndLayoutMirrors();
|
||||
};
|
||||
|
||||
void TstRtl::directionPropagatesAndLayoutMirrors() {
|
||||
velox::gui::rpc::RpcClient client(QStringLiteral("/nonexistent/velox-rtl-test.sock"));
|
||||
MainWindow window(&client); // never started — the window must build without a daemon
|
||||
window.resize(900, 500);
|
||||
|
||||
window.setLayoutDirection(Qt::LeftToRight);
|
||||
window.show();
|
||||
|
||||
auto *bannerLabel = window.findChild<QLabel *>(QStringLiteral("offlineBannerLabel"));
|
||||
QVERIFY2(bannerLabel != nullptr, "offline banner label not found");
|
||||
QVERIFY2(bannerLabel->isVisible(), "offline banner should be visible while disconnected");
|
||||
|
||||
const int leftLtr = settledLeftOf(bannerLabel);
|
||||
|
||||
window.setLayoutDirection(Qt::RightToLeft);
|
||||
|
||||
// Propagation: the window and its central widget must both flip.
|
||||
QCOMPARE(window.layoutDirection(), Qt::RightToLeft);
|
||||
QVERIFY2(window.centralWidget() != nullptr, "no central widget");
|
||||
QCOMPARE(window.centralWidget()->layoutDirection(), Qt::RightToLeft);
|
||||
|
||||
const int leftRtl = settledLeftOf(bannerLabel);
|
||||
|
||||
// The banner is [label][stretch] in a QHBoxLayout we build ourselves. LTR pins the
|
||||
// label near x=0; RTL must push it to the right by (roughly) the free space. If the
|
||||
// layout ignored direction this delta would be ~0.
|
||||
QVERIFY2(leftRtl - leftLtr > 100,
|
||||
qPrintable(QStringLiteral("offline banner did not mirror under RTL: "
|
||||
"label x LTR=%1 RTL=%2")
|
||||
.arg(leftLtr)
|
||||
.arg(leftRtl)));
|
||||
}
|
||||
|
||||
QTEST_MAIN(TstRtl)
|
||||
#include "tst_rtl.moc"
|
||||
Reference in New Issue
Block a user