blob: 1be0c59c7849fb3cded4f7f51af6dc956012b1aa [file] [log] [blame]
Steven Moreland63a2d512021-06-25 01:10:15 +00001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <binder/Binder.h>
18#include <binder/IBinder.h>
19#include <gtest/gtest.h>
20
21using android::BBinder;
22using android::OK;
23using android::sp;
24
25const void* kObjectId1 = reinterpret_cast<const void*>(1);
26const void* kObjectId2 = reinterpret_cast<const void*>(2);
27void* kObject1 = reinterpret_cast<void*>(101);
28void* kObject2 = reinterpret_cast<void*>(102);
29void* kObject3 = reinterpret_cast<void*>(103);
30
31TEST(Binder, AttachObject) {
32 auto binder = sp<BBinder>::make();
33 EXPECT_EQ(nullptr, binder->attachObject(kObjectId1, kObject1, nullptr, nullptr));
34 EXPECT_EQ(nullptr, binder->attachObject(kObjectId2, kObject2, nullptr, nullptr));
35 EXPECT_EQ(kObject1, binder->attachObject(kObjectId1, kObject3, nullptr, nullptr));
36}
37
38TEST(Binder, DetachObject) {
39 auto binder = sp<BBinder>::make();
40 EXPECT_EQ(nullptr, binder->attachObject(kObjectId1, kObject1, nullptr, nullptr));
41 EXPECT_EQ(kObject1, binder->detachObject(kObjectId1));
42 EXPECT_EQ(nullptr, binder->attachObject(kObjectId1, kObject2, nullptr, nullptr));
43}