Skip to content

Commit dd80d6b

Browse files
authored
Merge pull request #14 from lo-simon/is-14-get_properties_by_path-error
IS-14: Fix get_properties_by_path bug
2 parents 4eb2690 + 38a424e commit dd80d6b

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

Development/cmake/NmosCppTest.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ set(NMOS_CPP_TEST_NMOS_TEST_SOURCES
4343
nmos/test/api_utils_test.cpp
4444
nmos/test/capabilities_test.cpp
4545
nmos/test/channels_test.cpp
46+
nmos/test/configuration_methods_test.cpp
4647
nmos/test/configuration_resources_test.cpp
4748
nmos/test/configuration_utils_test.cpp
4849
nmos/test/control_protocol_test.cpp

Development/nmos/configuration_methods.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
#include "nmos/control_protocol_resources.h"
99
#include "nmos/control_protocol_state.h"
1010
#include "nmos/control_protocol_utils.h"
11-
#include "nmos/slog.h"
1211

1312
namespace nmos
1413
{
1514
namespace details
1615
{
17-
web::json::value make_property_value_holders(const nmos::resource& resource, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor)
16+
web::json::array make_property_value_holders(const nmos::resource& resource, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor)
1817
{
1918
using web::json::value;
2019

@@ -35,15 +34,15 @@ namespace nmos
3534
}
3635
class_id.pop_back();
3736
}
38-
return property_value_holders;
37+
return property_value_holders.as_array();
3938
}
4039

4140
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)
4241
{
4342
using web::json::value;
4443

4544
// Get property_value_holders for this resource
46-
const auto& property_value_holders = make_property_value_holders(resource, get_control_protocol_class_descriptor).as_array();
45+
const auto& property_value_holders = make_property_value_holders(resource, get_control_protocol_class_descriptor);
4746

4847
const auto role_path = get_role_path(resources, resource);
4948

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)