19 #include <itksys/SystemTools.hxx>
25 #include <QtConcurrentRun>
27 void LogMessages(
unsigned int threadID,
unsigned int numberOfTimes)
29 unsigned int times = 0;
31 while (times < numberOfTimes)
33 MITK_INFO <<
"Test info stream in thread" << threadID <<
"\n even with newlines";
34 MITK_WARN <<
"Test warning stream in thread " << threadID <<
". "
35 <<
"Even with a very long text, even without meaning or implied meaning or content, just a long sentence "
36 "to see whether something has problems with long sentences or output in files or into windows or "
37 "commandlines or whatever.";
38 MITK_DEBUG <<
"Test debugging stream in thread " << threadID;
39 MITK_ERROR <<
"Test error stream in thread " << threadID;
40 MITK_FATAL <<
"Test fatal stream in thread " << threadID;
51 bool testSucceded =
true;
58 itksys::SystemTools::RemoveFile(filename.c_str());
62 unsigned int numberOfThreads = 10;
63 unsigned int threadRuntimeInMilliseconds = 4000;
64 QVector<QFuture<void>> threads;
67 for (
unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
69 threads.push_back(QtConcurrent::run(
LogMessages, threadIdx, 100));
70 std::cout <<
"Created " << threadIdx <<
". thread." << std::endl;
74 itksys::SystemTools::Delay(threadRuntimeInMilliseconds);
77 for (
unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
79 threads[threadIdx].waitForFinished();
80 std::cout << threadIdx <<
". thread has finished" << std::endl;
83 catch (std::exception e)
85 MITK_ERROR <<
"exception during 'TestThreadSaveLog': " << e.what();
90 MITK_ERROR <<
"unknown exception during 'TestThreadSaveLog'";
103 MITK_TEST_OUTPUT(<<
"TESTING ALL LOGGING OUTPUTS, ERROR MESSAGES ARE ALSO TESTED AND NOT MEANING AN ERROR OCCURED!")
108 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 const std::string filename
static void SetLogFile(const char *file)
Sets extra log file path (additionally to the console log)
static StandardFileLocations * GetInstance()