From c8fec97695cc2f71b59f3d8979b4203aefc6e6db Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 27 Sep 2018 06:21:04 -0700 Subject: Bluetooth: add helper to separate BT name and address And restructure the existing "isBtAddress()" function in the process. Also add more tests. Signed-off-by: Dirk Hohndel --- tests/testhelper.cpp | 18 ++++++++++++++++++ tests/testhelper.h | 1 + 2 files changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/testhelper.cpp b/tests/testhelper.cpp index 6d15ad3c4..83cd3176d 100644 --- a/tests/testhelper.cpp +++ b/tests/testhelper.cpp @@ -23,4 +23,22 @@ void TestHelper::recognizeBtAddress() QCOMPARE(isBluetoothAddress("LE:{6e50ff5d-cdd3-4c43-ag0a-1ed4c7d2d2a5}"), false); } +void TestHelper::parseNameAddress() +{ + QString name, address; + address = extractBluetoothNameAddress("01:a2:b3:c4:d5:06", name); + QCOMPARE(address, "01:a2:b3:c4:d5:06"); + QCOMPARE(name, QString()); + address = extractBluetoothNameAddress("somename (01:a2:b3:c4:d5:06)", name); + QCOMPARE(address, "01:a2:b3:c4:d5:06"); + QCOMPARE(name, QString("somename")); + address = extractBluetoothNameAddress("garbage", name); + QCOMPARE(address, QString()); + QCOMPARE(name, QString()); + address = extractBluetoothNameAddress("somename (LE:{6e50ff5d-cdd3-4c43-a80a-1ed4c7d2d2a5})", name); + QCOMPARE(address, "LE:{6e50ff5d-cdd3-4c43-a80a-1ed4c7d2d2a5}"); + QCOMPARE(name, QString("somename")); + +} + QTEST_GUILESS_MAIN(TestHelper) diff --git a/tests/testhelper.h b/tests/testhelper.h index e6af513dc..00a187c6f 100644 --- a/tests/testhelper.h +++ b/tests/testhelper.h @@ -10,6 +10,7 @@ class TestHelper : public QObject { private slots: void initTestCase(); void recognizeBtAddress(); + void parseNameAddress(); }; #endif -- cgit v1.2.3-70-g09d2