Test HIDL safe_union destructors (C++)
This change implements a GTest test-case to exercise destructors
synthesized for HIDL safe unions.
Bug: 79878527
Test: Ran the hidl_test suite (including the new test)
Change-Id: I70e702e693717696ac2d42acfcbb29988790d024
diff --git a/test/hidl_test/hidl_test_client.cpp b/test/hidl_test/hidl_test_client.cpp
index f181c10..aec8406 100644
--- a/test/hidl_test/hidl_test_client.cpp
+++ b/test/hidl_test/hidl_test_client.cpp
@@ -2015,6 +2015,31 @@
}));
}
+TEST_F(HidlTest, SafeUnionSimpleDestructorTest) {
+ sp<IOtherInterface> otherInterface = new OtherInterface();
+ ASSERT_EQ(1, otherInterface->getStrongCount());
+
+ {
+ InterfaceTypeSafeUnion safeUnion;
+ safeUnion.c(otherInterface);
+ EXPECT_EQ(2, otherInterface->getStrongCount());
+ }
+
+ EXPECT_EQ(1, otherInterface->getStrongCount());
+}
+
+TEST_F(HidlTest, SafeUnionSwitchActiveComponentsDestructorTest) {
+ sp<IOtherInterface> otherInterface = new OtherInterface();
+ ASSERT_EQ(1, otherInterface->getStrongCount());
+
+ InterfaceTypeSafeUnion safeUnion;
+ safeUnion.c(otherInterface);
+ EXPECT_EQ(2, otherInterface->getStrongCount());
+
+ safeUnion.a(1);
+ EXPECT_EQ(1, otherInterface->getStrongCount());
+}
+
class HidlMultithreadTest : public ::testing::Test {
public:
sp<IMultithread> multithreadInterface;