File indexing completed on 2024-05-12 05:40:51

0001 #include "helper.h"
0002 #include "charactersheet/charactersheet.h"
0003 #include "charactersheet_widgets/sheetwidget.h"
0004 #include "controller/view_controller/selectconnprofilecontroller.h"
0005 #include "controller/view_controller/sharednotecontroller.h"
0006 #include "controller/view_controller/webpagecontroller.h"
0007 #include "data/charactervision.h"
0008 #include "media/mediatype.h"
0009 #include "mindmap/data/linkcontroller.h"
0010 #include "mindmap/data/mindnode.h"
0011 #include "model/filteredcharactermodel.h"
0012 #include "model/participantmodel.h"
0013 #include "network/networkmessagewriter.h"
0014 #include "network/serverconnection.h"
0015 #include "test_root_path.h"
0016 #include "utils/iohelper.h"
0017 
0018 #include <QBrush>
0019 #include <QColor>
0020 #include <QCursor>
0021 #include <QDate>
0022 #include <QFont>
0023 #include <QFontDatabase>
0024 #include <QIcon>
0025 #include <QLine>
0026 #include <QMetaObject>
0027 #include <QMetaProperty>
0028 #include <QMetaType>
0029 #include <QPainterPath>
0030 #include <QPixmap>
0031 #include <QPolygon>
0032 #include <QPolygonF>
0033 #include <QRect>
0034 #include <QRectF>
0035 #include <QRegularExpression>
0036 #include <QSignalSpy>
0037 #include <QTest>
0038 #include <QUuid>
0039 #include <QVariant>
0040 #include <QtHttpServer>
0041 #include <limits>
0042 
0043 namespace Helper
0044 {
0045 QVariantList values(QMetaType type, QVariant currentValue, QObject* parent= nullptr)
0046 {
0047     QVariantList res;
0048     switch(type.id())
0049     {
0050     case QMetaType::User:
0051     case QMetaType::UnknownType:
0052     case QMetaType::Void:
0053     case QMetaType::Nullptr:
0054     case QMetaType::VoidStar:
0055     case QMetaType::QObjectStar:
0056     case QMetaType::QVariantPair:
0057     case QMetaType::QVariant:
0058     case QMetaType::QVariantList:
0059     case QMetaType::QColorSpace:
0060     case QMetaType::QModelIndex:
0061     case QMetaType::QPersistentModelIndex:
0062     case QMetaType::QTextLength:
0063     case QMetaType::QVariantMap:
0064     case QMetaType::QVariantHash:
0065     case QMetaType::QTextFormat:
0066     case QMetaType::QRegion:
0067     case QMetaType::QBitArray:
0068     case QMetaType::QPalette:
0069     case QMetaType::QKeySequence:
0070     case QMetaType::QSizePolicy:
0071         break;
0072     case QMetaType::Char16:
0073         res= {static_cast<char16_t>('A'), static_cast<char16_t>('1'), static_cast<char16_t>('z'),
0074               std::numeric_limits<char16_t>::max(), std::numeric_limits<char16_t>::lowest()};
0075         break;
0076     case QMetaType::Char32:
0077         res= {static_cast<char32_t>('A'), static_cast<char32_t>('1'), static_cast<char32_t>('z'),
0078               std::numeric_limits<char32_t>::max(), std::numeric_limits<char32_t>::lowest()};
0079         break;
0080     case QMetaType::Bool:
0081         res= {true, false};
0082         break;
0083     case QMetaType::Int:
0084         res= {std::numeric_limits<int>::max(), std::numeric_limits<int>::lowest()};
0085         break;
0086     case QMetaType::UInt:
0087         res= {std::numeric_limits<uint>::max(), std::numeric_limits<uint>::lowest()};
0088         break;
0089     case QMetaType::Double:
0090         res= {std::numeric_limits<double>::max(), std::numeric_limits<double>::lowest()};
0091         break;
0092     case QMetaType::QChar:
0093         res= {QChar('A'), QChar('1'), QChar('z')};
0094         break;
0095     case QMetaType::QString:
0096         res= {QString("aaaa"), QString("zzzz"), QString("ppppp")};
0097         break;
0098     case QMetaType::QByteArray:
0099         res= {QByteArray(), QByteArray("aaaa"), QByteArray("zzzz")};
0100         break;
0101     case QMetaType::Long:
0102         res= {QVariant::fromValue(std::numeric_limits<long>::max()),
0103               QVariant::fromValue(std::numeric_limits<long>::min())};
0104         break;
0105     case QMetaType::LongLong:
0106         res= {std::numeric_limits<long long>::max(), std::numeric_limits<long long>::min()};
0107         break;
0108     case QMetaType::Short:
0109         res= {std::numeric_limits<short>::max(), std::numeric_limits<short>::min()};
0110         break;
0111     case QMetaType::Char:
0112         res= {static_cast<char>('A'), static_cast<char>('1'), static_cast<char>('z'), std::numeric_limits<char>::max(),
0113               std::numeric_limits<char>::min()};
0114         break;
0115     case QMetaType::ULong:
0116         res= {QVariant::fromValue(std::numeric_limits<unsigned long>::max()),
0117               QVariant::fromValue(std::numeric_limits<unsigned long>::min())};
0118         break;
0119     case QMetaType::ULongLong:
0120         res= {std::numeric_limits<unsigned long long>::max(), std::numeric_limits<unsigned long long>::min()};
0121         break;
0122     case QMetaType::UShort:
0123         res= {std::numeric_limits<unsigned short>::max(), std::numeric_limits<unsigned short>::min()};
0124         break;
0125     case QMetaType::SChar:
0126         res= {static_cast<signed char>('A'), static_cast<signed char>('1'), static_cast<signed char>('z'),
0127               std::numeric_limits<signed char>::max(), std::numeric_limits<signed char>::min()};
0128         break;
0129     case QMetaType::UChar:
0130         res= {static_cast<unsigned char>('A'), static_cast<unsigned char>('1'), static_cast<unsigned char>('z'),
0131               std::numeric_limits<unsigned char>::max(), std::numeric_limits<unsigned char>::min()};
0132         break;
0133     case QMetaType::Float:
0134         res= {std::numeric_limits<float>::max(), std::numeric_limits<float>::min()};
0135         break;
0136     case QMetaType::QCursor:
0137         res= {QVariant::fromValue(QCursor(Qt::ArrowCursor)), QVariant::fromValue(QCursor(Qt::SizeHorCursor))};
0138         break;
0139     case QMetaType::QDate:
0140         res= {QDate::currentDate(), QDate()};
0141         break;
0142     case QMetaType::QSize:
0143         res= {QSize(10, 10), QSize(100, 100), QSize(1, 1), QSize()};
0144         break;
0145     case QMetaType::QTime:
0146         res= {QTime(10, 10), QTime(1, 1), QTime(23, 34), QTime::currentTime()};
0147         break;
0148     case QMetaType::QPolygon:
0149         res= {QPolygon({QPoint{0, 0}, QPoint{10, 0}, QPoint{10, 10}, QPoint{0, 10}}),
0150               QPolygon({QPoint{0, 0}, QPoint{100, 0}, QPoint{100, 100}, QPoint{0, 100}})};
0151         break;
0152     case QMetaType::QPolygonF:
0153         res= {QPolygonF({QPointF{0., 0.}, QPointF{10., 0.}, QPointF{10., 10.}, QPointF{0., 10.}}),
0154               QPolygonF({QPointF{0., 0.}, QPointF{100., 0.}, QPointF{100., 100.}, QPointF{0., 100.}})};
0155         break;
0156     case QMetaType::QColor:
0157         res= {QColor(Qt::black), QColor(Qt::red), QColor(Qt::green), QColor(Qt::darkCyan)};
0158         break;
0159     case QMetaType::QSizeF:
0160         res= {QSizeF(10., 10.), QSizeF(100., 100.), QSizeF(1., 1.), QSizeF()};
0161         break;
0162     case QMetaType::QRectF:
0163         res= {QRectF(10., 10., 10., 10.), QRectF(100., 100., 100., 100.), QRectF(1., 1., 1., 1.),
0164               QRectF(12., 12., 12., 12.)};
0165         break;
0166     case QMetaType::QLine:
0167         res= {QLine(10, 10, 20, 20), QLine(100, 100, 200, 200), QLine()};
0168         break;
0169     case QMetaType::QStringList:
0170         res= {QStringList{"aaa", "bbbb", "cccc"}, QStringList{"zzz", "yyyyy", "xxxxx"}};
0171         break;
0172     case QMetaType::QIcon:
0173         res= {QIcon(":/img/arbre_square_500.jpg"), QIcon(":/img/lion.jpg"), QIcon(":/img/white.png")};
0174         break;
0175     case QMetaType::QPen:
0176         res= {QStringList{"aaa", "bbbb", "cccc"}, QStringList{"zzz", "yyyyy", "xxxxx"}};
0177         break;
0178     case QMetaType::QLineF:
0179         res= {QLineF(10., 10., 20., 20.), QLineF(100., 100., 200., 200.), QLineF()};
0180         break;
0181     case QMetaType::QRect:
0182         res= {QRect(10, 10, 10, 10), QRect(100, 100, 100, 100), QRect(1, 1, 1, 1), QRect()};
0183         break;
0184     case QMetaType::QPoint:
0185         res= {QPoint(0, 0), QPoint{10, 10}, QPoint{100, 100}, QPoint{50, 500}};
0186         break;
0187     case QMetaType::QUrl:
0188         res= {QUrl{"https://www.rolisteam.org"}, QUrl{"https://doc.rolisteam.org"}, QUrl{"https://google.com"},
0189               QUrl{"https://fr.wikipedia.org"}, QUrl{"qrc:/img/lion.jpg"}};
0190         break;
0191     case QMetaType::QRegularExpression:
0192         res= {QRegularExpression{"(.*)k(.*)"}, QRegularExpression{"([0-9]+)C([0-9]+)"}};
0193         break;
0194     case QMetaType::QDateTime:
0195         res= {QDateTime::currentDateTime(), QDateTime(QDate(2012, 7, 6), QTime(8, 30, 0))};
0196         break;
0197     case QMetaType::QPointF:
0198         res= {QPointF(0., 0.), QPointF{10., 10.}, QPointF{100., 100.}, QPointF{50., 500.}};
0199         break;
0200     case QMetaType::QFont:
0201     {
0202         auto italic= QFontDatabase::systemFont(QFontDatabase::GeneralFont);
0203         italic.setItalic(true);
0204 
0205         auto bold= QFontDatabase::systemFont(QFontDatabase::TitleFont);
0206         bold.setBold(true);
0207 
0208         res= {QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont),
0209               QFontDatabase::systemFont(QFontDatabase::FixedFont), italic, bold};
0210     }
0211     break;
0212     case QMetaType::QBrush:
0213         res= {QBrush{Qt::red}, QBrush{Qt::black}, QBrush{Qt::green}};
0214         break;
0215     case QMetaType::QImage:
0216         res= {QImage(":/img/arbre_square_500.jpg"), QImage(":/img/lion.jpg"), QImage(":/img/white.png")};
0217         break;
0218     case QMetaType::QPixmap:
0219         res= {QPixmap(":/img/arbre_square_500.jpg"), QPixmap(":/img/lion.jpg"), QPixmap(":/img/white.png")};
0220         break;
0221     case QMetaType::QLocale:
0222         break;
0223     case QMetaType::QBitmap:
0224         break;
0225     case QMetaType::QTransform:
0226         break;
0227     case QMetaType::QMatrix4x4:
0228         break;
0229     case QMetaType::QVector2D:
0230         break;
0231     case QMetaType::QVector3D:
0232         break;
0233     case QMetaType::QVector4D:
0234         break;
0235     case QMetaType::QQuaternion:
0236         break;
0237     case QMetaType::QEasingCurve:
0238         break;
0239     case QMetaType::QJsonValue:
0240         break;
0241     case QMetaType::QJsonObject:
0242         res= {QJsonObject({{"key1", "value1"}, {"key2", "value2"}}),
0243               QJsonObject({{"keyA", "valueA"}, {"keyB", "valueB"}})};
0244         break;
0245     case QMetaType::QJsonArray:
0246         break;
0247     case QMetaType::QJsonDocument:
0248         break;
0249     case QMetaType::QCborValue:
0250         break;
0251     case QMetaType::QCborArray:
0252         break;
0253     case QMetaType::QCborMap:
0254         break;
0255     case QMetaType::QCborSimpleType:
0256         break;
0257     case QMetaType::QUuid:
0258         res= {QUuid().createUuid(), QUuid().createUuid()};
0259         break;
0260     case QMetaType::QByteArrayList:
0261         break;
0262     }
0263 
0264     if(res.empty())
0265     {
0266         if(qMetaTypeId<CharacterSheet*>() == type.id())
0267         {
0268             res= {QVariant::fromValue(new CharacterSheet(parent)), QVariant::fromValue(new CharacterSheet(parent))};
0269         }
0270         else if(qMetaTypeId<Core::ScaleUnit>() == type.id())
0271         {
0272             res= {Core::ScaleUnit::M,    Core::ScaleUnit::KM,   Core::ScaleUnit::CM,   Core::ScaleUnit::MILE,
0273                   Core::ScaleUnit::YARD, Core::ScaleUnit::INCH, Core::ScaleUnit::FEET, Core::ScaleUnit::PX};
0274         }
0275         else if(qMetaTypeId<Core::PermissionMode>() == type.id())
0276         {
0277             res= {Core::PermissionMode::GM_ONLY, Core::PermissionMode::PC_MOVE, Core::PermissionMode::PC_ALL};
0278         }
0279         else if(qMetaTypeId<Core::GridPattern>() == type.id())
0280         {
0281             res= {QVariant::fromValue(Core::GridPattern::HEXAGON), QVariant::fromValue(Core::GridPattern::SQUARE),
0282                   QVariant::fromValue(Core::GridPattern::NONE), QVariant::fromValue(Core::GridPattern::OCTOGON)};
0283         }
0284         else if(qMetaTypeId<Core::VisibilityMode>() == type.id())
0285         {
0286             res= {QVariant::fromValue(Core::VisibilityMode::NONE), QVariant::fromValue(Core::VisibilityMode::FOGOFWAR),
0287                   QVariant::fromValue(Core::VisibilityMode::ALL), QVariant::fromValue(Core::VisibilityMode::HIDDEN)};
0288         }
0289         else if(qMetaTypeId<Core::Layer>() == type.id())
0290         {
0291             res= {QVariant::fromValue(Core::Layer::GROUND),          QVariant::fromValue(Core::Layer::OBJECT),
0292                   QVariant::fromValue(Core::Layer::CHARACTER_LAYER), QVariant::fromValue(Core::Layer::FOG),
0293                   QVariant::fromValue(Core::Layer::GRIDLAYER),       QVariant::fromValue(Core::Layer::NONE),
0294                   QVariant::fromValue(Core::Layer::GAMEMASTER_LAYER)};
0295         }
0296         else if(qMetaTypeId<Core::SelectableTool>() == type.id())
0297         {
0298             res= {QVariant::fromValue(Core::SelectableTool::PEN),
0299                   QVariant::fromValue(Core::SelectableTool::EMPTYRECT),
0300                   QVariant::fromValue(Core::SelectableTool::LINE),
0301                   QVariant::fromValue(Core::SelectableTool::FILLRECT),
0302                   QVariant::fromValue(Core::SelectableTool::EMPTYELLIPSE),
0303                   QVariant::fromValue(Core::SelectableTool::FILLEDELLIPSE),
0304                   QVariant::fromValue(Core::SelectableTool::TEXT),
0305                   QVariant::fromValue(Core::SelectableTool::HANDLER),
0306                   QVariant::fromValue(Core::SelectableTool::NonPlayableCharacter),
0307                   QVariant::fromValue(Core::SelectableTool::PlayableCharacter),
0308                   QVariant::fromValue(Core::SelectableTool::IMAGE),
0309                   QVariant::fromValue(Core::SelectableTool::RULE),
0310                   QVariant::fromValue(Core::SelectableTool::PATH),
0311                   QVariant::fromValue(Core::SelectableTool::ANCHOR),
0312                   QVariant::fromValue(Core::SelectableTool::TEXTBORDER),
0313                   QVariant::fromValue(Core::SelectableTool::PIPETTE),
0314                   QVariant::fromValue(Core::SelectableTool::BUCKET),
0315                   QVariant::fromValue(Core::SelectableTool::HIGHLIGHTER)};
0316         }
0317         else if(qMetaTypeId<Core::EditionMode>() == type.id())
0318         {
0319             res= {QVariant::fromValue(Core::EditionMode::Painting), QVariant::fromValue(Core::EditionMode::Mask),
0320                   QVariant::fromValue(Core::EditionMode::Unmask)};
0321         }
0322         else if(qMetaTypeId<Core::ContentType>() == type.id())
0323         {
0324             res= {QVariant::fromValue(Core::ContentType::VECTORIALMAP),
0325                   QVariant::fromValue(Core::ContentType::PICTURE),
0326                   QVariant::fromValue(Core::ContentType::NOTES),
0327                   QVariant::fromValue(Core::ContentType::CHARACTERSHEET),
0328                   QVariant::fromValue(Core::ContentType::SHAREDNOTE),
0329                   QVariant::fromValue(Core::ContentType::PDF),
0330                   QVariant::fromValue(Core::ContentType::WEBVIEW),
0331                   QVariant::fromValue(Core::ContentType::INSTANTMESSAGING),
0332                   QVariant::fromValue(Core::ContentType::MINDMAP),
0333                   QVariant::fromValue(Core::ContentType::UNKNOWN)};
0334         }
0335         else if(qMetaTypeId<Core::State>() == type.id())
0336         {
0337             res= {QVariant::fromValue(Core::State::Unloaded), QVariant::fromValue(Core::State::Hidden),
0338                   QVariant::fromValue(Core::State::Displayed)};
0339         }
0340         else if(qMetaTypeId<Core::MediaType>() == type.id())
0341         {
0342             res= {QVariant::fromValue(Core::MediaType::Unknown),
0343                   QVariant::fromValue(Core::MediaType::TokenFile),
0344                   QVariant::fromValue(Core::MediaType::ImageFile),
0345                   QVariant::fromValue(Core::MediaType::MapFile),
0346                   QVariant::fromValue(Core::MediaType::TextFile),
0347                   QVariant::fromValue(Core::MediaType::CharacterSheetFile),
0348                   QVariant::fromValue(Core::MediaType::PdfFile),
0349                   QVariant::fromValue(Core::MediaType::WebpageFile),
0350                   QVariant::fromValue(Core::MediaType::MindmapFile),
0351                   QVariant::fromValue(Core::MediaType::AudioFile),
0352                   QVariant::fromValue(Core::MediaType::PlayListFile)};
0353         }
0354         else if(qMetaTypeId<Core::LoadingMode>() == type.id())
0355         {
0356             res= {QVariant::fromValue(Core::LoadingMode::Internal), QVariant::fromValue(Core::LoadingMode::Linked)};
0357         }
0358         else if(qMetaTypeId<std::vector<QPointF>>() == type.id())
0359         {
0360             res= {QVariant::fromValue(std::vector({QPointF(10., 10.), QPointF(100., 100.), QPointF(300., 100.)})),
0361                   QVariant::fromValue(std::vector({QPointF(500., 10.), QPointF(100., 400.), QPointF(10., 1000.)}))};
0362         }
0363         else if(qMetaTypeId<QList<QPointF>>() == type.id())
0364         {
0365             res= {QVariant::fromValue(QList({QPointF(10., 10.), QPointF(100., 100.), QPointF(300., 100.)})),
0366                   QVariant::fromValue(QList({QPointF(500., 10.), QPointF(100., 400.), QPointF(10., 1000.)}))};
0367         }
0368         else if(qMetaTypeId<SelectConnProfileController::ConnectionState>() == type.id())
0369         {
0370             res= {
0371                 QVariant::fromValue(SelectConnProfileController::ConnectionState::LOADING),
0372                 QVariant::fromValue(SelectConnProfileController::ConnectionState::LOADED),
0373                 QVariant::fromValue(SelectConnProfileController::ConnectionState::CONNECTING),
0374                 QVariant::fromValue(SelectConnProfileController::ConnectionState::IDLE),
0375             };
0376         }
0377         /*else if(qMetaTypeId<ParticipantModel::Permission>() == type.id())
0378         {
0379             res= {QVariant::fromValue(ParticipantModel::Permission::readWrite),
0380                   QVariant::fromValue(ParticipantModel::Permission::readOnly),
0381                   QVariant::fromValue(ParticipantModel::Permission::hidden)};
0382         }*/
0383         else if(qMetaTypeId<SharedNoteController::HighlightedSyntax>() == type.id())
0384         {
0385             res= {QVariant::fromValue(SharedNoteController::HighlightedSyntax::None),
0386                   QVariant::fromValue(SharedNoteController::HighlightedSyntax::MarkDown)};
0387         }
0388         else if(qMetaTypeId<WebpageController::State>() == type.id())
0389         {
0390             res= {QVariant::fromValue(WebpageController::State::localIsGM),
0391                   QVariant::fromValue(WebpageController::State::LocalIsPlayer),
0392                   QVariant::fromValue(WebpageController::State::RemoteView)};
0393         }
0394         else if(qMetaTypeId<WebpageController::SharingMode>() == type.id())
0395         {
0396             res= {QVariant::fromValue(WebpageController::SharingMode::Url),
0397                   QVariant::fromValue(WebpageController::SharingMode::None)};
0398         }
0399         else if(qMetaTypeId<Qt::CaseSensitivity>() == type.id())
0400         {
0401             res= {QVariant::fromValue(Qt::CaseInsensitive), QVariant::fromValue(Qt::CaseSensitive)};
0402         }
0403         else if(qMetaTypeId<campaign::FilteredCharacterModel::Definition>() == type.id())
0404         {
0405             res= {QVariant::fromValue(campaign::FilteredCharacterModel::Definition::All),
0406                   QVariant::fromValue(campaign::FilteredCharacterModel::Definition::With),
0407                   QVariant::fromValue(campaign::FilteredCharacterModel::Definition::Without)};
0408         }
0409         else if(qMetaTypeId<campaign::FilteredCharacterModel::HealthState>() == type.id())
0410         {
0411             res= {QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_All),
0412                   QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_Full),
0413                   QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_Dead),
0414                   QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_Injured)};
0415         }
0416         else if(qMetaTypeId<campaign::FilteredCharacterModel::HealthState>() == type.id())
0417         {
0418             res= {QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_All),
0419                   QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_Full),
0420                   QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_Dead),
0421                   QVariant::fromValue(campaign::FilteredCharacterModel::HealthState::HS_Injured)};
0422         }
0423         else if(qMetaTypeId<QPainterPath>() == type.id())
0424         {
0425             res= {QVariant::fromValue(QPainterPath(QPointF(1200., 500.))), QVariant::fromValue(QPainterPath(QPointF(200., 100.))),
0426                   QVariant::fromValue(QPainterPath())};
0427         }
0428         else if(qMetaTypeId<Person*>() == type.id())
0429         {
0430             res= {QVariant::fromValue(new Player()), QVariant::fromValue(new Player())};
0431         }
0432         else if(qMetaTypeId<ServerConnection*>() == type.id())
0433         {
0434             res= {QVariant::fromValue(new ServerConnection(nullptr)),
0435                   QVariant::fromValue(new ServerConnection(nullptr))};
0436         }
0437         else if(qMetaTypeId<mindmap::PositionedItem*>() == type.id())
0438         {
0439             res= {QVariant::fromValue(new mindmap::MindNode()), QVariant::fromValue(new mindmap::MindNode())};
0440         }
0441         else if(qMetaTypeId<campaign::NonPlayableCharacter*>() == type.id())
0442         {
0443             res= {QVariant::fromValue(new campaign::NonPlayableCharacter()),
0444                   QVariant::fromValue(new campaign::NonPlayableCharacter())};
0445         }
0446         else if(qMetaTypeId<RolisteamTheme*>() == type.id())
0447         {
0448             res= {QVariant::fromValue(new RolisteamTheme())};
0449         }
0450         else if(qMetaTypeId<campaign::Campaign::State>() == type.id())
0451         {
0452             res= {QVariant::fromValue(campaign::Campaign::State::Ready),
0453                   QVariant::fromValue(campaign::Campaign::State::None),
0454                   QVariant::fromValue(campaign::Campaign::State::Checking)};
0455         }
0456         else if(qMetaTypeId<CharacterVision::SHAPE>() == type.id())
0457         {
0458             res= {QVariant::fromValue(CharacterVision::SHAPE::ANGLE),
0459                   QVariant::fromValue(CharacterVision::SHAPE::DISK)};
0460         }
0461         else if(qMetaTypeId<mindmap::LinkController::Direction>() == type.id())
0462         {
0463             res= {QVariant::fromValue(mindmap::LinkController::StartToEnd),
0464                   QVariant::fromValue(mindmap::LinkController::Both),
0465                   QVariant::fromValue(mindmap::LinkController::EndToStart)};
0466         }
0467     }
0468 
0469     if(res.empty())
0470     {
0471         qDebug() << "Unmanaged Type::" << type.id() << type.name();
0472     }
0473 
0474     if(res.removeOne(currentValue))
0475         res.append(currentValue);
0476 
0477     return res;
0478 }
0479 namespace cv= Core::vmapkeys;
0480 const std::map<QString, QVariant> buildRectController(bool filled, const QRectF& rect, const QPointF& pos)
0481 {
0482     return {{"filled", filled},
0483             {"tool", filled ? Core::SelectableTool::FILLRECT : Core::SelectableTool::EMPTYRECT},
0484             {"rect", rect},
0485             {"position", pos}};
0486 }
0487 
0488 const std::map<QString, QVariant> buildTextController(bool border, const QString& text, const QRectF& rect,
0489                                                       const QPointF& pos)
0490 {
0491     return {{"border", border},
0492             {"rect", rect},
0493             {"position", pos},
0494             {"text", text},
0495             {"tool", border ? Core::SelectableTool::TEXT : Core::SelectableTool::TEXTBORDER}};
0496 }
0497 
0498 const std::map<QString, QVariant> buildEllipseController(bool filled, qreal rx, qreal ry, const QPointF& pos)
0499 {
0500     return {{"filled", filled},
0501             {"tool", filled ? Core::SelectableTool::FILLEDELLIPSE : Core::SelectableTool::EMPTYELLIPSE},
0502             {"rx", rx},
0503             {"ry", ry},
0504             {"position", pos}};
0505 }
0506 
0507 const std::map<QString, QVariant> buildImageController(const QString& path, const QRectF& rect, const QPointF& pos)
0508 {
0509     return {{cv::KEY_PATH, path}, {"rect", rect}, {"tool", Core::SelectableTool::IMAGE}, {"position", pos}};
0510 }
0511 
0512 const std::map<QString, QVariant> buildPenController(bool filled, const std::vector<QPointF>& points,
0513                                                      const QPointF& pos)
0514 {
0515     return {{"filled", filled},
0516             {"tool", Core::SelectableTool::PEN},
0517             {"points", QVariant::fromValue(points)},
0518             {"position", pos}};
0519 }
0520 
0521 HELPER_EXPORT const std::map<QString, QVariant> buildTokenController(bool isNpc, const QPointF& pos)
0522 {
0523     return {{"isNpc", isNpc},
0524             {"tool",isNpc ? Core::SelectableTool::NonPlayableCharacter : Core::SelectableTool::PlayableCharacter },
0525             {"position", pos}};
0526 }
0527 const std::map<QString, QVariant> buildPathController(bool filled, const std::vector<QPointF>& points,
0528                                                       const QPointF& pos)
0529 {
0530     return {{"filled", filled},
0531             {"tool", Core::SelectableTool::PATH},
0532             {"points", QVariant::fromValue(points)},
0533             {"position", pos}};
0534 }
0535 const std::map<QString, QVariant> buildLineController(const QPointF& p1, const QPointF& p2, const QPointF& pos)
0536 {
0537     return {{"tool", Core::SelectableTool::LINE},
0538             {"start", QVariant::fromValue(p1)},
0539             {"end", QVariant::fromValue(p2)},
0540             {"position", pos}};
0541 }
0542 
0543 TestMessageSender::TestMessageSender() {}
0544 
0545 void TestMessageSender::sendMessage(const NetworkMessage* msg)
0546 {
0547     auto const writer= dynamic_cast<const NetworkMessageWriter*>(msg);
0548     if(writer)
0549         m_msgData= writer->data();
0550 }
0551 
0552 QByteArray TestMessageSender::messageData() const
0553 {
0554     return m_msgData;
0555 }
0556 
0557 std::pair<bool, QStringList> testAllProperties(QObject* obj, bool setAgain)
0558 {
0559     if(!obj)
0560         return {};
0561     auto meta= obj->metaObject();
0562     bool res= false;
0563     QStringList unmanaged;
0564     for(int i= meta->propertyOffset(); i < meta->propertyCount(); ++i)
0565     {
0566         auto p= meta->property(i);
0567         if(p.isConstant())
0568         {
0569             p.read(obj);
0570             continue;
0571         }
0572 
0573         if(p.hasNotifySignal() && p.isWritable())
0574         {
0575 
0576             auto vs= values(p.metaType(), p.read(obj), obj);
0577 
0578             if(vs.isEmpty())
0579             {
0580                 unmanaged.append(p.name());
0581                 continue;
0582             }
0583 
0584             auto currentval= p.read(obj);
0585             QSignalSpy spy(obj, p.notifySignal());
0586             int countChange = 0;
0587             for(const auto& v : vs)
0588             {
0589                 if(!p.write(obj, v))
0590                     qDebug() << "write failed for " << p.name() << v;
0591                 res= true;
0592 
0593                 if(setAgain)
0594                 {
0595                     p.write(obj, v);
0596                 }
0597             }
0598 
0599             spy.wait(10);
0600 
0601             if(!QTest::qCompare(spy.count(), vs.size(), "spy.count()", "vs.size()", __FILE__, __LINE__))
0602             {
0603                 qDebug() << p.name() << "values:" << vs << "current val:" << currentval << "change count:"<< countChange;
0604             }
0605 
0606             p.write(obj, currentval);
0607         }
0608     }
0609 
0610     return std::make_pair(res, unmanaged);
0611 }
0612 
0613 QString imagePath(bool isSquare)
0614 {
0615     QStringList array{":/img/girafe.jpg", ":/img/lion.jpg",  ":/img/control_life_bar.gif", ":/img/girafe3.jpg",
0616                       ":/img/lion3.jpg",  ":/img/white.png", ":/img/arbre_500.jpg"};
0617 
0618     if(isSquare)
0619         array= QStringList{":/img/arbre_square_500.jpg"};
0620 
0621     return array[generate<int>(0, array.size() - 1)];
0622 }
0623 
0624 QUrl imagePathUrl(bool isSquare)
0625 {
0626     QList<QUrl> array{QUrl("qrc:/img/girafe.jpg"), QUrl("qrc:/img/lion.jpg"),  QUrl("qrc:/img/control_life_bar.gif"), QUrl("qrc:/img/girafe3.jpg"),
0627                       QUrl("qrc:/img/lion3.jpg"),  QUrl("qrc:/img/white.png"), QUrl("qrc:/img/arbre_500.jpg")};
0628 
0629     if(isSquare)
0630         array= QList<QUrl>{QUrl("qrc:/img/arbre_square_500.jpg")};
0631 
0632     return array[generate<int>(0, array.size() - 1)];
0633 }
0634 
0635 QByteArray imageData(bool isSquare)
0636 {
0637     return utils::IOHelper::loadFile(imagePath(isSquare));
0638 }
0639 
0640 QByteArray randomData(int length)
0641 {
0642     QByteArray res;
0643     res.resize(length);
0644 
0645     std::generate(res.begin(), res.end(),
0646                   []
0647                   {
0648                       static std::random_device rd;
0649                       static std::mt19937 generator(rd());
0650                       static std::uniform_int_distribution<int> dist(0, std::numeric_limits<char>::max());
0651                       return dist(generator);
0652                   });
0653 
0654     return res;
0655 }
0656 
0657 QColor randomColor()
0658 {
0659     return QColor(generate<int>(0, 255), generate<int>(0, 255), generate<int>(0, 255));
0660 }
0661 
0662 QPointF randomPoint()
0663 {
0664     return QPointF{generate<qreal>(0., 800.), generate<qreal>(0., 800.)};
0665 }
0666 
0667 QObject* initWebServer(int port)
0668 {
0669     auto server= new QHttpServer();
0670 
0671     server->route("/image/<arg>",
0672                   [](const QUrl& url) {
0673                       return QHttpServerResponse::fromFile(
0674                           QStringLiteral("%1/resources/img/%2").arg(tests::root_path, url.path()));
0675                   });
0676 
0677     server->listen(QHostAddress::Any, port);
0678 
0679     return server;
0680 }
0681 
0682 QUrl randomUrl()
0683 {
0684     static QStringList files{"arbre_500.jpg",        "girafe3.jpg", "lion.jpg",           "Seppun_tashime.jpg",
0685                              "arbre_square_500.jpg", "girafe.jpg",  "lynn_gray_rike.jpg", "white.png",
0686                              "control_life_bar.gif", "lion3.jpg",   "predateur.jpg"};
0687     auto file= files[generate<int>(0, files.size() - 1)];
0688 
0689     return QUrl(QString("http://127.0.0.1:9090/image/%1").arg(file));
0690 }
0691 
0692 QRectF randomRect()
0693 {
0694     return QRectF{generate<qreal>(0., 800.), generate<qreal>(0., 800.), generate<qreal>(0., 800.),
0695                   generate<qreal>(0., 800.)};
0696 }
0697 
0698 QMovie randomMovie()
0699 {
0700     static QStringList list{"qrc:/img/control_life_bar.gif", "qrc:/img/control_life_bar.gif"};
0701     return QMovie(list[generate<int>(0, list.size() - 1)]);
0702 }
0703 
0704 } // namespace Helper