MCPcopy Create free account
hub / github.com/apache/qpid-proton / test_decoder_primitives_exact

Function test_decoder_primitives_exact

cpp/src/interop_test.cpp:61–84  ·  view source on GitHub ↗

Test extracting to exact AMQP types works correctly, extracting to invalid types fails.

Source from the content-addressed store, hash-verified

59
60// Test extracting to exact AMQP types works correctly, extracting to invalid types fails.
61void test_decoder_primitives_exact() {
62 value dv;
63 decoder d(dv);
64 d.decode(read("primitives"));
65 ASSERT(d.more());
66 try { get< ::int8_t>(d); FAIL("got bool as byte"); } catch(const conversion_error&){}
67 ASSERT_EQUAL(true, get<bool>(d));
68 ASSERT_EQUAL(false, get<bool>(d));
69 try { get< ::int8_t>(d); FAIL("got ubyte as byte"); } catch(const conversion_error&){}
70 ASSERT_EQUAL(42, get< ::uint8_t>(d));
71 try { get< ::int32_t>(d); FAIL("got uint as ushort"); } catch(const conversion_error&){}
72 ASSERT_EQUAL(42, get< ::uint16_t>(d));
73 try { get< ::uint16_t>(d); FAIL("got short as ushort"); } catch(const conversion_error&){}
74 ASSERT_EQUAL(-42, get< ::int16_t>(d));
75 ASSERT_EQUAL(12345u, get< ::uint32_t>(d));
76 ASSERT_EQUAL(-12345, get< ::int32_t>(d));
77 ASSERT_EQUAL(12345u, get< ::uint64_t>(d));
78 ASSERT_EQUAL(-12345, get< ::int64_t>(d));
79 try { get<double>(d); FAIL("got float as double"); } catch(const conversion_error&){}
80 ASSERT_EQUAL(0.125f, get<float>(d));
81 try { get<float>(d); FAIL("got double as float"); } catch(const conversion_error&){}
82 ASSERT_EQUAL(0.125, get<double>(d));
83 ASSERT(!d.more());
84}
85
86// Test inserting primitive sand encoding as AMQP.
87void test_encoder_primitives() {

Callers 1

mainFunction · 0.85

Calls 3

readFunction · 0.85
decodeMethod · 0.45
moreMethod · 0.45

Tested by

no test coverage detected