1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtBluetooth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30
31#include <QDebug>
32#include <QMap>
33
34#include <qbluetoothtransferrequest.h>
35#include <qbluetoothaddress.h>
36#include <qbluetoothlocaldevice.h>
37
38QT_USE_NAMESPACE
39
40typedef QMap<int,QVariant> tst_QBluetoothTransferRequest_QParameterMap;
41Q_DECLARE_METATYPE(tst_QBluetoothTransferRequest_QParameterMap)
42
43class tst_QBluetoothTransferRequest : public QObject
44{
45 Q_OBJECT
46
47public:
48 tst_QBluetoothTransferRequest();
49 ~tst_QBluetoothTransferRequest();
50
51private slots:
52 void initTestCase();
53
54 void tst_construction_data();
55 void tst_construction();
56
57 void tst_assignment_data();
58 void tst_assignment();
59};
60
61tst_QBluetoothTransferRequest::tst_QBluetoothTransferRequest()
62{
63}
64
65tst_QBluetoothTransferRequest::~tst_QBluetoothTransferRequest()
66{
67}
68
69void tst_QBluetoothTransferRequest::initTestCase()
70{
71 // start Bluetooth if not started
72 QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
73 device->powerOn();
74 delete device;
75}
76
77void tst_QBluetoothTransferRequest::tst_construction_data()
78{
79 QTest::addColumn<QBluetoothAddress>(name: "address");
80 QTest::addColumn<QMap<int, QVariant> >(name: "parameters");
81
82 QMap<int, QVariant> inparameters;
83 inparameters.insert(akey: (int)QBluetoothTransferRequest::DescriptionAttribute, avalue: "Desciption");
84 inparameters.insert(akey: (int)QBluetoothTransferRequest::LengthAttribute, avalue: QVariant(1024));
85 inparameters.insert(akey: (int)QBluetoothTransferRequest::TypeAttribute, avalue: "OPP");
86
87 QTest::newRow(dataTag: "0x000000 COD") << QBluetoothAddress("000000000000") << inparameters;
88 QTest::newRow(dataTag: "0x000100 COD") << QBluetoothAddress("000000000000") << inparameters;
89 QTest::newRow(dataTag: "0x000104 COD") << QBluetoothAddress("000000000000") << inparameters;
90 QTest::newRow(dataTag: "0x000118 COD") << QBluetoothAddress("000000000000") << inparameters;
91 QTest::newRow(dataTag: "0x000200 COD") << QBluetoothAddress("000000000000") << inparameters;
92}
93
94void tst_QBluetoothTransferRequest::tst_construction()
95{
96 QFETCH(QBluetoothAddress, address);
97 QFETCH(tst_QBluetoothTransferRequest_QParameterMap, parameters);
98
99 QBluetoothTransferRequest transferRequest(address);
100
101 const QList<int> keys = parameters.keys();
102 for (const int key : keys) {
103 transferRequest.setAttribute(code: (QBluetoothTransferRequest::Attribute)key, value: parameters[key]);
104 QCOMPARE(parameters[key], transferRequest.attribute((QBluetoothTransferRequest::Attribute)key));
105 }
106
107 QCOMPARE(transferRequest.address(), address);
108
109 QBluetoothTransferRequest copyRequest(transferRequest);
110
111 QCOMPARE(copyRequest.address(), address);
112 QCOMPARE(transferRequest, copyRequest);
113}
114
115void tst_QBluetoothTransferRequest::tst_assignment_data()
116{
117 tst_construction_data();
118}
119
120void tst_QBluetoothTransferRequest::tst_assignment()
121{
122 QFETCH(QBluetoothAddress, address);
123 QFETCH(tst_QBluetoothTransferRequest_QParameterMap, parameters);
124
125 QBluetoothTransferRequest transferRequest(address);
126
127 const QList<int> keys = parameters.keys();
128 for (const int key : keys) {
129 transferRequest.setAttribute(code: (QBluetoothTransferRequest::Attribute)key, value: parameters[key]);
130 }
131
132 {
133 QBluetoothTransferRequest copyRequest = transferRequest;
134
135 QCOMPARE(copyRequest.address(), address);
136 QCOMPARE(transferRequest, copyRequest);
137 }
138
139 {
140 QBluetoothTransferRequest copyRequest(QBluetoothAddress("000000000001"));
141
142 copyRequest = transferRequest;
143
144 QCOMPARE(copyRequest.address(), address);
145 QCOMPARE(transferRequest, copyRequest);
146 }
147
148 {
149 QBluetoothTransferRequest copyRequest1(QBluetoothAddress("000000000001"));
150 QBluetoothTransferRequest copyRequest2(QBluetoothAddress("000000000001"));
151
152 copyRequest1 = copyRequest2 = transferRequest;
153
154 QCOMPARE(copyRequest1.address(), address);
155 QCOMPARE(copyRequest2.address(), address);
156 QCOMPARE(transferRequest, copyRequest1);
157 QCOMPARE(transferRequest, copyRequest2);
158
159 }
160}
161
162QTEST_MAIN(tst_QBluetoothTransferRequest)
163
164#include "tst_qbluetoothtransferrequest.moc"
165

source code of qtconnectivity/tests/auto/qbluetoothtransferrequest/tst_qbluetoothtransferrequest.cpp