| 238 | } |
| 239 | |
| 240 | bool TestKdevFormatSource::initTest(const QStringList& formatFileData) |
| 241 | { |
| 242 | QTest::addColumn<QString>("path"); |
| 243 | QTest::addColumn<bool>("isFound"); |
| 244 | QTest::addColumn<bool>("isRead"); |
| 245 | QTest::addColumn<bool>("isApplied"); |
| 246 | QTest::addColumn<QStringList>("lines"); |
| 247 | |
| 248 | m_temporaryDir.reset(new QTemporaryDir); |
| 249 | const QString workPath = m_temporaryDir->path(); |
| 250 | qDebug() << "Using temporary dir:" << workPath; |
| 251 | |
| 252 | if (!mkPath(workPath + "/src1")) |
| 253 | return false; |
| 254 | |
| 255 | if (!mkPath(workPath + "/src2")) |
| 256 | return false; |
| 257 | |
| 258 | if (!QDir::setCurrent(workPath)) { |
| 259 | qDebug() << "unable to set current directory to" << workPath; |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | m_sources.resize(3); |
| 264 | |
| 265 | m_sources[0].path = workPath + "/src1/source_1.cpp"; |
| 266 | m_sources[0].lines = QStringList({ |
| 267 | QStringLiteral("void foo(int x) {"), |
| 268 | QStringLiteral(" printf(\"squared x = %d\\n\", x * x);"), |
| 269 | QStringLiteral("}") |
| 270 | }); |
| 271 | |
| 272 | m_sources[1].path = workPath + "/src2/source_2.cpp"; |
| 273 | m_sources[1].lines = QStringList({ |
| 274 | QStringLiteral("void bar(double x) {"), |
| 275 | QStringLiteral(" x = sqrt(x);"), |
| 276 | QStringLiteral(" printf(\"sqrt(x) = %e\\n\", x);"), |
| 277 | QStringLiteral("}") |
| 278 | }); |
| 279 | |
| 280 | m_sources[2].path = workPath + "/source_3.cpp"; |
| 281 | m_sources[2].lines = QStringList({ |
| 282 | QStringLiteral("void baz(double x, double y) {"), |
| 283 | QStringLiteral(" double z = pow(x, y);"), |
| 284 | QStringLiteral(" printf(\"x^y = %e\\n\", z);"), |
| 285 | QStringLiteral("}") |
| 286 | }); |
| 287 | |
| 288 | for (const Source& source : std::as_const(m_sources)) { |
| 289 | if (!writeLines(source.path, source.lines)) |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | if (!formatFileData.isEmpty() && !writeLines(QStringLiteral("format_sources"), formatFileData)) |
| 294 | return false; |
| 295 | |
| 296 | return true; |
| 297 | } |
nothing calls this directly
no test coverage detected