File: get_activity_object_test.cpp

package info (click to toggle)
sight 25.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,252 kB
  • sloc: cpp: 310,629; xml: 17,622; ansic: 9,960; python: 1,379; sh: 144; makefile: 33
file content (166 lines) | stat: -rw-r--r-- 5,786 bytes parent folder | download
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/************************************************************************
 *
 * Copyright (C) 2025 IRCAD France
 *
 * 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 "get_activity_object_test.hpp"

#include <core/runtime/runtime.hpp>

#include <data/activity_set.hpp>
#include <data/image_series.hpp>
#include <data/model_series.hpp>

#include <service/op.hpp>

#include <boost/property_tree/xml_parser.hpp>

#include <sstream>

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(sight::module::data::ut::get_activity_object_test);

namespace sight::module::data::ut
{

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

void get_activity_object_test::setUp()
{
}

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

void get_activity_object_test::tearDown()
{
}

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

void get_activity_object_test::extract_objects()
{
    auto activity_set = std::make_shared<sight::data::activity_set>();

    sight::service::base::sptr srv = sight::service::add("sight::module::data::get_activity_object");
    CPPUNIT_ASSERT(srv);
    CPPUNIT_ASSERT(srv->is_a("sight::module::data::get_activity_object"));

    // create different series
    sight::data::series::sptr series1 = std::make_shared<sight::data::model_series>();
    sight::data::series::sptr series2 = std::make_shared<sight::data::image_series>();
    sight::data::series::sptr series3 = std::make_shared<sight::data::model_series>();
    sight::data::series::sptr series4 = std::make_shared<sight::data::image_series>();
    sight::data::series::sptr series5 = std::make_shared<sight::data::model_series>();
    sight::data::series::sptr series6 = std::make_shared<sight::data::model_series>();

    sight::data::activity::sptr activity1 = std::make_shared<sight::data::activity>();
    sight::data::activity::sptr activity2 = std::make_shared<sight::data::activity>();

    activity1->set_activity_config_id("config1");
    activity2->set_activity_config_id("config2");
    CPPUNIT_ASSERT(activity1->empty());
    CPPUNIT_ASSERT(activity2->empty());

    (*activity1)["req1"] = series1;
    (*activity1)["req2"] = series2;
    (*activity1)["req3"] = series3;

    (*activity2)["req1"] = series4;
    (*activity2)["req2"] = series5;
    (*activity2)["req3"] = series6;

    CPPUNIT_ASSERT(activity_set->empty());

    activity_set->push_back(activity1);
    activity_set->push_back(activity2);

    service::config_t config;
    std::stringstream config_string;
    config_string
    << R"(<id>config1</id>)"
       R"(<out group="objects">)"
       R"(<key name="req1" uid="object1"/>)"
       R"(<key name="req2" uid="object2"/>)"
       R"(</out>)";
    boost::property_tree::read_xml(config_string, config);
    srv->set_config(config);
    srv->set_input(activity_set, "activity_set");
    srv->configure();
    srv->start().wait();
    srv->update().wait();

    CPPUNIT_ASSERT(*srv->output("objects", 0).lock() == *series1);
    CPPUNIT_ASSERT(*srv->output("objects", 1).lock() == *series2);

    activity1->erase("req2");

    CPPUNIT_ASSERT_NO_THROW(srv->update().get());

    CPPUNIT_ASSERT(*srv->output("objects", 0).lock() == *series1);
    CPPUNIT_ASSERT(srv->output("objects", 1).lock() == nullptr);

    activity_set->clear();
    CPPUNIT_ASSERT_THROW(srv->update().get(), sight::data::exception);

    CPPUNIT_ASSERT(srv->output("objects", 0).lock() == nullptr);
    CPPUNIT_ASSERT(srv->output("objects", 1).lock() == nullptr);

    srv->stop().wait();
    sight::service::remove(srv);
}

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

void get_activity_object_test::invalid_activity()
{
    auto activity_set = std::make_shared<sight::data::activity_set>();

    sight::service::base::sptr srv = sight::service::add("sight::module::data::get_activity_object");
    CPPUNIT_ASSERT(srv);
    CPPUNIT_ASSERT(srv->is_a("sight::module::data::get_activity_object"));

    // create different series
    sight::data::series::sptr series1     = std::make_shared<sight::data::model_series>();
    sight::data::activity::sptr activity1 = std::make_shared<sight::data::activity>();
    activity1->set_activity_config_id("config1");
    (*activity1)["req1"] = series1;
    activity_set->push_back(activity1);

    service::config_t config;
    std::stringstream config_string;
    config_string
    << R"(<id>config_unknown</id>)"
       R"(<out group="objects">)"
       R"(<key name="req1" uid="object1"/>)"
       R"(<key name="req2" uid="object2"/>)"
       R"(</out>)";
    boost::property_tree::read_xml(config_string, config);
    srv->set_config(config);
    srv->set_input(activity_set, "activity_set");
    srv->configure();
    srv->start().wait();
    CPPUNIT_ASSERT_THROW(srv->update().get(), sight::data::exception);

    srv->stop().wait();
    sight::service::remove(srv);
}

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

} // namespace sight::module::data::ut