|
7 | 7 | #include "base/type.hpp" |
8 | 8 | #include <BoostTestTargetConfig.h> |
9 | 9 |
|
| 10 | +#include "icinga/service.hpp" |
| 11 | + |
10 | 12 | using namespace icinga; |
11 | 13 |
|
12 | 14 | BOOST_AUTO_TEST_SUITE(base_type) |
@@ -44,4 +46,36 @@ BOOST_AUTO_TEST_CASE(instantiate) |
44 | 46 | BOOST_CHECK(p); |
45 | 47 | } |
46 | 48 |
|
| 49 | +BOOST_AUTO_TEST_CASE(sort_by_load_after) |
| 50 | +{ |
| 51 | + auto types (Type::GetConfigTypesSortedByLoadDependencies()); |
| 52 | + BOOST_REQUIRE_GE(types.size(), 29); |
| 53 | + |
| 54 | + std::unordered_set<Type*> previousTypes; |
| 55 | + for (auto type : types) { |
| 56 | + BOOST_CHECK_EQUAL(true, ConfigObject::TypeInstance->IsAssignableFrom(type)); |
| 57 | + |
| 58 | + if (previousTypes.size() == 0) { |
| 59 | + BOOST_CHECK_EQUAL(0, type->GetLoadDependencies().size()); |
| 60 | + } else { |
| 61 | + if (Service::TypeInstance->IsAssignableFrom(type) || Endpoint::TypeInstance->IsAssignableFrom(type)) { |
| 62 | + BOOST_CHECK_MESSAGE(type->GetLoadDependencies().size() > 0, "load dependencies must be non-zero"); |
| 63 | + } |
| 64 | + |
| 65 | + for (Type* dependency : type->GetLoadDependencies()) { |
| 66 | + BOOST_CHECK_MESSAGE(previousTypes.find(dependency) != previousTypes.end(), "type '" << type->GetName() |
| 67 | + << "' depends on '"<< dependency->GetName() << "' type, but it's not loaded before"); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + previousTypes.emplace(type.get()); |
| 72 | + } |
| 73 | + |
| 74 | + BOOST_CHECK_MESSAGE(previousTypes.find(Host::TypeInstance.get()) != previousTypes.end(), "host type should be in the list"); |
| 75 | + BOOST_CHECK_MESSAGE(previousTypes.find(Service::TypeInstance.get()) != previousTypes.end(), "service type should be in the list"); |
| 76 | + BOOST_CHECK_MESSAGE(previousTypes.find(Endpoint::TypeInstance.get()) != previousTypes.end(), "endpoint type should be in the list"); |
| 77 | + BOOST_CHECK_MESSAGE(previousTypes.find(Downtime::TypeInstance.get()) != previousTypes.end(), "downtime type should be in the list"); |
| 78 | + BOOST_CHECK_MESSAGE(previousTypes.find(Comment::TypeInstance.get()) != previousTypes.end(), "comment type should be in the list"); |
| 79 | +} |
| 80 | + |
47 | 81 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments