[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasmate/terietor/frameworks/packagehandler] plasmate: Implement the projecthandler and its unit te
From: Antonis Tsiapaliokas <kok3rs () gmail ! com>
Date: 2014-01-16 15:42:12
Message-ID: E1W3p5A-0003ID-RS () scm ! kde ! org
[Download RAW message or body]
Git commit b398fc72288a47201c717bdd5a227dc56acab53e by Antonis Tsiapaliokas.
Committed on 13/01/2014 at 19:33.
Pushed by tsiapaliokas into branch 'terietor/frameworks/packagehandler'.
Implement the projecthandler and its unit tests.
And disble the editpage unit test from tests/CMakeLists.txt
because it is not ported yet.
A +127 -0 plasmate/projecthandler.cpp [License: GPL]
A +48 -0 plasmate/projecthandler.h [License: GPL]
M +15 -6 plasmate/tests/CMakeLists.txt
A +107 -0 plasmate/tests/projecthandlertest.cpp [License: GPL]
A +46 -0 plasmate/tests/projecthandlertest.h [License: GPL]
http://commits.kde.org/plasmate/b398fc72288a47201c717bdd5a227dc56acab53e
diff --git a/plasmate/projecthandler.cpp b/plasmate/projecthandler.cpp
new file mode 100644
index 0000000..db170a1
--- /dev/null
+++ b/plasmate/projecthandler.cpp
@@ -0,0 +1,127 @@
+/*
+
+Copyright 2014 Antonis Tsiapaliokas <kok3rs@gmail.com>
+
+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) version 3 or any later version
+accepted by the membership of KDE e.V. (or its successor approved
+by the membership of KDE e.V.), which shall act as a proxy
+defined in Section 14 of version 3 of the license.
+
+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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "projecthandler.h"
+#include "packagehandler.h"
+#include <QApplication>
+#include <QDir>
+#include <QDebug>
+#include <QStandardPaths>
+#include <QStringList>
+
+#include <KConfigGroup>
+#include <KSharedConfig>
+
+ProjectHandler::ProjectHandler(QObject *parent)
+ : QObject(parent),
+ m_packageHandler(new PackageHandler(this))
+{
+}
+
+ProjectHandler::~ProjectHandler()
+{
+}
+
+PackageHandler *ProjectHandler::packageHandler()
+{
+ return m_packageHandler;
+}
+
+const QStringList &ProjectHandler::loadProjectsList()
+{
+ m_projectsList.clear();
+ const QString projectPath = QStandardPaths::standardLocations(QStandardPaths::DataLocation).at(0);
+
+ // load the projects which are inside on our homedir like ~/.local5
+ QDir projectDir(projectPath);
+ for (const auto &it : projectDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ // TODO find a way to check if the package is valid
+ QDir currentProject(projectPath + '/' + it);
+ if (currentProject.exists(QStringLiteral("metadata.desktop")) && \
!currentProject.path().isEmpty()) { + m_projectsList << currentProject.path();
+ }
+ }
+
+ // load the external projects
+ KConfigGroup externalProjectsConfig(KSharedConfig::openConfig(qApp->applicationDisplayName()), \
QStringLiteral("ProjectHandler")); +
+ QString externalProjects = externalProjectsConfig.readEntry("externalProjects", "");
+
+ if (!externalProjects.isEmpty()) {
+ for (const auto it : externalProjects.split(',')) {
+ if (!it.isEmpty()) {
+ m_projectsList << it;
+ }
+ }
+ }
+
+ return m_projectsList;
+}
+
+void ProjectHandler::addProject(const QString &projectPath)
+{
+ QDir projectDir(projectPath);
+
+ if (!projectDir.exists()) {
+ // If our package doesn't exist we are creating it.
+ m_packageHandler->setPackagePath(projectDir.absolutePath());
+ } else if (!projectDir.exists(QStringLiteral("metadata.desktop"))) {
+ qWarning() << "the project " << projectPath << "is not valid. metadata.desktop cannot be found";
+ return;
+ }
+
+ // In order our tests to run. We use qApp->applicationDisplayName()
+ KConfigGroup projectConfig(KSharedConfig::openConfig(qApp->applicationDisplayName()), \
QStringLiteral("ProjectHandler")); +
+ // We load the current config and if the external project
+ // doesn't exist. Then we are adding it.
+ const QString currentConfig = projectConfig.readEntry("externalProjects", "");
+ if (!currentConfig.contains(projectPath)) {
+ const QString updatedConfig = currentConfig + ',' + projectPath;
+ projectConfig.writeEntry("externalProjects", updatedConfig);
+ projectConfig.sync();
+ }
+
+ // Now we are updating the list of projects.
+ loadProjectsList();
+}
+
+void ProjectHandler::removeProject(const QString &projectPath)
+{
+ // In order for our tests to run. We use qApp->applicationDisplayName()
+ KConfigGroup projectConfig(KSharedConfig::openConfig(qApp->applicationDisplayName()), \
QStringLiteral("ProjectHandler")); +
+ QString currentConfig = projectConfig.readEntry("externalProjects", "");
+ if (!currentConfig.contains(projectPath)) {
+ qWarning() << "The " << projectPath << " doesn't exist. We cannot remove it";
+ return;
+ }
+
+ // In order to remove the project we are replacing the project path
+ // and the ',' which appends before it.
+ const QString newConfig = currentConfig.replace(',' + projectPath, "");
+ projectConfig.writeEntry("externalProjects", newConfig);
+ projectConfig.sync();
+
+ // Now we are updating the list of our projects.
+ loadProjectsList();
+}
+
diff --git a/plasmate/projecthandler.h b/plasmate/projecthandler.h
new file mode 100644
index 0000000..e3969ef
--- /dev/null
+++ b/plasmate/projecthandler.h
@@ -0,0 +1,48 @@
+/*
+
+Copyright 2014 Antonis Tsiapaliokas <kok3rs@gmail.com>
+
+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) version 3 or any later version
+accepted by the membership of KDE e.V. (or its successor approved
+by the membership of KDE e.V.), which shall act as a proxy
+defined in Section 14 of version 3 of the license.
+
+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, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef PROJECTHANDLER_H
+#define PROJECTHANDLER_H
+
+#include <QObject>
+#include <QStringList>
+
+class PackageHandler;
+
+class ProjectHandler : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit ProjectHandler(QObject *parent = 0);
+ ~ProjectHandler();
+
+ const QStringList &loadProjectsList();
+ void addProject(const QString &projectPath);
+ void removeProject(const QString &projectPath);
+ PackageHandler *packageHandler();
+private:
+ QStringList m_projectsList;
+ PackageHandler *m_packageHandler;
+};
+
+#endif
+
diff --git a/plasmate/tests/CMakeLists.txt b/plasmate/tests/CMakeLists.txt
index 043a82f..3763e28 100644
--- a/plasmate/tests/CMakeLists.txt
+++ b/plasmate/tests/CMakeLists.txt
@@ -27,14 +27,14 @@ set(editpageTest_SRCS ui/editpagetest.cpp
../editors/kconfigxt/kconfigxtwriter.cpp
)
-kde4_add_ui_files(editpageTest_SRCS ../editors/kconfigxt/kconfigxteditor.ui
-)
+#kde4_add_ui_files(editpageTest_SRCS ../editors/kconfigxt/kconfigxteditor.ui
+#)
-add_executable(editpagetest ${editpageTest_SRCS})
+#add_executable(editpagetest ${editpageTest_SRCS})
-target_link_libraries(editpagetest Qt5::Core Qt5::Widgets Qt5::Test
- Qt5::Svg KF5::Plasma KF5::I18n KF5::Service
- KF5::KIOCore KF5::KDE4Support)
+#target_link_libraries(editpagetest Qt5::Core Qt5::Widgets Qt5::Test
+# Qt5::Svg KF5::Plasma KF5::I18n KF5::Service
+# KF5::KIOCore KF5::KDE4Support)
set(metadatahandler_SRCS metadatahandlertest.cpp
../editors/metadata/metadatahandler.cpp
@@ -44,3 +44,12 @@ add_executable(metadatahandlertest ${metadatahandler_SRCS})
target_link_libraries(metadatahandlertest Qt5::Core Qt5::Test KF5::ConfigCore)
+set(projecthandlerTest_SRCS
+ projecthandlertest.cpp
+ ../projecthandler.cpp
+ ../packagehandler.cpp
+)
+
+add_executable(projecthandlertest ${projecthandlerTest_SRCS})
+
+target_link_libraries(projecthandlertest Qt5::Core Qt5::Test KF5::Plasma)
diff --git a/plasmate/tests/projecthandlertest.cpp b/plasmate/tests/projecthandlertest.cpp
new file mode 100644
index 0000000..0528d29
--- /dev/null
+++ b/plasmate/tests/projecthandlertest.cpp
@@ -0,0 +1,107 @@
+/*
+
+Copyright 2014 Antonis Tsiapaliokas <kok3rs@gmail.com>
+
+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) version 3 or any later version
+accepted by the membership of KDE e.V. (or its successor approved
+by the membership of KDE e.V.), which shall act as a proxy
+defined in Section 14 of version 3 of the license.
+
+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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "projecthandlertest.h"
+#include "../packagehandler.h"
+
+#include <QDir>
+#include <QDebug>
+#include <QFile>
+#include <QTest>
+#include <QStandardPaths>
+
+ProjectHandlerTest::ProjectHandlerTest(QObject *parent)
+ : QObject(parent)
+{
+}
+
+ProjectHandlerTest::~ProjectHandlerTest()
+{
+}
+
+void ProjectHandlerTest::initTestCase()
+{
+ QStandardPaths::enableTestMode(true);
+}
+
+void ProjectHandlerTest::createTestProject()
+{
+ // Here we create a test package in case it
+ // doesn't exist.
+ const QString projectTestPath = \
QStandardPaths::standardLocations(QStandardPaths::DataLocation).at(0); +
+ Q_ASSERT(!projectTestPath.isEmpty());
+ PackageHandler packageHandler;
+
+ // If our project package exists, then we are removing it.
+ // In order to ensure that it has been created properly
+ QDir invalidTestPackageDir(projectTestPath + "/invalidtestpackage");
+ if (invalidTestPackageDir.exists()) {
+ invalidTestPackageDir.removeRecursively();
+ }
+
+ QDir externalInvalidTestPackageDir(QDir::tempPath() + "/invalidtestpackageexternal");
+ if (externalInvalidTestPackageDir.exists()) {
+ externalInvalidTestPackageDir.removeRecursively();
+ }
+
+ packageHandler.setPackagePath(projectTestPath + "/testpackage");
+ packageHandler.setPackagePath(invalidTestPackageDir.path());
+
+ // Extrenal project
+ packageHandler.setPackagePath(QDir::tempPath() + "/externaltestpackage");
+ packageHandler.setPackagePath(externalInvalidTestPackageDir.path());
+
+ // Our external package is valid so we must make it invalid.
+ QFile invalidPackageExternalMetadata(externalInvalidTestPackageDir.path() + "/metadata.desktop");
+ Q_ASSERT(invalidPackageExternalMetadata.remove());
+
+ // Our package is valid so we must make it invalid.
+ QFile invalidPackageMetadata(invalidTestPackageDir.path() + "/metadata.desktop");
+ Q_ASSERT(invalidPackageMetadata.remove());
+
+ m_projectHandler.addProject(QDir::tempPath() + "/externaltestpackage");
+ m_projectHandler.addProject(QDir::tempPath() + "/newtestpackage");
+}
+
+void ProjectHandlerTest::projectsList()
+{
+ QStringList list = m_projectHandler.loadProjectsList();
+ const QString projectTestPath = \
QStandardPaths::standardLocations(QStandardPaths::DataLocation).at(0); + const QString testPackagePath \
= projectTestPath + "/testpackage"; + const QString externalTestPackagePath = QDir::tempPath() + \
"/externaltestpackage"; + const QString newTestPackage = QDir::tempPath() + "/newtestpackage";
+
+ Q_ASSERT(list.length() > 0);
+ Q_ASSERT(list.count() == 3);
+ Q_ASSERT(list.contains(testPackagePath));
+ Q_ASSERT(list.contains(externalTestPackagePath));
+ Q_ASSERT(list.contains(newTestPackage));
+
+ m_projectHandler.removeProject(QDir::tempPath() + "/externaltestpackage");
+ list = m_projectHandler.loadProjectsList();
+ Q_ASSERT(list.length() > 0);
+ Q_ASSERT(list.count() == 2);
+ Q_ASSERT(list.contains(testPackagePath));
+}
+
+QTEST_GUILESS_MAIN(ProjectHandlerTest)
+
diff --git a/plasmate/tests/projecthandlertest.h b/plasmate/tests/projecthandlertest.h
new file mode 100644
index 0000000..7841f85
--- /dev/null
+++ b/plasmate/tests/projecthandlertest.h
@@ -0,0 +1,46 @@
+/*
+
+Copyright 2014 Antonis Tsiapaliokas <kok3rs@gmail.com>
+
+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) version 3 or any later version
+accepted by the membership of KDE e.V. (or its successor approved
+by the membership of KDE e.V.), which shall act as a proxy
+defined in Section 14 of version 3 of the license.
+
+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, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef PROJECTHANDLERTEST_H
+#define PROJECTHANDLERTEST_H
+
+#include "../projecthandler.h"
+
+class ProjectHandlerTest : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ explicit ProjectHandlerTest(QObject *parent = 0);
+ ~ProjectHandlerTest();
+
+private Q_SLOTS:
+ void initTestCase();
+ void createTestProject();
+ void projectsList();
+
+private:
+ ProjectHandler m_projectHandler;
+};
+
+#endif
+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic