diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-08-17 12:44:52 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2017-09-14 13:39:55 +0000 |
commit | 3adb71d45ebebd8c8fc2ec6beeb7a5ee67d64e4e (patch) | |
tree | 7bbe767ce3f6c39f4e19428dc67e5ddb6f6c233e /tests/unit/unittest/sqlitetable-test.cpp | |
parent | 8488ce627b82238c7737c24909d7f6164b2061dd (diff) | |
download | qt-creator-3adb71d45ebebd8c8fc2ec6beeb7a5ee67d64e4e.tar.gz |
Clang: Add Symbol Indexing
It is a first step and now a database is generated if you start QtCreator.
Some code is now shared with the PchManager which can be improved in the
future.
Change-Id: Ic267fe7960f6c455d91832859a673ce98f269aa2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'tests/unit/unittest/sqlitetable-test.cpp')
-rw-r--r-- | tests/unit/unittest/sqlitetable-test.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/tests/unit/unittest/sqlitetable-test.cpp b/tests/unit/unittest/sqlitetable-test.cpp index 7873181580..fc5917d296 100644 --- a/tests/unit/unittest/sqlitetable-test.cpp +++ b/tests/unit/unittest/sqlitetable-test.cpp @@ -27,7 +27,7 @@ #include "spydummy.h" #include <sqlitecolumn.h> -#include <sqlitedatabase.h> +#include <mocksqlitedatabase.h> #include <sqlitetable.h> namespace { @@ -41,13 +41,8 @@ using Sqlite::SqliteDatabase; class SqliteTable : public ::testing::Test { protected: - void SetUp() override; - void TearDown() override; - -protected: - SpyDummy spyDummy; - SqliteDatabase database; - Sqlite::SqliteTable &table = database.addTable(); + NiceMock<MockSqliteDatabase> mockDatabase; + Sqlite::SqliteTable table; Utils::SmallString tableName = "testTable"; }; @@ -73,26 +68,46 @@ TEST_F(SqliteTable, SetUseWithoutRowid) ASSERT_TRUE(table.useWithoutRowId()); } -TEST_F(SqliteTable, TableIsReadyAfterOpenDatabase) +TEST_F(SqliteTable, AddIndex) { table.setName(tableName.clone()); - table.addColumn("name"); + auto &column = table.addColumn("name"); + auto &column2 = table.addColumn("value"); - database.open(); + auto index = table.addIndex({column, column2}); - ASSERT_TRUE(table.isReady()); + ASSERT_THAT(Utils::SmallStringView(index.sqlStatement()), + Eq("CREATE INDEX IF NOT EXISTS index_testTable_name_value ON testTable(name, value)")); } -void SqliteTable::SetUp() +TEST_F(SqliteTable, InitializeTable) { - database.setJournalMode(JournalMode::Memory); - database.setDatabaseFilePath( QStringLiteral(":memory:")); + table.setName(tableName.clone()); + table.setUseIfNotExists(true); + table.setUseTemporaryTable(true); + table.setUseWithoutRowId(true); + table.addColumn("name"); + table.addColumn("value"); + + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE IF NOT EXISTS testTable(name NUMERIC, value NUMERIC) WITHOUT ROWID"))); + + table.initialize(mockDatabase); } -void SqliteTable::TearDown() +TEST_F(SqliteTable, InitializeTableWithIndex) { - if (database.isOpen()) - database.close(); + InSequence sequence; + table.setName(tableName.clone()); + auto &column = table.addColumn("name"); + auto &column2 = table.addColumn("value"); + table.addIndex({column}); + table.addIndex({column2}); + + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE testTable(name NUMERIC, value NUMERIC)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_testTable_name ON testTable(name)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_testTable_value ON testTable(value)"))); + + table.initialize(mockDatabase); } } |