diff --git a/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp b/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp index 478dec6ac4..4d41c6aaa9 100644 --- a/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp +++ b/tests/auto/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp @@ -14,12 +14,7 @@ class tst_QSqlRecord : public QObject { -Q_OBJECT - -public: - tst_QSqlRecord(); - virtual ~tst_QSqlRecord(); - + Q_OBJECT public slots: void init(); @@ -47,26 +42,11 @@ private slots: void append(); private: - QSqlRecord* rec; - QSqlField* fields[ NUM_FIELDS ]; + std::unique_ptr rec; + std::array, NUM_FIELDS> fields; void createTestRecord(); }; -tst_QSqlRecord::tst_QSqlRecord() -{ - rec = 0; - for ( int i = 0; i < NUM_FIELDS; ++i ) - fields[ i ] = 0; -} - -tst_QSqlRecord::~tst_QSqlRecord() -{ - delete rec; - for ( int i = 0; i < NUM_FIELDS; ++i ) - delete fields[ i ]; - rec = 0; -} - void tst_QSqlRecord::init() { cleanup(); @@ -74,31 +54,26 @@ void tst_QSqlRecord::init() void tst_QSqlRecord::cleanup() { - delete rec; - for ( int i = 0; i < NUM_FIELDS; ++i ) { - delete fields[ i ]; - fields[ i ] = 0; - } - rec = 0; + rec = nullptr; + for (auto &field : fields) + field = nullptr; } void tst_QSqlRecord::createTestRecord() { - delete rec; - rec = new QSqlRecord(); - fields[0] = new QSqlField(QStringLiteral("string"), QMetaType(QMetaType::QString), QStringLiteral("stringtable")); - fields[1] = new QSqlField(QStringLiteral("int"), QMetaType(QMetaType::Int), QStringLiteral("inttable")); - fields[2] = new QSqlField(QStringLiteral("double"), QMetaType(QMetaType::Double), QStringLiteral("doubletable")); - fields[3] = new QSqlField(QStringLiteral("bool"), QMetaType(QMetaType::Bool)); - for ( int i = 0; i < NUM_FIELDS; ++i ) - rec->append( *(fields[ i ] ) ); + rec = std::make_unique(); + fields[0] = std::make_unique(QStringLiteral("string"), QMetaType(QMetaType::QString), QStringLiteral("stringtable")); + fields[1] = std::make_unique(QStringLiteral("int"), QMetaType(QMetaType::Int), QStringLiteral("inttable")); + fields[2] = std::make_unique(QStringLiteral("double"), QMetaType(QMetaType::Double), QStringLiteral("doubletable")); + fields[3] = std::make_unique(QStringLiteral("bool"), QMetaType(QMetaType::Bool)); + for (const auto &field : fields) + rec->append(*field); } void tst_QSqlRecord::append() { - delete rec; - rec = new QSqlRecord(); + rec = std::make_unique(); rec->append(QSqlField("string", QMetaType(QMetaType::QString), QStringLiteral("stringtable"))); QCOMPARE( rec->field( 0 ).name(), (QString) "string" ); QCOMPARE(rec->field(0).tableName(), QStringLiteral("stringtable")); @@ -157,10 +132,7 @@ void tst_QSqlRecord::clearValues() QFETCH( double, dval ); QFETCH( int, bval ); - if(rec) - delete rec; - - rec = new QSqlRecord(); + rec = std::make_unique(); rec->append( QSqlField( "string", QMetaType(QMetaType::QString) ) ); QCOMPARE( rec->field(0).name(), (QString) "string" ); QVERIFY( !rec->isEmpty() ); @@ -200,8 +172,8 @@ void tst_QSqlRecord::clearValues() void tst_QSqlRecord::contains() { createTestRecord(); - for ( int i = 0; i < NUM_FIELDS; ++i ) - QVERIFY( rec->contains( fields[ i ]->name() ) ); + for (const auto &field : fields) + QVERIFY(rec->contains(field->name())); QVERIFY( !rec->contains( "__Harry__" ) ); } @@ -233,8 +205,8 @@ void tst_QSqlRecord::fieldName() { createTestRecord(); - for ( int i = 0; i < NUM_FIELDS; ++i ) - QVERIFY( rec->field( (fields[ i ] )->name() ) == *( fields[ i ] ) ); + for (const auto &field : fields) + QVERIFY(rec->field(field->name()) == *field); QVERIFY( rec->fieldName( NUM_FIELDS ).isNull() ); } @@ -412,8 +384,7 @@ void tst_QSqlRecord::setValue() { int i; - delete rec; - rec = new QSqlRecord(); + rec = std::make_unique(); rec->append( QSqlField( "string", QMetaType(QMetaType::QString) ) ); QCOMPARE( rec->field( 0 ).name(), (QString) "string" ); QVERIFY( !rec->isEmpty() );