-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppConsoleLog_test.cpp
More file actions
78 lines (67 loc) · 2.1 KB
/
AppConsoleLog_test.cpp
File metadata and controls
78 lines (67 loc) · 2.1 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <gtest/gtest.h>
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
#include "AppConsoleLog.h"
class AppConsoleLogTest : public ::testing::Test {
protected:
void SetUp() override {
ASSERT_NE(qobject_cast<QApplication*>(QCoreApplication::instance()), nullptr);
}
};
TEST_F(AppConsoleLogTest, InstallIsIdempotent)
{
AppConsoleLog::install();
AppConsoleLog::install(); // second call must be a no-op
AppConsoleLog::install();
// Reaching here without crashing or recursing is enough.
SUCCEED();
}
TEST_F(AppConsoleLogTest, DetachNullDoesNothing)
{
AppConsoleLog::detachMainWindow(nullptr);
SUCCEED();
}
TEST_F(AppConsoleLogTest, AttachNullIsIgnored)
{
// Per the contract, attach with a null window must early-out.
AppConsoleLog::attachMainWindow(nullptr);
SUCCEED();
}
TEST_F(AppConsoleLogTest, FlushStdioChunksSafeWhenCaptureNotActive)
{
// flushStdioChunks() should be a no-op when capture isn't running.
AppConsoleLog::flushStdioChunks();
SUCCEED();
}
TEST_F(AppConsoleLogTest, MessageHandlerSurvivesAllSeverityLevels)
{
AppConsoleLog::install();
// Detach any previous attachment so messages go to the in-process buffer.
AppConsoleLog::detachMainWindow(nullptr);
qDebug() << "test debug";
qInfo() << "test info";
qWarning() << "test warning";
QCoreApplication::processEvents();
SUCCEED();
}
#ifndef Q_OS_WIN
TEST_F(AppConsoleLogTest, StdioCaptureInstallAndShutdownRoundTrip)
{
// Stdio capture only makes sense in GUI builds; the function is built
// on POSIX dup2/pipe so we exercise it here to cover both the install
// and shutdown paths.
const bool ok = AppConsoleLog::installStdioCapture();
ASSERT_TRUE(ok);
// Write something through C stdio so the reader thread sees data.
std::fputs("hello-from-stdout\n", stdout);
std::fflush(stdout);
std::fputs("hello-from-stderr\n", stderr);
std::fflush(stderr);
// Give the reader thread time to drain the pipe.
QThread::msleep(50);
AppConsoleLog::shutdown();
SUCCEED();
}
#endif