Add unittest

wilder-work
Montel Laurent 11 years ago
parent a4c5f2cf95
commit c486040a3a
  1. 14
      mailmerge/tests/CMakeLists.txt
  2. 45
      mailmerge/tests/csvwidgettest.cpp
  3. 34
      mailmerge/tests/csvwidgettest.h
  4. 56
      mailmerge/widgets/csvwidget.cpp
  5. 41
      mailmerge/widgets/csvwidget.h
  6. 15
      mailmerge/widgets/mailmergewidget.cpp
  7. 3
      mailmerge/widgets/mailmergewidget.h

@ -3,7 +3,7 @@ include_directories(
)
# convenience macro to add qtest unit tests
macro(add_kmail_unittest _source)
set(_test ${_source} ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp)
set(_test ${_source} ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp ../widgets/csvwidget.cpp)
get_filename_component(_name ${_source} NAME_WE)
kde4_add_unit_test(${_name} TESTNAME kmail-${_name} ${_test})
target_link_libraries( ${_name}
@ -18,7 +18,7 @@ endmacro ()
add_kmail_unittest( mailmergewidgettest.cpp )
set(mailmergewidget_gui_SRCS mailmergewidgettest_gui.cpp ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp)
set(mailmergewidget_gui_SRCS mailmergewidgettest_gui.cpp ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp ../widgets/csvwidget.cpp)
kde4_add_executable(mailmergewidget_gui TEST ${mailmergewidget_gui_SRCS})
target_link_libraries(mailmergewidget_gui
${QT_QTCORE_LIBRARY}
@ -30,13 +30,13 @@ target_link_libraries(mailmergewidget_gui
# Convenience macro to add unit tests.
macro( kmail_mailmerge _source )
set( _test ${_source} )
macro( kmail_mailmerge _source _additionalsource)
set( _test ${_source} ${_additionalsource})
get_filename_component( _name ${_source} NAME_WE )
kde4_add_unit_test( ${_name} TESTNAME kmailmailmerge-${_name} ${_test} )
target_link_libraries( ${_name} ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} )
target_link_libraries( ${_name} ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS} )
endmacro()
kmail_mailmerge(addressbookwidgettest.cpp)
kmail_mailmerge(addressbookwidgettest.cpp "")
kmail_mailmerge(csvwidgettest.cpp "../widgets/csvwidget.cpp")

@ -0,0 +1,45 @@
/*
Copyright (c) 2015 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 "csvwidgettest.h"
#include "../widgets/csvwidget.h"
#include <KUrlRequester>
#include <QLabel>
#include <qtest_kde.h>
CsvWidgetTest::CsvWidgetTest(QObject *parent)
: QObject(parent)
{
}
CsvWidgetTest::~CsvWidgetTest()
{
}
void CsvWidgetTest::shouldHaveDefaultValue()
{
MailMerge::CsvWidget w;
QLabel *lab = qFindChild<QLabel *>(&w, QLatin1String("label"));
QVERIFY(lab);
KUrlRequester *urlrequester = qFindChild<KUrlRequester *>(&w, QLatin1String("cvsurlrequester"));
QVERIFY(urlrequester);
}
QTEST_KDEMAIN(CsvWidgetTest, GUI)

@ -0,0 +1,34 @@
/*
Copyright (c) 2015 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 CSVWIDGETTEST_H
#define CSVWIDGETTEST_H
#include <QObject>
class CsvWidgetTest : public QObject
{
Q_OBJECT
public:
explicit CsvWidgetTest(QObject *parent = 0);
~CsvWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // CSVWIDGETTEST_H

@ -0,0 +1,56 @@
/*
Copyright (c) 2015 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 "csvwidget.h"
#include <KUrlRequester>
#include <QLabel>
#include <QVBoxLayout>
#include <KLocalizedString>
using namespace MailMerge;
CsvWidget::CsvWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *csvWidgetLayout = new QVBoxLayout;
csvWidgetLayout->setMargin(0);
setLayout(csvWidgetLayout);
QLabel *lab = new QLabel(i18n("Path:"));
lab->setObjectName(QLatin1String("label"));
csvWidgetLayout->addWidget(lab);
mCvsUrlRequester = new KUrlRequester;
mCvsUrlRequester->setObjectName(QLatin1String("cvsurlrequester"));
csvWidgetLayout->addWidget(mCvsUrlRequester);
}
CsvWidget::~CsvWidget()
{
}
void CsvWidget::setPath(const KUrl &path)
{
mCvsUrlRequester->setUrl(path);
}
KUrl CsvWidget::path() const
{
return mCvsUrlRequester->url();
}

@ -0,0 +1,41 @@
/*
Copyright (c) 2015 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 CSVWIDGET_H
#define CSVWIDGET_H
#include <QWidget>
class KUrlRequester;
class KUrl;
namespace MailMerge {
class CsvWidget : public QWidget
{
Q_OBJECT
public:
explicit CsvWidget(QWidget *parent=0);
~CsvWidget();
void setPath(const KUrl &path);
KUrl path() const;
private:
KUrlRequester *mCvsUrlRequester;
};
}
#endif // CSVWIDGET_H

@ -16,6 +16,7 @@
*/
#include "mailmergewidget.h"
#include "../widgets/csvwidget.h"
#include "attachmentlistwidget.h"
@ -62,18 +63,10 @@ MailMergeWidget::MailMergeWidget(QWidget *parent)
addressBookWidget->setLayout(addressBookWidgetLayout);
mStackedWidget->addWidget(addressBookWidget);
QWidget *csvWidget = new QWidget;
csvWidget->setObjectName(QLatin1String("csvwidget"));
QVBoxLayout *csvWidgetLayout = new QVBoxLayout;
csvWidgetLayout->setMargin(0);
csvWidget->setLayout(csvWidgetLayout);
mCsvWidget = new MailMerge::CsvWidget;
mCsvWidget->setObjectName(QLatin1String("cvswidget"));
lab = new QLabel(i18n("Path:"));
csvWidgetLayout->addWidget(lab);
mCvsUrlRequester = new KUrlRequester;
csvWidgetLayout->addWidget(mCvsUrlRequester);
mStackedWidget->addWidget(csvWidget);
mStackedWidget->addWidget(mCsvWidget);
lab = new QLabel(i18n("Attachment:"));
vbox->addWidget(lab);

@ -25,6 +25,7 @@ class QStackedWidget;
class KUrlRequester;
namespace MailMerge {
class CsvWidget;
class AttachmentListWidget;
class MailMergeWidget : public QWidget
{
@ -48,7 +49,7 @@ private:
KComboBox *mSource;
QStackedWidget *mStackedWidget;
AttachmentListWidget *mAttachment;
KUrlRequester *mCvsUrlRequester;
MailMerge::CsvWidget *mCsvWidget;
};
}
#endif // MAILMERGEWIDGET_H

Loading…
Cancel
Save