File indexing completed on 2024-05-12 05:40:48
0001 #include <QTest> 0002 0003 #include <QSignalSpy> 0004 0005 #include "controller/view_controller/selectconnprofilecontroller.h" 0006 #include "model/profilemodel.h" 0007 #include "network/characterdatamodel.h" 0008 #include "network/connectionprofile.h" 0009 #include "worker/iohelper.h" 0010 #include <QAbstractItemModelTester> 0011 #include <helper.h> 0012 #include <limits> 0013 0014 struct CharacterInfo 0015 { 0016 QString uuid; 0017 QString name; 0018 QColor color; 0019 QByteArray avatar; 0020 }; 0021 0022 class ProfileControllerTest : public QObject 0023 { 0024 Q_OBJECT 0025 public: 0026 ProfileControllerTest()= default; 0027 0028 private slots: 0029 void init(); 0030 0031 void clone(); 0032 void clone_data(); 0033 void serialization(); 0034 void serialization_data(); 0035 void canConnect(); 0036 void canConnect_data(); 0037 0038 void connectTest(); 0039 0040 private: 0041 std::unique_ptr<ProfileModel> m_profileModel; 0042 std::unique_ptr<SelectConnProfileController> m_ctrl; 0043 std::unique_ptr<QUndoStack> m_stack; 0044 }; 0045 Q_DECLARE_METATYPE(CharacterInfo) 0046 void ProfileControllerTest::init() 0047 { 0048 m_profileModel.reset(new ProfileModel()); 0049 m_ctrl.reset(new SelectConnProfileController(m_profileModel.get(), nullptr)); 0050 new QAbstractItemModelTester(m_profileModel.get()); 0051 } 0052 0053 void ProfileControllerTest::clone() 0054 { 0055 0056 QFETCH(int, profileCount); 0057 QFETCH(int, characterCount); 0058 QFETCH(bool, avatarSquare); 0059 QFETCH(bool, isGM); 0060 QFETCH(bool, isServer); 0061 QFETCH(bool, expected); 0062 0063 for(int i= 0; i < profileCount; ++i) 0064 { 0065 m_ctrl->addProfile(); 0066 QCOMPARE(m_profileModel->rowCount(), i + 1); 0067 m_ctrl->setCurrentProfileIndex(i); 0068 auto profile= m_profileModel->getProfile(i); 0069 QSignalSpy nameSpy(profile, &ConnectionProfile::titleChanged); 0070 0071 auto name= Helper::randomString(); 0072 // set player info 0073 m_ctrl->setProfileName(name); 0074 nameSpy.wait(10); 0075 QCOMPARE(nameSpy.count(), 1); 0076 auto playername= Helper::randomString(); 0077 QSignalSpy playerNameSpy(profile, &ConnectionProfile::playerNameChanged); 0078 m_ctrl->setPlayerName(playername); 0079 playerNameSpy.wait(10); 0080 QCOMPARE(playerNameSpy.count(), 1); 0081 0082 m_ctrl->setPlayerAvatar(Helper::imageData(avatarSquare)); 0083 0084 // set Campaign info 0085 QTemporaryDir dir; 0086 dir.setAutoRemove(false); 0087 dir.isValid(); 0088 auto path= dir.path(); 0089 0090 if(m_ctrl->isGameMaster() != isGM) 0091 { 0092 QSignalSpy gmSpy(profile, &ConnectionProfile::gmChanged); 0093 m_ctrl->setIsGameMaster(isGM); 0094 gmSpy.wait(10); 0095 QCOMPARE(gmSpy.count(), 1); 0096 } 0097 0098 QSignalSpy campSpy(profile, &ConnectionProfile::campaignPathChanged); 0099 m_ctrl->setCampaignPath(path); 0100 campSpy.wait(10); 0101 0102 QCOMPARE(campSpy.count(), 1); 0103 0104 // set network info 0105 if(m_ctrl->isServer() != isServer) 0106 { 0107 QSignalSpy serverSpy(profile, &ConnectionProfile::serverChanged); 0108 m_ctrl->setIsServer(isServer); 0109 serverSpy.wait(10); 0110 QCOMPARE(serverSpy.count(), 1); 0111 } 0112 0113 { 0114 auto port= Helper::generate(0, 20000); 0115 while(port == m_ctrl->port()) 0116 port= Helper::generate(0, 20000); 0117 QSignalSpy portSpy(profile, &ConnectionProfile::portChanged); 0118 m_ctrl->setPort(port); 0119 portSpy.wait(10); 0120 QCOMPARE(portSpy.count(), 1); 0121 } 0122 if(!isServer) 0123 { 0124 auto address= "192.168.1.24"; 0125 profile->setAddress(address); 0126 QCOMPARE(m_ctrl->address(), address); 0127 } 0128 0129 for(int j= 0; j < characterCount; ++j) 0130 { 0131 m_ctrl->addCharacter(); 0132 m_ctrl->editCharacterName(j, Helper::randomString()); 0133 m_ctrl->editCharacterColor(j, Qt::red); 0134 m_ctrl->editCharacterAvatar(j, Helper::imageData(avatarSquare)); 0135 } 0136 } 0137 0138 for(int i= 0; i < profileCount; ++i) 0139 { 0140 m_ctrl->setCurrentProfileIndex(i); 0141 QCOMPARE(m_ctrl->canConnect(), expected); 0142 } 0143 0144 for(int i= profileCount - 1; i >= 0; --i) 0145 { 0146 m_ctrl->cloneProfile(i); 0147 0148 auto origin= m_profileModel->getProfile(i); 0149 auto clone= m_profileModel->getProfile(m_ctrl->profileModel()->rowCount() - 1); 0150 QVERIFY(origin->profileTitle() != clone->profileTitle()); 0151 QCOMPARE(origin->playerName(), clone->playerName()); 0152 QCOMPARE(origin->isGM(), clone->isGM()); 0153 QCOMPARE(origin->isServer(), clone->isServer()); 0154 QCOMPARE(m_ctrl->canConnect(), expected); 0155 } 0156 0157 for(int i= m_profileModel->rowCount() - 1; i >= 0; --i) 0158 { 0159 m_ctrl->removeProfile(i); 0160 } 0161 } 0162 0163 void ProfileControllerTest::clone_data() 0164 { 0165 QTest::addColumn<int>("profileCount"); 0166 QTest::addColumn<int>("characterCount"); 0167 QTest::addColumn<bool>("avatarSquare"); 0168 QTest::addColumn<bool>("isGM"); 0169 QTest::addColumn<bool>("isServer"); 0170 QTest::addColumn<bool>("expected"); 0171 0172 QTest::addRow("empty") << 0 << 0 << false << false << false << false; 0173 QTest::addRow("empty but gm") << 0 << 0 << false << true << false << false; 0174 QTest::addRow("one profile") << 1 << 0 << false << false << false << false; 0175 0176 QTest::addRow("One profile but gm") << 1 << 0 << false << true << true << false; 0177 QTest::addRow("One profile with square") << 1 << 1 << true << true << true << true; 0178 QTest::addRow("One profile without square") << 1 << 1 << false << true << true << false; 0179 0180 for(int i= 0; i < 5; ++i) 0181 { 0182 QTest::addRow("%d profile but gm", i) << i << 0 << false << true << true << false; 0183 QTest::addRow("%d profile with square", i) << i << i << true << true << true << true; 0184 QTest::addRow("%d profile without square", i) << i << i << false << true << true << false; 0185 } 0186 } 0187 0188 void ProfileControllerTest::serialization() 0189 { 0190 QFETCH(int, profileCount); 0191 QFETCH(int, characterCount); 0192 QFETCH(bool, avatarSquare); 0193 QFETCH(bool, isGM); 0194 QFETCH(bool, isServer); 0195 QFETCH(bool, expected); 0196 0197 m_ctrl.reset(new SelectConnProfileController(nullptr, nullptr)); 0198 0199 // should not lead to crash 0200 m_ctrl->addProfile(); 0201 m_ctrl->cloneProfile(0); 0202 m_ctrl->removeProfile(0); 0203 m_ctrl->validCharacterAvatar(); 0204 m_ctrl->validCharacterColor(); 0205 m_ctrl->validCharacterName(); 0206 m_ctrl->address(); 0207 m_ctrl->campaignPath(); 0208 m_ctrl->playerAvatar(); 0209 m_ctrl->playerColor(); 0210 m_ctrl->playerName(); 0211 0212 m_profileModel.reset(new ProfileModel()); 0213 0214 for(int i= 0; i < profileCount; ++i) 0215 { 0216 m_profileModel->appendProfile(); 0217 QCOMPARE(m_profileModel->rowCount(), i + 1); 0218 auto profile= m_profileModel->getProfile(i); 0219 QSignalSpy nameSpy(profile, &ConnectionProfile::titleChanged); 0220 0221 auto name= Helper::randomString(); 0222 // set player info 0223 profile->setProfileTitle(name); 0224 nameSpy.wait(10); 0225 QCOMPARE(nameSpy.count(), 1); 0226 auto playername= Helper::randomString(); 0227 QSignalSpy playerNameSpy(profile, &ConnectionProfile::playerNameChanged); 0228 profile->setPlayerName(playername); 0229 playerNameSpy.wait(10); 0230 QCOMPARE(playerNameSpy.count(), 1); 0231 0232 profile->setPlayerAvatar(Helper::imageData(avatarSquare)); 0233 0234 // set Campaign info 0235 QTemporaryDir dir; 0236 dir.setAutoRemove(false); 0237 dir.isValid(); 0238 auto path= dir.path(); 0239 0240 if(profile->isGM() != isGM) 0241 { 0242 QSignalSpy gmSpy(profile, &ConnectionProfile::gmChanged); 0243 profile->setGm(isGM); 0244 gmSpy.wait(10); 0245 QCOMPARE(gmSpy.count(), 1); 0246 } 0247 0248 QSignalSpy campSpy(profile, &ConnectionProfile::campaignPathChanged); 0249 profile->setCampaignPath(path); 0250 campSpy.wait(10); 0251 0252 QCOMPARE(campSpy.count(), 1); 0253 0254 // set network info 0255 if(profile->isServer() != isServer) 0256 { 0257 QSignalSpy serverSpy(profile, &ConnectionProfile::serverChanged); 0258 profile->setServerMode(isServer); 0259 serverSpy.wait(10); 0260 QCOMPARE(serverSpy.count(), 1); 0261 } 0262 0263 { 0264 auto port= Helper::generate(0, 20000); 0265 while(port == profile->port()) 0266 port= Helper::generate(0, 20000); 0267 QSignalSpy portSpy(profile, &ConnectionProfile::portChanged); 0268 profile->setPort(port); 0269 portSpy.wait(10); 0270 QCOMPARE(portSpy.count(), 1); 0271 } 0272 if(!isServer) 0273 { 0274 auto address= "192.168.1.24"; 0275 profile->setAddress(address); 0276 m_ctrl->address(); 0277 } 0278 0279 for(int j= 0; j < characterCount; ++j) 0280 { 0281 profile->addCharacter(connection::CharacterData( 0282 {Helper::randomString(), Helper::randomString(), Qt::red, Helper::imageData(avatarSquare), {}})); 0283 } 0284 } 0285 0286 m_ctrl.reset(new SelectConnProfileController(m_profileModel.get(), nullptr)); 0287 0288 for(int i= 0; i < profileCount; ++i) 0289 { 0290 m_ctrl->setCurrentProfileIndex(i); 0291 // auto prof= m_profileModel->getProfile(i); 0292 // qDebug() << "characters:" << prof->charactersValid() << "connections" << prof->connectionInfoValid() 0293 // << "campaignInfoValid" << prof->campaignInfoValid() << "playerInfoValid" << 0294 // prof->playerInfoValid(); 0295 0296 QCOMPARE(m_ctrl->canConnect(), expected); 0297 } 0298 0299 for(int i= profileCount - 1; i >= 0; --i) 0300 { 0301 m_ctrl->cloneProfile(i); 0302 0303 auto origin= m_profileModel->getProfile(i); 0304 auto clone= m_profileModel->getProfile(m_ctrl->profileModel()->rowCount() - 1); 0305 QVERIFY(origin->profileTitle() != clone->profileTitle()); 0306 QCOMPARE(origin->playerName(), clone->playerName()); 0307 QCOMPARE(origin->isGM(), clone->isGM()); 0308 QCOMPARE(origin->isServer(), clone->isServer()); 0309 QCOMPARE(m_ctrl->canConnect(), expected); 0310 } 0311 } 0312 void ProfileControllerTest::serialization_data() 0313 { 0314 QTest::addColumn<int>("profileCount"); 0315 QTest::addColumn<int>("characterCount"); 0316 QTest::addColumn<bool>("avatarSquare"); 0317 QTest::addColumn<bool>("isGM"); 0318 QTest::addColumn<bool>("isServer"); 0319 QTest::addColumn<bool>("expected"); 0320 0321 QTest::addRow("empty") << 0 << 0 << false << false << false << false; 0322 QTest::addRow("empty but gm") << 0 << 0 << false << true << false << false; 0323 QTest::addRow("one profile") << 1 << 0 << false << false << false << false; 0324 0325 QTest::addRow("One profile but gm") << 1 << 0 << false << true << true << false; 0326 QTest::addRow("One profile with square") << 1 << 1 << true << true << true << true; 0327 QTest::addRow("One profile without square") << 1 << 1 << false << true << true << false; 0328 0329 for(int i= 0; i < 5; ++i) 0330 { 0331 QTest::addRow("%d profile but gm", i) << i << 0 << false << true << true << false; 0332 QTest::addRow("%d profile with square", i) << i << i << true << true << true << true; 0333 QTest::addRow("%d profile without square", i) << i << i << false << true << true << false; 0334 } 0335 } 0336 0337 void ProfileControllerTest::connectTest() 0338 { 0339 m_ctrl.reset(new SelectConnProfileController(m_profileModel.get(), nullptr)); 0340 m_ctrl->setCurrentProfileIndex(10); 0341 m_ctrl->setCurrentProfileIndex(m_ctrl->currentProfileIndex()); 0342 QCOMPARE(m_profileModel->rowCount(), 0); 0343 0344 m_profileModel.reset(new ProfileModel()); 0345 auto profil= new ConnectionProfile(); 0346 profil->setProfileTitle("Text1"); 0347 m_profileModel->appendProfile(profil); 0348 m_ctrl.reset(new SelectConnProfileController(m_profileModel.get(), nullptr)); 0349 0350 auto profileModel= m_ctrl->profileModel(); 0351 QCOMPARE(profileModel->rowCount(), 1); 0352 QCOMPARE(m_ctrl->profileName(), "Text1"); 0353 0354 QVERIFY(!m_ctrl->validCampaignPath()); 0355 0356 QTemporaryDir dir; 0357 dir.setAutoRemove(false); 0358 dir.isValid(); 0359 auto path= dir.path(); 0360 0361 QSignalSpy campSpy(m_ctrl.get(), &SelectConnProfileController::campaignPathChanged); 0362 m_ctrl->setCampaignPath(path); 0363 campSpy.wait(10); 0364 0365 QCOMPARE(campSpy.count(), 1); 0366 0367 QCOMPARE(m_ctrl->connectionState(), SelectConnProfileController::ConnectionState::IDLE); 0368 0369 auto error= Helper::randomString(); 0370 m_ctrl->setErrorMsg(error); 0371 QCOMPARE(m_ctrl->errorMsg(), error); 0372 m_ctrl->setErrorMsg(error); 0373 0374 auto info= Helper::randomString(); 0375 m_ctrl->setInfoMsg(info); 0376 QCOMPARE(m_ctrl->infoMsg(), info); 0377 m_ctrl->setInfoMsg(info); 0378 0379 m_ctrl->addCharacter(); 0380 auto model= m_ctrl->characterModel(); 0381 0382 QCOMPARE(model->rowCount(), 1); 0383 auto name= Helper::randomString(); 0384 m_ctrl->editCharacterName(0, name); 0385 auto character= model->character(0); 0386 QCOMPARE(character.m_name, name); 0387 0388 m_ctrl->editCharacterColor(0, Qt::darkGray); 0389 character= model->character(0); 0390 QCOMPARE(character.m_color, Qt::darkGray); 0391 0392 auto avatar= Helper::imageData(true); 0393 m_ctrl->editCharacterAvatar(0, avatar); 0394 m_ctrl->editCharacterColor(0, Qt::red); 0395 m_ctrl->editCharacterName(0, Helper::randomString()); 0396 character= model->character(0); 0397 QCOMPARE(character.m_avatarData, avatar); 0398 QVERIFY(m_ctrl->validCharacter()); 0399 QVERIFY(m_ctrl->validCharacterAvatar()); 0400 QVERIFY(m_ctrl->validCharacterColor()); 0401 QVERIFY(m_ctrl->validCharacterName()); 0402 0403 m_ctrl->removeCharacter(0); 0404 QCOMPARE(model->rowCount(), 0); 0405 0406 auto pw= Helper::randomString(); 0407 m_ctrl->setPassword(pw.toUtf8()); 0408 QVERIFY(m_ctrl->password() != pw); 0409 } 0410 0411 void ProfileControllerTest::canConnect() 0412 { 0413 QFETCH(QString, profileName); 0414 QFETCH(QString, playerName); 0415 QFETCH(QColor, playerColor); 0416 QFETCH(QByteArray, playerAvatar); 0417 QFETCH(bool, isGameMaster); 0418 QFETCH(bool, isServer); 0419 QFETCH(QString, address); 0420 QFETCH(int, port); 0421 QFETCH(QString, campaignPath); 0422 QFETCH(QList<CharacterInfo>, characters); 0423 QFETCH(bool, canConnectStatus); 0424 0425 QCOMPARE(m_profileModel->rowCount(), 0); 0426 m_ctrl->addProfile(); 0427 QCOMPARE(m_profileModel->rowCount(), 1); 0428 0429 m_ctrl->setCurrentProfileIndex(0); 0430 QCOMPARE(m_ctrl->currentProfileIndex(), 0); 0431 0432 QSignalSpy spy(m_ctrl.get(), &SelectConnProfileController::canConnectChanged); 0433 0434 m_ctrl->setProfileName(profileName); 0435 0436 m_ctrl->setPlayerName(playerName); 0437 QCOMPARE(m_ctrl->playerName(), playerName); 0438 m_ctrl->setPlayerColor(playerColor); 0439 QCOMPARE(m_ctrl->playerColor(), playerColor); 0440 m_ctrl->setPlayerAvatar(playerAvatar); 0441 QCOMPARE(m_ctrl->playerAvatar(), playerAvatar); 0442 0443 m_ctrl->setIsGameMaster(isGameMaster); 0444 m_ctrl->setIsServer(isServer); 0445 0446 m_ctrl->setAddress(address); 0447 m_ctrl->setPort(port); 0448 0449 m_ctrl->setCampaignPath(campaignPath); 0450 auto characterModel= m_ctrl->characterModel(); 0451 characterModel->removeCharacter(0); 0452 0453 QList<connection::CharacterData> list; 0454 std::transform(std::begin(characters), std::end(characters), std::back_inserter(list), 0455 [](const CharacterInfo& info) -> connection::CharacterData { 0456 return {info.uuid, info.name, info.color, info.avatar, {}}; 0457 }); 0458 0459 for(auto const& data : qAsConst(list)) 0460 { 0461 characterModel->addCharacter(data); 0462 } 0463 0464 spy.wait(10); 0465 0466 QCOMPARE(m_ctrl->canConnect(), canConnectStatus); 0467 0468 if(isGameMaster && !campaignPath.isNull()) 0469 QVERIFY2(m_ctrl->validCampaignPath(), QString("campaignPath: %1").arg(campaignPath).toStdString().c_str()); 0470 } 0471 0472 void ProfileControllerTest::canConnect_data() 0473 { 0474 QTest::addColumn<QString>("profileName"); 0475 QTest::addColumn<QString>("playerName"); 0476 QTest::addColumn<QColor>("playerColor"); 0477 QTest::addColumn<QByteArray>("playerAvatar"); 0478 QTest::addColumn<bool>("isGameMaster"); 0479 QTest::addColumn<bool>("isServer"); 0480 QTest::addColumn<QString>("address"); 0481 QTest::addColumn<int>("port"); 0482 QTest::addColumn<QString>("campaignPath"); 0483 QTest::addColumn<QList<CharacterInfo>>("characters"); 0484 QTest::addColumn<bool>("canConnectStatus"); 0485 0486 auto badImg= IOHelper::imageToData(IOHelper::readImageFromFile(":/img/arbre_500.jpg")); 0487 auto goodImg= IOHelper::imageToData(IOHelper::readImageFromFile(":/img/arbre_square_500.jpg")); 0488 QTemporaryDir dir; 0489 dir.setAutoRemove(false); 0490 dir.isValid(); 0491 0492 // No valid field 0493 QTest::addRow("connect1") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0494 << QString() << QList<CharacterInfo>() << false; 0495 0496 // One valid field 0497 QTest::addRow("connect2") << QString("test") << QString() << QColor() << QByteArray() << false << false << QString() 0498 << 0 << QString() << QList<CharacterInfo>() << false; 0499 0500 QTest::addRow("connect3") << QString() << QString("test") << QColor() << QByteArray() << false << false << QString() 0501 << 0 << QString() << QList<CharacterInfo>() << false; 0502 0503 QTest::addRow("connect4") << QString() << QString() << QColor(Qt::blue) << QByteArray() << false << false 0504 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0505 0506 QTest::addRow("connect5") << QString() << QString() << QColor() << badImg << false << false << QString() << 0 0507 << QString() << QList<CharacterInfo>() << false; 0508 QTest::addRow("connect5") << QString() << QString() << QColor() << goodImg << false << false << QString() << 0 0509 << QString() << QList<CharacterInfo>() << false; 0510 QTest::addRow("connect6") << QString() << QString() << QColor() << QByteArray() << true << false << QString() << 0 0511 << QString() << QList<CharacterInfo>() << false; 0512 QTest::addRow("connect7") << QString() << QString() << QColor() << QByteArray() << false << true << QString() << 0 0513 << QString() << QList<CharacterInfo>() << false; 0514 QTest::addRow("connect8") << QString() << QString() << QColor() << QByteArray() << false << false 0515 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0516 QTest::addRow("connect9") << QString() << QString() << QColor() << QByteArray() << false << false << QString() 0517 << 6660 << QString() << QList<CharacterInfo>() << false; 0518 QTest::addRow("connect10") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0519 << dir.path() << QList<CharacterInfo>() << false; 0520 0521 QTest::addRow("connect11") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0522 << QString() << QList<CharacterInfo>{{QString(), QString(), QColor(), QByteArray()}} 0523 << false; 0524 0525 QTest::addRow("connect12") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0526 << QString() 0527 << QList<CharacterInfo>{{QString(), QString("Player"), QColor(), QByteArray()}} << false; 0528 0529 QTest::addRow("connect13") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0530 << QString() 0531 << QList<CharacterInfo>{{QString(), QString(), QColor(Qt::blue), QByteArray()}} << false; 0532 0533 QTest::addRow("connect14") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0534 << QString() << QList<CharacterInfo>{{QString(), QString(), QColor(), badImg}} << false; 0535 0536 QTest::addRow("connect15") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0537 << QString() << QList<CharacterInfo>{{QString(), QString(), QColor(), goodImg}} << false; 0538 0539 // two valid fields 0540 QTest::addRow("connect16") << QString("test") << QString("test") << QColor() << QByteArray() << false << false 0541 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0542 0543 QTest::addRow("connect17") << QString() << QString("test") << QColor(Qt::blue) << QByteArray() << false << false 0544 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0545 0546 QTest::addRow("connect18") << QString() << QString() << QColor(Qt::blue) << goodImg << false << false << QString() 0547 << 0 << QString() << QList<CharacterInfo>() << false; 0548 QTest::addRow("connect19") << QString() << QString() << QColor(Qt::blue) << badImg << false << false << QString() 0549 << 0 << QString() << QList<CharacterInfo>() << false; 0550 0551 QTest::addRow("connect20") << QString() << QString() << QColor() << badImg << true << false << QString() << 0 0552 << QString() << QList<CharacterInfo>() << false; 0553 QTest::addRow("connect21") << QString() << QString() << QColor() << QByteArray() << true << true << QString() << 0 0554 << QString() << QList<CharacterInfo>() << false; 0555 0556 QTest::addRow("connect22") << QString() << QString() << QColor() << QByteArray() << false << true 0557 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0558 0559 QTest::addRow("connect23") << QString() << QString() << QColor() << QByteArray() << false << false 0560 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0561 0562 QTest::addRow("connect24") << QString() << QString() << QColor() << QByteArray() << false << false << QString() 0563 << 6660 << dir.path() << QList<CharacterInfo>() << false; 0564 0565 QTest::addRow("connect25") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0566 << dir.path() 0567 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), QByteArray()}} 0568 << false; 0569 QTest::addRow("connect26") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0570 << dir.path() << QList<CharacterInfo>{{QString(), QString(), QColor(Qt::blue), goodImg}} 0571 << false; 0572 QTest::addRow("connect27") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0573 << dir.path() << QList<CharacterInfo>{{QString(), QString(), QColor(Qt::blue), badImg}} 0574 << false; 0575 QTest::addRow("connect28") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0576 << dir.path() << QList<CharacterInfo>{{QString(), QString("player"), QColor(), goodImg}} 0577 << false; 0578 QTest::addRow("connect29") << QString() << QString() << QColor() << QByteArray() << false << false << QString() << 0 0579 << dir.path() << QList<CharacterInfo>{{QString(), QString("player"), QColor(), badImg}} 0580 << false; 0581 0582 // three valid fields 0583 QTest::addRow("connect30") << QString("test") << QString("test") << QColor(Qt::blue) << QByteArray() << false 0584 << false << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0585 QTest::addRow("connect31") << QString() << QString("test") << QColor(Qt::blue) << goodImg << false << false 0586 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0587 QTest::addRow("connect32") << QString() << QString("test") << QColor(Qt::blue) << badImg << false << false 0588 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0589 QTest::addRow("connect33") << QString() << QString() << QColor(Qt::blue) << goodImg << true << false << QString() 0590 << 0 << QString() << QList<CharacterInfo>() << false; 0591 QTest::addRow("connect34") << QString() << QString() << QColor(Qt::blue) << badImg << true << false << QString() 0592 << 0 << QString() << QList<CharacterInfo>() << false; 0593 QTest::addRow("connect35") << QString() << QString() << QColor() << badImg << true << true << QString() << 0 0594 << QString() << QList<CharacterInfo>() << false; 0595 QTest::addRow("connect36") << QString() << QString() << QColor() << goodImg << true << true << QString() << 0 0596 << QString() << QList<CharacterInfo>() << false; 0597 0598 QTest::addRow("connect37") << QString() << QString() << QColor() << QByteArray() << true << true 0599 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0600 QTest::addRow("connect38") << QString() << QString() << QColor() << QByteArray() << false << true 0601 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0602 0603 QTest::addRow("connect39") << QString() << QString() << QColor() << QByteArray() << false << false 0604 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0605 QTest::addRow("connect40") << QString() << QString() << QColor() << QByteArray() << false << false << QString() 0606 << 6660 << dir.path() 0607 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), badImg}} 0608 << false; 0609 QTest::addRow("connect41") << QString() << QString() << QColor() << QByteArray() << false << false << QString() 0610 << 6660 << dir.path() 0611 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0612 << false; 0613 0614 // Four valid fields 0615 QTest::addRow("connect42") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << false << false 0616 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0617 QTest::addRow("connect43") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << false << false 0618 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0619 QTest::addRow("connect44") << QString() << QString("test") << QColor(Qt::blue) << goodImg << true << false 0620 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0621 QTest::addRow("connect45") << QString() << QString("test") << QColor(Qt::blue) << badImg << true << false 0622 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0623 QTest::addRow("connect46") << QString() << QString() << QColor(Qt::blue) << badImg << true << true << QString() << 0 0624 << QString() << QList<CharacterInfo>() << false; 0625 QTest::addRow("connect47") << QString() << QString() << QColor(Qt::blue) << goodImg << true << true << QString() 0626 << 0 << QString() << QList<CharacterInfo>() << false; 0627 0628 QTest::addRow("connect48") << QString() << QString() << QColor() << goodImg << true << true << QString("localhost") 0629 << 0 << QString() << QList<CharacterInfo>() << false; 0630 QTest::addRow("connect49") << QString() << QString() << QColor() << badImg << true << true << QString("localhost") 0631 << 0 << QString() << QList<CharacterInfo>() << false; 0632 QTest::addRow("connect50") << QString() << QString() << QColor() << QByteArray() << true << true 0633 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0634 QTest::addRow("connect51") << QString() << QString() << QColor() << QByteArray() << false << true 0635 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0636 QTest::addRow("connect52") << QString() << QString() << QColor() << QByteArray() << false << false 0637 << QString("localhost") << 6660 << dir.path() 0638 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0639 << false; 0640 0641 // five valid fields 0642 QTest::addRow("connect53") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << true << false 0643 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0644 QTest::addRow("connect54") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << true << false 0645 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0646 QTest::addRow("connect55") << QString() << QString("test") << QColor(Qt::blue) << badImg << true << true 0647 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0648 QTest::addRow("connect56") << QString() << QString("test") << QColor(Qt::blue) << goodImg << true << true 0649 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0650 QTest::addRow("connect57") << QString() << QString() << QColor(Qt::blue) << goodImg << true << true 0651 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0652 QTest::addRow("connect58") << QString() << QString() << QColor(Qt::blue) << badImg << true << true 0653 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0654 QTest::addRow("connect59") << QString() << QString() << QColor() << badImg << true << true << QString("localhost") 0655 << 6660 << QString() << QList<CharacterInfo>() << false; 0656 QTest::addRow("connect60") << QString() << QString() << QColor() << goodImg << true << true << QString("localhost") 0657 << 6660 << QString() << QList<CharacterInfo>() << false; 0658 QTest::addRow("connect61") << QString() << QString() << QColor() << QByteArray() << true << true 0659 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0660 QTest::addRow("connect62") << QString() << QString() << QColor() << QByteArray() << false << true 0661 << QString("localhost") << 6660 << dir.path() 0662 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0663 << false; 0664 0665 // six valid fields 0666 QTest::addRow("connect63") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << true << true 0667 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0668 QTest::addRow("connect64") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << true << true 0669 << QString() << 0 << QString() << QList<CharacterInfo>() << false; 0670 QTest::addRow("connect65") << QString() << QString("test") << QColor(Qt::blue) << goodImg << true << true 0671 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0672 QTest::addRow("connect66") << QString() << QString("test") << QColor(Qt::blue) << badImg << true << true 0673 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0674 0675 QTest::addRow("connect67") << QString() << QString() << QColor(Qt::blue) << goodImg << true << true 0676 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0677 QTest::addRow("connect68") << QString() << QString() << QColor(Qt::blue) << badImg << true << true 0678 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0679 0680 QTest::addRow("connect69") << QString() << QString() << QColor() << goodImg << true << true << QString("localhost") 0681 << 6660 << dir.path() << QList<CharacterInfo>() << false; 0682 QTest::addRow("connect70") << QString() << QString() << QColor() << badImg << true << true << QString("localhost") 0683 << 6660 << dir.path() << QList<CharacterInfo>() << false; 0684 0685 QTest::addRow("connect71") << QString() << QString() << QColor() << QByteArray() << true << true 0686 << QString("localhost") << 6660 << dir.path() 0687 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0688 << false; 0689 0690 // seven valid fields 0691 QTest::addRow("connect72") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << true << true 0692 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0693 QTest::addRow("connect73") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << true << true 0694 << QString("localhost") << 0 << QString() << QList<CharacterInfo>() << false; 0695 0696 QTest::addRow("connect74") << QString() << QString("test") << QColor(Qt::blue) << badImg << true << true 0697 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0698 QTest::addRow("connect75") << QString() << QString("test") << QColor(Qt::blue) << goodImg << true << true 0699 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0700 0701 QTest::addRow("connect76") << QString() << QString() << QColor(Qt::blue) << badImg << true << true 0702 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0703 QTest::addRow("connect77") << QString() << QString() << QColor(Qt::blue) << goodImg << true << true 0704 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0705 0706 QTest::addRow("connect78") << QString() << QString() << QColor() << badImg << true << true << QString("localhost") 0707 << 6660 << dir.path() 0708 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0709 << false; 0710 QTest::addRow("connect79") << QString() << QString() << QColor() << goodImg << true << true << QString("localhost") 0711 << 6660 << dir.path() 0712 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0713 << false; 0714 0715 // eight valid fields 0716 QTest::addRow("connect80") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << true << true 0717 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0718 QTest::addRow("connect81") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << true << true 0719 << QString("localhost") << 6660 << QString() << QList<CharacterInfo>() << false; 0720 0721 QTest::addRow("connect82") << QString() << QString("test") << QColor(Qt::blue) << badImg << true << true 0722 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0723 QTest::addRow("connect83") << QString() << QString("test") << QColor(Qt::blue) << goodImg << true << true 0724 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0725 0726 QTest::addRow("connect84") << QString() << QString() << QColor(Qt::blue) << badImg << true << true 0727 << QString("localhost") << 6660 << dir.path() 0728 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0729 << false; 0730 QTest::addRow("connect85") << QString() << QString() << QColor(Qt::blue) << goodImg << true << true 0731 << QString("localhost") << 6660 << dir.path() 0732 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0733 << false; 0734 0735 // nine valid field 0736 QTest::addRow("connect86") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << true << true 0737 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << false; 0738 QTest::addRow("connect87") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << true << true 0739 << QString("localhost") << 6660 << dir.path() << QList<CharacterInfo>() << true; 0740 0741 QTest::addRow("connect88") << QString() << QString("test") << QColor(Qt::blue) << badImg << true << true 0742 << QString("localhost") << 6660 << dir.path() 0743 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0744 << false; 0745 QTest::addRow("connect89") << QString() << QString("test") << QColor(Qt::blue) << goodImg << true << true 0746 << QString("localhost") << 6660 << dir.path() 0747 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0748 << false; 0749 0750 // ten valid field 0751 0752 // bad img 0753 QTest::addRow("connect90") << QString("test") << QString("test") << QColor(Qt::blue) << badImg << true << true 0754 << QString("localhost") << 6660 << dir.path() 0755 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), goodImg}} 0756 << false; 0757 0758 // false 0759 QTest::addRow("connect91") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << true << true 0760 << QString("localhost") << 6660 << dir.path() 0761 << QList<CharacterInfo>{{QString("uuid"), QString("player"), QColor(Qt::blue), goodImg}} 0762 << true; // no player with game master 0763 0764 QTest::addRow("connect92") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << false << true 0765 << QString("localhost") << 6660 << dir.path() 0766 << QList<CharacterInfo>{{QString(), QString("player"), QColor(Qt::blue), badImg}} 0767 << false; 0768 0769 QTest::addRow("connect93") << QString("test") << QString("test") << QColor(Qt::blue) << goodImg << false << true 0770 << QString("localhost") << 6660 << QString() 0771 << QList<CharacterInfo>{{QString("uuid"), QString("player"), QColor(Qt::blue), goodImg}} 0772 << true; 0773 } 0774 QTEST_MAIN(ProfileControllerTest); 0775 #include "tst_profilecontroller.moc"