mirror of
https://github.com/ukui/kylin-nm.git
synced 2026-10-24 05:45:10 -07:00
149 lines
4.3 KiB
C++
149 lines
4.3 KiB
C++
/*
|
|
* Kylin-NM Unit Test for src-vpn/main.cpp
|
|
* Test functions: messageOutput
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#include <QDir>
|
|
#include <QTemporaryDir>
|
|
#include <QStandardPaths>
|
|
#include <QMessageLogContext>
|
|
#include <unistd.h>
|
|
|
|
// Forward declarations from main.cpp
|
|
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
|
|
|
// Test messageOutput with QtDebugMsg
|
|
TEST(MainTest, MessageOutputDebugMsg) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "Test debug message";
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with QtInfoMsg
|
|
TEST(MainTest, MessageOutputInfoMsg) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "Test info message";
|
|
EXPECT_NO_THROW(messageOutput(QtInfoMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with QtWarningMsg
|
|
TEST(MainTest, MessageOutputWarningMsg) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "Test warning message";
|
|
EXPECT_NO_THROW(messageOutput(QtWarningMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with QtCriticalMsg
|
|
TEST(MainTest, MessageOutputCriticalMsg) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "Test critical message";
|
|
EXPECT_NO_THROW(messageOutput(QtCriticalMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with empty message
|
|
TEST(MainTest, MessageOutputEmptyMessage) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "";
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with null context
|
|
TEST(MainTest, MessageOutputNullContext) {
|
|
QMessageLogContext context;
|
|
context.file = nullptr;
|
|
context.function = nullptr;
|
|
context.line = 0;
|
|
|
|
QString msg = "Test with null context";
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with long message
|
|
TEST(MainTest, MessageOutputLongMessage) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = QString("Test long message: ").repeated(100);
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with special characters
|
|
TEST(MainTest, MessageOutputSpecialCharacters) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "Test with special chars: test";
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput multiple calls
|
|
TEST(MainTest, MessageOutputMultipleCalls) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
QString msg = QString("Test message %1").arg(i);
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
}
|
|
|
|
// Test all QtMsgType values
|
|
TEST(MainTest, MessageOutputAllMsgTypes) {
|
|
QMessageLogContext context;
|
|
context.file = __FILE__;
|
|
context.function = "test_function";
|
|
context.line = __LINE__;
|
|
|
|
QString msg = "Testing all message types";
|
|
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
EXPECT_NO_THROW(messageOutput(QtInfoMsg, context, msg));
|
|
EXPECT_NO_THROW(messageOutput(QtWarningMsg, context, msg));
|
|
EXPECT_NO_THROW(messageOutput(QtCriticalMsg, context, msg));
|
|
}
|
|
|
|
// Test messageOutput with different file paths
|
|
TEST(MainTest, MessageOutputDifferentFilePaths) {
|
|
QMessageLogContext context;
|
|
|
|
const char* files[] = {"/path/to/file1.cpp", "/another/path/file2.cpp", nullptr};
|
|
for (int i = 0; files[i] != nullptr; i++) {
|
|
context.file = files[i];
|
|
context.function = "test_function";
|
|
context.line = __LINE__ + i;
|
|
|
|
QString msg = QString("Testing with file: %1").arg(files[i]);
|
|
EXPECT_NO_THROW(messageOutput(QtDebugMsg, context, msg));
|
|
}
|
|
}
|