diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cpptools/cpptoolsplugin.h | 7 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolsunittestfiles.pri | 6 | ||||
-rw-r--r-- | src/plugins/cpptools/projectinfo_test.cpp | 105 |
3 files changed, 114 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index 0aabf24577..203cab22d7 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -254,6 +254,13 @@ private slots: void test_headerPathFilter_removeGccInternalPathsExceptForStandardPaths(); void test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderNoVersion(); void test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderAndroidClang(); + void test_projectFileCategorizer_c(); + void test_projectFileCategorizer_cxxWithUnambiguousHeaderSuffix(); + void test_projectFileCategorizer_cxxWithAmbiguousHeaderSuffix(); + void test_projectFileCategorizer_objectiveC(); + void test_projectFileCategorizer_objectiveCxx(); + void test_projectFileCategorizer_mixedCAndCxx(); + void test_projectFileCategorizer_ambiguousHeaderOnly(); #endif private: diff --git a/src/plugins/cpptools/cpptoolsunittestfiles.pri b/src/plugins/cpptools/cpptoolsunittestfiles.pri index 83548cd26e..64167bd297 100644 --- a/src/plugins/cpptools/cpptoolsunittestfiles.pri +++ b/src/plugins/cpptools/cpptoolsunittestfiles.pri @@ -7,11 +7,9 @@ shared { HEADERS += \ $$PWD/cppprojectfile.h \ $$PWD/senddocumenttracker.h \ - $$PWD/projectpart.h \ - $$PWD/cppprojectfilecategorizer.h + $$PWD/projectpart.h SOURCES += \ $$PWD/cppprojectfile.cpp \ $$PWD/senddocumenttracker.cpp \ - $$PWD/projectpart.cpp \ - $$PWD/cppprojectfilecategorizer.cpp + $$PWD/projectpart.cpp diff --git a/src/plugins/cpptools/projectinfo_test.cpp b/src/plugins/cpptools/projectinfo_test.cpp index 520ebe23d3..e371e388a6 100644 --- a/src/plugins/cpptools/projectinfo_test.cpp +++ b/src/plugins/cpptools/projectinfo_test.cpp @@ -23,6 +23,7 @@ ** ****************************************************************************/ +#include "cppprojectfilecategorizer.h" #include "cppprojectinfogenerator.h" #include "cppprojectpartchooser.h" #include "cpptoolsplugin.h" @@ -714,5 +715,109 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderA t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include")})); } +void CppToolsPlugin::test_projectFileCategorizer_c() +{ + const ProjectFileCategorizer categorizer({}, {"foo.c", "foo.h"}); + const ProjectFiles expected { + ProjectFile("foo.c", ProjectFile::CSource), + ProjectFile("foo.h", ProjectFile::CHeader), + }; + + QCOMPARE(categorizer.cSources(), expected); + QVERIFY(categorizer.cxxSources().isEmpty()); + QVERIFY(categorizer.objcSources().isEmpty()); + QVERIFY(categorizer.objcxxSources().isEmpty()); +} + +void CppToolsPlugin::test_projectFileCategorizer_cxxWithUnambiguousHeaderSuffix() +{ + const ProjectFileCategorizer categorizer({}, {"foo.cpp", "foo.hpp"}); + const ProjectFiles expected { + ProjectFile("foo.cpp", ProjectFile::CXXSource), + ProjectFile("foo.hpp", ProjectFile::CXXHeader), + }; + + QCOMPARE(categorizer.cxxSources(), expected); + QVERIFY(categorizer.cSources().isEmpty()); + QVERIFY(categorizer.objcSources().isEmpty()); + QVERIFY(categorizer.objcxxSources().isEmpty()); +} + +void CppToolsPlugin::test_projectFileCategorizer_cxxWithAmbiguousHeaderSuffix() +{ + const ProjectFiles expected { + ProjectFile("foo.cpp", ProjectFile::CXXSource), + ProjectFile("foo.h", ProjectFile::CXXHeader), + }; + + const ProjectFileCategorizer categorizer({}, {"foo.cpp", "foo.h"}); + + QCOMPARE(categorizer.cxxSources(), expected); + QVERIFY(categorizer.cSources().isEmpty()); + QVERIFY(categorizer.objcSources().isEmpty()); + QVERIFY(categorizer.objcxxSources().isEmpty()); +} + +void CppToolsPlugin::test_projectFileCategorizer_objectiveC() +{ + const ProjectFiles expected { + ProjectFile("foo.m", ProjectFile::ObjCSource), + ProjectFile("foo.h", ProjectFile::ObjCHeader), + }; + + const ProjectFileCategorizer categorizer({}, {"foo.m", "foo.h"}); + + QCOMPARE(categorizer.objcSources(), expected); + QVERIFY(categorizer.cxxSources().isEmpty()); + QVERIFY(categorizer.cSources().isEmpty()); + QVERIFY(categorizer.objcxxSources().isEmpty()); +} + +void CppToolsPlugin::test_projectFileCategorizer_objectiveCxx() +{ + const ProjectFiles expected { + ProjectFile("foo.mm", ProjectFile::ObjCXXSource), + ProjectFile("foo.h", ProjectFile::ObjCXXHeader), + }; + + const ProjectFileCategorizer categorizer({}, {"foo.mm", "foo.h"}); + + QCOMPARE(categorizer.objcxxSources(), expected); + QVERIFY(categorizer.objcSources().isEmpty()); + QVERIFY(categorizer.cSources().isEmpty()); + QVERIFY(categorizer.cxxSources().isEmpty()); +} + +void CppToolsPlugin::test_projectFileCategorizer_mixedCAndCxx() +{ + const ProjectFiles expectedCxxSources { + ProjectFile("foo.cpp", ProjectFile::CXXSource), + ProjectFile("foo.h", ProjectFile::CXXHeader), + ProjectFile("bar.h", ProjectFile::CXXHeader), + }; + const ProjectFiles expectedCSources { + ProjectFile("bar.c", ProjectFile::CSource), + ProjectFile("foo.h", ProjectFile::CHeader), + ProjectFile("bar.h", ProjectFile::CHeader), + }; + + const ProjectFileCategorizer categorizer({}, {"foo.cpp", "foo.h", "bar.c", "bar.h"}); + + QCOMPARE(categorizer.cxxSources(), expectedCxxSources); + QCOMPARE(categorizer.cSources(), expectedCSources); + QVERIFY(categorizer.objcSources().isEmpty()); + QVERIFY(categorizer.objcxxSources().isEmpty()); +} + +void CppToolsPlugin::test_projectFileCategorizer_ambiguousHeaderOnly() +{ + const ProjectFileCategorizer categorizer({}, {"foo.h"}); + + QCOMPARE(categorizer.cSources(), {ProjectFile("foo.h", ProjectFile::CHeader)}); + QCOMPARE(categorizer.cxxSources(), {ProjectFile("foo.h", ProjectFile::CXXHeader)}); + QCOMPARE(categorizer.objcSources(), {ProjectFile("foo.h", ProjectFile::ObjCHeader)}); + QCOMPARE(categorizer.objcxxSources(), {ProjectFile("foo.h", ProjectFile::ObjCXXHeader)}); +} + } // namespace Internal } // namespace CppTools |