@@ -3023,7 +3023,7 @@ TEST(decode, alloc_fail)
30233023 , 0x21 , 0x35 , 0xDA
30243024 , 0x42 , 4 , 0xFE , 0xE1 , 0xAB , 0xBA // <T=0x42, L, FLD_IP>
30253025 , 0 ,2 , 0x76 , 0x54 , 0x98 , 0x76 // <C16, FLD_W>
3026- , 0x62 , 4 , 0x01 , 0x02 , 0x03 , 0x04 // [T=0x51, L, FLD_DW]
3026+ , 0x62 , 4 , 0x01 , 0x02 , 0x03 , 0x04 // [T=0x51, L, FLD_DW]
30273027 , 9 , ' t' , ' e' , ' s' , ' t' , ' .' , ' t' , ' h' , ' i' , ' s'
30283028 , 7 , ' t' , ' e' , ' s' , ' t' , ' .' , ' i' , ' t'
30293029 };
@@ -3053,6 +3053,50 @@ TEST(decode, alloc_fail)
30533053 EXPECT_NE (nullptr , toString (ctx.error_ctx ()));
30543054#endif
30553055}
3056+
3057+ TEST (copy, mseq_open)
3058+ {
3059+ uint8_t const encoded[] = {
3060+ 0x21 , 0x35 , 0xD9 // <T=0x21, FLD_U16>
3061+ , 0x21 , 0x35 , 0xDA
3062+ , 0x42 , 4 , 0xFE , 0xE1 , 0xAB , 0xBA // <T=0x42, L, FLD_IP>
3063+ , 0 ,2 , 0x76 , 0x54 , 0x98 , 0x76 // <C16, FLD_W>
3064+ , 0x62 , 4 , 0x01 , 0x02 , 0x03 , 0x04 // [T=0x51, L, FLD_DW]
3065+ , 9 , ' t' , ' e' , ' s' , ' t' , ' .' , ' t' , ' h' , ' i' , ' s'
3066+ , 7 , ' t' , ' e' , ' s' , ' t' , ' .' , ' i' , ' t'
3067+ };
3068+
3069+ MSEQ_OPEN src_msg;
3070+ MSEQ_OPEN dst_msg;
3071+
3072+ uint8_t dec_buf[1024 ];
3073+ {
3074+ med::decoder_context<> ctx{ encoded, dec_buf };
3075+ #if (MED_EXCEPTIONS)
3076+ decode (make_octet_decoder (ctx), src_msg);
3077+ ASSERT_THROW (dst_msg.copy (src_msg), med::exception);
3078+ dst_msg.copy (src_msg, ctx);
3079+ #else
3080+ if (!decode (make_octet_decoder (ctx), src_msg)) { FAIL () << toString (ctx.error_ctx ()); }
3081+ ASSERT_FALSE (dst_msg.copy (src_msg));
3082+ ASSERT_TRUE (dst_msg.copy (src_msg, ctx));
3083+ #endif
3084+ }
3085+
3086+ {
3087+ uint8_t buffer[1024 ];
3088+ med::encoder_context<> ctx{ buffer };
3089+
3090+ #if (MED_EXCEPTIONS)
3091+ encode (make_octet_encoder (ctx), dst_msg);
3092+ #else
3093+ if (!encode (make_octet_encoder (ctx), dst_msg)) { FAIL () << toString (ctx.error_ctx ()); }
3094+ #endif
3095+ EXPECT_EQ (sizeof (encoded), ctx.buffer ().get_offset ());
3096+ EXPECT_TRUE (Matches (encoded, buffer));
3097+ }
3098+ }
3099+
30563100#endif
30573101
30583102#if 1
0 commit comments