1 /*
2 * Copyright 2023 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 #undef LOG_TAG
18 #define LOG_TAG "SmallAreaDetectionAllowMappingsTest"
19
20 #include <gtest/gtest.h>
21
22 #include "Scheduler/SmallAreaDetectionAllowMappings.h"
23
24 namespace android::scheduler {
25
26 class SmallAreaDetectionAllowMappingsTest : public testing::Test {
27 protected:
28 SmallAreaDetectionAllowMappings mMappings;
29 static constexpr int32_t kAppId1 = 10100;
30 static constexpr int32_t kAppId2 = 10101;
31 static constexpr float kThreshold1 = 0.05f;
32 static constexpr float kThreshold2 = 0.07f;
33 };
34
35 namespace {
TEST_F(SmallAreaDetectionAllowMappingsTest,testUpdate)36 TEST_F(SmallAreaDetectionAllowMappingsTest, testUpdate) {
37 std::vector<std::pair<int32_t, float>> mappings;
38 mappings.reserve(2);
39 mappings.push_back(std::make_pair(kAppId1, kThreshold1));
40 mappings.push_back(std::make_pair(kAppId2, kThreshold2));
41
42 mMappings.update(mappings);
43 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1).value(), kThreshold1);
44 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId2).value(), kThreshold2);
45 }
46
TEST_F(SmallAreaDetectionAllowMappingsTest,testSetThresholdForAppId)47 TEST_F(SmallAreaDetectionAllowMappingsTest, testSetThresholdForAppId) {
48 mMappings.setThresholdForAppId(kAppId1, kThreshold1);
49 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1), kThreshold1);
50 }
51
TEST_F(SmallAreaDetectionAllowMappingsTest,testAppIdNotInTheMappings)52 TEST_F(SmallAreaDetectionAllowMappingsTest, testAppIdNotInTheMappings) {
53 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1), std::nullopt);
54 }
55
56 } // namespace
57 } // namespace android::scheduler
58