Add per-module unit-test dirs for the Release 2 scope
One unit-test/ directory per module/target, mirroring the existing TetraIF/unit-test/ layout (one QtTest executable per module, guarded by BUILD_TESTING and the module target, each registered with ctest): Lts/Common/CodeGen codegen_unit_test Lts/Common/LtsCoordinate ltscoordinate_unit_test Lts/Common/LtsSession ltssession_unit_test Lts/DDS/Core ddscore_unit_test Lts/DDS/QosProfile ddsqos_unit_test Lts/Tools/LogViewer logviewer_unit_test Lts/Tools/SqlBrowser sqlbrowser_unit_test Z/src/NGLLogger ngllogger_unit_test Z/src/WMS_Interface wms_json_ds_unit_test Z/src/nglapplication nglcoreapplication_unit_test Z/src/nglcompression nglcompression_unit_test Z/src/nglsettings nglsettings_unit_test Z/src/ngltranslator ngltranslator_unit_test Where a module is built with hidden visibility and has no export macro (LogViewer, SqlBrowser, ngltranslator, NGLLogger, nglcompression, nglsettings), its sources are compiled directly into the test executable, the same pattern as prtcnv_unit_test. ctest baseline in the container (QT_QPA_PLATFORM=offscreen): 20/23 passed (13 new + 7 pre-existing in-scope tests), 3 Not Run as before (nglcomp_test, GrantleeParserSmoke, utils_test). README: ctest baseline table extended to the 23 registered tests and section 2.4 now documents the per-module test layout. ddsview has no unit test (GUI tool, XmlHelper needs the DDS dynamic-xtypes runtime).
This commit is contained in:
1 parent
a62b729577
commit
09b6df8bc3
40 files changed
+4966
-17
No files matched your search
@@ -57,5 +57,9 @@ ELSE()
|
||||
MESSAGE(STATUS "Log4Qt not found; skipping test_ngllogger")
|
||||
ENDIF()
|
||||
|
||||
#
|
||||
# Unit tests
|
||||
#
|
||||
ADD_SUBDIRECTORY(unit-test)
|
||||
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.props ${CMAKE_BINARY_DIR}/log4cxx.props COPYONLY)
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Unit tests for the NGLLogger module.
|
||||
# One test executable per module, each registered with ctest.
|
||||
#
|
||||
if (NOT BUILD_TESTING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# --- NGLLogger: bootstrap + logger lookup (Log4Qt-independent; works in
|
||||
# --- the Log4Qt-less (stub) build).
|
||||
# --- MurmurHash2 has no export macro and the tree builds with hidden
|
||||
# --- visibility, so its symbols are not exported from libNGLLogger - the
|
||||
# --- module source is compiled directly into the test (same pattern as the
|
||||
# --- LogView test in TetraIF/unit-test).
|
||||
if (TARGET NGLLogger)
|
||||
ADD_EXECUTABLE(ngllogger_unit_test
|
||||
ngllogger_unit_test.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../MurmurHash2.cpp)
|
||||
TARGET_LINK_LIBRARIES(ngllogger_unit_test
|
||||
NGLLogger
|
||||
Qt6::Core
|
||||
Qt6::Test
|
||||
)
|
||||
ADD_TEST(NAME ngllogger_unit_test COMMAND $<TARGET_FILE:ngllogger_unit_test>)
|
||||
endif()
|
||||
@@ -0,0 +1,163 @@
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <NGLLogger/NGLLogger.h>
|
||||
#include <NGLLogger/MurmurHash2.h>
|
||||
#include <QtTest/QTest>
|
||||
#include <QtTest/QTestEventLoop>
|
||||
|
||||
class ngllogger_unit_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
// Create the root logger once for the whole test process.
|
||||
// Works in both the Log4Qt build and the Log4Qt-less (stub) build.
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", false);
|
||||
}
|
||||
|
||||
void A_LoggerHierarchyHelperSameNameReturnsSameInstance()
|
||||
{
|
||||
#ifndef HAVE_LOG4QT
|
||||
// The instance cache (m_loggermap) is only populated in Log4Qt builds
|
||||
// (NGLLogger constructor); the stub build creates a fresh logger per call.
|
||||
QSKIP("requires the Log4Qt build (instance caching is a Log4Qt feature)");
|
||||
#else
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
auto &b = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
QCOMPARE(&a, &b); // same instance for same name
|
||||
#endif
|
||||
}
|
||||
|
||||
void B_LoggerHierarchyHelperDifferentNamesReturnDifferentInstances()
|
||||
{
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui.AES");
|
||||
auto &b = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui.Dataview");
|
||||
QVERIFY(&a != &b); // different instances for different names
|
||||
}
|
||||
|
||||
void C_LoggerNameRoundTrip()
|
||||
{
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
QCOMPARE(a.getLoggerName(), std::string("Gui"));
|
||||
auto &b = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui.AES");
|
||||
QCOMPARE(b.getLoggerName(), std::string("Gui.AES"));
|
||||
}
|
||||
|
||||
void D_StdStringAndCharOverloadsReturnSameInstance()
|
||||
{
|
||||
#ifndef HAVE_LOG4QT
|
||||
QSKIP("requires the Log4Qt build (instance caching is a Log4Qt feature)");
|
||||
#else
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
auto &b = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(std::string("Gui"));
|
||||
QCOMPARE(&a, &b);
|
||||
auto &c = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui.AES");
|
||||
auto &d = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(std::string("Gui.AES"));
|
||||
QCOMPARE(&c, &d);
|
||||
#endif
|
||||
}
|
||||
|
||||
void E_NoSpaceFlag()
|
||||
{
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
QVERIFY(a.noSpace()); // default true
|
||||
a.setNoSpace(false);
|
||||
QVERIFY(!a.noSpace());
|
||||
a.setNoSpace(true);
|
||||
QVERIFY(a.noSpace());
|
||||
}
|
||||
|
||||
void F_LogLevelEnumOrdering()
|
||||
{
|
||||
QVERIFY(NGL::LogLevel::Trace < NGL::LogLevel::Debug);
|
||||
QVERIFY(NGL::LogLevel::Debug < NGL::LogLevel::Info);
|
||||
QVERIFY(NGL::LogLevel::Info < NGL::LogLevel::Warning);
|
||||
QVERIFY(NGL::LogLevel::Warning < NGL::LogLevel::Error);
|
||||
QVERIFY(NGL::LogLevel::Error < NGL::LogLevel::Fatal);
|
||||
}
|
||||
|
||||
void G_PerLevelHelpersAgreeWithGeneric()
|
||||
{
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
QCOMPARE(a.isTraceEnabled(), a.isLevelEnabled(NGL::LogLevel::Trace));
|
||||
QCOMPARE(a.isDebugEnabled(), a.isLevelEnabled(NGL::LogLevel::Debug));
|
||||
QCOMPARE(a.isInfoEnabled(), a.isLevelEnabled(NGL::LogLevel::Info));
|
||||
QCOMPARE(a.isWarningEnabled(), a.isLevelEnabled(NGL::LogLevel::Warning));
|
||||
QCOMPARE(a.isErrorEnabled(), a.isLevelEnabled(NGL::LogLevel::Error));
|
||||
QCOMPARE(a.isFatalEnabled(), a.isLevelEnabled(NGL::LogLevel::Fatal));
|
||||
}
|
||||
|
||||
void H_LevelEnabledIsUpwardClosed()
|
||||
{
|
||||
// For any two levels lo < hi: if lo enabled then hi enabled; if hi disabled then lo
|
||||
// disabled. This holds regardless of the actual enabled level.
|
||||
const auto levels = {
|
||||
NGL::LogLevel::Trace, NGL::LogLevel::Debug, NGL::LogLevel::Info,
|
||||
NGL::LogLevel::Warning, NGL::LogLevel::Error, NGL::LogLevel::Fatal
|
||||
};
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
for (auto lo : levels)
|
||||
for (auto hi : levels)
|
||||
{
|
||||
if (lo < hi)
|
||||
{
|
||||
if (a.isLevelEnabled(lo))
|
||||
QVERIFY(a.isLevelEnabled(hi));
|
||||
if (!a.isLevelEnabled(hi))
|
||||
QVERIFY(!a.isLevelEnabled(lo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I_BootstrapCreateAndGet()
|
||||
{
|
||||
auto &a = NGL::NGLLoggerBootstrap::getNGLRootLogger();
|
||||
auto &b = NGL::NGLLoggerBootstrap::getNGLRootLogger();
|
||||
QCOMPARE(&a, &b); // get returns the created root logger
|
||||
// create with ignore-already-created returns the existing root logger
|
||||
auto &c = NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", true);
|
||||
QCOMPARE(&a, &c);
|
||||
}
|
||||
|
||||
void J_AlreadyCreatedError()
|
||||
{
|
||||
// Re-creating without ignore-already-created throws AlreadyCreatedError (root was
|
||||
// created in initTestCase)
|
||||
bool threw = false;
|
||||
try
|
||||
{
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", false);
|
||||
}
|
||||
catch (const NGL::NGLLogger::AlreadyCreatedError &e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
threw = true;
|
||||
}
|
||||
QVERIFY(threw);
|
||||
}
|
||||
|
||||
void K_NotCreatedError()
|
||||
{
|
||||
// Not tested here: requires a fresh process without prior bootstrap, and initTestCase
|
||||
// already created the root logger
|
||||
QSKIP("requires fresh process without prior bootstrap");
|
||||
}
|
||||
|
||||
void L_MurmurHash2Determinism()
|
||||
{
|
||||
QCOMPARE(NGL::MurmurHash2("", 0, 0), 0u); // empty, seed 0
|
||||
QCOMPARE(NGL::MurmurHash2("hello", 5, 0), NGL::MurmurHash2("hello", 5, 0));
|
||||
}
|
||||
|
||||
void M_MurmurHash2Distinctness()
|
||||
{
|
||||
QVERIFY(NGL::MurmurHash2("hello", 5, 0) != NGL::MurmurHash2("hello", 5, 1)); //
|
||||
// different seed
|
||||
QVERIFY(NGL::MurmurHash2("abc", 3, 0) != NGL::MurmurHash2("abd", 3, 0)); //
|
||||
// different input
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ngllogger_unit_test)
|
||||
#include "ngllogger_unit_test.moc"
|
||||
Reference in new issue
Block a user