File: config_update_test.cpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (145 lines) | stat: -rw-r--r-- 4,582 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/************************************************************************
 *
 * Copyright (C) 2009-2024 IRCAD France
 * Copyright (C) 2012-2021 IHU Strasbourg
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#include "config_update_test.hpp"

#include "helper.hpp"
#include "test_service.hpp"
#include "test_services.hpp"

#include <core/com/signal.hpp>
#include <core/com/signal.hxx>
#include <core/com/slot.hxx>
#include <core/runtime/helper.hpp>
#include <core/runtime/path.hpp>
#include <core/runtime/runtime.hpp>
#include <core/time_stamp.hpp>

#include <data/boolean.hpp>
#include <data/image.hpp>
#include <data/string.hpp>

#include <service/extension/config.hpp>
#include <service/registry.hpp>

#include <utest/wait.hpp>

#include <filesystem>
#include <ranges>

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(sight::app::ut::config_update_test);

namespace sight::app::ut
{

//------------------------------------------------------------------------------

void config_update_test::setUp()
{
    // Set up context before running a test.
    core::runtime::init();

    std::filesystem::path location = core::runtime::get_resource_file_path("app_ut");
    CPPUNIT_ASSERT(std::filesystem::exists(location));

    core::runtime::add_modules(location);
    core::runtime::load_module("sight::module::app");
    core::runtime::load_module("config_update_test");

    auto app_config = app::extension::config::get();
    app_config->clear_registry();
    app_config->parse_plugin_infos();

    auto srv_config = sight::service::extension::config::get_default();
    srv_config->clear_registry();
    srv_config->parse_plugin_infos();
}

//------------------------------------------------------------------------------

void config_update_test::tearDown()
{
    // Clean up after the test run.
    if(m_app_config_mgr)
    {
        // If everything went well, the manager should have been destroyed
        // This means a test failed, thus we need to clean everything properly, otherwise
        // We will get an assert from the destructor and we will not get the cppunit report in the console
        m_app_config_mgr->stop_and_destroy();
        m_app_config_mgr = nullptr;
    }
}

//------------------------------------------------------------------------------

const auto TEST_SERVICE =
    [](unsigned int _i)
    {
        core::object::sptr service = core::id::get_object("test" + std::to_string(_i) + "_srv");
        auto srv                   = std::dynamic_pointer_cast<sight::app::ut::test_order_srv>(service);
        CPPUNIT_ASSERT_EQUAL(true, srv->started());
        SIGHT_TEST_WAIT(srv->update_order() == _i);
        CPPUNIT_ASSERT_EQUAL(_i, srv->update_order());
    };

//------------------------------------------------------------------------------

void config_update_test::simple_sequence_test()
{
    test_order_srv::s_ORDER = 1;
    m_app_config_mgr        = app::ut::launch_app_config_mgr("sequence_cfg_test");

    for(const auto i : std::views::iota(1U, 4U))
    {
        TEST_SERVICE(i);
    }
}

//------------------------------------------------------------------------------

void config_update_test::imbricated_sequence_test()
{
    test_order_srv::s_ORDER = 1;
    m_app_config_mgr        = app::ut::launch_app_config_mgr("imbricated_sequence_cfg_test");

    for(const auto i : std::views::iota(1U, 7U))
    {
        TEST_SERVICE(i);
    }
}

//------------------------------------------------------------------------------

void config_update_test::mutiple_config_sequence_test()
{
    test_order_srv::s_ORDER = 1;
    m_app_config_mgr        = app::ut::launch_app_config_mgr("mutiple_config_sequence_cfg_test");

    TEST_SERVICE(1);
    TEST_SERVICE(4);
    TEST_SERVICE(7);
}

//------------------------------------------------------------------------------

} // namespace sight::app::ut