diff --git a/plugins/filetemplates/tests/CMakeLists.txt b/plugins/filetemplates/tests/CMakeLists.txt index 95ca0c3012..5ea4633fdc 100644 --- a/plugins/filetemplates/tests/CMakeLists.txt +++ b/plugins/filetemplates/tests/CMakeLists.txt @@ -1,9 +1,9 @@ configure_file(tests_config.h.cmake tests_config.h) add_subdirectory(data/testgenerationtest/templates) -ecm_add_test(testgenerationtest.cpp LINK_LIBRARIES +ecm_add_test(test_generationtest.cpp LINK_LIBRARIES Qt5::Test KDev::Tests KDev::Language ) diff --git a/plugins/filetemplates/tests/testgenerationtest.cpp b/plugins/filetemplates/tests/test_generationtest.cpp similarity index 99% rename from plugins/filetemplates/tests/testgenerationtest.cpp rename to plugins/filetemplates/tests/test_generationtest.cpp index 08b4576fda..5b1643668e 100644 --- a/plugins/filetemplates/tests/testgenerationtest.cpp +++ b/plugins/filetemplates/tests/test_generationtest.cpp @@ -1,126 +1,126 @@ /* * This file is part of KDevelop * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "testgenerationtest.h" +#include "test_generationtest.h" #include "tests_config.h" #include #include #include #include #include #include #include using namespace KDevelop; #define COMPARE_FILES(name) \ do { \ QFile actualFile(Path(Path(baseUrl), name).toLocalFile()); \ QVERIFY(actualFile.open(QIODevice::ReadOnly)); \ QFile expectedFile(TESTS_EXPECTED_DIR "/" name); \ QVERIFY(expectedFile.open(QIODevice::ReadOnly)); \ QCOMPARE(actualFile.size(), expectedFile.size()); \ QCOMPARE(QString(actualFile.readAll()), QString(expectedFile.readAll())); \ } while(0) void TestGenerationTest::initTestCase() { QByteArray xdgData = qgetenv("XDG_DATA_DIRS"); xdgData.prepend(TESTS_DATA_DIR ":"); bool addedDir = qputenv("XDG_DATA_DIRS", xdgData); QVERIFY(addedDir); AutoTestShell::init(); TestCore::initialize (Core::NoUi); TemplatesModel model("testgenerationtest"); model.refresh(); renderer = new TemplateRenderer; renderer->setEmptyLinesPolicy(TemplateRenderer::TrimEmptyLines); renderer->addVariable("name", "TestName"); renderer->addVariable("license", "Test license header\nIn two lines"); QStringList testCases; testCases << "firstTestCase"; testCases << "secondTestCase"; testCases << "thirdTestCase"; renderer->addVariable("testCases", testCases); } void TestGenerationTest::cleanupTestCase() { delete renderer; TestCore::shutdown(); } void TestGenerationTest::init() { dir.reset(new QTemporaryDir); baseUrl = QUrl::fromLocalFile(dir->path()); } void TestGenerationTest::yamlTemplate() { QString description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "testgenerationtest/template_descriptions/test_yaml2.desktop"); QVERIFY(!description.isEmpty()); SourceFileTemplate file; file.addAdditionalSearchLocation(TESTS_DATA_DIR "/testgenerationtest/templates"); file.setTemplateDescription(description, "testgenerationtest"); QCOMPARE(file.name(), QString("Testing YAML Template")); DocumentChangeSet changes = renderer->renderFileTemplate(file, baseUrl, urls(file)); changes.applyAllChanges(); COMPARE_FILES("testname.yaml"); } void TestGenerationTest::cppTemplate() { QString description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "testgenerationtest/template_descriptions/test_qtestlib.desktop"); QVERIFY(!description.isEmpty()); SourceFileTemplate file; file.addAdditionalSearchLocation(TESTS_DATA_DIR "/testgenerationtest/templates"); file.setTemplateDescription(description, "testgenerationtest"); QCOMPARE(file.name(), QString("Testing C++ Template")); DocumentChangeSet changes = renderer->renderFileTemplate(file, baseUrl, urls(file)); changes.applyAllChanges(); COMPARE_FILES("testname.h"); COMPARE_FILES("testname.cpp"); } QHash< QString, QUrl > TestGenerationTest::urls (const SourceFileTemplate& file) { QHash ret; foreach (const SourceFileTemplate::OutputFile& output, file.outputFiles()) { QUrl url = Path(Path(baseUrl), renderer->render(output.outputName).toLower()).toUrl(); ret.insert(output.identifier, url); } return ret; } QTEST_GUILESS_MAIN(TestGenerationTest); diff --git a/plugins/filetemplates/tests/testgenerationtest.h b/plugins/filetemplates/tests/test_generationtest.h similarity index 77% rename from plugins/filetemplates/tests/testgenerationtest.h rename to plugins/filetemplates/tests/test_generationtest.h index 15be1835ef..53211f15e6 100644 --- a/plugins/filetemplates/tests/testgenerationtest.h +++ b/plugins/filetemplates/tests/test_generationtest.h @@ -1,38 +1,38 @@ /* * */ -#ifndef KDEVPLATFORM_PLUGIN_TESTGENERATIONTEST_H -#define KDEVPLATFORM_PLUGIN_TESTGENERATIONTEST_H +#ifndef KDEVPLATFORM_PLUGIN_TEST_GENERATIONTEST_H +#define KDEVPLATFORM_PLUGIN_TEST_GENERATIONTEST_H #include #include #include namespace KDevelop { class TemplateRenderer; class SourceFileTemplate; } class TestGenerationTest : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void init(); void yamlTemplate(); void cppTemplate(); private: KDevelop::TemplateRenderer* renderer; QScopedPointer dir; QUrl baseUrl; QHash urls(const KDevelop::SourceFileTemplate& file); }; -#endif // KDEVPLATFORM_PLUGIN_TESTGENERATIONTEST_H +#endif // KDEVPLATFORM_PLUGIN_TEST_GENERATIONTEST_H