File: option_base_test.cpp

package info (click to toggle)
wf-config 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: cpp: 5,743; xml: 37; makefile: 4
file content (87 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download | duplicates (3)
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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <wayfire/config/option.hpp>

class option_base_stub_t : public wf::config::option_base_t
{
  public:
    option_base_stub_t(std::string name) :
        option_base_t(name)
    {}

    std::shared_ptr<option_base_t> clone_option() const override
    {
        return nullptr;
    }

    bool set_default_value_str(const std::string&) override
    {
        return true;
    }

    bool set_value_str(const std::string&) override
    {
        return false;
    }

    void reset_to_default() override
    {}
    std::string get_value_str() const override
    {
        return "";
    }

    std::string get_default_value_str() const override
    {
        return "";
    }

  public:
    void notify_updated() const
    {
        option_base_t::notify_updated();
    }
};


TEST_CASE("wf::option_base_t")
{
    option_base_stub_t option{"string"};
    CHECK(option.get_name() == "string");

    int callback_called  = 0;
    int callback2_called = 0;

    wf::config::option_base_t::updated_callback_t callback, callback2;
    callback  = [&] () { callback_called++; };
    callback2 = [&] () { callback2_called++; };

    option.add_updated_handler(&callback);
    option.notify_updated();
    CHECK(callback_called == 1);
    CHECK(callback2_called == 0);

    option.add_updated_handler(&callback);
    option.add_updated_handler(&callback2);
    option.notify_updated();
    CHECK(callback_called == 3);
    CHECK(callback2_called == 1);

    option.rem_updated_handler(&callback);
    option.notify_updated();
    CHECK(callback_called == 3);
    CHECK(callback2_called == 2);

    option.rem_updated_handler(&callback2);
    option.notify_updated();
    CHECK(callback_called == 3);
    CHECK(callback2_called == 2);

    option.set_locked();
    CHECK(option.is_locked());
    option.set_locked();
    option.set_locked(false);
    CHECK(option.is_locked());
    option.set_locked(false);
    CHECK(option.is_locked() == false);
}