The Simple Test

April 21, 2009 at 11:37 pm Leave a comment

I am learning a few of QtTest and I am showing the simple and little test  for QtDate . The test verify if  the date is valid and compare the actual date.

== test.cpp==

1 #include <QtTest>
2
3
4
5 class testDate: public QObject
6 {
7 Q_OBJECT
8
9 private slots:
10
11 void testValidity();
12 void testCurrentDate();
13
14 };
15
16 /* Here the test for verifying if the date is Valid, can you change the Day for plus 31 and the Mo nth plus 12 */
17 void testDate::testValidity()
18 {
19 QDate date (2009, 04, 33);
20 QVERIFY(date.isValid());
21 }
22
23
24 /* Here the Date is compared with the actual Date */
25 void testDate::testCurrentDate()
26 {
27
28 QDate date, date2;
29 date.setYMD(2009, 4, 22);
30 date2 = QDate::currentDate();
31 QCOMPARE(date, date2);
32 }
33
34
35
36
37 QTEST_MAIN(testDate);
38 #include “test1.moc”

==

QVERIFY ( condition )

The QVERIFY() macro checks whether the condition is true or not. If it is true, execution continues. If not, a failure is recorded in the test log and the test won’t be executed further.

QCOMPARE ( actual, expected )

The QCOMPARE macro compares an actual value to an expected value using the equals operator. If actual and expected are identical, execution continues. If not, a failure is recorded in the test log and the test won’t be executed further.

References:

http://doc.trolltech.com/4.5/qtestlib-manual.html

Advertisements

Entry filed under: Qt. Tags: .

State Machine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

April 2009
M T W T F S S
    Jul »
 12345
6789101112
13141516171819
20212223242526
27282930  

Most Recent Posts


%d bloggers like this: