File indexing completed on 2024-05-12 05:40:54
0001 /*************************************************************************** 0002 * Copyright (C) 2011 by Renaud Guezennec * 0003 * http://renaudguezennec.homelinux.org/accueil,3.html * 0004 * * 0005 * Rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #include <QtTest/QtTest> 0021 0022 #include "controller/view_controller/vectorialmapcontroller.h" 0023 #include "data/cleveruri.h" 0024 #include "network/networkmessagereader.h" 0025 #include "network/networkmessagewriter.h" 0026 #include "updater/media/vmapupdater.h" 0027 #include "updater/vmapitem/vmapitemcontrollerupdater.h" 0028 #include "worker/convertionhelper.h" 0029 #include <memory> 0030 0031 class UpdaterVMapTest : public QObject 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 enum Type 0037 { 0038 REAL, 0039 INT, 0040 LAYER, 0041 VISIBILITY, 0042 GRIDPATTERN, 0043 PERMISSION, 0044 BOOL, 0045 QCOLOR, 0046 UNIT, 0047 SIGHT 0048 }; 0049 Q_ENUM(Type) 0050 UpdaterVMapTest(); 0051 0052 private slots: 0053 void init(); 0054 void cleanupTestCase(); 0055 void serializationTest(); 0056 void serializationTest_data(); 0057 0058 private: 0059 std::unique_ptr<VMapUpdater> m_updater; 0060 }; 0061 0062 UpdaterVMapTest::UpdaterVMapTest() {} 0063 0064 void UpdaterVMapTest::init() 0065 { 0066 m_updater.reset(new VMapUpdater(nullptr, nullptr)); 0067 } 0068 0069 void UpdaterVMapTest::cleanupTestCase() {} 0070 0071 void UpdaterVMapTest::serializationTest() 0072 { 0073 QFETCH(QString, propertyName); 0074 QFETCH(QVariant, propertyValue); 0075 QFETCH(Type, type); 0076 QFETCH(bool, result); 0077 0078 VectorialMapController map(""); 0079 auto ok= map.setProperty(propertyName.toLocal8Bit().data(), propertyValue); 0080 QVERIFY(ok); 0081 0082 NetworkMessageWriter msg(NetMsg::MediaCategory, NetMsg::UpdateMediaProperty); 0083 msg.string16(propertyName); 0084 switch(type) 0085 { 0086 case REAL: 0087 Helper::variantToType<qreal>(propertyValue.value<qreal>(), msg); 0088 break; 0089 case INT: 0090 Helper::variantToType<int>(propertyValue.value<int>(), msg); 0091 break; 0092 case LAYER: 0093 Helper::variantToType<Core::Layer>(propertyValue.value<Core::Layer>(), msg); 0094 break; 0095 case VISIBILITY: 0096 Helper::variantToType<Core::VisibilityMode>(propertyValue.value<Core::VisibilityMode>(), msg); 0097 break; 0098 case GRIDPATTERN: 0099 Helper::variantToType<Core::GridPattern>(propertyValue.value<Core::GridPattern>(), msg); 0100 break; 0101 case PERMISSION: 0102 Helper::variantToType<Core::PermissionMode>(propertyValue.value<Core::PermissionMode>(), msg); 0103 break; 0104 case BOOL: 0105 Helper::variantToType<bool>(propertyValue.value<bool>(), msg); 0106 break; 0107 case QCOLOR: 0108 Helper::variantToType<QColor>(propertyValue.value<QColor>(), msg); 0109 break; 0110 case UNIT: 0111 Helper::variantToType<Core::ScaleUnit>(propertyValue.value<Core::ScaleUnit>(), msg); 0112 break; 0113 case SIGHT: 0114 Helper::variantToType<QPainterPath>(propertyValue.value<QPainterPath>(), msg); 0115 break; 0116 } 0117 0118 auto data= msg.data(); 0119 0120 NetworkMessageReader msgReader; 0121 msgReader.setData(data); 0122 0123 VectorialMapController ma2p(""); 0124 QCOMPARE(m_updater->updateVMapProperty(&msgReader, &ma2p), result); 0125 } 0126 0127 void UpdaterVMapTest::serializationTest_data() 0128 { 0129 QTest::addColumn<QString>("propertyName"); 0130 QTest::addColumn<QVariant>("propertyValue"); 0131 QTest::addColumn<Type>("type"); 0132 QTest::addColumn<bool>("result"); 0133 0134 QTest::addRow("value 1") << QString("collision") << QVariant::fromValue(true) << BOOL << true; 0135 QTest::addRow("value 2") << QString("collision") << QVariant::fromValue(false) << BOOL << true; 0136 QTest::addRow("value 3") << QString("characterVision") << QVariant::fromValue(true) << BOOL << true; 0137 QTest::addRow("value 4") << QString("characterVision") << QVariant::fromValue(false) << BOOL << true; 0138 QTest::addRow("value 5") << QString("gridColor") << QVariant::fromValue(QColor(Qt::yellow)) << QCOLOR << true; 0139 QTest::addRow("value 6") << QString("gridScale") << QVariant::fromValue(1.5) << REAL << true; 0140 QTest::addRow("value 7") << QString("gridSize") << QVariant::fromValue(29) << INT << true; 0141 QTest::addRow("value 8") << QString("gridVisibility") << QVariant::fromValue(true) << BOOL << true; 0142 QTest::addRow("value 8bis") << QString("gridVisibility") << QVariant::fromValue(false) << BOOL << true; 0143 QTest::addRow("value 9") << QString("gridAbove") << QVariant::fromValue(false) << BOOL << true; 0144 QTest::addRow("value 9bis") << QString("gridAbove") << QVariant::fromValue(true) << BOOL << true; 0145 QTest::addRow("value 10") << QString("scaleUnit") << QVariant::fromValue(Core::KM) << UNIT << true; 0146 QTest::addRow("value 11") << QString("permission") << QVariant::fromValue(Core::PC_ALL) << PERMISSION << true; 0147 QTest::addRow("value 12") << QString("gridPattern") << QVariant::fromValue(Core::GridPattern::SQUARE) << GRIDPATTERN 0148 << true; 0149 QTest::addRow("value 13") << QString("visibility") << QVariant::fromValue(Core::FOGOFWAR) << VISIBILITY << true; 0150 QTest::addRow("value 14") << QString("backgroundColor") << QVariant::fromValue(QColor(Qt::yellow)) << QCOLOR 0151 << true; 0152 QTest::addRow("value 15") << QString("layer") << QVariant::fromValue(Core::Layer::GROUND) << LAYER << true; 0153 QTest::addRow("value 16") << QString("zIndex") << QVariant::fromValue(18) << INT << true; 0154 } 0155 0156 QTEST_MAIN(UpdaterVMapTest); 0157 0158 #include "tst_vmapupdatertest.moc"