Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd65531e authored by Yu Shan's avatar Yu Shan
Browse files

Fix empty array object obtain.

Test: atest VehicleHalVehicleUtilsTest
Bug: 316432606
Change-Id: I6b2009cf3e96be33cc4abdfaa4c781b46a0f49f8
parent bdea4eaf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ class VehiclePropValuePool {

    bool isDisposable(aidl::android::hardware::automotive::vehicle::VehiclePropertyType type,
                      size_t vectorSize) const {
        return vectorSize > mMaxRecyclableVectorSize || isComplexType(type);
        return vectorSize == 0 || vectorSize > mMaxRecyclableVectorSize || isComplexType(type);
    }

    RecyclableType obtainDisposable(
+0 −1
Original line number Diff line number Diff line
@@ -124,7 +124,6 @@ createVehiclePropValueVec(aidl::android::hardware::automotive::vehicle::VehicleP
            break;  // Valid, but nothing to do.
        default:
            ALOGE("createVehiclePropValue: unknown type: %d", toInt(type));
            val.reset(nullptr);
    }
    return val;
}
+0 −7
Original line number Diff line number Diff line
@@ -55,13 +55,6 @@ VehiclePropValuePool::RecyclableType VehiclePropValuePool::obtain(const VehicleP
    int propId = src.prop;
    VehiclePropertyType type = getPropType(propId);
    size_t vectorSize = getVehicleRawValueVectorSize(src.value, type);
    if (vectorSize == 0 && !isComplexType(type)) {
        ALOGW("empty vehicle prop value, contains no content");
        ALOGW("empty vehicle prop value, contains no content, prop: %d", propId);
        // Return any empty VehiclePropValue.
        return RecyclableType{new VehiclePropValue{}, mDisposableDeleter};
    }

    auto dest = obtain(type, vectorSize);

    dest->prop = propId;
+14 −0
Original line number Diff line number Diff line
@@ -267,6 +267,20 @@ TEST_F(VehicleObjectPoolTest, testObtainCopyInt32Values) {
    ASSERT_EQ(*gotValue, prop);
}

TEST_F(VehicleObjectPoolTest, testObtainCopyInt32ValuesEmptyArray) {
    VehiclePropValue prop{
            // INT32_VEC property.
            .prop = toInt(VehicleProperty::INFO_FUEL_TYPE),
            .areaId = 2,
            .timestamp = 3,
            .value = {.int32Values = {}},
    };
    auto gotValue = mValuePool->obtain(prop);

    ASSERT_NE(gotValue, nullptr);
    ASSERT_EQ(*gotValue, prop);
}

TEST_F(VehicleObjectPoolTest, testObtainCopyInt64Values) {
    VehiclePropValue prop{
            // INT64_VEC property.