summaryrefslogtreecommitdiffstats
path: root/tests/auto/headers
diff options
context:
space:
mode:
authorFrans Englich <frans.englich@nokia.com>2009-08-14 15:16:34 (GMT)
committerFrans Englich <frans.englich@nokia.com>2009-08-14 15:33:38 (GMT)
commita931fac02fe0430439a351dacc5167ddeca1d4d0 (patch)
tree5b04d1cf28757a25153f46921e4f2e625734ae1e /tests/auto/headers
parent9db9c1f2215e32047c7329ab769d54dd3c1ddeb7 (diff)
downloadQt-a931fac02fe0430439a351dacc5167ddeca1d4d0.zip
Qt-a931fac02fe0430439a351dacc5167ddeca1d4d0.tar.gz
Qt-a931fac02fe0430439a351dacc5167ddeca1d4d0.tar.bz2
Perform license checks on source files.
Previously we only checked headers, but we actually care about source files too. This detects about 50 errors all over Qt. Discussed with Thiago.
Diffstat (limited to 'tests/auto/headers')
-rw-r--r--tests/auto/headers/tst_headers.cpp84
1 files changed, 65 insertions, 19 deletions
diff --git a/tests/auto/headers/tst_headers.cpp b/tests/auto/headers/tst_headers.cpp
index 51e3a55..f5a11f4 100644
--- a/tests/auto/headers/tst_headers.cpp
+++ b/tests/auto/headers/tst_headers.cpp
@@ -50,7 +50,7 @@ public:
private slots:
void initTestCase();
- void licenseCheck_data() { allHeadersData(); }
+ void licenseCheck_data() { allSourceFilesData(); }
void licenseCheck();
void privateSlots_data() { allHeadersData(); }
@@ -60,11 +60,19 @@ private slots:
void macros();
private:
+ static QStringList getFiles(const QString &path,
+ const QStringList dirFilters,
+ const QRegExp &exclude);
+ static QStringList getHeaders(const QString &path);
+ static QStringList getSourceFiles(const QString &path);
+
+ void allSourceFilesData();
void allHeadersData();
QStringList headers;
const QRegExp copyrightPattern;
const QRegExp licensePattern;
const QRegExp moduleTest;
+ QString qtSrcDir;
};
tst_Headers::tst_Headers() :
@@ -74,29 +82,41 @@ tst_Headers::tst_Headers() :
{
}
-QStringList getHeaders(const QString &path)
+QStringList tst_Headers::getFiles(const QString &path,
+ const QStringList dirFilters,
+ const QRegExp &excludeReg)
{
- QStringList headers;
-
- QDir dir(path);
- QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ const QDir dir(path);
+ const QStringList dirs(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
+ QStringList result;
foreach (QString subdir, dirs)
- headers += getHeaders(path + "/" + subdir);
+ result += getFiles(path + "/" + subdir, dirFilters, excludeReg);
- QStringList entries = dir.entryList(QStringList("*.h"), QDir::Files);
- QRegExp reg("^(?!ui_)");
- entries = entries.filter(reg);
+ QStringList entries = dir.entryList(dirFilters, QDir::Files);
+ entries = entries.filter(excludeReg);
foreach (QString entry, entries)
- headers += path + "/" + entry;
+ result += path + "/" + entry;
- return headers;
+ return result;
+}
+
+QStringList tst_Headers::getHeaders(const QString &path)
+{
+ return getFiles(path, QStringList("*.h"), QRegExp("^(?!ui_)"));
+}
+
+QStringList tst_Headers::getSourceFiles(const QString &path)
+{
+ return getFiles(path, QStringList("*.cpp"), QRegExp("^(?!(moc_|qrc_))"));
}
void tst_Headers::initTestCase()
{
- QString qtSrcDir = QString::fromLocal8Bit(qgetenv("QTSRCDIR").isEmpty()
- ? qgetenv("QTDIR") : qgetenv("QTSRCDIR"));
+ qtSrcDir = QString::fromLocal8Bit(qgetenv("QTSRCDIR").isEmpty()
+ ? qgetenv("QTDIR")
+ : qgetenv("QTSRCDIR"));
+
headers = getHeaders(qtSrcDir + "/src");
#ifndef Q_OS_WINCE
@@ -108,6 +128,30 @@ void tst_Headers::initTestCase()
QVERIFY(licensePattern.isValid());
}
+void tst_Headers::allSourceFilesData()
+{
+ QTest::addColumn<QString>("sourceFile");
+
+ const QStringList sourceFiles(getSourceFiles(qtSrcDir));
+
+ foreach (QString sourceFile, sourceFiles) {
+ if (sourceFile.contains("/3rdparty/")
+ || sourceFile.contains("/config.tests/")
+ || sourceFile.contains("/snippets/")
+ || sourceFile.contains("linguist/lupdate/testdata")
+ || 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"))
+ continue;
+
+ QTest::newRow(qPrintable(sourceFile)) << sourceFile;
+ }
+}
+
void tst_Headers::allHeadersData()
{
QTest::addColumn<QString>("header");
@@ -125,12 +169,14 @@ void tst_Headers::allHeadersData()
void tst_Headers::licenseCheck()
{
- QFETCH(QString, header);
+ QFETCH(QString, sourceFile);
- if (header.endsWith("/qgifhandler.h") || header.endsWith("/qconfig.h"))
+ if (sourceFile.endsWith("/qgifhandler.h")
+ || sourceFile.endsWith("/qconfig.h")
+ || sourceFile.endsWith("/qconfig.cpp"))
return;
- QFile f(header);
+ QFile f(sourceFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QByteArray data = f.readAll();
QStringList content = QString::fromLocal8Bit(data.replace('\r',"")).split("\n");
@@ -138,8 +184,8 @@ void tst_Headers::licenseCheck()
if (content.first().contains("generated"))
content.takeFirst();
- QVERIFY(licensePattern.exactMatch(content.at(7)) ||
- licensePattern.exactMatch(content.at(4)));
+ QVERIFY(licensePattern.exactMatch(content.value(7)) ||
+ licensePattern.exactMatch(content.value(4)));
QString licenseType = licensePattern.cap(1);
int i = 0;