/** * @RDE_HEADER@ * AvaCommTest * $Id$ * $HeadURL$ * $Author$ * Created by Christian Fröbel, SLSE, 2017-06-20 */ #include "ava_comm_test.h" #include "ava_test_server.h" #include #include #include #include #include #include #include #include #include using namespace AudioVideoManagement; class AvaCommTest::SignalSpy : public QObject { Q_OBJECT public: SignalSpy(AvaComm *signalSource) { Q_ASSERT(signalSource); connect(signalSource, &AvaComm::ok, this, &SignalSpy::onOk); connect(signalSource, &AvaComm::connected, this, &SignalSpy::onConnected); connect(signalSource, &AvaComm::streamListBeginReceived, this, &SignalSpy::onStreamListBeginReceived); connect(signalSource, &AvaComm::timelineListBeginReceived, this, &SignalSpy::onTimelineListBeginReceived); connect(signalSource, &AvaComm::elokaListBeginReceived, this, &SignalSpy::onElokaListBeginReceived); connect(signalSource, &AvaComm::listValueReceived, this, &SignalSpy::onListValueReceived); connect(signalSource, &AvaComm::endOfListReceived, this, &SignalSpy::onEndOfListReceived); connect(signalSource, &AvaComm::streamStateReceived, this, &SignalSpy::onStreamStateReceived); connect(signalSource, &AvaComm::streamInfoReceived, this, &SignalSpy::onStreamInfoReceived); } void reset() { m_connected = false; m_ok = false; m_streamListBegin = false; m_timelineListBegin = false; m_elokaListBegin = false; m_endOfList = false; m_listValues.clear(); m_streamState.reset(); m_streamInfo.reset(); } public slots: void onConnected() { m_connected = true; } void onOk() { m_ok = true; } void onStreamListBeginReceived() { m_streamListBegin = true; } void onTimelineListBeginReceived() { m_timelineListBegin = true; } void onElokaListBeginReceived() { m_elokaListBegin = true; } void onListValueReceived(const QVector &parts) { m_listValues.append(parts); } void onEndOfListReceived() { m_endOfList = true; } void onStreamStateReceived(const QString &dialogId, const QString &streamName, AvaStreamState streamState) { Q_UNUSED(dialogId); Q_UNUSED(streamName); m_streamState = streamState; } void onStreamInfoReceived(const QString &dialogId, const QString &streamName, const AvaStreamInfo &streamInfo) { Q_UNUSED(dialogId); Q_UNUSED(streamName); m_streamInfo = streamInfo; } public: bool m_connected{false}; bool m_ok{false}; bool m_streamListBegin{false}; bool m_timelineListBegin{false}; bool m_elokaListBegin{false}; bool m_endOfList{false}; QVector> m_listValues; boost::optional m_streamState; boost::optional m_streamInfo; }; AvaCommTest::AvaCommTest() = default; AvaCommTest::~AvaCommTest() = default; void AvaCommTest::initTestCase() { m_fakeAvaServer.reset(new AvaTestServer); } void AvaCommTest::cleanupTestCase() { m_fakeAvaServer.reset(); } void AvaCommTest::init() { m_avaComm.reset(new AvaComm(QStringLiteral("localhost"), 6370)); m_spy.reset(new SignalSpy(m_avaComm.get())); m_avaComm->start(); } void AvaCommTest::cleanup() { m_spy.reset(); m_avaComm.reset(); } void AvaCommTest::testSwitchContext() { const int EXERCISE = 42; QTRY_VERIFY(m_spy->m_connected); m_avaComm->switchContext(EXERCISE); QTRY_VERIFY(m_spy->m_ok); } void AvaCommTest::testSetUserProfile() { QTRY_VERIFY(m_spy->m_connected); m_avaComm->setUserProfile(QStringLiteral("ctc"), QStringLiteral("en_US"), AvaAudioPrio(1), AvaGuiStyle::Light); QTRY_VERIFY(m_spy->m_ok); } void AvaCommTest::testSetVideoDialogProfile() { // The real server needs a user profile before setVideoDialogProfile can be issued. testSetUserProfile(); m_spy->reset(); m_avaComm->setVideoDialogProfile(AvsDialog::VIDEO_1, AvaVisibility::Hidden); QTRY_VERIFY(m_spy->m_ok); } void AvaCommTest::testGetStreamList() { // The real server needs a context before getStreamList actually returns some streams. testSwitchContext(); m_spy->reset(); m_avaComm->getStreamList(AvaStreamType::Video, AvaStreamSource::Server); QTRY_VERIFY(m_spy->m_endOfList); QVERIFY(m_spy->m_streamListBegin); QCOMPARE(m_spy->m_listValues.size(), 5); // sample check const QVector expected = {"2", "2", u8"Videöäü 50-5(S)"}; QCOMPARE(m_spy->m_listValues.at(1), expected); } void AvaCommTest::testChooseStream() { // The real server needs a context and a user profile before chooseStream can be issued. login(); m_spy->reset(); const bool notMuted = false; m_avaComm->chooseStream(AvsDialog::VIDEO_1, QStringLiteral("Video 52-1(S)"), notMuted); QTRY_VERIFY(m_spy->m_ok); QTRY_VERIFY(m_spy->m_streamState && *m_spy->m_streamState == AvaStreamState::Stop); QTRY_VERIFY(m_spy->m_streamInfo); const AvaStreamInfo& actual = *m_spy->m_streamInfo; QCOMPARE(actual.start, AvaTimePoint(AvaDuration{125551541486})); QCOMPARE(actual.end, AvaTimePoint(AvaDuration{125563407789})); QCOMPARE(actual.duration, AvaDuration{11866303}); } void AvaCommTest::testQueryTimeline() { // The real server needs a context and a user profile before queryTimeline can be issued. login(); m_spy->reset(); m_avaComm->queryTimeline(QStringLiteral("Video 52-1(S)")); QTRY_VERIFY(m_spy->m_ok); QTRY_VERIFY(m_spy->m_endOfList); QVERIFY(m_spy->m_timelineListBegin); QCOMPARE(m_spy->m_listValues.size(), 2); QVector> expected = {{"1499415421.77-1499416659.03"}, {"1499417373.77-1499417842.06"}}; QCOMPARE(m_spy->m_listValues, expected); } void AvaCommTest::testGetElokaList() { // The real server needs a context before getStreamList actually returns some streams. testSwitchContext(); m_spy->reset(); m_avaComm->getElokaList(QStringLiteral("TrSpFuKr12")); QTRY_VERIFY(m_spy->m_ok); QTRY_VERIFY(m_spy->m_endOfList); QVERIFY(m_spy->m_elokaListBegin); QCOMPARE(m_spy->m_listValues.size(), 2); QVector> expected = {{"ELOKA 1"}, {"Eloka 2"}}; QCOMPARE(m_spy->m_listValues, expected); } /** * Login with context and user profile. */ void AvaCommTest::login() { const int EXERCISE = 42; QTRY_VERIFY(m_spy->m_connected); m_avaComm->switchContext(EXERCISE); QTRY_VERIFY(m_spy->m_ok); m_spy->reset(); m_avaComm->setUserProfile(QStringLiteral("ctc"), QStringLiteral("en_US"), AvaAudioPrio(1), AvaGuiStyle::Light); QTRY_VERIFY(m_spy->m_ok); } #include "ava_comm_test.moc"