/*************************************************************************** * Copyright (C) 2020 by Gustavo Sousa - gustavocms@gmail.com * * Copyright (C) 2020 by Stephen Lyons - slysven@virginmedia.com * * Copyright (C) 2023 by Michael Weller - michael.weller@t-online.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "TMxpVersionTagHandler.h" #include "TMxpStubClient.h" #include #include #include class TMxpVersionTagTest : public QObject { Q_OBJECT private: private slots: QSharedPointer parseNode(const QString& tagText) const { auto nodes = TMxpTagParser::parseToMxpNodeList(tagText); return nodes.size() > 0 ? nodes.first() : nullptr; } void initTestCase() {} void testVersionTag() { // Vanilla use of version TMxpStubContext ctx; TMxpStubClient stub; auto versionTag = parseNode(""); TMxpVersionTagHandler versionTagHandler; TMxpTagHandler& tagHandler = versionTagHandler; tagHandler.handleTag(ctx, stub, versionTag->asTag()); QCOMPARE(stub.sentToServer, "\n\u001B[1z\n"); } void testVersionStyle() { // Set a Style (Version of MXP Template of mud) TMxpStubContext ctx; TMxpStubClient stub; // style is generally just a string, but compared to other implementations we must at least allow // for full 9 digits (which would fit into a 32bit int) auto versionTag = parseNode(""); TMxpVersionTagHandler versionTagHandler; TMxpTagHandler& tagHandler = versionTagHandler; tagHandler.handleTag(ctx, stub, versionTag->asTag()); // NO return value when setting style (this is a grey area.. but Z/CMUD and mushclient do it this way and // the MXP definition seems to imply this interpretation: // The client caches this version information and returns it when requested by a plain request. // One can interprete this like: it ONLY returns it when using a plain request... but...) QCOMPARE(stub.sentToServer, ""); // From now on, return it with version versionTag = parseNode(""); tagHandler.handleTag(ctx, stub, versionTag->asTag()); QCOMPARE(stub.sentToServer, "\n\u001B[1z\n"); } void cleanupTestCase() {} }; #include "TMxpVersionTagTest.moc" QTEST_MAIN(TMxpVersionTagTest)