Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd8b30c4 authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "SpAIBinder: allow comparison with pointers" into main

parents 27af6c5a 25b25fc6
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -115,17 +115,29 @@ class SpAIBinder {
     */
    AIBinder** getR() { return &mBinder; }

    bool operator!=(const SpAIBinder& rhs) const { return get() != rhs.get(); }
    bool operator<(const SpAIBinder& rhs) const { return get() < rhs.get(); }
    bool operator<=(const SpAIBinder& rhs) const { return get() <= rhs.get(); }
    bool operator==(const SpAIBinder& rhs) const { return get() == rhs.get(); }
    bool operator>(const SpAIBinder& rhs) const { return get() > rhs.get(); }
    bool operator>=(const SpAIBinder& rhs) const { return get() >= rhs.get(); }

   private:
    AIBinder* mBinder = nullptr;
};

#define SP_AIBINDER_COMPARE(_op_)                                                    \
    static inline bool operator _op_(const SpAIBinder& lhs, const SpAIBinder& rhs) { \
        return lhs.get() _op_ rhs.get();                                             \
    }                                                                                \
    static inline bool operator _op_(const SpAIBinder& lhs, const AIBinder* rhs) {   \
        return lhs.get() _op_ rhs;                                                   \
    }                                                                                \
    static inline bool operator _op_(const AIBinder* lhs, const SpAIBinder& rhs) {   \
        return lhs _op_ rhs.get();                                                   \
    }

SP_AIBINDER_COMPARE(!=)
SP_AIBINDER_COMPARE(<)
SP_AIBINDER_COMPARE(<=)
SP_AIBINDER_COMPARE(==)
SP_AIBINDER_COMPARE(>)
SP_AIBINDER_COMPARE(>=)
#undef SP_AIBINDER_COMPARE

namespace impl {

/**
+3 −3
Original line number Diff line number Diff line
@@ -761,9 +761,9 @@ TEST(NdkBinder, ConvertToPlatformBinder) {
          // local
          ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder()}) {
        // convert to platform binder
        EXPECT_NE(binder.get(), nullptr);
        EXPECT_NE(binder, nullptr);
        sp<IBinder> platformBinder = AIBinder_toPlatformBinder(binder.get());
        EXPECT_NE(platformBinder.get(), nullptr);
        EXPECT_NE(platformBinder, nullptr);
        auto proxy = interface_cast<IBinderNdkUnitTest>(platformBinder);
        EXPECT_NE(proxy, nullptr);

@@ -774,7 +774,7 @@ TEST(NdkBinder, ConvertToPlatformBinder) {

        // convert back
        ndk::SpAIBinder backBinder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(platformBinder));
        EXPECT_EQ(backBinder.get(), binder.get());
        EXPECT_EQ(backBinder, binder);
    }
}