diff --git a/nfc/1.0/vts/functional/VtsHalNfcV1_0TargetTest.cpp b/nfc/1.0/vts/functional/VtsHalNfcV1_0TargetTest.cpp index 2f00fbb8b7..e17c961d64 100644 --- a/nfc/1.0/vts/functional/VtsHalNfcV1_0TargetTest.cpp +++ b/nfc/1.0/vts/functional/VtsHalNfcV1_0TargetTest.cpp @@ -24,6 +24,7 @@ #include #include +#include using ::android::hardware::nfc::V1_0::INfc; using ::android::hardware::nfc::V1_0::INfcClientCallback; @@ -93,11 +94,26 @@ class NfcClientCallback }; }; +// Test environment for Nfc HIDL HAL. +class NfcHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static NfcHidlEnvironment* Instance() { + static NfcHidlEnvironment* instance = new NfcHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService(); } + private: + NfcHidlEnvironment() {} +}; + // The main test class for NFC HIDL HAL. class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase { public: virtual void SetUp() override { - nfc_ = ::testing::VtsHalHidlTargetTestBase::getService(); + nfc_ = ::testing::VtsHalHidlTargetTestBase::getService( + NfcHidlEnvironment::Instance()->getServiceName()); ASSERT_NE(nfc_, nullptr); nfc_cb_ = new NfcClientCallback(); @@ -163,15 +179,6 @@ class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase { sp nfc_cb_; }; -// A class for test environment setup (kept since this file is a template). -class NfcHidlEnvironment : public ::testing::Environment { - public: - virtual void SetUp() {} - virtual void TearDown() {} - - private: -}; - /* * OpenAndClose: * Makes an open call, waits for NfcEvent.OPEN_CPLT @@ -586,8 +593,9 @@ TEST_F(NfcHidlTest, OpenAfterOpen) { } int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(new NfcHidlEnvironment); + ::testing::AddGlobalTestEnvironment(NfcHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); + NfcHidlEnvironment::Instance()->init(&argc, argv); std::system("svc nfc disable"); /* Turn off NFC */ sleep(5); diff --git a/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp b/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp index a5b40d479b..bef412b6c2 100644 --- a/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp +++ b/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp @@ -25,6 +25,7 @@ #include #include +#include using ::android::hardware::nfc::V1_1::INfc; using ::android::hardware::nfc::V1_1::INfcClientCallback; @@ -78,6 +79,20 @@ class NfcClientCallback : public ::testing::VtsHalHidlTargetCallbackBase(); } + private: + NfcHidlEnvironment() {} +}; + // The main test class for NFC HIDL HAL. class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase { public: @@ -127,15 +142,6 @@ class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase { sp nfc_cb_; }; -// A class for test environment setup (kept since this file is a template). -class NfcHidlEnvironment : public ::testing::Environment { - public: - virtual void SetUp() {} - virtual void TearDown() {} - - private: -}; - /* * factoryReset * calls factoryReset() @@ -204,8 +210,9 @@ TEST_F(NfcHidlTest, CloseForPowerCaseOffAfterClose) { } int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(new NfcHidlEnvironment); + ::testing::AddGlobalTestEnvironment(NfcHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); + NfcHidlEnvironment::Instance()->init(&argc, argv); std::system("svc nfc disable"); /* Turn off NFC */ sleep(5);