diff --git a/autotests/KDbTest.h b/autotests/KDbTest.h --- a/autotests/KDbTest.h +++ b/autotests/KDbTest.h @@ -54,6 +54,8 @@ void deleteRecordWithTwoConstraintsTest(); void deleteRecordWithThreeConstraintsTest(); void deleteAllRecordsTest(); + void recordCountTest(); + void fieldCountTest(); void cleanupTestCase(); private: void testUnescapeStringHelper(const QString &sequenceString, const QString &resultString, diff --git a/autotests/KDbTest.cpp b/autotests/KDbTest.cpp --- a/autotests/KDbTest.cpp +++ b/autotests/KDbTest.cpp @@ -22,7 +22,7 @@ #include #include #include - +#include #include #include @@ -1205,6 +1205,35 @@ QVERIFY(utils.testDisconnectAndDropDb()); } +void KDbTest::recordCountTest() +{ + QVERIFY(utils.testCreateDbWithTables("KDbTest")); + QVERIFY2(KDb::recordCount(utils.connection.data(), KDbEscapedString("persons")) == 4, + "Number of records in default persons table is 4."); + QVERIFY2(KDb::recordCount(utils.connection.data(), KDbEscapedString("cars")) == 5, + "Number of records in default cars table is 5."); + QVERIFY2(KDb::recordCount(utils.connection.data(), KDbEscapedString("Foo")) == -1, + "Should return -1 when a table does not exist."); + QVERIFY(utils.testDisconnectAndDropDb()); +} + +void KDbTest::fieldCountTest() +{ + QVERIFY(utils.testCreateDbWithTables("KDbTest")); + KDbTableSchema* kdb_t = utils.connection.data()->tableSchema("persons"); + QVERIFY(kdb_t); + KDbTableOrQuerySchema* tableOrQuery; + tableOrQuery = new KDbTableOrQuerySchema(utils.connection.data(), "persons"); + QVERIFY(tableOrQuery); + QCOMPARE(KDb::fieldCount(tableOrQuery), 4); + QVERIFY2(KDb::fieldCount(tableOrQuery) == 4, "Number of fields should have been 4"); + tableOrQuery = new KDbTableOrQuerySchema(kdb_t); + QVERIFY(tableOrQuery); + QCOMPARE(KDb::fieldCount(tableOrQuery), 4); + QVERIFY2(KDb::fieldCount(tableOrQuery) == 4, "Number of fields should have been 4"); + QVERIFY(utils.testDisconnectAndDropDb()); +} + void KDbTest::cleanupTestCase() { }