From 53454b0f79fcfebab909d071e931557114ace558 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 20 Feb 2018 12:43:05 +0100 Subject: Clang: Use PCHs for indexing As generating the AST is quite expensive it would be very useful to cache the not changed include. So we generate PCHs for include outside of a project part. With this change this PCHs are used by the indexer. For that they are save to the symbol database by the PCH manager and when fetched by the symbol indexer. Change-Id: I7a5b07cfb32d72d50dc52d2b108cd41727a7bfc7 Reviewed-by: Ivan Donchevskii --- .../unittest/precompiledheaderstorage-test.cpp | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/unit/unittest/precompiledheaderstorage-test.cpp (limited to 'tests/unit/unittest/precompiledheaderstorage-test.cpp') diff --git a/tests/unit/unittest/precompiledheaderstorage-test.cpp b/tests/unit/unittest/precompiledheaderstorage-test.cpp new file mode 100644 index 0000000000..2871e3fd11 --- /dev/null +++ b/tests/unit/unittest/precompiledheaderstorage-test.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "googletest.h" +#include "mocksqlitedatabase.h" + +#include +#include +#include +#include + +namespace { + +using Storage = ClangPchManager::PrecompiledHeaderStorage>; + +class PrecompiledHeaderStorage : public testing::Test +{ +protected: + NiceMock database; + Storage storage{database}; + MockSqliteWriteStatement &insertPrecompiledHeaderStatement = storage.m_insertPrecompiledHeaderStatement; + MockSqliteWriteStatement &insertProjectPartStatement = storage.m_insertProjectPartStatement; + MockSqliteWriteStatement &deletePrecompiledHeaderStatement = storage.m_deletePrecompiledHeaderStatement; +}; + +TEST_F(PrecompiledHeaderStorage, UseTransaction) +{ + InSequence s; + + EXPECT_CALL(database, immediateBegin()); + EXPECT_CALL(database, commit()); + + Storage storage{database}; +} + +TEST_F(PrecompiledHeaderStorage, InsertPrecompiledHeader) +{ + InSequence s; + + EXPECT_CALL(insertProjectPartStatement, write(TypedEq("project1"))); + EXPECT_CALL(insertPrecompiledHeaderStatement, + write(TypedEq("project1"), + TypedEq("/path/to/pch"), + TypedEq(22))); + + storage.insertPrecompiledHeader("project1", "/path/to/pch", 22); +} + +TEST_F(PrecompiledHeaderStorage, DeletePrecompiledHeader) +{ + InSequence s; + + EXPECT_CALL(deletePrecompiledHeaderStatement, write(TypedEq("project1"))); + + storage.deletePrecompiledHeader("project1"); +} + +TEST_F(PrecompiledHeaderStorage, InsertPrecompiledHeaderStatement) +{ + ASSERT_THAT(insertPrecompiledHeaderStatement.sqlStatement, + Eq("INSERT OR REPLACE INTO precompiledHeaders(projectPartId, pchPath, pchBuildTime) VALUES((SELECT projectPartId FROM projectParts WHERE projectPartName = ?),?,?)")); +} + +TEST_F(PrecompiledHeaderStorage, InsertProjectPartStatement) +{ + ASSERT_THAT(insertProjectPartStatement.sqlStatement, + Eq("INSERT OR IGNORE INTO projectParts(projectPartName) VALUES (?)")); +} + +TEST_F(PrecompiledHeaderStorage, DeletePrecompiledHeaderStatement) +{ + ASSERT_THAT(deletePrecompiledHeaderStatement.sqlStatement, + Eq("DELETE FROM precompiledHeaders WHERE projectPartId = (SELECT projectPartId FROM projectParts WHERE projectPartName = ?)")); +} + +TEST_F(PrecompiledHeaderStorage, CompilePrecompiledHeaderStatements) +{ + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; + + ASSERT_NO_THROW(ClangPchManager::PrecompiledHeaderStorage<>{database}); +} + +} -- cgit v1.2.1