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
|
/************************************************************************
*
* Copyright (C) 2009-2023 IRCAD France
* Copyright (C) 2012-2020 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 "activity_test.hpp"
#include <data/integer.hpp>
#include <data/string.hpp>
#include <ranges>
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(sight::data::ut::activity_test);
namespace sight::data::ut
{
//------------------------------------------------------------------------------
void activity_test::setUp()
{
// Set up context before running a test.
m_activity = std::make_shared<data::activity>();
}
//------------------------------------------------------------------------------
void activity_test::tearDown()
{
// Clean up after the test run.
m_activity.reset();
}
//------------------------------------------------------------------------------
void activity_test::activity_config_id_test()
{
const data::activity::config_id_t activity_config_id = "Visu2D";
CPPUNIT_ASSERT(m_activity);
m_activity->set_activity_config_id(activity_config_id);
CPPUNIT_ASSERT_EQUAL(activity_config_id, m_activity->get_activity_config_id());
auto activity2 = std::make_shared<data::activity>();
CPPUNIT_ASSERT(*activity2 != *m_activity);
std::ranges::copy(*m_activity, std::inserter(*activity2, activity2->begin()));
activity2->set_activity_config_id(m_activity->get_activity_config_id());
CPPUNIT_ASSERT(*activity2 == *m_activity);
}
//------------------------------------------------------------------------------
void activity_test::data_test()
{
auto activity2 = std::make_shared<data::activity>();
CPPUNIT_ASSERT(m_activity);
CPPUNIT_ASSERT(activity2);
// Both data are "empty"
CPPUNIT_ASSERT(*activity2 == *m_activity);
std::ranges::copy(*m_activity, std::inserter(*activity2, activity2->begin()));
activity2->set_activity_config_id(m_activity->get_activity_config_id());
CPPUNIT_ASSERT(*activity2 == *m_activity);
}
//------------------------------------------------------------------------------
void activity_test::equality_test()
{
auto activity1 = std::make_shared<data::activity>();
auto activity2 = std::make_shared<data::activity>();
CPPUNIT_ASSERT(*activity1 == *activity2 && !(*activity1 != *activity2));
activity1->set_activity_config_id("1");
CPPUNIT_ASSERT(*activity1 != *activity2 && !(*activity1 == *activity2));
activity2->set_activity_config_id(activity1->get_activity_config_id());
CPPUNIT_ASSERT(*activity1 == *activity2 && !(*activity1 != *activity2));
(*activity1)["data"] = std::make_shared<data::integer>(2);
CPPUNIT_ASSERT(*activity1 != *activity2 && !(*activity1 == *activity2));
std::ranges::copy(*activity1, std::inserter(*activity2, activity2->begin()));
CPPUNIT_ASSERT(*activity1 == *activity2 && !(*activity1 != *activity2));
}
//------------------------------------------------------------------------------
void activity_test::shallow_copy_test()
{
CPPUNIT_ASSERT(m_activity);
m_activity->set_activity_config_id("MyActivity");
(*m_activity)["data"] = std::make_shared<data::string>("Hello world");
auto activity2 = std::make_shared<data::activity>();
CPPUNIT_ASSERT(*m_activity != *activity2);
activity2->shallow_copy(m_activity);
CPPUNIT_ASSERT(*m_activity == *activity2);
}
} //namespace sight::data::ut
|