62 private: |
62 private: |
63 static QStringList getFiles(const QString &path, |
63 static QStringList getFiles(const QString &path, |
64 const QStringList dirFilters, |
64 const QStringList dirFilters, |
65 const QRegExp &exclude); |
65 const QRegExp &exclude); |
66 static QStringList getHeaders(const QString &path); |
66 static QStringList getHeaders(const QString &path); |
67 static QStringList getSourceFiles(const QString &path); |
67 static QStringList getQmlFiles(const QString &path); |
|
68 static QStringList getCppFiles(const QString &path); |
|
69 static QStringList getQDocFiles(const QString &path); |
68 |
70 |
69 void allSourceFilesData(); |
71 void allSourceFilesData(); |
70 void allHeadersData(); |
72 void allHeadersData(); |
71 QStringList headers; |
73 QStringList headers; |
72 const QRegExp copyrightPattern; |
74 const QRegExp copyrightPattern; |
104 QStringList tst_Headers::getHeaders(const QString &path) |
106 QStringList tst_Headers::getHeaders(const QString &path) |
105 { |
107 { |
106 return getFiles(path, QStringList("*.h"), QRegExp("^(?!ui_)")); |
108 return getFiles(path, QStringList("*.h"), QRegExp("^(?!ui_)")); |
107 } |
109 } |
108 |
110 |
109 QStringList tst_Headers::getSourceFiles(const QString &path) |
111 QStringList tst_Headers::getCppFiles(const QString &path) |
110 { |
112 { |
111 return getFiles(path, QStringList("*.cpp"), QRegExp("^(?!(moc_|qrc_))")); |
113 return getFiles(path, QStringList("*.cpp"), QRegExp("^(?!(moc_|qrc_))")); |
|
114 } |
|
115 |
|
116 QStringList tst_Headers::getQmlFiles(const QString &path) |
|
117 { |
|
118 return getFiles(path, QStringList("*.qml"), QRegExp(".")); |
|
119 } |
|
120 |
|
121 QStringList tst_Headers::getQDocFiles(const QString &path) |
|
122 { |
|
123 return getFiles(path, QStringList("*.qdoc"), QRegExp(".")); |
112 } |
124 } |
113 |
125 |
114 void tst_Headers::initTestCase() |
126 void tst_Headers::initTestCase() |
115 { |
127 { |
116 qtSrcDir = QString::fromLocal8Bit(qgetenv("QTSRCDIR").isEmpty() |
128 qtSrcDir = QString::fromLocal8Bit(qgetenv("QTSRCDIR").isEmpty() |
145 "/tools", |
157 "/tools", |
146 "/util" |
158 "/util" |
147 }; |
159 }; |
148 |
160 |
149 for (int i = 0; i < sizeof(subdirs) / sizeof(subdirs[0]); ++i) { |
161 for (int i = 0; i < sizeof(subdirs) / sizeof(subdirs[0]); ++i) { |
150 sourceFiles << getSourceFiles(qtSrcDir + subdirs[i]); |
162 sourceFiles << getCppFiles(qtSrcDir + subdirs[i]); |
|
163 if (subdirs[i] != QLatin1String("/tests")) |
|
164 sourceFiles << getQmlFiles(qtSrcDir + subdirs[i]); |
151 sourceFiles << getHeaders(qtSrcDir + subdirs[i]); |
165 sourceFiles << getHeaders(qtSrcDir + subdirs[i]); |
|
166 sourceFiles << getQDocFiles(qtSrcDir + subdirs[i]); |
152 } |
167 } |
153 |
168 |
154 foreach (QString sourceFile, sourceFiles) { |
169 foreach (QString sourceFile, sourceFiles) { |
155 if (sourceFile.contains("/3rdparty/") |
170 if (sourceFile.contains("/3rdparty/") |
156 || sourceFile.contains("/tests/auto/qmake/testdata/bundle-spaces/main.cpp") |
171 || sourceFile.contains("/tests/auto/qmake/testdata/bundle-spaces/main.cpp") |
190 QFile f(sourceFile); |
205 QFile f(sourceFile); |
191 QVERIFY(f.open(QIODevice::ReadOnly)); |
206 QVERIFY(f.open(QIODevice::ReadOnly)); |
192 QByteArray data = f.readAll(); |
207 QByteArray data = f.readAll(); |
193 data.replace("\r\n", "\n"); // Windows |
208 data.replace("\r\n", "\n"); // Windows |
194 data.replace('\r', '\n'); // Mac OS9 |
209 data.replace('\r', '\n'); // Mac OS9 |
195 QStringList content = QString::fromLocal8Bit(data).split("\n"); |
210 QStringList content = QString::fromLocal8Bit(data).split("\n", QString::SkipEmptyParts); |
|
211 |
|
212 if (content.count() <= 2) // likely a #include line and empty line only. Not a copyright issue. |
|
213 return; |
196 |
214 |
197 if (content.first().contains("generated")) { |
215 if (content.first().contains("generated")) { |
198 content.takeFirst(); |
216 content.takeFirst(); |
199 if (content.first().isEmpty()) |
|
200 content.takeFirst(); |
|
201 } |
217 } |
202 |
218 |
203 if (sourceFile.endsWith("/tests/auto/linguist/lupdate/testdata/good/merge_ordering/foo.cpp") |
219 if (sourceFile.endsWith("/tests/auto/linguist/lupdate/testdata/good/merge_ordering/foo.cpp") |
204 || sourceFile.endsWith("/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp")) |
220 || sourceFile.endsWith("/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp")) |
205 { |
221 { |
206 // These files are meant to start with empty lines. |
222 // These files are meant to start with empty lines. |
207 while (content.first().isEmpty() || content.first().startsWith("//")) |
223 while (content.first().startsWith("//")) |
208 content.takeFirst(); |
224 content.takeFirst(); |
|
225 } |
|
226 |
|
227 if (sourceFile.endsWith("/doc/src/classes/phonon-api.qdoc")) { |
|
228 // This is an external file |
|
229 return; |
209 } |
230 } |
210 |
231 |
211 QVERIFY(licensePattern.exactMatch(content.value(8)) || |
232 QVERIFY(licensePattern.exactMatch(content.value(8)) || |
212 licensePattern.exactMatch(content.value(5))); |
233 licensePattern.exactMatch(content.value(5))); |
213 QString licenseType = licensePattern.cap(1); |
234 QString licenseType = licensePattern.cap(1); |
256 QFETCH(QString, header); |
277 QFETCH(QString, header); |
257 |
278 |
258 if (header.endsWith("_p.h") || header.endsWith("_pch.h") |
279 if (header.endsWith("_p.h") || header.endsWith("_pch.h") |
259 || header.contains("global/qconfig-") || header.endsWith("/qconfig.h") |
280 || header.contains("global/qconfig-") || header.endsWith("/qconfig.h") |
260 || header.contains("/src/tools/") || header.contains("/src/plugins/") |
281 || header.contains("/src/tools/") || header.contains("/src/plugins/") |
|
282 || header.contains("/src/imports/") |
261 || header.endsWith("/qiconset.h") || header.endsWith("/qfeatures.h") |
283 || header.endsWith("/qiconset.h") || header.endsWith("/qfeatures.h") |
262 || header.endsWith("qt_windows.h")) |
284 || header.endsWith("qt_windows.h")) |
263 return; |
285 return; |
264 |
286 |
265 QFile f(header); |
287 QFile f(header); |