From 13ad39d1b1512ed352718050a58a35c7f6e85d0b Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 3 Dec 2014 14:21:49 +0100 Subject: Make QLEController unit test pass on Android 1.) Android needs some time in between disconnect/connect attempts. 2.) Adjust unit test to modified charWritten/charChanged signals 3.) Make tst pass on Android when using WriteWithoutResponse mode when writing characteristics. Android seems to ignore this property as the platform keeps sending characteristicWritten() signals. Change-Id: I9879af989471b32ff28acc64c9897da018910515 Reviewed-by: Timur Pocheptsov Reviewed-by: Alex Blasche --- .../tst_qlowenergycontroller.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 67ae1872..80c3e532 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -74,6 +74,7 @@ public: private slots: void initTestCase(); + void init(); void cleanupTestCase(); void tst_emptyCtor(); void tst_connect(); @@ -159,6 +160,20 @@ void tst_QLowEnergyController::initTestCase() foundServices << QBluetoothUuid(QString("f000ffc0-0451-4000-b000-000000000000")); } +/* + * Executed in between each test function call. + */ +void tst_QLowEnergyController::init() +{ +#ifdef Q_OS_ANDROID + /* + * Add a delay to give Android stack time to catch up in between + * the multiple connect/disconnects within each test function. + */ + QTest::qWait(2000); +#endif +} + void tst_QLowEnergyController::cleanupTestCase() { @@ -2119,7 +2134,7 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() QLowEnergyCharacteristic second = entry[0].value(); QByteArray val2 = entry[1].toByteArray(); QCOMPARE(imageIdentityChar, second); - QCOMPARE(val2, QByteArray::fromHex("0")); + QVERIFY(val2 == QByteArray::fromHex("0") || val2 == val1); charChangedSpy.clear(); charWrittenSpy.clear(); @@ -2145,7 +2160,12 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() second = entry[0].value(); val2 = entry[1].toByteArray(); QCOMPARE(imageIdentityChar, second); - QCOMPARE(val2, QByteArray::fromHex("1")); + + /* Bluez resends the last confirmed write value, other platforms + * send the value received by the change notification value. + */ + qDebug() << "Image B(1):" << val1.toHex() << val2.toHex(); + QVERIFY(val2 == QByteArray::fromHex("1") || val2 == val1); QVERIFY2(foundOneImage, "The SensorTag doesn't have a valid image? (1)"); @@ -2168,6 +2188,10 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() first = entry[0].value(); val1 = entry[1].toByteArray(); +#ifdef Q_OS_ANDROID + QEXPECT_FAIL("", "Android sends write confirmation when using WriteWithoutResponse", + Continue); +#endif QVERIFY(charWrittenSpy.isEmpty()); if (val1.size() == 8) { QCOMPARE(first, imageIdentityChar); @@ -2193,6 +2217,10 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() first = entry[0].value(); val1 = entry[1].toByteArray(); +#ifdef Q_OS_ANDROID + QEXPECT_FAIL("", "Android sends write confirmation when using WriteWithoutResponse", + Continue); +#endif QVERIFY(charWrittenSpy.isEmpty()); if (val1.size() == 8) { QCOMPARE(first, imageIdentityChar); -- cgit v1.2.3