Merge "Convert audio hal test to use VtsHalHidlTargetTestEnvBase"
This commit is contained in:
commit
27a7eb5796
2 changed files with 13 additions and 5 deletions
|
@ -20,6 +20,7 @@
|
|||
#include <functional>
|
||||
#include <list>
|
||||
|
||||
#include <VtsHalHidlTargetTestEnvBase.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace android {
|
||||
|
@ -33,13 +34,13 @@ namespace utility {
|
|||
* Avoid destroying static objects after main return.
|
||||
* Post main return destruction leads to incorrect gtest timing measurements as
|
||||
* well as harder debuging if anything goes wrong during destruction. */
|
||||
class Environment : public ::testing::Environment {
|
||||
class Environment : public ::testing::VtsHalHidlTargetTestEnvBase {
|
||||
public:
|
||||
using TearDownFunc = std::function<void()>;
|
||||
void registerTearDown(TearDownFunc&& tearDown) { tearDowns.push_back(std::move(tearDown)); }
|
||||
|
||||
private:
|
||||
void TearDown() override {
|
||||
void HidlTearDown() override {
|
||||
// Call the tear downs in reverse order of insertion
|
||||
for (auto& tearDown : tearDowns) {
|
||||
tearDown();
|
||||
|
|
|
@ -88,8 +88,13 @@ using ::android::hardware::audio::common::V2_0::ThreadInfo;
|
|||
|
||||
using namespace ::android::hardware::audio::common::test::utility;
|
||||
|
||||
class AudioHidlTestEnvironment : public ::Environment {
|
||||
public:
|
||||
virtual void registerTestServices() override { registerTestService<IDevicesFactory>(); }
|
||||
};
|
||||
|
||||
// Instance to register global tearDown
|
||||
static Environment* environment;
|
||||
static AudioHidlTestEnvironment* environment;
|
||||
|
||||
class HidlTest : public ::testing::VtsHalHidlTargetTestBase {
|
||||
protected:
|
||||
|
@ -109,7 +114,8 @@ class AudioHidlTest : public HidlTest {
|
|||
|
||||
if (devicesFactory == nullptr) {
|
||||
environment->registerTearDown([] { devicesFactory.clear(); });
|
||||
devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>();
|
||||
devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>(
|
||||
environment->getServiceName<IDevicesFactory>("default"));
|
||||
}
|
||||
ASSERT_TRUE(devicesFactory != nullptr);
|
||||
}
|
||||
|
@ -1265,9 +1271,10 @@ TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
environment = new Environment;
|
||||
environment = new AudioHidlTestEnvironment;
|
||||
::testing::AddGlobalTestEnvironment(environment);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
environment->init(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
return status;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue