summaryrefslogtreecommitdiffstats
path: root/tests/auto/headers/tst_headers.cpp
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-21 11:45:07 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-21 12:22:37 (GMT)
commitfb52ca581e644a7b8699665f26248c33dac30cef (patch)
tree2e505672140ac20a5d59bca0ceb62e1444c8800a /tests/auto/headers/tst_headers.cpp
parente39d9914491c4a21f7c44140a26fc9bdff682b9d (diff)
downloadQt-fb52ca581e644a7b8699665f26248c33dac30cef.zip
Qt-fb52ca581e644a7b8699665f26248c33dac30cef.tar.gz
Qt-fb52ca581e644a7b8699665f26248c33dac30cef.tar.bz2
Improved license header autotest.
Check the license in .h files as well as .cpp files and check some files that were previously skipped. Instead of scanning through the whole Qt directory for .cpp and .h files, only search through a set of subdirectories. Accept '\r' as line break in addition to '\n' and "\r\n". Reenable the copyright check that was commented out. Reviewed-by: Frans Englich
Diffstat (limited to 'tests/auto/headers/tst_headers.cpp')
-rw-r--r--tests/auto/headers/tst_headers.cpp76
1 files changed, 52 insertions, 24 deletions
diff --git a/tests/auto/headers/tst_headers.cpp b/tests/auto/headers/tst_headers.cpp
index 1b28648..d4f2ff4 100644
--- a/tests/auto/headers/tst_headers.cpp
+++ b/tests/auto/headers/tst_headers.cpp
@@ -132,23 +132,36 @@ void tst_Headers::allSourceFilesData()
{
QTest::addColumn<QString>("sourceFile");
- const QStringList sourceFiles(getSourceFiles(qtSrcDir));
+ QStringList sourceFiles;
+ static char const * const subdirs[] = {
+ "/config.tests",
+ "/demos",
+ "/doc",
+ "/examples",
+ "/mkspecs",
+ "/qmake",
+ "/src",
+ "/tests",
+ "/tools",
+ "/util"
+ };
+
+ for (int i = 0; i < sizeof(subdirs) / sizeof(subdirs[0]); ++i) {
+ sourceFiles << getSourceFiles(qtSrcDir + subdirs[i]);
+ sourceFiles << getHeaders(qtSrcDir + subdirs[i]);
+ }
foreach (QString sourceFile, sourceFiles) {
if (sourceFile.contains("/3rdparty/")
- || sourceFile.contains("/config.tests/")
- || sourceFile.contains("/snippets/")
- || sourceFile.contains("linguist/lupdate/testdata")
- || sourceFile.contains("testdata/bundle-spaces/main.cpp")
- || sourceFile.contains("demos/embedded/fluidlauncher/pictureflow.cpp")
- || sourceFile.contains("tools/porting/src/")
- || sourceFile.contains("/fulltextsearch/"))
- continue;
-
- // This test is crude, but if a file contains this string, we skip it.
- QFile file(sourceFile);
- QVERIFY(file.open(QIODevice::ReadOnly));
- if (file.readAll().contains("This file was generated by"))
+ || sourceFile.contains("/tests/auto/qmake/testdata/bundle-spaces/main.cpp")
+ || sourceFile.contains("/demos/embedded/fluidlauncher/pictureflow.cpp")
+ || sourceFile.contains("/tools/porting/src/")
+ || sourceFile.contains("/tools/assistant/lib/fulltextsearch/")
+ || sourceFile.endsWith("_pch.h.cpp")
+ || sourceFile.endsWith(".ui.h")
+ || sourceFile.endsWith("/src/corelib/global/qconfig.h")
+ || sourceFile.endsWith("/src/corelib/global/qconfig.cpp")
+ || sourceFile.endsWith("/src/tools/uic/qclass_lib_map.h"))
continue;
QTest::newRow(qPrintable(sourceFile)) << sourceFile;
@@ -163,7 +176,7 @@ void tst_Headers::allHeadersData()
QSKIP("can't find any headers in your $QTDIR/src", SkipAll);
foreach (QString hdr, headers) {
- if (hdr.contains("/3rdparty/") || hdr.endsWith("/qclass_lib_map.h"))
+ if (hdr.contains("/3rdparty/") || hdr.endsWith("/src/tools/uic/qclass_lib_map.h"))
continue;
QTest::newRow(qPrintable(hdr)) << hdr;
@@ -174,18 +187,26 @@ void tst_Headers::licenseCheck()
{
QFETCH(QString, sourceFile);
- if (sourceFile.endsWith("/qgifhandler.h")
- || sourceFile.endsWith("/qconfig.h")
- || sourceFile.endsWith("/qconfig.cpp"))
- return;
-
QFile f(sourceFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QByteArray data = f.readAll();
- QStringList content = QString::fromLocal8Bit(data.replace('\r',"")).split("\n");
+ data.replace("\r\n", "\n"); // Windows
+ data.replace('\r', '\n'); // Mac OS9
+ QStringList content = QString::fromLocal8Bit(data).split("\n");
- if (content.first().contains("generated"))
+ if (content.first().contains("generated")) {
content.takeFirst();
+ if (content.first().isEmpty())
+ content.takeFirst();
+ }
+
+ if (sourceFile.endsWith("/tests/auto/linguist/lupdate/testdata/good/merge_ordering/foo.cpp")
+ || sourceFile.endsWith("/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp"))
+ {
+ // These files are meant to start with empty lines.
+ while (content.first().isEmpty() || content.first().startsWith("//"))
+ content.takeFirst();
+ }
QVERIFY(licensePattern.exactMatch(content.value(8)) ||
licensePattern.exactMatch(content.value(5)));
@@ -196,8 +217,15 @@ void tst_Headers::licenseCheck()
QCOMPARE(content.at(i++), QString("/****************************************************************************"));
if (licenseType != "3RDPARTY") {
QCOMPARE(content.at(i++), QString("**"));
- // QVERIFY(copyrightPattern.exactMatch(content.at(i++)));
- i++;
+ if (sourceFile.endsWith("/tests/auto/qabstractitemmodel/dynamictreemodel.cpp")
+ || sourceFile.endsWith("/tests/auto/qabstractitemmodel/dynamictreemodel.h")
+ || sourceFile.endsWith("/src/network/kernel/qnetworkproxy_p.h"))
+ {
+ // These files are not copyrighted by Nokia.
+ ++i;
+ } else {
+ QVERIFY(copyrightPattern.exactMatch(content.at(i++)));
+ }
i++;
QCOMPARE(content.at(i++), QString("** Contact: Nokia Corporation (qt-info@nokia.com)"));
}