CppTools: Tests: Allow to check only project relevant state

Needed for ClangCodeModel.

If editors are open, the global snapshot and working copy will not be
empty.

Change-Id: I0d1bab8e082a7f41630c7b1b78febe2da009298b
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-05-08 12:19:08 +02:00
parent 9425812066
commit c5c57dca0c
4 changed files with 16 additions and 10 deletions

View File

@@ -363,16 +363,18 @@ VerifyCleanCppModelManager::~VerifyCleanCppModelManager() {
#define RETURN_FALSE_IF_NOT(check) if (!(check)) return false;
bool VerifyCleanCppModelManager::isClean()
bool VerifyCleanCppModelManager::isClean(bool testOnlyForCleanedProjects)
{
CppModelManager *mm = CppModelManager::instance();
RETURN_FALSE_IF_NOT(mm->projectInfos().isEmpty());
RETURN_FALSE_IF_NOT(mm->headerPaths().isEmpty());
RETURN_FALSE_IF_NOT(mm->definedMacros().isEmpty());
RETURN_FALSE_IF_NOT(mm->projectFiles().isEmpty());
RETURN_FALSE_IF_NOT(mm->snapshot().isEmpty());
RETURN_FALSE_IF_NOT(mm->workingCopy().size() == 1);
RETURN_FALSE_IF_NOT(mm->workingCopy().contains(mm->configurationFileName()));
if (!testOnlyForCleanedProjects) {
RETURN_FALSE_IF_NOT(mm->snapshot().isEmpty());
RETURN_FALSE_IF_NOT(mm->workingCopy().size() == 1);
RETURN_FALSE_IF_NOT(mm->workingCopy().contains(mm->configurationFileName()));
}
return true;
}

View File

@@ -161,7 +161,7 @@ class CPPTOOLS_EXPORT VerifyCleanCppModelManager
public:
VerifyCleanCppModelManager();
~VerifyCleanCppModelManager();
static bool isClean();
static bool isClean(bool testCleanedProjects = true);
};
class FileWriterAndRemover

View File

@@ -54,8 +54,10 @@ TestProject::~TestProject()
{
}
ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent) :
QObject(parent)
ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent,
bool testOnlyForCleanedProjects)
: QObject(parent)
, m_testOnlyForCleanedProjects(testOnlyForCleanedProjects)
{
CppModelManager *mm = CppModelManager::instance();
@@ -69,13 +71,13 @@ ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent) :
this, &ModelManagerTestHelper::gcFinished);
cleanup();
QVERIFY(Tests::VerifyCleanCppModelManager::isClean());
QVERIFY(Tests::VerifyCleanCppModelManager::isClean(m_testOnlyForCleanedProjects));
}
ModelManagerTestHelper::~ModelManagerTestHelper()
{
cleanup();
QVERIFY(Tests::VerifyCleanCppModelManager::isClean());
QVERIFY(Tests::VerifyCleanCppModelManager::isClean(m_testOnlyForCleanedProjects));
}
void ModelManagerTestHelper::cleanup()

View File

@@ -75,7 +75,8 @@ class CPPTOOLS_EXPORT ModelManagerTestHelper: public QObject
public:
typedef ProjectExplorer::Project Project;
explicit ModelManagerTestHelper(QObject *parent = 0);
explicit ModelManagerTestHelper(QObject *parent = 0,
bool testOnlyForCleanedProjects = true);
~ModelManagerTestHelper();
void cleanup();
@@ -99,6 +100,7 @@ public slots:
private:
bool m_gcFinished;
bool m_refreshHappened;
bool m_testOnlyForCleanedProjects;
QSet<QString> m_lastRefreshedSourceFiles;
};