-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from lo-simon/is-14-get_properties_by_path-error
IS-14: Fix get_properties_by_path bug
- Loading branch information
Showing
3 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// The first "test" is of course whether the header compiles standalone | ||
#include "nmos/control_protocol_resource.h" | ||
#include "nmos/control_protocol_resources.h" | ||
#include "nmos/control_protocol_state.h" | ||
#include "nmos/control_protocol_typedefs.h" | ||
#include "nmos/control_protocol_utils.h" | ||
#include "nmos/configuration_handlers.h" | ||
#include "nmos/configuration_resources.h" | ||
#include "nmos/configuration_methods.h" | ||
#include "nmos/configuration_utils.h" | ||
|
||
#include "bst/test/test.h" | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////////////// | ||
BST_TEST_CASE(testGetPropertiesByPath) | ||
{ | ||
using web::json::value_of; | ||
using web::json::value; | ||
|
||
nmos::resources resources; | ||
nmos::experimental::control_protocol_state control_protocol_state; | ||
nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor = nmos::make_get_control_protocol_class_descriptor_handler(control_protocol_state); | ||
nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor = nmos::make_get_control_protocol_datatype_descriptor_handler(control_protocol_state); | ||
|
||
// Create Device Model | ||
// root | ||
auto root_block = nmos::make_root_block(); | ||
auto oid = nmos::root_block_oid; | ||
// root, ClassManager | ||
auto class_manager = nmos::make_class_manager(++oid, control_protocol_state); | ||
auto receiver_block_oid = ++oid; | ||
// root, receivers | ||
auto receivers = nmos::make_block(receiver_block_oid, nmos::root_block_oid, U("receivers"), U("Receivers"), U("Receivers block")); | ||
nmos::make_rebuildable(receivers); | ||
// root, receivers, mon1 | ||
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")})}})); | ||
// make monitor1 rebuildable | ||
nmos::make_rebuildable(monitor1); | ||
|
||
auto monitor_class_id = nmos::details::parse_nc_class_id(nmos::fields::nc::class_id(monitor1.data)); | ||
// root, receivers, mon2 | ||
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")})} })); | ||
nmos::nc::push_back(receivers, monitor1); | ||
// add example-control to root-block | ||
nmos::nc::push_back(receivers, monitor2); | ||
// add stereo-gain to root-block | ||
nmos::nc::push_back(root_block, receivers); | ||
// add class-manager to root-block | ||
nmos::nc::push_back(root_block, class_manager); | ||
insert_resource(resources, std::move(root_block)); | ||
insert_resource(resources, std::move(class_manager)); | ||
insert_resource(resources, std::move(receivers)); | ||
insert_resource(resources, std::move(monitor1)); | ||
insert_resource(resources, std::move(monitor2)); | ||
|
||
{ | ||
const auto target_role_path = value_of({ U("root") }); | ||
const auto& resource = nmos::nc::find_resource_by_role_path(resources, target_role_path.as_array()); | ||
auto method_result = get_properties_by_path(resources, *resource, true, get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor); | ||
|
||
BST_REQUIRE_EQUAL(nmos::nc_method_status::ok, nmos::fields::nc::status(method_result)); | ||
|
||
const auto& bulk_values_holder = nmos::fields::nc::value(method_result); | ||
const auto& object_properties_holders = nmos::fields::nc::values(bulk_values_holder); | ||
|
||
BST_REQUIRE_EQUAL(5, object_properties_holders.size()); | ||
} | ||
{ | ||
const auto target_role_path = value_of({ U("root"), U("receivers") }); | ||
const auto& resource = nmos::nc::find_resource_by_role_path(resources, target_role_path.as_array()); | ||
auto method_result = get_properties_by_path(resources, *resource, true, get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor); | ||
|
||
BST_REQUIRE_EQUAL(nmos::nc_method_status::ok, nmos::fields::nc::status(method_result)); | ||
|
||
const auto& bulk_values_holder = nmos::fields::nc::value(method_result); | ||
const auto& object_properties_holders = nmos::fields::nc::values(bulk_values_holder); | ||
|
||
BST_REQUIRE_EQUAL(3, object_properties_holders.size()); | ||
} | ||
{ | ||
const auto target_role_path = value_of({ U("root"), U("receivers"), U("mon1") }); | ||
const auto& resource = nmos::nc::find_resource_by_role_path(resources, target_role_path.as_array()); | ||
auto method_result = get_properties_by_path(resources, *resource, true, get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor); | ||
|
||
BST_REQUIRE_EQUAL(nmos::nc_method_status::ok, nmos::fields::nc::status(method_result)); | ||
|
||
const auto& bulk_values_holder = nmos::fields::nc::value(method_result); | ||
const auto& object_properties_holders = nmos::fields::nc::values(bulk_values_holder); | ||
|
||
BST_REQUIRE_EQUAL(1, object_properties_holders.size()); | ||
} | ||
} |