summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2013-08-05 10:07:05 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-09 14:57:14 +0200
commit40158b4277984890a55d87fca4e44d86d9a936f7 (patch)
tree2ab827035abc8976c56c912f5cff960ec4f8faa4
parentf0e7da6dab3a19a9c978f2cbba2dea60fcea619b (diff)
Improve QBluetoothTransferManager unit test
and fix some minor issues during the process. Task-number: QTBUG-22017 Change-Id: Iff1adde28ba818c3ed0511cb5d45404f05d7c36f Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--examples/bluetooth/btfiletransfer/remoteselector.cpp3
-rw-r--r--src/bluetooth/qbluetoothtransfermanager_bluez.cpp5
-rw-r--r--src/bluetooth/qbluetoothtransfermanager_qnx.cpp5
-rw-r--r--src/bluetooth/qbluetoothtransferreply.cpp2
-rw-r--r--src/bluetooth/qbluetoothtransferreply_bluez.cpp7
-rw-r--r--src/bluetooth/qbluetoothtransferreply_bluez_p.h2
-rw-r--r--src/bluetooth/qbluetoothtransferreply_qnx.cpp7
-rw-r--r--src/bluetooth/qbluetoothtransferreply_qnx_p.h2
-rw-r--r--tests/auto/qbluetoothtransfermanager/qbluetoothtransfermanager.pro2
-rw-r--r--tests/auto/qbluetoothtransfermanager/testfile.txt1
-rw-r--r--tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp314
11 files changed, 240 insertions, 110 deletions
diff --git a/examples/bluetooth/btfiletransfer/remoteselector.cpp b/examples/bluetooth/btfiletransfer/remoteselector.cpp
index f7e68906..70cde972 100644
--- a/examples/bluetooth/btfiletransfer/remoteselector.cpp
+++ b/examples/bluetooth/btfiletransfer/remoteselector.cpp
@@ -222,6 +222,9 @@ void RemoteSelector::on_sendButton_clicked()
p->show();
QBluetoothTransferReply *reply = mgr.put(req, m_file);
+ //mgr is default parent
+ //ensure that mgr doesn't take reply down when leaving scope
+ reply->setParent(this);
if (reply->error()){
qDebug() << "Failed to send file";
p->finished(reply);
diff --git a/src/bluetooth/qbluetoothtransfermanager_bluez.cpp b/src/bluetooth/qbluetoothtransfermanager_bluez.cpp
index 5bb0b956..c43aed81 100644
--- a/src/bluetooth/qbluetoothtransfermanager_bluez.cpp
+++ b/src/bluetooth/qbluetoothtransfermanager_bluez.cpp
@@ -49,11 +49,8 @@ QT_BEGIN_NAMESPACE_BLUETOOTH
QBluetoothTransferReply *QBluetoothTransferManager::put(const QBluetoothTransferRequest &request,
QIODevice *data)
{
-
- QBluetoothTransferReplyBluez *rep = new QBluetoothTransferReplyBluez(data, request);
-
+ QBluetoothTransferReplyBluez *rep = new QBluetoothTransferReplyBluez(data, request, this);
connect(rep, SIGNAL(finished(QBluetoothTransferReply*)), this, SIGNAL(finished(QBluetoothTransferReply*)));
-
return rep;
}
diff --git a/src/bluetooth/qbluetoothtransfermanager_qnx.cpp b/src/bluetooth/qbluetoothtransfermanager_qnx.cpp
index 26502fcc..1b9b9693 100644
--- a/src/bluetooth/qbluetoothtransfermanager_qnx.cpp
+++ b/src/bluetooth/qbluetoothtransfermanager_qnx.cpp
@@ -47,11 +47,8 @@ QT_BEGIN_NAMESPACE_BLUETOOTH
QBluetoothTransferReply *QBluetoothTransferManager::put(const QBluetoothTransferRequest &request,
QIODevice *data)
{
-
- QBluetoothTransferReplyQnx *reply = new QBluetoothTransferReplyQnx(data, request);
-
+ QBluetoothTransferReplyQnx *reply = new QBluetoothTransferReplyQnx(data, request, this);
connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), this, SIGNAL(finished(QBluetoothTransferReply*)));
-
return reply;
}
diff --git a/src/bluetooth/qbluetoothtransferreply.cpp b/src/bluetooth/qbluetoothtransferreply.cpp
index d6bf4dba..a7c9c003 100644
--- a/src/bluetooth/qbluetoothtransferreply.cpp
+++ b/src/bluetooth/qbluetoothtransferreply.cpp
@@ -125,7 +125,7 @@ QBluetoothTransferReply::~QBluetoothTransferReply()
/*!
Returns the QBluetoothTransferManager that was used to create this QBluetoothTransferReply
- object.
+ object. Initially, it is also the parent object.
*/
QBluetoothTransferManager *QBluetoothTransferReply::manager() const
{
diff --git a/src/bluetooth/qbluetoothtransferreply_bluez.cpp b/src/bluetooth/qbluetoothtransferreply_bluez.cpp
index 159fdbcc..d5871b89 100644
--- a/src/bluetooth/qbluetoothtransferreply_bluez.cpp
+++ b/src/bluetooth/qbluetoothtransferreply_bluez.cpp
@@ -58,12 +58,13 @@ static const QLatin1String agentPath("/qt/agent");
QT_BEGIN_NAMESPACE_BLUETOOTH
QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, const QBluetoothTransferRequest &request,
- QObject *parent)
+ QBluetoothTransferManager *parent)
: QBluetoothTransferReply(parent), tempfile(0), source(input),
m_running(false), m_finished(false), m_size(0),
m_error(QBluetoothTransferReply::NoError), m_errorStr(), m_transfer_path()
{
setRequest(request);
+ setManager(parent);
client = new OrgOpenobexClientInterface(QLatin1String("org.openobex.client"), QLatin1String("/"),
QDBusConnection::sessionBus());
@@ -79,6 +80,7 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con
qRegisterMetaType<QBluetoothTransferReply*>("QBluetoothTransferReply*");
QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
+ m_running = true;
}
/*!
@@ -92,8 +94,7 @@ QBluetoothTransferReplyBluez::~QBluetoothTransferReplyBluez()
bool QBluetoothTransferReplyBluez::start()
{
- m_running = true;
-
+// qDebug() << "Got a:" << source->metaObject()->className();
QFile *file = qobject_cast<QFile *>(source);
if(!file){
diff --git a/src/bluetooth/qbluetoothtransferreply_bluez_p.h b/src/bluetooth/qbluetoothtransferreply_bluez_p.h
index 941b024c..c476136f 100644
--- a/src/bluetooth/qbluetoothtransferreply_bluez_p.h
+++ b/src/bluetooth/qbluetoothtransferreply_bluez_p.h
@@ -62,7 +62,7 @@ class Q_BLUETOOTH_EXPORT QBluetoothTransferReplyBluez : public QBluetoothTransfe
public:
explicit QBluetoothTransferReplyBluez(QIODevice *input, const QBluetoothTransferRequest &request,
- QObject *parent = 0);
+ QBluetoothTransferManager *parent = 0);
~QBluetoothTransferReplyBluez();
bool isFinished() const;
diff --git a/src/bluetooth/qbluetoothtransferreply_qnx.cpp b/src/bluetooth/qbluetoothtransferreply_qnx.cpp
index f2f60fcd..5124906b 100644
--- a/src/bluetooth/qbluetoothtransferreply_qnx.cpp
+++ b/src/bluetooth/qbluetoothtransferreply_qnx.cpp
@@ -61,11 +61,14 @@
QT_BEGIN_NAMESPACE_BLUETOOTH
QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const QBluetoothTransferRequest &request,
- QObject *parent)
+ QBluetoothTransferManager *parent)
: QBluetoothTransferReply(parent), tempfile(0), source(input),
m_running(false), m_finished(false),
m_error(QBluetoothTransferReply::NoError), m_errorStr()
{
+ setRequest(request);
+ setManager(parent);
+
ppsRegisterControl();
//qsrand(QTime::currentTime().msec());
//m_agent_path = agentPath;
@@ -75,6 +78,7 @@ QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const Q
ppsRegisterForEvent(QStringLiteral("opp_cancelled"), this);
QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
+ m_running = true;
}
/*!
@@ -87,7 +91,6 @@ QBluetoothTransferReplyQnx::~QBluetoothTransferReplyQnx()
bool QBluetoothTransferReplyQnx::start()
{
- m_running = true;
m_error = QBluetoothTransferReply::NoError;
m_errorStr = QString();
diff --git a/src/bluetooth/qbluetoothtransferreply_qnx_p.h b/src/bluetooth/qbluetoothtransferreply_qnx_p.h
index 5add8d6a..430ee4e6 100644
--- a/src/bluetooth/qbluetoothtransferreply_qnx_p.h
+++ b/src/bluetooth/qbluetoothtransferreply_qnx_p.h
@@ -63,7 +63,7 @@ class Q_BLUETOOTH_EXPORT QBluetoothTransferReplyQnx : public QBluetoothTransferR
public:
explicit QBluetoothTransferReplyQnx(QIODevice *input, const QBluetoothTransferRequest &request,
- QObject *parent = 0);
+ QBluetoothTransferManager *parent = 0);
~QBluetoothTransferReplyQnx();
bool isFinished() const;
diff --git a/tests/auto/qbluetoothtransfermanager/qbluetoothtransfermanager.pro b/tests/auto/qbluetoothtransfermanager/qbluetoothtransfermanager.pro
index ef13503b..aeb45868 100644
--- a/tests/auto/qbluetoothtransfermanager/qbluetoothtransfermanager.pro
+++ b/tests/auto/qbluetoothtransfermanager/qbluetoothtransfermanager.pro
@@ -7,5 +7,5 @@ QT = core concurrent bluetooth testlib
INCLUDEPATH += ../../../tests/btclient
-CONFIG += insignificant_test # QTBUG-22017
+TESTDATA += *.txt
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/qbluetoothtransfermanager/testfile.txt b/tests/auto/qbluetoothtransfermanager/testfile.txt
new file mode 100644
index 00000000..630a0118
--- /dev/null
+++ b/tests/auto/qbluetoothtransfermanager/testfile.txt
@@ -0,0 +1 @@
+This is a small test file to be transmitted by tst_bluetoothtransfermanager.
diff --git a/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp b/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp
index 19b0e5db..998e3d4e 100644
--- a/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp
+++ b/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp
@@ -56,13 +56,20 @@
#include <qbluetoothservicediscoveryagent.h>
#include <btclient.h>
+/*
+ * Some tests require a Bluetooth device within the vincinity of the test
+ * machine executing this test. The tests require manual interaction
+ * as pairing and file transfer requests must be accepted.
+ * The remote device's address must be passed
+ * via the BT_TEST_DEVICE env variable. The remote device must be
+ * discoverable and the object push service must be accessible. Any
+ **/
+
QT_USE_NAMESPACE_BLUETOOTH
-typedef QMap<int,QVariant> tst_QBluetoothTransferManager_QParameterMap;
+typedef QMap<QBluetoothTransferRequest::Attribute,QVariant> tst_QBluetoothTransferManager_QParameterMap;
Q_DECLARE_METATYPE(tst_QBluetoothTransferManager_QParameterMap)
-char BTADDRESS[] = "00:00:00:00:00:00";
-
static const int MaxConnectTime = 60 * 1000; // 1 minute in ms
class tst_QBluetoothTransferManager : public QObject
@@ -78,20 +85,14 @@ private slots:
void tst_construction();
- void tst_put_data();
- void tst_put();
-
- void tst_putAbort_data();
- void tst_putAbort();
-
- void tst_attribute_data();
- void tst_attribute();
+ void tst_request_data();
+ void tst_request();
- void tst_operation_data();
- void tst_operation();
+ void tst_sendFile_data();
+ void tst_sendFile();
- void tst_manager_data();
- void tst_manager();
+ void tst_sendBuffer_data();
+ void tst_sendBuffer();
public slots:
void serviceDiscovered(const QBluetoothServiceInfo &info);
@@ -99,10 +100,13 @@ public slots:
void error(QBluetoothServiceDiscoveryAgent::Error error);
private:
bool done_discovery;
+ QBluetoothAddress remoteAddress;
+ QBluetoothAddress foundAddress;
};
tst_QBluetoothTransferManager::tst_QBluetoothTransferManager()
{
+ qRegisterMetaType<QBluetoothTransferReply*>("QBluetoothTransferReply*");
}
tst_QBluetoothTransferManager::~tst_QBluetoothTransferManager()
@@ -111,9 +115,23 @@ tst_QBluetoothTransferManager::~tst_QBluetoothTransferManager()
void tst_QBluetoothTransferManager::initTestCase()
{
+ const QString remote = qgetenv("BT_TEST_DEVICE");
+ if (!remote.isEmpty()) {
+ remoteAddress = QBluetoothAddress(remote);
+ QVERIFY(!remoteAddress.isNull());
+ qWarning() << "Using remote device " << remote << " for testing. Ensure that the device is discoverable for pairing requests";
+ } else {
+ qWarning() << "Not using any remote device for testing. Set BT_TEST_DEVICE env to run manual tests involving a remote device";
+ }
+
+
+
if (!QBluetoothLocalDevice::allDevices().count())
QSKIP("Skipping test due to missing Bluetooth device");
+ if (remoteAddress.isNull())
+ QSKIP("Remote upload test not possible. Set BT_TEST_DEVICE");
+
// start Bluetooth if not started
QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
device->powerOn();
@@ -127,9 +145,8 @@ void tst_QBluetoothTransferManager::initTestCase()
qDebug() << "Starting discovery";
done_discovery = false;
- memset(BTADDRESS, 0, 18);
- sda->setUuidFilter(QBluetoothUuid(QString(ECHO_SERVICE_UUID)));
+ sda->setUuidFilter(QBluetoothUuid(QBluetoothUuid::ObexObjectPush));
sda->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery);
for (int connectTime = MaxConnectTime; !done_discovery && connectTime > 0; connectTime -= 1000)
@@ -137,15 +154,15 @@ void tst_QBluetoothTransferManager::initTestCase()
sda->stop();
- if (BTADDRESS[0] == 0) {
- QFAIL("Unable to find test service");
- }
+ if (foundAddress.isNull())
+ QFAIL("Unable to find test service/device");
+
delete sda;
}
void tst_QBluetoothTransferManager::error(QBluetoothServiceDiscoveryAgent::Error error)
{
qDebug() << "Received error" << error;
-// done_discovery = true;
+ done_discovery = true;
}
void tst_QBluetoothTransferManager::finished()
@@ -156,9 +173,11 @@ void tst_QBluetoothTransferManager::finished()
void tst_QBluetoothTransferManager::serviceDiscovered(const QBluetoothServiceInfo &info)
{
- qDebug() << "Found: " << info.device().name() << info.serviceUuid();
- strcpy(BTADDRESS, info.device().address().toString().toLatin1());
- done_discovery = true;
+ qDebug() << "Found: " << info.device().name() << info.device().address().toString() << info.serviceName();
+ if (info.device().address() == remoteAddress) {
+ foundAddress = remoteAddress;
+ done_discovery = true;
+ }
}
void tst_QBluetoothTransferManager::tst_construction()
@@ -169,115 +188,224 @@ void tst_QBluetoothTransferManager::tst_construction()
delete manager;
}
-void tst_QBluetoothTransferManager::tst_put_data()
+void tst_QBluetoothTransferManager::tst_request_data()
{
QTest::addColumn<QBluetoothAddress>("address");
- QTest::addColumn<QMap<int, QVariant> >("parameters");
+ QTest::addColumn<QMap<QBluetoothTransferRequest::Attribute, QVariant> >("parameters");
- QMap<int, QVariant> inparameters;
- inparameters.insert((int)QBluetoothTransferRequest::DescriptionAttribute, "Desciption");
- inparameters.insert((int)QBluetoothTransferRequest::LengthAttribute, QVariant(1024));
- inparameters.insert((int)QBluetoothTransferRequest::TypeAttribute, "OPP");
+ QMap<QBluetoothTransferRequest::Attribute, QVariant> inparameters;
+ inparameters.insert(QBluetoothTransferRequest::DescriptionAttribute, "Description");
+ inparameters.insert(QBluetoothTransferRequest::LengthAttribute, QVariant(1024));
+ inparameters.insert(QBluetoothTransferRequest::TypeAttribute, "OPP");
+ inparameters.insert(QBluetoothTransferRequest::NameAttribute, "name");
+ inparameters.insert(QBluetoothTransferRequest::TimeAttribute, QDateTime::currentDateTime());
- QTest::newRow("0x000000 COD") << QBluetoothAddress(BTADDRESS) << inparameters;
+ QTest::newRow("TESTDATA") << QBluetoothAddress("00:11:22:33:44:55:66") << inparameters;
}
-void tst_QBluetoothTransferManager::tst_put()
+void tst_QBluetoothTransferManager::tst_request()
{
QFETCH(QBluetoothAddress, address);
QFETCH(tst_QBluetoothTransferManager_QParameterMap, parameters);
QBluetoothTransferRequest transferRequest(address);
+ foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ QCOMPARE(transferRequest.attribute(key), QVariant());
- foreach (int key, parameters.keys()) {
+ foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
transferRequest.setAttribute((QBluetoothTransferRequest::Attribute)key, parameters[key]);
- }
- QBluetoothTransferManager manager;
+ QCOMPARE(transferRequest.address(), address);
+ foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ QCOMPARE(transferRequest.attribute(key), parameters[key]);
+
+ //test copy constructor
+ QBluetoothTransferRequest constructorCopy = transferRequest;
+ QVERIFY(constructorCopy == transferRequest);
+ QVERIFY(!(constructorCopy != transferRequest));
+ QCOMPARE(constructorCopy.address(), address);
+ foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ QCOMPARE(constructorCopy.attribute(key), parameters[key]);
+
+ //test assignment operator
+ QBluetoothTransferRequest request;
+ QVERIFY(request.address().isNull());
+ foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ QCOMPARE(request.attribute(key), QVariant());
+ request = transferRequest;
+ QCOMPARE(request.address(), address);
+ foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ QCOMPARE(request.attribute(key), parameters[key]);
+
+ //test that it's a true and independent copy
+ constructorCopy.setAttribute(QBluetoothTransferRequest::DescriptionAttribute, "newDescription");
+ request.setAttribute(QBluetoothTransferRequest::TypeAttribute, "FTP");
+
+ QCOMPARE(constructorCopy.attribute(QBluetoothTransferRequest::DescriptionAttribute).toString(),QString("newDescription"));
+ QCOMPARE(request.attribute(QBluetoothTransferRequest::DescriptionAttribute).toString(),QString("Description"));
+ QCOMPARE(transferRequest.attribute(QBluetoothTransferRequest::DescriptionAttribute).toString(),QString("Description"));
+
+ QCOMPARE(constructorCopy.attribute(QBluetoothTransferRequest::TypeAttribute).toString(),QString("OPP"));
+ QCOMPARE(request.attribute(QBluetoothTransferRequest::TypeAttribute).toString(),QString("FTP"));
+ QCOMPARE(transferRequest.attribute(QBluetoothTransferRequest::TypeAttribute).toString(),QString("OPP"));
}
-void tst_QBluetoothTransferManager::tst_putAbort_data()
+void tst_QBluetoothTransferManager::tst_sendFile_data()
{
- QTest::addColumn<QBluetoothAddress>("address");
- QTest::addColumn<QMap<int, QVariant> >("parameters");
-
- QMap<int, QVariant> inparameters;
- inparameters.insert((int)QBluetoothTransferRequest::DescriptionAttribute, "Desciption");
- inparameters.insert((int)QBluetoothTransferRequest::LengthAttribute, QVariant(1024));
- inparameters.insert((int)QBluetoothTransferRequest::TypeAttribute, "OPP");
+ QTest::addColumn<QBluetoothAddress>("deviceAddress");
+ QTest::addColumn<bool>("expectSuccess");
+ QTest::addColumn<bool>("isInvalidFile");
+
+ if (foundAddress.isNull()) {
+ qDebug("Skipping send file test due to not finding remote device");
+ } else {
+ QTest::newRow("Push to remote test device") << foundAddress << true << false;
+ QTest::newRow("Push of non-existing file") << foundAddress << false << true;
+ }
+ QTest::newRow("Push to invalid address") << QBluetoothAddress() << false << false;
+ QTest::newRow("Push to non-existend device") << QBluetoothAddress("11:22:33:44:55:66") << false << false;
- QTest::newRow("0x000000 COD") << QBluetoothAddress(BTADDRESS) << inparameters;
}
-void tst_QBluetoothTransferManager::tst_putAbort()
+void tst_QBluetoothTransferManager::tst_sendFile()
{
- QFETCH(QBluetoothAddress, address);
- QFETCH(tst_QBluetoothTransferManager_QParameterMap, parameters);
-
- QBluetoothTransferRequest transferRequest(address);
-
- foreach (int key, parameters.keys()) {
- transferRequest.setAttribute((QBluetoothTransferRequest::Attribute)key, parameters[key]);
+ QFETCH(QBluetoothAddress, deviceAddress);
+ QFETCH(bool, expectSuccess);
+ QFETCH(bool, isInvalidFile);
+
+ QBluetoothLocalDevice dev;
+ if (expectSuccess) {
+ dev.requestPairing(deviceAddress, QBluetoothLocalDevice::Paired);
+ QTest::qWait(2000);
+ QCOMPARE(dev.pairingStatus(deviceAddress), QBluetoothLocalDevice::Paired);
}
- QBluetoothTransferManager manager;
-}
+ QBluetoothTransferRequest request(deviceAddress);
+ QCOMPARE(request.address(), deviceAddress);
-void tst_QBluetoothTransferManager::tst_attribute_data()
-{
- QTest::addColumn<QBluetoothAddress>("address");
- QTest::addColumn<QMap<int, QVariant> >("parameters");
+ QBluetoothTransferManager manager;
+ QString fileHandle;
+ if (!isInvalidFile) {
+ fileHandle = QFINDTESTDATA("testfile.txt");
+ QVERIFY(!fileHandle.isEmpty());
+ } else {
+ fileHandle = QFINDTESTDATA("arbitraryFileName.txt"); //file doesn't exist
+ QVERIFY(fileHandle.isEmpty());
+ }
+ QFile f(fileHandle);
+ QCOMPARE(f.exists(), !isInvalidFile);
+
+
+ qDebug() << "Transferring file to " << deviceAddress.toString();
+ if (expectSuccess)
+ qDebug() << "Please accept Object push request on remote device";
+ QBluetoothTransferReply* reply = manager.put(request, &f);
+ QSignalSpy finishedSpy(reply, SIGNAL(finished(QBluetoothTransferReply*)));
+ QSignalSpy progressSpy(reply, SIGNAL(transferProgress(qint64,qint64)));
+
+ QCOMPARE(reply->request(), request);
+ QVERIFY(reply->manager() == &manager);
+ QVERIFY(!reply->isFinished());
+ QVERIFY(reply->isRunning());
+
+ const int maxWaitTime = 20 * 1000; //20s
+ for (int time = 0;
+ time<maxWaitTime && (finishedSpy.count()==0);
+ time+=10000) {
+ QTest::qWait(10000); //if interval
+ }
- QMap<int, QVariant> inparameters;
- inparameters.insert((int)QBluetoothTransferRequest::DescriptionAttribute, "Desciption");
- inparameters.insert((int)QBluetoothTransferRequest::LengthAttribute, QVariant(1024));
- inparameters.insert((int)QBluetoothTransferRequest::TypeAttribute, "OPP");
+ QVERIFY(finishedSpy.count()>0);
+ if (expectSuccess) {
+ QVERIFY(progressSpy.count()>0);
+ QCOMPARE(reply->error(), QBluetoothTransferReply::NoError);
+ QCOMPARE(reply->errorString(), QString());
+ } else {
+ QVERIFY(progressSpy.count() == 0);
+ if (isInvalidFile)
+ QVERIFY(reply->error() == QBluetoothTransferReply::FileNotFoundError);
+ else
+ QVERIFY(reply->error() != QBluetoothTransferReply::NoError);
+ QVERIFY(!reply->errorString().isEmpty());
+ }
- QTest::newRow("0x000000 COD") << QBluetoothAddress(BTADDRESS) << inparameters;
+ QVERIFY(reply->isFinished());
+ QVERIFY(!reply->isRunning());
}
-void tst_QBluetoothTransferManager::tst_attribute()
+void tst_QBluetoothTransferManager::tst_sendBuffer_data()
{
- QFETCH(QBluetoothAddress, address);
- QFETCH(tst_QBluetoothTransferManager_QParameterMap, parameters);
-
- QBluetoothTransferRequest transferRequest(address);
- foreach (int key, parameters.keys()) {
- transferRequest.setAttribute((QBluetoothTransferRequest::Attribute)key, parameters[key]);
- }
-
- QBluetoothTransferManager manager;
+ QTest::addColumn<QBluetoothAddress>("deviceAddress");
+ QTest::addColumn<bool>("expectSuccess");
+ QTest::addColumn<QByteArray>("data");
+
+ if (foundAddress.isNull())
+ qDebug("Skipping send file test due to not finding remote device");
+ else
+ QTest::newRow("Push to remote test device") << foundAddress << true <<
+ QByteArray("This is a very long byte arry which we are going to access via a QBuffer"); ;
+ //QTest::newRow("Push to invalid address") << QBluetoothAddress() << false;
+ //QTest::newRow("Push to non-existend device") << QBluetoothAddress("11:22:33:44:55:66") << false;
}
-void tst_QBluetoothTransferManager::tst_operation_data()
-{
- QTest::addColumn<QBluetoothAddress>("address");
- QTest::newRow("0x000000 COD") << QBluetoothAddress(BTADDRESS);
-}
-void tst_QBluetoothTransferManager::tst_operation()
+void tst_QBluetoothTransferManager::tst_sendBuffer()
{
- QFETCH(QBluetoothAddress, address);
+ QFETCH(QBluetoothAddress, deviceAddress);
+ QFETCH(bool, expectSuccess);
+ QFETCH(QByteArray, data);
+
+ QBuffer buffer;
+ buffer.setData(data);
+ buffer.open(QIODevice::ReadOnly);
+ buffer.seek(0);
+
+ QBluetoothLocalDevice dev;
+ if (expectSuccess) {
+ dev.requestPairing(deviceAddress, QBluetoothLocalDevice::Paired);
+ QTest::qWait(2000);
+ QCOMPARE(dev.pairingStatus(deviceAddress), QBluetoothLocalDevice::Paired);
+ }
- QBluetoothTransferRequest transferRequest(address);
- QBluetoothTransferManager manager;
-}
+ QBluetoothTransferRequest request(deviceAddress);
+ QCOMPARE(request.address(), deviceAddress);
-void tst_QBluetoothTransferManager::tst_manager_data()
-{
- QTest::addColumn<QBluetoothAddress>("address");
+ QBluetoothTransferManager manager;
- QTest::newRow("0x000000 COD") << QBluetoothAddress(BTADDRESS);
-}
+ qDebug() << "Transferring test buffer to " << deviceAddress.toString();
+ if (expectSuccess)
+ qDebug() << "Please accept Object push request on remote device";
+ QBluetoothTransferReply* reply = manager.put(request, &buffer);
+ QSignalSpy finishedSpy(reply, SIGNAL(finished(QBluetoothTransferReply*)));
+ QSignalSpy progressSpy(reply, SIGNAL(transferProgress(qint64,qint64)));
+
+ QCOMPARE(reply->request(), request);
+ QVERIFY(reply->manager() == &manager);
+ QVERIFY(!reply->isFinished());
+ QVERIFY(reply->isRunning());
+
+ const int maxWaitTime = 20 * 1000; //20s
+ for (int time = 0;
+ time<maxWaitTime && (finishedSpy.count()==0);
+ time+=10000) {
+ QTest::qWait(10000); //if interval
+ }
-void tst_QBluetoothTransferManager::tst_manager()
-{
- QFETCH(QBluetoothAddress, address);
+ QVERIFY(finishedSpy.count()>0);
+ if (expectSuccess) {
+ QVERIFY(progressSpy.count()>0);
+ QCOMPARE(reply->error(), QBluetoothTransferReply::NoError);
+ QCOMPARE(reply->errorString(), QString());
+ } else {
+ QVERIFY(progressSpy.count() == 0);
+ QVERIFY(reply->error() != QBluetoothTransferReply::NoError);
+ QVERIFY(!reply->errorString().isEmpty());
+ }
- QBluetoothTransferRequest transferRequest(address);
- QBluetoothTransferManager manager;
+ QVERIFY(reply->isFinished());
+ QVERIFY(!reply->isRunning());
}
QTEST_MAIN(tst_QBluetoothTransferManager)