[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Is there any QTEST_MAIN-liked in kde4
From: "Roy Qu" <royqh1979 () gmail ! com>
Date: 2007-09-20 6:56:30
Message-ID: e1dda82e0709192356m7ac4d588j8b44577d8edef354 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Qt4 have nice built-in unittest support.
Now I'm trying it write a test for a kde4-based class , but can't get it
work.
The test class is defined as below:
14 class TestKConfigBindManager: public QObject {
15 Q_OBJECT
16 private slots:
17 void initTestCase() {
18 m_pConfig=new KConfig(QString(TESTCONFIG),KConfig::OnlyLocal);
19 m_pManager=new KConfigBindManager(m_pConfig);
20 }
21 void cleanUpTestCase(){
22 delete(m_pManager);
23 delete(m_pConfig);
24 }
25 void test(){
26 QCheckBox checkbox;
27 m_pManager->bind("<default>","doIt",&checkbox,true);
28 m_pManager->save();
29 }
30 public slots:
31 void showEvent(){
32 qDebug("states changed");
33 }
34 private:
35 KConfig* m_pConfig;
36 KConfigBindManager* m_pManager;
37 };
38
39 QTEST_MAIN(TestKConfigBindManger)
40 #include "testkconfigbindmanager.moc"
It can be complied, but when I run it, I got message like" QFATAL :
TestKConfigBindManager::initTestCase() Fatal error: you need to have a
KComponentData object before you do anything that requires it! Examples of
this are config objects, standard directories or translations."
It's obviously that the Qt4's QTEST_MAIN macro can't initialize data that a
kde4'app needed.
I have tried to change "QTEST_MAIN(TestKConfigBindManger)" to:
39 int main(int argc, char *argv[]) {
40 KAboutData aboutData("tutorial1", // The program
name used internally.
41 0, // The message catalog name, use
program name if null.
42 ki18n("Tutorial 1"), // A displayable program name string.
43 "1.0", // The program version string.
44 ki18n("KMessageBox popup"), // A short description of what
the program does.
45 KAboutData::License_GPL, // License identifier
46 ki18n("(c) 2007"), // Copyright Statement
47 ki18n("Some text..."), // Some free form text, that can
contain any kind of information.
48 "http://tutorial.com", // The program homepage string.
49 "submit@bugs.kde.org"); // The bug report email address
string.
50 KCmdLineArgs::init(argc,argv,&aboutData);
51 KApplication app();
52 TestKConfigBindManager tc;
53 return QTest::qExec(&tc, argc, argv);
54 }
But I won't work, either.
So how should I write the test case?
[Attachment #5 (text/html)]
Qt4 have nice built-in unittest support.<br>Now I'm trying it write a test for a \
kde4-based class , but can't get it work.<br><br>The test class is defined as \
below:<br>14 class TestKConfigBindManager: public QObject { \
<br> 15 Q_OBJECT<br> 16 private \
slots:<br> 17 void initTestCase() \
{<br> 18 m_pConfig=new \
KConfig(QString(TESTCONFIG),KConfig::OnlyLocal);<br> 19 \
m_pManager=new KConfigBindManager(m_pConfig);<br> 20 } \
<br> 21 void \
cleanUpTestCase(){<br> 22 \
delete(m_pManager);<br> 23 \
delete(m_pConfig);<br> 24 \
}<br> 25 void \
test(){<br> 26 QCheckBox \
checkbox;<br> 27 \
m_pManager->bind("<default>","doIt",&checkbox,true); \
<br> 28 \
m_pManager->save();<br> 29 }<br> 30 public \
slots:<br> 31 void \
showEvent(){<br> 32 \
qDebug("states changed");<br> 33 }<br> 34 \
private:<br> 35 KConfig* \
m_pConfig;<br> 36 KConfigBindManager* m_pManager; \
<br> 37 };<br> 38<br> 39 QTEST_MAIN(TestKConfigBindManger)<br> 40 \
#include "testkconfigbindmanager.moc"<br>It can be complied, but when I run \
it, I got message like" QFATAL : TestKConfigBindManager::initTestCase() Fatal \
error: you need to have a KComponentData object before you do anything that requires \
it! Examples of this are config objects, standard directories or translations." \
<br><br>It's obviously that the Qt4's QTEST_MAIN macro can't initialize \
data that a kde4'app needed.<br><br>I have tried to change \
"QTEST_MAIN(TestKConfigBindManger)" to:<br> 39 int main(int argc, char \
*argv[]) { <br> 40 KAboutData \
aboutData("tutorial1", \
// The program name used \
internally.<br> 41 \
0, \
// The message catalog name, use program name if \
null.<br> 42 ki18n("Tutorial \
1"), // A displayable \
program name string. <br> 43 \
"1.0", \
// The program version string.<br> 44 \
ki18n("KMessageBox popup"), // A short description of what \
the program \
does.<br> 45 \
KAboutData::License_GPL, // License identifier \
<br> 46 ki18n("(c) \
2007"), // \
Copyright Statement<br> 47 ki18n("Some \
text..."), // Some free form text, \
that can contain any kind of \
information.<br> 48 "<a href="http://tutorial.com"> \
http://tutorial.com</a>", // The \
program homepage string.<br> 49 "<a \
href="mailto:submit@bugs.kde.org">submit@bugs.kde.org</a>"); \
// The bug report email address string.<br> 50 \
KCmdLineArgs::init(argc,argv,&aboutData); <br> 51 \
KApplication app();<br> 52 TestKConfigBindManager \
tc;<br> 53 return QTest::qExec(&tc, argc, \
argv);<br> 54 }<br> But I won't work, either.<br><br>So how should I \
write the test case?<br><br><br>
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic