-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeletetest.cpp
65 lines (53 loc) · 1.95 KB
/
deletetest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#define QUERYBUILDER_UNITTEST
#include "testschema.h"
#include "testbase.h"
#include "Sql.h"
#include "SqlDelete.h"
#include <QObject>
#include <QtTest/QtTest>
using namespace Sql;
Q_DECLARE_METATYPE( SqlDeleteQueryBuilder )
Q_DECLARE_METATYPE( QVector<QVariant> )
class DeleteTest : public TestBase
{
Q_OBJECT
private Q_SLOTS:
void initTestCase() {
openDbTest();
createEmptyDb();
}
void testDelete_data()
{
QTest::addColumn<SqlDeleteQueryBuilder>( "qb" );
QTest::addColumn<QString>( "sql" );
QTest::addColumn<QVector<QVariant> >( "bindVals" );
QTest::newRow( "delete rows, one condition" )
<< del()
.from( Person )
.where( Person.PersonSurname == QLatin1String( "Ford" ) ).queryBuilder()
<< "DELETE FROM tblPerson WHERE tblPerson.PersonSurname = :0"
<< (QVector<QVariant>() << QLatin1String( "Ford" ));
QTest::newRow( "delete rows, multiple conditions" )
<< del()
.from( Person )
.where( Person.PersonSurname == QLatin1String( "Ford" ) && Person.PersonForename == QLatin1String( "Gerald" )).queryBuilder()
<< "DELETE FROM tblPerson WHERE (tblPerson.PersonSurname = :0 AND tblPerson.PersonForename = :1)"
<< (QVector<QVariant>() << QLatin1String( "Ford" ) << QLatin1String("Gerald"));
QTest::newRow( "delete all rows" )
<< del()
.from( Person ).queryBuilder()
<< "DELETE FROM tblPerson"
<< QVector<QVariant>();
}
void testDelete()
{
QFETCH( SqlDeleteQueryBuilder, qb );
QFETCH( QString, sql );
QFETCH( QVector<QVariant>, bindVals );
qb.query(); // trigger query assembly
QCOMPARE( qb.m_queryString, sql );
QCOMPARE( qb.m_bindValues, bindVals );
}
};
QTEST_MAIN( DeleteTest )
#include "deletetest.moc"