From 10877cd2e8ade1fef3c5de5edc469bc107043fa8 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Tue, 7 Mar 2017 17:04:26 -0800 Subject: [PATCH] Test ITuner::setConfiguration against bad input. Bug: b/33382424 Test: VTS Change-Id: I9c1f31e1a55e6b45e24daaec029c43c535a2e600 --- .../VtsHalBroadcastradioV1_0TargetTest.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/broadcastradio/1.0/vts/functional/VtsHalBroadcastradioV1_0TargetTest.cpp b/broadcastradio/1.0/vts/functional/VtsHalBroadcastradioV1_0TargetTest.cpp index 4268ddd3e8..42af27657a 100644 --- a/broadcastradio/1.0/vts/functional/VtsHalBroadcastradioV1_0TargetTest.cpp +++ b/broadcastradio/1.0/vts/functional/VtsHalBroadcastradioV1_0TargetTest.cpp @@ -42,6 +42,7 @@ using ::android::hardware::broadcastradio::V1_0::ITunerCallback; using ::android::hardware::broadcastradio::V1_0::Result; using ::android::hardware::broadcastradio::V1_0::Class; using ::android::hardware::broadcastradio::V1_0::Properties; +using ::android::hardware::broadcastradio::V1_0::Band; using ::android::hardware::broadcastradio::V1_0::BandConfig; using ::android::hardware::broadcastradio::V1_0::Direction; using ::android::hardware::broadcastradio::V1_0::ProgramInfo; @@ -372,6 +373,38 @@ TEST_F(BroadcastRadioHidlTest, SetAndGetConfiguration) { EXPECT_EQ(mHalProperties.bands[0].type, halConfig.type); } +/** + * Test ITuner::setConfiguration() with invalid arguments. + * + * Verifies that: + * - the methods returns INVALID_ARGUMENTS on invalid arguments + * - the method recovers and succeeds after passing correct arguments + */ +TEST_F(BroadcastRadioHidlTest, SetConfigurationFails) { + ASSERT_EQ(true, openTuner()); + + // Let's define a config that's bad for sure. + BandConfig badConfig = {}; + badConfig.type = Band::FM; + badConfig.lowerLimit = 0xFFFFFFFF; + badConfig.upperLimit = 0; + badConfig.spacings = (std::vector){ 0 }; + + // Test setConfiguration failing on bad data. + mCallbackCalled = false; + auto setResult = mTuner->setConfiguration(badConfig); + EXPECT_TRUE(setResult.isOk()); + EXPECT_EQ(Result::INVALID_ARGUMENTS, setResult); + + // Test setConfiguration recovering after passing good data. + mCallbackCalled = false; + setResult = mTuner->setConfiguration(mHalProperties.bands[0]); + EXPECT_TRUE(setResult.isOk()); + EXPECT_EQ(Result::OK, setResult); + EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs)); + EXPECT_EQ(Result::OK, mResultCallbackData); +} + /** * Test ITuner::scan *