Skip to content

Commit

Permalink
2127 test project updates - support for multiple QBluetoothDeviceInfo…
Browse files Browse the repository at this point in the history
… configuration criteria (#2134)

* #2127 additional tests to cater for bluetooth services that should and shout not be present

* #2127 permanently remove KICKR CORE from FTMSBike2TestData, as it is now handled by FTMSBike4TestData with the BT service criteria too

* #2127 initial support for multiple bluetooth device info configs in tests not quite working properly

* #2172 fixed some test data

* #2127 touch-ups

* #2127 added a guide to writing device detection tests

* #2127 updated test data for Stages bike detection

* #2127 alterations due to proof reading

* #2127 added TACX SATORI to stagesbike detection test to make consistent with documentation

* #2127 change as a result of proof reading
  • Loading branch information
drmason789 authored Feb 17, 2024
1 parent 408ee35 commit df88e7e
Show file tree
Hide file tree
Showing 12 changed files with 587 additions and 124 deletions.
463 changes: 463 additions & 0 deletions docs/50_writing_tests.md

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions tst/Devices/DomyosTreadmill/domyostreadmilltestdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "Devices/FTMSBike/ftmsbiketestdata.h"

DomyosTreadmillTestData::DomyosTreadmillTestData() : TreadmillTestData("Domyos Treadmill") {
this->testInvalidBluetoothDeviceInfo = true;

this->addDeviceName("Domyos", comparison::StartsWith);

this->addInvalidDeviceName("DomyosBr", comparison::StartsWith);
Expand All @@ -37,17 +35,15 @@ bool DomyosTreadmillTestData::get_isExpectedDevice(bluetoothdevice *detectedDevi
}


QBluetoothDeviceInfo DomyosTreadmillTestData::get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid)
{
QBluetoothDeviceInfo result = BluetoothDeviceTestData::get_bluetoothDeviceInfo(uuid, name, true);
void DomyosTreadmillTestData::configureBluetoothDeviceInfos(const QBluetoothDeviceInfo &info, bool enable, std::vector<QBluetoothDeviceInfo> &bluetoothDeviceInfos) const {

if(valid) {
// No 0x1826 service
return result;
}
if(enable) return;

// Should not be created if the 0x1826 service is present
// Should not be identified if it has 0x1826
auto result = info;
result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));
bluetoothDeviceInfos.push_back(result);


return result;
}

4 changes: 2 additions & 2 deletions tst/Devices/DomyosTreadmill/domyostreadmilltestdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


class DomyosTreadmillTestData : public TreadmillTestData {

protected:
void configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const override;
public:
DomyosTreadmillTestData();

Expand All @@ -14,6 +15,5 @@ class DomyosTreadmillTestData : public TreadmillTestData {

bool get_isExpectedDevice(bluetoothdevice * detectedDevice) const override;

QBluetoothDeviceInfo get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true) override;
};

25 changes: 9 additions & 16 deletions tst/Devices/FTMSBike/ftmsbiketestdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,18 @@ class FTMSBike3TestData : public FTMSBikeTestData {
};

class FTMSBike4TestData : public FTMSBikeTestData {
protected:
void configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const override {
auto result = info;
if(enable) {
result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));
}

bluetoothDeviceInfos.push_back(result);
}
public:

FTMSBike4TestData() : FTMSBikeTestData("FTMS KICKR CORE") {
this->testInvalidBluetoothDeviceInfo = true;

this->addDeviceName("KICKR CORE", comparison::StartsWithIgnoreCase); // KICKR CORE
}

QBluetoothDeviceInfo get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true) override
{
QBluetoothDeviceInfo result = BluetoothDeviceTestData::get_bluetoothDeviceInfo(uuid, name, true);

if(!valid) {
// No 0x1826 service
return result;
}

result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));

return result;
}
};
26 changes: 9 additions & 17 deletions tst/Devices/HorizonTreadmill/horizontreadmilltestdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,23 @@ class HorizonTreadmillBodyToneTestData : public TreadmillTestData {


class HorizonTreadmillDomyosTCTestData : public TreadmillTestData {
protected:
void configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const override {
auto result = info;
if(enable) {
result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));
}

bluetoothDeviceInfos.push_back(result);
}
public:
HorizonTreadmillDomyosTCTestData() : TreadmillTestData("Horizon Treadmill (Domyos TC)") {
this->testInvalidBluetoothDeviceInfo = true;

this->addDeviceName("DOMYOS-TC", comparison::StartsWithIgnoreCase);
}

deviceType get_expectedDeviceType() const override { return deviceType::HorizonTreadmill; }

bool get_isExpectedDevice(bluetoothdevice *detectedDevice) const override {
return dynamic_cast<horizontreadmill *>(detectedDevice) != nullptr;
}

QBluetoothDeviceInfo get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true) override
{
QBluetoothDeviceInfo result = BluetoothDeviceTestData::get_bluetoothDeviceInfo(uuid, name, true);

if(!valid) {
// No 0x1826 service
return result;
}

result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));

return result;
}
}
};
12 changes: 7 additions & 5 deletions tst/Devices/M3IBike/m3ibiketestdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ static QByteArray hex2bytes(const std::string& s)
return v;
}

QBluetoothDeviceInfo M3IBikeTestData::get_bluetoothDeviceInfo(const QBluetoothUuid &uuid, const QString &name, bool valid) {
void M3IBikeTestData::configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const {
// The M3I bike detector looks into the manufacturer data.

QBluetoothDeviceInfo result = BluetoothDeviceTestData::get_bluetoothDeviceInfo(uuid, name, true);
QBluetoothDeviceInfo result = info;

if(!valid) {
if(!enable) {
result.setManufacturerData(1, QByteArray("Invalid manufacturer data."));
return result;
bluetoothDeviceInfos.push_back(result);

return;
}

int key=0;
Expand Down Expand Up @@ -70,7 +72,7 @@ QBluetoothDeviceInfo M3IBikeTestData::get_bluetoothDeviceInfo(const QBluetoothUu
result.setManufacturerData(key++, hex2bytes("02010639009FD3000000030000000000000001"));
*/

return result;
bluetoothDeviceInfos.push_back(result);
}


5 changes: 2 additions & 3 deletions tst/Devices/M3IBike/m3ibiketestdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


class M3IBikeTestData : public BikeTestData {
protected:
void configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const override;

public:
M3IBikeTestData() : BikeTestData("M3I Bike") {
this->testInvalidBluetoothDeviceInfo = true;

this->addDeviceName("M3", comparison::StartsWith);
}

Expand All @@ -22,6 +22,5 @@ class M3IBikeTestData : public BikeTestData {
return dynamic_cast<m3ibike*>(detectedDevice)!=nullptr;
}

QBluetoothDeviceInfo get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true) override;
};

2 changes: 2 additions & 0 deletions tst/Devices/StagesBike/stagesbiketestdata.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "stagesbiketestdata.h"

#include "Devices/FTMSBike/ftmsbiketestdata.h"

void StagesBikeTestData::configureExclusions() {
this->exclude(new FTMSBike1TestData());
this->exclude(new FTMSBike2TestData());
Expand Down
42 changes: 20 additions & 22 deletions tst/Devices/StagesBike/stagesbiketestdata.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

#include "Devices/Bike/biketestdata.h"
#include "Devices/FTMSBike/ftmsbiketestdata.h"

#include "devices/stagesbike/stagesbike.h"

class StagesBikeTestData : public BikeTestData {
Expand All @@ -25,8 +23,9 @@ class StagesBike1TestData : public StagesBikeTestData {
public:
StagesBike1TestData() : StagesBikeTestData("Stages Bike") {
this->addDeviceName("STAGES ", comparison::StartsWithIgnoreCase);
this->addDeviceName("TACX SATORI", comparison::StartsWithIgnoreCase);
this->addDeviceName("QD", comparison::IgnoreCase);
}

};


Expand All @@ -44,31 +43,30 @@ class StagesBike2TestData : public StagesBikeTestData {
};

class StagesBike3TestData : public StagesBikeTestData {

public:
StagesBike3TestData() : StagesBikeTestData("Stages Bike (KICKR CORE)") {
this->testInvalidBluetoothDeviceInfo = true;

this->addDeviceName("KICKR CORE", comparison::StartsWithIgnoreCase);
}

QBluetoothDeviceInfo get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true) override
{
QBluetoothDeviceInfo result = BluetoothDeviceTestData::get_bluetoothDeviceInfo(uuid, name, true);

protected:
void configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const override {
// The condition, if the name is acceptable, is:
// !deviceHasService(b, QBluetoothUuid((quint16)0x1826)) && deviceHasService(b, QBluetoothUuid((quint16)0x1818)))

if(valid) {
if(enable) {
QBluetoothDeviceInfo result = info;
result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1818)}));
return result;
bluetoothDeviceInfos.push_back(result);
} else {
QBluetoothDeviceInfo hasInvalid = info;
hasInvalid.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));
QBluetoothDeviceInfo hasBoth = hasInvalid;
hasBoth.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1818),QBluetoothUuid((quint16)0x1826)}));

bluetoothDeviceInfos.push_back(info); // has neither
bluetoothDeviceInfos.push_back(hasInvalid);
bluetoothDeviceInfos.push_back(hasBoth);
}
}

result.setServiceUuids(QVector<QBluetoothUuid>({QBluetoothUuid((quint16)0x1826)}));

// this doesn't check the invalid case where it has both services. Framework does not currently support multiple QBluetoothDeviceInfo scenarios
public:
StagesBike3TestData() : StagesBikeTestData("Stages Bike (KICKR CORE)") {

return result;
this->addDeviceName("KICKR CORE", comparison::StartsWithIgnoreCase);
}

};
18 changes: 12 additions & 6 deletions tst/Devices/bluetoothdevicetestdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@ std::vector<DeviceDiscoveryInfo> BluetoothDeviceTestData::get_configurations(con
return result;
}

bool BluetoothDeviceTestData::get_testInvalidBluetoothDeviceInfo() const { return this->testInvalidBluetoothDeviceInfo; }

QString BluetoothDeviceTestData::get_testIP() const { return "1.2.3.4"; }

QBluetoothDeviceInfo BluetoothDeviceTestData::get_bluetoothDeviceInfo(const QBluetoothUuid &uuid, const QString &name, bool valid) {
if(!valid)
throw "Invalid bluetooth device info is not implemented in this class.";
return QBluetoothDeviceInfo(uuid, name, 0);
std::vector<QBluetoothDeviceInfo> BluetoothDeviceTestData::get_bluetoothDeviceInfo(const QBluetoothUuid &uuid, const QString &name, bool valid) {
std::vector<QBluetoothDeviceInfo> result;

QBluetoothDeviceInfo info(uuid, name, 0);

this->configureBluetoothDeviceInfos(info, valid, result);

// make sure there is always a valid item
if(valid && result.empty())
result.push_back(info);

return result;
}

32 changes: 12 additions & 20 deletions tst/Devices/bluetoothdevicetestdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ class BluetoothDeviceTestData {
StartsWithIgnoreCase = IgnoreCase+StartsWith
};

/**
* @brief Indicates if invalid bluetooth device info should be tested for.
*/
bool testInvalidBluetoothDeviceInfo = false;

/**
* @brief Call exclude(...) to populate the exclusions vector. This vector is populated on demand
* to avoid circularities in the constructors.
Expand Down Expand Up @@ -176,7 +171,15 @@ class BluetoothDeviceTestData {
* @param configurations The variations of the provided object to test.
*/
virtual void configureSettings(const DeviceDiscoveryInfo& info, bool enable, std::vector<DeviceDiscoveryInfo>& configurations) const;



/**
* @brief Configure multiple QBluetoothDeviceInfo objects to either enable or disable the device in multiple ways.
* @info An initial object configured aith a name and UUID for copying. This is expceted to have no service UUIDs.
* @param enable Indicates if the request is for enabling (true) or disabling (false) configurations on the bluetooth device info.
* @param bluetoothDeviceInfos The objects to test.
*/
virtual void configureBluetoothDeviceInfos(const QBluetoothDeviceInfo& info, bool enable, std::vector<QBluetoothDeviceInfo>& bluetoothDeviceInfos) const {}

/**
* @brief Configure the devicediscoveryinfo object to either enable or disable the device.
Expand All @@ -201,7 +204,6 @@ class BluetoothDeviceTestData {
*/
virtual std::string get_testName() const;


/**
* @brief Indicates if the test data is for an abstract class.
* @return
Expand Down Expand Up @@ -232,9 +234,6 @@ class BluetoothDeviceTestData {
*/
virtual std::vector<DeviceDiscoveryInfo> get_configurations(const DeviceDiscoveryInfo& info, bool enable);




/**
* @brief Gets the expected device type enumeration value to be detected for this device.
*/
Expand All @@ -247,26 +246,19 @@ class BluetoothDeviceTestData {
*/
virtual bool get_isExpectedDevice(bluetoothdevice * detectedDevice) const =0;

/**
* @brief Indicates if invalid bluetooth device info should be tested for.
* @return
*/
bool get_testInvalidBluetoothDeviceInfo() const;

/**
* @brief Specifies a test IP address for wifi devices.
*/
virtual QString get_testIP() const;


/**
* @brief Gets a QBluetoothDeviceInfo object for the specified name and UUID. Can be used to
* generate invalid objects where device identification relies on more than just the name.
* @brief Gets a vector of QBluetoothDeviceInfo objects for the specified name and UUID. Can be used to
* generate valid and invalid objects where device identification relies on more than just the name.
* @param uuid
* @param name
* @param valid
*/
virtual QBluetoothDeviceInfo get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true);
std::vector<QBluetoothDeviceInfo> get_bluetoothDeviceInfo(const QBluetoothUuid& uuid, const QString& name, bool valid=true);


};
Loading

0 comments on commit df88e7e

Please sign in to comment.