[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&#39;m trying it write a test for a \
kde4-based class , but can&#39;t get it work.<br><br>The test class is defined as \
below:<br>14 class TestKConfigBindManager: public QObject { \
<br>&nbsp;15&nbsp;&nbsp;&nbsp;&nbsp; Q_OBJECT<br>&nbsp;16 private \
slots:<br>&nbsp;17&nbsp;&nbsp;&nbsp;&nbsp; void initTestCase() \
{<br>&nbsp;18&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_pConfig=new \
KConfig(QString(TESTCONFIG),KConfig::OnlyLocal);<br>&nbsp;19&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
m_pManager=new KConfigBindManager(m_pConfig);<br>&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp; } \
<br>&nbsp;21&nbsp;&nbsp;&nbsp;&nbsp; void \
cleanUpTestCase(){<br>&nbsp;22&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
delete(m_pManager);<br>&nbsp;23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
delete(m_pConfig);<br>&nbsp;24&nbsp;&nbsp;&nbsp;&nbsp; \
}<br>&nbsp;25&nbsp;&nbsp;&nbsp;&nbsp; void \
test(){<br>&nbsp;26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QCheckBox \
checkbox;<br>&nbsp;27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
m_pManager-&gt;bind(&quot;&lt;default&gt;&quot;,&quot;doIt&quot;,&amp;checkbox,true); \
<br>&nbsp;28&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
m_pManager-&gt;save();<br>&nbsp;29&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;30 public \
slots:<br>&nbsp;31&nbsp;&nbsp;&nbsp;&nbsp; void \
showEvent(){<br>&nbsp;32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
qDebug(&quot;states changed&quot;);<br>&nbsp;33&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;34 \
private:<br>&nbsp;35&nbsp;&nbsp;&nbsp;&nbsp; KConfig* \
m_pConfig;<br>&nbsp;36&nbsp;&nbsp;&nbsp;&nbsp; KConfigBindManager* m_pManager; \
<br>&nbsp;37 };<br>&nbsp;38<br>&nbsp;39 QTEST_MAIN(TestKConfigBindManger)<br>&nbsp;40 \
#include &quot;testkconfigbindmanager.moc&quot;<br>It can be complied, but when I run \
it, I got message like&quot; 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.&quot; \
<br><br>It&#39;s obviously that the Qt4&#39;s QTEST_MAIN macro can&#39;t initialize \
data that a kde4&#39;app needed.<br><br>I have tried to change \
&quot;QTEST_MAIN(TestKConfigBindManger)&quot; to:<br>&nbsp;39 int main(int argc, char \
*argv[]) { <br>&nbsp;40&nbsp;&nbsp;&nbsp;&nbsp; KAboutData \
aboutData(&quot;tutorial1&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
// The program name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; used \
internally.<br>&nbsp;41&nbsp;&nbsp;&nbsp;&nbsp; \
0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
// The message catalog name, use program&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name if \
null.<br>&nbsp;42&nbsp;&nbsp;&nbsp;&nbsp; ki18n(&quot;Tutorial \
1&quot;),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // A displayable \
program name string. <br>&nbsp;43&nbsp;&nbsp;&nbsp;&nbsp; \
&quot;1.0&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
// The program version string.<br>&nbsp;44&nbsp;&nbsp;&nbsp;&nbsp; \
ki18n(&quot;KMessageBox popup&quot;),&nbsp;&nbsp; // A short description of what \
the&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; program \
does.<br>&nbsp;45&nbsp;&nbsp;&nbsp;&nbsp; \
KAboutData::License_GPL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // License identifier \
<br>&nbsp;46&nbsp;&nbsp;&nbsp;&nbsp; ki18n(&quot;(c) \
2007&quot;),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // \
Copyright Statement<br>&nbsp;47&nbsp;&nbsp;&nbsp;&nbsp; ki18n(&quot;Some \
text...&quot;),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Some free form text, \
that can contain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; any kind of \
information.<br>&nbsp;48&nbsp;&nbsp;&nbsp;&nbsp; &quot;<a href="http://tutorial.com"> \
http://tutorial.com</a>&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The \
program homepage string.<br>&nbsp;49&nbsp;&nbsp;&nbsp;&nbsp; &quot;<a \
href="mailto:submit@bugs.kde.org">submit@bugs.kde.org</a>&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
// The bug report email address string.<br>&nbsp;50&nbsp;&nbsp;&nbsp;&nbsp; \
KCmdLineArgs::init(argc,argv,&amp;aboutData); <br>&nbsp;51&nbsp;&nbsp;&nbsp;&nbsp; \
KApplication app();<br>&nbsp;52&nbsp;&nbsp;&nbsp;&nbsp; TestKConfigBindManager \
tc;<br>&nbsp;53&nbsp;&nbsp;&nbsp;&nbsp; return QTest::qExec(&amp;tc, argc, \
argv);<br>&nbsp;54 }<br>&nbsp;But I won&#39;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