2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-11-08 11:17:46 +01:00
|
|
|
|
2017-05-15 15:51:39 +02:00
|
|
|
#include "base/perfdatavalue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/dictionary.hpp"
|
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/application.hpp"
|
|
|
|
#include "base/type.hpp"
|
2024-09-10 09:28:28 +02:00
|
|
|
#include "icinga/host.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
2016-09-07 08:20:51 +02:00
|
|
|
#include <BoostTestTargetConfig.h>
|
2013-11-08 11:17:46 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2024-09-10 09:28:28 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE(types)
|
2013-11-08 11:17:46 +01:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(gettype)
|
|
|
|
{
|
2014-11-03 00:44:04 +01:00
|
|
|
Type::Ptr t = Type::GetByName("Application");
|
2013-11-08 11:17:46 +01:00
|
|
|
|
|
|
|
BOOST_CHECK(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(assign)
|
|
|
|
{
|
2014-11-03 00:44:04 +01:00
|
|
|
Type::Ptr t1 = Type::GetByName("Application");
|
2015-08-15 20:28:05 +02:00
|
|
|
Type::Ptr t2 = Type::GetByName("ConfigObject");
|
2013-11-08 11:17:46 +01:00
|
|
|
|
|
|
|
BOOST_CHECK(t1->IsAssignableFrom(t1));
|
|
|
|
BOOST_CHECK(t2->IsAssignableFrom(t1));
|
|
|
|
BOOST_CHECK(!t1->IsAssignableFrom(t2));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(byname)
|
|
|
|
{
|
2014-11-03 00:44:04 +01:00
|
|
|
Type::Ptr t = Type::GetByName("Application");
|
2013-11-08 11:17:46 +01:00
|
|
|
|
|
|
|
BOOST_CHECK(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(instantiate)
|
|
|
|
{
|
2014-11-03 00:44:04 +01:00
|
|
|
Type::Ptr t = Type::GetByName("PerfdataValue");
|
2013-11-08 11:17:46 +01:00
|
|
|
|
2016-03-29 14:42:32 +02:00
|
|
|
Object::Ptr p = t->Instantiate(std::vector<Value>());
|
2013-11-08 11:17:46 +01:00
|
|
|
|
|
|
|
BOOST_CHECK(p);
|
|
|
|
}
|
|
|
|
|
2024-09-10 09:28:28 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(sort_by_load_after)
|
|
|
|
{
|
|
|
|
int totalDependencies{0};
|
|
|
|
std::unordered_set<Type*> previousTypes;
|
|
|
|
for (auto type : Type::GetConfigTypesSortedByLoadDependencies()) {
|
|
|
|
BOOST_CHECK_EQUAL(true, ConfigObject::TypeInstance->IsAssignableFrom(type));
|
|
|
|
|
|
|
|
totalDependencies += type->GetLoadDependencies().size();
|
|
|
|
for (Type* dependency : type->GetLoadDependencies()) {
|
|
|
|
// Note, Type::GetConfigTypesSortedByLoadDependencies() does not detect any cyclic load dependencies,
|
|
|
|
// instead, it relies on this test case to fail.
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(dependency) != previousTypes.end(), "type '" << type->GetName()
|
|
|
|
<< "' depends on '"<< dependency->GetName() << "' type, but it's not loaded before");
|
|
|
|
}
|
|
|
|
|
|
|
|
previousTypes.emplace(type.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// The magic number 12 is the sum of host,service,comment,downtime and endpoint load_after dependencies.
|
|
|
|
BOOST_CHECK_MESSAGE(totalDependencies >= 12, "total size of load dependency must be at least 12");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Host::TypeInstance.get()) != previousTypes.end(), "Host type should be in the list");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Service::TypeInstance.get()) != previousTypes.end(), "Service type should be in the list");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Downtime::TypeInstance.get()) != previousTypes.end(), "Downtime type should be in the list");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Comment::TypeInstance.get()) != previousTypes.end(), "Comment type should be in the list");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Notification::TypeInstance.get()) != previousTypes.end(), "Notification type should be in the list");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Zone::TypeInstance.get()) != previousTypes.end(), "Zone type should be in the list");
|
|
|
|
BOOST_CHECK_MESSAGE(previousTypes.find(Endpoint::TypeInstance.get()) != previousTypes.end(), "Endpoint type should be in the list");
|
|
|
|
}
|
|
|
|
|
2013-11-08 11:17:46 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|