From 8ef4acd0cecaa8df6846d27270c4989083d36b4d Mon Sep 17 00:00:00 2001 From: rrandomsky Date: Wed, 18 Jan 2023 20:18:17 +0100 Subject: [PATCH] [MOS-776] Deletion of outdated and invalid SettingsApi test Deletion of outdated and invalid SettingsApi test. New test are planed. --- products/PurePhone/test/CMakeLists.txt | 1 - .../test/test-settings/CMakeLists.txt | 19 -- .../PurePhone/test/test-settings/Database.cpp | 219 -------------- .../test-service-db-settings-api.cpp | 102 ------- .../test-service-db-settings-testapps.hpp | 274 ------------------ .../test-service-db-settings-testmsgs.hpp | 177 ----------- .../test-service-db-settings-testservices.hpp | 86 ------ 7 files changed, 878 deletions(-) delete mode 100644 products/PurePhone/test/test-settings/CMakeLists.txt delete mode 100644 products/PurePhone/test/test-settings/Database.cpp delete mode 100644 products/PurePhone/test/test-settings/test-service-db-settings-api.cpp delete mode 100644 products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp delete mode 100644 products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp delete mode 100644 products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp diff --git a/products/PurePhone/test/CMakeLists.txt b/products/PurePhone/test/CMakeLists.txt index ea98a3bf2ee484e21971aeff92a2e8110a89fb27..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/products/PurePhone/test/CMakeLists.txt +++ b/products/PurePhone/test/CMakeLists.txt @@ -1 +0,0 @@ -add_subdirectory(test-settings) diff --git a/products/PurePhone/test/test-settings/CMakeLists.txt b/products/PurePhone/test/test-settings/CMakeLists.txt deleted file mode 100644 index f40dd9077f15c32091bc08e14624809d63eeff25..0000000000000000000000000000000000000000 --- a/products/PurePhone/test/test-settings/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# service-db tests -add_catch2_executable( - NAME - service-db-settings - SRCS - test-service-db-settings-api.cpp - LIBS - db - evtmgr - sys - module-audio - module-cellular - module-vfs - service-audio - service-cellular - Microsoft.GSL::GSL - DEPS - module-sys -) diff --git a/products/PurePhone/test/test-settings/Database.cpp b/products/PurePhone/test/test-settings/Database.cpp deleted file mode 100644 index 8eb75660c2de41106336f94384348e83d5740883..0000000000000000000000000000000000000000 --- a/products/PurePhone/test/test-settings/Database.cpp +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "module-db/Database/Database.hpp" - -#include - -#include -#include - -#include -#include -#include - -#include - -#include -#include - -class DatabaseInitializer -{ - public: - DatabaseInitializer(Database *) - {} - virtual ~DatabaseInitializer() = default; -}; - -std::map variables; -std::string profile = "_startProfileValue"; -std::string mode = "_initialModeValue"; -std::set profiles, modes; -const std::string system_phone_mode("system/phone_mode"); -const std::string system_phone_profile("system/phone_profile"); - -bool stubExecute(const std::string &format, const std::string &path, const std::string &val) -{ - if (format.empty()) { - return false; - } - - if (format == std::string(settings::Statements::insertValue)) { - LOG_DEBUG("Database::execute set %s", path.c_str()); - variables[path] = val; - return true; - } - - if (format == std::string(settings::Statements::setNotification)) { - return true; - } - if (format == std::string(settings::Statements::clearNotificationdRow)) { - return true; - } - - if (format == std::string(settings::Statements::updateValue)) { - // profile change, mode change - if (val == system_phone_mode) { - mode = path; - return true; - } - if (val == system_phone_profile) { - profile = path; - return true; - } - return false; - } - - if (format == std::string(settings::Statements::addDictValue)) { - // add new profile, add new mode - if (path == system_phone_mode) { - modes.insert(val); - return true; - } - if (path == system_phone_profile) { - profiles.insert(val); - return true; - } - return false; - } - - return false; -} - -std::unique_ptr stubQuery(const std::string &format, const std::string &what) -{ - std::vector row; - auto queryResult = std::make_unique(); - if (std::string(settings::Statements::getValue) == format) { - if (system_phone_mode == what) // settings::DbPaths::phone_mode - { - row.push_back(Field{mode.c_str()}); - } - else if (system_phone_profile == what) // settings::DbPaths::phone_profile - { - row.push_back(Field{profile.c_str()}); - } - else // variable - { - if (variables.end() == variables.find(what)) { - variables[what] = what + " _initialValue"; - } - LOG_DEBUG("Database::query for %s", what.c_str()); - row.push_back(Field{variables[what].c_str()}); - } - queryResult->addRow(row); - } - else if (std::string(settings::Statements::getDictValue) == format) { - if (system_phone_mode == what) { - for (const auto &mode : modes) { - row.clear(); - row.push_back(Field{mode.c_str()}); - queryResult->addRow(row); - } - } - else if (system_phone_profile == what) { - for (const auto &profile : profiles) { - row.clear(); - row.push_back(Field{profile.c_str()}); - queryResult->addRow(row); - } - } - // allProfiles, allModes - } - return queryResult; -} - -Database::Database(const char *name, bool) : dbName(name), queryStatementBuffer{nullptr}, isInitialized_(false) -{ - isInitialized_ = true; -} - -void Database::initQueryStatementBuffer() -{} - -void Database::clearQueryStatementBuffer() -{ - std::memset(queryStatementBuffer, 0, maxQueryLen); -} - -Database::~Database() -{} - -bool Database::initialize() -{ - return true; -} - -bool Database::deinitialize() -{ - return true; -} - -bool Database::execute(const char *format, ...) -{ - if (format == nullptr) { - return false; - } - std::string format_str(format); - if (format_str.find("%") == std::string::npos) { - return true; - } - std::string path, val; - va_list ap; - va_start(ap, format); - format = va_arg(ap, const char *); - if (format != nullptr) { - path = std::string(format); - format = va_arg(ap, const char *); - if (format != nullptr) { - val = std::string(format); - } - } - va_end(ap); - if (!path.empty() && !val.empty()) { - return stubExecute(format_str, path, val); - } - return true; -} - -std::unique_ptr Database::query(const char *format, ...) -{ - if (format == nullptr) { - return nullptr; - } - - std::string format_str(format); - if (format_str.find("%") == std::string::npos) { - return nullptr; - } - std::string what; - va_list ap; - va_start(ap, format); - format = va_arg(ap, const char *); - if (format != nullptr) { - what = std::string(format); - } - va_end(ap); - if (what.empty()) { - return nullptr; - } - return stubQuery(format_str, what); -} - -int Database::queryCallback(void *usrPtr, int count, char **data, char **columns) -{ - return 0; -} - -uint32_t Database::getLastInsertRowId() -{ - return 1; -} - -void Database::pragmaQuery(const std::string &pragmaStatemnt) -{} - -bool Database::storeIntoFile(const std::filesystem::path &backupPath) -{ - return true; -} diff --git a/products/PurePhone/test/test-settings/test-service-db-settings-api.cpp b/products/PurePhone/test/test-settings/test-service-db-settings-api.cpp deleted file mode 100644 index bd6cbe38f3fe0861b2283c059b70f831e3d4668a..0000000000000000000000000000000000000000 --- a/products/PurePhone/test/test-settings/test-service-db-settings-api.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include -#include -#include -#include -#include -#include // for Message_t, ResponseMessage, DataMessage, Message - -#include -#include -#include - -#include "test-service-db-settings-testmsgs.hpp" -#include "test-service-db-settings-testservices.hpp" -#include "test-service-db-settings-testapps.hpp" -#include "Database.cpp" - -#include "module-db/databases/CalllogDB.hpp" -#include -#include -#include "module-db/databases/NotesDB.hpp" -#include "module-db/databases/NotificationsDB.hpp" -#include "module-db/databases/SmsDB.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -TEST_CASE("SettingsApi", "[.]") -{ - SECTION("variable/profile/mode register/set/get/unregister") - { - auto manager = std::make_shared(std::vector>{}); - std::shared_ptr varWritter; - std::shared_ptr varReader; - std::shared_ptr testVar; - std::shared_ptr testStart; - - std::shared_ptr postMortemSetting; - - manager->StartSystem( - nullptr, - [manager, &varWritter, &varReader, &testVar, &testStart, &postMortemSetting]() { - // preliminary - testStart = std::make_shared(); - testStart->lock(); - std::cout << "start thr_id: " << std::this_thread::get_id() << std::endl << std::flush; - auto ret = sys::SystemManagerCommon::RunSystemService(std::make_shared(), manager.get()); - ret &= sys::SystemManagerCommon::RunSystemService(std::make_shared(), manager.get()); - - varWritter = std::make_shared("writterVar"); - varReader = std::make_shared("readerVar"); - - postMortemSetting = varWritter->getSettings(); - - ret &= sys::SystemManagerCommon::RunSystemService(varWritter, manager.get()); - ret &= sys::SystemManagerCommon::RunSystemService(varReader, manager.get()); - - testVar = std::make_shared("appTest", varWritter, varReader, testStart); - ret &= sys::SystemManagerCommon::RunSystemService(testVar, manager.get()); - - std::cout << "koniec start thr_id: " << std::this_thread::get_id() << std::endl << std::flush; - testStart->unlock(); - auto msgStart = std::make_shared(); - manager->bus.sendUnicast(std::move(msgStart), "appTest"); - - msgStart = std::make_shared(); - manager->bus.sendUnicast(std::move(msgStart), "appTestProfile"); - - msgStart = std::make_shared(); - manager->bus.sendUnicast(std::move(msgStart), "appTestMode"); - - return ret; - }, - nullptr); - - try { - // start application - cpp_freertos::Thread::StartScheduler(); - - // check the results - std::cout << "testVar values:" << std::endl << std::flush; - for (const auto &s : testVar->v) { - std::cout << s << std::endl << std::flush; - } - REQUIRE(testVar->v.size() == 3); - REQUIRE(testVar->v[1] == testVar->v[0] + "1"); - REQUIRE(testVar->v[2] == testVar->v[1] + "2"); - } - catch (std::exception &error) { - std::cout << error.what() << std::endl; - exit(1); - } - } -} diff --git a/products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp b/products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp deleted file mode 100644 index dc0ceb063f4352e1220155592b51df8677f98333..0000000000000000000000000000000000000000 --- a/products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp +++ /dev/null @@ -1,274 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include -#include - -namespace app -{ - class UserPowerDownRequest : public sys::DataMessage - {}; -} // namespace app -namespace settings -{ - class TestService : public sys::Service - { - public: - TestService(const std::string &name) : sys::Service(name) - {} - sys::ReturnCodes InitHandler() override - { - std::cout << "inithandler thr_id: " << std::this_thread::get_id() << std::endl << std::flush; - return sys::ReturnCodes::Success; - } - sys::ReturnCodes DeinitHandler() override - { - std::cout << "deinithandler thr_id: " << std::this_thread::get_id() << std::endl << std::flush; - return sys::ReturnCodes::Success; - } - sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override - { - return sys::ReturnCodes::Success; - } - sys::MessagePointer DataReceivedHandler(sys::DataMessage *req, sys::ResponseMessage *resp) override - { - return std::make_shared(); - }; - }; - /* @brief AppTest handles async communication between two services (setter and getter) - and simulates synchronous following flow: - 1. getter registers on value changes and gets the startup value of param "brightness" - 2. the setter app sets "brightness" to received in step 1 value + "1" - 3. check if the new value was received by getter - 4. unregister "brightness" on getter - 5. set "brightness" to value+"1"+"2" on setter - 6. wait 200ms and if getter does not provide value change finish - */ - class AppTest : public TestService - { - public: - enum class State : uint8_t - { - Unk, // init - Start, // got start, send register - Register, // got register cnf - RegisterStartVal, // got onchang (v), set (v+1) - RegisterSetVal, // got vcnf (v+1) && got onchange (v+1), send unregister - UnregisterWait, // - Unregister, - RegisterAllWait, - RegisterAll, - RegisterAllAdd, - RegisterAllAddWait, - Stop - }; - std::shared_ptr setter; - std::shared_ptr getter; - std::shared_ptr testStart; - State state; - std::string last_v; - std::vector v; - - void setState(State state) - { - printf("state change: [%s]->[%s]\n", - std::string(magic_enum::enum_name(this->state)).c_str(), - std::string(magic_enum::enum_name(state)).c_str()); - this->state = state; - } - bool isState(State cmp) - { - printf("state compare: [%s]->[%s]\n", - std::string(magic_enum::enum_name(this->state)).c_str(), - std::string(magic_enum::enum_name(state)).c_str()); - return this->state == cmp; - } - - AppTest(std::string name, - std::shared_ptr setter, - std::shared_ptr getter, - std::shared_ptr testStart) - : TestService(std::move(name)), setter(std::move(setter)), getter(std::move(getter)), - testStart(std::move(testStart)) - {} - sys::ReturnCodes InitHandler() override - { - setState(State::Unk); - return sys::ReturnCodes::Success; - } - sys::ReturnCodes DeinitHandler() override - { - return sys::ReturnCodes::Success; - } - sys::MessagePointer DataReceivedHandler(sys::DataMessage *msg, sys::ResponseMessage *resp) override - { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - if (nullptr != dynamic_cast(msg)) { - testStart->lock(); - testStart->unlock(); - if (!isState(State::Unk)) { - closeSystem(); - } - else { - setState(State::Start); - auto msg = std::make_shared("brightness", "none"); - bus.sendUnicast(std::move(msg), getter->GetName()); - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::Start)) { - setState(State::Register); - } - } - else if (auto m = dynamic_cast(msg)) { - if (isState(State::Register)) { - setState(State::RegisterStartVal); - v.push_back(m->value); - auto msg = std::make_shared("brightness", v[0] + "1"); - bus.sendUnicast(std::move(msg), setter->GetName()); - } - else if (isState(State::RegisterSetVal)) { - if (m->value == v[0] + "1") { - v.push_back(m->value); - auto msg = std::make_shared("brightness", "empty"); - bus.sendUnicast(std::move(msg), getter->GetName()); - setState(State::UnregisterWait); - } - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::UnregisterWait)) { - setState(State::Unregister); - auto msg = std::make_shared("brightness", v.back() + "2"); - bus.sendUnicast(std::move(msg), setter->GetName()); - } - } - else if (auto m = dynamic_cast(msg)) { - if (isState(State::RegisterStartVal)) { - setState(State::RegisterSetVal); - } - else if (isState(State::Unregister)) { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - v.push_back(m->value); - auto msg = std::make_shared(); - bus.sendUnicast(std::move(msg), GetName()); - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::Unregister)) { - closeSystem(); - } - } - - return std::make_shared(); - } - - protected: - void closeSystem() - { - auto msg = std::make_shared(); - bus.sendUnicast(std::move(msg), service::name::system_manager); - } - }; - - class AppTestProfileMode : public AppTest - { - public: - AppTestProfileMode(const std::string &name, - std::shared_ptr setter, - std::shared_ptr getter, - std::shared_ptr testStart) - : AppTest(name, setter, getter, testStart) - {} - sys::MessagePointer DataReceivedHandler(sys::DataMessage *msg, sys::ResponseMessage *resp) override - { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - if (nullptr != dynamic_cast(msg)) { - testStart->lock(); - testStart->unlock(); - if (!isState(State::Unk)) { - closeSystem(); - } - else { - setState(State::Start); - auto msg = std::make_shared(); - bus.sendUnicast(std::move(msg), getter->GetName()); - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::Start)) { - setState(State::Register); - } - } - else if (auto m = dynamic_cast(msg)) { - if (isState(State::Register)) { - setState(State::RegisterStartVal); - v.push_back(m->name); - auto msg = std::make_shared(m->name + "1"); - bus.sendUnicast(std::move(msg), setter->GetName()); - } - else if (isState(State::RegisterSetVal)) { - if (m->name == v[0] + "1") { - v.push_back(m->name); - auto msg = std::make_shared(); - bus.sendUnicast(std::move(msg), getter->GetName()); - setState(State::UnregisterWait); - } - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::UnregisterWait)) { - setState(State::Unregister); - auto msg = std::make_shared(v.back() + "2"); - bus.sendUnicast(std::move(msg), setter->GetName()); - } - } - else if (auto m = dynamic_cast(msg)) { - if (isState(State::RegisterStartVal)) { - setState(State::RegisterSetVal); - } - else if (isState(State::Unregister)) { - v.push_back(m->name); - auto msg = std::make_shared(); - bus.sendUnicast(std::move(msg), getter->GetName()); - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::Unregister)) { - setState(State::RegisterAllWait); - } - } - else if (auto m = dynamic_cast(msg)) { - if (isState(State::RegisterAllWait)) { - setState(State::RegisterAll); - for (auto prof : m->profiles) { - v.push_back(prof); - } - auto msg = std::make_shared("other"); - bus.sendUnicast(std::move(msg), setter->GetName()); - } - else if (isState(State::RegisterAllAddWait)) { - setState(State::RegisterAllAdd); - for (auto prof : m->profiles) { - v.push_back(prof); - } - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - auto msg = std::make_shared(); - bus.sendUnicast(std::move(msg), GetName()); - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::RegisterAll)) { - setState(State::RegisterAllAddWait); - } - } - else if (nullptr != dynamic_cast(msg)) { - if (isState(State::RegisterAllAdd)) { - closeSystem(); - } - } - - return std::make_shared(); - } - }; -} // namespace settings diff --git a/products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp b/products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp deleted file mode 100644 index 4df6e8adb0eb944b5bdbb6a98516f1b57f27031e..0000000000000000000000000000000000000000 --- a/products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -namespace settings -{ - namespace UTMsg - { - class SettingsUTMsg : public ::settings::Messages::SettingsMessage - { - public: - explicit SettingsUTMsg(MessageType type = MessageType::Settings) - : ::settings::Messages::SettingsMessage(type){}; - ~SettingsUTMsg() override = default; - }; - - class UTMsgReq : public SettingsUTMsg - { - public: - std::string name, value; - UTMsgReq() = default; - UTMsgReq(std::string name, std::string value) : name(std::move(name)), value(std::move(value)) - {} - }; - class UTMsgCnf : public SettingsUTMsg - { - public: - std::string name, value; - UTMsgCnf() = default; - UTMsgCnf(std::string name, std::string value) : name(std::move(name)), value(std::move(value)) - {} - }; - class UTMsgStart : public SettingsUTMsg - { - public: - UTMsgStart() = default; - }; - class UTMsgStop : public SettingsUTMsg - { - public: - UTMsgStop() = default; - }; - - class ReqRegValChg : public UTMsgReq - { - public: - ReqRegValChg(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value)) - {} - }; - class ReqUnRegValChg : public UTMsgReq - { - public: - ReqUnRegValChg(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value)) - {} - }; - class ReqSetVal : public UTMsgReq - { - public: - ReqSetVal(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value)) - {} - }; - class ReqGetVal : public UTMsgReq - { - public: - ReqGetVal(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value)) - {} - }; - class CnfRegValChg : public UTMsgCnf - { - public: - CnfRegValChg() = default; - CnfRegValChg(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value)) - {} - }; - class CnfUnRegValChg : public UTMsgCnf - { - public: - CnfUnRegValChg() = default; - CnfUnRegValChg(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value)) - {} - }; - class CnfReqSetVal : public UTMsgCnf - { - public: - CnfReqSetVal() = default; - CnfReqSetVal(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value)) - {} - }; - class CnfReqGetVal : public UTMsgCnf - { - public: - CnfReqGetVal() = default; - CnfReqGetVal(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value)) - {} - }; - class CnfValChg : public UTMsgCnf - { - public: - CnfValChg() = default; - CnfValChg(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value)) - {} - }; - - class ReqRegProfileChg : public UTMsgReq - { - public: - ReqRegProfileChg() = default; - }; - class ReqUnRegProfileChg : public UTMsgReq - { - public: - ReqUnRegProfileChg() = default; - }; - class ReqSetCurrentProfile : public UTMsgReq - { - public: - ReqSetCurrentProfile(std::string profile) : UTMsgReq(std::move(profile), "") - {} - }; - class ReqGetAllProfiles : public UTMsgReq - { - public: - ReqGetAllProfiles() = default; - }; - class ReqAddProfile : public UTMsgReq - { - public: - ReqAddProfile(std::string profile) : UTMsgReq(std::move(profile), "") - {} - }; - class CnfRegProfileChg : public UTMsgCnf - { - public: - CnfRegProfileChg() = default; - }; - class CnfUnRegProfileChg : public UTMsgCnf - { - public: - CnfUnRegProfileChg() = default; - }; - class CnfSetCurrentProfile : public UTMsgCnf - { - public: - CnfSetCurrentProfile(std::string profile) : UTMsgCnf(std::move(profile), "") - {} - }; - class CnfGetAllProfiles : public UTMsgCnf - { - public: - CnfGetAllProfiles() = default; - }; - class CnfAddProfile : public UTMsgCnf - { - public: - CnfAddProfile(std::string profile) : UTMsgCnf(std::move(profile), "") - {} - }; - class CnfReqProfileChg : public UTMsgCnf - { - public: - CnfReqProfileChg(std::string profile) : UTMsgCnf(std::move(profile), "") - {} - }; - class ProfileChg : public UTMsgCnf - { - public: - ProfileChg(std::string profile) : UTMsgCnf(std::move(profile), "") - {} - }; - class ProfilesChg : public UTMsgCnf - { - public: - std::list profiles; - ProfilesChg(std::list profiles) : UTMsgCnf(), profiles(std::move(profiles)) - {} - }; - }; // namespace UTMsg -} // namespace settings diff --git a/products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp b/products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp deleted file mode 100644 index 4e66a03effc5ef1a31211ad748ae5b59e4bfcd0f..0000000000000000000000000000000000000000 --- a/products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include -#include - -namespace settings -{ - class MyService : public sys::Service - { - public: - MyService(const std::string &name) : sys::Service(name) - {} - std::shared_ptr mySettings; - std::vector valChanged; - std::string whoRequestedNotifyOnChange; - void ValueChanged(std::string value) - { - valChanged.emplace_back(value); - } - void debug(const std::string &cmd, const std::string &k, const std::string &v) - { - std::cout << "[thr_id:" << std::this_thread::get_id() << ", thr_name:" << GetName() << "] " << cmd - << " [key, val] = (" << k << ", " << v << ")" << std::endl - << std::flush; - } - sys::MessagePointer DataReceivedHandler(sys::DataMessage *req, sys::ResponseMessage *resp) override - { - if (auto msg = dynamic_cast(req)) { - debug("ReqRegValChg", msg->name, msg->value); - whoRequestedNotifyOnChange = msg->sender; - mySettings->registerValueChange(msg->name, - ([this](std::string value) { - ValueChanged(value); - auto cnf = std::make_shared("", value); - bus.sendUnicast(std::move(cnf), whoRequestedNotifyOnChange); - }), - settings::SettingsScope::Global); - auto cnf = std::make_shared(msg->name, msg->value); - bus.sendUnicast(std::move(cnf), whoRequestedNotifyOnChange); - } - else if (auto msg = dynamic_cast(req)) { - // unregister - debug("ReqUnRegValChg", msg->name, msg->value); - mySettings->unregisterValueChange(msg->name, settings::SettingsScope::Global); - auto cnf = std::make_shared(msg->name, msg->value); - bus.sendUnicast(std::move(cnf), msg->sender); - } - else if (auto msg = dynamic_cast(req)) { - // set value - debug("ReqSetVal", msg->name, msg->value); - mySettings->setValue(msg->name, msg->value, settings::SettingsScope::Global); - auto cnf = std::make_shared(msg->name, msg->value); - bus.sendUnicast(std::move(cnf), msg->sender); - } - else if (dynamic_cast(msg)) { - debug("ReqGetValChg", msg->name, msg->value); - } - return std::make_shared(); - } - sys::ReturnCodes InitHandler() override - { - std::cout << "InitHandler thr_id: " << std::this_thread::get_id() << "name: " << GetName() << std::endl - << std::flush; - mySettings = std::make_shared(); - mySettings->init(service::ServiceProxy(shared_from_this())); - return sys::ReturnCodes::Success; - } - sys::ReturnCodes DeinitHandler() override - { - mySettings->deinit(); - std::cout << "deinithandler thr_id: " << std::this_thread::get_id() << std::endl << std::flush; - return sys::ReturnCodes::Success; - } - sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override - { - return sys::ReturnCodes::Success; - } - - std::shared_ptr getSettings() - { - return mySettings; - } - }; - -} // namespace settings