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