Author: astitcher
Date: Wed May 8 17:37:34 2013
New Revision: 1480376
URL: http://svn.apache.org/r1480376
Log:
QPID-4822: Allow Variant::parse() to produce VAR_UINT64 types.
- Extend qpid::messaging::Variant string parser to output unsigned 64 bit
type where relevant (positive integer larger than signed 64 bits)
- Added some unit tests for the qpid::messageing::Variant string parser
Modified:
qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp
qpid/trunk/qpid/cpp/src/tests/Variant.cpp
Modified: qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp?rev=1480376&r1=1480375&r2=1480376&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp Wed May 8 17:37:34 2013
@@ -122,7 +122,7 @@ class VariantImpl
} else {
T r = boost::lexical_cast<T>(s.substr(1));
if (std::numeric_limits<T>::is_signed) {
- return -r;
+ return -r;
} else {
if (r==0) return 0;
}
@@ -804,6 +804,9 @@ Variant& Variant::parse(const std::strin
return operator=(asInt64());
} catch (const InvalidConversion&) {}
try {
+ return operator=(asUint64());
+ } catch (const InvalidConversion&) {}
+ try {
return operator=(asDouble());
} catch (const InvalidConversion&) {}
try {
Modified: qpid/trunk/qpid/cpp/src/tests/Variant.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/Variant.cpp?rev=1480376&r1=1480375&r2=1480376&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/Variant.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/Variant.cpp Wed May 8 17:37:34 2013
@@ -780,6 +780,33 @@ QPID_AUTO_TEST_CASE(testBufferEncoding)
BOOST_CHECK_THROW(MapCodec::encode(inMap, buffer), std::exception);
}
+QPID_AUTO_TEST_CASE(parse)
+{
+ Variant a;
+ a.parse("What a fine mess");
+ BOOST_CHECK(a.getType()==types::VAR_STRING);
+ a.parse("true");
+ BOOST_CHECK(a.getType()==types::VAR_BOOL);
+ a.parse("FalsE");
+ BOOST_CHECK(a.getType()==types::VAR_BOOL);
+ a.parse("3.1415926");
+ BOOST_CHECK(a.getType()==types::VAR_DOUBLE);
+ a.parse("-7.2e-15");
+ BOOST_CHECK(a.getType()==types::VAR_DOUBLE);
+ a.parse("9223372036854775807");
+ BOOST_CHECK(a.getType()==types::VAR_INT64);
+ a.parse("9223372036854775808");
+ BOOST_CHECK(a.getType()==types::VAR_UINT64);
+ a.parse("-9223372036854775807");
+ BOOST_CHECK(a.getType()==types::VAR_INT64);
+ a.parse("-9223372036854775808");
+ BOOST_CHECK(a.getType()==types::VAR_DOUBLE);
+ a.parse("18446744073709551615");
+ BOOST_CHECK(a.getType()==types::VAR_UINT64);
+ a.parse("18446744073709551616");
+ BOOST_CHECK(a.getType()==types::VAR_DOUBLE);
+}
+
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]