diff --git a/CMakeLists.txt b/CMakeLists.txt index a8a490d..cb9fb97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,24 @@ target_link_libraries(checkmate_core PUBLIC Qt6::Core Qt6::Gui Qt6::Network Qt6::Qml Qt6::Quick Qt6::QuickControls2 Qt6::DBus Qt6::Quick3D Qt6::Concurrent) target_compile_options(checkmate_core PUBLIC -Wall -Wextra) +# The version comes from the release, never from the code: a tag's tarball +# unpacks as checkmate-, and a checkout asks git. +get_filename_component(source_dir_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME) +if(source_dir_name MATCHES "^checkmate-([0-9][0-9.]*)$") + set(CHECKMATE_VERSION "${CMAKE_MATCH_1}") +else() + execute_process(COMMAND git describe --tags --always --dirty + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE CHECKMATE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + string(REGEX REPLACE "^v" "" CHECKMATE_VERSION "${CHECKMATE_VERSION}") + if(NOT CHECKMATE_VERSION) + set(CHECKMATE_VERSION dev) + endif() +endif() + add_executable(checkmate src/main.cpp src/resources.qrc) target_link_libraries(checkmate PRIVATE checkmate_core) +target_compile_definitions(checkmate PRIVATE CHECKMATE_VERSION="${CHECKMATE_VERSION}") # The tests load the real Main.qml, so they carry the resources too. enable_testing() @@ -33,6 +49,12 @@ find_program(XVFB_RUN xvfb-run REQUIRED) add_test(NAME checkmate_tests COMMAND ${XVFB_RUN} -a $) set_tests_properties(checkmate_tests PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QUICK_BACKEND=rhi;QSG_RHI_BACKEND=opengl;LIBGL_ALWAYS_SOFTWARE=1") +# --version answers without a display. A checkout without tags reports git's commit or "dev" rather than a number. +add_test(NAME checkmate_version_without_display + COMMAND ${CMAKE_COMMAND} -E env --unset=QT_QPA_PLATFORM --unset=WAYLAND_DISPLAY --unset=DISPLAY + $ --version) +set_tests_properties(checkmate_version_without_display PROPERTIES PASS_REGULAR_EXPRESSION "^Checkmate [0-9a-z]") + # `cmake --install build --prefix ~/.local` puts the app in the launcher # before it is packaged; a package installs the same files under /usr. include(GNUInstallDirs) diff --git a/src/main.cpp b/src/main.cpp index 990192a..c4cc8a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) { const std::string command = argc > 1 ? argv[1] : "open"; if (command == "--help" || command == "--version") { - std::cout << (command == "--version" ? "Checkmate 0.1.0\n" : "Checkmate — 3D chess\nUsage: checkmate [open | inspect | export | legal [FEN] | --help | --version]\nHeadless commands accept --json. export prints PGN to stdout.\n"); + std::cout << (command == "--version" ? "Checkmate " CHECKMATE_VERSION "\n" : "Checkmate — 3D chess\nUsage: checkmate [open | inspect | export | legal [FEN] | --help | --version]\nHeadless commands accept --json. export prints PGN to stdout.\n"); return 0; } if (command == "inspect" || command == "export" || command == "legal") return runCli(argc,argv); @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) { qmlRegisterType("Checkmate", 1, 0, "SculptGeometry"); qmlRegisterType("Checkmate",1,0,"SurfaceTexture"); app.setApplicationName("checkmate"); - app.setApplicationVersion("0.1.0"); + app.setApplicationVersion(CHECKMATE_VERSION); // Matches the window to checkmate.desktop, so the compositor (Wayland app_id) // and the launcher pick up the installed icon. The compiled-in copy covers diff --git a/tests/checkmate_tests.cpp b/tests/checkmate_tests.cpp index 7adb04d..8a16482 100644 --- a/tests/checkmate_tests.cpp +++ b/tests/checkmate_tests.cpp @@ -834,14 +834,20 @@ private slots: QTest::qWait(150); for (int set=0;set<4;++set) { backend.setPieceSet(set); - QTest::qWait(60); - for (float x : {-4.55f,4.55f}) for (float z : {-4.55f,4.55f}) { - QVector3D point; - QVERIFY(QMetaObject::invokeMethod(view,"mapFrom3DScene",Q_RETURN_ARG(QVector3D,point),Q_ARG(QVector3D,QVector3D(x,0,z)))); - QVERIFY2(point.x()>=0 && point.x()<=board->width() && point.y()>=0 && point.y()<=board->height(), - qPrintable(QString("set %1 at %2x%3: corner %4,%5 lands at %6,%7").arg(set).arg(size.width()).arg(size.height()) - .arg(x).arg(z).arg(point.x()).arg(point.y()))); - } + // The view answers from the last frame it drew, and a slow renderer takes its time over one. + QString stray; + auto framed=[&] { + stray.clear(); + for (float x : {-4.55f,4.55f}) for (float z : {-4.55f,4.55f}) { + QVector3D point; + if (!QMetaObject::invokeMethod(view,"mapFrom3DScene",Q_RETURN_ARG(QVector3D,point),Q_ARG(QVector3D,QVector3D(x,0,z)))) return false; + if (point.x()<0 || point.x()>board->width() || point.y()<0 || point.y()>board->height()) + stray=QString("set %1 at %2x%3: corner %4,%5 lands at %6,%7").arg(set).arg(size.width()).arg(size.height()) + .arg(x).arg(z).arg(point.x()).arg(point.y()); + } + return stray.isEmpty(); + }; + QTRY_VERIFY2_WITH_TIMEOUT(framed(),qPrintable(stray),10000); } } backend.setPieceSet(0); @@ -933,14 +939,15 @@ private slots: auto *pawn=window->findChild("figure-20"); QVERIFY(pawn); QVERIFY(backend.move(12,28)); - QTest::qWait(160); - QVERIFY(pawn->property("lift").toDouble()>0); - QVERIFY(pawn->property("z").toDouble()>.5); - QVERIFY(pawn->property("z").toDouble()<2.5); + // A slow renderer may draw the whole journey in a frame or two, so nothing is sampled in mid-air: + // the journey has started, it is aimed up the board, and it ends on the square. + QVERIFY(pawn->findChild("leap")->property("running").toBool()); + QVERIFY(qAbs(pawn->property("leanZ").toDouble())>.9); + QTRY_VERIFY_WITH_TIMEOUT(qFuzzyCompare(pawn->property("z").toFloat(),.5f),5000); backend.undo(); // Quick 3D coordinates use float precision, including the final animation setter. - QTRY_VERIFY_WITH_TIMEOUT(qFuzzyCompare(pawn->property("z").toFloat(),2.5f),1500); - QTRY_COMPARE_WITH_TIMEOUT(pawn->property("lift").toDouble(),0.0,1500); + QTRY_VERIFY_WITH_TIMEOUT(qFuzzyCompare(pawn->property("z").toFloat(),2.5f),8000); + QTRY_COMPARE_WITH_TIMEOUT(pawn->property("lift").toDouble(),0.0,8000); auto *leap=pawn->findChild("leap"); auto *perk=pawn->findChild("perk"); QVERIFY(leap && perk); @@ -970,16 +977,16 @@ private slots: pawn->setProperty("wiggle",8.0); QVERIFY(backend.move(12,28)); QVERIFY(leap->property("running").toBool()); - QTRY_VERIFY(qAbs(pawn->property("lean").toDouble())>2); - QVERIFY(pawn->property("lift").toDouble()>0); + QVERIFY(qAbs(pawn->property("leanZ").toDouble())>.9); + QVERIFY(leap->property("height").toDouble()>0); // A captured piece waits for its captor, then goes. QVERIFY(backend.move(51,35)); auto *taken=window->findChild("figure-"+QString::number(backend.position().board[35].id)); QVERIFY(taken); QVERIFY(backend.move(28,35)); QCOMPARE(taken->property("presence").toDouble(),1.0); - QTRY_COMPARE_WITH_TIMEOUT(taken->property("presence").toDouble(),0.0,2500); - QTRY_VERIFY_WITH_TIMEOUT(!leap->property("running").toBool(),2500); + QTRY_COMPARE_WITH_TIMEOUT(taken->property("presence").toDouble(),0.0,8000); + QTRY_VERIFY_WITH_TIMEOUT(!leap->property("running").toBool(),8000); QCOMPARE(pawn->property("lean").toDouble(),0.0); QCOMPARE(pawn->property("stretch").toDouble(),1.0); QCOMPARE(pawn->property("lift").toDouble(),0.0); @@ -1014,8 +1021,8 @@ private slots: QTRY_VERIFY(qAbs(neighbour->property("look").toDouble())>5); QVERIFY(backend.move(12,28)); QVERIFY(leap->property("running").toBool()); - QTRY_VERIFY(qAbs(pawn->property("lean").toDouble())>2); - QVERIFY(pawn->property("lift").toDouble()>0); + QVERIFY(qAbs(pawn->property("leanZ").toDouble())>.9); + QVERIFY(leap->property("height").toDouble()>0); QTRY_VERIFY_WITH_TIMEOUT(!leap->property("running").toBool(),2000); QVERIFY(qFuzzyCompare(pawn->property("z").toFloat(),.5f)); QCOMPARE(pawn->property("lean").toDouble(),0.0);