Ady Abraham | 78cd1c3 | 2019-03-12 15:38:18 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 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 "LibSurfaceFlingerUnittests" |
| 19 | #define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include <memory> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | #include <log/log.h> |
| 27 | |
| 28 | #include "AllowedDisplayConfigs.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace { |
| 32 | |
| 33 | class AllowedDisplayConfigsTest : public testing::Test { |
| 34 | protected: |
| 35 | AllowedDisplayConfigsTest(); |
| 36 | ~AllowedDisplayConfigsTest() override; |
| 37 | |
| 38 | void buildAllowedConfigs(); |
| 39 | |
| 40 | const std::vector<int32_t> expectedConfigs = {0, 2, 7, 129}; |
| 41 | constexpr static int32_t notAllowedConfig = 5; |
| 42 | std::unique_ptr<const AllowedDisplayConfigs> mAllowedConfigs; |
| 43 | }; |
| 44 | |
| 45 | AllowedDisplayConfigsTest::AllowedDisplayConfigsTest() { |
| 46 | const ::testing::TestInfo* const test_info = |
| 47 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 48 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 49 | } |
| 50 | |
| 51 | AllowedDisplayConfigsTest::~AllowedDisplayConfigsTest() { |
| 52 | const ::testing::TestInfo* const test_info = |
| 53 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 54 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 55 | } |
| 56 | |
| 57 | void AllowedDisplayConfigsTest::buildAllowedConfigs() { |
| 58 | AllowedDisplayConfigs::Builder builder; |
| 59 | for (int config : expectedConfigs) { |
| 60 | builder.addConfig(config); |
| 61 | } |
| 62 | mAllowedConfigs = builder.build(); |
| 63 | } |
| 64 | |
| 65 | /* ------------------------------------------------------------------------ |
| 66 | * Test cases |
| 67 | */ |
| 68 | |
| 69 | TEST_F(AllowedDisplayConfigsTest, checkConfigs) { |
| 70 | buildAllowedConfigs(); |
| 71 | |
| 72 | // Check that all expected configs are allowed |
| 73 | for (int config : expectedConfigs) { |
| 74 | EXPECT_TRUE(mAllowedConfigs->isConfigAllowed(config)); |
| 75 | } |
| 76 | |
| 77 | // Check that all the allowed configs are expected |
| 78 | std::vector<int32_t> allowedConfigVector; |
| 79 | mAllowedConfigs->getAllowedConfigs(&allowedConfigVector); |
| 80 | EXPECT_EQ(allowedConfigVector, expectedConfigs); |
| 81 | |
| 82 | // Check that notAllowedConfig is indeed not allowed |
| 83 | EXPECT_TRUE(std::find(expectedConfigs.begin(), expectedConfigs.end(), notAllowedConfig) == |
| 84 | expectedConfigs.end()); |
| 85 | EXPECT_FALSE(mAllowedConfigs->isConfigAllowed(notAllowedConfig)); |
| 86 | } |
| 87 | |
| 88 | TEST_F(AllowedDisplayConfigsTest, getAllowedConfigsNullptr) { |
| 89 | buildAllowedConfigs(); |
| 90 | |
| 91 | // No other expectations rather than no crash |
| 92 | mAllowedConfigs->getAllowedConfigs(nullptr); |
| 93 | } |
| 94 | |
| 95 | } // namespace |
| 96 | } // namespace android |