|
40 | 40 | #include <sys/eventfd.h> |
41 | 41 | #include <sys/prctl.h> |
42 | 42 |
|
| 43 | +#include <gmock/gmock.h> |
| 44 | + |
43 | 45 | using namespace std::chrono_literals; // NOLINT - google-build-using-namespace |
44 | 46 | using android::binder::unique_fd; |
45 | 47 |
|
@@ -222,6 +224,7 @@ class ISafeInterfaceTest : public IInterface { |
222 | 224 | SetDeathToken = IBinder::FIRST_CALL_TRANSACTION, |
223 | 225 | ReturnsNoMemory, |
224 | 226 | LogicalNot, |
| 227 | + LogicalNotVector, |
225 | 228 | ModifyEnum, |
226 | 229 | IncrementFlattenable, |
227 | 230 | IncrementLightFlattenable, |
@@ -249,6 +252,7 @@ class ISafeInterfaceTest : public IInterface { |
249 | 252 |
|
250 | 253 | // These are ordered according to their corresponding methods in SafeInterface::ParcelHandler |
251 | 254 | virtual status_t logicalNot(bool a, bool* notA) const = 0; |
| 255 | + virtual status_t logicalNot(const std::vector<bool>& a, std::vector<bool>* notA) const = 0; |
252 | 256 | virtual status_t modifyEnum(TestEnum a, TestEnum* b) const = 0; |
253 | 257 | virtual status_t increment(const TestFlattenable& a, TestFlattenable* aPlusOne) const = 0; |
254 | 258 | virtual status_t increment(const TestLightFlattenable& a, |
@@ -288,7 +292,14 @@ class BpSafeInterfaceTest : public SafeBpInterface<ISafeInterfaceTest> { |
288 | 292 | } |
289 | 293 | status_t logicalNot(bool a, bool* notA) const override { |
290 | 294 | ALOG(LOG_INFO, getLogTag(), "%s", __PRETTY_FUNCTION__); |
291 | | - return callRemote<decltype(&ISafeInterfaceTest::logicalNot)>(Tag::LogicalNot, a, notA); |
| 295 | + using Signature = status_t (ISafeInterfaceTest::*)(bool, bool*) const; |
| 296 | + return callRemote<Signature>(Tag::LogicalNot, a, notA); |
| 297 | + } |
| 298 | + status_t logicalNot(const std::vector<bool>& a, std::vector<bool>* notA) const override { |
| 299 | + ALOG(LOG_INFO, getLogTag(), "%s", __PRETTY_FUNCTION__); |
| 300 | + using Signature = status_t (ISafeInterfaceTest::*)(const std::vector<bool>&, |
| 301 | + std::vector<bool>*) const; |
| 302 | + return callRemote<Signature>(Tag::LogicalNotVector, a, notA); |
292 | 303 | } |
293 | 304 | status_t modifyEnum(TestEnum a, TestEnum* b) const override { |
294 | 305 | ALOG(LOG_INFO, getLogTag(), "%s", __PRETTY_FUNCTION__); |
@@ -406,6 +417,14 @@ class BnSafeInterfaceTest : public SafeBnInterface<ISafeInterfaceTest> { |
406 | 417 | *notA = !a; |
407 | 418 | return NO_ERROR; |
408 | 419 | } |
| 420 | + status_t logicalNot(const std::vector<bool>& a, std::vector<bool>* notA) const override { |
| 421 | + ALOG(LOG_INFO, getLogTag(), "%s", __PRETTY_FUNCTION__); |
| 422 | + notA->clear(); |
| 423 | + for (bool value : a) { |
| 424 | + notA->push_back(!value); |
| 425 | + } |
| 426 | + return NO_ERROR; |
| 427 | + } |
409 | 428 | status_t modifyEnum(TestEnum a, TestEnum* b) const override { |
410 | 429 | ALOG(LOG_INFO, getLogTag(), "%s", __PRETTY_FUNCTION__); |
411 | 430 | *b = (a == TestEnum::INITIAL) ? TestEnum::FINAL : TestEnum::INVALID; |
@@ -513,7 +532,13 @@ class BnSafeInterfaceTest : public SafeBnInterface<ISafeInterfaceTest> { |
513 | 532 | return callLocal(data, reply, &ISafeInterfaceTest::returnsNoMemory); |
514 | 533 | } |
515 | 534 | case ISafeInterfaceTest::Tag::LogicalNot: { |
516 | | - return callLocal(data, reply, &ISafeInterfaceTest::logicalNot); |
| 535 | + using Signature = status_t (ISafeInterfaceTest::*)(bool a, bool* notA) const; |
| 536 | + return callLocal<Signature>(data, reply, &ISafeInterfaceTest::logicalNot); |
| 537 | + } |
| 538 | + case ISafeInterfaceTest::Tag::LogicalNotVector: { |
| 539 | + using Signature = status_t (ISafeInterfaceTest::*)(const std::vector<bool>& a, |
| 540 | + std::vector<bool>* notA) const; |
| 541 | + return callLocal<Signature>(data, reply, &ISafeInterfaceTest::logicalNot); |
517 | 542 | } |
518 | 543 | case ISafeInterfaceTest::Tag::ModifyEnum: { |
519 | 544 | return callLocal(data, reply, &ISafeInterfaceTest::modifyEnum); |
@@ -639,6 +664,15 @@ TEST_F(SafeInterfaceTest, TestLogicalNot) { |
639 | 664 | ASSERT_EQ(!b, notB); |
640 | 665 | } |
641 | 666 |
|
| 667 | +TEST_F(SafeInterfaceTest, TestLogicalNotVector) { |
| 668 | + const std::vector<bool> a = {true, false, true}; |
| 669 | + std::vector<bool> notA; |
| 670 | + status_t result = mSafeInterfaceTest->logicalNot(a, ¬A); |
| 671 | + ASSERT_EQ(NO_ERROR, result); |
| 672 | + std::vector<bool> expected = {false, true, false}; |
| 673 | + ASSERT_THAT(notA, testing::ContainerEq(expected)); |
| 674 | +} |
| 675 | + |
642 | 676 | TEST_F(SafeInterfaceTest, TestModifyEnum) { |
643 | 677 | const TestEnum a = TestEnum::INITIAL; |
644 | 678 | TestEnum b = TestEnum::INVALID; |
|
0 commit comments