mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 22:04:26 +00:00
Merge "Enforce sensors of the same type having a unique name." into sc-dev am: 5ce2cca301
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/interfaces/+/14967964 Change-Id: Ib5449b22e3b029f65226c518235c9b51863e831e
This commit is contained in:
@@ -24,7 +24,9 @@
|
||||
#include <log/log.h>
|
||||
#include <utils/SystemClock.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
using ::android::hardware::Return;
|
||||
@@ -149,6 +151,7 @@ std::vector<SensorInfo> SensorsHidlTest::getSensorsList() {
|
||||
TEST_P(SensorsHidlTest, SensorListValid) {
|
||||
S()->getSensorsList([&](const auto& list) {
|
||||
const size_t count = list.size();
|
||||
std::unordered_map<int32_t, std::vector<std::string>> sensorTypeNameMap;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const auto& s = list[i];
|
||||
SCOPED_TRACE(::testing::Message()
|
||||
@@ -167,6 +170,14 @@ TEST_P(SensorsHidlTest, SensorListValid) {
|
||||
EXPECT_FALSE(s.name.empty());
|
||||
EXPECT_FALSE(s.vendor.empty());
|
||||
|
||||
// Make sure that sensors of the same type have a unique name.
|
||||
std::vector<std::string>& v = sensorTypeNameMap[static_cast<int32_t>(s.type)];
|
||||
bool isUniqueName = std::find(v.begin(), v.end(), s.name) == v.end();
|
||||
EXPECT_TRUE(isUniqueName) << "Duplicate sensor Name: " << s.name;
|
||||
if (isUniqueName) {
|
||||
v.push_back(s.name);
|
||||
}
|
||||
|
||||
// Test power > 0, maxRange > 0
|
||||
EXPECT_LE(0, s.power);
|
||||
EXPECT_LT(0, s.maxRange);
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
#include <log/log.h>
|
||||
#include <utils/SystemClock.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <condition_variable>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
@@ -373,6 +375,7 @@ int32_t SensorsHidlTest::getInvalidSensorHandle() {
|
||||
TEST_P(SensorsHidlTest, SensorListValid) {
|
||||
getSensors()->getSensorsList([&](const auto& list) {
|
||||
const size_t count = list.size();
|
||||
std::unordered_map<int32_t, std::vector<std::string>> sensorTypeNameMap;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const auto& s = list[i];
|
||||
SCOPED_TRACE(::testing::Message()
|
||||
@@ -393,6 +396,14 @@ TEST_P(SensorsHidlTest, SensorListValid) {
|
||||
EXPECT_FALSE(s.name.empty());
|
||||
EXPECT_FALSE(s.vendor.empty());
|
||||
|
||||
// Make sure that sensors of the same type have a unique name.
|
||||
std::vector<std::string>& v = sensorTypeNameMap[static_cast<int32_t>(s.type)];
|
||||
bool isUniqueName = std::find(v.begin(), v.end(), s.name) == v.end();
|
||||
EXPECT_TRUE(isUniqueName) << "Duplicate sensor Name: " << s.name;
|
||||
if (isUniqueName) {
|
||||
v.push_back(s.name);
|
||||
}
|
||||
|
||||
// Test power > 0, maxRange > 0
|
||||
EXPECT_LE(0, s.power);
|
||||
EXPECT_LT(0, s.maxRange);
|
||||
|
||||
Reference in New Issue
Block a user