Files
qdomyos-zwift/src/qmdnsengine/tests/TestCache.cpp
Roberto Viola b2d7821f68 Implement MAC address randomization for Rouvy compatibility (#3999)
* Implement MAC address randomization for Rouvy compatibility

When Rouvy compatibility mode is enabled, the dirconmanager now uses
a specific MAC address base (24:DC:C3:E3:B5:XX) with the last byte
set to the dircon_id value from settings. This allows each instance
to have a unique identifier while maintaining compatibility with Rouvy.

Changes:
- Modified getMacAddress() to accept rouvy_compatibility and dircon_id parameters
- Added logic to generate MAC address "24:DC:C3:E3:B5:XX" where XX is dircon_id in hex
- Updated constructor to pass settings values to getMacAddress()
- Maintained backward compatibility with default parameter values

* Refactor getMacAddress to read Rouvy setting internally

Modified getMacAddress() to read the rouvy_compatibility setting
directly from QSettings instead of receiving it as a parameter.
This simplifies the function interface and ensures the setting is
always read from the current configuration.

Changes:
- Removed rouvy_compatibility parameter from getMacAddress()
- Added QSettings read inside getMacAddress() function
- Updated function call to only pass dircon_id parameter

* Simplify getMacAddress to read all settings internally

Modified getMacAddress() to be a parameter-free function that reads
both rouvy_compatibility and dircon_id settings internally from QSettings.
This creates a cleaner, more self-contained interface.

Changes:
- Removed dircon_id parameter from getMacAddress()
- Added dircon_id read inside getMacAddress() function
- Removed local dircon_id_value variable from constructor
- Function now takes no parameters and reads all needed settings internally

* Simplify Rouvy compatibility to advertise only ELITE AVANTI device

When Rouvy compatibility mode is enabled, now only the ELITE AVANTI
device is created and advertised. Removed WAHOO_BLUEHR (heart rate),
WAHOO_RPM_SPEED, and WAHOO_TREADMILL from the Rouvy macro to streamline
the device presentation to Rouvy app.

This change is safe because:
- All enum types remain defined via DM_MACHINE_OP
- All services continue to exist
- Only runtime device initialization is affected when Rouvy mode is enabled

Changes:
- Removed WAHOO_BLUEHR, WAHOO_RPM_SPEED, and WAHOO_TREADMILL from DM_MACHINE_OP_ROUVY
- Only WAHOO_KICKR (ELITE AVANTI) remains for Rouvy compatibility

* Update qmdnsengine submodule to use cagnulein-patch-1 branch

Changed qmdnsengine submodule configuration to use the cagnulein-patch-1
branch and commit 5e5469a06d79c1daa31bbc34d48241c53b6d4fea instead of the
previous zwift branch and commit 602da51dc43c55bd9aa8a83c47ea3594a9b01b98.

Changes:
- Updated .gitmodules: branch zwift → cagnulein-patch-1
- Updated GitHub workflows: all refs to "zwift" → "cagnulein-patch-1"
- Updated GitHub workflows: git checkout commands to use new commit hash
- This ensures all CI/CD builds use the correct qmdnsengine version

* Fix qmdnsengine commit SHA to correct version

Corrected the qmdnsengine submodule commit SHA from the incorrect
5e5469a06d79c1daa31bbc34d48241c53b6d4fea to the correct
16cf29108dfaf9c26d21038a620332c103a5b4f8 in all GitHub workflow
"Fix qmdnsengine submodule" steps.

This ensures all CI/CD builds use the correct qmdnsengine version
from the cagnulein-patch-1 branch.

* adding qmdnsengine as source code directly removing the submodules

* Update main.yml

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-09 12:02:48 +01:00

138 lines
3.8 KiB
C++

/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Nathan Osman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <QObject>
#include <QSignalSpy>
#include <QTest>
#include <qmdnsengine/dns.h>
#include <qmdnsengine/cache.h>
#include <qmdnsengine/record.h>
Q_DECLARE_METATYPE(QMdnsEngine::Record)
const QByteArray Name = "Test";
const quint16 Type = QMdnsEngine::TXT;
class TestCache : public QObject
{
Q_OBJECT
public:
TestCache() : mCounter(0) {}
private Q_SLOTS:
void initTestCase();
void testExpiry();
void testRemoval();
void testCacheFlush();
private:
QMdnsEngine::Record createRecord();
int mCounter;
};
void TestCache::initTestCase()
{
qRegisterMetaType<QMdnsEngine::Record>("Record");
}
void TestCache::testExpiry()
{
QMdnsEngine::Cache cache;
cache.addRecord(createRecord());
QSignalSpy shouldQuerySpy(&cache, SIGNAL(shouldQuery(Record)));
QSignalSpy recordExpiredSpy(&cache, SIGNAL(recordExpired(Record)));
// The record should be in the cache
QMdnsEngine::Record record;
QVERIFY(cache.lookupRecord(Name, Type, record));
// After entering the event loop, the record should be purged when its TTL
// expires in 1s
QTRY_VERIFY(!cache.lookupRecord(Name, Type, record));
// Ensure that the shouldQuery() signal was emitted at least once and the
// recordExpired() signal was eventually emitted as well
QVERIFY(shouldQuerySpy.count() > 0);
QCOMPARE(recordExpiredSpy.count(), 1);
}
void TestCache::testRemoval()
{
QMdnsEngine::Cache cache;
QMdnsEngine::Record record = createRecord();
cache.addRecord(record);
QSignalSpy recordExpiredSpy(&cache, SIGNAL(recordExpired(Record)));
// Purge the record from the cache by setting its TTL to 0
record.setTtl(0);
cache.addRecord(record);
// Verify that the record is gone
QVERIFY(!cache.lookupRecord(Name, Type, record));
QCOMPARE(recordExpiredSpy.count(), 1);
}
void TestCache::testCacheFlush()
{
QMdnsEngine::Cache cache;
for (int i = 0; i < 2; ++i) {
cache.addRecord(createRecord());
}
QList<QMdnsEngine::Record> records;
QVERIFY(cache.lookupRecords(Name, Type, records));
QCOMPARE(records.length(), 2);
// Insert a new record with the cache clear bit set
QMdnsEngine::Record record = createRecord();
record.setFlushCache(true);
cache.addRecord(record);
// Confirm that only a single record exists
records.clear();
QVERIFY(cache.lookupRecords(Name, Type, records));
QCOMPARE(records.length(), 1);
}
QMdnsEngine::Record TestCache::createRecord()
{
QMdnsEngine::Record record;
record.setName(Name);
record.setType(Type);
record.setTtl(1);
record.addAttribute("key", QByteArray::number(mCounter++));
return record;
}
QTEST_MAIN(TestCache)
#include "TestCache.moc"