Qt 5.10 Book Examples
chapter45
DataDrivenTest
test.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// test.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtTest>
12
#include "
MyClass.h
"
13
14
// ======================================================================
15
class
Test_MyClass
:
public
QObject {
16
Q_OBJECT
17
private
slots:
18
void
min_data();
19
void
max_data();
20
21
void
min();
22
void
max();
23
};
24
25
// ----------------------------------------------------------------------
26
void
Test_MyClass::min_data()
27
{
28
QTest::addColumn<int>(
"arg1"
);
29
QTest::addColumn<int>(
"arg2"
);
30
QTest::addColumn<int>(
"result"
);
31
32
QTest::newRow(
"min_test1"
) << 25 << 0 << 0;
33
QTest::newRow(
"min_test2"
) << -12 << -5 << -12;
34
QTest::newRow(
"min_test3"
) << 2007 << 2007 << 2007;
35
QTest::newRow(
"min_test4"
) << -12 << 5 << -12;
36
}
37
38
// ----------------------------------------------------------------------
39
void
Test_MyClass::max_data()
40
{
41
QTest::addColumn<int>(
"arg1"
);
42
QTest::addColumn<int>(
"arg2"
);
43
QTest::addColumn<int>(
"result"
);
44
45
QTest::newRow(
"max_test1"
) << 25 << 0 << 25;
46
QTest::newRow(
"max_test2"
) << -12 << -5 << -5;
47
QTest::newRow(
"max_test3"
) << 2007 << 2007 << 2007;
48
QTest::newRow(
"max_test4"
) << -12 << 5 << 5;
49
}
50
51
// ----------------------------------------------------------------------
52
void
Test_MyClass::min()
53
{
54
MyClass
myClass;
55
QFETCH(
int
, arg1);
56
QFETCH(
int
, arg2);
57
QFETCH(
int
, result);
58
59
QCOMPARE(myClass.
min
(arg1, arg2), result);
60
}
61
62
// ----------------------------------------------------------------------
63
void
Test_MyClass::max()
64
{
65
MyClass
myClass;
66
QFETCH(
int
, arg1);
67
QFETCH(
int
, arg2);
68
QFETCH(
int
, result);
69
70
QCOMPARE(myClass.
max
(arg1, arg2), result);
71
}
72
73
QTEST_MAIN(
Test_MyClass
)
74
#include "test.moc"
Test_MyClass
Definition:
test.cpp:15
MyClass::max
int max(int n1, int n2)
Definition:
MyClass.h:21
MyClass.h
MyClass::min
int min(int n1, int n2)
Definition:
MyClass.h:16
MyClass
Definition:
MyClass.h:14
Generated by
1.8.14