Changeset View
Changeset View
Standalone View
Standalone View
autotests/KDbTestUtils.cpp
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | 104 | { | |||
---|---|---|---|---|---|
105 | QStringList mimeTypes; | 105 | QStringList mimeTypes; | ||
106 | mimeTypes << "application/x-kexiproject-sqlite3" << "application/x-sqlite3"; | 106 | mimeTypes << "application/x-kexiproject-sqlite3" << "application/x-sqlite3"; | ||
107 | testDriver("org.kde.kdb.sqlite", | 107 | testDriver("org.kde.kdb.sqlite", | ||
108 | true, // file-based | 108 | true, // file-based | ||
109 | mimeTypes); | 109 | mimeTypes); | ||
110 | QVERIFY2(mimeTypes.contains(KDb::defaultFileBasedDriverMimeType()), "SQLite's MIME types should include the default file based one"); | 110 | QVERIFY2(mimeTypes.contains(KDb::defaultFileBasedDriverMimeType()), "SQLite's MIME types should include the default file based one"); | ||
111 | } | 111 | } | ||
112 | 112 | | |||
113 | void KDbTestUtils::testConnectInternal(const KDbConnectionData &cdata) | 113 | void KDbTestUtils::testConnectInternal(const KDbConnectionData &cdata, | ||
114 | const KDbConnectionOptions &options) | ||||
114 | { | 115 | { | ||
115 | //qDebug() << cdata; | 116 | //qDebug() << cdata; | ||
116 | 117 | | |||
117 | if (!driver) { | 118 | if (!driver) { | ||
118 | //! @todo don't hardcode SQLite here | 119 | //! @todo don't hardcode SQLite here | ||
119 | KDB_VERIFY(manager.resultable(), driver = manager.driver("org.kde.kdb.sqlite"), "Driver not found"); | 120 | KDB_VERIFY(manager.resultable(), driver = manager.driver("org.kde.kdb.sqlite"), "Driver not found"); | ||
120 | } | 121 | } | ||
121 | 122 | | |||
122 | KDbConnectionOptions connOptions; | 123 | KDbConnectionOptions connOptionsOverride(options); | ||
123 | QStringList extraSqliteExtensionPaths; | 124 | QStringList extraSqliteExtensionPaths; | ||
124 | extraSqliteExtensionPaths << SQLITE_LOCAL_ICU_EXTENSION_PATH; | 125 | extraSqliteExtensionPaths << SQLITE_LOCAL_ICU_EXTENSION_PATH; | ||
125 | connOptions.insert("extraSqliteExtensionPaths", extraSqliteExtensionPaths); | 126 | connOptionsOverride.insert("extraSqliteExtensionPaths", extraSqliteExtensionPaths); | ||
126 | 127 | | |||
127 | connection.reset(); // remove previous connection if present | 128 | connection.reset(); // remove previous connection if present | ||
128 | const int connCount = driver->connections().count(); | 129 | const int connCount = driver->connections().count(); | ||
129 | connection.reset(driver->createConnection(cdata, connOptions)); | 130 | connection.reset(driver->createConnection(cdata, connOptionsOverride)); | ||
130 | KDB_VERIFY(driver, !connection.isNull(), "Failed to create connection"); | 131 | KDB_VERIFY(driver, !connection.isNull(), "Failed to create connection"); | ||
131 | QVERIFY2(cdata.driverId().isEmpty(), "Connection data has filled driver ID"); | 132 | QVERIFY2(cdata.driverId().isEmpty(), "Connection data has filled driver ID"); | ||
132 | QCOMPARE(connection->data().driverId(), driver->metaData()->id()); | 133 | QCOMPARE(connection->data().driverId(), driver->metaData()->id()); | ||
133 | QVERIFY2(driver->connections().contains(connection.data()), "Driver does not list created connection"); | 134 | QVERIFY2(driver->connections().contains(connection.data()), "Driver does not list created connection"); | ||
134 | QCOMPARE(driver->connections().count(), connCount + 1); // one more | 135 | QCOMPARE(driver->connections().count(), connCount + 1); // one more | ||
135 | 136 | | |||
136 | const KDbUtils::Property extraSqliteExtensionPathsProperty = connection->options()->property("extraSqliteExtensionPaths"); | 137 | const KDbUtils::Property extraSqliteExtensionPathsProperty = connection->options()->property("extraSqliteExtensionPaths"); | ||
137 | QVERIFY2(!extraSqliteExtensionPathsProperty.isNull(), "extraSqliteExtensionPaths property not found"); | 138 | QVERIFY2(!extraSqliteExtensionPathsProperty.isNull(), "extraSqliteExtensionPaths property not found"); | ||
Show All 12 Lines | |||||
150 | 151 | | |||
151 | void KDbTestUtils::testUseInternal() | 152 | void KDbTestUtils::testUseInternal() | ||
152 | { | 153 | { | ||
153 | KDB_VERIFY(connection, connection->databaseExists(connection->data().databaseName()), "Database does not exists"); | 154 | KDB_VERIFY(connection, connection->databaseExists(connection->data().databaseName()), "Database does not exists"); | ||
154 | KDB_VERIFY(connection, connection->useDatabase(), "Failed to use database"); | 155 | KDB_VERIFY(connection, connection->useDatabase(), "Failed to use database"); | ||
155 | KDB_VERIFY(connection, connection->isDatabaseUsed(), "Database not used after call to useDatabase()"); | 156 | KDB_VERIFY(connection, connection->isDatabaseUsed(), "Database not used after call to useDatabase()"); | ||
156 | } | 157 | } | ||
157 | 158 | | |||
159 | void KDbTestUtils::testConnectAndUseInternal(const KDbConnectionData &cdata, | ||||
160 | const KDbConnectionOptions &options) | ||||
161 | { | ||||
162 | if (!testConnect(cdata, options) || !connection) { | ||||
163 | qWarning() << driver->result(); | ||||
164 | QFAIL("testConnect"); | ||||
165 | } | ||||
166 | if (!testUse() || !connection->isDatabaseUsed()) { | ||||
167 | qWarning() << connection->result(); | ||||
168 | bool result = testDisconnect(); | ||||
169 | Q_UNUSED(result); | ||||
170 | QFAIL("testUse"); | ||||
171 | } | ||||
172 | } | ||||
173 | | ||||
174 | void KDbTestUtils::testConnectAndUseInternal(const QString &path, | ||||
175 | const KDbConnectionOptions &options) | ||||
176 | { | ||||
177 | KDbConnectionData cdata; | ||||
178 | cdata.setDatabaseName(path); | ||||
179 | testConnectAndUseInternal(cdata, options); | ||||
180 | } | ||||
181 | | ||||
158 | void KDbTestUtils::testCreateDbInternal(const QString &dbName) | 182 | void KDbTestUtils::testCreateDbInternal(const QString &dbName) | ||
159 | { | 183 | { | ||
160 | //open connection | 184 | //open connection | ||
161 | KDbConnectionData cdata; | 185 | KDbConnectionData cdata; | ||
162 | //! @todo don't hardcode SQLite (.kexi) extension here | 186 | //! @todo don't hardcode SQLite (.kexi) extension here | ||
163 | QString fullDbName(QDir::fromNativeSeparators(QFile::decodeName(FILES_OUTPUT_DIR "/") | 187 | QString fullDbName(QDir::fromNativeSeparators(QFile::decodeName(FILES_OUTPUT_DIR "/") | ||
164 | + dbName + ".kexi")); | 188 | + dbName + ".kexi")); | ||
165 | cdata.setDatabaseName(fullDbName); | 189 | cdata.setDatabaseName(fullDbName); | ||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |