Add range constructor to hidl_vec.
Bug: b/36864090
Test: Unit test
Test: a device boots
Test: marlin boots and completes unit test
Change-Id: I7d37f75ec6c8ba0252c3c60afd515eff87dfc4dd
diff --git a/test_main.cpp b/test_main.cpp
index bce9294..1f2f845 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -262,6 +262,30 @@
EXPECT_TRUE(hv1 != hv3);
}
+TEST_F(LibHidlTest, VecRangeCtorTest) {
+ struct ConvertibleType {
+ int val;
+
+ explicit ConvertibleType(int val) : val(val) {}
+ explicit operator int() const { return val; }
+ bool operator==(const int& other) const { return val == other; }
+ };
+
+ std::vector<ConvertibleType> input{
+ ConvertibleType(1), ConvertibleType(2), ConvertibleType(3),
+ };
+
+ android::hardware::hidl_vec<int> hv(input.begin(), input.end());
+
+ EXPECT_EQ(input.size(), hv.size());
+ int sum = 0;
+ for (unsigned i = 0; i < input.size(); i++) {
+ EXPECT_EQ(input[i], hv[i]);
+ sum += hv[i];
+ }
+ EXPECT_EQ(sum, 1 + 2 + 3);
+}
+
TEST_F(LibHidlTest, ArrayTest) {
using android::hardware::hidl_array;
int32_t array[] = {5, 6, 7};