51
|
1 |
/*!
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QtGui>
|
|
19 |
#include <QtTest/QtTest>
|
|
20 |
#include <mockservice.h>
|
|
21 |
|
|
22 |
#include <hbapplication.h>
|
|
23 |
#include <hblineedit.h>
|
|
24 |
|
|
25 |
#include "dialpadtest.h"
|
|
26 |
#include "dialpad.h"
|
|
27 |
#include "dialpadmailboxeventfilterbase.h"
|
|
28 |
|
|
29 |
|
|
30 |
// Dummy helper class
|
|
31 |
class DummyFilter : public DialpadMailboxEventFilterBase
|
|
32 |
{
|
|
33 |
Q_OBJECT
|
|
34 |
friend class ut_DialpadMailboxEventFilterBase;
|
|
35 |
public:
|
|
36 |
DummyFilter(Dialpad* dialpad, QObject* parent = 0);
|
|
37 |
virtual ~DummyFilter(){};
|
|
38 |
|
|
39 |
public:
|
|
40 |
bool eventFilter(QObject *, QEvent *){return true;};
|
|
41 |
bool handleCallButtonPress(){return true;};
|
|
42 |
void handleMailboxOperation(){};
|
|
43 |
|
|
44 |
public slots:
|
|
45 |
void handleLongKeyPress(){};
|
|
46 |
|
|
47 |
};
|
|
48 |
|
|
49 |
DummyFilter::DummyFilter(Dialpad *dialpad, QObject *parent)
|
|
50 |
:DialpadMailboxEventFilterBase(dialpad, parent)
|
|
51 |
{
|
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
// test class
|
|
56 |
class ut_DialpadMailboxEventFilterBase : public QObject, MockService
|
|
57 |
{
|
|
58 |
Q_OBJECT
|
|
59 |
|
|
60 |
public:
|
|
61 |
ut_DialpadMailboxEventFilterBase();
|
|
62 |
virtual ~ut_DialpadMailboxEventFilterBase();
|
|
63 |
|
|
64 |
private slots:
|
|
65 |
void init();
|
|
66 |
void cleanup();
|
|
67 |
|
|
68 |
// Mailbox event filter base unit tests
|
|
69 |
void testCheckIfSendEventAndConsumeEvent();
|
|
70 |
void testIsLongKeyPressSupported();
|
|
71 |
void testClearEditor();
|
|
72 |
void testCreateCall();
|
|
73 |
|
|
74 |
private:
|
|
75 |
DummyFilter *mEventFilter;
|
|
76 |
Dialpad *mDialpad;
|
|
77 |
};
|
|
78 |
|
|
79 |
|
|
80 |
ut_DialpadMailboxEventFilterBase::ut_DialpadMailboxEventFilterBase()
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
ut_DialpadMailboxEventFilterBase::~ut_DialpadMailboxEventFilterBase()
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
void ut_DialpadMailboxEventFilterBase::init()
|
|
89 |
{
|
|
90 |
initialize();
|
|
91 |
HbMainWindow *window = 0;
|
|
92 |
mDialpad = new Dialpad(*window);
|
|
93 |
mEventFilter = new DummyFilter(mDialpad);
|
|
94 |
}
|
|
95 |
|
|
96 |
void ut_DialpadMailboxEventFilterBase::cleanup()
|
|
97 |
{
|
|
98 |
delete mEventFilter;
|
|
99 |
delete mDialpad;
|
|
100 |
reset();
|
|
101 |
}
|
|
102 |
|
|
103 |
void ut_DialpadMailboxEventFilterBase::testCheckIfSendEventAndConsumeEvent()
|
|
104 |
{
|
|
105 |
int key = Qt::Key_Yes;
|
|
106 |
int type = QEvent::KeyPress;
|
|
107 |
bool handled = mEventFilter->checkIfSendEventAndConsumeEvent(key, type);
|
|
108 |
QVERIFY(handled);
|
|
109 |
|
|
110 |
key = Qt::Key_Enter;
|
|
111 |
type = QEvent::KeyRelease;
|
|
112 |
HbLineEdit line;
|
|
113 |
EXPECT(Dialpad, editor).returns(&line);
|
|
114 |
EXPECT(HbLineEdit, text).returns(QString("blah"));
|
|
115 |
handled = mEventFilter->checkIfSendEventAndConsumeEvent(key, type);
|
|
116 |
QVERIFY(verify() && handled);
|
|
117 |
|
|
118 |
key = Qt::Key_Enter;
|
|
119 |
type = QEvent::KeyRelease;
|
|
120 |
EXPECT(Dialpad, editor).returns(&line);
|
|
121 |
EXPECT(HbLineEdit, text).returns(QString(""));
|
|
122 |
handled = mEventFilter->checkIfSendEventAndConsumeEvent(key, type);
|
|
123 |
QVERIFY(verify() && !handled);
|
|
124 |
|
|
125 |
key = Qt::Key_Enter;
|
|
126 |
type = QEvent::MouseButtonPress;
|
|
127 |
handled = mEventFilter->checkIfSendEventAndConsumeEvent(key, type);
|
|
128 |
QVERIFY(!handled);
|
|
129 |
|
|
130 |
key = Qt::Key_Apostrophe;
|
|
131 |
handled = mEventFilter->checkIfSendEventAndConsumeEvent(key, type);
|
|
132 |
QVERIFY(!handled);
|
|
133 |
}
|
|
134 |
|
|
135 |
void ut_DialpadMailboxEventFilterBase::testIsLongKeyPressSupported()
|
|
136 |
{
|
|
137 |
int key = Qt::Key_Apostrophe;
|
|
138 |
bool supported = mEventFilter->isLongKeyPressSupported(key);
|
|
139 |
QVERIFY(!supported);
|
|
140 |
|
|
141 |
key = Qt::Key_1;
|
|
142 |
supported = mEventFilter->isLongKeyPressSupported(key);
|
|
143 |
QVERIFY(supported);
|
|
144 |
}
|
|
145 |
|
|
146 |
void ut_DialpadMailboxEventFilterBase::testClearEditor()
|
|
147 |
{
|
|
148 |
HbLineEdit line;
|
|
149 |
EXPECT(Dialpad, editor).returns(&line);
|
|
150 |
EXPECT(HbLineEdit, setText).with(QString(""));
|
|
151 |
mEventFilter->clearEditor();
|
|
152 |
QVERIFY(verify());
|
|
153 |
}
|
|
154 |
|
|
155 |
void ut_DialpadMailboxEventFilterBase::testCreateCall()
|
|
156 |
{
|
|
157 |
QString number("313");
|
|
158 |
mEventFilter->createCall(number, true);
|
|
159 |
mEventFilter->createCall(number, false);
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
DIALPAD_TEST_MAIN(ut_DialpadMailboxEventFilterBase)
|
|
164 |
#include "ut_dialpadmailboxeventfilterbase.moc"
|
|
165 |
|