Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119// SPDX-License-Identifier: GPL-3.0-or-later#include "app/editor/soundstab.h"#include "app/state.h"
#include <QApplication>#include <QDir>#include <QFile>#include <QMessageBox>#include <QPushButton>#include <QTemporaryDir>#include <QTest>#include <QTimer>#include <QTreeWidget>
using namespace xpl;
class TestSoundsTab : public QObject{ Q_OBJECT QTemporaryDir m_home; QByteArray m_path;
void write(const QString &name, const QByteArray &bytes, bool executable = false) { QFile file(m_home.filePath(name)); QVERIFY(file.open(QIODevice::WriteOnly)); QCOMPARE(file.write(bytes), bytes.size()); file.close(); if (executable) QVERIFY(file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)); }
QPushButton *selectSound(editor::SoundsTab &tab) { auto *events = tab.findChild<QTreeWidget *>(); events->setCurrentItem(events->topLevelItem(0)->child(0)); return tab.findChild<QPushButton *>(QStringLiteral("soundPreview")); }
private Q_SLOTS: void initTestCase() { QVERIFY(m_home.isValid()); qputenv("HOME", m_home.path().toUtf8()); m_path = qgetenv("PATH"); qputenv("PATH", m_home.path().toUtf8()); write(QStringLiteral("sound with spaces.wav"), "fixture"); State state; sounds::Scheme scheme{QStringLiteral("Test"), {{sounds::events().first().key, m_home.filePath(QStringLiteral("sound with spaces.wav"))}}}; state.settings.insert(QStringLiteral("sounds"), scheme.toJson()); QVERIFY(state.save()); }
void cleanupTestCase() { qputenv("PATH", m_path); }
void fallback_data() { QTest::addColumn<QByteArray>("firstPlayer"); QTest::newRow("unavailable-server") << QByteArray("#!/bin/sh\necho 'Host is down' >&2\nexit 1\n"); QTest::newRow("cannot-start") << QByteArray("#!/missing/interpreter\n"); }
void fallback() { QFETCH(QByteArray, firstPlayer); QFile::remove(m_home.filePath(QStringLiteral("played"))); write(QStringLiteral("pw-play"), firstPlayer, true); write(QStringLiteral("paplay"), "#!/bin/sh\nprintf '%s' \"$1\" > \"$HOME/played\"\n", true); editor::SoundsTab tab; auto *button = selectSound(tab); QVERIFY(button && button->isEnabled()); button->click(); QTRY_VERIFY(QFile::exists(m_home.filePath(QStringLiteral("played")))); QTRY_COMPARE(button->accessibleName(), QStringLiteral("Play sound")); QFile played(m_home.filePath(QStringLiteral("played"))); QVERIFY(played.open(QIODevice::ReadOnly)); QCOMPARE(played.readAll(), m_home.filePath(QStringLiteral("sound with spaces.wav")).toUtf8()); }
void stopPlayback() { QFile::remove(m_home.filePath(QStringLiteral("played"))); write(QStringLiteral("pw-play"), "#!/bin/sh\nexec /bin/sleep 30\n", true); editor::SoundsTab tab; auto *button = selectSound(tab); button->click(); QCOMPARE(button->accessibleName(), QStringLiteral("Stop sound")); button->click(); QCOMPARE(button->accessibleName(), QStringLiteral("Play sound")); QVERIFY(!QFile::exists(m_home.filePath(QStringLiteral("played")))); }
void allPlayersFail() { write(QStringLiteral("pw-play"), "#!/bin/sh\necho 'no PipeWire server' >&2\nexit 1\n", true); write(QStringLiteral("paplay"), "#!/bin/sh\necho 'no PulseAudio server' >&2\nexit 1\n", true); editor::SoundsTab tab; auto *button = selectSound(tab); QString message; QTimer dismiss; connect(&dismiss, &QTimer::timeout, this, [&] { for (QWidget *widget : QApplication::topLevelWidgets()) if (auto *box = qobject_cast<QMessageBox *>(widget)) { message = box->text(); box->accept(); } }); dismiss.start(10); button->click(); QTRY_VERIFY(!message.isEmpty()); QVERIFY(message.contains(QStringLiteral("no PipeWire server"))); QVERIFY(message.contains(QStringLiteral("no PulseAudio server"))); QCOMPARE(button->accessibleName(), QStringLiteral("Play sound")); }};
QTEST_MAIN(TestSoundsTab)#include "test_soundstab.moc"