Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/tests/test_duchain.cpp
Show First 20 Lines • Show All 1896 Lines • ▼ Show 20 Line(s) | 1888 | { | |||
---|---|---|---|---|---|
1897 | } | 1897 | } | ||
1898 | QCOMPARE(decl->toString(), QStringLiteral("VariadicTemplate< int, double, bool > variadic")); | 1898 | QCOMPARE(decl->toString(), QStringLiteral("VariadicTemplate< int, double, bool > variadic")); | ||
1899 | 1899 | | |||
1900 | QVERIFY(decl->abstractType()); | 1900 | QVERIFY(decl->abstractType()); | ||
1901 | QCOMPARE(decl->abstractType()->toString(), QStringLiteral("VariadicTemplate< int, double, bool >")); | 1901 | QCOMPARE(decl->abstractType()->toString(), QStringLiteral("VariadicTemplate< int, double, bool >")); | ||
1902 | } | 1902 | } | ||
1903 | } | 1903 | } | ||
1904 | 1904 | | |||
1905 | void TestDUChain::testProblemRequestedHere() | ||||
1906 | { | ||||
1907 | auto headerCode = QStringLiteral(R"( | ||||
1908 | #pragma once | ||||
1909 | | ||||
1910 | template <typename T> | ||||
1911 | T AddObjects(const T& a, const T& b) | ||||
1912 | { | ||||
1913 | return a + b; | ||||
1914 | } | ||||
1915 | )"); | ||||
1916 | TestFile header(headerCode, QStringLiteral("h")); | ||||
1917 | | ||||
1918 | QString sourceCode = QStringLiteral(R"( | ||||
1919 | #include "%1" | ||||
1920 | struct A {}; | ||||
1921 | | ||||
1922 | int main() | ||||
1923 | { | ||||
1924 | A a, b; | ||||
1925 | AddObjects(a, b); | ||||
1926 | return 0; | ||||
1927 | } | ||||
1928 | )").arg(header.url().str()); | ||||
1929 | TestFile impl(sourceCode, QStringLiteral("cpp"), &header); | ||||
1930 | QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses)); | ||||
1931 | | ||||
1932 | DUChainReadLocker lock; | ||||
1933 | | ||||
1934 | auto top = impl.topContext(); | ||||
1935 | QVERIFY(top); | ||||
1936 | | ||||
1937 | auto* headerCtx = dynamic_cast<TopDUContext*>(top->importedParentContexts().first().context(top)); | ||||
1938 | QVERIFY(headerCtx); | ||||
1939 | QCOMPARE(headerCtx->url(), header.url()); | ||||
1940 | | ||||
1941 | QCOMPARE(headerCtx->problems().count(), 1); | ||||
1942 | QCOMPARE(headerCtx->localDeclarations().count(), 1); | ||||
1943 | | ||||
1944 | // Verify that the problem is reported for the source file. | ||||
1945 | QCOMPARE(top->problems().count(), 1); | ||||
1946 | QCOMPARE(top->localDeclarations().count(), 2); | ||||
1947 | } | ||||
mwolff: QStringLiteral(R"(
#include "%1"
...
").arg(header.url().str()); | |||||
1948 | | ||||
1949 | void TestDUChain::testProblemRequestedHereSameFile() | ||||
1950 | { | ||||
1951 | auto sourceCode = QStringLiteral(R"( | ||||
1952 | struct A {}; | ||||
1953 | | ||||
1954 | template <typename T> | ||||
1955 | T AddObjects(const T& a, const T& b) | ||||
1956 | { | ||||
1957 | return a + b; | ||||
1958 | } | ||||
1959 | | ||||
1960 | int main() | ||||
1961 | { | ||||
1962 | A a, b; | ||||
1963 | AddObjects(a, b); | ||||
1964 | return 0; | ||||
1965 | } | ||||
mwolff: auto | |||||
1966 | )"); | ||||
1967 | TestFile impl(sourceCode, QStringLiteral("cpp")); | ||||
1968 | QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses)); | ||||
1969 | | ||||
1970 | DUChainReadLocker lock; | ||||
1971 | | ||||
1972 | auto top = impl.topContext(); | ||||
1973 | QVERIFY(top); | ||||
1974 | | ||||
1975 | QCOMPARE(top->problems().count(), 2); | ||||
why is that? i.e. can you elaborate on this - do you know already what would be required to fix this too? mwolff: why is that? i.e. can you elaborate on this - do you know already what would be required to fix… | |||||
1976 | } | ||||
1977 | | ||||
1978 | void TestDUChain::testProblemRequestedHereChain() | ||||
1979 | { | ||||
1980 | auto headerCode = QStringLiteral(R"( | ||||
1981 | #pragma once | ||||
1982 | | ||||
1983 | template <typename T> | ||||
1984 | T AddObjects(const T& a, const T& b) | ||||
1985 | { | ||||
1986 | return a + b; | ||||
1987 | } | ||||
1988 | )"); | ||||
1989 | TestFile header(headerCode, QStringLiteral("h")); | ||||
1990 | | ||||
1991 | QString sourceCode = QStringLiteral(R"( | ||||
1992 | #include "%1" | ||||
1993 | struct A {}; | ||||
1994 | | ||||
1995 | template <typename T> | ||||
1996 | T AddObjects2(const T& a, const T& b) | ||||
1997 | { | ||||
1998 | return AddObjects(a, b); | ||||
1999 | } | ||||
2000 | | ||||
2001 | int main() | ||||
2002 | { | ||||
2003 | A a, b; | ||||
2004 | AddObjects2(a, b); | ||||
2005 | return 0; | ||||
2006 | } | ||||
2007 | )").arg(header.url().str()); | ||||
2008 | TestFile impl(sourceCode, QStringLiteral("cpp"), &header); | ||||
2009 | QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses)); | ||||
2010 | | ||||
2011 | DUChainReadLocker lock; | ||||
2012 | | ||||
2013 | auto top = impl.topContext(); | ||||
2014 | QVERIFY(top); | ||||
2015 | | ||||
2016 | auto* headerCtx = dynamic_cast<TopDUContext*>(top->importedParentContexts().first().context(top)); | ||||
2017 | QVERIFY(headerCtx); | ||||
2018 | QCOMPARE(headerCtx->url(), header.url()); | ||||
2019 | | ||||
mwolff: see above | |||||
2020 | QCOMPARE(headerCtx->problems().count(), 1); | ||||
2021 | QCOMPARE(headerCtx->localDeclarations().count(), 1); | ||||
2022 | | ||||
2023 | // Verify that the problem is reported for the source file. | ||||
2024 | QCOMPARE(top->problems().count(), 2); | ||||
2025 | QCOMPARE(top->localDeclarations().count(), 3); | ||||
2026 | } | ||||
2027 | | ||||
1905 | void TestDUChain::testGccCompatibility() | 2028 | void TestDUChain::testGccCompatibility() | ||
1906 | { | 2029 | { | ||
1907 | // TODO: make it easier to change the compiler provider for testing purposes | 2030 | // TODO: make it easier to change the compiler provider for testing purposes | ||
1908 | QTemporaryDir dir; | 2031 | QTemporaryDir dir; | ||
1909 | auto project = new TestProject(Path(dir.path()), this); | 2032 | auto project = new TestProject(Path(dir.path()), this); | ||
1910 | auto definesAndIncludesConfig = project->projectConfiguration()->group("CustomDefinesAndIncludes"); | 2033 | auto definesAndIncludesConfig = project->projectConfiguration()->group("CustomDefinesAndIncludes"); | ||
1911 | auto pathConfig = definesAndIncludesConfig.group("ProjectPath0"); | 2034 | auto pathConfig = definesAndIncludesConfig.group("ProjectPath0"); | ||
1912 | pathConfig.writeEntry("Path", "."); | 2035 | pathConfig.writeEntry("Path", "."); | ||
1913 | pathConfig.group("Compiler").writeEntry("Name", "GCC"); | 2036 | pathConfig.group("Compiler").writeEntry("Name", "GCC"); | ||
1914 | m_projectController->addProject(project); | 2037 | m_projectController->addProject(project); | ||
1915 | 2038 | | |||
1916 | { | 2039 | { | ||
1917 | // TODO: Also test in C mode. Currently it doesn't work (some intrinsics missing?) | 2040 | // TODO: Also test in C mode. Currently it doesn't work (some intrinsics missing?) | ||
1918 | TestFile file(QStringLiteral(R"( | 2041 | TestFile file(QStringLiteral(R"( | ||
1919 | #include <x86intrin.h> | 2042 | #include <x86intrin.h> | ||
1920 | 2043 | | |||
1921 | int main() { return 0; } | 2044 | int main() { return 0; } | ||
mwolff: auto | |||||
1922 | )"), QStringLiteral("cpp"), project, dir.path()); | 2045 | )"), QStringLiteral("cpp"), project, dir.path()); | ||
1923 | 2046 | | |||
1924 | file.parse(); | 2047 | file.parse(); | ||
1925 | QVERIFY(file.waitForParsed(50000)); | 2048 | QVERIFY(file.waitForParsed(50000)); | ||
1926 | 2049 | | |||
1927 | DUChainReadLocker lock; | 2050 | DUChainReadLocker lock; | ||
1928 | QSet<TopDUContext*> checked; | 2051 | QSet<TopDUContext*> checked; | ||
1929 | verifyNoErrors(file.topContext(), checked); | 2052 | verifyNoErrors(file.topContext(), checked); | ||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |
QStringLiteral(R"(
#include "%1"
...
").arg(header.url().str());