WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 3553625

Browse files
committed
PROTON-2911: [C++] Correctly handle terminus capabilities
Terminus capabilities can be a single AMQP symbol as well as an AMQP array of symbols.
1 parent b1b9b07 commit 3553625

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

cpp/src/connection_driver_test.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@
3939
#include "proton/types_fwd.hpp"
4040
#include "proton/uuid.hpp"
4141

42-
#include <deque>
42+
#include <proton/codec.h>
43+
#include <proton/terminus.h>
44+
4345
#include <algorithm>
46+
#include <cstring>
47+
#include <deque>
4448

4549
namespace {
4650

@@ -466,6 +470,25 @@ void test_link_capability_filter() {
466470
ASSERT_EQUAL(value("22"), f.get("2"));
467471
}
468472

473+
void test_terminus_capabilities_single_symbol() {
474+
// Test that capabilities() correctly handles a single symbol (not an array)
475+
// Capabilities can be encoded as either a single AMQP symbol or an array of symbols.
476+
record_handler ha, hb;
477+
driver_pair d(ha, hb);
478+
479+
// Annoyingly, we have to use the C API to set capabilities as a single symbol
480+
// because the C++ API only supports setting arrays of symbols.
481+
auto s = d.a.connection().open_sender("test-address");
482+
auto caps_data = pn_terminus_capabilities(unwrap(s.target()));
483+
auto cap_str = "single-capability";
484+
pn_data_put_symbol(caps_data, pn_bytes(strlen(cap_str), cap_str));
485+
486+
// Verify that capabilities() returns a vector with the single symbol
487+
auto caps = s.target().capabilities();
488+
ASSERT_EQUAL(1U, caps.size());
489+
ASSERT_EQUAL(proton::symbol("single-capability"), caps[0]);
490+
}
491+
469492
void test_message() {
470493
// Verify a message arrives intact
471494
record_handler ha, hb;
@@ -544,6 +567,7 @@ int main(int argc, char** argv) {
544567
RUN_ARGV_TEST(failed, test_link_address());
545568
RUN_ARGV_TEST(failed, test_link_anonymous_dynamic());
546569
RUN_ARGV_TEST(failed, test_link_capability_filter());
570+
RUN_ARGV_TEST(failed, test_terminus_capabilities_single_symbol());
547571
RUN_ARGV_TEST(failed, test_message());
548572
RUN_ARGV_TEST(failed, test_message_timeout_succeed());
549573
RUN_ARGV_TEST(failed, test_message_timeout_fail());

cpp/src/terminus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ value terminus::node_properties() const {
5858

5959
std::vector<symbol> terminus::capabilities() const {
6060
value caps(pn_terminus_capabilities(object_));
61-
return caps.empty() ? std::vector<symbol>() : caps.get<std::vector<symbol> >();
61+
return get_multiple<std::vector<symbol>>(caps);
6262
}
6363

6464
terminus::dynamic_property_map terminus::dynamic_properties() const {

cpp/tests.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ endmacro(add_cpp_test)
5252

5353
add_cpp_test(codec_test)
5454
add_cpp_test(connection_driver_test)
55+
target_link_libraries(connection_driver_test qpid-proton-core)
5556
add_cpp_test(interop_test ${PROJECT_SOURCE_DIR}/tests)
5657
add_cpp_test(message_test)
5758
add_cpp_test(map_test)

0 commit comments

Comments
 (0)