tests: add test for the BT/BLE address recognition

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-09-24 17:24:15 -07:00
parent 0cfd76740b
commit c6b62cbe5c
3 changed files with 42 additions and 0 deletions

View file

@ -92,6 +92,7 @@ TEST(TestUnitConversion testunitconversion.cpp)
TEST(TestProfile testprofile.cpp)
TEST(TestGpsCoords testgpscoords.cpp)
TEST(TestParse testparse.cpp)
TEST(TestHelper testhelper.cpp)
TEST(TestParsePerformance testparseperformance.cpp)
TEST(TestPlan testplan.cpp)
TEST(TestDiveSiteDuplication testdivesiteduplication.cpp)

26
tests/testhelper.cpp Normal file
View file

@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-2.0
#include "testhelper.h"
#include "core/btdiscovery.h"
void TestHelper::initTestCase()
{
/* we need to manually tell that the resource exists, because we are using it as library. */
Q_INIT_RESOURCE(subsurface);
}
void TestHelper::recognizeBtAddress()
{
QCOMPARE(isBluetoothAddress("01:a2:b3:c4:d5:06"), true);
QCOMPARE(isBluetoothAddress("LE:01:A2:B3:C4:D5:06"), true);
QCOMPARE(isBluetoothAddress("01:A2:b3:04:05"), false);
QCOMPARE(isBluetoothAddress("LE:01:02:03:04:05"), false);
QCOMPARE(isBluetoothAddress("01:02:03:04:051:67"), false);
QCOMPARE(isBluetoothAddress("LE:01:g2:03:04:05"), false);
QCOMPARE(isBluetoothAddress("LE:{6e50ff5d-cdd3-4c43-a80a-1ed4c7d2d2a5}"), true);
QCOMPARE(isBluetoothAddress("LE:{6e5ff5d-cdd3-4c43-a80a-1ed4c7d2d2a5}"), false);
QCOMPARE(isBluetoothAddress("LE:{6e50ff5d-cdda33-4c43-a80a-1ed4c7d2d2a5}"), false);
QCOMPARE(isBluetoothAddress("LE:{6e50ff5d-cdd3-4c43-1ed4c7d2d2a5}"), false);
QCOMPARE(isBluetoothAddress("LE:{6e50ff5d-cdd3-4c43-ag0a-1ed4c7d2d2a5}"), false);
}
QTEST_GUILESS_MAIN(TestHelper)

15
tests/testhelper.h Normal file
View file

@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-2.0
#ifndef TESTPARSE_H
#define TESTPARSE_H
#include <QtTest>
#include <sqlite3.h>
class TestHelper : public QObject {
Q_OBJECT
private slots:
void initTestCase();
void recognizeBtAddress();
};
#endif