summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-11-29 16:56:42 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-12-05 12:06:39 +0000
commit82a6f38873b75c75b345c4eea1a378fd867f5e69 (patch)
treeb7c40709502c95872659a8ade4b2eb204db72655 /tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
parente3b6f6d16577c74433de1ca9e15402cdf285abca (diff)
tst_qsqlquery.cpp: Refactor runIntegralTypesMysqlTest()
Change 3370ab9119df09ca14f7d4641c555e60c1b3f478 introduced warnings from MSVC: tst_qsqlquery.cpp(4005): warning C4805: '==': unsafe mix of type 'const bool' and type 'int' in operation tst_qsqlquery.cpp(4059): note: see reference to function template instantiation 'void runIntegralTypesMysqlTest<bool>(QSqlDatabase &,const QString &,const QString &,const bool,const T,const T)' being compiled with [ T=bool ] tst_qsqlquery.cpp(4006): warning C4805: '==': unsafe mix of type 'const bool' and type 'int' in operation tst_qsqlquery.cpp(4006): warning C4804: '/': unsafe use of type 'bool' in operation tst_qsqlquery.cpp(4026): warning C4804: '+=': unsafe use of type 'bool' in operation Extract an overload taking a QVector of values and use that for the bool case instead of looping over min/max to generate a sequence of values for bool. Change-Id: I72583774e788b8df899f22ed1a64278217e664f6 Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp44
1 files changed, 28 insertions, 16 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 84e9643e77..8deb5ddf8f 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -3995,35 +3995,29 @@ void tst_QSqlQuery::aggregateFunctionTypes()
}
template<typename T>
-void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const QString &type, const bool withPreparedStatement,
- const T min = std::numeric_limits<T>::min(), const T max = std::numeric_limits<T>::max())
+void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName,
+ const QString &type, bool withPreparedStatement,
+ const QVector<T> &values)
{
+ QVector<QVariant> variantValues;
+ variantValues.reserve(values.size());
+
QSqlQuery q(db);
QVERIFY_SQL(q, exec("DROP TABLE IF EXISTS " + tableName));
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id " + type + ')'));
- const int steps = (max == min + 1) ? 2 : 20;
- const T increment = (max == min + 1) ? 1 : (max / steps - min / steps);
-
- // insert some values
- QVector<T> values;
- QVector<QVariant> variantValues;
- values.resize(steps);
- variantValues.resize(steps);
- T v = min;
if (withPreparedStatement) {
QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (id) VALUES (?)"));
}
for (int i = 0; i < values.size(); ++i) {
+ const T v = values.at(i);
if (withPreparedStatement) {
q.bindValue(0, v);
QVERIFY_SQL(q, exec());
} else {
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (" + QString::number(v) + QLatin1Char(')')));
}
- values[i] = v;
- variantValues[i] = QVariant::fromValue(v);
- v += increment;
+ variantValues.append(QVariant::fromValue(v));
}
// ensure we can read them back properly
@@ -4048,16 +4042,34 @@ void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const
QCOMPARE(actualVariantValues, variantValues);
}
+template<typename T>
+void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName,
+ const QString &type, const bool withPreparedStatement,
+ const T min = std::numeric_limits<T>::min(),
+ const T max = std::numeric_limits<T>::max())
+{
+ // insert some values
+ const int steps = 20;
+ const T increment = (max / steps - min / steps);
+ QVector<T> values;
+ values.reserve(steps);
+ T v = min;
+ for (int i = 0; i < steps; ++i, v += increment)
+ values.append(v);
+ runIntegralTypesMysqlTest(db, tableName, type, withPreparedStatement, values);
+}
+
void tst_QSqlQuery::integralTypesMysql()
{
QFETCH(QString, dbName);
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
+ const QVector<bool> boolValues = QVector<bool>() << false << true;
for (int i = 0; i < 2; ++i) {
const bool withPreparedStatement = (i == 1);
- runIntegralTypesMysqlTest<bool>(db, "tinyInt1Test", "TINYINT(1)", withPreparedStatement);
- runIntegralTypesMysqlTest<bool>(db, "unsignedTinyInt1Test", "TINYINT(1) UNSIGNED", withPreparedStatement);
+ runIntegralTypesMysqlTest<bool>(db, "tinyInt1Test", "TINYINT(1)", withPreparedStatement, boolValues);
+ runIntegralTypesMysqlTest<bool>(db, "unsignedTinyInt1Test", "TINYINT(1) UNSIGNED", withPreparedStatement, boolValues);
runIntegralTypesMysqlTest<qint8>(db, "tinyIntTest", "TINYINT", withPreparedStatement);
runIntegralTypesMysqlTest<quint8>(db, "unsignedTinyIntTest", "TINYINT UNSIGNED", withPreparedStatement);
runIntegralTypesMysqlTest<qint16>(db, "smallIntTest", "SMALLINT", withPreparedStatement);