#include #include #include "AudioTests.h" #include "AudioClient.h" #include "DependencyManager.h" #include "NodeList.h" #include "plugins/CodecPlugin.h" #include "plugins/PluginManager.h" QTEST_MAIN(AudioTests) Q_DECLARE_METATYPE(QList) void AudioTests::initTestCase() { // AudioClient starts networking, but for the purposes of the tests here we don't care, // so just got to use some port. int listenPort = 10000; DependencyManager::registerInheritance(); DependencyManager::set(NodeType::Agent, listenPort); DependencyManager::set(); DependencyManager::set(); QSharedPointer ac = DependencyManager::get(); qRegisterMetaType>(); ac->startThread(); } void AudioTests::listAudioDevices() { QSharedPointer ac = DependencyManager::get(); QVERIFY(!ac.isNull()); /* // AudioClient::devicesChanged is declared as: // void devicesChanged(QAudio::Mode mode, const QList& devices); // // Unfortunately with QSignalSpy we have to use the old SIGNAL() syntax, so it was a bit tricky // to figure out how to get the signal to connect. The snippet below lists signals in the format // that Qt understands. Turns out we lose the 'const &'. const QMetaObject *mo = ac->metaObject(); QList signalSignatures; // Start from MyClass members for(int methodIdx = mo->methodOffset(); methodIdx < mo->methodCount(); ++methodIdx) { QMetaMethod mmTest = mo->method(methodIdx); switch((int)mmTest.methodType()) { case QMetaMethod::Signal: signalSignatures.append(QString(mmTest.methodSignature())); qDebug() << "SIG: " << QString(mmTest.methodSignature()); break; } } */ QSignalSpy spy(ac.get(), SIGNAL(devicesChanged(QAudio::Mode,QList))); QVERIFY(spy.isValid()); // This checks that the signal has connected spy.wait(15000); // We always get two events here, one for audio input, and one for output, // but signals keep coming and we could potentially get more repetitions. QVERIFY(spy.count() > 0); qDebug() << "Received" << spy.count() << "device events"; // QSignalSpy is a QList, which stores the received signals. We can then examine it to see // what we got. for(auto event : spy) { QAudio::Mode mode = qvariant_cast(event.at(0)); QList devs = qvariant_cast>(event.at(1)); QVERIFY(devs.count() > 0); qDebug() << "Mode:" << mode; for(auto dev : devs) { qDebug() << "\t" << dev.deviceName(); } } }