Michael Wright | c1359ac | 2022-07-01 02:42:10 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2022 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 <optional> |
| 18 | #define LOG_TAG "PowerHalLoaderTest" |
| 19 | |
| 20 | #include <android-base/logging.h> |
| 21 | #include <android/WorkSource.h> |
| 22 | #include <binder/Parcel.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | #include <future> |
| 26 | |
| 27 | using namespace android; |
| 28 | using namespace testing; |
| 29 | |
| 30 | TEST(WorkSourceTest, Parcel) { |
| 31 | std::vector<int32_t> uids = {1, 2}; |
| 32 | using Names = std::vector<std::optional<String16>>; |
| 33 | std::optional<Names> names = std::make_optional<Names>({std::make_optional(String16("name"))}); |
| 34 | os::WorkSource ws{uids, names}; |
| 35 | |
| 36 | Parcel p; |
| 37 | ws.writeToParcel(&p); |
| 38 | p.setDataPosition(0); |
| 39 | |
| 40 | os::WorkSource otherWs; |
| 41 | otherWs.readFromParcel(&p); |
| 42 | |
| 43 | EXPECT_EQ(ws, otherWs); |
| 44 | EXPECT_EQ(uids, otherWs.getUids()); |
| 45 | EXPECT_EQ(names, otherWs.getNames()); |
| 46 | } |