From cf75d5b1a62badd5ae588aeed6b4f98ba987ca3e Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Fri, 17 Jul 2009 14:51:11 +1000 Subject: Fixed failure of badxml selftest on Windows. Don't try to write to files with special characters in the name. Also fix bizarre indent. --- src/testlib/qtestfilelogger.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/testlib/qtestfilelogger.cpp b/src/testlib/qtestfilelogger.cpp index 0c146b4..a717058 100644 --- a/src/testlib/qtestfilelogger.cpp +++ b/src/testlib/qtestfilelogger.cpp @@ -72,15 +72,24 @@ void QTestFileLogger::init() QTest::qt_snprintf(filename, sizeof(filename), "%s.log", QTestResult::currentTestObjectName()); - #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, filename, "wt")) { - #else - QTest::stream = ::fopen(filename, "wt"); - if (!QTest::stream) { - #endif - printf("Unable to open file for simple logging: %s", filename); - ::exit(1); + // Keep filenames simple + for (int i = 0; i < sizeof(filename) && filename[i]; ++i) { + char& c = filename[i]; + if (!(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '-' + || c == '.')) { + c = '_'; } + } + +#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) + if (::fopen_s(&QTest::stream, filename, "wt")) { +#else + QTest::stream = ::fopen(filename, "wt"); + if (!QTest::stream) { +#endif + printf("Unable to open file for simple logging: %s", filename); + ::exit(1); + } } void QTestFileLogger::flush(const char *msg) -- cgit v0.12