|
@@ -42,6 +42,223 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// @brief Test parsing buffer into array of int8_t or uint8_t values.
|
|
|
+ ///
|
|
|
+ /// @warning this function does not perform type check. Make
|
|
|
+ /// sure that only int8_t or uint8_t type is used.
|
|
|
+ ///
|
|
|
+ /// @tparam T int8_t or uint8_t.
|
|
|
+ template<typename T>
|
|
|
+ void bufferToIntTest8() {
|
|
|
+ // Create option that conveys array of multiple uint8_t or int8_t values.
|
|
|
+ // In fact there is no need to use this template class for array
|
|
|
+ // of uint8_t values because Option class is sufficient - it
|
|
|
+ // returns the buffer which is actually the array of uint8_t.
|
|
|
+ // However, since we allow using uint8_t types with this template
|
|
|
+ // class we have to test it here.
|
|
|
+ boost::shared_ptr<Option6IntArray<T> > opt;
|
|
|
+ const int opt_len = 10;
|
|
|
+ const uint16_t opt_code = 80;
|
|
|
+
|
|
|
+ // Constructor throws exception if provided buffer is empty.
|
|
|
+ EXPECT_THROW(
|
|
|
+ Option6IntArray<T>(opt_code, buf_.begin(), buf_.begin()),
|
|
|
+ isc::OutOfRange
|
|
|
+ );
|
|
|
+
|
|
|
+ // Provided buffer is not empty so it should not throw exception.
|
|
|
+ ASSERT_NO_THROW(
|
|
|
+ opt = boost::shared_ptr<
|
|
|
+ Option6IntArray<T> >(new Option6IntArray<T>(opt_code, buf_.begin(),
|
|
|
+ buf_.begin() + opt_len))
|
|
|
+ );
|
|
|
+
|
|
|
+ EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ // Option should return the collection of int8_t or uint8_t values that
|
|
|
+ // we can match with the buffer we used to create the option.
|
|
|
+ std::vector<T> values = opt->getValues();
|
|
|
+ // We need to copy values from the buffer to apply sign if signed
|
|
|
+ // type is used.
|
|
|
+ std::vector<T> reference_values;
|
|
|
+ for (int i = 0; i < opt_len; ++i) {
|
|
|
+ // Values have been read from the buffer in network
|
|
|
+ // byte order. We put them back in the same order here.
|
|
|
+ reference_values.push_back(static_cast<T>(buf_[i]));
|
|
|
+ }
|
|
|
+
|
|
|
+ // Compare the values against the reference buffer.
|
|
|
+ ASSERT_EQ(opt_len, values.size());
|
|
|
+ EXPECT_TRUE(std::equal(reference_values.begin(), reference_values.begin()
|
|
|
+ + opt_len, values.begin()));
|
|
|
+
|
|
|
+ // test for pack()
|
|
|
+ opt->pack(out_buf_);
|
|
|
+
|
|
|
+ // Data length is 10 bytes.
|
|
|
+ EXPECT_EQ(10, opt->len() - opt->getHeaderLen());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ // The total length is 10 bytes for data and 4 bytes for header.
|
|
|
+ ASSERT_EQ(14, out_buf_.getLength());
|
|
|
+
|
|
|
+ // Check if pack worked properly:
|
|
|
+ InputBuffer out(out_buf_.getData(), out_buf_.getLength());
|
|
|
+ // if option type is correct
|
|
|
+ EXPECT_EQ(opt_code, out.readUint16());
|
|
|
+ // if option length is correct
|
|
|
+ EXPECT_EQ(10, out.readUint16());
|
|
|
+ // if data is correct
|
|
|
+ std::vector<uint8_t> out_data;
|
|
|
+ ASSERT_NO_THROW(out.readVector(out_data, opt_len));
|
|
|
+ ASSERT_EQ(opt_len, out_data.size());
|
|
|
+ EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, out_data.begin()));;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Test parsing buffer into array of int16_t or uint16_t values.
|
|
|
+ ///
|
|
|
+ /// @warning this function does not perform type check. Make
|
|
|
+ /// sure that only int16_t or uint16_t type is used.
|
|
|
+ ///
|
|
|
+ /// @tparam T int16_t or uint16_t.
|
|
|
+ template<typename T>
|
|
|
+ void bufferToIntTest16() {
|
|
|
+ // Create option that conveys array of multiple uint16_t or int16_t values.
|
|
|
+ boost::shared_ptr<Option6IntArray<T> > opt;
|
|
|
+ const int opt_len = 20;
|
|
|
+ const uint16_t opt_code = 81;
|
|
|
+
|
|
|
+ // Constructor throws exception if provided buffer is empty.
|
|
|
+ EXPECT_THROW(
|
|
|
+ Option6IntArray<T>(opt_code, buf_.begin(), buf_.begin()),
|
|
|
+ isc::OutOfRange
|
|
|
+ );
|
|
|
+
|
|
|
+ // Constructor throws exception if provided buffer's length is not
|
|
|
+ // multiple of 2-bytes.
|
|
|
+ EXPECT_THROW(
|
|
|
+ Option6IntArray<T>(opt_code, buf_.begin(), buf_.begin() + 5),
|
|
|
+ isc::OutOfRange
|
|
|
+ );
|
|
|
+
|
|
|
+ // Now the buffer length is correct.
|
|
|
+ ASSERT_NO_THROW(
|
|
|
+ opt = boost::shared_ptr<
|
|
|
+ Option6IntArray<T> >(new Option6IntArray<T>(opt_code, buf_.begin(),
|
|
|
+ buf_.begin() + opt_len))
|
|
|
+ );
|
|
|
+
|
|
|
+ EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ // Option should return vector of uint16_t values which should be
|
|
|
+ // constructed from the buffer we provided.
|
|
|
+ std::vector<T> values = opt->getValues();
|
|
|
+ ASSERT_EQ(opt_len, values.size() * sizeof(T));
|
|
|
+ // Create reference values from the buffer so as we can
|
|
|
+ // simply compare two vectors.
|
|
|
+ std::vector<T> reference_values;
|
|
|
+ for (int i = 0; i < opt_len; i += 2) {
|
|
|
+ reference_values.push_back((buf_[i] << 8) |
|
|
|
+ buf_[i + 1]);
|
|
|
+ }
|
|
|
+ EXPECT_TRUE(std::equal(reference_values.begin(), reference_values.end(),
|
|
|
+ values.begin()));
|
|
|
+
|
|
|
+ // Test for pack()
|
|
|
+ opt->pack(out_buf_);
|
|
|
+
|
|
|
+ // Data length is 20 bytes.
|
|
|
+ EXPECT_EQ(20, opt->len() - opt->getHeaderLen());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ // The total length is 20 bytes for data and 4 bytes for header.
|
|
|
+ ASSERT_EQ(24, out_buf_.getLength());
|
|
|
+
|
|
|
+ // Check if pack worked properly:
|
|
|
+ InputBuffer out(out_buf_.getData(), out_buf_.getLength());
|
|
|
+ // if option type is correct
|
|
|
+ EXPECT_EQ(opt_code, out.readUint16());
|
|
|
+ // if option length is correct
|
|
|
+ EXPECT_EQ(20, out.readUint16());
|
|
|
+ // if data is correct
|
|
|
+ std::vector<uint8_t> out_data;
|
|
|
+ ASSERT_NO_THROW(out.readVector(out_data, opt_len));
|
|
|
+ ASSERT_EQ(opt_len, out_data.size());
|
|
|
+ EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, out_data.begin()));;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Test parsing buffer into array of int32_t or uint32_t values.
|
|
|
+ ///
|
|
|
+ /// @warning this function does not perform type check. Make
|
|
|
+ /// sure that only int32_t or uint32_t type is used.
|
|
|
+ ///
|
|
|
+ /// @tparam T int32_t or uint32_t.
|
|
|
+ template<typename T>
|
|
|
+ void bufferToIntTest32() {
|
|
|
+ // Create option that conveys array of multiple uint16_t values.
|
|
|
+ boost::shared_ptr<Option6IntArray<T> > opt;
|
|
|
+ const int opt_len = 40;
|
|
|
+ const uint16_t opt_code = 82;
|
|
|
+
|
|
|
+ // Constructor throws exception if provided buffer is empty.
|
|
|
+ EXPECT_THROW(
|
|
|
+ Option6IntArray<T>(opt_code, buf_.begin(), buf_.begin()),
|
|
|
+ isc::OutOfRange
|
|
|
+ );
|
|
|
+
|
|
|
+ // Constructor throws exception if provided buffer's length is not
|
|
|
+ // multiple of 4-bytes.
|
|
|
+ EXPECT_THROW(
|
|
|
+ Option6IntArray<T>(opt_code, buf_.begin(), buf_.begin() + 9),
|
|
|
+ isc::OutOfRange
|
|
|
+ );
|
|
|
+
|
|
|
+ // Now the buffer length is correct.
|
|
|
+ ASSERT_NO_THROW(
|
|
|
+ opt = boost::shared_ptr<
|
|
|
+ Option6IntArray<T> >(new Option6IntArray<T>(opt_code, buf_.begin(),
|
|
|
+ buf_.begin() + opt_len))
|
|
|
+ );
|
|
|
+
|
|
|
+ EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ // Option should return vector of uint32_t values which should be
|
|
|
+ // constructed from the buffer we provided.
|
|
|
+ std::vector<T> values = opt->getValues();
|
|
|
+ ASSERT_EQ(opt_len, values.size() * sizeof(T));
|
|
|
+ // Create reference values from the buffer so as we can
|
|
|
+ // simply compare two vectors.
|
|
|
+ std::vector<T> reference_values;
|
|
|
+ for (int i = 0; i < opt_len; i += 4) {
|
|
|
+ reference_values.push_back((buf_[i] << 24) |
|
|
|
+ (buf_[i + 1] << 16 & 0x00FF0000) |
|
|
|
+ (buf_[i + 2] << 8 & 0xFF00) |
|
|
|
+ (buf_[i + 3] & 0xFF));
|
|
|
+ }
|
|
|
+ EXPECT_TRUE(std::equal(reference_values.begin(), reference_values.end(),
|
|
|
+ values.begin()));
|
|
|
+
|
|
|
+ // Test for pack()
|
|
|
+ opt->pack(out_buf_);
|
|
|
+
|
|
|
+ // Data length is 40 bytes.
|
|
|
+ EXPECT_EQ(40, opt->len() - opt->getHeaderLen());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ // The total length is 40 bytes for data and 4 bytes for header.
|
|
|
+ ASSERT_EQ(44, out_buf_.getLength());
|
|
|
+
|
|
|
+ // Check if pack worked properly:
|
|
|
+ InputBuffer out(out_buf_.getData(), out_buf_.getLength());
|
|
|
+ // if option type is correct
|
|
|
+ EXPECT_EQ(opt_code, out.readUint16());
|
|
|
+ // if option length is correct
|
|
|
+ EXPECT_EQ(40, out.readUint16());
|
|
|
+ // if data is correct
|
|
|
+ std::vector<uint8_t> out_data;
|
|
|
+ ASSERT_NO_THROW(out.readVector(out_data, opt_len));
|
|
|
+ ASSERT_EQ(opt_len, out_data.size());
|
|
|
+ EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, out_data.begin()));;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
OptionBuffer buf_; ///< Option buffer
|
|
|
OutputBuffer out_buf_; ///< Output buffer
|
|
|
};
|
|
@@ -68,156 +285,28 @@ TEST_F(Option6IntArrayTest, useInvalidType) {
|
|
|
}
|
|
|
|
|
|
TEST_F(Option6IntArrayTest, bufferToUint8) {
|
|
|
- // Create option that conveys array of multiple uint8_t values.
|
|
|
- // In fact there is no need to use this template class for array
|
|
|
- // of uint8_t values because Option class is sufficient - it
|
|
|
- // returns the buffer which is actually the array of uint8_t.
|
|
|
- // However, since we allow using uint8_t types with this template
|
|
|
- // class we have to test it here.
|
|
|
- boost::shared_ptr<Option6IntArray<uint8_t> > opt;
|
|
|
- const int opt_len = 10;
|
|
|
- const uint16_t opt_code = 80;
|
|
|
- // Constructor may throw in case provided buffer is too short.
|
|
|
- ASSERT_NO_THROW(
|
|
|
- opt = boost::shared_ptr<
|
|
|
- Option6IntArray<uint8_t> >(new Option6IntArray<uint8_t>(opt_code, buf_.begin(),
|
|
|
- buf_.begin() + opt_len))
|
|
|
- );
|
|
|
-
|
|
|
- EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
- EXPECT_EQ(opt_code, opt->getType());
|
|
|
- // Option should return the same value that we initialized the first
|
|
|
- // byte of the buffer with.
|
|
|
- std::vector<uint8_t> values = opt->getValues();
|
|
|
- ASSERT_EQ(opt_len, values.size());
|
|
|
- EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, values.begin()));
|
|
|
-
|
|
|
- // test for pack()
|
|
|
- opt->pack(out_buf_);
|
|
|
+ bufferToIntTest8<uint8_t>();
|
|
|
+}
|
|
|
|
|
|
- // Data length is 10 bytes.
|
|
|
- EXPECT_EQ(10, opt->len() - opt->getHeaderLen());
|
|
|
- EXPECT_EQ(opt_code, opt->getType());
|
|
|
- // The total length is 10 bytes for data and 4 bytes for header.
|
|
|
- ASSERT_EQ(14, out_buf_.getLength());
|
|
|
-
|
|
|
- // Check if pack worked properly:
|
|
|
- InputBuffer out(out_buf_.getData(), out_buf_.getLength());
|
|
|
- // if option type is correct
|
|
|
- EXPECT_EQ(opt_code, out.readUint16());
|
|
|
- // if option length is correct
|
|
|
- EXPECT_EQ(10, out.readUint16());
|
|
|
- // if data is correct
|
|
|
- std::vector<uint8_t> out_data;
|
|
|
- ASSERT_NO_THROW(out.readVector(out_data, opt_len));
|
|
|
- ASSERT_EQ(opt_len, out_data.size());
|
|
|
- EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, out_data.begin()));;
|
|
|
+TEST_F(Option6IntArrayTest, bufferToInt8) {
|
|
|
+ bufferToIntTest8<int8_t>();
|
|
|
}
|
|
|
|
|
|
TEST_F(Option6IntArrayTest, bufferToUint16) {
|
|
|
- // Create option that conveys array of multiple uint16_t values.
|
|
|
- boost::shared_ptr<Option6IntArray<uint16_t> > opt;
|
|
|
- const int opt_len = 20;
|
|
|
- const uint16_t opt_code = 81;
|
|
|
- // Constructor may throw in case provided buffer is too short.
|
|
|
- ASSERT_NO_THROW(
|
|
|
- opt = boost::shared_ptr<
|
|
|
- Option6IntArray<uint16_t> >(new Option6IntArray<uint16_t>(opt_code, buf_.begin(),
|
|
|
- buf_.begin() + opt_len))
|
|
|
- );
|
|
|
-
|
|
|
- EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
- EXPECT_EQ(opt_code, opt->getType());
|
|
|
- // Option should return vector of uint16_t values which should be
|
|
|
- // constructed from the buffer we provided.
|
|
|
- std::vector<uint16_t> values = opt->getValues();
|
|
|
- // Let's pack the values back into some uint8_t buffer to compare
|
|
|
- // it later with the reference data.
|
|
|
- std::vector<uint8_t> values_buf;
|
|
|
- for (int i = 0; i < values.size(); ++i) {
|
|
|
- // Values have been read from the buffer in network
|
|
|
- // byte order. We put them back in the same order here.
|
|
|
- values_buf.push_back(values[i] >> 8);
|
|
|
- values_buf.push_back(values[i] & 0xFF);
|
|
|
- }
|
|
|
- ASSERT_EQ(opt_len, values_buf.size());
|
|
|
- EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, values_buf.begin()));
|
|
|
-
|
|
|
- // Test for pack()
|
|
|
- opt->pack(out_buf_);
|
|
|
+ bufferToIntTest16<uint16_t>();
|
|
|
+}
|
|
|
|
|
|
- // Data length is 20 bytes.
|
|
|
- EXPECT_EQ(20, opt->len() - opt->getHeaderLen());
|
|
|
- EXPECT_EQ(opt_code, opt->getType());
|
|
|
- // The total length is 20 bytes for data and 4 bytes for header.
|
|
|
- ASSERT_EQ(24, out_buf_.getLength());
|
|
|
-
|
|
|
- // Check if pack worked properly:
|
|
|
- InputBuffer out(out_buf_.getData(), out_buf_.getLength());
|
|
|
- // if option type is correct
|
|
|
- EXPECT_EQ(opt_code, out.readUint16());
|
|
|
- // if option length is correct
|
|
|
- EXPECT_EQ(20, out.readUint16());
|
|
|
- // if data is correct
|
|
|
- std::vector<uint8_t> out_data;
|
|
|
- ASSERT_NO_THROW(out.readVector(out_data, opt_len));
|
|
|
- ASSERT_EQ(opt_len, out_data.size());
|
|
|
- EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, out_data.begin()));;
|
|
|
+TEST_F(Option6IntArrayTest, bufferToInt16) {
|
|
|
+ bufferToIntTest16<int16_t>();
|
|
|
}
|
|
|
|
|
|
TEST_F(Option6IntArrayTest, bufferToUint32) {
|
|
|
- // Create option that conveys array of multiple uint16_t values.
|
|
|
- boost::shared_ptr<Option6IntArray<uint32_t> > opt;
|
|
|
- const int opt_len = 40;
|
|
|
- const uint16_t opt_code = 82;
|
|
|
- // Constructor may throw in case provided buffer is too short.
|
|
|
- ASSERT_NO_THROW(
|
|
|
- opt = boost::shared_ptr<
|
|
|
- Option6IntArray<uint32_t> >(new Option6IntArray<uint32_t>(opt_code, buf_.begin(),
|
|
|
- buf_.begin() + opt_len))
|
|
|
- );
|
|
|
-
|
|
|
- EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
- EXPECT_EQ(opt_code, opt->getType());
|
|
|
- // Option should return vector of uint32_t values which should be
|
|
|
- // constructed from the buffer we provided.
|
|
|
- std::vector<uint32_t> values = opt->getValues();
|
|
|
- // Let's pack the values back into some uint8_t buffer to compare
|
|
|
- // it later with the reference data.
|
|
|
- std::vector<uint8_t> values_buf;
|
|
|
- for (int i = 0; i < values.size(); ++i) {
|
|
|
- // Values have been read from the buffer in network
|
|
|
- // byte order. We put them back in the same order here.
|
|
|
- values_buf.push_back(values[i] >> 24);
|
|
|
- values_buf.push_back(values[i] >> 16 & 0xFF);
|
|
|
- values_buf.push_back(values[i] >> 8 & 0xFF);
|
|
|
- values_buf.push_back(values[i] & 0xFF);
|
|
|
- }
|
|
|
- ASSERT_EQ(opt_len, values_buf.size());
|
|
|
- EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, values_buf.begin()));
|
|
|
-
|
|
|
- // Test for pack()
|
|
|
- opt->pack(out_buf_);
|
|
|
-
|
|
|
- // Data length is 40 bytes.
|
|
|
- EXPECT_EQ(40, opt->len() - opt->getHeaderLen());
|
|
|
- EXPECT_EQ(opt_code, opt->getType());
|
|
|
- // The total length is 40 bytes for data and 4 bytes for header.
|
|
|
- ASSERT_EQ(44, out_buf_.getLength());
|
|
|
-
|
|
|
- // Check if pack worked properly:
|
|
|
- InputBuffer out(out_buf_.getData(), out_buf_.getLength());
|
|
|
- // if option type is correct
|
|
|
- EXPECT_EQ(opt_code, out.readUint16());
|
|
|
- // if option length is correct
|
|
|
- EXPECT_EQ(40, out.readUint16());
|
|
|
- // if data is correct
|
|
|
- std::vector<uint8_t> out_data;
|
|
|
- ASSERT_NO_THROW(out.readVector(out_data, opt_len));
|
|
|
- ASSERT_EQ(opt_len, out_data.size());
|
|
|
- EXPECT_TRUE(std::equal(buf_.begin(), buf_.begin() + opt_len, out_data.begin()));;
|
|
|
+ bufferToIntTest32<uint32_t>();
|
|
|
}
|
|
|
|
|
|
+TEST_F(Option6IntArrayTest, bufferToInt32) {
|
|
|
+ bufferToIntTest32<int32_t>();
|
|
|
+}
|
|
|
|
|
|
TEST_F(Option6IntArrayTest, setValuesUint8) {
|
|
|
const uint16_t opt_code = 100;
|
|
@@ -226,7 +315,7 @@ TEST_F(Option6IntArrayTest, setValuesUint8) {
|
|
|
// Initialize vector with some data and pass to the option.
|
|
|
std::vector<uint8_t> values;
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
- values.push_back(255 - i);
|
|
|
+ values.push_back(numeric_limits<uint8_t>::max() - i);
|
|
|
}
|
|
|
opt->setValues(values);
|
|
|
|
|
@@ -237,6 +326,24 @@ TEST_F(Option6IntArrayTest, setValuesUint8) {
|
|
|
EXPECT_TRUE(std::equal(values.begin(), values.end(), returned_values.begin()));
|
|
|
}
|
|
|
|
|
|
+TEST_F(Option6IntArrayTest, setValuesInt8) {
|
|
|
+ const uint16_t opt_code = 100;
|
|
|
+ // Create option with empty vector of values.
|
|
|
+ boost::shared_ptr<Option6IntArray<int8_t> > opt(new Option6IntArray<int8_t>(opt_code));
|
|
|
+ // Initialize vector with some data and pass to the option.
|
|
|
+ std::vector<int8_t> values;
|
|
|
+ for (int i = 0; i < 10; ++i) {
|
|
|
+ values.push_back(numeric_limits<int8_t>::min() + i);
|
|
|
+ }
|
|
|
+ opt->setValues(values);
|
|
|
+
|
|
|
+ // Check if universe, option type and data was set correctly.
|
|
|
+ EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ std::vector<int8_t> returned_values = opt->getValues();
|
|
|
+ EXPECT_TRUE(std::equal(values.begin(), values.end(), returned_values.begin()));
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(Option6IntArrayTest, setValuesUint16) {
|
|
|
const uint16_t opt_code = 101;
|
|
|
// Create option with empty vector of values.
|
|
@@ -244,7 +351,7 @@ TEST_F(Option6IntArrayTest, setValuesUint16) {
|
|
|
// Initialize vector with some data and pass to the option.
|
|
|
std::vector<uint16_t> values;
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
- values.push_back(0xFFFF - i);
|
|
|
+ values.push_back(numeric_limits<uint16_t>::max() - i);
|
|
|
}
|
|
|
opt->setValues(values);
|
|
|
|
|
@@ -255,6 +362,24 @@ TEST_F(Option6IntArrayTest, setValuesUint16) {
|
|
|
EXPECT_TRUE(std::equal(values.begin(), values.end(), returned_values.begin()));
|
|
|
}
|
|
|
|
|
|
+TEST_F(Option6IntArrayTest, setValuesInt16) {
|
|
|
+ const uint16_t opt_code = 101;
|
|
|
+ // Create option with empty vector of values.
|
|
|
+ boost::shared_ptr<Option6IntArray<int16_t> > opt(new Option6IntArray<int16_t>(opt_code));
|
|
|
+ // Initialize vector with some data and pass to the option.
|
|
|
+ std::vector<int16_t> values;
|
|
|
+ for (int i = 0; i < 10; ++i) {
|
|
|
+ values.push_back(numeric_limits<int16_t>::min() + i);
|
|
|
+ }
|
|
|
+ opt->setValues(values);
|
|
|
+
|
|
|
+ // Check if universe, option type and data was set correctly.
|
|
|
+ EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ std::vector<int16_t> returned_values = opt->getValues();
|
|
|
+ EXPECT_TRUE(std::equal(values.begin(), values.end(), returned_values.begin()));
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(Option6IntArrayTest, setValuesUint32) {
|
|
|
const uint32_t opt_code = 101;
|
|
|
// Create option with empty vector of values.
|
|
@@ -262,7 +387,7 @@ TEST_F(Option6IntArrayTest, setValuesUint32) {
|
|
|
// Initialize vector with some data and pass to the option.
|
|
|
std::vector<uint32_t> values;
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
- values.push_back(0xFFFFFFFF - i);
|
|
|
+ values.push_back(numeric_limits<uint32_t>::max() - i);
|
|
|
}
|
|
|
opt->setValues(values);
|
|
|
|
|
@@ -273,4 +398,23 @@ TEST_F(Option6IntArrayTest, setValuesUint32) {
|
|
|
EXPECT_TRUE(std::equal(values.begin(), values.end(), returned_values.begin()));
|
|
|
}
|
|
|
|
|
|
+TEST_F(Option6IntArrayTest, setValuesInt32) {
|
|
|
+ const uint32_t opt_code = 101;
|
|
|
+ // Create option with empty vector of values.
|
|
|
+ boost::shared_ptr<Option6IntArray<int32_t> > opt(new Option6IntArray<int32_t>(opt_code));
|
|
|
+ // Initialize vector with some data and pass to the option.
|
|
|
+ std::vector<int32_t> values;
|
|
|
+ for (int i = 0; i < 10; ++i) {
|
|
|
+ values.push_back(numeric_limits<int32_t>::min() + i);
|
|
|
+ }
|
|
|
+ opt->setValues(values);
|
|
|
+
|
|
|
+ // Check if universe, option type and data was set correctly.
|
|
|
+ EXPECT_EQ(Option::V6, opt->getUniverse());
|
|
|
+ EXPECT_EQ(opt_code, opt->getType());
|
|
|
+ std::vector<int32_t> returned_values = opt->getValues();
|
|
|
+ EXPECT_TRUE(std::equal(values.begin(), values.end(), returned_values.begin()));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
} // anonymous namespace
|