From 4db4b7b602de2968223dd2aff061ba72d75d269a Mon Sep 17 00:00:00 2001 From: Weilin Xu Date: Fri, 5 Apr 2024 14:03:15 -0700 Subject: [PATCH] Fix wrong integer type in AIDL bcradio utils lib Bug: 310029333 Test: atest broadcastradio_utils_aidl_test Change-Id: I929049c0991a557f518853ecebd5ba67973e4274 --- .../vts/src/VtsHalBroadcastradioAidlTargetTest.cpp | 11 ++++++----- .../include/broadcastradio-utils-aidl/Utils.h | 2 +- broadcastradio/common/utilsaidl/src/Utils.cpp | 4 ++-- .../common/utilsaidl/test/BroadcastRadioUtilsTest.cpp | 11 ++++++++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp b/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp index 9633ebb5ae..ee0c63988d 100644 --- a/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp +++ b/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp @@ -193,7 +193,7 @@ class BroadcastRadioHalTest : public testing::TestWithParam { MATCHER_P(InfoHasId, id, std::string(negation ? "does not contain" : "contains") + " " + id.toString()) { - vector ids = bcutils::getAllIds(arg.selector, id.type); + vector ids = bcutils::getAllIds(arg.selector, id.type); return ids.end() != find(ids.begin(), ids.end(), id.value); } @@ -697,7 +697,7 @@ TEST_P(BroadcastRadioHalTest, FmTune) { LOG(DEBUG) << "Current program info: " << infoCb.toString(); // it should tune exactly to what was requested - vector freqs = bcutils::getAllIds(infoCb.selector, IdentifierType::AMFM_FREQUENCY_KHZ); + vector freqs = bcutils::getAllIds(infoCb.selector, IdentifierType::AMFM_FREQUENCY_KHZ); EXPECT_NE(freqs.end(), find(freqs.begin(), freqs.end(), freq)) << "FM freq " << freq << " kHz is not sent back by callback."; } @@ -829,7 +829,7 @@ TEST_P(BroadcastRadioHalTest, DabTune) { LOG(DEBUG) << "Current program info: " << infoCb.toString(); // it should tune exactly to what was requested - vector freqs = bcutils::getAllIds(infoCb.selector, IdentifierType::DAB_FREQUENCY_KHZ); + vector freqs = bcutils::getAllIds(infoCb.selector, IdentifierType::DAB_FREQUENCY_KHZ); EXPECT_NE(freqs.end(), find(freqs.begin(), freqs.end(), freq)) << "DAB freq " << freq << " kHz is not sent back by callback."; } @@ -1152,7 +1152,7 @@ TEST_P(BroadcastRadioHalTest, GetProgramListFromAmFmFilter) { int expectedResultSize = 0; uint64_t expectedFreq = 0; for (const auto& program : *completeList) { - vector amfmIds = + vector amfmIds = bcutils::getAllIds(program.selector, IdentifierType::AMFM_FREQUENCY_KHZ); EXPECT_LE(amfmIds.size(), 1u); if (amfmIds.size() == 0) { @@ -1238,7 +1238,8 @@ TEST_P(BroadcastRadioHalTest, HdRadioStationNameId) { } for (const auto& program : *list) { - vector nameIds = bcutils::getAllIds(program.selector, IdentifierType::HD_STATION_NAME); + vector nameIds = + bcutils::getAllIds(program.selector, IdentifierType::HD_STATION_NAME); EXPECT_LE(nameIds.size(), 1u); if (nameIds.size() == 0) { continue; diff --git a/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h b/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h index 25c96d075f..a34ee10507 100644 --- a/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h +++ b/broadcastradio/common/utilsaidl/include/broadcastradio-utils-aidl/Utils.h @@ -121,7 +121,7 @@ int64_t getId(const ProgramSelector& sel, const IdentifierType& type, int64_t de /** * Returns all IDs of a given type. */ -std::vector getAllIds(const ProgramSelector& sel, const IdentifierType& type); +std::vector getAllIds(const ProgramSelector& sel, const IdentifierType& type); /** * Checks, if a given selector is supported by the radio module. diff --git a/broadcastradio/common/utilsaidl/src/Utils.cpp b/broadcastradio/common/utilsaidl/src/Utils.cpp index 4ab04d2a52..3de18660eb 100644 --- a/broadcastradio/common/utilsaidl/src/Utils.cpp +++ b/broadcastradio/common/utilsaidl/src/Utils.cpp @@ -178,8 +178,8 @@ int64_t getId(const ProgramSelector& sel, const IdentifierType& type, int64_t de return getId(sel, type); } -vector getAllIds(const ProgramSelector& sel, const IdentifierType& type) { - vector ret; +vector getAllIds(const ProgramSelector& sel, const IdentifierType& type) { + vector ret; // iterate through primaryId and secondaryIds for (auto it = begin(sel); it != end(sel); it++) { diff --git a/broadcastradio/common/utilsaidl/test/BroadcastRadioUtilsTest.cpp b/broadcastradio/common/utilsaidl/test/BroadcastRadioUtilsTest.cpp index b633ff0af2..81f94706a8 100644 --- a/broadcastradio/common/utilsaidl/test/BroadcastRadioUtilsTest.cpp +++ b/broadcastradio/common/utilsaidl/test/BroadcastRadioUtilsTest.cpp @@ -237,13 +237,22 @@ TEST(BroadcastRadioUtilsTest, GetAllIdsWithAvailableIds) { sel.secondaryIds.push_back( utils::makeIdentifier(IdentifierType::AMFM_FREQUENCY_KHZ, secondaryFrequencyKHz)); - std::vector allIds = utils::getAllIds(sel, IdentifierType::AMFM_FREQUENCY_KHZ); + std::vector allIds = utils::getAllIds(sel, IdentifierType::AMFM_FREQUENCY_KHZ); ASSERT_EQ(allIds.size(), 2u); EXPECT_NE(std::find(allIds.begin(), allIds.end(), kFmFrequencyKHz), allIds.end()); EXPECT_NE(std::find(allIds.begin(), allIds.end(), secondaryFrequencyKHz), allIds.end()); } +TEST(BroadcastRadioUtilsTest, GetAllIdsWithIdLongerThan32Bit) { + ProgramSelector sel = utils::makeSelectorDab(kDabSidExt, kDabEnsemble, kDabFrequencyKhz); + + std::vector allIds = utils::getAllIds(sel, IdentifierType::DAB_SID_EXT); + + ASSERT_EQ(allIds.size(), 1u); + EXPECT_NE(std::find(allIds.begin(), allIds.end(), kDabSidExt), allIds.end()); +} + TEST(BroadcastRadioUtilsTest, GetAllIdsWithIdNotFound) { ProgramSelector sel = utils::makeSelectorDab(kDabSidExt, kDabEnsemble, kDabFrequencyKhz);