summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-02-27 15:29:58 +0100
committerAndrea Diamantini <adjam7@gmail.com>2010-02-27 15:29:58 +0100
commit0f1dfeac60cdf35e44838b1323d98db8383738c7 (patch)
tree7f01671350c421a8bb82ec17d57c6afeda26b367
parenttests support for every Qt derived rekonq class (diff)
downloadrekonq-0f1dfeac60cdf35e44838b1323d98db8383738c7.tar.xz
New (embrional) unit tests: mainview, tabbar, webtab, webpage
-rw-r--r--src/tabbar.cpp4
-rw-r--r--src/tests/CMakeLists.txt49
-rw-r--r--src/tests/mainview_test.cpp47
-rw-r--r--src/tests/tabbar_test.cpp107
-rw-r--r--src/tests/webpage_test.cpp123
-rw-r--r--src/tests/webtab_test.cpp67
6 files changed, 313 insertions, 84 deletions
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index ff996cb5..49ed230b 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -93,13 +93,13 @@ QSize TabBar::tabSizeHint(int index) const
int minWidth = view->sizeHint().width()/MIN_WIDTH_DIVISOR;
int w;
- if (baseWidth*count()<tabBarWidth)
+ if (baseWidth*count() < tabBarWidth)
{
w = baseWidth;
}
else
{
- if (count() > 0 && tabBarWidth/count()>minWidth)
+ if (count() > 0 && tabBarWidth/count() > minWidth)
{
w = tabBarWidth/count();
}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 18de9299..ccb25551 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -2,7 +2,14 @@
SET( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
-INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_BINARY_DIR}/..
+INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/..
+ ${CMAKE_CURRENT_SOURCE_DIR}/../adblock
+ ${CMAKE_CURRENT_SOURCE_DIR}/../bookmarks
+ ${CMAKE_CURRENT_SOURCE_DIR}/../history
+ ${CMAKE_CURRENT_SOURCE_DIR}/../rekonqpage
+ ${CMAKE_CURRENT_SOURCE_DIR}/../settings
+ ${CMAKE_CURRENT_SOURCE_DIR}/../urlbar
${KDE4_INCLUDES}
${QT4_INCLUDES}
)
@@ -20,13 +27,37 @@ target_link_libraries( tabbar_test
##### ------------- mainview test
-# kde4_add_unit_test( mainview_test mainview_test.cpp )
-#
-# target_link_libraries( mainview_test
-# kdeinit_rekonq
-# ${KDE4_KDECORE_LIBS}
-# ${KDE4_KDEUI_LIBS}
-# ${QT_QTTEST_LIBRARY}
-# )
+kde4_add_unit_test( mainview_test mainview_test.cpp )
+
+target_link_libraries( mainview_test
+ kdeinit_rekonq
+ ${KDE4_KDECORE_LIBS}
+ ${KDE4_KDEUI_LIBS}
+ ${QT_QTTEST_LIBRARY}
+)
+
+##### ------------- webpage test
+
+kde4_add_unit_test( webpage_test webpage_test.cpp )
+
+target_link_libraries( webpage_test
+ kdeinit_rekonq
+ ${KDE4_KDECORE_LIBS}
+ ${KDE4_KDEUI_LIBS}
+ ${KDE4_KDEWEBKIT_LIBS}
+ ${QT_QTTEST_LIBRARY}
+)
+
+##### ------------- webtab test
+
+kde4_add_unit_test( webtab_test webtab_test.cpp )
+
+target_link_libraries( webtab_test
+ kdeinit_rekonq
+ ${KDE4_KDECORE_LIBS}
+ ${KDE4_KDEUI_LIBS}
+ ${KDE4_KDEWEBKIT_LIBS}
+ ${QT_QTTEST_LIBRARY}
+)
############################################################
diff --git a/src/tests/mainview_test.cpp b/src/tests/mainview_test.cpp
index f56d73ab..1dfffcbe 100644
--- a/src/tests/mainview_test.cpp
+++ b/src/tests/mainview_test.cpp
@@ -31,8 +31,21 @@
#include <QtCore>
#include <QtGui>
-#include "../mainview.h"
-#include "../webview.h"
+#include "mainview.h"
+#include "webview.h"
+
+
+// Subclass that exposes the protected functions.
+class SubMainView : public MainView
+{
+public:
+ SubMainView(MainWindow *parent) : MainView(parent) {};
+
+ void call_resizeEvent(QResizeEvent *event)
+ { return SubMainView::resizeEvent(event); }
+};
+
+// -----------------------------------------------------------
class MainViewTest : public QObject
@@ -42,8 +55,6 @@ class MainViewTest : public QObject
public slots:
void initTestCase();
void cleanupTestCase();
- void init();
- void cleanup();
private slots:
void tabwidget_data();
@@ -75,38 +86,30 @@ private slots:
void currentChanged_data();
void currentChanged();
+
+private:
+ MainWindow *mainWindow;
+ SubMainView *mainView;
};
-// Subclass that exposes the protected functions.
-class SubMainView : public MainView
-{
-public:
- void call_resizeEvent(QResizeEvent *event)
- { return SubMainView::resizeEvent(event); }
-};
+// -------------------------------------------------------------------------------
// This will be called before the first test function is executed.
// It is only called once.
void MainViewTest::initTestCase()
{
+ mainWindow = new MainWindow;
+ mainView = new SubMainView(mainWindow);
}
// This will be called after the last test function is executed.
// It is only called once.
void MainViewTest::cleanupTestCase()
{
-}
-
-// This will be called before each test function is executed.
-void MainViewTest::init()
-{
-}
-
-// This will be called after every test function.
-void MainViewTest::cleanup()
-{
+ delete mainView;
+ delete mainWindow;
}
// -------------------------------------------
@@ -117,7 +120,6 @@ void MainViewTest::tabwidget_data()
void MainViewTest::tabwidget()
{
- SubMainView widget;
// widget.currentWebView();
// QCOMPARE(widget.currentIndex(), 0);
// widget.newTab();
@@ -140,7 +142,6 @@ void MainViewTest::closeTab()
{
QFETCH(int, index);
- SubMainView widget;
/*
QSignalSpy spy0(&widget, SIGNAL(linkHovered(const QString &)));
QSignalSpy spy3(&widget, SIGNAL(setCurrentTitle(const QString &)));
diff --git a/src/tests/tabbar_test.cpp b/src/tests/tabbar_test.cpp
index 7162e6a4..560f2c9b 100644
--- a/src/tests/tabbar_test.cpp
+++ b/src/tests/tabbar_test.cpp
@@ -24,29 +24,14 @@
#include <QtCore>
#include <QtGui>
-#include "../tabbar.h"
+#include "mainwindow.h"
+#include "mainview.h"
+#include "tabbar.h"
-class TabBarTest : public QObject
-{
- Q_OBJECT
-
-public slots:
- void initTestCase();
- void cleanupTestCase();
- void init();
- void cleanup();
-
-private slots:
- void tabbar_data();
- void tabbar();
-
- void tabSizeHint_data();
- void tabSizeHint();
-};
-
-
-// Subclass that exposes the protected functions.
+/**
+ * Subclass that exposes the protected functions.
+ */
class SubTabBar : public TabBar
{
public:
@@ -70,62 +55,84 @@ public:
};
-// This will be called before the first test function is executed.
-// It is only called once.
-void TabBarTest::initTestCase()
-{
-}
+// ------------------------------------------------------------------
-// This will be called after the last test function is executed.
-// It is only called once.
-void TabBarTest::cleanupTestCase()
+class TabBarTest : public QObject
{
-}
+ Q_OBJECT
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private slots:
+ void tabSizeHint_data();
+ void tabSizeHint();
+
+ void mousePress_data();
+ void mousePress();
+
+private:
+ SubTabBar *_bar;
+};
+
+
+// -------------------------------------------
-// This will be called before each test function is executed.
-void TabBarTest::init()
+void TabBarTest::initTestCase()
{
+ MainWindow *w = new MainWindow;
+ MainView *mv = new MainView(w);
+ _bar = new SubTabBar(mv);
}
-
-// This will be called after every test function.
-void TabBarTest::cleanup()
+void TabBarTest::cleanupTestCase()
{
+ delete _bar;
}
// -------------------------------------------
-void TabBarTest::tabbar_data()
+void TabBarTest::tabSizeHint_data()
{
+ QTest::addColumn<int>("index");
+
+ QTest::newRow("1th") << 0;
+ QTest::newRow("2nd") << 1;
+ QTest::newRow("3rd") << 2;
+ QTest::newRow("4th") << 3;
+ QTest::newRow("5th") << 4;
+ QTest::newRow("6th") << 5;
+ QTest::newRow("7th") << 6;
+ QTest::newRow("8th") << 7;
+ QTest::newRow("9th") << 8;
+ QTest::newRow("10th") << 9;
}
-void TabBarTest::tabbar()
+void TabBarTest::tabSizeHint()
{
- QWidget *w = new QWidget;
- SubTabBar widget(w);
+ QFETCH(int, index);
+
+ QVERIFY(_bar->call_tabSizeHint(index).width() > 0);
}
-// -------------------------------------------
-void TabBarTest::tabSizeHint_data()
+void TabBarTest::mousePress_data()
{
-// QTest::addColumn<int>("index");
-// QTest::newRow("0") << 0;
}
-// protected QSize tabSizeHint(int index) const
-void TabBarTest::tabSizeHint()
+void TabBarTest::mousePress()
{
- // Need fixes as our function uses MainView methods to determine size
-// QFETCH(int, index);
-// SubTabBar bar;
-// QVERIFY(bar.call_tabSizeHint(index).width() <= 250);
+// QTest::mousePress(_bar, Qt::MidButton);
+// // QCOMPARE(); ?
+//
+// QTest::mousePress(_bar, Qt::LeftButton);
+// // QCOMPARE(); ?
}
-
+
// -------------------------------------------
QTEST_KDEMAIN(TabBarTest, GUI)
diff --git a/src/tests/webpage_test.cpp b/src/tests/webpage_test.cpp
new file mode 100644
index 00000000..7afb5502
--- /dev/null
+++ b/src/tests/webpage_test.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2010 Andrea Diamantini <adjam7@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) 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 <qtest_kde.h>
+
+#include <QtTest>
+#include <QtCore>
+#include <QtWebKit>
+
+#include "webpage.h"
+#include "webview.h"
+#include "webtab.h"
+
+
+class WebPageTest : public QObject
+{
+ Q_OBJECT
+
+public:
+ WebPageTest();
+ virtual ~WebPageTest();
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private slots:
+ void manageNetworkErrors();
+ void downloadRequest();
+ void downloadAllContentsWithKGet();
+
+ void createWindow();
+ void acceptNavigationRequest();
+
+ void handleUnsupportedContent();
+
+ void loadFinished();
+
+private:
+ WebTab *tab;
+ WebPage *page;
+ WebView *view;
+};
+
+
+// -------------------------------------------
+
+
+WebPageTest::WebPageTest()
+{}
+
+
+WebPageTest::~WebPageTest()
+{}
+
+
+void WebPageTest::initTestCase()
+{
+ tab = new WebTab;
+ view = new WebView(tab);
+ page = view->page();
+}
+
+
+void WebPageTest::cleanupTestCase()
+{
+ delete tab;
+}
+
+
+// -------------------------------------------
+
+
+void WebPageTest::manageNetworkErrors()
+{
+}
+
+void WebPageTest::downloadRequest()
+{
+}
+
+void WebPageTest::downloadAllContentsWithKGet()
+{
+}
+
+void WebPageTest::createWindow()
+{
+}
+
+void WebPageTest::acceptNavigationRequest()
+{
+}
+
+void WebPageTest::handleUnsupportedContent()
+{
+}
+
+void WebPageTest::loadFinished()
+{
+}
+
+// -------------------------------------------
+
+QTEST_MAIN(WebPageTest)
+#include "webpage_test.moc"
diff --git a/src/tests/webtab_test.cpp b/src/tests/webtab_test.cpp
new file mode 100644
index 00000000..ae5647f3
--- /dev/null
+++ b/src/tests/webtab_test.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2010 Andrea Diamantini <adjam7@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) 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 <qtest_kde.h>
+
+#include <QtTest>
+#include <QtCore>
+#include <QtWebKit>
+
+#include "webpage.h"
+#include "webview.h"
+#include "webtab.h"
+
+
+class WebTabTest : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private:
+ WebTab *tab;
+};
+
+
+// -------------------------------------------
+
+
+void WebTabTest::initTestCase()
+{
+ tab = new WebTab;
+}
+
+
+void WebTabTest::cleanupTestCase()
+{
+ delete tab;
+}
+
+
+// -------------------------------------------
+
+
+// -------------------------------------------
+
+QTEST_MAIN(WebTabTest)
+#include "webtab_test.moc"