Files
hardware_interfaces/automotive/ivn_android_device/impl/default/test/IvnAndroidDeviceServiceUnittest.cpp
Yu Shan a45f94d60d Add reference ivn HAL impl.
Add reference ivn HAL impl. The reference implementation reads
a JSON config file and provides static information.

Test: atest IvnAndroidDeviceServiceUnitTest
Bug: 274139217
Change-Id: Idc55d3ac8573bd1eeff096c4f12d8bfd935fb859
2023-04-25 18:16:42 -07:00

111 lines
3.4 KiB
C++

/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "IvnAndroidDeviceService.h"
#include <aidl/android/hardware/automotive/ivn/OccupantType.h>
#include <aidl/android/hardware/automotive/ivn/OccupantZoneInfo.h>
#include <android-base/file.h>
#include <gtest/gtest.h>
namespace android {
namespace hardware {
namespace automotive {
namespace ivn {
using ::aidl::android::hardware::automotive::ivn::OccupantType;
using ::aidl::android::hardware::automotive::ivn::OccupantZoneInfo;
using ::ndk::ScopedAStatus;
class IvnAndroidDeviceServiceUnitTest : public ::testing::Test {
public:
virtual void SetUp() override {
mService = ndk::SharedRefBase::make<IvnAndroidDeviceService>(
android::base::GetExecutableDirectory() + "/DefaultConfig.json");
mService->init();
}
std::shared_ptr<IvnAndroidDeviceService> mService;
};
TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetMyDeviceId) {
int deviceId = -1;
ScopedAStatus status = mService->getMyDeviceId(&deviceId);
ASSERT_TRUE(status.isOk());
ASSERT_EQ(deviceId, 0);
}
TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetOtherDeviceIds) {
std::vector<int> deviceIds;
ScopedAStatus status = mService->getOtherDeviceIds(&deviceIds);
ASSERT_TRUE(status.isOk());
ASSERT_EQ(deviceIds, std::vector<int>({1}));
}
TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetDeviceIdForOccupantZone) {
int deviceId = -1;
ScopedAStatus status = mService->getDeviceIdForOccupantZone(/*zoneId=*/0, &deviceId);
ASSERT_TRUE(status.isOk());
EXPECT_EQ(deviceId, 0);
status = mService->getDeviceIdForOccupantZone(/*zoneId=*/1, &deviceId);
ASSERT_TRUE(status.isOk());
EXPECT_EQ(deviceId, 0);
status = mService->getDeviceIdForOccupantZone(/*zoneId=*/2, &deviceId);
ASSERT_TRUE(status.isOk());
EXPECT_EQ(deviceId, 1);
status = mService->getDeviceIdForOccupantZone(/*zoneId=*/3, &deviceId);
ASSERT_TRUE(status.isOk());
EXPECT_EQ(deviceId, 1);
status = mService->getDeviceIdForOccupantZone(/*zoneId=*/4, &deviceId);
ASSERT_FALSE(status.isOk());
}
TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetOccupantZonesForDevice) {
std::vector<OccupantZoneInfo> occupantZones;
ScopedAStatus status =
mService->getOccupantZonesForDevice(/*androidDeviceId=*/0, &occupantZones);
ASSERT_TRUE(status.isOk());
EXPECT_EQ(occupantZones.size(), 2);
if (occupantZones.size() == 2) {
EXPECT_EQ(occupantZones[0].zoneId, 0);
EXPECT_EQ(occupantZones[0].occupantType, OccupantType::DRIVER);
EXPECT_EQ(occupantZones[0].seat, 1);
EXPECT_EQ(occupantZones[1].zoneId, 1);
EXPECT_EQ(occupantZones[1].occupantType, OccupantType::FRONT_PASSENGER);
EXPECT_EQ(occupantZones[1].seat, 4);
}
}
} // namespace ivn
} // namespace automotive
} // namespace hardware
} // namespace android