From dacc2e470d48673595fb0b1b6db2c0199ff96e22 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sat, 3 Jul 2021 10:32:18 +0200 Subject: [PATCH 01/26] Add .clang-tidy support Initial .clang-tidy config run with: clang-tidy -p libsrc/*.cpp Signed-off-by: Thomas Ruschival --- .clang-tidy | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..7ccfcdd --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,195 @@ +Checks: '-*, + bugprone-argument-comment, + bugprone-bad-signal-to-kill-thread, + bugprone-bool-pointer-implicit-conversion, + bugprone-copy-constructor-init, + bugprone-dangling-handle, + bugprone-fold-init-type, + bugprone-forward-declaration-namespace, + bugprone-inaccurate-erase, + bugprone-incorrect-roundings, + bugprone-infinite-loop, + bugprone-integer-division, + bugprone-macro-repeated-side-effects, + bugprone-misplaced-operator-in-strlen-in-alloc, + bugprone-misplaced-pointer-artithmetic-in-alloc, + bugprone-misplaced-widening-cast, + bugprone-move-forwarding-reference, + bugprone-multiple-statement-macro, + bugprone-parent-virtual-call, + bugprone-posix-return, + bugprone-reserved-identifier, + bugprone-signed-char-misuse, + bugprone-sizeof-container, + bugprone-sizeof-expression, + bugprone-string-constructor, + bugprone-string-integer-assignment, + bugprone-string-literal-with-embedded-nul, + bugprone-suspicious-enum-usage, + bugprone-suspicious-include, + bugprone-suspicious-memset-usage, + bugprone-suspicious-missing-comma, + bugprone-suspicious-string-compare, + bugprone-swapped-arguments, + bugprone-terminating-continue, + bugprone-throw-keyword-missing, + bugprone-too-small-loop-variable, + bugprone-undefined-memory-manipulation, + bugprone-undelegated-constructor, + bugprone-unhandled-self-assignment, + bugprone-unused-raii, + bugprone-unused-return-value, + bugprone-use-after-move, + bugprone-virtual-near-miss, + cert-dcl21-cpp, + cert-dcl50-cpp, + cert-env33-c, + cert-err34-c, + cert-err52-cpp, + cert-flp30-c, + cert-mem57-cpp, + cert-msc50-cpp, + cert-oop58-cpp, + clang-analyzer-core.CallAndMessage, + clang-analyzer-core.DivideZero, + clang-analyzer-core.NonNullParamChecker, + clang-analyzer-core.NullDereference, + clang-analyzer-core.StackAddressEscape, + clang-analyzer-core.UndefinedBinaryOperatorResult, + clang-analyzer-core.uninitialized.ArraySubscript, + clang-analyzer-core.uninitialized.Assign, + clang-analyzer-core.uninitialized.Branch, + clang-analyzer-core.uninitialized.CapturedBlockVariable, + clang-analyzer-core.uninitialized.UndefReturn, + clang-analyzer-core.VLASize, + clang-analyzer-cplusplus.InnerPointer, + clang-analyzer-cplusplus.NewDelete, + clang-analyzer-cplusplus.NewDeleteLeaks, + clang-analyzer-cplusplus.PlacementNewChecker, + clang-analyzer-cplusplus.SelfAssignment, + clang-analyzer-deadcode.DeadStores, + clang-analyzer-optin.cplusplus.VirtualCall, + clang-analyzer-security.insecureAPI.bcmp, + clang-analyzer-security.insecureAPI.bcopy, + clang-analyzer-security.insecureAPI.bzero, + clang-analyzer-security.insecureAPI.getpw, + clang-analyzer-security.insecureAPI.gets, + clang-analyzer-security.insecureAPI.mkstemp, + clang-analyzer-security.insecureAPI.mktemp, + clang-analyzer-security.insecureAPI.rand, + clang-analyzer-security.insecureAPI.strcpy, + clang-analyzer-security.insecureAPI.UncheckedReturn, + clang-analyzer-unix.cstring.BadSizeArg, + clang-analyzer-unix.cstring.NullArg, + clang-analyzer-unix.Malloc, + clang-analyzer-unix.MallocSizeof, + clang-analyzer-unix.MismatchedDeallocator, + clang-analyzer-unix.Vfork, + google-build-explicit-make-pair, + google-build-namespaces, + google-default-arguments, + google-explicit-constructor, + google-readability-avoid-underscore-in-googletest-name, + google-readability-casting, + google-runtime-int, + google-runtime-operator, + hicpp-exception-baseclass, + misc-misplaced-const, + misc-redundant-expression, + misc-static-assert, + misc-throw-by-value-catch-by-reference, + misc-unconventional-assign-operator, + misc-unconventional-assign-operator, + misc-uniqueptr-reset-release, + misc-unused-alias-decls, + misc-unused-parameters, + misc-unused-using-decls, + modernize-avoid-bind, + modernize-loop-convert, + modernize-make-shared, + modernize-make-unique, + modernize-raw-string-literal, + modernize-redundant-void-arg, + modernize-replace-auto-ptr, + modernize-replace-random-shuffle, + modernize-use-bool-literals, + modernize-use-equals-default, + modernize-use-equals-delete, + modernize-use-nullptr, + modernize-use-using, + performance-faster-string-find, + performance-for-range-copy, + performance-implicit-conversion-in-loop, + performance-inefficient-algorithm, + performance-inefficient-vector-operation, + performance-move-constructor-init, + performance-no-automatic-move, + performance-trivially-destructible, + performance-unnecessary-copy-initialization, + readability-avoid-const-params-in-decls, + readability-const-return-type, + readability-container-size-empty, + readability-convert-member-functions-to-static, + readability-deleted-default, + readability-delete-null-pointer, + readability-identifier-naming, + readability-inconsistent-declaration-parameter-name, + readability-make-member-function-const, + readability-misplaced-array-index, + readability-non-const-parameter, + readability-qualified-auto, + readability-redundant-access-specifiers, + readability-redundant-control-flow, + readability-redundant-function-ptr-dereference, + readability-redundant-member-init, + readability-redundant-smartptr-get, + readability-redundant-string-cstr, + readability-redundant-string-init, + readability-simplify-boolean-expr, + readability-simplify-subscript-expr, + readability-static-definition-in-anonymous-namespace, + readability-string-compare, + readability-uniqueptr-delete-release, + zircon-temporary-objects, +' +WarningsAsErrors: '*' + +CheckOptions: + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.LocalVariableCase + value: lower_case + - key: readability-identifier-naming.StaticConstantCase + value: aNy_CasE + - key: readability-identifier-naming.MemberCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberPrefix + value: '' + - key: readability-identifier-naming.ProtectedMemberPrefix + value: '' + - key: readability-identifier-naming.PublicMemberCase + value: lower_case + - key: readability-identifier-naming.MethodCase + value: camelBack + - key: readability-identifier-naming.PrivateMethodPrefix + value: '' + - key: readability-identifier-naming.ProtectedMethodPrefix + value: '' + - key: readability-identifier-naming.ParameterPackCase + value: lower_case + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.TemplateTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TemplateUsingCase + value: lower_case + - key: readability-identifier-naming.TypeTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TypedefCase + value: CamelCase + - key: readability-identifier-naming.UnionCase + value: CamelCase + - key: readability-identifier-naming.UsingCase + value: CamelCase \ No newline at end of file From 3de5df596d80c4b6cf5ba0554bfb39c93c97927f Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sat, 3 Jul 2021 10:32:43 +0200 Subject: [PATCH 02/26] Fix first findings of clang-tidy Signed-off-by: Thomas Ruschival --- include/IWeatherConfigStore.hpp | 8 ++++---- include/weather.hpp | 4 ++-- libsrc/configuration_manager.cpp | 4 ++-- libsrc/weather.cpp | 7 ++++--- libsrc/wifi_control.cpp | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/IWeatherConfigStore.hpp b/include/IWeatherConfigStore.hpp index e1517c4..1b38e52 100644 --- a/include/IWeatherConfigStore.hpp +++ b/include/IWeatherConfigStore.hpp @@ -27,12 +27,12 @@ class WeatherConfig { public: /** * Constructor with 'relevant' information - * @param token - * @param cityid - * @param interval 1hour + * @param token personal access token for API + * @param location OpenWeatherAPI assigned location id + * @param interval update interaval (1h) */ WeatherConfig(QString token = QString(), - QString cityid = QString(), + QString location = QString(), std::chrono::seconds interval = std::chrono::seconds(3600)); /** diff --git a/include/weather.hpp b/include/weather.hpp index 31f8c0c..8c414eb 100644 --- a/include/weather.hpp +++ b/include/weather.hpp @@ -162,9 +162,9 @@ class Weather : public QObject { const IWeatherConfigStore& store, QObject* parent = nullptr); /** * Update Download interval - * @param iv interval in seconds + * @param interval in seconds */ - void set_update_interval(std::chrono::seconds iv); + void set_update_interval(std::chrono::seconds interval); std::chrono::seconds get_update_interval() const; /** diff --git a/libsrc/configuration_manager.cpp b/libsrc/configuration_manager.cpp index ebcca42..28f3b78 100644 --- a/libsrc/configuration_manager.cpp +++ b/libsrc/configuration_manager.cpp @@ -292,7 +292,7 @@ void ConfigurationManager::dataChanged() { } /*****************************************************************************/ -void ConfigurationManager::fileChanged(const QString& path) { +void ConfigurationManager::fileChanged(const QString& /*path*/) { qCDebug(CLASS_LC) << Q_FUNC_INFO; refresh_configuration(); } @@ -493,7 +493,7 @@ QString ConfigurationManager::get_cache_dir_name() { void ConfigurationManager::delete_alarm(const QUuid& id) { qCDebug(CLASS_LC) << Q_FUNC_INFO; // Disconnect signal-slot - auto a = find_by_id(alarms, id); + auto* a = find_by_id(alarms, id); disconnect(a, &Alarm::dataChanged, this, &ConfigurationManager::alarm_data_changed); /* delete may throw - just pass it on to the client */ diff --git a/libsrc/weather.cpp b/libsrc/weather.cpp index a404285..af7df3e 100644 --- a/libsrc/weather.cpp +++ b/libsrc/weather.cpp @@ -21,7 +21,8 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.Weather"); /*****************************************************************************/ Weather::Weather(const IWeatherConfigStore& store, QObject* parent) - : cm(store) { + : QObject(parent) + , cm(store) { qCDebug(CLASS_LC) << Q_FUNC_INFO; // timer starts refresh, refresh calls downloader @@ -106,7 +107,7 @@ QUrl Weather::get_weather_icon_url() const { WeatherStatus* Weather::get_weather(int idx) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; try { - auto ret = new WeatherStatus(&weather.at(idx)); + auto* ret = new WeatherStatus(&weather.at(idx)); return ret; } catch (std::out_of_range&) { qCCritical(CLASS_LC) << "Forecast index out of range!"; @@ -127,7 +128,7 @@ void Weather::parse_forecast(const QByteArray& content) { // QJson is very forgiving if "list" does not exist or is not an array // default will be created auto fc_array = doc["list"].toArray(); - if (fc_array.size() <= 0) { + if (fc_array.empty()) { qCWarning(CLASS_LC) << "no forecast 'list' found!"; return; } diff --git a/libsrc/wifi_control.cpp b/libsrc/wifi_control.cpp index 08d7a52..0237f4f 100644 --- a/libsrc/wifi_control.cpp +++ b/libsrc/wifi_control.cpp @@ -139,7 +139,7 @@ void WifiControl::parse_event(const QString& e_string) { } /****************************************************************************/ -void WifiControl::ctrl_event(int fd) { +void WifiControl::ctrl_event(int /* fd */) { qCDebug(CLASS_LC) << Q_FUNC_INFO; char buf[128] = {}; while (wpa_ctrl_pending(ctrl) > 0) { @@ -208,7 +208,7 @@ WifiNetwork DigitalRooster::line_to_network(const QStringRef& line) { /****************************************************************************/ std::vector DigitalRooster::parse_scanresult( const char* buffer, size_t len) { - QString results(buffer); + auto results = QString::fromLocal8Bit(buffer,len); auto lines = results.splitRef("\n"); std::vector cont; /* From d1423e8c018f7cbbc9d19f09af57671ff257284f Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Fri, 4 Feb 2022 18:00:32 +0100 Subject: [PATCH 03/26] ghactions: switch to ghcr images (bullseye) Signed-off-by: Thomas Ruschival --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/coverity.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 8199bb8..ff4a676 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -16,7 +16,7 @@ jobs: INSTALL_DIR_HOST: /tmp/install BUILD_DIR: /build SRC_DIR: /src - BUILD_IMAGE: ruschi/devlinuxqt-pistache + BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:latest CONTAINER_NAME: buildc TEST_ARTIFACT: test-trace.tgz INSTALL_DIR: /tmp/install diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 8bc756d..a93ac16 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -14,7 +14,7 @@ jobs: BUILD_DIR_HOST: /tmp/build BUILD_DIR: /build SRC_DIR: /src - BUILD_IMAGE: ruschi/devlinuxqt-pistache + BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:latest CONTAINER_NAME: buildc COVERITY_INSTALL_DIR: /tmp/coverity COVERITY_RESULT_DIR: cov-int From 42bff207cc311edd169a06a1a9333c3ab9fe5d6f Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Fri, 4 Feb 2022 18:11:06 +0100 Subject: [PATCH 04/26] login to GHCR Signed-off-by: Thomas Ruschival --- .github/workflows/build_and_test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index ff4a676..33dd07d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -23,6 +23,14 @@ jobs: steps: - name: Clone Repository uses: actions/checkout@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.PULL_SECRET }} + - name: Check Environment run: | docker --version From 258c17c3fe139b71448cd66664cc9d210e8c1492 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Fri, 4 Feb 2022 18:16:24 +0100 Subject: [PATCH 05/26] Try with login and private cr Signed-off-by: Thomas Ruschival --- .github/workflows/build_and_test.yml | 14 ++++++++++++++ .github/workflows/coverity.yml | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 33dd07d..5794d2a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -39,14 +39,17 @@ jobs: echo "host dir: $BUILD_DIR_HOST" echo "container build dir: $BUILD_DIR" echo "container src_dir: $SRC_DIR" + - name: Create build dir run: | mkdir -p $BUILD_DIR_HOST mkdir -p $INSTALL_DIR_HOST chmod 777 $BUILD_DIR_HOST $INSTALL_DIR_HOST + - name: Pull docker container run: docker pull $BUILD_IMAGE timeout-minutes: 5 + - name: Start Docker run: > docker run -itd -u $UID:$GID --privileged --name $CONTAINER_NAME @@ -54,6 +57,7 @@ jobs: -v$BUILD_DIR_HOST:$BUILD_DIR -v$INSTALL_DIR_HOST:$INSTALL_DIR $BUILD_IMAGE + - name: Configure run: > docker exec $CONTAINER_NAME cmake @@ -62,43 +66,53 @@ jobs: -H$SRC_DIR -B$BUILD_DIR -DBUILD_TESTS=On -DTEST_COVERAGE=On -DBUILD_GTEST_FROM_SRC=On -DREST_API=On + - name: Build run: docker exec $CONTAINER_NAME cmake --build $BUILD_DIR --parallel + - name: Get OpenAPI client run: | docker exec -w $SRC_DIR $CONTAINER_NAME buildscripts/get_openapi_client.py + - name: Prepare Python run: | docker exec -w $SRC_DIR $CONTAINER_NAME python3 -m pip install nulltype + - name: Run tests run: docker exec -w $BUILD_DIR $CONTAINER_NAME ctest -V + - name: Package Test output for analysis if: failure() run: > tar -C ${{ env.BUILD_DIR_HOST }} -czf ${{ env.BUILD_DIR_HOST }}/${{ env.TEST_ARTIFACT }} test_trace.log gtest_results.xml + - name: Upload program trace if: failure() uses: actions/upload-artifact@v1 with: name: ${{ env.TEST_ARTIFACT }} path: ${{ env.BUILD_DIR_HOST }}/${{ env.TEST_ARTIFACT }} + - name: Collect coverage run: > docker exec -w $BUILD_DIR $CONTAINER_NAME lcov --directory . --capture --output-file $BUILD_DIR/coverage.info + - name: Prune 3rd party code from coverage info run: > docker exec -w $BUILD_DIR $CONTAINER_NAME lcov --remove $BUILD_DIR/coverage.info --output-file $BUILD_DIR/coverage.info "/usr/*" "*/GTestExternal/*" "*/__/*" + - name: Upload coverage to codecov uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} file: /tmp/build/coverage.info + - name: Test make install run: > docker exec -w $BUILD_DIR -eDESTDIR=$INSTALL_DIR $CONTAINER_NAME diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index a93ac16..6d9f629 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -22,6 +22,14 @@ jobs: steps: - name: Clone Repository uses: actions/checkout@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.PULL_SECRET }} + - name: Check Environment run: | docker --version @@ -32,10 +40,12 @@ jobs: echo "container src_dir: $SRC_DIR" echo "Coverity tarball:" $COVERITY_TARBALL echo "Coverity result:" $COVERITY_RESULT_DIR + - name: Create build dir run: | mkdir -p $BUILD_DIR_HOST mkdir -p $COVERITY_INSTALL_DIR + - name: Install Coverity run: | wget -q https://scan.coverity.com/download/cxx/linux64 \ @@ -44,9 +54,11 @@ jobs: tar xzf cov-analysis-linux64.tar.gz --strip 1 -C $COVERITY_INSTALL_DIR env: TOKEN: ${{ secrets.COVERITY_TOKEN }} + - name: Pull docker container run: docker pull $BUILD_IMAGE timeout-minutes: 5 + - name: Start Docker run: > docker run -itd -u $UID:$GID --privileged --name $CONTAINER_NAME @@ -54,6 +66,7 @@ jobs: -v$BUILD_DIR_HOST:$BUILD_DIR -v$COVERITY_INSTALL_DIR:/coverity $BUILD_IMAGE + - name: Configure (Release, No Tests) run: > docker exec $CONTAINER_NAME cmake @@ -62,12 +75,15 @@ jobs: -H$SRC_DIR -B$BUILD_DIR -DBUILD_TESTS=Off -DTEST_COVERAGE=Off -DBUILD_GTEST_FROM_SRC=Off -DREST_API=On + - name: Gather Coverity build info run: > docker exec -w $BUILD_DIR $CONTAINER_NAME /coverity/bin/cov-build --dir $COVERITY_RESULT_DIR make -j 3 + - name: Package Coverity output run: tar cjvf $COVERITY_TARBALL -C $BUILD_DIR_HOST $COVERITY_RESULT_DIR + - name: Upload Coverity Info run: > curl --form token=$TOKEN From ccbb0c540988377882236083d1b94318a7e20b8c Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Fri, 4 Feb 2022 18:31:44 +0100 Subject: [PATCH 06/26] Why did coverage go down? Signed-off-by: Thomas Ruschival --- .github/workflows/coverity.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 6d9f629..97bca16 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -80,10 +80,8 @@ jobs: run: > docker exec -w $BUILD_DIR $CONTAINER_NAME /coverity/bin/cov-build --dir $COVERITY_RESULT_DIR make -j 3 - - name: Package Coverity output run: tar cjvf $COVERITY_TARBALL -C $BUILD_DIR_HOST $COVERITY_RESULT_DIR - - name: Upload Coverity Info run: > curl --form token=$TOKEN From ffbb099f7b0577de46a65372135182612b7d80ba Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 09:54:25 +0100 Subject: [PATCH 07/26] Minor cleanups Signed-off-by: Thomas Ruschival --- include/IHardware.hpp | 2 +- include/alarmmonitor.hpp | 2 +- libsrc/alarmmonitor.cpp | 1 - libsrc/hardwarecontrol_stub.cpp | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/IHardware.hpp b/include/IHardware.hpp index 257c383..cf0e5f1 100644 --- a/include/IHardware.hpp +++ b/include/IHardware.hpp @@ -63,7 +63,7 @@ class IHardware : public QObject { virtual AlsValue read_als_sensor() = 0; /** need virtual destructor */ - virtual ~IHardware(); + virtual ~IHardware()=default; public slots: /** diff --git a/include/alarmmonitor.hpp b/include/alarmmonitor.hpp index 6920f6b..8438e23 100644 --- a/include/alarmmonitor.hpp +++ b/include/alarmmonitor.hpp @@ -4,7 +4,7 @@ * * \details * - * \copyright (c) 2018 2018 Thomas Ruschival + * \copyright (c) 2018 Thomas Ruschival * \license {This file is licensed under GNU PUBLIC LICENSE Version 3 or later * SPDX-License-Identifier: GPL-3.0-or-later} * diff --git a/libsrc/alarmmonitor.cpp b/libsrc/alarmmonitor.cpp index a7465b1..6c23c11 100644 --- a/libsrc/alarmmonitor.cpp +++ b/libsrc/alarmmonitor.cpp @@ -32,7 +32,6 @@ AlarmMonitor::AlarmMonitor(MediaPlayer& player, if (error != QMediaPlayer::NoError && fallback_alarm_timer.isActive()) { qCWarning(CLASS_LC) << "player error occurred"; - set_state(FallBackMode); trigger_fallback_behavior(); } }); diff --git a/libsrc/hardwarecontrol_stub.cpp b/libsrc/hardwarecontrol_stub.cpp index e0771e0..84fc491 100644 --- a/libsrc/hardwarecontrol_stub.cpp +++ b/libsrc/hardwarecontrol_stub.cpp @@ -15,7 +15,7 @@ using namespace Hal; static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.HardwareControl"); // need for definition in cpp file -Hal::IHardware::~IHardware() = default; +//Hal::IHardware::~IHardware() = default; /*****************************************************************************/ HardwareControlStub::~HardwareControlStub() { From 4d277b81d6e3884be8987d8ccdf3e35f53859eda Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 10:19:27 +0100 Subject: [PATCH 08/26] Updated URL for googletest to release 1.11 Signed-off-by: Thomas Ruschival --- test/CMakeLists.txt.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt.in b/test/CMakeLists.txt.in index a4fd81d..84e0089 100644 --- a/test/CMakeLists.txt.in +++ b/test/CMakeLists.txt.in @@ -19,7 +19,7 @@ PROJECT(GTestExternal include(ExternalProject) ExternalProject_Add(GTestExternal - URL https://github.com/google/googletest/archive/v1.10.x.tar.gz + URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz # GIT_REPOSITORY https://github.com/google/googletest.git # GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e TIMEOUT 10 From d2ba50242ccc878eaa193f781f2538df921d37b8 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 13:43:24 +0100 Subject: [PATCH 09/26] Updated pistache & use std::optional In recent versions of libpistache Pistache::Optional was replaced by std::optional. Reflect this change in source REST-Api code. Signed-off-by: Thomas Ruschival --- REST/ApiHandler.cpp | 7 +++++-- REST/common.hpp | 7 ++++--- test/test_restapihandler.cpp | 9 +++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/REST/ApiHandler.cpp b/REST/ApiHandler.cpp index 176e34a..0772ab2 100644 --- a/REST/ApiHandler.cpp +++ b/REST/ApiHandler.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -95,12 +96,14 @@ QJsonObject DigitalRooster::REST::qjson_form_std_string( /*****************************************************************************/ int DigitalRooster::REST::get_val_from_query_within_range( - const Pistache::Optional& query, int min, int max) { + const std::optional& query, int min, int max) { qCDebug(CLASS_LC) << Q_FUNC_INFO; int val = min; try { - val = std::stoi(query.get()); + val = std::stoi(query.value()); + } catch (const std::bad_optional_access& e) { + qCCritical(CLASS_LC) << Q_FUNC_INFO << e.what(); } catch (const std::invalid_argument& e) { qCCritical(CLASS_LC) << Q_FUNC_INFO << e.what(); } diff --git a/REST/common.hpp b/REST/common.hpp index 8d791d6..1213689 100644 --- a/REST/common.hpp +++ b/REST/common.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -89,7 +90,7 @@ namespace REST { * @return value within range */ int get_val_from_query_within_range( - const Pistache::Optional& query, int min, int max); + const std::optional& query, int min, int max); /** * Convenience function to get a QJsonObject from a std::string @@ -117,14 +118,14 @@ namespace REST { auto max_size = all.size(); int offset = 0; auto offset_param = request.query().get("offset"); - if (!offset_param.isEmpty()) { + if (offset_param.has_value()) { // Offset between 0 and max_size offset = get_val_from_query_within_range(offset_param, 0, max_size); } int length = max_size; auto length_param = request.query().get("length"); - if (!length_param.isEmpty()) { + if (length_param.has_value()) { // length between 0 and max_size-offset length = get_val_from_query_within_range( length_param, 1, max_size - offset); diff --git a/test/test_restapihandler.cpp b/test/test_restapihandler.cpp index 5caa712..d9c2676 100644 --- a/test/test_restapihandler.cpp +++ b/test/test_restapihandler.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -25,25 +26,25 @@ using ::testing::AtLeast; /*****************************************************************************/ TEST(RestAdapter, getUintNotAvailableDefaultToMin) { - auto query = Pistache::Optional(); + auto query = std::optional{}; ASSERT_EQ(get_val_from_query_within_range(query, 2, 5), 2); } /*****************************************************************************/ TEST(RestAdapter, getUintNegativeDefaultToMin) { - Pistache::Optional query = Pistache::Some("-123"); + auto query = std::optional{"-123"}; ASSERT_EQ(get_val_from_query_within_range(query, 5, 100), 5); } /*****************************************************************************/ TEST(RestAdapter, getUintUnConvertableDefaultToMin) { - Pistache::Optional query = Pistache::Some("FOO"); + auto query = std::optional{"FOO"}; ASSERT_EQ(get_val_from_query_within_range(query, 5, 100), 5); } /*****************************************************************************/ TEST(RestAdapter, getUintOutOfRangeCapMax) { - Pistache::Optional query = Pistache::Some("100"); + auto query = std::optional{"100"}; ASSERT_EQ(get_val_from_query_within_range(query, 5, 50), 50); } From e2b3194353f60faa98e7ca1d2953196cbd0c04db Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 13:44:58 +0100 Subject: [PATCH 10/26] Fix compiler warnings about deprecated endl in QT since Qt 5.15 (?) QT wants qualified use of Qt::endl to avoid clash with std::endl. Signed-off-by: Thomas Ruschival --- libsrc/logger.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/logger.cpp b/libsrc/logger.cpp index d686c40..343ed04 100644 --- a/libsrc/logger.cpp +++ b/libsrc/logger.cpp @@ -28,7 +28,7 @@ static void messageHandler( if (!initialized) { out << "\n ======= " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") - << " =======" << endl; + << " =======" << Qt::endl; initialized = true; } out << QDateTime::currentDateTime().toString("hh:mm:ss.zzz "); @@ -50,7 +50,7 @@ static void messageHandler( out << "FAT\t"; break; } - out << context.category << "\t" << msg << endl; + out << context.category << "\t" << msg << Qt::endl; out.flush(); } From 2083e5b450fbf58f5d408043529e79151a13c45d Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 14:37:00 +0100 Subject: [PATCH 11/26] CI-chain: Pin build container tag to v1.0.0 using latest tag might create weird issues in github actions Signed-off-by: Thomas Ruschival --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/coverity.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 5794d2a..a199ac9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -16,7 +16,7 @@ jobs: INSTALL_DIR_HOST: /tmp/install BUILD_DIR: /build SRC_DIR: /src - BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:latest + BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:v1.1.0 CONTAINER_NAME: buildc TEST_ARTIFACT: test-trace.tgz INSTALL_DIR: /tmp/install diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 97bca16..d5ca10a 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -14,7 +14,7 @@ jobs: BUILD_DIR_HOST: /tmp/build BUILD_DIR: /build SRC_DIR: /src - BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:latest + BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:v.1.1.0 CONTAINER_NAME: buildc COVERITY_INSTALL_DIR: /tmp/coverity COVERITY_RESULT_DIR: cov-int From 0f2d78994d97156c17841fed0152cac25f8a35c3 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 16:31:46 +0100 Subject: [PATCH 12/26] Implement Episode count limit with max_episodes Finally implement limiting number of episodes in PodcastSource. If more than max_episodes are in vector the oldest will be discarded. Signed-off-by: Thomas Ruschival --- libsrc/PodcastSource.cpp | 32 +++++++++++++++---------- test/test_podcastsource.cpp | 47 ++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/libsrc/PodcastSource.cpp b/libsrc/PodcastSource.cpp index 3b5497d..6edc30b 100644 --- a/libsrc/PodcastSource.cpp +++ b/libsrc/PodcastSource.cpp @@ -43,15 +43,18 @@ PodcastSource::~PodcastSource() { /*****************************************************************************/ void PodcastSource::add_episode( const std::shared_ptr& episode) { - qCDebug(CLASS_LC) << Q_FUNC_INFO; - if (episodes.size() >= max_episodes) { - qInfo(CLASS_LC) << " > max episodes reached: " << max_episodes; + qCDebug(CLASS_LC) << Q_FUNC_INFO << episode->get_guid(); + auto ep = get_episode_by_id(episode->get_guid()); + /* If episode already in list - skip it */ + if (ep) { + qCDebug(CLASS_LC) << episode->get_guid() << "already in list"; return; } - auto ep = get_episode_by_id(episode->get_guid()); - /* add if not found */ - if (!ep) { - qCDebug(CLASS_LC) << " > new Episode :" << episode->get_guid(); + // Only add if still space left or if episode more recent than oldest + // episode + if (episodes.size() <= max_episodes or + (*episodes.end())->get_publication_date() < + episode->get_publication_date()) { // insert sorted by publication date auto iterator = std::lower_bound(episodes.begin(), episodes.end(), episode, @@ -61,13 +64,16 @@ void PodcastSource::add_episode( rhs->get_publication_date(); }); episodes.insert(iterator, episode); - /* get notified if any data changes */ - connect(episode.get(), &PodcastEpisode::data_changed, this, - &PodcastSource::episode_info_changed); - emit episodes_count_changed(episodes.size()); - } else { - qCDebug(CLASS_LC) << " < " << episode->get_guid() << "already in list"; + /* Remove oldest episode if max episodes has been reached */ + if (episodes.size() > max_episodes) { + qInfo(CLASS_LC) << " > max episodes reached, removing"; + episodes.pop_back(); + } } + /* get notified if any data changes */ + connect(episode.get(), &PodcastEpisode::data_changed, this, + &PodcastSource::episode_info_changed); + emit episodes_count_changed(episodes.size()); } /*****************************************************************************/ diff --git a/test/test_podcastsource.cpp b/test/test_podcastsource.cpp index 7c49df5..a4196b2 100644 --- a/test/test_podcastsource.cpp +++ b/test/test_podcastsource.cpp @@ -34,6 +34,13 @@ class PodcastSourceFixture : public virtual ::testing::Test { "DigitalRoosterGui/develop/test/old_icon.png") , cache_file( cache_dir.filePath(uid.toString(QUuid::WithoutBraces) + ".png")) { + ps.set_max_episodes(5); + ep1 = std::make_shared("Name1",QUrl("http://foo-1.bar")); + ep1->set_publication_date(QDateTime::fromSecsSinceEpoch(100000000)); + ep2 = std::make_shared("Name2",QUrl("http://foo-2.bar")); + ep2->set_publication_date(QDateTime::fromSecsSinceEpoch(200000000)); + ep3 = std::make_shared("Name3",QUrl("http://foo-3.bar")); + ep3->set_publication_date(QDateTime::fromSecsSinceEpoch(300000000)); } ~PodcastSourceFixture() { @@ -53,6 +60,10 @@ class PodcastSourceFixture : public virtual ::testing::Test { PodcastSource ps; QUrl image_url; QFile cache_file; + /* common episodes */ + std::shared_ptr ep1; + std::shared_ptr ep2; + std::shared_ptr ep3; }; /******************************************************************************/ @@ -64,6 +75,39 @@ TEST_F(PodcastSourceFixture, dont_add_twice) { EXPECT_EQ(ps.get_episodes().size(), 1); } +/******************************************************************************/ +TEST_F(PodcastSourceFixture, expected_order) { + ps.add_episode(ep2); + ps.add_episode(ep3); + ps.add_episode(ep1); + EXPECT_EQ(ps.get_episodes().size(), 3); + // oldest last + EXPECT_EQ(ps.get_episodes().back()->get_url(),ep1->get_url()); + // ep3 first + EXPECT_EQ(ps.get_episodes().front()->get_url(),ep3->get_url()); +} + + +/******************************************************************************/ +TEST_F(PodcastSourceFixture, max_reached_adding) { + ps.set_max_episodes(3); + auto p4 = + std::make_shared("Name4", QUrl("http://foo-4.bar")); + // episode 4 is published between ep2 and ep3 + p4->set_publication_date(QDateTime::fromSecsSinceEpoch(220000000)); + ps.add_episode(ep1); + ps.add_episode(ep2); + ps.add_episode(ep3); + ps.add_episode(p4); + // expect ep1 to be removed + EXPECT_EQ(ps.get_episodes().size(), 3); + // now p2 is oldest + EXPECT_EQ(ps.get_episodes().back()->get_url(),ep2->get_url()); + // ep3 first + EXPECT_EQ(ps.get_episodes().front()->get_url(),ep3->get_url()); +} + + /******************************************************************************/ TEST_F(PodcastSourceFixture, add_two_with_guid) { auto pi1 = @@ -218,7 +262,8 @@ TEST_F(PodcastSourceFixture, updateWithNewIconTriggersDownload) { // Second time the local cache should be returned ASSERT_EQ(ps.get_icon(), expected_icon_url); - QFile iconcache_new(cache_dir.filePath(ps.create_image_file_name(image_url_new))); + QFile iconcache_new( + cache_dir.filePath(ps.create_image_file_name(image_url_new))); ASSERT_TRUE(iconcache_new.exists()); } From 88f41caa6d6e24bb43bae4c0b4763c1f740f66b0 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 16:32:38 +0100 Subject: [PATCH 13/26] Max_episodes as size_t to make compiler happy since max_episodes is internal, it does not need to be int and comparison warning can be avoided. Signed-off-by: Thomas Ruschival --- include/PodcastSource.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/PodcastSource.hpp b/include/PodcastSource.hpp index 39d2617..359d304 100644 --- a/include/PodcastSource.hpp +++ b/include/PodcastSource.hpp @@ -380,7 +380,7 @@ public slots: /** * show max_episodes in the list */ - int max_episodes = std::numeric_limits::max(); + size_t max_episodes = std::numeric_limits::max(); /** * Interval in ms for auto refresh of content From c97443adbee3d7e7298f7cd82839b614f1e83683 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 16:34:22 +0100 Subject: [PATCH 14/26] Do not return something from void function Even if the implementation of the called function does not return something now, no need to write return ....; The interface of the function is void. Signed-off-by: Thomas Ruschival --- libsrc/mediaplayer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/mediaplayer.cpp b/libsrc/mediaplayer.cpp index 9486b59..dcf9726 100644 --- a/libsrc/mediaplayer.cpp +++ b/libsrc/mediaplayer.cpp @@ -28,19 +28,19 @@ double MediaPlayer::get_volume() const { /*****************************************************************************/ void MediaPlayer::set_muted(bool muted) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return do_set_muted(muted); + do_set_muted(muted); } /*****************************************************************************/ void MediaPlayer::set_volume(double volume) { qCDebug(CLASS_LC) << Q_FUNC_INFO << volume; - return do_set_volume(std::clamp(volume, 0.0, 100.0)); + do_set_volume(std::clamp(volume, 0.0, 100.0)); } /*****************************************************************************/ void MediaPlayer::increment_volume(double increment) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return do_increment_volume(increment); + do_increment_volume(increment); } /*****************************************************************************/ From 8ee47261204e9600620b7c6609a8e98a36913b0a Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 17:08:38 +0100 Subject: [PATCH 15/26] Refactor ConfigurationManager->Configuration 1/x Signed-off-by: Thomas Ruschival --- include/PlayableItem.hpp | 2 +- ...guration_manager.hpp => configuration.hpp} | 6 +- include/weather.hpp | 2 +- include/wifi_control.hpp | 4 +- libsrc/CMakeLists.txt | 4 +- ...guration_manager.cpp => configuration.cpp} | 106 +++++++++--------- libsrc/wifi_control.cpp | 4 +- qtgui/main.cpp | 8 +- qtgui/podcastepisodemodel.hpp | 2 +- test/CMakeLists.txt | 4 +- test/cm_mock.hpp | 6 +- test/restserver.cpp | 4 +- ...st_settings.cpp => test_configuration.cpp} | 92 +++++++-------- 13 files changed, 122 insertions(+), 122 deletions(-) rename include/{configuration_manager.hpp => configuration.hpp} (98%) rename libsrc/{configuration_manager.cpp => configuration.cpp} (87%) rename test/{test_settings.cpp => test_configuration.cpp} (87%) diff --git a/include/PlayableItem.hpp b/include/PlayableItem.hpp index 69e393b..2176561 100644 --- a/include/PlayableItem.hpp +++ b/include/PlayableItem.hpp @@ -157,7 +157,7 @@ class PlayableItem : public QObject { private: /** - * 'unique' id for this object, info managed by configuration_manager + * 'unique' id for this object, info managed by configuration */ const QUuid id; diff --git a/include/configuration_manager.hpp b/include/configuration.hpp similarity index 98% rename from include/configuration_manager.hpp rename to include/configuration.hpp index a7a3f23..74a16bf 100644 --- a/include/configuration_manager.hpp +++ b/include/configuration.hpp @@ -40,7 +40,7 @@ class Alarm; /** * Reads JSON configuration and provides API to configuration objects */ -class ConfigurationManager : public QObject, +class Configuration : public QObject, public IAlarmStore, public IStationStore, public IPodcastStore, @@ -62,9 +62,9 @@ class ConfigurationManager : public QObject, * @param configpath path to application configuration * @param cachedir directory to cache data (podcastlist etc) */ - ConfigurationManager(const QString& configpath, const QString& cachedir); + Configuration(const QString& configpath, const QString& cachedir); - virtual ~ConfigurationManager() = default; + virtual ~Configuration() = default; /** * return compile time version string diff --git a/include/weather.hpp b/include/weather.hpp index 8c414eb..a100865 100644 --- a/include/weather.hpp +++ b/include/weather.hpp @@ -30,7 +30,7 @@ namespace DigitalRooster { class Weather; -class ConfigurationManager; +class Configuration; /** * Object for Forecast data diff --git a/include/wifi_control.hpp b/include/wifi_control.hpp index 8e27e78..787eed5 100644 --- a/include/wifi_control.hpp +++ b/include/wifi_control.hpp @@ -28,7 +28,7 @@ namespace DigitalRooster { // Forward declaration -class ConfigurationManager; +class Configuration; /** * Function to register as callback @@ -69,7 +69,7 @@ class WifiControl : public QObject { * @param cm configuration manager (to get WIFI interface) * @return */ - static WifiControl* get_instance(ConfigurationManager* cm = nullptr); + static WifiControl* get_instance(Configuration* cm = nullptr); /** * Trigger Push Button Configuration (PBC) authentication diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index 57d82a6..a589405 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -45,7 +45,7 @@ LIST(APPEND CPP_DEFS GIT_DESCRIBE_REV=${GIT_DESCRIBE_REV} ) SET(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/playableitem.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/configuration_manager.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/configuration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rss2podcastsource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PodcastSource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/httpclient.cpp @@ -74,7 +74,7 @@ SET(SRCS # Moc any classes derived from QObject SET(MOC_SRC - ${PROJECT_INCLUDE_DIR}/configuration_manager.hpp + ${PROJECT_INCLUDE_DIR}/configuration.hpp ${PROJECT_INCLUDE_DIR}/httpclient.hpp ${PROJECT_INCLUDE_DIR}/UpdateTask.hpp ${PROJECT_INCLUDE_DIR}/PlayableItem.hpp diff --git a/libsrc/configuration_manager.cpp b/libsrc/configuration.cpp similarity index 87% rename from libsrc/configuration_manager.cpp rename to libsrc/configuration.cpp index 28f3b78..507c306 100644 --- a/libsrc/configuration_manager.cpp +++ b/libsrc/configuration.cpp @@ -17,7 +17,7 @@ #include "PodcastSource.hpp" #include "UpdateTask.hpp" #include "alarm.hpp" -#include "configuration_manager.hpp" +#include "configuration.hpp" #include "util.hpp" using namespace DigitalRooster; @@ -69,7 +69,7 @@ void delete_by_id(std::vector>& container, const QUuid& id) { } /*****************************************************************************/ -ConfigurationManager::ConfigurationManager( +Configuration::Configuration( const QString& configpath, const QString& cachedir) : global_alarm_timeout(DEFAULT_ALARM_TIMEOUT) , sleep_timeout(DEFAULT_SLEEP_TIMEOUT) @@ -113,14 +113,14 @@ ConfigurationManager::ConfigurationManager( // store connection to disconnect during write_config_file fwConn = connect(&filewatcher, &QFileSystemWatcher::fileChanged, this, - &ConfigurationManager::fileChanged); + &Configuration::fileChanged); // Event loop timer every 5 seconds to update remaining time evt_timer_id = startTimer(std::chrono::seconds(5)); }; /*****************************************************************************/ -void ConfigurationManager::timerEvent(QTimerEvent* evt) { +void Configuration::timerEvent(QTimerEvent* evt) { qCDebug(CLASS_LC) << Q_FUNC_INFO; if (evt->timerId() == evt_timer_id && dirty) { store_current_config(); @@ -131,7 +131,7 @@ void ConfigurationManager::timerEvent(QTimerEvent* evt) { } /*****************************************************************************/ -void ConfigurationManager::refresh_configuration() { +void Configuration::refresh_configuration() { qCDebug(CLASS_LC) << Q_FUNC_INFO; alarms.clear(); @@ -143,7 +143,7 @@ void ConfigurationManager::refresh_configuration() { } /*****************************************************************************/ -QString ConfigurationManager::get_json_from_file(const QString& path) { +QString Configuration::get_json_from_file(const QString& path) { QString content; QFile file(path); qCDebug(CLASS_LC) << Q_FUNC_INFO; @@ -162,7 +162,7 @@ QString ConfigurationManager::get_json_from_file(const QString& path) { } /*****************************************************************************/ -void ConfigurationManager::parse_json(const QByteArray& json) { +void Configuration::parse_json(const QByteArray& json) { qCDebug(CLASS_LC) << Q_FUNC_INFO; QJsonDocument doc = QJsonDocument::fromJson(json); QJsonObject appconfig = doc.object(); @@ -197,7 +197,7 @@ void ConfigurationManager::parse_json(const QByteArray& json) { } /*****************************************************************************/ -void ConfigurationManager::read_radio_streams(const QJsonObject& appconfig) { +void Configuration::read_radio_streams(const QJsonObject& appconfig) { qCDebug(CLASS_LC) << Q_FUNC_INFO; QJsonArray stations = appconfig[DigitalRooster::KEY_GROUP_IRADIO_SOURCES].toArray(); @@ -222,7 +222,7 @@ void ConfigurationManager::read_radio_streams(const QJsonObject& appconfig) { } /*****************************************************************************/ -void ConfigurationManager::read_podcasts(const QJsonObject& appconfig) { +void Configuration::read_podcasts(const QJsonObject& appconfig) { qCDebug(CLASS_LC) << Q_FUNC_INFO; QJsonArray podcasts = appconfig[DigitalRooster::KEY_GROUP_PODCAST_SOURCES].toArray(); @@ -241,7 +241,7 @@ void ConfigurationManager::read_podcasts(const QJsonObject& appconfig) { // Get notifications if name etc. changes connect(ps.get(), &PodcastSource::dataChanged, this, - &ConfigurationManager::dataChanged); + &Configuration::dataChanged); podcast_sources.push_back(ps); } catch (std::invalid_argument& exc) { qCDebug(CLASS_LC) << "invalid argument" << exc.what(); @@ -256,7 +256,7 @@ void ConfigurationManager::read_podcasts(const QJsonObject& appconfig) { } /*****************************************************************************/ -void ConfigurationManager::read_alarms(const QJsonObject& appconfig) { +void Configuration::read_alarms(const QJsonObject& appconfig) { qCDebug(CLASS_LC) << Q_FUNC_INFO; QJsonArray alarm_config = appconfig[DigitalRooster::KEY_GROUP_ALARMS].toArray(); @@ -264,7 +264,7 @@ void ConfigurationManager::read_alarms(const QJsonObject& appconfig) { try { auto alarm = Alarm::from_json_object(al.toObject()); connect(alarm.get(), &Alarm::dataChanged, this, - &ConfigurationManager::alarm_data_changed); + &Configuration::alarm_data_changed); alarms.push_back(alarm); } catch (std::invalid_argument& exc) { qCWarning(CLASS_LC) @@ -275,7 +275,7 @@ void ConfigurationManager::read_alarms(const QJsonObject& appconfig) { } /*****************************************************************************/ -void ConfigurationManager::read_weather(const QJsonObject& appconfig) { +void Configuration::read_weather(const QJsonObject& appconfig) { qCDebug(CLASS_LC) << Q_FUNC_INFO; QJsonObject json_weather = appconfig[KEY_WEATHER].toObject(); try { @@ -286,58 +286,58 @@ void ConfigurationManager::read_weather(const QJsonObject& appconfig) { } /*****************************************************************************/ -void ConfigurationManager::dataChanged() { +void Configuration::dataChanged() { qCDebug(CLASS_LC) << Q_FUNC_INFO; dirty = true; } /*****************************************************************************/ -void ConfigurationManager::fileChanged(const QString& /*path*/) { +void Configuration::fileChanged(const QString& /*path*/) { qCDebug(CLASS_LC) << Q_FUNC_INFO; refresh_configuration(); } /*****************************************************************************/ -void ConfigurationManager::set_volume(double vol) { +void Configuration::set_volume(double vol) { qCDebug(CLASS_LC) << Q_FUNC_INFO << vol; this->volume = std::clamp(vol, 0.0, 100.0); dirty = true; } /*****************************************************************************/ -void ConfigurationManager::set_standby_brightness(int brightness) { +void Configuration::set_standby_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness; this->brightness_sb = std::clamp(brightness, 0, 100); dirty = true; } /*****************************************************************************/ -void ConfigurationManager::set_active_brightness(int brightness) { +void Configuration::set_active_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness; do_set_brightness_act(std::clamp(brightness, 0, 100)); } /*****************************************************************************/ -void ConfigurationManager::do_set_brightness_act(int brightness) { +void Configuration::do_set_brightness_act(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness; this->brightness_act = brightness; dirty = true; } /*****************************************************************************/ -bool ConfigurationManager::backlight_control_enabled() const { +bool Configuration::backlight_control_enabled() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return backlight_control_act; } /*****************************************************************************/ -void ConfigurationManager::enable_backlight_control(bool ena) { +void Configuration::enable_backlight_control(bool ena) { qCDebug(CLASS_LC) << Q_FUNC_INFO; backlight_control_act = ena; } /*****************************************************************************/ -void ConfigurationManager::store_current_config() { +void Configuration::store_current_config() { qCDebug(CLASS_LC) << Q_FUNC_INFO; QJsonObject appconfig; @@ -382,7 +382,7 @@ void ConfigurationManager::store_current_config() { } /*****************************************************************************/ -void ConfigurationManager::write_config_file(const QJsonObject& appconfig) { +void Configuration::write_config_file(const QJsonObject& appconfig) { qCDebug(CLASS_LC) << Q_FUNC_INFO; auto file_path = get_configuration_path(); @@ -404,7 +404,7 @@ void ConfigurationManager::write_config_file(const QJsonObject& appconfig) { } // Reconnect filewatcher to be notified if someone else changes file fwConn = connect(&filewatcher, &QFileSystemWatcher::fileChanged, this, - &ConfigurationManager::fileChanged); + &Configuration::fileChanged); if (!fwConn) { qCCritical(CLASS_LC) << "reconnect failed!"; } @@ -412,7 +412,7 @@ void ConfigurationManager::write_config_file(const QJsonObject& appconfig) { } /*****************************************************************************/ -void ConfigurationManager::create_default_configuration() { +void Configuration::create_default_configuration() { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* 2 Alarms */ alarms.push_back(std::make_shared( @@ -448,25 +448,25 @@ void ConfigurationManager::create_default_configuration() { } /*****************************************************************************/ -QString ConfigurationManager::get_configuration_path() const { +QString Configuration::get_configuration_path() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return config_file; } /*****************************************************************************/ -QString ConfigurationManager::get_wpa_socket_name() const { +QString Configuration::get_wpa_socket_name() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return wpa_socket_name; } /*****************************************************************************/ -QString ConfigurationManager::get_net_dev_name() const { +QString Configuration::get_net_dev_name() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return net_dev_name; } /*****************************************************************************/ -QString ConfigurationManager::check_and_create_config() { +QString Configuration::check_and_create_config() { qCDebug(CLASS_LC) << Q_FUNC_INFO; // check if file exists -> assume some default config and write file auto path = get_configuration_path(); @@ -479,7 +479,7 @@ QString ConfigurationManager::check_and_create_config() { } /*****************************************************************************/ -QString ConfigurationManager::get_cache_dir_name() { +QString Configuration::get_cache_dir_name() { qCDebug(CLASS_LC) << Q_FUNC_INFO; return application_cache_dir.path(); } @@ -490,29 +490,29 @@ QString ConfigurationManager::get_cache_dir_name() { /***************************************************************************** * Implementation of IAlarmStore *****************************************************************************/ -void ConfigurationManager::delete_alarm(const QUuid& id) { +void Configuration::delete_alarm(const QUuid& id) { qCDebug(CLASS_LC) << Q_FUNC_INFO; // Disconnect signal-slot auto* a = find_by_id(alarms, id); disconnect(a, &Alarm::dataChanged, this, - &ConfigurationManager::alarm_data_changed); + &Configuration::alarm_data_changed); /* delete may throw - just pass it on to the client */ delete_by_id(alarms, id); dataChanged(); emit alarms_changed(); }; /*****************************************************************************/ -void ConfigurationManager::add_alarm(std::shared_ptr alarm) { +void Configuration::add_alarm(std::shared_ptr alarm) { qCDebug(CLASS_LC) << Q_FUNC_INFO; this->alarms.push_back(alarm); connect(alarm.get(), &Alarm::dataChanged, this, - &ConfigurationManager::alarm_data_changed); + &Configuration::alarm_data_changed); dataChanged(); emit alarms_changed(); } /*****************************************************************************/ -const Alarm* ConfigurationManager::get_alarm(const QUuid& id) const { +const Alarm* Configuration::get_alarm(const QUuid& id) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* Find by id throws - just pass it on to the client */ return find_by_id(alarms, id); @@ -520,13 +520,13 @@ const Alarm* ConfigurationManager::get_alarm(const QUuid& id) const { /*****************************************************************************/ const std::vector>& -ConfigurationManager::get_alarms() const { +Configuration::get_alarms() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return alarms; } /*****************************************************************************/ -void ConfigurationManager::alarm_data_changed() { +void Configuration::alarm_data_changed() { qCDebug(CLASS_LC) << Q_FUNC_INFO; emit alarms_changed(); dataChanged(); // save the changes @@ -535,7 +535,7 @@ void ConfigurationManager::alarm_data_changed() { /***************************************************************************** * Implementation of IStationStore *****************************************************************************/ -void ConfigurationManager::add_radio_station( +void Configuration::add_radio_station( std::shared_ptr src) { qCDebug(CLASS_LC) << Q_FUNC_INFO; this->stream_sources.push_back(src); @@ -544,7 +544,7 @@ void ConfigurationManager::add_radio_station( } /*****************************************************************************/ -void ConfigurationManager::delete_radio_station(const QUuid& id) { +void Configuration::delete_radio_station(const QUuid& id) { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* delete may throw - just pass it on to the client */ delete_by_id(stream_sources, id); @@ -553,7 +553,7 @@ void ConfigurationManager::delete_radio_station(const QUuid& id) { }; /*****************************************************************************/ -const PlayableItem* ConfigurationManager::get_station(const QUuid& id) const { +const PlayableItem* Configuration::get_station(const QUuid& id) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* Find by id throws - just pass it on to the client */ return find_by_id(stream_sources, id); @@ -561,7 +561,7 @@ const PlayableItem* ConfigurationManager::get_station(const QUuid& id) const { /*****************************************************************************/ const std::vector>& -ConfigurationManager::get_stations() const { +Configuration::get_stations() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return stream_sources; } @@ -570,7 +570,7 @@ ConfigurationManager::get_stations() const { /***************************************************************************** * Implementation of IPodcastStore *****************************************************************************/ -void ConfigurationManager::add_podcast_source( +void Configuration::add_podcast_source( std::shared_ptr podcast) { qCDebug(CLASS_LC) << Q_FUNC_INFO; this->podcast_sources.push_back(podcast); @@ -579,7 +579,7 @@ void ConfigurationManager::add_podcast_source( } /*****************************************************************************/ -void ConfigurationManager::delete_podcast_source(const QUuid& id) { +void Configuration::delete_podcast_source(const QUuid& id) { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* delete may throw - just pass it on to the client */ delete_by_id(podcast_sources, id); @@ -588,7 +588,7 @@ void ConfigurationManager::delete_podcast_source(const QUuid& id) { }; /*****************************************************************************/ -const PodcastSource* ConfigurationManager::get_podcast_source( +const PodcastSource* Configuration::get_podcast_source( const QUuid& id) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* Find by id throws - just pass it on to the client */ @@ -597,20 +597,20 @@ const PodcastSource* ConfigurationManager::get_podcast_source( /*****************************************************************************/ const std::vector>& -ConfigurationManager::get_podcast_sources() const { +Configuration::get_podcast_sources() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return podcast_sources; } /*****************************************************************************/ -PodcastSource* ConfigurationManager::get_podcast_source_by_index( +PodcastSource* Configuration::get_podcast_source_by_index( int index) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return podcast_sources.at(index).get(); } /*****************************************************************************/ -void ConfigurationManager::remove_podcast_source_by_index(int index) { +void Configuration::remove_podcast_source_by_index(int index) { qCDebug(CLASS_LC) << Q_FUNC_INFO; assert((index >= 0) && (podcast_sources.begin() + index < podcast_sources.end())); @@ -622,13 +622,13 @@ void ConfigurationManager::remove_podcast_source_by_index(int index) { /***************************************************************************** * Implementation of IBrightnessStore *****************************************************************************/ -int ConfigurationManager::get_active_brightness() const { +int Configuration::get_active_brightness() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return brightness_act; } /*****************************************************************************/ -int ConfigurationManager::get_standby_brightness() const { +int Configuration::get_standby_brightness() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return brightness_sb; } @@ -636,19 +636,19 @@ int ConfigurationManager::get_standby_brightness() const { /***************************************************************************** * Implementation of ITimeoutStore *****************************************************************************/ -std::chrono::minutes ConfigurationManager::get_sleep_timeout() const { +std::chrono::minutes Configuration::get_sleep_timeout() const { return sleep_timeout; } /*****************************************************************************/ -void ConfigurationManager::set_sleep_timeout(std::chrono::minutes timeout) { +void Configuration::set_sleep_timeout(std::chrono::minutes timeout) { qCDebug(CLASS_LC) << Q_FUNC_INFO; sleep_timeout = timeout; dirty = true; } /*****************************************************************************/ -std::chrono::minutes ConfigurationManager::get_alarm_timeout() const { +std::chrono::minutes Configuration::get_alarm_timeout() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return global_alarm_timeout; } @@ -656,7 +656,7 @@ std::chrono::minutes ConfigurationManager::get_alarm_timeout() const { /***************************************************************************** * Implementation of IWeatherConfigStore *****************************************************************************/ -const WeatherConfig& ConfigurationManager::get_weather_config() const { +const WeatherConfig& Configuration::get_weather_config() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return weather_cfg; } diff --git a/libsrc/wifi_control.cpp b/libsrc/wifi_control.cpp index 0237f4f..2adec16 100644 --- a/libsrc/wifi_control.cpp +++ b/libsrc/wifi_control.cpp @@ -10,7 +10,7 @@ #include #include "appconstants.hpp" -#include "configuration_manager.hpp" +#include "configuration.hpp" #include "wifi_control.hpp" #include "wpa_ctrl/wpa_ctrl.h" @@ -19,7 +19,7 @@ using namespace DigitalRooster; static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.WifiControl"); /****************************************************************************/ -WifiControl* WifiControl::get_instance(ConfigurationManager* cm) { +WifiControl* WifiControl::get_instance(Configuration* cm) { qCDebug(CLASS_LC) << Q_FUNC_INFO; static WifiControl instance; // only if not initialized and we have a control_manager diff --git a/qtgui/main.cpp b/qtgui/main.cpp index e2b9405..da0482b 100644 --- a/qtgui/main.cpp +++ b/qtgui/main.cpp @@ -35,7 +35,7 @@ #include "alarmmonitor.hpp" #include "appconstants.hpp" #include "brightnesscontrol.hpp" -#include "configuration_manager.hpp" +#include "configuration.hpp" #include "iradiolistmodel.hpp" #include "logger.hpp" #include "mediaplayerproxy.hpp" @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) { /* * Read configuration */ - ConfigurationManager cm( + Configuration cm( cmdline.value(CMD_ARG_CONFIG_FILE), cmdline.value(CMD_ARG_CACHE_DIR)); cm.update_configuration(); @@ -143,7 +143,7 @@ int main(int argc, char* argv[]) { playerproxy.set_volume(cm.get_volume()); AlarmDispatcher alarmdispatcher(cm); - QObject::connect(&cm, &ConfigurationManager::alarms_changed, + QObject::connect(&cm, &Configuration::alarms_changed, &alarmdispatcher, &AlarmDispatcher::check_alarms); AlarmMonitor alarmmonitor(playerproxy, std::chrono::seconds(20)); QObject::connect(&alarmdispatcher, &AlarmDispatcher::alarm_triggered, @@ -212,7 +212,7 @@ int main(int argc, char* argv[]) { QObject::connect(&power, &PowerControl::active, &volbtn, &VolumeButton::monitor_rotary_button); QObject::connect(&playerproxy, &MediaPlayer::volume_changed, &cm, - &ConfigurationManager::set_volume); + &Configuration::set_volume); /* Network / Wifi Settings */ NetworkInfo netinfo(cm.get_net_dev_name()); diff --git a/qtgui/podcastepisodemodel.hpp b/qtgui/podcastepisodemodel.hpp index 393dd75..8aa6e07 100644 --- a/qtgui/podcastepisodemodel.hpp +++ b/qtgui/podcastepisodemodel.hpp @@ -20,7 +20,7 @@ namespace DigitalRooster { -class ConfigurationManager; +class Configuration; class PodcastEpisode; class MediaPlayer; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ee18a46..c7a3b8a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -195,11 +195,12 @@ CONFIGURE_FILE( # Unit test sources, TestDoubles, Mocks etc. #------------------------------------------------------------------------------- SET(TEST_HARNESS_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/test_alarm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_alarm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_alarmdispatcher.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_alarmmonitor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_brightness.cpp ${CMAKE_CURRENT_SOURCE_DIR}/testcommon.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_configuration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_hardware_config.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_mediaplayerproxy.cpp @@ -208,7 +209,6 @@ SET(TEST_HARNESS_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test_podcast_serializer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_podcastsource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_powercontrol.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test_settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_sleeptimer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_update_task.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_volume_button.cpp diff --git a/test/cm_mock.hpp b/test/cm_mock.hpp index 87030ab..5a3a573 100644 --- a/test/cm_mock.hpp +++ b/test/cm_mock.hpp @@ -11,17 +11,17 @@ #include #include "appconstants.hpp" -#include "configuration_manager.hpp" +#include "configuration.hpp" #include "gmock/gmock.h" #include "gtest/gtest.h" -class CmMock : public DigitalRooster::ConfigurationManager { +class CmMock : public DigitalRooster::Configuration { public: CmMock(const QString& configpath = QString(DigitalRooster::TEST_FILE_PATH + "/" + DigitalRooster::CONFIG_JSON_FILE_NAME), const QString& cachedir = QString( DigitalRooster::TEST_FILE_PATH + "/" + "cache")) - : ConfigurationManager(configpath, cachedir) { + : Configuration(configpath, cachedir) { qRegisterMetaType>( "std::shared_ptr"); }; diff --git a/test/restserver.cpp b/test/restserver.cpp index 7910971..4c6ae5e 100644 --- a/test/restserver.cpp +++ b/test/restserver.cpp @@ -12,7 +12,7 @@ #include "RestApi.hpp" #include "appconstants.hpp" -#include "configuration_manager.hpp" +#include "configuration.hpp" #include "testcommon.hpp" #include "util.hpp" @@ -36,7 +36,7 @@ int main(int argc, char** argv) { setup_tests(); qDebug() << argv[0]; - ConfigurationManager cm( + Configuration cm( cmdline.value(CMD_ARG_CONFIG_FILE), cmdline.value(CMD_ARG_CACHE_DIR)); RestApi restserver(cm, cm, cm, cm, cm); cm.update_configuration(); diff --git a/test/test_settings.cpp b/test/test_configuration.cpp similarity index 87% rename from test/test_settings.cpp rename to test/test_configuration.cpp index dc99184..fe39774 100644 --- a/test/test_settings.cpp +++ b/test/test_configuration.cpp @@ -15,18 +15,18 @@ #include "PodcastSource.hpp" #include "alarm.hpp" #include "appconstants.hpp" -#include "configuration_manager.hpp" +#include "configuration.hpp" using namespace DigitalRooster; -class SettingsFixture : public virtual ::testing::Test { +class ConfigurationFixture : public virtual ::testing::Test { public: - SettingsFixture() + ConfigurationFixture() : filename(DEFAULT_CONFIG_FILE_PATH + "_SettingsFixture") , cache_dir(DEFAULT_CACHE_DIR_PATH) { } - ~SettingsFixture() { + ~ConfigurationFixture() { } void SetUp() { @@ -42,7 +42,7 @@ class SettingsFixture : public virtual ::testing::Test { tf.write(doc.toJson()); tf.close(); - cm = std::make_unique(filename, cache_dir); + cm = std::make_unique(filename, cache_dir); cm->update_configuration(); } @@ -58,7 +58,7 @@ class SettingsFixture : public virtual ::testing::Test { QString filename; QString cache_dir; QJsonObject appconfig; - std::unique_ptr cm; + std::unique_ptr cm; void add_internet_radio(QJsonObject& root) { QJsonArray radiosources; @@ -188,13 +188,13 @@ class SettingsFixture : public virtual ::testing::Test { /*****************************************************************************/ -TEST_F(SettingsFixture, read_radio_streams_two_streams) { +TEST_F(ConfigurationFixture, read_radio_streams_two_streams) { auto& v = cm->get_stations(); ASSERT_EQ(2, v.size()); } /*****************************************************************************/ -TEST_F(SettingsFixture, addRadioStation_no_write) { +TEST_F(ConfigurationFixture, addRadioStation_no_write) { cm->add_radio_station( std::make_shared("foo", QUrl("http://bar.baz"))); cm->add_radio_station( @@ -204,7 +204,7 @@ TEST_F(SettingsFixture, addRadioStation_no_write) { } /*****************************************************************************/ -TEST_F(SettingsFixture, addRadioStation_write) { +TEST_F(ConfigurationFixture, addRadioStation_write) { { cm->add_radio_station( std::make_shared("foo", QUrl("http://bar.baz"))); @@ -213,7 +213,7 @@ TEST_F(SettingsFixture, addRadioStation_write) { /* should write file in destructor */ cm->store_current_config(); } - ConfigurationManager control(filename, TEST_FILE_PATH); + Configuration control(filename, TEST_FILE_PATH); control.update_configuration(); auto& v = control.get_stations(); ASSERT_EQ(4, v.size()); @@ -223,7 +223,7 @@ TEST_F(SettingsFixture, addRadioStation_write) { } /*****************************************************************************/ -TEST_F(SettingsFixture, add_podcast_source) { +TEST_F(ConfigurationFixture, add_podcast_source) { QSignalSpy spy(cm.get(), SIGNAL(podcast_sources_changed())); ASSERT_TRUE(spy.isValid()); auto ps = std::make_shared( @@ -235,13 +235,13 @@ TEST_F(SettingsFixture, add_podcast_source) { } /*****************************************************************************/ -TEST_F(SettingsFixture, get_podcast_source_throws) { +TEST_F(ConfigurationFixture, get_podcast_source_throws) { EXPECT_THROW( cm->get_podcast_source(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, get_podcast_source_ok) { +TEST_F(ConfigurationFixture, get_podcast_source_ok) { auto& v = cm->get_podcast_sources(); auto uid = v[0]->get_id(); auto item = cm->get_podcast_source(uid); @@ -249,7 +249,7 @@ TEST_F(SettingsFixture, get_podcast_source_ok) { } /*****************************************************************************/ -TEST_F(SettingsFixture, delete_podcast_source) { +TEST_F(ConfigurationFixture, delete_podcast_source) { auto& v = cm->get_podcast_sources(); auto size_before = v.size(); auto uid = v[0]->get_id(); @@ -258,13 +258,13 @@ TEST_F(SettingsFixture, delete_podcast_source) { EXPECT_THROW(cm->get_podcast_source(uid), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, delete_podcast_throws) { +TEST_F(ConfigurationFixture, delete_podcast_throws) { EXPECT_THROW( cm->delete_podcast_source(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, add_radio_station) { +TEST_F(ConfigurationFixture, add_radio_station) { QSignalSpy spy(cm.get(), SIGNAL(stations_changed())); ASSERT_TRUE(spy.isValid()); auto radio = std::make_shared(); @@ -275,12 +275,12 @@ TEST_F(SettingsFixture, add_radio_station) { } /*****************************************************************************/ -TEST_F(SettingsFixture, get_radio_station_throws) { +TEST_F(ConfigurationFixture, get_radio_station_throws) { EXPECT_THROW(cm->get_station(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, get_radio_station_ok) { +TEST_F(ConfigurationFixture, get_radio_station_ok) { auto& v = cm->get_stations(); auto uid = v[0]->get_id(); auto item = cm->get_station(uid); @@ -288,7 +288,7 @@ TEST_F(SettingsFixture, get_radio_station_ok) { } /*****************************************************************************/ -TEST_F(SettingsFixture, delete_radio_station) { +TEST_F(ConfigurationFixture, delete_radio_station) { auto& v = cm->get_stations(); auto size_before = v.size(); auto uid = v[0]->get_id(); @@ -297,14 +297,14 @@ TEST_F(SettingsFixture, delete_radio_station) { EXPECT_THROW(cm->get_station(uid), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, delete_radio_throws) { +TEST_F(ConfigurationFixture, delete_radio_throws) { EXPECT_THROW( cm->delete_radio_station(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, add_alarm) { +TEST_F(ConfigurationFixture, add_alarm) { QSignalSpy spy(cm.get(), SIGNAL(alarms_changed())); ASSERT_TRUE(spy.isValid()); auto alm = std::make_shared(); @@ -315,12 +315,12 @@ TEST_F(SettingsFixture, add_alarm) { } /*****************************************************************************/ -TEST_F(SettingsFixture, get_alarm_throws) { +TEST_F(ConfigurationFixture, get_alarm_throws) { EXPECT_THROW(cm->get_alarm(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, get_alarm_ok) { +TEST_F(ConfigurationFixture, get_alarm_ok) { auto& v = cm->get_alarms(); auto uid = v[0]->get_id(); auto item = cm->get_alarm(uid); @@ -328,7 +328,7 @@ TEST_F(SettingsFixture, get_alarm_ok) { } /*****************************************************************************/ -TEST_F(SettingsFixture, delete_alarm) { +TEST_F(ConfigurationFixture, delete_alarm) { auto& v = cm->get_alarms(); auto size_before = v.size(); auto uid = v[0]->get_id(); @@ -338,12 +338,12 @@ TEST_F(SettingsFixture, delete_alarm) { } /*****************************************************************************/ -TEST_F(SettingsFixture, delete_alarm_throws) { +TEST_F(ConfigurationFixture, delete_alarm_throws) { EXPECT_THROW(cm->delete_alarm(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ -TEST_F(SettingsFixture, ChangeAlarmEmitsAlarmsChanged) { +TEST_F(ConfigurationFixture, ChangeAlarmEmitsAlarmsChanged) { auto& v = cm->get_alarms(); QSignalSpy spy(cm.get(), SIGNAL(alarms_changed())); v[0]->enable(false); @@ -351,13 +351,13 @@ TEST_F(SettingsFixture, ChangeAlarmEmitsAlarmsChanged) { } /*****************************************************************************/ -TEST_F(SettingsFixture, read_2podcasts) { +TEST_F(ConfigurationFixture, read_2podcasts) { auto& v = cm->get_podcast_sources(); ASSERT_EQ(2, v.size()); } /*****************************************************************************/ -TEST_F(SettingsFixture, deletePodcastByIndex) { +TEST_F(ConfigurationFixture, deletePodcastByIndex) { auto& v = cm->get_podcast_sources(); ASSERT_EQ(2, v.size()); cm->remove_podcast_source_by_index(0); @@ -365,14 +365,14 @@ TEST_F(SettingsFixture, deletePodcastByIndex) { } /*****************************************************************************/ -TEST_F(SettingsFixture, read_PodcastUri) { +TEST_F(ConfigurationFixture, read_PodcastUri) { auto ps = cm->get_podcast_source_by_index(0); ASSERT_EQ( ps->get_url(), QString("https://alternativlos.org/alternativlos.rss")); } /*****************************************************************************/ -TEST_F(SettingsFixture, podcastSource_incomplete) { +TEST_F(ConfigurationFixture, podcastSource_incomplete) { auto& v = cm->get_podcast_sources(); ASSERT_EQ(v[0]->get_url(), QString("https://alternativlos.org/alternativlos.rss")); @@ -389,7 +389,7 @@ TEST(StringToPeriodEnum, mapping_good) { } /*****************************************************************************/ -TEST_F(SettingsFixture, alarm_count) { +TEST_F(ConfigurationFixture, alarm_count) { auto& v = cm->get_alarms(); // Alarm 5 has an unknown peridicity string "Manchmal" // Alarm 6 has an invalid Timestamp string "25:34" @@ -398,7 +398,7 @@ TEST_F(SettingsFixture, alarm_count) { } /*****************************************************************************/ -TEST_F(SettingsFixture, alarm_id) { +TEST_F(ConfigurationFixture, alarm_id) { auto& v = cm->get_alarms(); auto res = std::find_if( v.begin(), v.end(), [&](const std::shared_ptr& item) { @@ -410,7 +410,7 @@ TEST_F(SettingsFixture, alarm_id) { } /*****************************************************************************/ -TEST_F(SettingsFixture, podcastid) { +TEST_F(ConfigurationFixture, podcastid) { auto& v = cm->get_podcast_sources(); auto res = std::find_if( v.begin(), v.end(), [&](const std::shared_ptr& item) { @@ -424,7 +424,7 @@ TEST_F(SettingsFixture, podcastid) { } /*****************************************************************************/ -TEST_F(SettingsFixture, streamsourceid) { +TEST_F(ConfigurationFixture, streamsourceid) { auto& v = cm->get_stations(); auto res = std::find_if( v.begin(), v.end(), [&](const std::shared_ptr& item) { @@ -436,7 +436,7 @@ TEST_F(SettingsFixture, streamsourceid) { } /*****************************************************************************/ -TEST_F(SettingsFixture, alarm_daily) { +TEST_F(ConfigurationFixture, alarm_daily) { auto& v = cm->get_alarms(); ASSERT_EQ(v[0]->get_period(), Alarm::Daily); ASSERT_EQ(v[0]->get_time(), QTime::fromString("10:00", "hh:mm")); @@ -444,7 +444,7 @@ TEST_F(SettingsFixture, alarm_daily) { } /*****************************************************************************/ -TEST_F(SettingsFixture, alarm_workdays) { +TEST_F(ConfigurationFixture, alarm_workdays) { auto& v = cm->get_alarms(); ASSERT_EQ(v[1]->get_period(), Alarm::Workdays); @@ -453,7 +453,7 @@ TEST_F(SettingsFixture, alarm_workdays) { } /*****************************************************************************/ -TEST_F(SettingsFixture, alarm_weekends) { +TEST_F(ConfigurationFixture, alarm_weekends) { auto& v = cm->get_alarms(); ASSERT_EQ(v[2]->get_period(), Alarm::Weekend); ASSERT_EQ(v[2]->get_time(), QTime::fromString("09:00", "hh:mm")); @@ -461,7 +461,7 @@ TEST_F(SettingsFixture, alarm_weekends) { } /*****************************************************************************/ -TEST_F(SettingsFixture, alarm_once) { +TEST_F(ConfigurationFixture, alarm_once) { auto& v = cm->get_alarms(); ASSERT_EQ(v[3]->get_period(), Alarm::Once); ASSERT_EQ(v[3]->get_time(), QTime::fromString("13:00", "hh:mm")); @@ -469,7 +469,7 @@ TEST_F(SettingsFixture, alarm_once) { } /*****************************************************************************/ -TEST_F(SettingsFixture, emitConfigChanged) { +TEST_F(ConfigurationFixture, emitConfigChanged) { auto number_of_alarms = cm->get_alarms().size(); QSignalSpy spy(cm.get(), SIGNAL(configuration_changed())); ASSERT_TRUE(spy.isValid()); @@ -479,40 +479,40 @@ TEST_F(SettingsFixture, emitConfigChanged) { } /*****************************************************************************/ -TEST(ConfigManager, DefaultForNotWritableCache) { +TEST(Configuration, DefaultForNotWritableCache) { QDir default_cache_dir(DEFAULT_CACHE_DIR_PATH); default_cache_dir.removeRecursively(); ASSERT_FALSE(default_cache_dir.exists()); - ConfigurationManager cm(DEFAULT_CONFIG_FILE_PATH, QString("/dev/")); + Configuration cm(DEFAULT_CONFIG_FILE_PATH, QString("/dev/")); ASSERT_TRUE(default_cache_dir.exists()); } /*****************************************************************************/ -TEST(ConfigManager, DefaultForNotWritableConfig) { +TEST(Configuration, DefaultForNotWritableConfig) { QFile default_conf_file(DEFAULT_CONFIG_FILE_PATH); // Delete it should it exist.. default_conf_file.remove(); - ConfigurationManager cm( + Configuration cm( QString("/dev/foobar.json"), DEFAULT_CACHE_DIR_PATH); ASSERT_TRUE(default_conf_file.exists()); } /*****************************************************************************/ -TEST_F(SettingsFixture, GetweatherConfigApiToken) { +TEST_F(ConfigurationFixture, GetweatherConfigApiToken) { auto cfg = cm->get_weather_config(); ASSERT_EQ(cfg.get_api_token(), QString("d77bd1ca2fd77ce4e1cdcdd5f8b7206c")); } /*****************************************************************************/ -TEST_F(SettingsFixture, GetweatherConfigCityId) { +TEST_F(ConfigurationFixture, GetweatherConfigCityId) { auto cfg = cm->get_weather_config(); ASSERT_EQ(cfg.get_location_id(), QString("3452925")); } /*****************************************************************************/ -TEST_F(SettingsFixture, changeSleepTimeoutMinutes) { +TEST_F(ConfigurationFixture, changeSleepTimeoutMinutes) { auto new_to = std::chrono::minutes(5); cm->set_sleep_timeout(new_to); ASSERT_EQ(cm->get_sleep_timeout(), new_to); From 40cc3b9777ca3178cecfce0c72ec188c194db494 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 17:18:59 +0100 Subject: [PATCH 16/26] Refactor ConfigurationManager->Configuration 2/2 Signed-off-by: Thomas Ruschival --- include/alarmdispatcher.hpp | 2 +- include/brightnesscontrol.hpp | 2 +- include/sleeptimer.hpp | 2 +- include/weather.hpp | 2 +- include/wifi_control.hpp | 4 +- libsrc/alarmdispatcher.cpp | 4 +- libsrc/brightnesscontrol.cpp | 20 ++-- libsrc/sleeptimer.cpp | 14 +-- libsrc/weather.cpp | 10 +- libsrc/wifi_control.cpp | 6 +- qtgui/alarmlistmodel.cpp | 20 ++-- qtgui/alarmlistmodel.hpp | 2 +- qtgui/iradiolistmodel.cpp | 12 +-- qtgui/iradiolistmodel.hpp | 2 +- qtgui/main.cpp | 32 +++--- qtgui/podcastsourcemodel.cpp | 16 +-- qtgui/podcastsourcemodel.hpp | 2 +- test/{cm_mock.hpp => config_mock.hpp} | 0 test/restserver.cpp | 6 +- test/test_alarmdispatcher.cpp | 20 ++-- test/test_brightness.cpp | 82 +++++++-------- test/test_configuration.cpp | 144 +++++++++++++------------- test/test_restapihandler.cpp | 2 +- test/test_sleeptimer.cpp | 8 +- test/test_weather.cpp | 30 +++--- test/test_wifi_control.cpp | 8 +- 26 files changed, 226 insertions(+), 226 deletions(-) rename test/{cm_mock.hpp => config_mock.hpp} (100%) diff --git a/include/alarmdispatcher.hpp b/include/alarmdispatcher.hpp index 60fd26a..46ed834 100644 --- a/include/alarmdispatcher.hpp +++ b/include/alarmdispatcher.hpp @@ -79,7 +79,7 @@ public slots: /** * Central configuration and data handler */ - IAlarmStore& cm; + IAlarmStore& config; /** * Next alarm to be dispatched, keep a copy diff --git a/include/brightnesscontrol.hpp b/include/brightnesscontrol.hpp index 1928d6c..9651528 100644 --- a/include/brightnesscontrol.hpp +++ b/include/brightnesscontrol.hpp @@ -156,7 +156,7 @@ public slots: /** * configuration and data handler */ - IBrightnessStore& cm; + IBrightnessStore& config; /** * Hardware controller diff --git a/include/sleeptimer.hpp b/include/sleeptimer.hpp index 395380b..1d3fa8e 100644 --- a/include/sleeptimer.hpp +++ b/include/sleeptimer.hpp @@ -142,7 +142,7 @@ public slots: /** * Central configuration and data handler */ - ITimeOutStore& cm; + ITimeOutStore& config; /** * Timer to trigger standby diff --git a/include/weather.hpp b/include/weather.hpp index a100865..d0edeca 100644 --- a/include/weather.hpp +++ b/include/weather.hpp @@ -261,7 +261,7 @@ public slots: /** * Central configuration and data handler */ - const IWeatherConfigStore& cm; + const IWeatherConfigStore& config; /** * Interval in ms for auto refresh of content diff --git a/include/wifi_control.hpp b/include/wifi_control.hpp index 787eed5..b303f93 100644 --- a/include/wifi_control.hpp +++ b/include/wifi_control.hpp @@ -66,10 +66,10 @@ class WifiControl : public QObject { /** * Singleton Creator method - * @param cm configuration manager (to get WIFI interface) + * @param config configuration manager (to get WIFI interface) * @return */ - static WifiControl* get_instance(Configuration* cm = nullptr); + static WifiControl* get_instance(Configuration* config = nullptr); /** * Trigger Push Button Configuration (PBC) authentication diff --git a/libsrc/alarmdispatcher.cpp b/libsrc/alarmdispatcher.cpp index 70e67d9..05bfe61 100644 --- a/libsrc/alarmdispatcher.cpp +++ b/libsrc/alarmdispatcher.cpp @@ -22,7 +22,7 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.AlarmDispatcher"); AlarmDispatcher::AlarmDispatcher(IAlarmStore& store, QObject* parent) : QObject(parent) - , cm(store) { + , config(store) { qCDebug(CLASS_LC) << Q_FUNC_INFO; timer.setSingleShot(true); connect(&timer, &QTimer::timeout, this, &AlarmDispatcher::trigger); @@ -72,7 +72,7 @@ std::chrono::milliseconds AlarmDispatcher::get_remaining_time() const { /*****************************************************************************/ std::shared_ptr AlarmDispatcher::get_upcoming_alarm() { // Sort a copy of the alarms not to mess up Alarm list in QML - auto v = std::vector(cm.get_alarms()); + auto v = std::vector(config.get_alarms()); if (v.empty()) { return nullptr; } diff --git a/libsrc/brightnesscontrol.cpp b/libsrc/brightnesscontrol.cpp index a80a2b4..5f8889b 100644 --- a/libsrc/brightnesscontrol.cpp +++ b/libsrc/brightnesscontrol.cpp @@ -24,7 +24,7 @@ static const double LOG_100 = 4.6052; /*****************************************************************************/ BrightnessControl::BrightnessControl( IBrightnessStore& store, Hal::IHardware* hw) - : cm(store) + : config(store) , hwctrl(hw) { qCDebug(CLASS_LC) << Q_FUNC_INFO; } @@ -34,10 +34,10 @@ void BrightnessControl::update_backlight(double bl_brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO << bl_brightness; if (standby) { current_brightness = - lin2log(cm.get_standby_brightness() + bl_brightness); + lin2log(config.get_standby_brightness() + bl_brightness); } else { current_brightness = - lin2log(cm.get_active_brightness() + bl_brightness); + lin2log(config.get_active_brightness() + bl_brightness); } hwctrl->set_backlight(current_brightness); emit brightness_changed(current_brightness); @@ -126,7 +126,7 @@ void BrightnessControl::als_value_changed(Hal::AlsValue brightness) { /*****************************************************************************/ void BrightnessControl::set_active_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - cm.set_active_brightness(brightness); + config.set_active_brightness(brightness); emit active_brightness_changed(brightness); if (!adaptive_mode()) { update_backlight(); @@ -136,7 +136,7 @@ void BrightnessControl::set_active_brightness(int brightness) { /*****************************************************************************/ void BrightnessControl::set_standby_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - cm.set_standby_brightness(brightness); + config.set_standby_brightness(brightness); emit standby_brightness_changed(brightness); if (!adaptive_mode()) { update_backlight(); @@ -146,13 +146,13 @@ void BrightnessControl::set_standby_brightness(int brightness) { /*****************************************************************************/ int BrightnessControl::get_active_brightness() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return cm.get_active_brightness(); + return config.get_active_brightness(); } /*****************************************************************************/ int BrightnessControl::get_standby_brightness() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return cm.get_standby_brightness(); + return config.get_standby_brightness(); } /*****************************************************************************/ @@ -165,8 +165,8 @@ int BrightnessControl::get_brightness() const { void BrightnessControl::set_adaptive_mode(bool ena) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - if (ena != cm.backlight_control_enabled()) { - cm.enable_backlight_control(ena); + if (ena != config.backlight_control_enabled()) { + config.enable_backlight_control(ena); emit adaptive_mode_changed(ena); } @@ -192,7 +192,7 @@ void BrightnessControl::active(bool active) { /*****************************************************************************/ bool BrightnessControl::adaptive_mode() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return cm.backlight_control_enabled() && hwctrl->als_sensor_available(); + return config.backlight_control_enabled() && hwctrl->als_sensor_available(); } /*****************************************************************************/ diff --git a/libsrc/sleeptimer.cpp b/libsrc/sleeptimer.cpp index f407c26..8117aee 100644 --- a/libsrc/sleeptimer.cpp +++ b/libsrc/sleeptimer.cpp @@ -20,13 +20,13 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.SleepTimer"); /*****************************************************************************/ SleepTimer::SleepTimer(ITimeOutStore& store, QObject* parent) : QObject(parent) - , cm(store) + , config(store) , evt_timer_id(0) - , remaining_time(cm.get_sleep_timeout()) + , remaining_time(config.get_sleep_timeout()) , activity(SleepTimer::Idle) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - sleep_timer.setInterval(cm.get_sleep_timeout()); + sleep_timer.setInterval(config.get_sleep_timeout()); sleep_timer.setSingleShot(true); connect(&sleep_timer, &QTimer::timeout, this, [=]() { @@ -45,7 +45,7 @@ void SleepTimer::playback_state_changed(QMediaPlayer::State state) { /* Check if alarm was dispatched do not set normal sleep_timeout */ if (activity != SleepTimer::Alarm) { qCDebug(CLASS_LC) << " restarting timer"; - sleep_timer.setInterval(cm.get_sleep_timeout()); + sleep_timer.setInterval(config.get_sleep_timeout()); sleep_timer.start(); emit remaining_time_changed(get_remaining_time()); } @@ -99,13 +99,13 @@ int SleepTimer::get_remaining_time() { /*****************************************************************************/ std::chrono::minutes SleepTimer::get_sleep_timeout() const { - return cm.get_sleep_timeout(); + return config.get_sleep_timeout(); } /*****************************************************************************/ void SleepTimer::set_sleep_timeout(std::chrono::minutes timeout) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - cm.set_sleep_timeout(timeout); + config.set_sleep_timeout(timeout); // also update running timeouts timeout_changed(timeout); emit sleep_timeout_changed(timeout); @@ -121,7 +121,7 @@ void SleepTimer::set_sleep_timeout(int timeout) { /*****************************************************************************/ int SleepTimer::get_sleep_timeout_minutes_count() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return cm.get_sleep_timeout().count(); + return config.get_sleep_timeout().count(); } /*****************************************************************************/ diff --git a/libsrc/weather.cpp b/libsrc/weather.cpp index af7df3e..37d8fd1 100644 --- a/libsrc/weather.cpp +++ b/libsrc/weather.cpp @@ -22,7 +22,7 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.Weather"); /*****************************************************************************/ Weather::Weather(const IWeatherConfigStore& store, QObject* parent) : QObject(parent) - , cm(store) { + , config(store) { qCDebug(CLASS_LC) << Q_FUNC_INFO; // timer starts refresh, refresh calls downloader @@ -36,9 +36,9 @@ Weather::Weather(const IWeatherConfigStore& store, QObject* parent) timer.setInterval(duration_cast(update_interval)); timer.setSingleShot(false); timer.start(); - weather_downloader.doDownload(create_weather_url(cm.get_weather_config())); + weather_downloader.doDownload(create_weather_url(config.get_weather_config())); forecast_downloader.doDownload( - create_forecast_url(cm.get_weather_config())); + create_forecast_url(config.get_weather_config())); } /*****************************************************************************/ @@ -59,9 +59,9 @@ std::chrono::seconds Weather::get_update_interval() const { void Weather::refresh() { qCDebug(CLASS_LC) << Q_FUNC_INFO; /* restart downloads */ - weather_downloader.doDownload(create_weather_url(cm.get_weather_config())); + weather_downloader.doDownload(create_weather_url(config.get_weather_config())); forecast_downloader.doDownload( - create_forecast_url(cm.get_weather_config())); + create_forecast_url(config.get_weather_config())); timer.start(); } diff --git a/libsrc/wifi_control.cpp b/libsrc/wifi_control.cpp index 2adec16..07a33e2 100644 --- a/libsrc/wifi_control.cpp +++ b/libsrc/wifi_control.cpp @@ -19,12 +19,12 @@ using namespace DigitalRooster; static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.WifiControl"); /****************************************************************************/ -WifiControl* WifiControl::get_instance(Configuration* cm) { +WifiControl* WifiControl::get_instance(Configuration* config) { qCDebug(CLASS_LC) << Q_FUNC_INFO; static WifiControl instance; // only if not initialized and we have a control_manager - if (!instance.ctrl && cm) { - instance.wpa_supplicant_sock_path = cm->get_wpa_socket_name(); + if (!instance.ctrl && config) { + instance.wpa_supplicant_sock_path = config->get_wpa_socket_name(); try { instance.connect_wpa_control_socket(); instance.ctrl_notifier = std::make_unique( diff --git a/qtgui/alarmlistmodel.cpp b/qtgui/alarmlistmodel.cpp index 751f65f..04f3f07 100644 --- a/qtgui/alarmlistmodel.cpp +++ b/qtgui/alarmlistmodel.cpp @@ -20,12 +20,12 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.AlarmListModel"); /******************************************************************************/ AlarmListModel::AlarmListModel(IAlarmStore& store, QObject* parent) : QAbstractListModel(parent) - , cm(store) { + , config(store) { } /******************************************************************************/ bool AlarmListModel::check_selection(int row) const { - auto sz = cm.get_alarms().size(); + auto sz = config.get_alarms().size(); /* static cast only if index >= 0 and thus can be converted */ if (row < 0 || static_cast(row) >= sz) { qCCritical(CLASS_LC) << Q_FUNC_INFO << "invalid row " << row; @@ -48,7 +48,7 @@ QHash AlarmListModel::roleNames() const { /******************************************************************************/ int AlarmListModel::rowCount(const QModelIndex& /*parent */) const { - auto sz = cm.get_alarms().size(); + auto sz = config.get_alarms().size(); if (sz <= 0) { qCInfo(CLASS_LC) << "no alarms configured "; } @@ -61,7 +61,7 @@ QVariant AlarmListModel::data(const QModelIndex& index, int role) const { return QVariant(); } - auto alarm = cm.get_alarms().at(index.row()); + auto alarm = config.get_alarms().at(index.row()); switch (role) { case PeriodicityRole: @@ -83,7 +83,7 @@ void AlarmListModel::set_enabled(int row, bool enabled) { if (!check_selection(row)) { return; } - cm.get_alarms().at(row)->enable(enabled); + config.get_alarms().at(row)->enable(enabled); emit dataChanged(index(row, 0), index(row, 0), {EnabledRole}); } @@ -94,7 +94,7 @@ DigitalRooster::Alarm* AlarmListModel::get_alarm(int row) { qCCritical(CLASS_LC) << Q_FUNC_INFO << "invalid row!"; return nullptr; } - auto ret = cm.get_alarms().at(row).get(); + auto ret = config.get_alarms().at(row).get(); QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership); return ret; @@ -114,7 +114,7 @@ bool AlarmListModel::removeRows( int row, int count, const QModelIndex& /*parent */) { qCWarning(CLASS_LC) << Q_FUNC_INFO << "is not implemented!"; // TODO: - // cm->delete_alarm(id); + // config->delete_alarm(id); return true; } @@ -123,9 +123,9 @@ int AlarmListModel::delete_alarm(qint64 row) { qCDebug(CLASS_LC) << Q_FUNC_INFO << row; beginRemoveRows(QModelIndex(), row, row); try { - auto alarm = cm.get_alarms().at(row); + auto alarm = config.get_alarms().at(row); if (alarm) { - cm.delete_alarm(alarm->get_id()); + config.delete_alarm(alarm->get_id()); } } catch (std::out_of_range&) { qCWarning(CLASS_LC) << Q_FUNC_INFO << " Alarm not found! "; @@ -147,7 +147,7 @@ DigitalRooster::Alarm* AlarmListModel::create_alarm() { beginInsertRows(QModelIndex(), rowCount(), rowCount()); QQmlEngine::setObjectOwnership(new_alarm.get(), QQmlEngine::CppOwnership); /* new_alarm is not only on the stack. Ownership shared with IAlarmStore*/ - cm.add_alarm(new_alarm); + config.add_alarm(new_alarm); endInsertRows(); return new_alarm.get(); } diff --git a/qtgui/alarmlistmodel.hpp b/qtgui/alarmlistmodel.hpp index fc8594b..f982a90 100644 --- a/qtgui/alarmlistmodel.hpp +++ b/qtgui/alarmlistmodel.hpp @@ -74,7 +74,7 @@ class AlarmListModel : public QAbstractListModel { QHash roleNames() const; private: - IAlarmStore& cm; + IAlarmStore& config; /** * Check if valid row was selected diff --git a/qtgui/iradiolistmodel.cpp b/qtgui/iradiolistmodel.cpp index f1ae25b..38c7af8 100644 --- a/qtgui/iradiolistmodel.cpp +++ b/qtgui/iradiolistmodel.cpp @@ -21,7 +21,7 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.IRadioListModel"); IRadioListModel::IRadioListModel( IStationStore& store, MediaPlayer& mp, QObject* parent) : QAbstractListModel(parent) - , cm(store) + , config(store) , mpp(mp) { } @@ -35,26 +35,26 @@ QHash IRadioListModel::roleNames() const { /*****************************************************************************/ int IRadioListModel::rowCount(const QModelIndex& /*parent */) const { - auto sz = cm.get_stations().size(); + auto sz = config.get_stations().size(); return sz; } /*****************************************************************************/ QUrl IRadioListModel::get_station_url(int index) { - auto pi = cm.get_stations().at(index); + auto pi = config.get_stations().at(index); return pi->get_url(); } /*****************************************************************************/ void IRadioListModel::send_to_player(int index) { - auto station = cm.get_stations().at(index); + auto station = config.get_stations().at(index); mpp.set_media(station); mpp.play(); } /*****************************************************************************/ QVariant IRadioListModel::data(const QModelIndex& index, int role) const { - auto sz = cm.get_stations().size(); + auto sz = config.get_stations().size(); /* static cast only if index.row() is >= 0 and thus can be converted */ if (index.row() < 0 || static_cast(index.row()) >= sz) { @@ -62,7 +62,7 @@ QVariant IRadioListModel::data(const QModelIndex& index, int role) const { return QVariant(); } - auto station = cm.get_stations().at(index.row()); + auto station = config.get_stations().at(index.row()); switch (role) { case StationNameRole: diff --git a/qtgui/iradiolistmodel.hpp b/qtgui/iradiolistmodel.hpp index 93109eb..56975b1 100644 --- a/qtgui/iradiolistmodel.hpp +++ b/qtgui/iradiolistmodel.hpp @@ -54,7 +54,7 @@ class IRadioListModel : public QAbstractListModel { QHash roleNames() const; private: - IStationStore& cm; + IStationStore& config; MediaPlayer& mpp; }; } // namespace DigitalRooster diff --git a/qtgui/main.cpp b/qtgui/main.cpp index da0482b..73ec624 100644 --- a/qtgui/main.cpp +++ b/qtgui/main.cpp @@ -134,31 +134,31 @@ int main(int argc, char* argv[]) { /* * Read configuration */ - Configuration cm( + Configuration config( cmdline.value(CMD_ARG_CONFIG_FILE), cmdline.value(CMD_ARG_CACHE_DIR)); - cm.update_configuration(); + config.update_configuration(); // Initialize Player MediaPlayerProxy playerproxy; - playerproxy.set_volume(cm.get_volume()); + playerproxy.set_volume(config.get_volume()); - AlarmDispatcher alarmdispatcher(cm); - QObject::connect(&cm, &Configuration::alarms_changed, + AlarmDispatcher alarmdispatcher(config); + QObject::connect(&config, &Configuration::alarms_changed, &alarmdispatcher, &AlarmDispatcher::check_alarms); AlarmMonitor alarmmonitor(playerproxy, std::chrono::seconds(20)); QObject::connect(&alarmdispatcher, &AlarmDispatcher::alarm_triggered, &alarmmonitor, &AlarmMonitor::alarm_triggered); - PodcastSourceModel psmodel(cm, playerproxy); - AlarmListModel alarmlistmodel(cm); - IRadioListModel iradiolistmodel(cm, playerproxy); + PodcastSourceModel psmodel(config, playerproxy); + AlarmListModel alarmlistmodel(config); + IRadioListModel iradiolistmodel(config, playerproxy); WifiListModel wifilistmodel; - Weather weather(cm); - SleepTimer sleeptimer(cm); + Weather weather(config); + SleepTimer sleeptimer(config); /* Brightness control sends pwm update requests to Hardware */ - BrightnessControl brightness(cm, &hwctrl); + BrightnessControl brightness(config, &hwctrl); QObject::connect(&brightness, &BrightnessControl::brightness_changed, &hwctrl, &Hal::IHardware::set_backlight); QObject::connect(&hwctrl, &Hal::IHardware::als_value_changed, &brightness, @@ -211,17 +211,17 @@ int main(int argc, char* argv[]) { /* Standby deactivates Volume button events */ QObject::connect(&power, &PowerControl::active, &volbtn, &VolumeButton::monitor_rotary_button); - QObject::connect(&playerproxy, &MediaPlayer::volume_changed, &cm, + QObject::connect(&playerproxy, &MediaPlayer::volume_changed, &config, &Configuration::set_volume); /* Network / Wifi Settings */ - NetworkInfo netinfo(cm.get_net_dev_name()); - WifiControl* wifictrl = WifiControl::get_instance(&cm); + NetworkInfo netinfo(config.get_net_dev_name()); + WifiControl* wifictrl = WifiControl::get_instance(&config); QObject::connect(wifictrl, &WifiControl::networks_found, &wifilistmodel, &WifiListModel::update_scan_results); #ifdef REST_API - RestApi rest(cm, cm, cm, cm, cm); + RestApi rest(config, config, config, config, config); #endif /* * QML Setup dynamically createable types @@ -252,7 +252,7 @@ int main(int argc, char* argv[]) { ctxt->setContextProperty("alarmlistmodel", &alarmlistmodel); ctxt->setContextProperty("iradiolistmodel", &iradiolistmodel); ctxt->setContextProperty("weather", &weather); - ctxt->setContextProperty("config", &cm); + ctxt->setContextProperty("config", &config); ctxt->setContextProperty("alarmdispatcher", &alarmdispatcher); ctxt->setContextProperty("powerControl", &power); ctxt->setContextProperty("brightnessControl", &brightness); diff --git a/qtgui/podcastsourcemodel.cpp b/qtgui/podcastsourcemodel.cpp index 5976fcf..a58b5c5 100644 --- a/qtgui/podcastsourcemodel.cpp +++ b/qtgui/podcastsourcemodel.cpp @@ -23,10 +23,10 @@ static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.PodcastSourceModel"); PodcastSourceModel::PodcastSourceModel( IPodcastStore& store, MediaPlayer& mp, QObject* parent) : QAbstractListModel(parent) - , cm(store) + , config(store) , mpp(mp) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - auto v = cm.get_podcast_sources(); + auto v = config.get_podcast_sources(); for (const auto& ps : v) { connect(ps.get(), &PodcastSource::titleChanged, this, &PodcastSourceModel::newDataAvailable); @@ -48,7 +48,7 @@ QHash PodcastSourceModel::roleNames() const { int PodcastSourceModel::rowCount(const QModelIndex& /*parent */) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; - return cm.get_podcast_sources().size(); + return config.get_podcast_sources().size(); } /*****************************************************************************/ @@ -61,7 +61,7 @@ void PodcastSourceModel::newDataAvailable() { PodcastEpisodeModel* PodcastSourceModel::get_episodes(int index) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - auto v = cm.get_podcast_sources(); + auto v = config.get_podcast_sources(); /* static cast only if index >= 0 and thus can be converted */ if (index < 0 || static_cast(index) >= v.size()) { qCCritical(CLASS_LC) << Q_FUNC_INFO << "index out of range " << index; @@ -77,7 +77,7 @@ PodcastEpisodeModel* PodcastSourceModel::get_episodes(int index) { /*****************************************************************************/ QVariant PodcastSourceModel::data(const QModelIndex& index, int role) const { qCDebug(CLASS_LC) << Q_FUNC_INFO; - auto v = cm.get_podcast_sources(); + auto v = config.get_podcast_sources(); /* static cast only if index.row() is >= 0 and thus can be converted */ if (index.row() < 0 || static_cast(index.row()) >= v.size()) { @@ -108,7 +108,7 @@ QVariant PodcastSourceModel::data(const QModelIndex& index, int role) const { void PodcastSourceModel::refresh(int index) { qCDebug(CLASS_LC) << Q_FUNC_INFO; try { - cm.get_podcast_source_by_index(index)->refresh(); + config.get_podcast_source_by_index(index)->refresh(); } catch (std::out_of_range&) { qCCritical(CLASS_LC) << "index out of range " << index; } @@ -118,7 +118,7 @@ void PodcastSourceModel::refresh(int index) { void PodcastSourceModel::purge(int index) { qCDebug(CLASS_LC) << Q_FUNC_INFO; try { - cm.get_podcast_source_by_index(index)->purge(); + config.get_podcast_source_by_index(index)->purge(); } catch (std::out_of_range&) { qCCritical(CLASS_LC) << "index out of range " << index; } @@ -129,7 +129,7 @@ void PodcastSourceModel::remove(int index) { qCDebug(CLASS_LC) << Q_FUNC_INFO; beginRemoveRows(QModelIndex(), index, index); try { - cm.remove_podcast_source_by_index(index); + config.remove_podcast_source_by_index(index); } catch (std::out_of_range&) { qCCritical(CLASS_LC) << "index out of range " << index; } diff --git a/qtgui/podcastsourcemodel.hpp b/qtgui/podcastsourcemodel.hpp index d502d8b..963f9af 100644 --- a/qtgui/podcastsourcemodel.hpp +++ b/qtgui/podcastsourcemodel.hpp @@ -62,7 +62,7 @@ public slots: QHash roleNames() const; private: - IPodcastStore& cm; + IPodcastStore& config; MediaPlayer& mpp; }; diff --git a/test/cm_mock.hpp b/test/config_mock.hpp similarity index 100% rename from test/cm_mock.hpp rename to test/config_mock.hpp diff --git a/test/restserver.cpp b/test/restserver.cpp index 4c6ae5e..3570c4e 100644 --- a/test/restserver.cpp +++ b/test/restserver.cpp @@ -36,10 +36,10 @@ int main(int argc, char** argv) { setup_tests(); qDebug() << argv[0]; - Configuration cm( + Configuration config( cmdline.value(CMD_ARG_CONFIG_FILE), cmdline.value(CMD_ARG_CACHE_DIR)); - RestApi restserver(cm, cm, cm, cm, cm); - cm.update_configuration(); + RestApi restserver(config, config, config, config, config); + config.update_configuration(); /* * coverage data is only generated if program is not killed forcefully diff --git a/test/test_alarmdispatcher.cpp b/test/test_alarmdispatcher.cpp index 93db983..0ac3de6 100644 --- a/test/test_alarmdispatcher.cpp +++ b/test/test_alarmdispatcher.cpp @@ -16,7 +16,7 @@ #include "alarm.hpp" #include "alarmdispatcher.hpp" -#include "cm_mock.hpp" +#include "config_mock.hpp" #include "mock_clock.hpp" using namespace DigitalRooster; @@ -30,16 +30,16 @@ class AlarmDispatcherFixture : public ::testing::Test { public: AlarmDispatcherFixture() : mc(new NiceMock) { - ON_CALL(cm, get_alarms()).WillByDefault(ReturnRef(cm.alarms)); + ON_CALL(config, get_alarms()).WillByDefault(ReturnRef(config.alarms)); alm1 = std::make_shared( QUrl("http://st01.dlf.de/dlf/01/104/ogg/stream.ogg"), QTime::fromString("08:30:00", "hh:mm:ss"), Alarm::Daily); - cm.alarms.push_back(alm1); + config.alarms.push_back(alm1); // need to make a pointer because AlarmDispatcher inherits QObject which // is not copyable - dut = std::make_unique(cm); + dut = std::make_unique(config); // QSignalSpy and spy->wait needed for Qt Eventloop processing, // otherwise timers are not started correctly spy = std::make_unique( @@ -59,7 +59,7 @@ class AlarmDispatcherFixture : public ::testing::Test { protected: std::shared_ptr> mc; - NiceMock cm; + NiceMock config; std::shared_ptr alm1; std::unique_ptr dut; std::unique_ptr spy; @@ -67,7 +67,7 @@ class AlarmDispatcherFixture : public ::testing::Test { /*****************************************************************************/ TEST_F(AlarmDispatcherFixture, CheckFixture) { - ASSERT_EQ(cm.get_alarms().size(), 1); + ASSERT_EQ(config.get_alarms().size(), 1); ASSERT_TRUE(spy->isValid()); } @@ -76,8 +76,8 @@ TEST_F(AlarmDispatcherFixture, InfoEmptyAlarms) { ON_CALL(*(mc.get()), get_time()) .WillByDefault( Return(QDateTime::fromString("2020-11-22T19:00:00", Qt::ISODate))); - cm.alarms.clear(); - ASSERT_EQ(cm.get_alarms().size(), 0); + config.alarms.clear(); + ASSERT_EQ(config.get_alarms().size(), 0); dut->check_alarms(); auto result = dut->get_upcoming_alarm(); @@ -109,12 +109,12 @@ TEST_F(AlarmDispatcherFixture, SortAlarms) { QUrl("http://st01.dlf.de/dlf/01/104/ogg/stream.ogg"), QTime::fromString("08:00:00", "hh:mm:ss"), Alarm::Daily); alm2->enable(false); - cm.alarms.push_back(alm2); + config.alarms.push_back(alm2); auto alm3 = std::make_shared( QUrl("http://st01.dlf.de/dlf/01/104/ogg/stream.ogg"), QTime::fromString("08:29:40", "hh:mm:ss"), Alarm::Daily); - cm.alarms.push_back(alm3); + config.alarms.push_back(alm3); EXPECT_CALL(*(mc.get()), get_time()) .Times(AnyNumber()) diff --git a/test/test_brightness.cpp b/test/test_brightness.cpp index 6a4de44..1c84e1e 100644 --- a/test/test_brightness.cpp +++ b/test/test_brightness.cpp @@ -9,7 +9,7 @@ #include "IHardware.hpp" #include "brightnesscontrol.hpp" -#include "cm_mock.hpp" /* mock configuration manager */ +#include "config_mock.hpp" /* mock configuration manager */ using namespace DigitalRooster; using namespace ::testing; @@ -31,38 +31,38 @@ class BrightnessFixture : public ::testing::Test { BrightnessFixture(){}; protected: - CmMock cm; + CmMock config; HardwareMock hwctrl; }; /*****************************************************************************/ TEST_F(BrightnessFixture, HwProxyGetSensor) { EXPECT_CALL(hwctrl, als_sensor_available()).Times(1).WillOnce(Return(true)); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); EXPECT_TRUE(dut.has_als_sensor()); } /*****************************************************************************/ TEST_F(BrightnessFixture, AdaptiveModeEnabledNoSensor) { - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(1) .WillOnce(Return(true)); EXPECT_CALL(hwctrl, als_sensor_available()) .Times(1) .WillOnce(Return(false)); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); EXPECT_FALSE(dut.adaptive_mode()); } /*****************************************************************************/ TEST_F(BrightnessFixture, SetAdaptiveModeHasSensor) { // standby brightness is read in set_adaptive_mode - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(1) .WillRepeatedly(Return(20)); - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(3) .WillOnce(Return(false)) .WillOnce(Return(true)) @@ -76,7 +76,7 @@ TEST_F(BrightnessFixture, SetAdaptiveModeHasSensor) { // When disabling we force setting backlight EXPECT_CALL(hwctrl, set_backlight(_)).Times(1); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.set_adaptive_mode(true); dut.set_adaptive_mode(false); dut.set_adaptive_mode(true); @@ -85,15 +85,15 @@ TEST_F(BrightnessFixture, SetAdaptiveModeHasSensor) { /*****************************************************************************/ TEST_F(BrightnessFixture, RestoreActiveManual) { // standby brightness is read in set_adaptive_mode - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(1) .WillRepeatedly(Return(20)); // Is read when switching to active - EXPECT_CALL(cm, get_active_brightness()) + EXPECT_CALL(config, get_active_brightness()) .Times(1) .WillRepeatedly(Return(42)); - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(2) .WillRepeatedly(Return(false)); @@ -103,7 +103,7 @@ TEST_F(BrightnessFixture, RestoreActiveManual) { // 42% Brighness maps logarithmically to 12% PWM setting EXPECT_CALL(hwctrl, set_backlight(12)).Times(1); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.set_adaptive_mode(false); dut.active(true); ASSERT_EQ(dut.get_brightness(), 12); @@ -112,17 +112,17 @@ TEST_F(BrightnessFixture, RestoreActiveManual) { /*****************************************************************************/ TEST_F(BrightnessFixture, RestoreStandbyManual) { // standby brightness is read in set_adaptive_mode and active() - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(2) .WillRepeatedly(Return(20)); - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(2) .WillRepeatedly(Return(false)); // 12% perceived brightness at 5% PWM EXPECT_CALL(hwctrl, set_backlight(5)).Times(2); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.set_adaptive_mode(false); dut.active(false); ASSERT_EQ(dut.get_brightness(), 5); @@ -131,7 +131,7 @@ TEST_F(BrightnessFixture, RestoreStandbyManual) { /*****************************************************************************/ TEST_F(BrightnessFixture, AutoControl) { /* Default behavior of various adaptive_mode() calls */ - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(AtLeast(1)) .WillRepeatedly(Return(true)); EXPECT_CALL(hwctrl, als_sensor_available()) @@ -139,11 +139,11 @@ TEST_F(BrightnessFixture, AutoControl) { .WillRepeatedly(Return(true)); // standby brightness is read in set_adaptive_mode - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(1) .WillRepeatedly(Return(20)); // Is read when switching to active - EXPECT_CALL(cm, get_active_brightness()) + EXPECT_CALL(config, get_active_brightness()) .Times(AtLeast(1)) .WillRepeatedly(Return(35)); @@ -151,7 +151,7 @@ TEST_F(BrightnessFixture, AutoControl) { // in adaptive mode dut.active(false) should not call hardware EXPECT_CALL(hwctrl, set_backlight(_)).Times(5); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.set_adaptive_mode(true); dut.active(true); @@ -177,7 +177,7 @@ TEST_F(BrightnessFixture, AutoControl) { /*****************************************************************************/ TEST_F(BrightnessFixture, AutoControlEmits) { /* Default behavior of various adaptive_mode() calls */ - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(AtLeast(1)) .WillRepeatedly(Return(true)); EXPECT_CALL(hwctrl, als_sensor_available()) @@ -185,13 +185,13 @@ TEST_F(BrightnessFixture, AutoControlEmits) { .WillRepeatedly(Return(true)); // standby brightness is read in set_adaptive_mode - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(1) .WillRepeatedly(Return(20)); EXPECT_CALL(hwctrl, set_backlight(_)).Times(1); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); QSignalSpy spy(&dut, SIGNAL(brightness_changed(int))); ASSERT_TRUE(spy.isValid()); @@ -203,19 +203,19 @@ TEST_F(BrightnessFixture, AutoControlEmits) { /*****************************************************************************/ TEST_F(BrightnessFixture, CmProxySetActiveBrightnessInStandby) { /* Operate in ManualMode */ - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(AtLeast(1)) .WillRepeatedly(Return(false)); // called in set_active_brighness and in active - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(2) .WillRepeatedly(Return(20)); - EXPECT_CALL(cm, set_active_brightness(12)).Times(AtLeast(1)); + EXPECT_CALL(config, set_active_brightness(12)).Times(AtLeast(1)); // switching active and set_active_brightness call hardware EXPECT_CALL(hwctrl, set_backlight(_)).Times(2); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.active(false); dut.set_active_brightness(12); } @@ -223,20 +223,20 @@ TEST_F(BrightnessFixture, CmProxySetActiveBrightnessInStandby) { /*****************************************************************************/ TEST_F(BrightnessFixture, CmProxySetStandbyBrightnessInStandby) { /* Operate in ManualMode */ - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(AtLeast(1)) .WillRepeatedly(Return(false)); // called in set_active_brighness and in active - EXPECT_CALL(cm, get_standby_brightness()) + EXPECT_CALL(config, get_standby_brightness()) .Times(2) .WillRepeatedly(Return(20)); - EXPECT_CALL(cm, set_standby_brightness(5)).Times(AtLeast(1)); + EXPECT_CALL(config, set_standby_brightness(5)).Times(AtLeast(1)); // switching active and set_active_brightness call hardware EXPECT_CALL(hwctrl, set_backlight(_)).Times(2); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.active(false); dut.set_standby_brightness(5); } @@ -244,19 +244,19 @@ TEST_F(BrightnessFixture, CmProxySetStandbyBrightnessInStandby) { /*****************************************************************************/ TEST_F(BrightnessFixture, CmProxySetActiveBrightnessActive) { /* Operate in ManualMode */ - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(AtLeast(1)) .WillRepeatedly(Return(false)); // Is read when switching to active - EXPECT_CALL(cm, get_active_brightness()) + EXPECT_CALL(config, get_active_brightness()) .Times(AtLeast(1)) .WillRepeatedly(Return(35)); - EXPECT_CALL(cm, set_active_brightness(12)).Times(AtLeast(1)); + EXPECT_CALL(config, set_active_brightness(12)).Times(AtLeast(1)); // switching active and set_active_brightness call hardware EXPECT_CALL(hwctrl, set_backlight(_)).Times(2); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.active(true); dut.set_active_brightness(12); } @@ -264,28 +264,28 @@ TEST_F(BrightnessFixture, CmProxySetActiveBrightnessActive) { /*****************************************************************************/ TEST_F(BrightnessFixture, CmProxySetStandbyBrightnessActive) { /* Operate in ManualMode */ - EXPECT_CALL(cm, backlight_control_enabled()) + EXPECT_CALL(config, backlight_control_enabled()) .Times(AtLeast(1)) .WillRepeatedly(Return(false)); // Is read when switching to active - EXPECT_CALL(cm, get_active_brightness()) + EXPECT_CALL(config, get_active_brightness()) .Times(AtLeast(1)) .WillRepeatedly(Return(35)); - EXPECT_CALL(cm, set_standby_brightness(5)).Times(AtLeast(1)); + EXPECT_CALL(config, set_standby_brightness(5)).Times(AtLeast(1)); // switching active and set_active_brightness call hardware EXPECT_CALL(hwctrl, set_backlight(_)).Times(2); - BrightnessControl dut(cm, &hwctrl); + BrightnessControl dut(config, &hwctrl); dut.active(true); dut.set_standby_brightness(5); } /*****************************************************************************/ TEST_F(BrightnessFixture, CmProxyGetBrightnessValues) { - EXPECT_CALL(cm, get_active_brightness()).Times(1).WillOnce(Return(35)); - EXPECT_CALL(cm, get_standby_brightness()).Times(1).WillOnce(Return(20)); - BrightnessControl dut(cm, &hwctrl); + EXPECT_CALL(config, get_active_brightness()).Times(1).WillOnce(Return(35)); + EXPECT_CALL(config, get_standby_brightness()).Times(1).WillOnce(Return(20)); + BrightnessControl dut(config, &hwctrl); EXPECT_EQ(dut.get_active_brightness(), 35); EXPECT_EQ(dut.get_standby_brightness(), 20); } diff --git a/test/test_configuration.cpp b/test/test_configuration.cpp index fe39774..05c9fe4 100644 --- a/test/test_configuration.cpp +++ b/test/test_configuration.cpp @@ -42,8 +42,8 @@ class ConfigurationFixture : public virtual ::testing::Test { tf.write(doc.toJson()); tf.close(); - cm = std::make_unique(filename, cache_dir); - cm->update_configuration(); + config = std::make_unique(filename, cache_dir); + config->update_configuration(); } void TearDown() { @@ -58,7 +58,7 @@ class ConfigurationFixture : public virtual ::testing::Test { QString filename; QString cache_dir; QJsonObject appconfig; - std::unique_ptr cm; + std::unique_ptr config; void add_internet_radio(QJsonObject& root) { QJsonArray radiosources; @@ -189,29 +189,29 @@ class ConfigurationFixture : public virtual ::testing::Test { /*****************************************************************************/ TEST_F(ConfigurationFixture, read_radio_streams_two_streams) { - auto& v = cm->get_stations(); + auto& v = config->get_stations(); ASSERT_EQ(2, v.size()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, addRadioStation_no_write) { - cm->add_radio_station( + config->add_radio_station( std::make_shared("foo", QUrl("http://bar.baz"))); - cm->add_radio_station( + config->add_radio_station( std::make_shared("ref", QUrl("http://gmx.net"))); - auto& v = cm->get_stations(); + auto& v = config->get_stations(); ASSERT_EQ(4, v.size()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, addRadioStation_write) { { - cm->add_radio_station( + config->add_radio_station( std::make_shared("foo", QUrl("http://bar.baz"))); - cm->add_radio_station( + config->add_radio_station( std::make_shared("ref", QUrl("http://gmx.net"))); /* should write file in destructor */ - cm->store_current_config(); + config->store_current_config(); } Configuration control(filename, TEST_FILE_PATH); control.update_configuration(); @@ -224,156 +224,156 @@ TEST_F(ConfigurationFixture, addRadioStation_write) { /*****************************************************************************/ TEST_F(ConfigurationFixture, add_podcast_source) { - QSignalSpy spy(cm.get(), SIGNAL(podcast_sources_changed())); + QSignalSpy spy(config.get(), SIGNAL(podcast_sources_changed())); ASSERT_TRUE(spy.isValid()); auto ps = std::make_shared( QUrl("https://alternativlos.org/alternativlos.rss")); - auto size_before = cm->get_podcast_sources().size(); - cm->add_podcast_source(ps); + auto size_before = config->get_podcast_sources().size(); + config->add_podcast_source(ps); ASSERT_EQ(spy.count(), 1); - ASSERT_EQ(cm->get_podcast_sources().size(), size_before + 1); + ASSERT_EQ(config->get_podcast_sources().size(), size_before + 1); } /*****************************************************************************/ TEST_F(ConfigurationFixture, get_podcast_source_throws) { EXPECT_THROW( - cm->get_podcast_source(QUuid::createUuid()), std::out_of_range); + config->get_podcast_source(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, get_podcast_source_ok) { - auto& v = cm->get_podcast_sources(); + auto& v = config->get_podcast_sources(); auto uid = v[0]->get_id(); - auto item = cm->get_podcast_source(uid); + auto item = config->get_podcast_source(uid); ASSERT_EQ(item, v[0].get()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, delete_podcast_source) { - auto& v = cm->get_podcast_sources(); + auto& v = config->get_podcast_sources(); auto size_before = v.size(); auto uid = v[0]->get_id(); - cm->delete_podcast_source(uid); - ASSERT_EQ(cm->get_podcast_sources().size(), size_before - 1); - EXPECT_THROW(cm->get_podcast_source(uid), std::out_of_range); + config->delete_podcast_source(uid); + ASSERT_EQ(config->get_podcast_sources().size(), size_before - 1); + EXPECT_THROW(config->get_podcast_source(uid), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, delete_podcast_throws) { EXPECT_THROW( - cm->delete_podcast_source(QUuid::createUuid()), std::out_of_range); + config->delete_podcast_source(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, add_radio_station) { - QSignalSpy spy(cm.get(), SIGNAL(stations_changed())); + QSignalSpy spy(config.get(), SIGNAL(stations_changed())); ASSERT_TRUE(spy.isValid()); auto radio = std::make_shared(); - auto size_before = cm->get_stations().size(); - cm->add_radio_station(radio); + auto size_before = config->get_stations().size(); + config->add_radio_station(radio); ASSERT_EQ(spy.count(), 1); - ASSERT_EQ(cm->get_stations().size(), size_before + 1); + ASSERT_EQ(config->get_stations().size(), size_before + 1); } /*****************************************************************************/ TEST_F(ConfigurationFixture, get_radio_station_throws) { - EXPECT_THROW(cm->get_station(QUuid::createUuid()), std::out_of_range); + EXPECT_THROW(config->get_station(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, get_radio_station_ok) { - auto& v = cm->get_stations(); + auto& v = config->get_stations(); auto uid = v[0]->get_id(); - auto item = cm->get_station(uid); + auto item = config->get_station(uid); ASSERT_EQ(item, v[0].get()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, delete_radio_station) { - auto& v = cm->get_stations(); + auto& v = config->get_stations(); auto size_before = v.size(); auto uid = v[0]->get_id(); - cm->delete_radio_station(uid); - ASSERT_EQ(cm->get_stations().size(), size_before - 1); - EXPECT_THROW(cm->get_station(uid), std::out_of_range); + config->delete_radio_station(uid); + ASSERT_EQ(config->get_stations().size(), size_before - 1); + EXPECT_THROW(config->get_station(uid), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, delete_radio_throws) { EXPECT_THROW( - cm->delete_radio_station(QUuid::createUuid()), std::out_of_range); + config->delete_radio_station(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, add_alarm) { - QSignalSpy spy(cm.get(), SIGNAL(alarms_changed())); + QSignalSpy spy(config.get(), SIGNAL(alarms_changed())); ASSERT_TRUE(spy.isValid()); auto alm = std::make_shared(); - auto size_before = cm->get_alarms().size(); - cm->add_alarm(alm); + auto size_before = config->get_alarms().size(); + config->add_alarm(alm); ASSERT_EQ(spy.count(), 1); - ASSERT_EQ(cm->get_alarms().size(), size_before + 1); + ASSERT_EQ(config->get_alarms().size(), size_before + 1); } /*****************************************************************************/ TEST_F(ConfigurationFixture, get_alarm_throws) { - EXPECT_THROW(cm->get_alarm(QUuid::createUuid()), std::out_of_range); + EXPECT_THROW(config->get_alarm(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, get_alarm_ok) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); auto uid = v[0]->get_id(); - auto item = cm->get_alarm(uid); + auto item = config->get_alarm(uid); ASSERT_EQ(item, v[0].get()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, delete_alarm) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); auto size_before = v.size(); auto uid = v[0]->get_id(); - cm->delete_alarm(uid); - ASSERT_EQ(cm->get_alarms().size(), size_before - 1); - EXPECT_THROW(cm->get_alarm(uid), std::out_of_range); + config->delete_alarm(uid); + ASSERT_EQ(config->get_alarms().size(), size_before - 1); + EXPECT_THROW(config->get_alarm(uid), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, delete_alarm_throws) { - EXPECT_THROW(cm->delete_alarm(QUuid::createUuid()), std::out_of_range); + EXPECT_THROW(config->delete_alarm(QUuid::createUuid()), std::out_of_range); } /*****************************************************************************/ TEST_F(ConfigurationFixture, ChangeAlarmEmitsAlarmsChanged) { - auto& v = cm->get_alarms(); - QSignalSpy spy(cm.get(), SIGNAL(alarms_changed())); + auto& v = config->get_alarms(); + QSignalSpy spy(config.get(), SIGNAL(alarms_changed())); v[0]->enable(false); ASSERT_EQ(spy.count(), 1); } /*****************************************************************************/ TEST_F(ConfigurationFixture, read_2podcasts) { - auto& v = cm->get_podcast_sources(); + auto& v = config->get_podcast_sources(); ASSERT_EQ(2, v.size()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, deletePodcastByIndex) { - auto& v = cm->get_podcast_sources(); + auto& v = config->get_podcast_sources(); ASSERT_EQ(2, v.size()); - cm->remove_podcast_source_by_index(0); - ASSERT_EQ(cm->get_podcast_sources().size(), 1); + config->remove_podcast_source_by_index(0); + ASSERT_EQ(config->get_podcast_sources().size(), 1); } /*****************************************************************************/ TEST_F(ConfigurationFixture, read_PodcastUri) { - auto ps = cm->get_podcast_source_by_index(0); + auto ps = config->get_podcast_source_by_index(0); ASSERT_EQ( ps->get_url(), QString("https://alternativlos.org/alternativlos.rss")); } /*****************************************************************************/ TEST_F(ConfigurationFixture, podcastSource_incomplete) { - auto& v = cm->get_podcast_sources(); + auto& v = config->get_podcast_sources(); ASSERT_EQ(v[0]->get_url(), QString("https://alternativlos.org/alternativlos.rss")); ASSERT_EQ(v[1]->get_description(), QString("")); @@ -390,7 +390,7 @@ TEST(StringToPeriodEnum, mapping_good) { /*****************************************************************************/ TEST_F(ConfigurationFixture, alarm_count) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); // Alarm 5 has an unknown peridicity string "Manchmal" // Alarm 6 has an invalid Timestamp string "25:34" // Alarm 7 has an invalid URL @@ -399,7 +399,7 @@ TEST_F(ConfigurationFixture, alarm_count) { /*****************************************************************************/ TEST_F(ConfigurationFixture, alarm_id) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); auto res = std::find_if( v.begin(), v.end(), [&](const std::shared_ptr& item) { return item->get_id() == @@ -411,7 +411,7 @@ TEST_F(ConfigurationFixture, alarm_id) { /*****************************************************************************/ TEST_F(ConfigurationFixture, podcastid) { - auto& v = cm->get_podcast_sources(); + auto& v = config->get_podcast_sources(); auto res = std::find_if( v.begin(), v.end(), [&](const std::shared_ptr& item) { return item->get_id() == @@ -425,7 +425,7 @@ TEST_F(ConfigurationFixture, podcastid) { /*****************************************************************************/ TEST_F(ConfigurationFixture, streamsourceid) { - auto& v = cm->get_stations(); + auto& v = config->get_stations(); auto res = std::find_if( v.begin(), v.end(), [&](const std::shared_ptr& item) { return item->get_id() == @@ -437,7 +437,7 @@ TEST_F(ConfigurationFixture, streamsourceid) { /*****************************************************************************/ TEST_F(ConfigurationFixture, alarm_daily) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); ASSERT_EQ(v[0]->get_period(), Alarm::Daily); ASSERT_EQ(v[0]->get_time(), QTime::fromString("10:00", "hh:mm")); ASSERT_TRUE(v[0]->is_enabled()); @@ -445,7 +445,7 @@ TEST_F(ConfigurationFixture, alarm_daily) { /*****************************************************************************/ TEST_F(ConfigurationFixture, alarm_workdays) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); ASSERT_EQ(v[1]->get_period(), Alarm::Workdays); ASSERT_EQ(v[1]->get_time(), QTime::fromString("07:00", "hh:mm")); @@ -454,7 +454,7 @@ TEST_F(ConfigurationFixture, alarm_workdays) { /*****************************************************************************/ TEST_F(ConfigurationFixture, alarm_weekends) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); ASSERT_EQ(v[2]->get_period(), Alarm::Weekend); ASSERT_EQ(v[2]->get_time(), QTime::fromString("09:00", "hh:mm")); ASSERT_FALSE(v[2]->is_enabled()); @@ -462,7 +462,7 @@ TEST_F(ConfigurationFixture, alarm_weekends) { /*****************************************************************************/ TEST_F(ConfigurationFixture, alarm_once) { - auto& v = cm->get_alarms(); + auto& v = config->get_alarms(); ASSERT_EQ(v[3]->get_period(), Alarm::Once); ASSERT_EQ(v[3]->get_time(), QTime::fromString("13:00", "hh:mm")); ASSERT_TRUE(v[3]->is_enabled()); @@ -470,12 +470,12 @@ TEST_F(ConfigurationFixture, alarm_once) { /*****************************************************************************/ TEST_F(ConfigurationFixture, emitConfigChanged) { - auto number_of_alarms = cm->get_alarms().size(); - QSignalSpy spy(cm.get(), SIGNAL(configuration_changed())); + auto number_of_alarms = config->get_alarms().size(); + QSignalSpy spy(config.get(), SIGNAL(configuration_changed())); ASSERT_TRUE(spy.isValid()); - cm->update_configuration(); + config->update_configuration(); ASSERT_EQ(spy.count(), 1); - ASSERT_EQ(cm->get_alarms().size(), number_of_alarms); + ASSERT_EQ(config->get_alarms().size(), number_of_alarms); } /*****************************************************************************/ @@ -484,7 +484,7 @@ TEST(Configuration, DefaultForNotWritableCache) { default_cache_dir.removeRecursively(); ASSERT_FALSE(default_cache_dir.exists()); - Configuration cm(DEFAULT_CONFIG_FILE_PATH, QString("/dev/")); + Configuration config(DEFAULT_CONFIG_FILE_PATH, QString("/dev/")); ASSERT_TRUE(default_cache_dir.exists()); } @@ -494,28 +494,28 @@ TEST(Configuration, DefaultForNotWritableConfig) { QFile default_conf_file(DEFAULT_CONFIG_FILE_PATH); // Delete it should it exist.. default_conf_file.remove(); - Configuration cm( + Configuration config( QString("/dev/foobar.json"), DEFAULT_CACHE_DIR_PATH); ASSERT_TRUE(default_conf_file.exists()); } /*****************************************************************************/ TEST_F(ConfigurationFixture, GetweatherConfigApiToken) { - auto cfg = cm->get_weather_config(); + auto cfg = config->get_weather_config(); ASSERT_EQ(cfg.get_api_token(), QString("d77bd1ca2fd77ce4e1cdcdd5f8b7206c")); } /*****************************************************************************/ TEST_F(ConfigurationFixture, GetweatherConfigCityId) { - auto cfg = cm->get_weather_config(); + auto cfg = config->get_weather_config(); ASSERT_EQ(cfg.get_location_id(), QString("3452925")); } /*****************************************************************************/ TEST_F(ConfigurationFixture, changeSleepTimeoutMinutes) { auto new_to = std::chrono::minutes(5); - cm->set_sleep_timeout(new_to); - ASSERT_EQ(cm->get_sleep_timeout(), new_to); + config->set_sleep_timeout(new_to); + ASSERT_EQ(config->get_sleep_timeout(), new_to); } /*****************************************************************************/ diff --git a/test/test_restapihandler.cpp b/test/test_restapihandler.cpp index d9c2676..263b7a2 100644 --- a/test/test_restapihandler.cpp +++ b/test/test_restapihandler.cpp @@ -14,7 +14,7 @@ #include #include "common.hpp" -#include "cm_mock.hpp" /* mock configuration manager */ +#include "config_mock.hpp" /* mock configuration manager */ using namespace DigitalRooster; using namespace DigitalRooster::REST; diff --git a/test/test_sleeptimer.cpp b/test/test_sleeptimer.cpp index ee55509..d4de88d 100644 --- a/test/test_sleeptimer.cpp +++ b/test/test_sleeptimer.cpp @@ -19,7 +19,7 @@ #include "alarmmonitor.hpp" #include "sleeptimer.hpp" -#include "cm_mock.hpp" +#include "config_mock.hpp" #include "player_mock.hpp" using namespace DigitalRooster; @@ -33,13 +33,13 @@ using ::testing::AtLeast; /*****************************************************************************/ class SleepTimerFixture : public ::testing::Test { public: - SleepTimerFixture() : dut(cm){ + SleepTimerFixture() : dut(config){ /* sleep timeout 500 ms */ - ON_CALL(cm, get_sleep_timeout()) + ON_CALL(config, get_sleep_timeout()) .WillByDefault(Return(duration_cast(500ms))); } protected: - NiceMock cm; + NiceMock config; SleepTimer dut; }; diff --git a/test/test_weather.cpp b/test/test_weather.cpp index 1a6f224..e7dcbe5 100644 --- a/test/test_weather.cpp +++ b/test/test_weather.cpp @@ -11,7 +11,7 @@ #include #include -#include "cm_mock.hpp" /* mock configuration manager */ +#include "config_mock.hpp" /* mock configuration manager */ #include "weather.hpp" using namespace DigitalRooster; @@ -43,7 +43,7 @@ class WeatherFile : public virtual ::testing::Test { forecastFile.errorString().toStdString()); } - EXPECT_CALL(cm, get_weather_config()) + EXPECT_CALL(config, get_weather_config()) .Times(AtLeast(1)) .WillRepeatedly(ReturnRef(weather_cfg)); }; @@ -52,12 +52,12 @@ class WeatherFile : public virtual ::testing::Test { QFile weatherFile; QFile forecastFile; WeatherConfig weather_cfg; - CmMock cm; + CmMock config; }; /*****************************************************************************/ TEST_F(WeatherFile, CheckSignals) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(weather_info_updated())); ASSERT_TRUE(spy.isValid()); QSignalSpy spy2(&dut, SIGNAL(forecast_available())); @@ -72,7 +72,7 @@ TEST_F(WeatherFile, CheckSignals) { /*****************************************************************************/ TEST_F(WeatherFile, GetConfigForDownloadAfterTimerExpired) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(weather_info_updated())); dut.set_update_interval(seconds(1)); ASSERT_EQ(dut.get_update_interval(), std::chrono::seconds(1)); @@ -82,7 +82,7 @@ TEST_F(WeatherFile, GetConfigForDownloadAfterTimerExpired) { /*****************************************************************************/ TEST_F(WeatherFile, parseWeatherTemperatures) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(temperature_changed(double))); dut.parse_weather(weatherFile.readAll()); spy.wait(10); @@ -98,7 +98,7 @@ TEST_F(WeatherFile, parseWeatherTemperatures) { /*****************************************************************************/ TEST_F(WeatherFile, parseWeatherCity) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(city_updated(const QString&))); dut.parse_weather(weatherFile.readAll()); spy.wait(10); @@ -111,7 +111,7 @@ TEST_F(WeatherFile, parseWeatherCity) { /*****************************************************************************/ TEST_F(WeatherFile, parseWeatherIconUrl) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(weather_info_updated())); dut.parse_weather(weatherFile.readAll()); spy.wait(10); @@ -122,7 +122,7 @@ TEST_F(WeatherFile, parseWeatherIconUrl) { /*****************************************************************************/ TEST_F(WeatherFile, parseWeatherJsonInvalid) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(city_updated(const QString&))); ASSERT_TRUE(spy.isValid()); @@ -135,7 +135,7 @@ TEST_F(WeatherFile, parseWeatherJsonInvalid) { /*****************************************************************************/ TEST_F(WeatherFile, parseWeatherNoTemperature) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(temperature_changed(double))); ASSERT_TRUE(spy.isValid()); auto no_temp = QByteArray::fromStdString(R"({ @@ -157,7 +157,7 @@ TEST_F(WeatherFile, parseWeatherNoTemperature) { /*****************************************************************************/ TEST_F(WeatherFile, parseWeatherNoCity) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(city_updated(const QString&))); ASSERT_TRUE(spy.isValid()); // forecast does not have the correct format @@ -169,7 +169,7 @@ TEST_F(WeatherFile, parseWeatherNoCity) { /*****************************************************************************/ TEST_F(WeatherFile, parseForecastsDoesNotTouchCurrent) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(forecast_available())); dut.parse_forecast(forecastFile.readAll()); spy.wait(10); @@ -180,7 +180,7 @@ TEST_F(WeatherFile, parseForecastsDoesNotTouchCurrent) { /*****************************************************************************/ TEST_F(WeatherFile, parseForecastBadJSON) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(forecast_available())); ASSERT_TRUE(spy.isValid()); auto crap = QByteArray::fromStdString( @@ -198,7 +198,7 @@ TEST_F(WeatherFile, parseForecastBadJSON) { /*****************************************************************************/ TEST_F(WeatherFile, ForecastOutOfRange) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(forecast_available())); dut.parse_forecast(forecastFile.readAll()); spy.wait(10); @@ -210,7 +210,7 @@ TEST_F(WeatherFile, ForecastOutOfRange) { /*****************************************************************************/ TEST_F(WeatherFile, ForeCastOk) { - Weather dut(cm); + Weather dut(config); QSignalSpy spy(&dut, SIGNAL(forecast_available())); dut.parse_forecast(forecastFile.readAll()); spy.wait(10); diff --git a/test/test_wifi_control.cpp b/test/test_wifi_control.cpp index 5cc7b6b..7a44b82 100644 --- a/test/test_wifi_control.cpp +++ b/test/test_wifi_control.cpp @@ -14,7 +14,7 @@ #include "wifi_control.hpp" #include "gtest/gtest.h" -#include "cm_mock.hpp" +#include "config_mock.hpp" using namespace DigitalRooster; using namespace ::testing; @@ -48,12 +48,12 @@ TEST(WifiControl, parseBuffer){ /*****************************************************************************/ TEST(WifiControl, startScan){ - CmMock cm; + CmMock config; // No real expectations but needed to return a network name. - EXPECT_CALL(cm, get_wpa_socket_name()) + EXPECT_CALL(config, get_wpa_socket_name()) .WillRepeatedly(Return(QString("/var/run/wpa_supplicant/wlp2s0"))); - auto dut = WifiControl::get_instance(&cm); + auto dut = WifiControl::get_instance(&config); int scanstatus_typeid = qRegisterMetaType("WifiControl::ScanStatus"); ASSERT_TRUE(QMetaType::isRegistered(scanstatus_typeid)); From db0ad180505cd3d2f26dec4117adff5971566cb0 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 17:43:36 +0100 Subject: [PATCH 17/26] Test for not-readable config Signed-off-by: Thomas Ruschival --- test/test_configuration.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/test_configuration.cpp b/test/test_configuration.cpp index 05c9fe4..745f918 100644 --- a/test/test_configuration.cpp +++ b/test/test_configuration.cpp @@ -494,8 +494,16 @@ TEST(Configuration, DefaultForNotWritableConfig) { QFile default_conf_file(DEFAULT_CONFIG_FILE_PATH); // Delete it should it exist.. default_conf_file.remove(); - Configuration config( - QString("/dev/foobar.json"), DEFAULT_CACHE_DIR_PATH); + Configuration config(QString("/dev/foobar.json"), DEFAULT_CACHE_DIR_PATH); + ASSERT_TRUE(default_conf_file.exists()); +} + +/*****************************************************************************/ +TEST(Configuration, DefaultForNotReadableConfig) { + QFile default_conf_file(DEFAULT_CONFIG_FILE_PATH); + // Delete it should it exist.. + default_conf_file.remove(); + Configuration config(QString("/dev/mem"), DEFAULT_CACHE_DIR_PATH); ASSERT_TRUE(default_conf_file.exists()); } From c242dc31199ac29f0b24ec77d85e3439c0da70c7 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 18:59:07 +0100 Subject: [PATCH 18/26] Read max_episodes form config Allow for per podcast feed limit of episodes using "maxEpisodes" as key in json Signed-off-by: Thomas Ruschival --- documentation/configuration.md | 1 + include/PodcastSource.hpp | 5 +++-- include/appconstants.hpp | 12 +++++++++++- libsrc/PodcastSource.cpp | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/documentation/configuration.md b/documentation/configuration.md index a957e9a..91a1d54 100644 --- a/documentation/configuration.md +++ b/documentation/configuration.md @@ -78,6 +78,7 @@ The only mandatory property is `url` others are optional: - `id` unique identifier - auto generated if not present - `title` human readable identifier, will be updated according to RSS XML - `url` RSS url +- `maxEpisodes` only shows most recent podcast episodes ### Internet Stream objects `InternetRadio` is an array containing individual stream source configurations. diff --git a/include/PodcastSource.hpp b/include/PodcastSource.hpp index 359d304..e723228 100644 --- a/include/PodcastSource.hpp +++ b/include/PodcastSource.hpp @@ -27,6 +27,7 @@ #include #include +#include "appconstants.hpp" #include "PlayableItem.hpp" #include "UpdateTask.hpp" #include "podcast_serializer.hpp" @@ -35,7 +36,7 @@ namespace DigitalRooster { class HttpClient; // forward declaration /** - * Class represeting information form an RSS Podcast feed with + * Class representing information form an RSS Podcast feed with * some meta information and \ref DigitalRooster::PodcastEpisode */ class PodcastSource : public QObject { @@ -380,7 +381,7 @@ public slots: /** * show max_episodes in the list */ - size_t max_episodes = std::numeric_limits::max(); + size_t max_episodes = DigitalRooster::DEFAULT_MAX_EPISODES; /** * Interval in ms for auto refresh of content diff --git a/include/appconstants.hpp b/include/appconstants.hpp index 0a8870e..e2a7f46 100644 --- a/include/appconstants.hpp +++ b/include/appconstants.hpp @@ -38,6 +38,11 @@ const QString KEY_GROUP_IRADIO_SOURCES("InternetRadio"); */ const QString KEY_GROUP_PODCAST_SOURCES("Podcasts"); +/** + * Maximum Number of episodes to add to this Podcast feed + */ +const QString KEY_MAX_EPISODES("maxEpisodes"); + /** * key for array of individual Podcast Episode objects */ @@ -274,7 +279,12 @@ const int WEATHER_FORECAST_COUNT = 8; /** * Step size of volume increment per rotary event */ -const double VOLUME_INCREMENT = 0.2; +const double VOLUME_INCREMENT = 0.5; + +/** + * Default episodes limit to show for each podcast feed + */ +const int DEFAULT_MAX_EPISODES = 100; /** * Where to find icons for weather condition diff --git a/libsrc/PodcastSource.cpp b/libsrc/PodcastSource.cpp index 6edc30b..554e0a8 100644 --- a/libsrc/PodcastSource.cpp +++ b/libsrc/PodcastSource.cpp @@ -327,11 +327,15 @@ std::shared_ptr PodcastSource::from_json_object( auto desc = json[KEY_DESCRIPTION].toString(); auto img_url = json[KEY_ICON_URL].toString(); auto img_cached = json[KEY_IMAGE_CACHE].toString(); + auto max_episodes = + json[KEY_MAX_EPISODES].toInt(DEFAULT_MAX_EPISODES); ps->set_title(title); ps->set_description(desc); ps->set_image_url(img_url); ps->set_image_file_path(img_cached); + ps->set_max_episodes(max_episodes); + ps->set_update_interval( std::chrono::seconds(json[KEY_UPDATE_INTERVAL].toInt(3600))); ps->set_update_task(std::make_unique(ps.get())); @@ -345,6 +349,7 @@ QJsonObject PodcastSource::to_json_object() const { json[KEY_ID] = get_id_string(); json[KEY_URI] = get_url().toString(); json[JSON_KEY_TITLE] = get_title(); + json[KEY_MAX_EPISODES] = static_cast(max_episodes); json[KEY_UPDATE_INTERVAL] = static_cast(get_update_interval().count()); return json; From f28ad1f32d09cb3ecdfbff9f3acc4b604af83461 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sun, 6 Mar 2022 19:22:28 +0100 Subject: [PATCH 19/26] fixed: variable never used Signed-off-by: Thomas Ruschival --- test/test_alarmdispatcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_alarmdispatcher.cpp b/test/test_alarmdispatcher.cpp index 0ac3de6..7d0cdc6 100644 --- a/test/test_alarmdispatcher.cpp +++ b/test/test_alarmdispatcher.cpp @@ -99,7 +99,7 @@ TEST_F(AlarmDispatcherFixture, InfoDisabledAlarms) { alm1->enable(false); dut->check_alarms(); - auto result = dut->get_upcoming_alarm(); + ASSERT_EQ(dut->get_upcoming_alarm(), nullptr); ASSERT_EQ(dut->get_upcoming_alarm_info(), QString("")); } From 2dba42fe3a50bde585a7e98ec8cdec45683fffc3 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Tue, 8 Mar 2022 20:54:17 +0100 Subject: [PATCH 20/26] Fix alarmdispatcher - remove unused code Signed-off-by: Thomas Ruschival --- test/test_alarmdispatcher.cpp | 1 - test/test_configuration.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_alarmdispatcher.cpp b/test/test_alarmdispatcher.cpp index 7d0cdc6..d42fb1a 100644 --- a/test/test_alarmdispatcher.cpp +++ b/test/test_alarmdispatcher.cpp @@ -99,7 +99,6 @@ TEST_F(AlarmDispatcherFixture, InfoDisabledAlarms) { alm1->enable(false); dut->check_alarms(); - ASSERT_EQ(dut->get_upcoming_alarm(), nullptr); ASSERT_EQ(dut->get_upcoming_alarm_info(), QString("")); } diff --git a/test/test_configuration.cpp b/test/test_configuration.cpp index 745f918..d003e07 100644 --- a/test/test_configuration.cpp +++ b/test/test_configuration.cpp @@ -507,6 +507,16 @@ TEST(Configuration, DefaultForNotReadableConfig) { ASSERT_TRUE(default_conf_file.exists()); } +/*****************************************************************************/ +TEST(Configuration, ExceptionNotReadableConfig) { + QFile cfg(QDir(QDir(DigitalRooster::TEST_FILE_PATH).filePath("testconfig")) + .filePath("config-ro.json")); + Configuration config(cfg.fileName(), DEFAULT_CACHE_DIR_PATH); + cfg.setPermissions(QFileDevice::WriteOwner); + ASSERT_THROW(config.update_configuration(), std::system_error); + cfg.remove(); +} + /*****************************************************************************/ TEST_F(ConfigurationFixture, GetweatherConfigApiToken) { auto cfg = config->get_weather_config(); From d25855e5d7e6c3a803f85b706b2680d4af10fd07 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Tue, 8 Mar 2022 21:01:48 +0100 Subject: [PATCH 21/26] CI-Chain: Coverity, fix typo in container image Signed-off-by: Thomas Ruschival --- .github/workflows/coverity.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index d5ca10a..080c8ae 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -14,7 +14,7 @@ jobs: BUILD_DIR_HOST: /tmp/build BUILD_DIR: /build SRC_DIR: /src - BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:v.1.1.0 + BUILD_IMAGE: ghcr.io/truschival/devlinuxqt-pistache:v1.1.0 CONTAINER_NAME: buildc COVERITY_INSTALL_DIR: /tmp/coverity COVERITY_RESULT_DIR: cov-int From 9b215337a72bfe352d9fd71a087bb25835a97be6 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Wed, 9 Mar 2022 19:51:31 +0100 Subject: [PATCH 22/26] Fix Invalid Iterator access Signed-off-by: Thomas Ruschival --- libsrc/PodcastSource.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libsrc/PodcastSource.cpp b/libsrc/PodcastSource.cpp index 554e0a8..662f43c 100644 --- a/libsrc/PodcastSource.cpp +++ b/libsrc/PodcastSource.cpp @@ -52,8 +52,10 @@ void PodcastSource::add_episode( } // Only add if still space left or if episode more recent than oldest // episode + // For an empty vector episodes.size() <= max_episodes holds true + // otherwise episodes.back() is guaranteed to have a value if (episodes.size() <= max_episodes or - (*episodes.end())->get_publication_date() < + episodes.back()->get_publication_date() < episode->get_publication_date()) { // insert sorted by publication date auto iterator = @@ -66,7 +68,7 @@ void PodcastSource::add_episode( episodes.insert(iterator, episode); /* Remove oldest episode if max episodes has been reached */ if (episodes.size() > max_episodes) { - qInfo(CLASS_LC) << " > max episodes reached, removing"; + qInfo(CLASS_LC) << "max episodes reached, removing"; episodes.pop_back(); } } @@ -109,8 +111,12 @@ void PodcastSource::set_link(const QUrl& newVal) { /*****************************************************************************/ void PodcastSource::set_max_episodes(int max) { qCDebug(CLASS_LC) << Q_FUNC_INFO; - if (max >= 0) + if (max > 0) { max_episodes = max; + } else { + QString what(KEY_MAX_EPISODES + "< 1 is not allowed!"); + throw std::invalid_argument(what.toStdString()); + } } /*****************************************************************************/ @@ -327,15 +333,17 @@ std::shared_ptr PodcastSource::from_json_object( auto desc = json[KEY_DESCRIPTION].toString(); auto img_url = json[KEY_ICON_URL].toString(); auto img_cached = json[KEY_IMAGE_CACHE].toString(); - auto max_episodes = - json[KEY_MAX_EPISODES].toInt(DEFAULT_MAX_EPISODES); + auto max_episodes = json[KEY_MAX_EPISODES].toInt(DEFAULT_MAX_EPISODES); ps->set_title(title); ps->set_description(desc); ps->set_image_url(img_url); ps->set_image_file_path(img_cached); - ps->set_max_episodes(max_episodes); - + try { + ps->set_max_episodes(max_episodes); + } catch (const std::invalid_argument& exc) { + qCWarning(CLASS_LC) << exc.what() << "- will use default"; + } ps->set_update_interval( std::chrono::seconds(json[KEY_UPDATE_INTERVAL].toInt(3600))); ps->set_update_task(std::make_unique(ps.get())); From 12d1df626f3288338d4748b2a49e9b42d300158b Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Wed, 9 Mar 2022 19:52:30 +0100 Subject: [PATCH 23/26] max_episodes is size_t Signed-off-by: Thomas Ruschival --- include/PodcastSource.hpp | 3 ++- include/appconstants.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/PodcastSource.hpp b/include/PodcastSource.hpp index e723228..f4f2db0 100644 --- a/include/PodcastSource.hpp +++ b/include/PodcastSource.hpp @@ -1,3 +1,4 @@ + /****************************************************************************** * \filename * \brief @@ -157,7 +158,7 @@ class PodcastSource : public QObject { /** * show max_episodes in the list */ - int get_max_episodes() const { + size_t get_max_episodes() const { return max_episodes; }; diff --git a/include/appconstants.hpp b/include/appconstants.hpp index e2a7f46..605e897 100644 --- a/include/appconstants.hpp +++ b/include/appconstants.hpp @@ -284,7 +284,7 @@ const double VOLUME_INCREMENT = 0.5; /** * Default episodes limit to show for each podcast feed */ -const int DEFAULT_MAX_EPISODES = 100; +const unsigned int DEFAULT_MAX_EPISODES = 100; /** * Where to find icons for weather condition From 5d2a810134cf692e3ef58d890f66f029d320ffd1 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Wed, 9 Mar 2022 19:53:11 +0100 Subject: [PATCH 24/26] Test for invalid max_episodes Signed-off-by: Thomas Ruschival --- libsrc/configuration.cpp | 2 +- test/test_podcastsource.cpp | 55 ++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/libsrc/configuration.cpp b/libsrc/configuration.cpp index 507c306..1966ad6 100644 --- a/libsrc/configuration.cpp +++ b/libsrc/configuration.cpp @@ -21,7 +21,7 @@ #include "util.hpp" using namespace DigitalRooster; -static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.ConfigurationManager"); +static Q_LOGGING_CATEGORY(CLASS_LC, "DigitalRooster.Configuration"); /*****************************************************************************/ bool DigitalRooster::is_writable_directory(const QString& dirname) { diff --git a/test/test_podcastsource.cpp b/test/test_podcastsource.cpp index a4196b2..5f9bb76 100644 --- a/test/test_podcastsource.cpp +++ b/test/test_podcastsource.cpp @@ -35,11 +35,14 @@ class PodcastSourceFixture : public virtual ::testing::Test { , cache_file( cache_dir.filePath(uid.toString(QUuid::WithoutBraces) + ".png")) { ps.set_max_episodes(5); - ep1 = std::make_shared("Name1",QUrl("http://foo-1.bar")); + ep1 = + std::make_shared("Name1", QUrl("http://foo-1.bar")); ep1->set_publication_date(QDateTime::fromSecsSinceEpoch(100000000)); - ep2 = std::make_shared("Name2",QUrl("http://foo-2.bar")); + ep2 = + std::make_shared("Name2", QUrl("http://foo-2.bar")); ep2->set_publication_date(QDateTime::fromSecsSinceEpoch(200000000)); - ep3 = std::make_shared("Name3",QUrl("http://foo-3.bar")); + ep3 = + std::make_shared("Name3", QUrl("http://foo-3.bar")); ep3->set_publication_date(QDateTime::fromSecsSinceEpoch(300000000)); } @@ -82,11 +85,15 @@ TEST_F(PodcastSourceFixture, expected_order) { ps.add_episode(ep1); EXPECT_EQ(ps.get_episodes().size(), 3); // oldest last - EXPECT_EQ(ps.get_episodes().back()->get_url(),ep1->get_url()); + EXPECT_EQ(ps.get_episodes().back()->get_url(), ep1->get_url()); // ep3 first - EXPECT_EQ(ps.get_episodes().front()->get_url(),ep3->get_url()); + EXPECT_EQ(ps.get_episodes().front()->get_url(), ep3->get_url()); } +/******************************************************************************/ +TEST_F(PodcastSourceFixture, max_episodes_lt0) { + EXPECT_THROW(ps.set_max_episodes(0), std::invalid_argument); +} /******************************************************************************/ TEST_F(PodcastSourceFixture, max_reached_adding) { @@ -102,9 +109,9 @@ TEST_F(PodcastSourceFixture, max_reached_adding) { // expect ep1 to be removed EXPECT_EQ(ps.get_episodes().size(), 3); // now p2 is oldest - EXPECT_EQ(ps.get_episodes().back()->get_url(),ep2->get_url()); + EXPECT_EQ(ps.get_episodes().back()->get_url(), ep2->get_url()); // ep3 first - EXPECT_EQ(ps.get_episodes().front()->get_url(),ep3->get_url()); + EXPECT_EQ(ps.get_episodes().front()->get_url(), ep3->get_url()); } @@ -330,7 +337,8 @@ TEST(PodcastSource, fromGoodJson) { "icon-cached": "/tmp/local_cache/foo.jpg", "timestamp": "Thu Nov 14 19:48:55 2019", "url": "https://alternativlos.org/alternativlos.rss", - "title": "MyTitle" + "title": "MyTitle", + "maxEpisodes" : 3 })"); auto jdoc = QJsonDocument::fromJson(json_string.toUtf8()); auto ps = PodcastSource::from_json_object(jdoc.object()); @@ -340,6 +348,7 @@ TEST(PodcastSource, fromGoodJson) { ps->get_url(), QUrl("https://alternativlos.org/alternativlos.rss")); EXPECT_EQ(ps->get_description(), QString("Some Description")); EXPECT_EQ(ps->get_icon(), QString("https://some.remote.url/test.jpg")); + EXPECT_EQ(ps->get_max_episodes(), 3); } /******************************************************************************/ @@ -347,7 +356,7 @@ TEST(PodcastSource, fromBadJson) { QString json_string(R"( { "aKeyWithoutValue" - })"); + })"); auto jdoc = QJsonDocument::fromJson(json_string.toUtf8()); EXPECT_THROW( PodcastSource::from_json_object(jdoc.object()), std::invalid_argument); @@ -356,15 +365,35 @@ TEST(PodcastSource, fromBadJson) { /******************************************************************************/ TEST(PodcastSource, fromBadJsonInvalidUrl) { QString json_string(R"( - { + { "id": "{5c81821d-17fc-44d5-ae45-5ab24ffd1d50}", "description": "Some Description", - "icon": "https://some.remote.url/test.jpg", + "icon": "https://some.remote.url/test.jpg", "icon-cached": "/tmp/local_cache/foo.jpg", "timestamp": "Thu Nov 14 19:48:55 2019", - "title": "MyTitle" - })"); + "title": "MyTitle", + "maxEpisodes": 5 + })"); auto jdoc = QJsonDocument::fromJson(json_string.toUtf8()); EXPECT_THROW( PodcastSource::from_json_object(jdoc.object()), std::invalid_argument); } + +/******************************************************************************/ +TEST(PodcastSource, fromBadJsonInvalidMaxEpisodes) { + QString json_string(R"( + { + "id": "{5c81821d-17fc-44d5-ae45-5ab24ffd1d50}", + "description": "Some Description", + "icon": "https://some.remote.url/test.jpg", + "icon-cached": "/tmp/local_cache/foo.jpg", + "timestamp": "Thu Nov 14 19:48:55 2019", + "url": "https://alternativlos.org/alternativlos.rss", + "title": "MyTitle", + "maxEpisodes": -1.2 + })"); + + auto jdoc = QJsonDocument::fromJson(json_string.toUtf8()); + auto ps = PodcastSource::from_json_object(jdoc.object()); + EXPECT_EQ(ps->get_max_episodes(), DEFAULT_MAX_EPISODES); +} From 4452946c3be1c4cf5df2ce59792eee46def44272 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Wed, 8 Jun 2022 17:53:23 +0200 Subject: [PATCH 25/26] Add maxEpisodes to REST interface careful: the generated code calls the property 'max_episodes' Signed-off-by: Thomas Ruschival --- REST/openapi.yml | 64 +++++++++++++++++---------------- libsrc/hardwarecontrol_mk3.cpp | 2 +- test/api-tests/test_podcasts.py | 8 +++++ 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/REST/openapi.yml b/REST/openapi.yml index 07e59be..6e3eee5 100644 --- a/REST/openapi.yml +++ b/REST/openapi.yml @@ -16,7 +16,7 @@ servers: variables: server: default: http://digitalrooster:6666 - + ############################################################################### components: # HTTP responses in case of errors @@ -28,13 +28,13 @@ components: content: application/json: schema: - $ref: '#/components/schemas/ResourceUuid' + $ref: '#/components/schemas/ResourceUuid' InvalidRequest: description: Invalid request parameters! content: application/json: schema: - $ref: '#/components/schemas/Error' + $ref: '#/components/schemas/Error' NotFound: description: The specified resource was not found content: @@ -47,7 +47,7 @@ components: application/json: schema: $ref: '#/components/schemas/Error' - + # Objects # schemas: # Schema for error response body @@ -87,7 +87,7 @@ components: type: array items: $ref: '#/components/schemas/Station' - + # PodcastSource definition Podcast: required: @@ -101,14 +101,16 @@ components: url: type: string updateInterval: - type: integer - + type: integer + maxEpisodes: + type: integer + # Array of PodcastSources Podcasts: type: array items: $ref: '#/components/schemas/Podcast' - + # Alarm definition Alarm: required: @@ -134,7 +136,7 @@ components: type: integer id: type: string - + # Alarm array Alarms: type: array @@ -189,8 +191,8 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 404: - $ref: '#/components/responses/NotFound' - + $ref: '#/components/responses/NotFound' + post: # Create a stream operationId: iradio.create tags: @@ -209,10 +211,10 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' - + $ref: '#/components/responses/NotFound' + # Manipulate single Radios Stream /radios/{id}: @@ -233,9 +235,9 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' + $ref: '#/components/responses/NotFound' delete: # delete stream identified by id operationId: iradio.delete @@ -246,11 +248,11 @@ paths: - $ref: '#/components/parameters/id' responses: 200: - $ref: '#/components/responses/Success' + $ref: '#/components/responses/Success' 401: $ref: '#/components/responses/Unauthorized' 404: - $ref: '#/components/responses/NotFound' + $ref: '#/components/responses/NotFound' ############################################################################### # Podcast Sources @@ -273,9 +275,9 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' + $ref: '#/components/responses/NotFound' post: # Add a podcast source with RSS feed operationId: podcasts.create @@ -295,7 +297,7 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' /podcasts/{id}: get: # read single podcast by id @@ -315,9 +317,9 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' + $ref: '#/components/responses/NotFound' delete: # delete podcasts identified by id operationId: podcasts.delete @@ -332,10 +334,10 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' - + $ref: '#/components/responses/NotFound' + ################################################################################ # Alarms /alarms: @@ -375,9 +377,9 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' + $ref: '#/components/responses/NotFound' /alarms/{id}: get: # read single alarm by id @@ -397,7 +399,7 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: $ref: '#/components/responses/NotFound' @@ -414,6 +416,6 @@ paths: 401: $ref: '#/components/responses/Unauthorized' 403: - $ref: '#/components/responses/InvalidRequest' + $ref: '#/components/responses/InvalidRequest' 404: - $ref: '#/components/responses/NotFound' + $ref: '#/components/responses/NotFound' diff --git a/libsrc/hardwarecontrol_mk3.cpp b/libsrc/hardwarecontrol_mk3.cpp index 33caee5..5adb81d 100644 --- a/libsrc/hardwarecontrol_mk3.cpp +++ b/libsrc/hardwarecontrol_mk3.cpp @@ -236,4 +236,4 @@ void HardwareControlMk3::set_backlight(int brightness_in) { } /*****************************************************************************/ -Hal::IHardware::~IHardware() = default; + diff --git a/test/api-tests/test_podcasts.py b/test/api-tests/test_podcasts.py index 1697e67..c50878f 100644 --- a/test/api-tests/test_podcasts.py +++ b/test/api-tests/test_podcasts.py @@ -43,6 +43,14 @@ def test_create_podcast_ok(api_client): r= c.podcasts_read_all().value assert len(r) == 3 +def test_create_podcast_max_episodes(api_client): + c = PodcastsApi(api_client) + podcast = Podcast(title="The Title", + url="http://armscontrolwonk.libsyn.com/rss", + maxEpisodes=5) + x= c.podcasts_create(podcast) + r= c.podcasts_read_one(x.id) + assert r.max_episodes == 5 def test_create_podcast_wrong_url(api_client): c = PodcastsApi(api_client) From b49e5e2960f7b813c2e260e701ab02200e68af71 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Wed, 8 Jun 2022 18:44:55 +0200 Subject: [PATCH 26/26] v1.2.0 - bump version Signed-off-by: Thomas Ruschival --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2359740..a8d27b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/) # Project Name MESSAGE( STATUS "Running ${CMAKE_COMMAND} v${CMAKE_VERSION}" ) PROJECT(DigitalRooster - VERSION 1.1.0 + VERSION 1.2.0 DESCRIPTION "A digital alarm clock and podcast player" LANGUAGES CXX C )