1 /*
2  * Copyright (c) 2021, 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 #ifndef CPP_WATCHDOG_SERVER_TESTS_PACKAGEINFOTESTUTILS_H_
18 #define CPP_WATCHDOG_SERVER_TESTS_PACKAGEINFOTESTUTILS_H_
19 
20 #include <aidl/android/automotive/watchdog/internal/ApplicationCategoryType.h>
21 #include <aidl/android/automotive/watchdog/internal/ComponentType.h>
22 #include <aidl/android/automotive/watchdog/internal/PackageInfo.h>
23 #include <aidl/android/automotive/watchdog/internal/UidType.h>
24 #include <gmock/gmock.h>
25 
26 #include <string>
27 #include <vector>
28 
29 namespace android {
30 namespace automotive {
31 namespace watchdog {
32 
33 aidl::android::automotive::watchdog::internal::PackageInfo constructPackageInfo(
34         const char* packageName, int32_t uid,
35         aidl::android::automotive::watchdog::internal::UidType uidType =
36                 aidl::android::automotive::watchdog::internal::UidType::UNKNOWN,
37         aidl::android::automotive::watchdog::internal::ComponentType componentType =
38                 aidl::android::automotive::watchdog::internal::ComponentType::UNKNOWN,
39         aidl::android::automotive::watchdog::internal::ApplicationCategoryType appCategoryType =
40                 aidl::android::automotive::watchdog::internal::ApplicationCategoryType::OTHERS,
41         std::vector<std::string> sharedUidPackages = {});
42 
43 aidl::android::automotive::watchdog::internal::PackageInfo constructAppPackageInfo(
44         const char* packageName,
45         const aidl::android::automotive::watchdog::internal::ComponentType componentType,
46         const aidl::android::automotive::watchdog::internal::ApplicationCategoryType
47                 appCategoryType = aidl::android::automotive::watchdog::internal::
48                         ApplicationCategoryType::OTHERS,
49         const std::vector<std::string>& sharedUidPackages = {});
50 
51 MATCHER_P(PackageIdentifierEq, expected, "") {
52     const auto& actual = arg;
53     return ::testing::Value(actual.name, ::testing::Eq(expected.name)) &&
54             ::testing::Value(actual.uid, ::testing::Eq(expected.uid));
55 }
56 
57 MATCHER_P(PackageInfoEq, expected, "") {
58     const auto& actual = arg;
59     return ::testing::Value(actual.packageIdentifier,
60                             PackageIdentifierEq(expected.packageIdentifier)) &&
61             ::testing::Value(actual.uidType, ::testing::Eq(expected.uidType)) &&
62             ::testing::Value(actual.sharedUidPackages,
63                              ::testing::UnorderedElementsAreArray(expected.sharedUidPackages)) &&
64             ::testing::Value(actual.componentType, ::testing::Eq(expected.componentType)) &&
65             ::testing::Value(actual.appCategoryType, ::testing::Eq(expected.appCategoryType));
66 }
67 
68 }  // namespace watchdog
69 }  // namespace automotive
70 }  // namespace android
71 
72 #endif  // CPP_WATCHDOG_SERVER_TESTS_PACKAGEINFOTESTUTILS_H_
73