Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 "RuleGenerator.h" |
| 18 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 19 | #include "aapt/SdkConstants.h" |
| 20 | #include "TestRules.h" |
| 21 | |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 23 | #include <utils/Vector.h> |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 24 | |
| 25 | using namespace android; |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 26 | using namespace split::test; |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 27 | |
| 28 | namespace split { |
| 29 | |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 30 | TEST(RuleGeneratorTest, testAbiRules) { |
| 31 | Vector<abi::Variant> abis; |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 32 | const ssize_t armeabiIndex = abis.add(abi::Variant_armeabi); |
| 33 | const ssize_t armeabi_v7aIndex = abis.add(abi::Variant_armeabi_v7a); |
| 34 | const ssize_t x86Index = abis.add(abi::Variant_x86); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 35 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 36 | EXPECT_RULES_EQ(RuleGenerator::generateAbi(abis, armeabiIndex), |
| 37 | ContainsAnyRule(Rule::NATIVE_PLATFORM, "armeabi") |
| 38 | ); |
| 39 | |
| 40 | EXPECT_RULES_EQ(RuleGenerator::generateAbi(abis, armeabi_v7aIndex), |
| 41 | ContainsAnyRule(Rule::NATIVE_PLATFORM, "armeabi-v7a", "arm64-v8a") |
| 42 | ); |
| 43 | |
| 44 | EXPECT_RULES_EQ(RuleGenerator::generateAbi(abis, x86Index), |
| 45 | ContainsAnyRule(Rule::NATIVE_PLATFORM, "x86", "x86_64") |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | TEST(RuleGeneratorTest, densityConstantsAreSane) { |
Adam Lesinski | 4d29c66 | 2014-11-10 14:32:11 -0800 | [diff] [blame] | 50 | EXPECT_LT(263, (int) ConfigDescription::DENSITY_XHIGH); |
| 51 | EXPECT_GT(262, (int) ConfigDescription::DENSITY_HIGH); |
| 52 | EXPECT_LT(363, (int) ConfigDescription::DENSITY_XXHIGH); |
| 53 | EXPECT_GT(362, (int) ConfigDescription::DENSITY_XHIGH); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | TEST(RuleGeneratorTest, testDensityRules) { |
| 57 | Vector<int> densities; |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 58 | const ssize_t highIndex = densities.add(ConfigDescription::DENSITY_HIGH); |
| 59 | const ssize_t xhighIndex = densities.add(ConfigDescription::DENSITY_XHIGH); |
| 60 | const ssize_t xxhighIndex = densities.add(ConfigDescription::DENSITY_XXHIGH); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 61 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 62 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, highIndex), |
| 63 | AndRule() |
| 64 | .add(LtRule(Rule::SCREEN_DENSITY, 263)) |
| 65 | ); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 66 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 67 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xhighIndex), |
| 68 | AndRule() |
| 69 | .add(GtRule(Rule::SCREEN_DENSITY, 262)) |
| 70 | .add(LtRule(Rule::SCREEN_DENSITY, 363)) |
| 71 | ); |
| 72 | |
| 73 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xxhighIndex), |
| 74 | AndRule() |
| 75 | .add(GtRule(Rule::SCREEN_DENSITY, 362)) |
| 76 | ); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 79 | TEST(RuleGeneratorTest, testDensityRulesWithAnyDpi) { |
| 80 | Vector<int> densities; |
| 81 | const ssize_t highIndex = densities.add(ConfigDescription::DENSITY_HIGH); |
| 82 | const ssize_t xhighIndex = densities.add(ConfigDescription::DENSITY_XHIGH); |
| 83 | const ssize_t xxhighIndex = densities.add(ConfigDescription::DENSITY_XXHIGH); |
| 84 | const ssize_t anyIndex = densities.add(ConfigDescription::DENSITY_ANY); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 85 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 86 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, highIndex), |
| 87 | AndRule() |
| 88 | .add(LtRule(Rule::SDK_VERSION, SDK_LOLLIPOP)) |
| 89 | .add(LtRule(Rule::SCREEN_DENSITY, 263)) |
| 90 | ); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 91 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 92 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xhighIndex), |
| 93 | AndRule() |
| 94 | .add(LtRule(Rule::SDK_VERSION, SDK_LOLLIPOP)) |
| 95 | .add(GtRule(Rule::SCREEN_DENSITY, 262)) |
| 96 | .add(LtRule(Rule::SCREEN_DENSITY, 363)) |
| 97 | ); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 98 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 99 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xxhighIndex), |
| 100 | AndRule() |
| 101 | .add(LtRule(Rule::SDK_VERSION, SDK_LOLLIPOP)) |
| 102 | .add(GtRule(Rule::SCREEN_DENSITY, 362)) |
| 103 | ); |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 104 | |
Adam Lesinski | dcdfe9f | 2014-11-06 12:54:36 -0800 | [diff] [blame] | 105 | // We expect AlwaysTrue because anydpi always has attached v21 to the configuration |
| 106 | // and the rest of the rule generation code generates the sdk version checks. |
| 107 | EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, anyIndex), AlwaysTrue()); |
Adam Lesinski | c3dc0b5 | 2014-11-03 12:05:15 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 110 | } // namespace split |