15 #include <itksys/SystemTools.hxx> 21 #include <QtConcurrentRun> 23 void LogMessages(
unsigned int threadID,
unsigned int numberOfTimes)
25 unsigned int times = 0;
27 while (times < numberOfTimes)
29 MITK_INFO <<
"Test info stream in thread" << threadID <<
"\n even with newlines";
30 MITK_WARN <<
"Test warning stream in thread " << threadID <<
". " 31 <<
"Even with a very long text, even without meaning or implied meaning or content, just a long sentence " 32 "to see whether something has problems with long sentences or output in files or into windows or " 33 "commandlines or whatever.";
34 MITK_DEBUG <<
"Test debugging stream in thread " << threadID;
35 MITK_ERROR <<
"Test error stream in thread " << threadID;
36 MITK_FATAL <<
"Test fatal stream in thread " << threadID;
47 bool testSucceded =
true;
54 itksys::SystemTools::RemoveFile(filename.c_str());
58 unsigned int numberOfThreads = 10;
59 unsigned int threadRuntimeInMilliseconds = 4000;
60 QVector<QFuture<void>> threads;
63 for (
unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
65 threads.push_back(QtConcurrent::run(
LogMessages, threadIdx, 100));
66 std::cout <<
"Created " << threadIdx <<
". thread." << std::endl;
70 itksys::SystemTools::Delay(threadRuntimeInMilliseconds);
73 for (
unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
75 threads[threadIdx].waitForFinished();
76 std::cout << threadIdx <<
". thread has finished" << std::endl;
79 catch (std::exception e)
81 MITK_ERROR <<
"exception during 'TestThreadSaveLog': " << e.what();
86 MITK_ERROR <<
"unknown exception during 'TestThreadSaveLog'";
99 MITK_TEST_OUTPUT(<<
"TESTING ALL LOGGING OUTPUTS, ERROR MESSAGES ARE ALSO TESTED AND NOT MEANING AN ERROR OCCURED!")
104 MITK_TEST_OUTPUT(<<
"Number of threads in QThreadPool: " << QThreadPool::globalInstance()->maxThreadCount())
void LogMessages(unsigned int threadID, unsigned int numberOfTimes)
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int QmitkThreadedLogTest(int, char *[])
static void TestThreadSaveLog(bool toFile)
Test logging from Qt threads.
#define MITK_TEST_OUTPUT(x)
Output some text.
std::string GetOptionDirectory()
Return directory of/for option files.
static void SetLogFile(const char *file)
Sets extra log file path (additionally to the console log)
static StandardFileLocations * GetInstance()