summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/sql/kernel/qsqlfield/tst_qsqlfield.cpp36
-rw-r--r--tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp18
2 files changed, 47 insertions, 7 deletions
diff --git a/tests/auto/sql/kernel/qsqlfield/tst_qsqlfield.cpp b/tests/auto/sql/kernel/qsqlfield/tst_qsqlfield.cpp
index cee33be3df..7efd19a2b8 100644
--- a/tests/auto/sql/kernel/qsqlfield/tst_qsqlfield.cpp
+++ b/tests/auto/sql/kernel/qsqlfield/tst_qsqlfield.cpp
@@ -62,6 +62,8 @@ private slots:
void isNull();
void clear_data();
void clear();
+ void setTableName_data();
+ void setTableName();
};
// Testing get/set functions
@@ -212,6 +214,9 @@ void tst_QSqlField::operator_Assign()
field3.clear();
field1 = field3;
QVERIFY( field1 == field3 );
+ QSqlField field4("test", QVariant::String, "ATable");
+ field1 = field4;
+ QVERIFY(field1 == field4);
}
void tst_QSqlField::operator_Equal()
@@ -219,8 +224,18 @@ void tst_QSqlField::operator_Equal()
QSqlField field1( "test", QVariant::String );
QSqlField field2( "test2", QVariant::String );
QSqlField field3( "test", QVariant::Int );
+ QSqlField field4("test", QVariant::String, QString("ATable"));
+ QSqlField field5("test2", QVariant::String, QString("ATable"));
+ QSqlField field6("test", QVariant::String, QString("BTable"));
+
QVERIFY( !(field1 == field2) );
QVERIFY( !(field1 == field3) );
+ QVERIFY(field1 != field4);
+ QVERIFY(field1 != field5);
+ QVERIFY(field1 != field6);
+ QVERIFY(field4 != field5);
+ QVERIFY(field4 != field6);
+
field2.setName( "test" );
QVERIFY( field1 == field2 );
QVERIFY( field1 == field2 );
@@ -232,6 +247,10 @@ void tst_QSqlField::operator_Equal()
QVERIFY( !(field1 == field2) );
field2.setReadOnly( true );
QVERIFY( field1 == field2 );
+ field4.setTableName("BTable");
+ QCOMPARE(field4, field6);
+ field6.setName("test3");
+ QVERIFY(field4 != field6);
}
void tst_QSqlField::setName_data()
@@ -333,5 +352,22 @@ void tst_QSqlField::type()
QVERIFY( field3.type() == QVariant::Double );
}
+void tst_QSqlField::setTableName_data()
+{
+ QTest::addColumn<QString>("tableName");
+
+ QTest::newRow("data0") << QString("");
+ QTest::newRow("data1") << QString("tbl");
+}
+
+void tst_QSqlField::setTableName()
+{
+ QSqlField field("test", QVariant::String, "test");
+ QFETCH(QString, tableName);
+ QCOMPARE(field.tableName(), QLatin1String("test"));
+ field.setTableName(tableName);
+ QCOMPARE(field.tableName(), tableName);
+}
+
QTEST_MAIN(tst_QSqlField)
#include "tst_qsqlfield.moc"
diff --git a/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp b/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp
index c5cca6c33b..83a61b91d7 100644
--- a/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp
+++ b/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp
@@ -111,10 +111,10 @@ void tst_QSqlRecord::createTestRecord()
{
delete rec;
rec = new QSqlRecord();
- fields[ 0 ] = new QSqlField( "string", QVariant::String );
- fields[ 1 ] = new QSqlField( "int", QVariant::Int );
- fields[ 2 ] = new QSqlField( "double", QVariant::Double );
- fields[ 3 ] = new QSqlField( "bool", QVariant::Bool );
+ fields[0] = new QSqlField(QStringLiteral("string"), QVariant::String, QStringLiteral("stringtable"));
+ fields[1] = new QSqlField(QStringLiteral("int"), QVariant::Int, QStringLiteral("inttable"));
+ fields[2] = new QSqlField(QStringLiteral("double"), QVariant::Double, QStringLiteral("doubletable"));
+ fields[3] = new QSqlField(QStringLiteral("bool"), QVariant::Bool);
for ( int i = 0; i < NUM_FIELDS; ++i )
rec->append( *(fields[ i ] ) );
}
@@ -124,12 +124,14 @@ void tst_QSqlRecord::append()
{
delete rec;
rec = new QSqlRecord();
- rec->append( QSqlField( "string", QVariant::String ) );
+ rec->append(QSqlField("string", QVariant::String, QStringLiteral("stringtable")));
QCOMPARE( rec->field( 0 ).name(), (QString) "string" );
+ QCOMPARE(rec->field(0).tableName(), QStringLiteral("stringtable"));
QVERIFY( !rec->isEmpty() );
QCOMPARE( (int)rec->count(), 1 );
- rec->append( QSqlField( "int", QVariant::Int ) );
+ rec->append(QSqlField("int", QVariant::Int, QStringLiteral("inttable")));
QCOMPARE( rec->field( 1 ).name(), (QString) "int" );
+ QCOMPARE(rec->field(1).tableName(), QStringLiteral("inttable"));
QCOMPARE( (int)rec->count(), 2 );
rec->append( QSqlField( "double", QVariant::Double ) );
QCOMPARE( rec->field( 2 ).name(), (QString) "double" );
@@ -381,7 +383,7 @@ void tst_QSqlRecord::operator_Assign()
buf3.remove( NUM_FIELDS - 1 );
QSqlRecord buf5 = buf3;
for ( i = 0; i < NUM_FIELDS - 1; ++i ) {
- QSqlField fi ( fields[ i ]->name(), fields[ i ]->type() );
+ QSqlField fi(fields[i]->name(), fields[i]->type(), fields[i]->tableName());
fi.clear();
QVERIFY( buf5.field( i ) == fi );
QVERIFY( buf5.isGenerated( i ) );
@@ -394,6 +396,8 @@ void tst_QSqlRecord::position()
int i;
for ( i = 0; i < NUM_FIELDS; ++i ) {
QCOMPARE( rec->indexOf( fields[ i ]->name() ), i );
+ if (!fields[i]->tableName().isEmpty())
+ QCOMPARE(rec->indexOf(fields[i]->tableName() + QChar('.') + fields[i]->name()), i);
}
}