dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobjectstests.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  *
25  * Additional note on redistribution: The copyright and license notices above
26  * must be maintained in each individual source file that is a derivative work
27  * of this source file; otherwise redistribution is prohibited.
28  */
29 
30 #include "uavobjectsplugin.h"
31 
32 #include "uavdataobject.h"
33 #include "uavobjectfield.h"
34 
35 #include <QTest>
36 #include <memory>
37 
38 
39 void UAVObjectsPlugin::testEnumFields()
40 {
41  auto field = new UAVObjectField("TestEnum", "photons", UAVObjectField::ENUM, 2, {"Yes", "No"},
42  {0, 1}, QString(), QStringLiteral("Test some stuff"), {"No", "Yes"});
43  quint8 testData[255] = {};
44 
45  field->initialize(testData, 0, nullptr);
46  QCOMPARE(field->getName(), QStringLiteral("TestEnum"));
47  QCOMPARE(field->getValue(0).toString(), QStringLiteral("Yes"));
48  QCOMPARE(field->getValue(1).toString(), QStringLiteral("Yes"));
49  QVERIFY(!field->isDefaultValue(0));
50  QVERIFY(field->isDefaultValue(1));
51 }
52 
53 void UAVObjectsPlugin::testIntFields()
54 {
55  std::unique_ptr<UAVObjectField> field(new UAVObjectField("TestUInt8", "photons", UAVObjectField::UINT8, 2, {},
56  {}, QString(), QStringLiteral("Test some stuff"), {254, 0}));
57  quint8 testData[255] = {};
58 
59  field->initialize(testData, 0, nullptr);
60  QCOMPARE(field->getName(), QStringLiteral("TestUInt8"));
61  QVERIFY(field->getValue(0).toUInt() == 0);
62  QVERIFY(field->getValue(1).toUInt() == 0);
63  QVERIFY(!field->isDefaultValue(0));
64  QVERIFY(field->isDefaultValue(1));
65 }
66 
void initialize(quint8 *data, quint32 dataOffset, UAVObject *obj)