File indexing completed on 2024-02-25 03:57:00

0001 /*
0002  * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #include "leadvertisingmanagertest.h"
0008 #include "autotests.h"
0009 #include "initmanagerjob.h"
0010 #include "leadvertisingmanager.h"
0011 #include "manager.h"
0012 #include "pendingcall.h"
0013 
0014 #include <QDBusObjectPath>
0015 
0016 namespace BluezQt
0017 {
0018 extern void bluezqt_initFakeBluezTestRun();
0019 }
0020 
0021 using namespace BluezQt;
0022 
0023 void TestAdvertisement::release()
0024 {
0025     m_releaseCalled = true;
0026 }
0027 
0028 void LEAdvertisingManagerTest::initTestCase()
0029 {
0030     bluezqt_initFakeBluezTestRun();
0031     FakeBluez::start();
0032     FakeBluez::runTest(QStringLiteral("bluez-standard"));
0033 
0034     // Create adapter
0035     QString adapter = QStringLiteral("/org/bluez/hci0");
0036     QVariantMap adapterProps;
0037     adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter));
0038     adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E");
0039     adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter");
0040     FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps);
0041 
0042     Manager *manager = new Manager(this);
0043     InitManagerJob *initJob = manager->init();
0044     initJob->exec();
0045     QVERIFY(!initJob->error());
0046     QCOMPARE(manager->adapters().count(), 1);
0047 
0048     m_adapter = manager->adapters().at(0);
0049     QVERIFY(m_adapter->leAdvertisingManager());
0050 
0051     m_advertisement = new TestAdvertisement({QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1")}, this);
0052     auto call = m_adapter->leAdvertisingManager()->registerAdvertisement(m_advertisement);
0053     call->waitForFinished();
0054     QVERIFY(!call->error());
0055 }
0056 
0057 void LEAdvertisingManagerTest::cleanupTestCase()
0058 {
0059     FakeBluez::stop();
0060 }
0061 
0062 void LEAdvertisingManagerTest::releaseTest()
0063 {
0064     QCOMPARE(m_advertisement->m_releaseCalled, false);
0065 
0066     QVariantMap params;
0067     params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi())));
0068     FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-leadvertisingmanager:release"), params);
0069 
0070     QTRY_COMPARE(m_advertisement->m_releaseCalled, true);
0071 }
0072 
0073 QTEST_MAIN(LEAdvertisingManagerTest)
0074 
0075 #include "moc_leadvertisingmanagertest.cpp"