mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-19 12:42:31 +02:00
Merge branch 'redboltz/add_integer_to_float_conv'
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <deque>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <type_traits>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -178,6 +179,59 @@ TEST(MSGPACK, simple_buffer_float)
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename F, typename I>
|
||||
struct TypePair {
|
||||
typedef F float_type;
|
||||
typedef I integer_type;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
template <typename T>
|
||||
class IntegerToFloatingPointTest : public testing::Test {
|
||||
};
|
||||
TYPED_TEST_CASE_P(IntegerToFloatingPointTest);
|
||||
|
||||
TYPED_TEST_P(IntegerToFloatingPointTest, simple_buffer)
|
||||
{
|
||||
typedef typename TypeParam::float_type float_type;
|
||||
typedef typename TypeParam::integer_type integer_type;
|
||||
vector<integer_type> v;
|
||||
v.push_back(0);
|
||||
v.push_back(1);
|
||||
if (is_signed<integer_type>::value) v.push_back(-1);
|
||||
else v.push_back(2);
|
||||
v.push_back(numeric_limits<integer_type>::min());
|
||||
v.push_back(numeric_limits<integer_type>::max());
|
||||
for (unsigned int i = 0; i < kLoop; i++) {
|
||||
v.push_back(rand());
|
||||
}
|
||||
for (unsigned int i = 0; i < v.size() ; i++) {
|
||||
msgpack::sbuffer sbuf;
|
||||
integer_type val1 = v[i];
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::zone z;
|
||||
msgpack::object obj;
|
||||
msgpack::unpack_return ret =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
|
||||
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
|
||||
float_type val2;
|
||||
obj.convert(&val2);
|
||||
EXPECT_TRUE(fabs(val2 - val1) <= kEPS);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_CASE_P(IntegerToFloatingPointTest,
|
||||
simple_buffer);
|
||||
|
||||
typedef testing::Types<TypePair<float, signed long long>,
|
||||
TypePair<float, unsigned long long>,
|
||||
TypePair<double, signed long long>,
|
||||
TypePair<double, unsigned long long> > IntegerToFloatingPointTestTypes;
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(IntegerToFloatingPointTestInstance,
|
||||
IntegerToFloatingPointTest,
|
||||
IntegerToFloatingPointTestTypes);
|
||||
|
||||
TEST(MSGPACK, simple_buffer_double)
|
||||
{
|
||||
vector<double> v;
|
||||
|
Reference in New Issue
Block a user