summaryrefslogtreecommitdiffstats
path: root/vibrator/1.2
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2018-02-23 21:21:26 +0000
committerMichael Wright <michaelwr@google.com>2018-03-01 22:15:13 +0000
commit47cde04edda4f9144ff5f2aa14e571b3ec458915 (patch)
tree8b6d03ea04ce92b4a593329432a5dd7b84baaacf /vibrator/1.2
parent668583d52900b1f653bbd9c66c91cd318e0b9b46 (diff)
downloadplatform_hardware_interfaces-47cde04edda4f9144ff5f2aa14e571b3ec458915.tar.gz
platform_hardware_interfaces-47cde04edda4f9144ff5f2aa14e571b3ec458915.tar.bz2
platform_hardware_interfaces-47cde04edda4f9144ff5f2aa14e571b3ec458915.zip
Add functional tests for bad input to 1.2
Bug: 73336721 Test: run vts Change-Id: Idec3fe2c168fe56d9d51a2460ac3b39ae4a05416
Diffstat (limited to 'vibrator/1.2')
-rw-r--r--vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp58
1 files changed, 54 insertions, 4 deletions
diff --git a/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp b/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp
index d8df18bbf1..3ed689aa86 100644
--- a/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp
+++ b/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp
@@ -33,6 +33,8 @@ using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
+#define EXPECT_OK(ret) ASSERT_TRUE((ret).isOk())
+
// Test environment for Vibrator HIDL HAL.
class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
@@ -65,22 +67,70 @@ class VibratorHidlTest_1_2 : public ::testing::VtsHalHidlTargetTestBase {
static void validatePerformEffect(Status status, uint32_t lengthMs) {
ASSERT_TRUE(status == Status::OK || status == Status::UNSUPPORTED_OPERATION);
if (status == Status::OK) {
- ASSERT_GT(lengthMs, static_cast<uint32_t>(0))
- << "Effects that return OK must return a non-zero duration";
+ ASSERT_LT(static_cast<uint32_t>(0), lengthMs)
+ << "Effects that return OK must return a positive duration";
} else {
- ASSERT_EQ(lengthMs, static_cast<uint32_t>(0))
+ ASSERT_EQ(static_cast<uint32_t>(0), lengthMs)
<< "Effects that return UNSUPPORTED_OPERATION must have a duration of zero";
}
}
+static void validatePerformEffectBadInput(Status status, uint32_t lengthMs) {
+ ASSERT_EQ(Status::UNSUPPORTED_OPERATION, status);
+ ASSERT_EQ(static_cast<uint32_t>(0), lengthMs)
+ << "Effects that return UNSUPPORTED_OPERATION must have a duration of zero";
+}
+
+/*
+ * Test to make sure effects within the valid range return are either supported and return OK with
+ * a valid duration, or are unsupported and return UNSUPPORTED_OPERATION with a duration of 0.
+ */
TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2) {
for (const auto& effect : hidl_enum_iterator<Effect>()) {
for (const auto& strength : hidl_enum_iterator<EffectStrength>()) {
- vibrator->perform_1_2(effect, strength, validatePerformEffect);
+ EXPECT_OK(vibrator->perform_1_2(effect, strength, validatePerformEffect));
}
}
}
+/*
+ * Test to make sure effect values above the valid range are rejected.
+ */
+TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_AboveValidRange) {
+ Effect effect = *std::prev(hidl_enum_iterator<Effect>().end());
+ Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) + 1);
+ EXPECT_OK(
+ vibrator->perform_1_2(badEffect, EffectStrength::LIGHT, validatePerformEffectBadInput));
+}
+
+/*
+ * Test to make sure effect values below the valid range are rejected.
+ */
+TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_BelowValidRange) {
+ Effect effect = *hidl_enum_iterator<Effect>().begin();
+ Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) - 1);
+ EXPECT_OK(
+ vibrator->perform_1_2(badEffect, EffectStrength::LIGHT, validatePerformEffectBadInput));
+}
+
+/*
+ * Test to make sure strength values above the valid range are rejected.
+ */
+TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_AboveValidRange) {
+ EffectStrength strength = *std::prev(hidl_enum_iterator<EffectStrength>().end());
+ EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) + 1);
+ EXPECT_OK(vibrator->perform_1_2(Effect::THUD, badStrength, validatePerformEffectBadInput));
+}
+
+/*
+ * Test to make sure strength values below the valid range are rejected.
+ */
+TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_BelowValidRange) {
+ EffectStrength strength = *hidl_enum_iterator<EffectStrength>().begin();
+ EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) - 1);
+ EXPECT_OK(vibrator->perform_1_2(Effect::THUD, badStrength, validatePerformEffectBadInput));
+}
+
int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);