|
| 1 | +// The first "test" is of course whether the header compiles standalone |
| 2 | +#include "nmos/control_protocol_resource.h" |
| 3 | +#include "nmos/control_protocol_resources.h" |
| 4 | +#include "nmos/control_protocol_state.h" |
| 5 | +#include "nmos/control_protocol_typedefs.h" |
| 6 | +#include "nmos/control_protocol_utils.h" |
| 7 | +#include "nmos/configuration_handlers.h" |
| 8 | +#include "nmos/configuration_resources.h" |
| 9 | +#include "nmos/configuration_methods.h" |
| 10 | +#include "nmos/configuration_utils.h" |
| 11 | + |
| 12 | +#include "bst/test/test.h" |
| 13 | + |
| 14 | + |
| 15 | +//////////////////////////////////////////////////////////////////////////////////////////// |
| 16 | +BST_TEST_CASE(testGetPropertiesByPath) |
| 17 | +{ |
| 18 | + using web::json::value_of; |
| 19 | + using web::json::value; |
| 20 | + |
| 21 | + nmos::resources resources; |
| 22 | + nmos::experimental::control_protocol_state control_protocol_state; |
| 23 | + nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor = nmos::make_get_control_protocol_class_descriptor_handler(control_protocol_state); |
| 24 | + nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor = nmos::make_get_control_protocol_datatype_descriptor_handler(control_protocol_state); |
| 25 | + |
| 26 | + // Create Device Model |
| 27 | + // root |
| 28 | + auto root_block = nmos::make_root_block(); |
| 29 | + auto oid = nmos::root_block_oid; |
| 30 | + // root, ClassManager |
| 31 | + auto class_manager = nmos::make_class_manager(++oid, control_protocol_state); |
| 32 | + auto receiver_block_oid = ++oid; |
| 33 | + // root, receivers |
| 34 | + auto receivers = nmos::make_block(receiver_block_oid, nmos::root_block_oid, U("receivers"), U("Receivers"), U("Receivers block")); |
| 35 | + nmos::make_rebuildable(receivers); |
| 36 | + // root, receivers, mon1 |
| 37 | + auto monitor1 = nmos::make_receiver_monitor(++oid, true, receiver_block_oid, U("mon1"), U("monitor 1"), U("monitor 1"), value_of({{nmos::details::make_nc_touchpoint_nmos({nmos::ncp_touchpoint_resource_types::receiver, U("id_1")})}})); |
| 38 | + // make monitor1 rebuildable |
| 39 | + nmos::make_rebuildable(monitor1); |
| 40 | + |
| 41 | + auto monitor_class_id = nmos::details::parse_nc_class_id(nmos::fields::nc::class_id(monitor1.data)); |
| 42 | + // root, receivers, mon2 |
| 43 | + auto monitor2 = nmos::make_receiver_monitor(++oid, true, receiver_block_oid, U("mon2"), U("monitor 2"), U("monitor 2"), value_of({ {nmos::details::make_nc_touchpoint_nmos({nmos::ncp_touchpoint_resource_types::receiver, U("id_2")})} })); |
| 44 | + nmos::nc::push_back(receivers, monitor1); |
| 45 | + // add example-control to root-block |
| 46 | + nmos::nc::push_back(receivers, monitor2); |
| 47 | + // add stereo-gain to root-block |
| 48 | + nmos::nc::push_back(root_block, receivers); |
| 49 | + // add class-manager to root-block |
| 50 | + nmos::nc::push_back(root_block, class_manager); |
| 51 | + insert_resource(resources, std::move(root_block)); |
| 52 | + insert_resource(resources, std::move(class_manager)); |
| 53 | + insert_resource(resources, std::move(receivers)); |
| 54 | + insert_resource(resources, std::move(monitor1)); |
| 55 | + insert_resource(resources, std::move(monitor2)); |
| 56 | + |
| 57 | + { |
| 58 | + const auto target_role_path = value_of({ U("root") }); |
| 59 | + const auto& resource = nmos::nc::find_resource_by_role_path(resources, target_role_path.as_array()); |
| 60 | + auto method_result = get_properties_by_path(resources, *resource, true, get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor); |
| 61 | + |
| 62 | + BST_REQUIRE_EQUAL(nmos::nc_method_status::ok, nmos::fields::nc::status(method_result)); |
| 63 | + |
| 64 | + const auto& bulk_values_holder = nmos::fields::nc::value(method_result); |
| 65 | + const auto& object_properties_holders = nmos::fields::nc::values(bulk_values_holder); |
| 66 | + |
| 67 | + BST_REQUIRE_EQUAL(5, object_properties_holders.size()); |
| 68 | + } |
| 69 | + { |
| 70 | + const auto target_role_path = value_of({ U("root"), U("receivers") }); |
| 71 | + const auto& resource = nmos::nc::find_resource_by_role_path(resources, target_role_path.as_array()); |
| 72 | + auto method_result = get_properties_by_path(resources, *resource, true, get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor); |
| 73 | + |
| 74 | + BST_REQUIRE_EQUAL(nmos::nc_method_status::ok, nmos::fields::nc::status(method_result)); |
| 75 | + |
| 76 | + const auto& bulk_values_holder = nmos::fields::nc::value(method_result); |
| 77 | + const auto& object_properties_holders = nmos::fields::nc::values(bulk_values_holder); |
| 78 | + |
| 79 | + BST_REQUIRE_EQUAL(3, object_properties_holders.size()); |
| 80 | + } |
| 81 | + { |
| 82 | + const auto target_role_path = value_of({ U("root"), U("receivers"), U("mon1") }); |
| 83 | + const auto& resource = nmos::nc::find_resource_by_role_path(resources, target_role_path.as_array()); |
| 84 | + auto method_result = get_properties_by_path(resources, *resource, true, get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor); |
| 85 | + |
| 86 | + BST_REQUIRE_EQUAL(nmos::nc_method_status::ok, nmos::fields::nc::status(method_result)); |
| 87 | + |
| 88 | + const auto& bulk_values_holder = nmos::fields::nc::value(method_result); |
| 89 | + const auto& object_properties_holders = nmos::fields::nc::values(bulk_values_holder); |
| 90 | + |
| 91 | + BST_REQUIRE_EQUAL(1, object_properties_holders.size()); |
| 92 | + } |
| 93 | +} |
0 commit comments