diff options
author | Janis Danisevskis <jdanis@google.com> | 2020-02-27 16:31:24 -0800 |
---|---|---|
committer | Janis Danisevskis <jdanis@google.com> | 2020-03-04 14:20:59 -0800 |
commit | df2c6716620ed292eb496993562c1560e47f38a8 (patch) | |
tree | 21c84ec90bf04075af291d5ff0056bc96778d736 /confirmationui | |
parent | a9e6f70d502a5a2cd440a1d0d803b53fe7aba4f8 (diff) |
Convert VtsHalConfirmationUIV1_0TargetTest to parameterized test
Convert VtsHalConfirmationUIV1_0TargetTest to parameterized test.
Bug: 150382633
Test: VtsHalConfirmationUIV1_0TargetTest
Merged-In: I19d02418d0ef01e6493906ea0bebfbd181e25815
Change-Id: I19d02418d0ef01e6493906ea0bebfbd181e25815
Diffstat (limited to 'confirmationui')
-rw-r--r-- | confirmationui/1.0/vts/functional/Android.bp | 2 | ||||
-rw-r--r-- | confirmationui/1.0/vts/functional/VtsHalConfirmationUIV1_0TargetTest.cpp | 124 |
2 files changed, 51 insertions, 75 deletions
diff --git a/confirmationui/1.0/vts/functional/Android.bp b/confirmationui/1.0/vts/functional/Android.bp index fd088cd360..c8b522c119 100644 --- a/confirmationui/1.0/vts/functional/Android.bp +++ b/confirmationui/1.0/vts/functional/Android.bp @@ -27,5 +27,5 @@ cc_test { "libcn-cbor", "android.hardware.confirmationui-support-lib", ], - test_suites: ["general-tests"], + test_suites: ["general-tests", "vts-core"], } diff --git a/confirmationui/1.0/vts/functional/VtsHalConfirmationUIV1_0TargetTest.cpp b/confirmationui/1.0/vts/functional/VtsHalConfirmationUIV1_0TargetTest.cpp index fb01ad065b..d953ab0fb2 100644 --- a/confirmationui/1.0/vts/functional/VtsHalConfirmationUIV1_0TargetTest.cpp +++ b/confirmationui/1.0/vts/functional/VtsHalConfirmationUIV1_0TargetTest.cpp @@ -26,8 +26,12 @@ #include <android/hardware/confirmationui/1.0/types.h> #include <android/hardware/confirmationui/support/confirmationui_utils.h> +#include <gtest/gtest.h> + #include <VtsHalHidlTargetCallbackBase.h> -#include <VtsHalHidlTargetTestBase.h> + +#include <hidl/GtestPrinter.h> +#include <hidl/ServiceManagement.h> #include <openssl/hmac.h> #include <openssl/sha.h> @@ -199,43 +203,18 @@ class ConfirmationTestCallback : public ::testing::VtsHalHidlTargetCallbackBase< } }; -class ConfirmationUIHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static ConfirmationUIHidlEnvironment* Instance() { - static ConfirmationUIHidlEnvironment* instance = new ConfirmationUIHidlEnvironment; - return instance; - } - - void registerTestServices() override { registerTestService<IConfirmationUI>(); } - - private: - ConfirmationUIHidlEnvironment(){}; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(ConfirmationUIHidlEnvironment); -}; - -class ConfirmationUIHidlTest : public ::testing::VtsHalHidlTargetTestBase { - public: - void TearDown() override { confirmator().abort(); } - - static void SetUpTestCase() { - string service_name = - ConfirmationUIHidlEnvironment::Instance()->getServiceName<IConfirmationUI>(); - confirmator_ = IConfirmationUI::getService(service_name); +class ConfirmationUIHidlTest : public ::testing::TestWithParam<std::string> { + public: + void TearDown() override { confirmator_->abort(); } + void SetUp() override { + confirmator_ = IConfirmationUI::getService(GetParam()); ASSERT_NE(nullptr, confirmator_.get()); } - static void TearDownTestCase() { confirmator_.clear(); } - - static IConfirmationUI& confirmator() { return *confirmator_; } - - private: - static sp<IConfirmationUI> confirmator_; + protected: + sp<IConfirmationUI> confirmator_; }; -sp<IConfirmationUI> ConfirmationUIHidlTest::confirmator_; - #define ASSERT_HAL_CALL(expected, call) \ { \ auto result = call; \ @@ -250,17 +229,17 @@ struct CnCborDeleter { typedef std::unique_ptr<cn_cbor, CnCborDeleter> CnCborPtr; // Simulates the User taping Ok -TEST_F(ConfirmationUIHidlTest, UserOkTest) { +TEST_P(ConfirmationUIHidlTest, UserOkTest) { static constexpr char test_prompt[] = "Me first, gimme gimme!"; static constexpr uint8_t test_extra[] = {0x1, 0x2, 0x3}; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); - ASSERT_HAL_CALL(ResponseCode::OK, confirmator().deliverSecureInputEvent( - makeTestToken(TestModeCommands::OK_EVENT))); + ASSERT_HAL_CALL(ResponseCode::OK, confirmator_->deliverSecureInputEvent( + makeTestToken(TestModeCommands::OK_EVENT))); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::OK, result.args->error_); @@ -294,40 +273,40 @@ TEST_F(ConfirmationUIHidlTest, UserOkTest) { } // Initiates a confirmation prompt with a message that is too long -TEST_F(ConfirmationUIHidlTest, MessageTooLongTest) { +TEST_P(ConfirmationUIHidlTest, MessageTooLongTest) { static constexpr uint8_t test_extra[static_cast<uint32_t>(MessageSize::MAX)] = {}; static constexpr char test_prompt[] = "D\'oh!"; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + sizeof(test_extra)); ASSERT_HAL_CALL(ResponseCode::UIErrorMessageTooLong, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); } // If the message gets very long some HAL implementations might fail even before the message // reaches the trusted app implementation. But the HAL must still diagnose the correct error. -TEST_F(ConfirmationUIHidlTest, MessageWayTooLongTest) { +TEST_P(ConfirmationUIHidlTest, MessageWayTooLongTest) { static constexpr uint8_t test_extra[static_cast<uint32_t>(MessageSize::MAX) * 10] = {}; static constexpr char test_prompt[] = "D\'oh!"; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + sizeof(test_extra)); ASSERT_HAL_CALL(ResponseCode::UIErrorMessageTooLong, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); } // Simulates the User tapping the Cancel -TEST_F(ConfirmationUIHidlTest, UserCancelTest) { +TEST_P(ConfirmationUIHidlTest, UserCancelTest) { static constexpr char test_prompt[] = "Me first, gimme gimme!"; static constexpr uint8_t test_extra[] = {0x1, 0x2, 0x3}; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); - ASSERT_HAL_CALL(ResponseCode::OK, confirmator().deliverSecureInputEvent( - makeTestToken(TestModeCommands::CANCEL_EVENT))); + ASSERT_HAL_CALL(ResponseCode::OK, confirmator_->deliverSecureInputEvent( + makeTestToken(TestModeCommands::CANCEL_EVENT))); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::Canceled, result.args->error_); @@ -337,16 +316,16 @@ TEST_F(ConfirmationUIHidlTest, UserCancelTest) { } // Simulates the framework cancelling an ongoing prompt -TEST_F(ConfirmationUIHidlTest, AbortTest) { +TEST_P(ConfirmationUIHidlTest, AbortTest) { static constexpr char test_prompt[] = "Me first, gimme gimme!"; static constexpr uint8_t test_extra[] = {0x1, 0x2, 0x3}; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); - confirmator().abort(); + confirmator_->abort(); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::Aborted, result.args->error_); @@ -356,7 +335,7 @@ TEST_F(ConfirmationUIHidlTest, AbortTest) { // Tests if the confirmation dialog can successfully render 100 'W' characters as required by // the design guidelines. -TEST_F(ConfirmationUIHidlTest, PortableMessageTest1) { +TEST_P(ConfirmationUIHidlTest, PortableMessageTest1) { static constexpr char test_prompt[] = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" "WWWWWWWWWWWWWW"; @@ -365,9 +344,9 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest1) { hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); - confirmator().abort(); + confirmator_->abort(); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::Aborted, result.args->error_); @@ -377,7 +356,7 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest1) { // Tests if the confirmation dialog can successfully render 100 'W' characters as required by // the design guidelines in magnified mode. -TEST_F(ConfirmationUIHidlTest, PortableMessageTest1Magnified) { +TEST_P(ConfirmationUIHidlTest, PortableMessageTest1Magnified) { static constexpr char test_prompt[] = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" "WWWWWWWWWWWWWW"; @@ -386,10 +365,10 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest1Magnified) { hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {UIOption::AccessibilityMagnified})); - confirmator().abort(); + confirmator_->abort(); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::Aborted, result.args->error_); @@ -399,7 +378,7 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest1Magnified) { // Tests if the confirmation dialog can successfully render 8 groups of 12 'W' characters as // required by the design guidelines. -TEST_F(ConfirmationUIHidlTest, PortableMessageTest2) { +TEST_P(ConfirmationUIHidlTest, PortableMessageTest2) { static constexpr char test_prompt[] = "WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW " "WWWWWWWWWWWW WWWWWWWWWWWW"; @@ -408,9 +387,9 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest2) { hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); - confirmator().abort(); + confirmator_->abort(); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::Aborted, result.args->error_); @@ -420,7 +399,7 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest2) { // Tests if the confirmation dialog can successfully render 8 groups of 12 'W' characters as // required by the design guidelines in magnified mode. -TEST_F(ConfirmationUIHidlTest, PortableMessageTest2Magnified) { +TEST_P(ConfirmationUIHidlTest, PortableMessageTest2Magnified) { static constexpr char test_prompt[] = "WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW " "WWWWWWWWWWWW WWWWWWWWWWWW"; @@ -429,10 +408,10 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest2Magnified) { hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::OK, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {UIOption::AccessibilityMagnified})); - confirmator().abort(); + confirmator_->abort(); auto result = conf_cb->WaitForCallback(); ASSERT_EQ(ResponseCode::Aborted, result.args->error_); @@ -442,19 +421,19 @@ TEST_F(ConfirmationUIHidlTest, PortableMessageTest2Magnified) { // Passing malformed UTF-8 to the confirmation UI // This test passes a string that ends in the middle of a multibyte character -TEST_F(ConfirmationUIHidlTest, MalformedUTF8Test1) { +TEST_P(ConfirmationUIHidlTest, MalformedUTF8Test1) { static constexpr char test_prompt[] = {char(0xc0), 0}; static constexpr uint8_t test_extra[] = {0x1, 0x2, 0x3}; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::UIErrorMalformedUTF8Encoding, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); } // Passing malformed UTF-8 to the confirmation UI // This test passes a string with a 5-byte character. -TEST_F(ConfirmationUIHidlTest, MalformedUTF8Test2) { +TEST_P(ConfirmationUIHidlTest, MalformedUTF8Test2) { static constexpr char test_prompt[] = {char(0xf8), char(0x82), char(0x82), char(0x82), char(0x82), 0}; static constexpr uint8_t test_extra[] = {0x1, 0x2, 0x3}; @@ -462,19 +441,19 @@ TEST_F(ConfirmationUIHidlTest, MalformedUTF8Test2) { hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::UIErrorMalformedUTF8Encoding, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); } // Passing malformed UTF-8 to the confirmation UI // This test passes a string with a 2-byte character followed by a stray non UTF-8 character. -TEST_F(ConfirmationUIHidlTest, MalformedUTF8Test3) { +TEST_P(ConfirmationUIHidlTest, MalformedUTF8Test3) { static constexpr char test_prompt[] = {char(0xc0), char(0x82), char(0x83), 0}; static constexpr uint8_t test_extra[] = {0x1, 0x2, 0x3}; sp<ConfirmationTestCallback> conf_cb = new ConfirmationTestCallback; hidl_string prompt_text(test_prompt); hidl_vec<uint8_t> extra(test_extra, test_extra + 3); ASSERT_HAL_CALL(ResponseCode::UIErrorMalformedUTF8Encoding, - confirmator().promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); + confirmator_->promptUserConfirmation(conf_cb, prompt_text, extra, "en", {})); } // Test the implementation of HMAC SHA 256 against a golden blob. @@ -494,16 +473,13 @@ TEST(ConfirmationUITestSelfTest, HMAC256SelfTest) { ASSERT_EQ(expected, result.value()); } +INSTANTIATE_TEST_SUITE_P( + PerInstance, ConfirmationUIHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IConfirmationUI::descriptor)), + android::hardware::PrintInstanceNameToString); + } // namespace test } // namespace V1_0 } // namespace confirmationui } // namespace hardware } // namespace android - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - std::vector<std::string> positional_args; - int status = RUN_ALL_TESTS(); - ALOGI("Test result = %d", status); - return status; -} |