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

Commit 8e0660dc authored by Parth Sane's avatar Parth Sane Committed by Automerger Merge Worker
Browse files

Merge "Add negative tests for ServiceManager RegisterForNotifications and...

Merge "Add negative tests for ServiceManager RegisterForNotifications and unregisterForNotifications" into main am: 77cd3a2b

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3111381



Change-Id: I402cf4083205cfc33ebeb1ed9862f7e9de28a285
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b1192a3a 77cd3a2b
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <binder/IServiceManager.h>
#include <binder/RpcServer.h>
#include <binder/RpcSession.h>
#include <binder/Status.h>
#include <binder/unique_fd.h>
#include <utils/Flattenable.h>

@@ -57,6 +58,7 @@ using namespace std::string_literals;
using namespace std::chrono_literals;
using android::base::testing::HasValue;
using android::base::testing::Ok;
using android::binder::Status;
using android::binder::unique_fd;
using testing::ExplainMatchResult;
using testing::Matcher;
@@ -461,6 +463,35 @@ TEST_F(BinderLibTest, AddManagerToManager) {
    EXPECT_EQ(NO_ERROR, sm->addService(String16("binderLibTest-manager"), binder));
}

TEST_F(BinderLibTest, RegisterForNotificationsFailure) {
    auto sm = defaultServiceManager();
    using LocalRegistrationCallback = IServiceManager::LocalRegistrationCallback;
    class LocalRegistrationCallbackImpl : public virtual LocalRegistrationCallback {
        void onServiceRegistration(const String16&, const sp<IBinder>&) override {}
        virtual ~LocalRegistrationCallbackImpl() {}
    };
    sp<LocalRegistrationCallback> cb = sp<LocalRegistrationCallbackImpl>::make();

    EXPECT_EQ(BAD_VALUE, sm->registerForNotifications(String16("ValidName"), nullptr));
    EXPECT_EQ(UNKNOWN_ERROR, sm->registerForNotifications(String16("InvalidName!$"), cb));
}

TEST_F(BinderLibTest, UnregisterForNotificationsFailure) {
    auto sm = defaultServiceManager();
    using LocalRegistrationCallback = IServiceManager::LocalRegistrationCallback;
    class LocalRegistrationCallbackImpl : public virtual LocalRegistrationCallback {
        void onServiceRegistration(const String16&, const sp<IBinder>&) override {}
        virtual ~LocalRegistrationCallbackImpl() {}
    };
    sp<LocalRegistrationCallback> cb = sp<LocalRegistrationCallbackImpl>::make();

    EXPECT_EQ(OK, sm->registerForNotifications(String16("ValidName"), cb));

    EXPECT_EQ(BAD_VALUE, sm->unregisterForNotifications(String16("ValidName"), nullptr));
    EXPECT_EQ(BAD_VALUE, sm->unregisterForNotifications(String16("AnotherValidName"), cb));
    EXPECT_EQ(BAD_VALUE, sm->unregisterForNotifications(String16("InvalidName!!!"), cb));
}

TEST_F(BinderLibTest, WasParceled) {
    auto binder = sp<BBinder>::make();
    EXPECT_FALSE(binder->wasParceled());