1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _U2_XML_TEST_UTILS_ 23 #define _U2_XML_TEST_UTILS_ 24 25 #include <U2Test/GTest.h> 26 27 #include "XMLTestFormat.h" 28 29 namespace U2 { 30 31 #define SIMPLE_XML_TEST_CONSTRUCT(ClassName, TFlags) \ 32 ClassName(XMLTestFormat *_tf, const QString &_name, GTest *_cp, const GTestEnvironment *_env, const QList<GTest *> &_contexts, const QDomElement &_el) \ 33 : XmlTest(_name, _cp, _env, TFlags, _contexts) { \ 34 init(_tf, _el); \ 35 } 36 37 #define SIMPLE_XML_TEST_BODY(ClassName, TFlags) \ 38 public: \ 39 SIMPLE_XML_TEST_CONSTRUCT(ClassName, TFlags) \ 40 void init(XMLTestFormat *tf, const QDomElement &el); 41 42 #define SIMPLE_XML_TEST_BODY_WITH_FACTORY_EXT(TestClass, TagName, TFlags) \ 43 SIMPLE_XML_TEST_BODY(TestClass, TFlags) \ 44 class TestClass##Factory : public XMLTestFactory { \ 45 public: \ 46 TestClass##Factory() : XMLTestFactory(TagName) { \ 47 } \ 48 \ 49 virtual GTest *createTest(XMLTestFormat *tf, const QString &testName, GTest *cp, const GTestEnvironment *env, const QList<GTest *> &subtasks, const QDomElement &el) { \ 50 return new TestClass(tf, testName, cp, env, subtasks, el); \ 51 } \ 52 }; \ 53 \ 54 static XMLTestFactory *createFactory() { \ 55 return new TestClass##Factory(); \ 56 } 57 58 #define SIMPLE_XML_TEST_BODY_WITH_FACTORY(TestClass, TagName) \ 59 SIMPLE_XML_TEST_BODY_WITH_FACTORY_EXT(TestClass, TagName, TaskFlags_NR_FOSCOE) 60 61 class U2TEST_EXPORT XmlTest : public GTest { 62 public: 63 XmlTest(const QString &taskName, 64 GTest *cp, 65 const GTestEnvironment *env, 66 TaskFlags flags, 67 const QList<GTest *> &subtasks = QList<GTest *>()); 68 69 void checkNecessaryAttributeExistence(const QDomElement &element, const QString &attribute); 70 void checkAttribute(const QDomElement &element, const QString &attribute, const QStringList &acceptableValues, bool isNecessary); 71 void checkBooleanAttribute(const QDomElement &element, const QString &attribute, bool isNecessary); 72 int getInt(const QDomElement &element, const QString &attribute); 73 qint64 getInt64(const QDomElement &element, const QString &attribute); 74 double getDouble(const QDomElement &element, const QString &attribute); 75 76 static const QString TRUE_VALUE; 77 static const QString FALSE_VALUE; 78 }; 79 80 class U2TEST_EXPORT XMLTestUtils { 81 public: 82 static QList<XMLTestFactory *> createTestFactories(); 83 static void replacePrefix(const GTestEnvironment *env, QString &path); 84 static bool parentTasksHaveError(Task *t); 85 86 static const QString TMP_DATA_DIR_PREFIX; 87 static const QString COMMON_DATA_DIR_PREFIX; 88 static const QString LOCAL_DATA_DIR_PREFIX; 89 static const QString SAMPLE_DATA_DIR_PREFIX; 90 static const QString WORKFLOW_SAMPLES_DIR_PREFIX; 91 static const QString WORKFLOW_OUTPUT_DIR_PREFIX; 92 static const QString EXPECTED_OUTPUT_DIR_PREFIX; 93 94 static const QString CONFIG_FILE_PATH; 95 }; 96 97 ////////////////////////////////////////////////////////////////////////// 98 // utility tasks 99 100 class XMLMultiTest : public XmlTest { 101 Q_OBJECT 102 public: 103 SIMPLE_XML_TEST_BODY_WITH_FACTORY(XMLMultiTest, "multi-test") 104 ReportResult report(); 105 106 static const QString FAIL_ON_SUBTEST_FAIL; // it defines whether the test should stop execution after the first error; is "true" by default 107 static const QString LOCK_FOR_LOG_LISTENING; // This attribute is used to avoid mixing log messages between different tests. Each test that listens to log should set this attribute to "true" 108 }; 109 110 class GTest_Fail : public XmlTest { 111 Q_OBJECT 112 public: 113 SIMPLE_XML_TEST_BODY_WITH_FACTORY_EXT(GTest_Fail, "fail", TaskFlag_NoRun) 114 ReportResult report(); 115 116 private: 117 QString msg; 118 }; 119 120 class GTest_DeleteTmpFile : public XmlTest { 121 Q_OBJECT 122 public: 123 SIMPLE_XML_TEST_BODY_WITH_FACTORY_EXT(GTest_DeleteTmpFile, "delete", TaskFlag_NoRun) 124 ReportResult report(); 125 126 private: 127 QString url; 128 }; 129 130 class GTest_CreateTmpFolder : public XmlTest { 131 Q_OBJECT 132 public: 133 SIMPLE_XML_TEST_BODY_WITH_FACTORY_EXT(GTest_CreateTmpFolder, "create-folder", TaskFlag_NoRun) 134 ReportResult report(); 135 136 private: 137 QString url; 138 }; 139 140 } // namespace U2 141 142 #endif 143