From 1eff3b109a0584bd34bfee8491660581b176b8d1 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Tue, 5 Dec 2023 20:42:13 -0800 Subject: [PATCH] tests: merge consolelog/ with lib-core/ --- Tarsnap.pro | 1 - tests/consolelog/.gitignore | 2 - tests/consolelog/confdir/test-consolelog.conf | 11 ---- tests/consolelog/test-consolelog.cpp | 62 ------------------- tests/consolelog/test-consolelog.pro | 19 ------ tests/lib-core/test-lib-core.cpp | 26 ++++++++ tests/lib-core/test-lib-core.pro | 4 ++ tests/run-valgrind-tests.sh | 2 +- 8 files changed, 31 insertions(+), 96 deletions(-) delete mode 100644 tests/consolelog/.gitignore delete mode 100644 tests/consolelog/confdir/test-consolelog.conf delete mode 100644 tests/consolelog/test-consolelog.cpp delete mode 100644 tests/consolelog/test-consolelog.pro diff --git a/Tarsnap.pro b/Tarsnap.pro index 361eaccd..fecce90a 100644 --- a/Tarsnap.pro +++ b/Tarsnap.pro @@ -290,7 +290,6 @@ UNIT_TESTS = \ tests/customfilesystemmodel \ tests/small-widgets \ tests/lib-widgets \ - tests/consolelog \ tests/task \ tests/lib-core diff --git a/tests/consolelog/.gitignore b/tests/consolelog/.gitignore deleted file mode 100644 index bcf46b62..00000000 --- a/tests/consolelog/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -test-consolelog -test-consolelog.app diff --git a/tests/consolelog/confdir/test-consolelog.conf b/tests/consolelog/confdir/test-consolelog.conf deleted file mode 100644 index ec5d3675..00000000 --- a/tests/consolelog/confdir/test-consolelog.conf +++ /dev/null @@ -1,11 +0,0 @@ -[app] -app_data=/tmp/tarsnap-gui-test/test-consolelog/appdata/ -wizard_done=true -default_jobs_dismissed=true - -[tarsnap] -cache=/tmp/tarsnap-gui-test/test-consolelog/cache/ -key=fake.key -path=/usr/bin -user= -version=1.0.37 diff --git a/tests/consolelog/test-consolelog.cpp b/tests/consolelog/test-consolelog.cpp deleted file mode 100644 index 65e1a209..00000000 --- a/tests/consolelog/test-consolelog.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "warnings-disable.h" - -WARNINGS_DISABLE -#include -#include -#include -#include -#include -#include -WARNINGS_ENABLE - -#include "ConsoleLog.h" -#include "TSettings.h" - -class TestConsoleLog : public QObject -{ - Q_OBJECT - -private slots: - void initTestCase(); - void cleanupTestCase(); - - void saveMessage(); -}; - -void TestConsoleLog::initTestCase() -{ - QCoreApplication::setOrganizationName(TEST_NAME); - - LOG.initializeConsoleLog(); -} - -void TestConsoleLog::cleanupTestCase() -{ - TSettings::destroy(); - ConsoleLog::destroy(); -} - -void TestConsoleLog::saveMessage() -{ - TSettings settings; - - QString appdata = settings.value("app/app_data", "").toString(); - QString logFile = appdata + QDir::separator() + TEST_NAME + ".log"; - - // Don't record this message - LOG << "don't write this\n"; - - // Save a message - LOG.setFilename(logFile); - LOG.setWriteToFile(true); - LOG << "write this\n"; - - // Disable saving again - LOG.setWriteToFile(false); - LOG << "don't write this\n"; -} - -QTEST_MAIN(TestConsoleLog) -WARNINGS_DISABLE -#include "test-consolelog.moc" -WARNINGS_ENABLE diff --git a/tests/consolelog/test-consolelog.pro b/tests/consolelog/test-consolelog.pro deleted file mode 100644 index 337f07d4..00000000 --- a/tests/consolelog/test-consolelog.pro +++ /dev/null @@ -1,19 +0,0 @@ -TARGET = test-consolelog -QT = core -TOPDIR = ../.. - -VALGRIND = true - -HEADERS += \ - $$TOPDIR/lib/core/ConsoleLog.h \ - $$TOPDIR/lib/core/TSettings.h - -SOURCES += test-consolelog.cpp \ - $$TOPDIR/lib/core/ConsoleLog.cpp \ - $$TOPDIR/lib/core/TSettings.cpp - -include(../tests-include.pri) - -test_home_prep.commands += ; mkdir -p "$${TEST_HOME}/$${TARGET}"; \ - mkdir -p "$${TEST_HOME}/$${TARGET}/appdata"; \ - cp -r confdir/* "$${TEST_HOME}/$${TARGET}" diff --git a/tests/lib-core/test-lib-core.cpp b/tests/lib-core/test-lib-core.cpp index cfc9e2bc..eb81fd0b 100644 --- a/tests/lib-core/test-lib-core.cpp +++ b/tests/lib-core/test-lib-core.cpp @@ -2,12 +2,14 @@ WARNINGS_DISABLE #include +#include #include #include #include #include WARNINGS_ENABLE +#include "ConsoleLog.h" #include "TSettings.h" class TestLibCore : public QObject @@ -21,16 +23,20 @@ private slots: void settings_default(); void settings_custom(); void settings_default_after_custom(); + + void log_saveMessage(); }; void TestLibCore::initTestCase() { QCoreApplication::setOrganizationName(TEST_NAME); + LOG.initializeConsoleLog(); } void TestLibCore::cleanupTestCase() { TSettings::destroy(); + ConsoleLog::destroy(); } void TestLibCore::settings_default() @@ -73,6 +79,26 @@ void TestLibCore::settings_default_after_custom() QVERIFY(user == "default_init"); } +void TestLibCore::log_saveMessage() +{ + TSettings settings; + + QString appdata = settings.value("app/app_data", "").toString(); + QString logFile = appdata + QDir::separator() + TEST_NAME + ".log"; + + // Don't record this message + LOG << "don't write this\n"; + + // Save a message + LOG.setFilename(logFile); + LOG.setWriteToFile(true); + LOG << "write this\n"; + + // Disable saving again + LOG.setWriteToFile(false); + LOG << "don't write this\n"; +} + QTEST_MAIN(TestLibCore) WARNINGS_DISABLE #include "test-lib-core.moc" diff --git a/tests/lib-core/test-lib-core.pro b/tests/lib-core/test-lib-core.pro index 81b92674..ee5eb3fc 100644 --- a/tests/lib-core/test-lib-core.pro +++ b/tests/lib-core/test-lib-core.pro @@ -5,12 +5,16 @@ TOPDIR = ../.. VALGRIND = true HEADERS += \ + $$TOPDIR/lib/core/ConsoleLog.h \ $$TOPDIR/lib/core/TSettings.h SOURCES += test-lib-core.cpp \ + $$TOPDIR/lib/core/ConsoleLog.cpp \ $$TOPDIR/lib/core/TSettings.cpp include(../tests-include.pri) +# We need the extra "appdata" to save the logfile. test_home_prep.commands += ; mkdir -p "$${TEST_HOME}/$${TARGET}"; \ + mkdir -p "$${TEST_HOME}/$${TARGET}/appdata"; \ cp confdir/*.conf "$${TEST_HOME}/$${TARGET}" diff --git a/tests/run-valgrind-tests.sh b/tests/run-valgrind-tests.sh index a4f09a57..3f03d1fe 100755 --- a/tests/run-valgrind-tests.sh +++ b/tests/run-valgrind-tests.sh @@ -4,7 +4,7 @@ set -e # Command-line DIRS_C="" -DIRS_C="${DIRS_C} lib-core consolelog" +DIRS_C="${DIRS_C} lib-core" DIRS_C="${DIRS_C} task taskmanager persistent" DIRS_C="${DIRS_C} app-cmdline cli"