blob: f753b83695574972fb8db124d61199a77a0dcdaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "qtestfilelogger.h"
#include "qtestassert.h"
#include "QtTest/private/qtestlog_p.h"
#include "QtTest/private/qtestresult_p.h"
#include <stdlib.h>
#include <stdio.h>
QT_BEGIN_NAMESPACE
namespace QTest
{
static FILE *stream = 0;
}
QTestFileLogger::QTestFileLogger()
{
}
QTestFileLogger::~QTestFileLogger()
{
if(QTest::stream)
fclose(QTest::stream);
QTest::stream = 0;
}
void QTestFileLogger::init()
{
char filename[100];
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);
}
}
void QTestFileLogger::flush(const char *msg)
{
QTEST_ASSERT(QTest::stream);
::fputs(msg, QTest::stream);
::fflush(QTest::stream);
}
QT_END_NAMESPACE
|