Commit 0ec5b37e authored by Laurent Montel's avatar Laurent Montel 😁

Add unittest

parent 0905e8ed
......@@ -20,3 +20,4 @@ set_target_properties(grantleetheme PROPERTIES VERSION ${GENERIC_LIB_VERSION} SO
install(TARGETS grantleetheme ${INSTALL_TARGETS_DEFAULT_ARGS})
add_subdirectory(kconf_update)
add_subdirectory(autotest)
add_definitions( -DGRANTLEETHEME_DATA_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\"" )
set( grantlee_theme_source grantleethemetest.cpp ../grantleetheme.cpp)
kde4_add_unit_test( grantleethemetest ${grantlee_theme_source})
target_link_libraries( grantleethemetest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS})
[Desktop Entry]
Name=Example
Description=Example theme for header.
FileName=header.html
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 "grantleethemetest.h"
#include "../grantleetheme.h"
#include <qtest_kde.h>
GrantleeThemeTest::GrantleeThemeTest(QObject *parent)
: QObject(parent)
{
}
GrantleeThemeTest::~GrantleeThemeTest()
{
}
void GrantleeThemeTest::shouldHaveDefaultValue()
{
GrantleeTheme::Theme theme;
QVERIFY(theme.description().isEmpty());
QVERIFY(theme.filename().isEmpty());
QVERIFY(theme.name().isEmpty());
QVERIFY(theme.displayExtraVariables().isEmpty());
QVERIFY(theme.dirName().isEmpty());
QVERIFY(theme.absolutePath().isEmpty());
QVERIFY(theme.author().isEmpty());
QVERIFY(theme.authorEmail().isEmpty());
QVERIFY(!theme.isValid());
}
void GrantleeThemeTest::shouldInvalidWhenPathIsNotValid()
{
const QString themePath(QLatin1String("/foo"));
const QString dirName(QLatin1String("name"));
const QString defaultDesktopFileName(QLatin1String("bla"));
GrantleeTheme::Theme theme(themePath, dirName, defaultDesktopFileName);
QVERIFY(theme.description().isEmpty());
QVERIFY(theme.filename().isEmpty());
QVERIFY(theme.name().isEmpty());
QVERIFY(theme.displayExtraVariables().isEmpty());
QVERIFY(!theme.dirName().isEmpty());
QVERIFY(!theme.absolutePath().isEmpty());
QVERIFY(theme.author().isEmpty());
QVERIFY(theme.authorEmail().isEmpty());
QVERIFY(!theme.isValid());
}
void GrantleeThemeTest::shouldLoadTheme_data()
{
QTest::addColumn<QString>("dirname");
QTest::addColumn<QString>("filename");
QTest::addColumn<bool>("isvalid");
QTest::addColumn<QStringList>("displayExtraVariables");
QTest::newRow("valid theme") << QString(QLatin1String("valid")) << QString(QLatin1String("filename.testdesktop")) << true << QStringList();
}
void GrantleeThemeTest::shouldLoadTheme()
{
QFETCH( QString, dirname );
QFETCH( QString, filename );
QFETCH( bool, isvalid );
QFETCH( QStringList, displayExtraVariables );
GrantleeTheme::Theme theme(QLatin1String( GRANTLEETHEME_DATA_DIR ), dirname, filename);
//QCOMPARE(theme.isValid(), isvalid);
QCOMPARE(theme.displayExtraVariables(), displayExtraVariables);
QCOMPARE(theme.dirName(), dirname);
//QCOMPARE(theme.filename(), filename);
}
QTEST_KDEMAIN(GrantleeThemeTest, NoGUI)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
*/
#ifndef GRANTLEETHEMETEST_H
#define GRANTLEETHEMETEST_H
#include <QObject>
class GrantleeThemeTest : public QObject
{
Q_OBJECT
public:
explicit GrantleeThemeTest(QObject *parent = 0);
~GrantleeThemeTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldInvalidWhenPathIsNotValid();
void shouldLoadTheme_data();
void shouldLoadTheme();
};
#endif // GRANTLEETHEMETEST_H
......@@ -16,16 +16,36 @@
*/
#include "grantleetheme.h"
#include <KConfig>
#include <KConfigGroup>
#include <QDir>
using namespace GrantleeTheme;
Theme::Theme()
{
}
Theme::Theme(const QString &themePath, const QString &dirName, const QString &defaultDesktopFileName)
{
const QString themeInfoFile = themePath + QDir::separator() + defaultDesktopFileName;
KConfig config( themeInfoFile );
KConfigGroup group( &config, QLatin1String( "Desktop Entry" ) );
if (group.isValid()) {
setDirName(dirName);
setName( group.readEntry( "Name", QString() ) );
setDescription( group.readEntry( "Description", QString() ) );
setFilename( group.readEntry( "FileName" , QString() ) );
setDisplayExtraVariables( group.readEntry( "DisplayExtraVariables", QStringList() ) );
setAbsolutePath(themePath);
}
}
Theme::~Theme()
{
}
bool Theme::isValid() const
{
return !mFileName.isEmpty() && !mName.isEmpty();
......
......@@ -25,6 +25,7 @@ class GRANTLEETHEME_EXPORT Theme
{
public:
Theme();
Theme(const QString &themePath, const QString &dirName, const QString &defaultDesktopFileName);
~Theme();
bool isValid() const;
......
......@@ -353,17 +353,7 @@ QString GrantleeThemeManager::pathFromThemes(const QString &themesRelativePath,
GrantleeTheme::Theme GrantleeThemeManager::loadTheme(const QString &themePath, const QString &dirName, const QString &defaultDesktopFileName )
{
const QString themeInfoFile = themePath + QDir::separator() + defaultDesktopFileName;
KConfig config( themeInfoFile );
KConfigGroup group( &config, QLatin1String( "Desktop Entry" ) );
GrantleeTheme::Theme theme;
theme.setDirName(dirName);
theme.setName( group.readEntry( "Name", QString() ) );
theme.setDescription( group.readEntry( "Description", QString() ) );
theme.setFilename( group.readEntry( "FileName" , QString() ) );
theme.setDisplayExtraVariables( group.readEntry( "DisplayExtraVariables", QStringList() ) );
theme.setAbsolutePath(themePath);
const GrantleeTheme::Theme theme(themePath, dirName, defaultDesktopFileName);
return theme;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment