~aleteoryx/muditaos

ref: b4568c32eb2a4b37e9dfbbe08c446430eee2145c muditaos/module-services/service-db/test/test-entry-path.cpp -rw-r--r-- 3.9 KiB
b4568c32 — Kuba Kleczkowski [MOS-977] Added VoLTE support in additional countries 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 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 <map>
#include <service-db/EntryPath.hpp>

using namespace settings;

TEST_CASE("Entry Path - is less comparison - different settings scope")
{
    EntryPath lhs{"mode", "service", "profile", "variable", SettingsScope::Global};
    EntryPath rhs{"mode", "service", "profile", "variable", SettingsScope::AppLocal};
    REQUIRE(lhs < rhs);
}

TEST_CASE("Entry Path - is less comparison - Global scope")
{
    SECTION("is lesser")
    {
        EntryPath lhs1{"mode", "service", "profile", "variableA", SettingsScope::Global};
        EntryPath rhs1{"mode", "service", "profile", "variableB", SettingsScope::Global};
        REQUIRE(lhs1 < rhs1);
    }

    SECTION("is equal")
    {
        EntryPath lhs2{"mode", "service", "profile", "variableA", SettingsScope::Global};
        EntryPath rhs2{"mode", "service", "profile", "variableA", SettingsScope::Global};
        REQUIRE(!(lhs2 < rhs2));
    }

    SECTION("is greater")
    {
        EntryPath lhs3{"mode", "service", "profile", "variableB", SettingsScope::Global};
        EntryPath rhs3{"mode", "service", "profile", "variableA", SettingsScope::Global};
        REQUIRE(!(lhs3 < rhs3));
    }
}

TEST_CASE("Entry Path - is less comparison - AppLocal scope")
{
    SECTION("All parts are lesser")
    {
        EntryPath lhs1{"modeA", "serviceA", "profileA", "variableA", SettingsScope::AppLocal};
        EntryPath rhs1{"modeB", "serviceB", "profileB", "variableB", SettingsScope::AppLocal};
        REQUIRE(lhs1 < rhs1);
    }

    SECTION("All parts are equal")
    {
        EntryPath lhs2{"modeA", "serviceA", "profileA", "variableA", SettingsScope::AppLocal};
        EntryPath rhs2{"modeA", "serviceA", "profileA", "variableA", SettingsScope::AppLocal};
        REQUIRE(!(lhs2 < rhs2));
    }

    SECTION("One part is lesser, others are equal")
    {
        EntryPath lhs3{"modeA", "serviceA", "profileA", "variableA", SettingsScope::AppLocal};
        EntryPath rhs3{"modeA", "serviceB", "profileA", "variableA", SettingsScope::AppLocal};
        REQUIRE(lhs3 < rhs3);
    }

    SECTION("Lesser part before greater part")
    {
        EntryPath lhs4{"modeA", "serviceA", "profileC", "variableA", SettingsScope::AppLocal};
        EntryPath rhs4{"modeB", "serviceA", "profileA", "variableA", SettingsScope::AppLocal};
        REQUIRE(lhs4 < rhs4);
    }
}

TEST_CASE("Entry Path - std::map::find - EGD-6486")
{
    EntryPath TestValGlobal1{"", "", "", "variableA", SettingsScope::Global};
    EntryPath TestValGlobal1Full{"Mode", "Service", "Profile", "variableA", SettingsScope::Global};
    EntryPath TestValLocal1{"", "", "", "variableA", SettingsScope::AppLocal};
    EntryPath TestValLocalBFull{"modeA", "serviceA", "profileC", "variableB", SettingsScope::AppLocal};

    std::map<EntryPath, std::string> map = {
        {TestValGlobal1, "1"},
        {TestValGlobal1, "2"},
        {TestValLocal1, "3"},
        {TestValLocalBFull, "3"},
    };

    REQUIRE(map.size() == 3);

    SECTION("Find global variable")
    {
        auto it1 = map.find(TestValGlobal1);
        REQUIRE(it1 != map.end());

        auto it2 = map.find(TestValGlobal1Full);
        REQUIRE(it2 != map.end());

        REQUIRE(it1 == it2);
    }

    SECTION("Find app local variable")
    {
        auto it = map.find(TestValLocalBFull);
        REQUIRE(it != map.end());
    }

    SECTION("Find app local variable - and erase")
    {
        auto it = map.find(TestValLocal1);
        REQUIRE(it != map.end());
        map.erase(it);

        auto it1 = map.find(TestValGlobal1);
        REQUIRE(it1 != map.end());
    }

    SECTION("Find app Global variable - and erase")
    {
        auto it1 = map.find(TestValGlobal1);
        REQUIRE(it1 != map.end());
        map.erase(it1);

        auto it = map.find(TestValLocal1);
        REQUIRE(it != map.end());
    }
}