File indexing completed on 2024-11-10 04:40:19

0001 /*
0002     SPDX-FileCopyrightText: 2012 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <QObject>
0008 #include <QTest>
0009 
0010 #include "aktest.h"
0011 #include "storage/dbtype.h"
0012 
0013 #define QL1S(x) QLatin1StringView(x)
0014 
0015 using namespace Akonadi::Server;
0016 
0017 Q_DECLARE_METATYPE(DbType::Type)
0018 
0019 class DbTypeTest : public QObject
0020 {
0021     Q_OBJECT
0022 private Q_SLOTS:
0023     void testDriverName_data()
0024     {
0025         QTest::addColumn<QString>("driverName");
0026         QTest::addColumn<DbType::Type>("dbType");
0027 
0028         QTest::newRow("mysql") << "QMYSQL" << DbType::MySQL;
0029         QTest::newRow("sqlite") << "QSQLITE" << DbType::Sqlite;
0030         QTest::newRow("psql") << "QPSQL" << DbType::PostgreSQL;
0031     }
0032 
0033     void testDriverName()
0034     {
0035         QFETCH(QString, driverName);
0036         QFETCH(DbType::Type, dbType);
0037 
0038         QCOMPARE(DbType::typeForDriverName(driverName), dbType);
0039 
0040         if (QSqlDatabase::drivers().contains(driverName)) {
0041             QSqlDatabase db = QSqlDatabase::addDatabase(driverName, driverName);
0042             QCOMPARE(DbType::type(db), dbType);
0043         }
0044     }
0045 };
0046 
0047 AKTEST_MAIN(DbTypeTest)
0048 
0049 #include "dbtypetest.moc"