~aleteoryx/muditaos

ref: d558e60a4d5bc26a982f0ba85f20631d7efac5df muditaos/module-services/service-db/test/test-settings-Settings/test-settings-Settings.cpp -rw-r--r-- 2.2 KiB
d558e60a — Lefucjusz [CP-2013] Add time sync endpoint 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>
#include <service-db/Settings.hpp>
#include <service-db/SettingsCache.hpp>
#include <utility>

/// stub
namespace settings
{
    SettingsProxy::~SettingsProxy()
    {}
    SettingsProxy::SettingsProxy(const service::ServiceProxy &interface) : service::ServiceProxy(interface)
    {}
    void SettingsProxy::init(std::function<void(EntryPath, std::string)> onChangeHandler)
    {
        this->onChangeHandler = std::move(onChangeHandler);
    }
    void SettingsProxy::deinit()
    {}

    void SettingsProxy::onChange(EntryPath path, std::string value)
    {
        if (onChangeHandler) {
            onChangeHandler(std::move(path), std::move(value));
        }
    };
    bool SettingsProxy::isValid() const noexcept
    {
        return true;
    }
    void SettingsProxy::registerValueChange(EntryPath){};
    void SettingsProxy::unregisterValueChange(EntryPath){};
    void SettingsProxy::setValue(const EntryPath &path, const std::string &value){};
    std::string SettingsProxy::ownerName()
    {
        return "";
    }

    const std::string &SettingsCache::getValue(const EntryPath &path) const
    {
        static const std::string val;
        return val;
    }
    void SettingsCache::setValue(const EntryPath &path, const std::string &value)
    {}

    SettingsCache *SettingsCache::getInstance()
    {
        static SettingsCache s;
        return &s;
    }

} // namespace settings

/// TODO shall we warn here... on uninitialized settings?
TEST_CASE("Settings - not initialized")
{
    settings::Settings setting;
    SECTION("Not initialized settings")
    {
        auto val = setting.getValue("lol");
        REQUIRE(val.empty());
    }

    SECTION("dead initialized settings")
    {
        auto val = setting.getValue("lol");
        REQUIRE(val.empty());
    }
}

TEST_CASE("Settings - initialized")
{
    /// this will require stubbing
    SECTION("get Value - not exists")
    {}

    SECTION("get Value - exists")
    {}

    SECTION("get Value - different type that expected")
    {}

    SECTION("set value - no value")
    {}

    SECTION("set value - override")
    {}
}