From f7472cc5d5d4a675e08f8bc72a18b2364e670b28 Mon Sep 17 00:00:00 2001 From: curtkrone Date: Wed, 16 Aug 2017 01:02:04 -0700 Subject: [PATCH 1/4] Add tentative test and fix to support UInt64 values in event payloads --- src/internal/sio_packet.cpp | 12 ++++++++++++ test/sio_test.cpp | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/internal/sio_packet.cpp b/src/internal/sio_packet.cpp index ec4551d9..2f30dbcf 100755 --- a/src/internal/sio_packet.cpp +++ b/src/internal/sio_packet.cpp @@ -141,6 +141,18 @@ namespace sio { return int_message::create(value.GetInt64()); } + // TODO: decide between returning int64 and double +#if 1 + else if (value.IsUint64()) + { + return int_message::create(value.GetInt64()); + } +#else + else if (value.IsUint64()) + { + return double_message::create(value.GetDouble()); + } +#endif else if(value.IsDouble()) { return double_message::create(value.GetDouble()); diff --git a/test/sio_test.cpp b/test/sio_test.cpp index fb6f3e50..1b0b9c1a 100644 --- a/test/sio_test.cpp +++ b/test/sio_test.cpp @@ -225,5 +225,25 @@ BOOST_AUTO_TEST_CASE( test_packet_parse_4 ) } +BOOST_AUTO_TEST_CASE( test_packet_parse_5 ) +{ + packet p; + bool hasbin = p.parse("42/nsp,1001[\"event\",17657333360744292000]"); + BOOST_CHECK(!hasbin); + BOOST_CHECK(p.get_frame() == packet::frame_message); + BOOST_CHECK(p.get_type() == packet::type_event); + BOOST_CHECK(p.get_nsp() == "/nsp"); + BOOST_CHECK(p.get_pack_id() == 1001); + BOOST_CHECK(p.get_message()->get_flag() == message::flag_array); + BOOST_REQUIRE(p.get_message()->get_vector().size() == 2); + BOOST_REQUIRE(p.get_message()->get_vector()[0]->get_flag() == message::flag_string); + BOOST_CHECK(p.get_message()->get_vector()[0]->get_string() == "event"); + // TODO: decide between returning int64 and double + //BOOST_REQUIRE(p.get_message()->get_vector()[1]->get_flag() == message::flag_double); + //BOOST_CHECK(p.get_message()->get_vector()[1]->get_double() == 17657333360744292000U); + BOOST_REQUIRE(p.get_message()->get_vector()[1]->get_flag() == message::flag_integer); + BOOST_CHECK(p.get_message()->get_vector()[1]->get_int() == 17657333360744292000U); +} + BOOST_AUTO_TEST_SUITE_END() From 85f67206b9e2ee820c937bc6f9e676827402263e Mon Sep 17 00:00:00 2001 From: Curt Krone Date: Wed, 16 Aug 2017 15:24:11 -0700 Subject: [PATCH 2/4] Commit to returning int_message (not double_message) for parsed UInt64 values in preparation for a PR --- src/internal/sio_packet.cpp | 8 -------- test/sio_test.cpp | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/internal/sio_packet.cpp b/src/internal/sio_packet.cpp index 2f30dbcf..05939bdd 100755 --- a/src/internal/sio_packet.cpp +++ b/src/internal/sio_packet.cpp @@ -141,18 +141,10 @@ namespace sio { return int_message::create(value.GetInt64()); } - // TODO: decide between returning int64 and double -#if 1 else if (value.IsUint64()) { return int_message::create(value.GetInt64()); } -#else - else if (value.IsUint64()) - { - return double_message::create(value.GetDouble()); - } -#endif else if(value.IsDouble()) { return double_message::create(value.GetDouble()); diff --git a/test/sio_test.cpp b/test/sio_test.cpp index 1b0b9c1a..5efc4591 100644 --- a/test/sio_test.cpp +++ b/test/sio_test.cpp @@ -225,6 +225,9 @@ BOOST_AUTO_TEST_CASE( test_packet_parse_4 ) } +/* + * Test parsing of UInt64 values. See #174. + */ BOOST_AUTO_TEST_CASE( test_packet_parse_5 ) { packet p; @@ -238,9 +241,6 @@ BOOST_AUTO_TEST_CASE( test_packet_parse_5 ) BOOST_REQUIRE(p.get_message()->get_vector().size() == 2); BOOST_REQUIRE(p.get_message()->get_vector()[0]->get_flag() == message::flag_string); BOOST_CHECK(p.get_message()->get_vector()[0]->get_string() == "event"); - // TODO: decide between returning int64 and double - //BOOST_REQUIRE(p.get_message()->get_vector()[1]->get_flag() == message::flag_double); - //BOOST_CHECK(p.get_message()->get_vector()[1]->get_double() == 17657333360744292000U); BOOST_REQUIRE(p.get_message()->get_vector()[1]->get_flag() == message::flag_integer); BOOST_CHECK(p.get_message()->get_vector()[1]->get_int() == 17657333360744292000U); } From abf8f5fb291756d6099789692dd8efd15a147255 Mon Sep 17 00:00:00 2001 From: Curt Krone Date: Fri, 18 Aug 2017 15:50:19 -0700 Subject: [PATCH 3/4] Switch to calling GetUint64() then casting to avoid debug assertions --- src/internal/sio_packet.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/internal/sio_packet.cpp b/src/internal/sio_packet.cpp index 05939bdd..65640490 100755 --- a/src/internal/sio_packet.cpp +++ b/src/internal/sio_packet.cpp @@ -143,7 +143,7 @@ namespace sio } else if (value.IsUint64()) { - return int_message::create(value.GetInt64()); + return int_message::create(static_cast(value.GetUint64())); } else if(value.IsDouble()) { @@ -187,14 +187,14 @@ namespace sio } return ptr; } - else if(value.IsBool()) - { - return bool_message::create(value.GetBool()); - } - else if(value.IsNull()) - { - return null_message::create(); - } + else if(value.IsBool()) + { + return bool_message::create(value.GetBool()); + } + else if(value.IsNull()) + { + return null_message::create(); + } return message::ptr(); } From ed8bb9d2b09c5e036eab8beda68dce01800559d7 Mon Sep 17 00:00:00 2001 From: curtkrone Date: Fri, 23 Aug 2024 12:04:04 -0700 Subject: [PATCH 4/4] finish updating test syntax --- test/sio_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sio_test.cpp b/test/sio_test.cpp index ba0afd18..bd6d352d 100644 --- a/test/sio_test.cpp +++ b/test/sio_test.cpp @@ -238,7 +238,7 @@ TEST_CASE( "test_packet_parse_4" ) /* * Test parsing of UInt64 values. See #174. */ -TEST_CASE( test_packet_parse_5 ) +TEST_CASE( "test_packet_parse_5" ) { packet p; bool hasbin = p.parse("42/nsp,1001[\"event\",17657333360744292000]");