diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index f542907c669..48d6d0633b6 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -20,6 +20,7 @@ if(client) # For some reason Qt segfaults when executing this test on FreeBSD without a display (even when using the offscreen plugin) use_test("TestSettingsJSONSerialization") endif() + use_test("OverlayTest") endif() if(server) diff --git a/src/tests/OverlayTest/CMakeLists.txt b/src/tests/OverlayTest/CMakeLists.txt new file mode 100644 index 00000000000..c47fa6a2c57 --- /dev/null +++ b/src/tests/OverlayTest/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright 2020-2022 The Mumble Developers. All rights reserved. +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file at the root of the +# Mumble source tree or at . + +add_executable(OverlayTest OverlayTest.cpp) + +set_target_properties(OverlayTest PROPERTIES AUTOMOC ON) + +find_pkg(Qt5 COMPONENTS Gui Widgets REQUIRED) + +target_link_libraries(OverlayTest PRIVATE mumble_client_object_lib) +target_link_libraries(OverlayTest PRIVATE shared Qt5::Test Qt5::Widgets) + +add_test(NAME OverlayTest COMMAND $) + +# OverlayTest is disabled because it can only be tested by humans checking that the application is correctly displaying the overlay +set_tests_properties(OverlayTest PROPERTIES DISABLED TRUE) diff --git a/src/tests/OverlayTest/OverlayTest.cpp b/src/tests/OverlayTest/OverlayTest.cpp index 8d8e8e4a732..012c8c249c7 100644 --- a/src/tests/OverlayTest/OverlayTest.cpp +++ b/src/tests/OverlayTest/OverlayTest.cpp @@ -21,7 +21,10 @@ #include #include -#include +#include +#include +#include + class OverlayWidget : public QWidget { Q_OBJECT @@ -33,7 +36,7 @@ class OverlayWidget : public QWidget { SharedMemory2 *smMem; QTimer *qtTimer; QRect qrActive; - QTime qtWall; + QElapsedTimer qtWall; unsigned int iFrameCount; int iLastFpsUpdate; @@ -185,7 +188,6 @@ void OverlayWidget::error(QLocalSocket::LocalSocketError) { void OverlayWidget::update() { ++iFrameCount; - clock_t t = clock(); float elapsed = static_cast< float >(qtWall.elapsed() - iLastFpsUpdate) / 1000.0f; if (elapsed > OVERLAY_FPS_INTERVAL) { @@ -216,12 +218,12 @@ void OverlayWidget::readyRead() { int ready = qlsSocket->bytesAvailable(); if (om.omh.iLength == -1) { - if (ready < sizeof(OverlayMsgHeader)) + if ((size_t)ready < sizeof(OverlayMsgHeader)) break; else { qlsSocket->read(reinterpret_cast< char * >(om.headerbuffer), sizeof(OverlayMsgHeader)); if ((om.omh.uiMagic != OVERLAY_MAGIC_NUMBER) || (om.omh.iLength < 0) - || (om.omh.iLength > sizeof(OverlayMsgShmem))) { + || ((size_t)om.omh.iLength > sizeof(OverlayMsgShmem))) { detach(); return; } @@ -264,11 +266,12 @@ void OverlayWidget::readyRead() { if (!smMem) break; - if (((omb->x + omb->w) > img.width()) || ((omb->y + omb->h) > img.height())) + if (((omb->x + omb->w) > (unsigned int)img.width()) + || ((omb->y + omb->h) > (unsigned int)img.height())) break; - for (int y = 0; y < omb->h; ++y) { + for (unsigned int y = 0; y < omb->h; ++y) { unsigned char *src = reinterpret_cast< unsigned char * >(smMem->data()) + 4 * (width() * (y + omb->y) + omb->x); unsigned char *dst = img.scanLine(y + omb->y) + omb->x * 4;