Skip to content

Commit

Permalink
Merge pull request #14 from lo-simon/is-14-get_properties_by_path-error
Browse files Browse the repository at this point in the history
IS-14: Fix get_properties_by_path bug
  • Loading branch information
lo-simon authored Jan 29, 2025
2 parents 4eb2690 + 38a424e commit dd80d6b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions Development/cmake/NmosCppTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(NMOS_CPP_TEST_NMOS_TEST_SOURCES
nmos/test/api_utils_test.cpp
nmos/test/capabilities_test.cpp
nmos/test/channels_test.cpp
nmos/test/configuration_methods_test.cpp
nmos/test/configuration_resources_test.cpp
nmos/test/configuration_utils_test.cpp
nmos/test/control_protocol_test.cpp
Expand Down
7 changes: 3 additions & 4 deletions Development/nmos/configuration_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
#include "nmos/control_protocol_resources.h"
#include "nmos/control_protocol_state.h"
#include "nmos/control_protocol_utils.h"
#include "nmos/slog.h"

namespace nmos
{
namespace details
{
web::json::value make_property_value_holders(const nmos::resource& resource, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor)
web::json::array make_property_value_holders(const nmos::resource& resource, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor)
{
using web::json::value;

Expand All @@ -35,15 +34,15 @@ namespace nmos
}
class_id.pop_back();
}
return property_value_holders;
return property_value_holders.as_array();
}

void populate_object_property_holder(const nmos::resources& resources, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, const nmos::resource& resource, bool recurse, web::json::value& object_properties_holders)
{
using web::json::value;

// Get property_value_holders for this resource
const auto& property_value_holders = make_property_value_holders(resource, get_control_protocol_class_descriptor).as_array();
const auto& property_value_holders = make_property_value_holders(resource, get_control_protocol_class_descriptor);

const auto role_path = get_role_path(resources, resource);

Expand Down
93 changes: 93 additions & 0 deletions Development/nmos/test/configuration_methods_test.cpp
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());
}
}

0 comments on commit dd80d6b

Please sign in to comment.