From ed49b5cda6d84793ffdfd433b2d2cea0583de219 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 26 Feb 2014 17:10:09 +0100 Subject: Add copy operator to QBluetoothHostInfo. The QBluetoothSocket unit test was sometimes failing because of it. Change-Id: I6071902e1aaa9e1138f071b7f2ce2a8ccb436789 Reviewed-by: Nedim Hadzic Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothhostinfo.cpp | 13 +++++++++++++ src/bluetooth/qbluetoothhostinfo.h | 2 ++ .../auto/qbluetoothhostinfo/tst_qbluetoothhostinfo.cpp | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/bluetooth/qbluetoothhostinfo.cpp b/src/bluetooth/qbluetoothhostinfo.cpp index 1e8dbc2e..00ce0680 100644 --- a/src/bluetooth/qbluetoothhostinfo.cpp +++ b/src/bluetooth/qbluetoothhostinfo.cpp @@ -81,6 +81,19 @@ QBluetoothHostInfo::~QBluetoothHostInfo() delete d_ptr; } +/*! + Assigns \a other to this QBluetoothHostInfo instance. +*/ +QBluetoothHostInfo &QBluetoothHostInfo::operator=(const QBluetoothHostInfo &other) +{ + Q_D(QBluetoothHostInfo); + + d->m_address = other.d_func()->m_address; + d->m_name = other.d_func()->m_name; + + return *this; +} + /*! Returns the Bluetooth address as a QBluetoothAddress. */ diff --git a/src/bluetooth/qbluetoothhostinfo.h b/src/bluetooth/qbluetoothhostinfo.h index 24590ebb..b4428a82 100644 --- a/src/bluetooth/qbluetoothhostinfo.h +++ b/src/bluetooth/qbluetoothhostinfo.h @@ -55,6 +55,8 @@ public: QBluetoothHostInfo(const QBluetoothHostInfo &other); ~QBluetoothHostInfo(); + QBluetoothHostInfo &operator=(const QBluetoothHostInfo &other); + QBluetoothAddress address() const; void setAddress(const QBluetoothAddress &address); diff --git a/tests/auto/qbluetoothhostinfo/tst_qbluetoothhostinfo.cpp b/tests/auto/qbluetoothhostinfo/tst_qbluetoothhostinfo.cpp index aa2448a8..be2cadbf 100644 --- a/tests/auto/qbluetoothhostinfo/tst_qbluetoothhostinfo.cpp +++ b/tests/auto/qbluetoothhostinfo/tst_qbluetoothhostinfo.cpp @@ -65,6 +65,8 @@ private slots: void tst_construction_data(); void tst_construction(); + + void tst_copy(); }; tst_QBluetoothHostInfo::tst_QBluetoothHostInfo() @@ -171,6 +173,22 @@ void tst_QBluetoothHostInfo::tst_construction() QCOMPARE(setter.address().isNull(), !validBtAddress); } +void tst_QBluetoothHostInfo::tst_copy() +{ + QBluetoothHostInfo original; + original.setAddress(QBluetoothAddress("11:22:33:44:55:66")); + original.setName(QStringLiteral("FunkyName")); + + QBluetoothHostInfo assignConstructor(original); + QCOMPARE(assignConstructor.name(), original.name()); + QCOMPARE(assignConstructor.address(), original.address()); + + QBluetoothHostInfo assignOperator; + assignOperator = original; + QCOMPARE(assignOperator.name(), original.name()); + QCOMPARE(assignOperator.address(), original.address()); +} + QTEST_MAIN(tst_QBluetoothHostInfo) #include "tst_qbluetoothhostinfo.moc" -- cgit v1.2.3