QSqlIndex: add move ctor & move operator
Add the move ctor and move operator for QSqlIndex, also add an explicit testcase for QSqlIndex Task-number: QTBUG-109938 Change-Id: I46cc6a24c2e7d5b23d2ac3427cafd01b9ba257ed Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
9f44553b3d
commit
46e909a37a
@ -41,6 +41,25 @@ QSqlIndex::QSqlIndex(const QSqlIndex& other)
|
||||
{
|
||||
}
|
||||
|
||||
/*! \fn QSqlIndex::QSqlIndex(QSqlIndex &&other)
|
||||
Move-constructs a new QSqlIndex from \a other.
|
||||
|
||||
\note The moved-from object \a other is placed in a
|
||||
partially-formed state, in which the only valid operations are
|
||||
destruction and assignment of a new value.
|
||||
|
||||
\since 6.6
|
||||
*/
|
||||
/*! \fn QSqlIndex& QSqlIndex::operator=(QSqlIndex &&other)
|
||||
Move-assigns \a other to this QSqlIndex instance.
|
||||
|
||||
\note The moved-from object \a other is placed in a
|
||||
partially-formed state, in which the only valid operations are
|
||||
destruction and assignment of a new value.
|
||||
|
||||
\since 6.6
|
||||
*/
|
||||
|
||||
/*!
|
||||
Sets the index equal to \a other.
|
||||
*/
|
||||
@ -54,6 +73,7 @@ QSqlIndex& QSqlIndex::operator=(const QSqlIndex& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Destroys the object and frees any allocated resources.
|
||||
*/
|
||||
|
@ -17,8 +17,11 @@ class Q_SQL_EXPORT QSqlIndex : public QSqlRecord
|
||||
public:
|
||||
explicit QSqlIndex(const QString &cursorName = QString(), const QString &name = QString());
|
||||
QSqlIndex(const QSqlIndex &other);
|
||||
QSqlIndex(QSqlIndex &&other) noexcept = default;
|
||||
~QSqlIndex();
|
||||
QSqlIndex &operator=(const QSqlIndex &other);
|
||||
QSqlIndex &operator=(QSqlIndex &&other) = default;
|
||||
|
||||
void setCursorName(const QString &cursorName);
|
||||
inline QString cursorName() const { return cursor; }
|
||||
void setName(const QString& name);
|
||||
@ -32,6 +35,7 @@ public:
|
||||
|
||||
private:
|
||||
QString createField(int i, const QString& prefix, bool verbose) const;
|
||||
// ### Qt7: move to d-ptr
|
||||
QString cursor;
|
||||
QString nm;
|
||||
QList<bool> sorts;
|
||||
|
@ -5,6 +5,7 @@ add_subdirectory(qsqlfield)
|
||||
add_subdirectory(qsqldatabase)
|
||||
add_subdirectory(qsqlerror)
|
||||
add_subdirectory(qsqldriver)
|
||||
add_subdirectory(qsqlindex)
|
||||
add_subdirectory(qsqlquery)
|
||||
add_subdirectory(qsqlrecord)
|
||||
add_subdirectory(qsqlthread)
|
||||
|
15
tests/auto/sql/kernel/qsqlindex/CMakeLists.txt
Normal file
15
tests/auto/sql/kernel/qsqlindex/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2023 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qsqlindex Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qsqlindex
|
||||
SOURCES
|
||||
tst_qsqlindex.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Sql
|
||||
Qt::SqlPrivate
|
||||
)
|
126
tests/auto/sql/kernel/qsqlindex/tst_qsqlindex.cpp
Normal file
126
tests/auto/sql/kernel/qsqlindex/tst_qsqlindex.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
#include <QtSql/QtSql>
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QTimeZone>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include "../qsqldatabase/tst_databases.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
QString qtest;
|
||||
|
||||
class tst_QSqlIndex : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QSqlIndex();
|
||||
|
||||
private slots:
|
||||
void construction_data();
|
||||
void construction();
|
||||
void assignment_data();
|
||||
void assignment();
|
||||
void basicFunctions();
|
||||
};
|
||||
|
||||
tst_QSqlIndex::tst_QSqlIndex()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QSqlIndex::construction_data()
|
||||
{
|
||||
QTest::addColumn<QSqlIndex>("sqlIndex");
|
||||
QTest::addColumn<QString>("cursorName");
|
||||
QTest::addColumn<QString>("name");
|
||||
|
||||
const QString cursorName("cusorName"_L1);
|
||||
const QString name("name"_L1);
|
||||
QSqlIndex sqlIndex(cursorName, name);
|
||||
QTest::newRow("ctor1") << QSqlIndex() << QString() << QString();
|
||||
QTest::newRow("ctor2") << sqlIndex << cursorName << name;
|
||||
QTest::newRow("copy ctor") << QSqlIndex(sqlIndex) << cursorName << name;
|
||||
QTest::newRow("move ctor") << QSqlIndex(std::move(sqlIndex)) << cursorName << name;
|
||||
}
|
||||
|
||||
void tst_QSqlIndex::construction()
|
||||
{
|
||||
QFETCH(QSqlIndex, sqlIndex);
|
||||
QFETCH(QString, cursorName);
|
||||
QFETCH(QString, name);
|
||||
|
||||
QCOMPARE(sqlIndex.cursorName(), cursorName);
|
||||
QCOMPARE(sqlIndex.name(), name);
|
||||
QCOMPARE(sqlIndex.isDescending(0), false);
|
||||
QCOMPARE(sqlIndex.count(), 0);
|
||||
}
|
||||
|
||||
void tst_QSqlIndex::assignment_data()
|
||||
{
|
||||
QTest::addColumn<QSqlIndex>("sqlIndex");
|
||||
QTest::addColumn<QString>("cursorName");
|
||||
QTest::addColumn<QString>("name");
|
||||
|
||||
const QString cursorName("cusorName"_L1);
|
||||
const QString name("name"_L1);
|
||||
QSqlIndex sqlIndex(cursorName, name);
|
||||
QSqlIndex sqlIndex1 = sqlIndex;
|
||||
QSqlIndex sqlIndex2 = std::move(sqlIndex);
|
||||
sqlIndex = std::move(sqlIndex2);
|
||||
QTest::newRow("copy assignment") << sqlIndex1 << cursorName << name;
|
||||
QTest::newRow("move assignment") << sqlIndex << cursorName << name;
|
||||
}
|
||||
|
||||
void tst_QSqlIndex::assignment()
|
||||
{
|
||||
QFETCH(QSqlIndex, sqlIndex);
|
||||
QFETCH(QString, cursorName);
|
||||
QFETCH(QString, name);
|
||||
|
||||
QCOMPARE(sqlIndex.cursorName(), cursorName);
|
||||
QCOMPARE(sqlIndex.name(), name);
|
||||
QCOMPARE(sqlIndex.isDescending(0), false);
|
||||
QCOMPARE(sqlIndex.count(), 0);
|
||||
}
|
||||
|
||||
void tst_QSqlIndex::basicFunctions()
|
||||
{
|
||||
QSqlIndex sqlIndex("cursorName"_L1, "name"_L1);
|
||||
const QSqlField f1("field1"_L1, QMetaType(QMetaType::UInt), "table1"_L1);
|
||||
const QSqlField f2("field2"_L1, QMetaType(QMetaType::Double), "table2"_L1);
|
||||
|
||||
QCOMPARE(sqlIndex.cursorName(), "cursorName"_L1);
|
||||
sqlIndex.setCursorName("updatedCursorName"_L1);
|
||||
QCOMPARE(sqlIndex.name(), "name"_L1);
|
||||
sqlIndex.setName("updatedName"_L1);
|
||||
QCOMPARE(sqlIndex.cursorName(), "updatedCursorName"_L1);
|
||||
QCOMPARE(sqlIndex.name(), "updatedName"_L1);
|
||||
|
||||
sqlIndex.append(f1);
|
||||
QCOMPARE(sqlIndex.count(), 1);
|
||||
QCOMPARE(sqlIndex.isDescending(0), false);
|
||||
|
||||
sqlIndex.append(f2, true);
|
||||
QCOMPARE(sqlIndex.count(), 2);
|
||||
QCOMPARE(sqlIndex.isDescending(0), false);
|
||||
QCOMPARE(sqlIndex.isDescending(1), true);
|
||||
|
||||
sqlIndex.setDescending(0, true);
|
||||
sqlIndex.setDescending(1, false);
|
||||
sqlIndex.setDescending(2, true);
|
||||
QCOMPARE(sqlIndex.count(), 2);
|
||||
QCOMPARE(sqlIndex.isDescending(0), true);
|
||||
QCOMPARE(sqlIndex.isDescending(1), false);
|
||||
|
||||
QCOMPARE(sqlIndex.field(0), f1);
|
||||
QCOMPARE(sqlIndex.field(1), f2);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QSqlIndex)
|
||||
#include "tst_qsqlindex.moc"
|
Loading…
Reference in New Issue
Block a user