blob: 470cadcde72fcef1c708d126901bfeeb184367c0 [file] [log] [blame]
Adam Lesinski40e8eef2014-09-16 14:43:29 -07001/*
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 Lesinskidcdfe9f2014-11-06 12:54:36 -080019#include "aapt/SdkConstants.h"
20#include "TestRules.h"
21
Adam Lesinski40e8eef2014-09-16 14:43:29 -070022#include <gtest/gtest.h>
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080023#include <utils/Vector.h>
Adam Lesinski40e8eef2014-09-16 14:43:29 -070024
25using namespace android;
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080026using namespace split::test;
Adam Lesinski40e8eef2014-09-16 14:43:29 -070027
28namespace split {
29
Adam Lesinski40e8eef2014-09-16 14:43:29 -070030TEST(RuleGeneratorTest, testAbiRules) {
31 Vector<abi::Variant> abis;
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080032 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 Lesinski40e8eef2014-09-16 14:43:29 -070035
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080036 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
49TEST(RuleGeneratorTest, densityConstantsAreSane) {
Adam Lesinski4d29c662014-11-10 14:32:11 -080050 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 Lesinski40e8eef2014-09-16 14:43:29 -070054}
55
56TEST(RuleGeneratorTest, testDensityRules) {
57 Vector<int> densities;
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080058 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 Lesinski40e8eef2014-09-16 14:43:29 -070061
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080062 EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, highIndex),
63 AndRule()
64 .add(LtRule(Rule::SCREEN_DENSITY, 263))
65 );
Adam Lesinski40e8eef2014-09-16 14:43:29 -070066
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080067 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 Lesinski40e8eef2014-09-16 14:43:29 -070077}
78
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080079TEST(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 Lesinski40e8eef2014-09-16 14:43:29 -070085
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080086 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 Lesinski40e8eef2014-09-16 14:43:29 -070091
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080092 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 Lesinski40e8eef2014-09-16 14:43:29 -070098
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080099 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 Lesinski40e8eef2014-09-16 14:43:29 -0700104
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -0800105 // 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 Lesinskic3dc0b52014-11-03 12:05:15 -0800108}
109
Adam Lesinski40e8eef2014-09-16 14:43:29 -0700110} // namespace split