@@ -176,8 +176,8 @@ BST_TEST_CASE(testServiceNameTruncationDistinct)
176176{
177177 using web::json::value_of;
178178
179- // even when truncated, names that differ only in the port (which is past the truncation point)
180- // should produce distinct names due to the hash suffix being based on the full untruncated name
179+ // settings that produce distinct over-long names before truncation usually result in
180+ // distinct names because the hash suffix is based on the full untruncated name
181181 const auto make_settings = [](int port)
182182 {
183183 return value_of ({
@@ -189,9 +189,25 @@ BST_TEST_CASE(testServiceNameTruncationDistinct)
189189
190190 const auto name1 = nmos::experimental::service_name (nmos::service_types::node, make_settings (3212 ));
191191 const auto name2 = nmos::experimental::service_name (nmos::service_types::node, make_settings (3213 ));
192- const auto name3 = nmos::experimental::service_name (nmos::service_types::node, make_settings (3214 ));
193192
194193 BST_CHECK (name1 != name2);
195- BST_CHECK (name1 != name3);
196- BST_CHECK (name2 != name3);
194+ }
195+
196+ // //////////////////////////////////////////////////////////////////////////////////////////
197+ BST_TEST_CASE (testServiceNameTruncationExample)
198+ {
199+ using web::json::value_of;
200+
201+ const nmos::settings settings = value_of ({
202+ { nmos::fields::host_name, U (" a-host-name-that-is-itself-valid-but-already-63-characters-long.xz6zx.example.com" ) },
203+ { nmos::experimental::fields::href_mode, 1 }
204+ });
205+
206+ const auto name = nmos::experimental::service_name (nmos::service_types::node, settings);
207+ BST_REQUIRE_EQUAL (" nmos-cpp_node_a-host-name-that-is-itself-valid-but-alread-" , name.substr (0 , name.size () - 5 ));
208+ #ifdef __GLIBCXX__
209+ BST_CHECK_EQUAL (" cr4ck" , name.substr (name.size () - 5 ));
210+ // ...e4y8q.example.com produces the same hash suffix with this std::hash implementation
211+ // but anything could happen on another platform...
212+ #endif
197213}
0 commit comments