Added MessagePanel unit test and added addHeaderItem method to panels.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 9 Nov 2010 12:22:49 +0000 (14:22 +0200)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 9 Nov 2010 12:22:49 +0000 (14:22 +0200)
src/ui/meetpeoplepanel.cpp
src/ui/meetpeoplepanel.h
src/ui/messagelistitem.cpp
src/ui/messagelistitem.h
src/ui/messagepanel.cpp
src/ui/messagepanel.h
tests/stubs/messagelistviewstub.h [new file with mode: 0644]
tests/stubs/stubs.pro
tests/ui/messagepanel/messagepanel.pro [new file with mode: 0644]
tests/ui/messagepanel/testmessagepanel.cpp [new file with mode: 0644]

index 95e94f6..dc68f4e 100644 (file)
@@ -65,6 +65,14 @@ MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
     m_itemButtonsLayout->addWidget(messageButton);
 }
 
+void MeetPeoplePanel::addHeaderItem(const QString &key, const QString &title)
+{
+    m_personListView->setItemDelegateForRow(m_personListView->count(), m_headerListItemDelegate);
+    ExtendedListItem *friendsHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
+    friendsHeaderItem->setTitle(title);
+    m_personListView->addListItem(key, friendsHeaderItem);
+}
+
 void MeetPeoplePanel::anyPanelClosed()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -153,10 +161,7 @@ void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &friends, QL
     initItemDelegates();
 
     if (friends.count() > 0) {
-        m_personListView->setItemDelegateForRow(0, m_headerListItemDelegate);
-        ExtendedListItem *friendsHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
-        friendsHeaderItem->setTitle(tr("Friends:"));
-        m_personListView->addListItem(QString("friendsHeader"), friendsHeaderItem);
+        addHeaderItem("friendsHeader", tr("Friends:"));
 
         foreach (User user, friends) {
             PersonListItem *item = new PersonListItem();
@@ -166,6 +171,8 @@ void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &friends, QL
     }
 
     if (others.count() > 0) {
+        addHeaderItem("friendsHeader", tr("Friends:"));
+
         m_personListView->setItemDelegateForRow(m_personListView->count(),
                                                 m_headerListItemDelegate);
         ExtendedListItem *othersHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
index 8407d83..4fcb2c0 100644 (file)
@@ -65,6 +65,9 @@ protected:
     */
     void hideEvent(QHideEvent *event);
 
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
 private slots:
     /**
     * @brief Called when any of the panel tabs is closed
@@ -112,10 +115,21 @@ private slots:
 
 private:
     /**
+    * @brief Adds header item to the list.
+    *
+    * @param key item key
+    * @param title item title
+    */
+    void addHeaderItem(const QString &key, const QString &title);
+
+    /**
     * @brief Inits item delegates for message list view.
     */
     void initItemDelegates();
 
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
 signals:
     /**
      * @brief Signal for person finding
index 4f054d4..cfd9c38 100644 (file)
@@ -17,21 +17,21 @@ MessageListItem::~MessageListItem()
     qDebug() << __PRETTY_FUNCTION__;
 }
 
-GeoCoordinate &MessageListItem::coordinates() const
+GeoCoordinate MessageListItem::coordinates() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     return m_coordinates;
 }
 
-QString &MessageListItem::id() const
+QString MessageListItem::id() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     return m_id;
 }
 
-QString &MessageListItem::newMessageReceiverId() const
+QString MessageListItem::newMessageReceiverId() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
index 38907be..e1efba0 100644 (file)
@@ -56,21 +56,21 @@ public:
     *
     * @return item's coordinates
     */
-    GeoCoordinate &coordinates() const;
+    GeoCoordinate coordinates() const;
 
     /**
     * @brief Returns message's ID.
     *
     * @return message's ID
     */
-    QString &id() const;
+    QString id() const;
 
     /**
     * @brief Returns new message message receiver's ID.
     *
     * @return new message message receiver's ID
     */
-    QString &newMessageReceiverId() const;
+    QString newMessageReceiverId() const;
 
     /**
     * @brief Sets new message message receiver's ID.
@@ -91,7 +91,7 @@ public:
 ******************************************************************************/
 private:
     QString m_id;                   ///< message's ID
-    QString m_newMessageReceiverId;           ///< new message reveiver's ID
+    QString m_newMessageReceiverId; ///< new message reveiver's ID
 
     GeoCoordinate m_coordinates;    ///< message's coordinates
 };
index 5bc7eeb..3561294 100644 (file)
@@ -28,7 +28,7 @@
 #include "messagelistitem.h"
 #include "messagelistview.h"
 #include "panelcommon.h"
-#include "situareservice/message.h"
+#include "../situareservice/message.h"
 
 #include "messagepanel.h"
 
@@ -84,6 +84,14 @@ MessagePanel::MessagePanel(QWidget *parent)
     m_genericButtonsLayout->addWidget(refreshMessagesButton);
 }
 
+void MessagePanel::addHeaderItem(const QString &key, const QString &title)
+{
+    m_messageListView->setItemDelegateForRow(m_messageListView->count(), m_headerListItemDelegate);
+    ExtendedListItem *receivedHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
+    receivedHeaderItem->setTitle(title);
+    m_messageListView->addListItem(key, receivedHeaderItem);
+}
+
 void MessagePanel::anyPanelClosed()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -144,10 +152,7 @@ void MessagePanel::populateMessageListView(QList<Message> &received, QList<Messa
     initItemDelegates();
 
     if (received.count() > 0) {
-        m_messageListView->setItemDelegateForRow(0, m_headerListItemDelegate);
-        ExtendedListItem *receivedHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
-        receivedHeaderItem->setTitle(tr("Received:"));
-        m_messageListView->addListItem(QString("receivedHeader"), receivedHeaderItem);
+        addHeaderItem("receivedHeader", tr("Received from:"));
 
         foreach (Message message, received) {
             MessageListItem *item = new MessageListItem();
@@ -157,11 +162,7 @@ void MessagePanel::populateMessageListView(QList<Message> &received, QList<Messa
     }
 
     if (sent.count() > 0) {
-        m_messageListView->setItemDelegateForRow(m_messageListView->count(),
-                                                 m_headerListItemDelegate);
-        ExtendedListItem *sentHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
-        sentHeaderItem->setTitle(tr("Sent:"));
-        m_messageListView->addListItem(QString("sentHeader"), sentHeaderItem);
+        addHeaderItem("sentHeader", tr("Sent to:"));
 
         foreach (Message message, sent) {
             MessageListItem *item = new MessageListItem();
index 5f4ce61..eb91e9e 100644 (file)
@@ -42,6 +42,11 @@ class MessagePanel : public PanelBase
 
 public:
     /**
+    * @brief Unit test class
+    */
+    friend class TestMessagePanel;
+
+    /**
      * @brief Default constructor
      *
      * @param parent
@@ -104,6 +109,14 @@ private slots:
 
 private:
     /**
+    * @brief Adds header item to the list.
+    *
+    * @param key item key
+    * @param title item title
+    */
+    void addHeaderItem(const QString &key, const QString &title);
+
+    /**
     * @brief Inits item delegates for message list view.
     */
     void initItemDelegates();
diff --git a/tests/stubs/messagelistviewstub.h b/tests/stubs/messagelistviewstub.h
new file mode 100644 (file)
index 0000000..ec122c0
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare 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.
+
+   Situare 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 Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef PERSONLISTVIEWSTUB_H
+#define PERSONLISTVIEWSTUB_H
+
+#include "../../src/ui/messagelistview.h"
+#include "listviewstub.h"
+#include "stubbase.h"
+
+class MessageListViewStub : public StubBase
+{
+public:
+    virtual void MessageListViewConstructor(QWidget *parent = 0);
+    virtual bool listItemClicked(ListItem *item);
+};
+
+void MessageListViewStub::MessageListViewConstructor(QWidget *parent)
+{
+    Q_UNUSED(parent)
+}
+
+bool MessageListViewStub::listItemClicked(ListItem *item)
+{
+    QList<ParameterBase *> params;
+    params.append(new Parameter<ListItem *>(item));
+    stubMethodEntered("listItemClicked", params);
+
+    return stubReturnValue<bool>("listItemClicked");
+}
+
+//Create a stub instance
+MessageListViewStub defaultMessageListViewStub;
+MessageListViewStub *messageListViewStub = &defaultMessageListViewStub;
+
+MessageListView::MessageListView(QWidget *parent)
+    : ListView(parent)
+{
+    messageListViewStub->MessageListViewConstructor(parent);
+}
+
+bool MessageListView::listItemClicked(ListItem *item)
+{
+    return messageListViewStub->listItemClicked(item);
+}
+
+#endif // PERSONLISTVIEWSTUB_H
index 31572de..eeb3717 100644 (file)
@@ -9,7 +9,8 @@ HEADERS += \
     listviewstub.h \
     listitemstub.h \
     extendedlistitemstub.h \
-    messagelistitemstub.h
+    messagelistitemstub.h \
+    messagelistviewstub.h
 
 SOURCES += \
     stubbase.cpp
diff --git a/tests/ui/messagepanel/messagepanel.pro b/tests/ui/messagepanel/messagepanel.pro
new file mode 100644 (file)
index 0000000..d7bd912
--- /dev/null
@@ -0,0 +1,36 @@
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+
+INCLUDEPATH += ../../stubs/
+
+HEADERS += \
+    ../../stubs/stubbase.h \
+    ../../stubs/messagelistitemstub.h \
+    ../../stubs/messagelistviewstub.h \
+    ../../../src/ui/messagelistview.h \
+    ../../../src/ui/listview.h \
+    ../../../src/ui/imagebutton.h \
+    ../../../src/ui/messagepanel.h \
+    ../../../src/ui/panelcommon.h \
+    ../../../src/ui/panelbase.h \
+    ../../../src/ui/extendedlistitemdelegate.h \
+    ../../../src/ui/extendedlistitemstore.h \
+    ../../../src/ui/headerlistitemdelegate.h \
+    ../../../src/ui/listitemdelegate.h \
+    ../../../src/coordinates/geocoordinate.h \
+    ../../../src/coordinates/scenecoordinate.h \
+    ../../../src/situareservice/message.h \
+
+SOURCES += \
+    ../../stubs/stubbase.cpp \
+    ../../../src/ui/messagepanel.cpp \
+    ../../../src/coordinates/geocoordinate.cpp \
+    ../../../src/ui/panelbase.cpp \
+    ../../../src/ui/imagebutton.cpp \
+    ../../../src/ui/extendedlistitemdelegate.cpp \
+    ../../../src/ui/headerlistitemdelegate.cpp \
+    ../../../src/ui/extendedlistitemstore.cpp \
+    ../../../src/situareservice/message.cpp \
+    ../../../src/coordinates/scenecoordinate.cpp \
+    ../../../src/ui/listitemdelegate.cpp \
+    testmessagepanel.cpp
diff --git a/tests/ui/messagepanel/testmessagepanel.cpp b/tests/ui/messagepanel/testmessagepanel.cpp
new file mode 100644 (file)
index 0000000..cfb489d
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare 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.
+
+   Situare 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 Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QtTest>
+#include <QtGui>
+#include <QMetaType>
+
+#include "../../stubs/messagelistviewstub.h"
+#include "../../stubs/messagelistitemstub.h"
+
+#include "../../../src/ui/messagepanel.h"
+
+class TestMessagePanel: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void cleanup();
+    void init();
+    void messageButtonPressed();
+
+private:
+    QList<Message> getMessages();
+
+private:
+    MessagePanel *m_messagePanel;
+};
+
+void TestMessagePanel::cleanup()
+{
+    delete m_messagePanel;
+
+    listViewStub->stubReset();
+}
+
+void TestMessagePanel::init()
+{
+    m_messagePanel = new MessagePanel();
+    QVERIFY(m_messagePanel);
+}
+
+QList<Message> TestMessagePanel::getMessages()
+{
+    QList<Message> messages;
+    Message message1;
+    message1.setSenderId("1");
+    message1.setReceiverId("2");
+    Message message2(Message::MessageTypeSent);
+    message2.setSenderId("3");
+    message2.setReceiverId("4");
+    messages.append(message1);
+    messages.append(message2);
+
+    return messages;
+}
+
+void TestMessagePanel::messageButtonPressed()
+{
+    MessageListItem messageItem;
+    messageItem.setMessageData(getMessages().at(0));
+    messageListItemStub->stubSetReturnValue("newMessageReceiverId", QString("1"));
+
+    typedef QPair<QString, QString> ReceiverPair;
+    Q_DECLARE_METATYPE(ReceiverPair);
+    qRegisterMetaType< QPair<QString, QString> >("QPair<QString,QString>");
+
+    QSignalSpy requestMessageDialogSpy(m_messagePanel,
+                                       SIGNAL(requestMessageDialog(QPair<QString,QString>)));
+    QVERIFY(requestMessageDialogSpy.isValid());
+
+    listViewStub->stubSetReturnValue("selectedItem", (ListItem*)0);
+
+    m_messagePanel->messageButtonPressed();
+    QCOMPARE(requestMessageDialogSpy.count(), 0);
+
+    listViewStub->stubSetReturnValue("selectedItem", (ListItem*)&messageItem);
+
+    m_messagePanel->messageButtonPressed();
+    QCOMPARE(listViewStub->stubCallCount("clearItemSelection"), 1);
+    QCOMPARE(requestMessageDialogSpy.count(), 1);
+    QList<QVariant> arguments = requestMessageDialogSpy.takeFirst();
+    //QPair<QString, QString> receiver = arguments.at(0).value<QPair<QString, QString> >();
+}
+
+QTEST_MAIN(TestMessagePanel)
+#include "testmessagepanel.moc"
+
+