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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/************************************************************************
*
* 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_point_test.hpp"
#include <core/runtime/runtime.hpp>
#include <data/image_series.hpp>
#include <data/point.hpp>
#include <service/op.hpp>
#include <boost/property_tree/xml_parser.hpp>
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(sight::module::data::ut::get_point_test);
namespace sight::module::data::ut
{
class tester final
{
public:
tester()
{
// Create service
srv = sight::service::add("sight::module::data::get_point");
CPPUNIT_ASSERT(srv);
CPPUNIT_ASSERT(srv->is_a("sight::module::data::get_point"));
// Create data
image = std::make_shared<sight::data::image_series>();
CPPUNIT_ASSERT(image);
auto fiducials = image->get_fiducials();
fiducials->add_group("test_group_1", {1.0, 0.0, 1.0, 1.0}, 3.F);
fiducials->add_point("test_group_1", {1.0, 80.0, 2.0});
fiducials->add_point("test_group_1", {-1.0, 5.0, -2.0});
fiducials->add_group("test_group_2", {1.0, 0.0, 1.0, 1.0}, 3.F);
fiducials->add_point("test_group_2", {6.0, 4.0, 7.0});
fiducials->add_point("test_group_2", {8.0, 9.0, -20.0});
point0 = std::make_shared<sight::data::point>();
CPPUNIT_ASSERT(point0);
point1 = std::make_shared<sight::data::point>();
CPPUNIT_ASSERT(point1);
point2 = std::make_shared<sight::data::point>();
CPPUNIT_ASSERT(point2);
}
//------------------------------------------------------------------------------
~tester()
{
if(srv->started())
{
srv->stop().get();
}
sight::service::remove(srv);
}
//------------------------------------------------------------------------------
sight::service::base::sptr srv;
sight::data::image_series::sptr image;
sight::data::point::sptr point0;
sight::data::point::sptr point1;
sight::data::point::sptr point2;
};
//------------------------------------------------------------------------------
void get_point_test::setUp()
{
// Set up context before running a test.
core::runtime::init();
auto module = core::runtime::load_module(std::string("sight::module::data"));
}
//------------------------------------------------------------------------------
void get_point_test::tearDown()
{
}
//------------------------------------------------------------------------------
void get_point_test::extracts_point_by_index()
{
tester srv_tester;
service::config_t config;
std::stringstream config_string;
config_string
<< R"(<inout group="points">)"
R"(<key group="test_group_2" index="1" uid="output_point0"/>)"
R"(<key group="test_group_1" index="0" uid="output_point1"/>)"
R"(<key group="test_group_1" index="1" uid="output_point2"/>)"
R"(</inout>)";
boost::property_tree::read_xml(config_string, config);
srv_tester.srv->set_config(config);
srv_tester.srv->set_input(srv_tester.image, "image");
srv_tester.srv->set_inout(srv_tester.point0, "points", false, false, 0);
srv_tester.srv->set_inout(srv_tester.point1, "points", false, false, 1);
srv_tester.srv->set_inout(srv_tester.point2, "points", false, false, 2);
srv_tester.srv->configure();
srv_tester.srv->start().get();
CPPUNIT_ASSERT_NO_THROW(srv_tester.srv->update().get());
CPPUNIT_ASSERT(sight::data::point({8.0, 9.0, -20.0}) == *srv_tester.point0);
CPPUNIT_ASSERT(sight::data::point({1.0, 80.0, 2.0}) == *srv_tester.point1);
CPPUNIT_ASSERT(sight::data::point({-1.0, 5.0, -2.0}) == *srv_tester.point2);
}
//------------------------------------------------------------------------------
void get_point_test::extracts_point_with_index_out_of_bound()
{
tester srv_tester;
service::config_t config;
std::stringstream config_string;
config_string
<< R"(<inout group="points">)"
R"(<key group="test_group_1" index="1" uid="output_point0"/>)"
R"(<key group="test_group_1" index="122" uid="output_point1"/>)"
R"(<key group="test_group_1" index="0" uid="output_point2"/>)"
R"(</inout>)";
boost::property_tree::read_xml(config_string, config);
srv_tester.srv->set_config(config);
srv_tester.srv->set_input(srv_tester.image, "image");
srv_tester.srv->set_inout(srv_tester.point0, "points", false, false, 0);
srv_tester.srv->set_inout(srv_tester.point1, "points", false, false, 1);
srv_tester.srv->set_inout(srv_tester.point2, "points", false, false, 2);
srv_tester.srv->configure();
srv_tester.srv->start().get();
CPPUNIT_ASSERT_THROW(srv_tester.srv->update().get(), sight::core::exception);
CPPUNIT_ASSERT(sight::data::point({-1.0, 5.0, -2.0}) == *srv_tester.point0);
CPPUNIT_ASSERT(sight::data::point({0.0, 0.0, 0.0}) == *srv_tester.point1); // Failed starting from there
CPPUNIT_ASSERT(sight::data::point({0.0, 0.0, 0.0}) == *srv_tester.point2);
}
//------------------------------------------------------------------------------
void get_point_test::extracts_point_with_unknown_group()
{
tester srv_tester;
service::config_t config;
std::stringstream config_string;
config_string
<< R"(<inout group="points">)"
R"(<key group="test_group_1" index="1" uid="output_point0"/>)"
R"(<key group="unknown" index="2" uid="output_point1"/>)"
R"(<key group="test_group_1" index="0" uid="output_point2"/>)"
R"(</inout>)";
boost::property_tree::read_xml(config_string, config);
srv_tester.srv->set_config(config);
srv_tester.srv->set_input(srv_tester.image, "image");
srv_tester.srv->set_inout(srv_tester.point0, "points", false, false, 0);
srv_tester.srv->set_inout(srv_tester.point1, "points", false, false, 1);
srv_tester.srv->set_inout(srv_tester.point2, "points", false, false, 2);
srv_tester.srv->configure();
srv_tester.srv->start().get();
CPPUNIT_ASSERT_THROW(srv_tester.srv->update().get(), sight::core::exception);
CPPUNIT_ASSERT(sight::data::point({-1.0, 5.0, -2.0}) == *srv_tester.point0);
CPPUNIT_ASSERT(sight::data::point({0.0, 0.0, 0.0}) == *srv_tester.point1); // Failed starting from there
CPPUNIT_ASSERT(sight::data::point({0.0, 0.0, 0.0}) == *srv_tester.point2);
}
//------------------------------------------------------------------------------
} // namespace sight::module::data::ut
|