diff --git a/Modules/Qmitk/Testing/QmitkThreadedLogTest.cpp b/Modules/Qmitk/Testing/QmitkThreadedLogTest.cpp index 6a29b258d2..d222144b57 100644 --- a/Modules/Qmitk/Testing/QmitkThreadedLogTest.cpp +++ b/Modules/Qmitk/Testing/QmitkThreadedLogTest.cpp @@ -1,110 +1,110 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkCommon.h" #include "mitkTestingMacros.h" #include #include #include #include #include -void LogMessages(unsigned int threadID, unsigned int numberOfTimes = 5000) +void LogMessages(unsigned int threadID, unsigned int numberOfTimes) { unsigned int times = 0; while(times < numberOfTimes) { MITK_INFO << "Test info stream in thread" << threadID << "\n even with newlines"; MITK_WARN << "Test warning stream in thread " << threadID <<". " << "Even with a very long text, even without meaning or implied meaning or content, just a long sentence to see whether something has problems with long sentences or output in files or into windows or commandlines or whatever."; MITK_DEBUG << "Test debugging stream in thread " << threadID; MITK_ERROR << "Test error stream in thread " << threadID; MITK_FATAL << "Test fatal stream in thread " << threadID; - times= 5; + times += 5; } } /** \brief Test logging from Qt threads */ static void TestThreadSaveLog(bool toFile) { bool testSucceded = true; try { if (toFile) { std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "/qtestthreadlog.log"; mitk::LoggingBackend::SetLogFile(filename.c_str()); } unsigned int numberOfThreads = 20; unsigned int threadRuntimeInMilliseconds = 4000; QVector< QFuture > threads; // Spawn some threads - for (unsigned int threadIdx = 0; threadIdx < numberOfThreads;+threadIdx) + for (unsigned int threadIdx = 0; threadIdx < numberOfThreads;++threadIdx) { - threads.push_back( QtConcurrent::run( LogMessages, threadIdx, 1000 ) ); + threads.push_back( QtConcurrent::run( LogMessages, threadIdx, 100 ) ); std::cout << "Created " << threadIdx << ". thread." << std::endl; } //wait for some time (milliseconds) itksys::SystemTools::Delay( threadRuntimeInMilliseconds ); // Wait for all to finish - for (unsigned int threadIdx = 0; threadIdx < numberOfThreads;+threadIdx) + for (unsigned int threadIdx = 0; threadIdx < numberOfThreads;++threadIdx) { threads[threadIdx].waitForFinished(); std::cout << threadIdx << ". thread has finished" << std::endl; } } catch(std::exception e) { MITK_ERROR << "exception during 'TestThreadSaveLog': "<maxThreadCount() ) // always end with this! MITK_TEST_END() }