diff --git a/src/WireEncoder.cpp b/src/WireEncoder.cpp index 7866821144..3a2536d74b 100644 --- a/src/WireEncoder.cpp +++ b/src/WireEncoder.cpp @@ -178,7 +178,7 @@ void WireEncoder::WriteValue(const NT_Value& value) { Write8(size); for (std::size_t i = 0; i < size; ++i) - WriteDouble(value.data.arr_double.arr[i] ? 1 : 0); + WriteDouble(value.data.arr_double.arr[i]); break; } case NT_STRING_ARRAY: { diff --git a/test/unit/WireEncoderTest.cpp b/test/unit/WireEncoderTest.cpp index 65e7c009ca..f24e976ce2 100644 --- a/test/unit/WireEncoderTest.cpp +++ b/test/unit/WireEncoderTest.cpp @@ -7,6 +7,9 @@ #include "WireEncoder.h" +#include "StringValueTest.h" +#include "ValueTest.h" + #include "gtest/gtest.h" #include @@ -19,20 +22,65 @@ namespace ntimpl { -TEST(WireEncoderTest, Construct) { +class WireEncoderTest : public ::testing::Test { + protected: + virtual void SetUp() { + Value v; + v_boolean.SetBoolean(true); + v_double.SetDouble(1.0); + v_string.SetString("hello"); + v_raw.SetRaw("hello"); + v_boolean_array.SetBooleanArray(std::vector{0, 1, 0}); + v_boolean_array_big.SetBooleanArray(std::vector(256)); + v_double_array.SetDoubleArray(std::vector{0.5, 0.25}); + v_double_array_big.SetDoubleArray(std::vector(256)); + + std::vector sa; + sa.push_back(StringValue("hello")); + sa.push_back(StringValue("goodbye")); + v_string_array.SetStringArray(sa); + + sa.clear(); + for (int i=0; i<256; ++i) + sa.push_back(StringValue("h")); + v_string_array_big.SetStringArray(sa); + + sv_normal = StringValue("hello"); + + std::string longstr; + longstr.append(127, '*'); + longstr.push_back('x'); + sv_long = StringValue(longstr); + + longstr.clear(); + longstr.append(65534, '*'); + longstr.append(3, 'x'); + sv_big = StringValue(longstr); + } + + Value v_empty; + Value v_boolean, v_double, v_string, v_raw; + Value v_boolean_array, v_boolean_array_big; + Value v_double_array, v_double_array_big; + Value v_string_array, v_string_array_big; + + StringValue sv_normal, sv_long, sv_big; +}; + +TEST_F(WireEncoderTest, Construct) { WireEncoder e(0x0300u); EXPECT_EQ(0u, e.size()); EXPECT_EQ(nullptr, e.error()); EXPECT_EQ(0x0300u, e.proto_rev()); } -TEST(WireEncoderTest, SetProtoRev) { +TEST_F(WireEncoderTest, SetProtoRev) { WireEncoder e(0x0300u); e.set_proto_rev(0x0200u); EXPECT_EQ(0x0200u, e.proto_rev()); } -TEST(WireEncoderTest, Write8) { +TEST_F(WireEncoderTest, Write8) { std::size_t off = BUFSIZE-1; WireEncoder e(0x0300u); for(std::size_t i=0; i