Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | using android::BBinder; |
| 22 | using android::OK; |
| 23 | using android::sp; |
| 24 | |
| 25 | const void* kObjectId1 = reinterpret_cast<const void*>(1); |
| 26 | const void* kObjectId2 = reinterpret_cast<const void*>(2); |
| 27 | void* kObject1 = reinterpret_cast<void*>(101); |
| 28 | void* kObject2 = reinterpret_cast<void*>(102); |
| 29 | void* kObject3 = reinterpret_cast<void*>(103); |
| 30 | |
| 31 | TEST(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 | |
| 38 | TEST(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 | } |