Skip to content

Commit

Permalink
TEST(overlay): adds build files for OverlayTest
Browse files Browse the repository at this point in the history
adds a test application that connects to MumbleOverlayPipe and displays the overlay as configured.
It's disabled by default as it is designed to be a check for humans
  • Loading branch information
carlocastoldi committed Nov 15, 2022
1 parent bfe53aa commit e90cb73
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions src/tests/OverlayTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <https://www.mumble.info/LICENSE>.

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 $<TARGET_FILE:OverlayTest>)

# 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)
17 changes: 10 additions & 7 deletions src/tests/OverlayTest/OverlayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#include <QtGui>
#include <QtNetwork>

#include <ctime>
#include <QWidget>
#include <QMainWindow>
#include <QApplication>


class OverlayWidget : public QWidget {
Q_OBJECT
Expand All @@ -33,7 +36,7 @@ class OverlayWidget : public QWidget {
SharedMemory2 *smMem;
QTimer *qtTimer;
QRect qrActive;
QTime qtWall;
QElapsedTimer qtWall;

unsigned int iFrameCount;
int iLastFpsUpdate;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e90cb73

Please sign in to comment.