Merge commit 'fa31eb2c' into manualmerge
Conflicts:
tools/split-select/RuleGenerator_test.cpp
Change-Id: I0d1261301d433f32e857cf1b0d75a861205f7625
diff --git a/tools/split-select/RuleGenerator_test.cpp b/tools/split-select/RuleGenerator_test.cpp
index 8d51118..470cadc 100644
--- a/tools/split-select/RuleGenerator_test.cpp
+++ b/tools/split-select/RuleGenerator_test.cpp
@@ -16,154 +16,95 @@
#include "RuleGenerator.h"
-#include <algorithm>
+#include "aapt/SdkConstants.h"
+#include "TestRules.h"
+
#include <gtest/gtest.h>
-#include <utils/String8.h>
+#include <utils/Vector.h>
using namespace android;
+using namespace split::test;
namespace split {
-static void expectDensityRule(const Vector<int>& densities, int density, int greaterThan, int lessThan);
-static void expectAbiRule(const Vector<abi::Variant>& abis, abi::Variant variant, const char* a);
-static void expectAbiRule(const Vector<abi::Variant>& abis, abi::Variant variant, const char* a, const char* b);
-
TEST(RuleGeneratorTest, testAbiRules) {
Vector<abi::Variant> abis;
- abis.add(abi::Variant_armeabi);
- abis.add(abi::Variant_armeabi_v7a);
- abis.add(abi::Variant_x86);
- std::sort(abis.begin(), abis.end());
+ const ssize_t armeabiIndex = abis.add(abi::Variant_armeabi);
+ const ssize_t armeabi_v7aIndex = abis.add(abi::Variant_armeabi_v7a);
+ const ssize_t x86Index = abis.add(abi::Variant_x86);
- expectAbiRule(abis, abi::Variant_armeabi, "armeabi");
- expectAbiRule(abis, abi::Variant_armeabi_v7a, "armeabi-v7a", "arm64-v8a");
- expectAbiRule(abis, abi::Variant_x86, "x86", "x86_64");
+ EXPECT_RULES_EQ(RuleGenerator::generateAbi(abis, armeabiIndex),
+ ContainsAnyRule(Rule::NATIVE_PLATFORM, "armeabi")
+ );
+
+ EXPECT_RULES_EQ(RuleGenerator::generateAbi(abis, armeabi_v7aIndex),
+ ContainsAnyRule(Rule::NATIVE_PLATFORM, "armeabi-v7a", "arm64-v8a")
+ );
+
+ EXPECT_RULES_EQ(RuleGenerator::generateAbi(abis, x86Index),
+ ContainsAnyRule(Rule::NATIVE_PLATFORM, "x86", "x86_64")
+ );
+}
+
+TEST(RuleGeneratorTest, densityConstantsAreSane) {
+ EXPECT_LT(263, (int) ConfigDescription::DENSITY_XHIGH);
+ EXPECT_GT(262, (int) ConfigDescription::DENSITY_HIGH);
+ EXPECT_LT(363, (int) ConfigDescription::DENSITY_XXHIGH);
+ EXPECT_GT(362, (int) ConfigDescription::DENSITY_XHIGH);
}
TEST(RuleGeneratorTest, testDensityRules) {
Vector<int> densities;
- densities.add(ConfigDescription::DENSITY_HIGH);
- densities.add(ConfigDescription::DENSITY_XHIGH);
- densities.add(ConfigDescription::DENSITY_XXHIGH);
- densities.add(ConfigDescription::DENSITY_ANY);
+ const ssize_t highIndex = densities.add(ConfigDescription::DENSITY_HIGH);
+ const ssize_t xhighIndex = densities.add(ConfigDescription::DENSITY_XHIGH);
+ const ssize_t xxhighIndex = densities.add(ConfigDescription::DENSITY_XXHIGH);
- ASSERT_LT(263, (int) ConfigDescription::DENSITY_XHIGH);
- ASSERT_GT(262, (int) ConfigDescription::DENSITY_HIGH);
- ASSERT_LT(363, (int) ConfigDescription::DENSITY_XXHIGH);
- ASSERT_GT(362, (int) ConfigDescription::DENSITY_XHIGH);
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, highIndex),
+ AndRule()
+ .add(LtRule(Rule::SCREEN_DENSITY, 263))
+ );
- expectDensityRule(densities, ConfigDescription::DENSITY_HIGH, 0, 263);
- expectDensityRule(densities, ConfigDescription::DENSITY_XHIGH, 262, 363);
- expectDensityRule(densities, ConfigDescription::DENSITY_XXHIGH, 362, 0);
- expectDensityRule(densities, ConfigDescription::DENSITY_ANY, 0, 0);
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xhighIndex),
+ AndRule()
+ .add(GtRule(Rule::SCREEN_DENSITY, 262))
+ .add(LtRule(Rule::SCREEN_DENSITY, 363))
+ );
+
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xxhighIndex),
+ AndRule()
+ .add(GtRule(Rule::SCREEN_DENSITY, 362))
+ );
}
-//
-// Helper methods.
-//
+TEST(RuleGeneratorTest, testDensityRulesWithAnyDpi) {
+ Vector<int> densities;
+ const ssize_t highIndex = densities.add(ConfigDescription::DENSITY_HIGH);
+ const ssize_t xhighIndex = densities.add(ConfigDescription::DENSITY_XHIGH);
+ const ssize_t xxhighIndex = densities.add(ConfigDescription::DENSITY_XXHIGH);
+ const ssize_t anyIndex = densities.add(ConfigDescription::DENSITY_ANY);
-static void expectDensityRule(const Vector<int>& densities, int density, int greaterThan, int lessThan) {
- const int* iter = std::find(densities.begin(), densities.end(), density);
- if (densities.end() == iter) {
- ADD_FAILURE() << density << "dpi was not in the density list.";
- return;
- }
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, highIndex),
+ AndRule()
+ .add(LtRule(Rule::SDK_VERSION, SDK_LOLLIPOP))
+ .add(LtRule(Rule::SCREEN_DENSITY, 263))
+ );
- sp<Rule> rule = RuleGenerator::generateDensity(densities, iter - densities.begin());
- if (rule->op != Rule::AND_SUBRULES) {
- ADD_FAILURE() << "Op in rule for " << density << "dpi is not Rule::AND_SUBRULES.";
- return;
- }
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xhighIndex),
+ AndRule()
+ .add(LtRule(Rule::SDK_VERSION, SDK_LOLLIPOP))
+ .add(GtRule(Rule::SCREEN_DENSITY, 262))
+ .add(LtRule(Rule::SCREEN_DENSITY, 363))
+ );
- size_t index = 0;
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, xxhighIndex),
+ AndRule()
+ .add(LtRule(Rule::SDK_VERSION, SDK_LOLLIPOP))
+ .add(GtRule(Rule::SCREEN_DENSITY, 362))
+ );
- bool isAnyDpi = density == ConfigDescription::DENSITY_ANY;
-
- sp<Rule> anyDpiRule = rule->subrules[index++];
- EXPECT_EQ(Rule::EQUALS, anyDpiRule->op)
- << "for " << density << "dpi ANY DPI rule";
- EXPECT_EQ(Rule::SCREEN_DENSITY, anyDpiRule->key)
- << "for " << density << "dpi ANY DPI rule";
- EXPECT_EQ(isAnyDpi == false, anyDpiRule->negate)
- << "for " << density << "dpi ANY DPI rule";
- if (anyDpiRule->longArgs.size() == 1) {
- EXPECT_EQ((long) ConfigDescription::DENSITY_ANY, anyDpiRule->longArgs[0])
- << "for " << density << "dpi ANY DPI rule";
- } else {
- EXPECT_EQ(1u, anyDpiRule->longArgs.size())
- << "for " << density << "dpi ANY DPI rule";
- }
-
-
- if (greaterThan != 0) {
- sp<Rule> greaterThanRule = rule->subrules[index++];
- EXPECT_EQ(Rule::GREATER_THAN, greaterThanRule->op)
- << "for " << density << "dpi GREATER_THAN rule";
- EXPECT_EQ(Rule::SCREEN_DENSITY, greaterThanRule->key)
- << "for " << density << "dpi GREATER_THAN rule";
- if (greaterThanRule->longArgs.size() == 1) {
- EXPECT_EQ(greaterThan, greaterThanRule->longArgs[0])
- << "for " << density << "dpi GREATER_THAN rule";
- } else {
- EXPECT_EQ(1u, greaterThanRule->longArgs.size())
- << "for " << density << "dpi GREATER_THAN rule";
- }
- }
-
- if (lessThan != 0) {
- sp<Rule> lessThanRule = rule->subrules[index++];
- EXPECT_EQ(Rule::LESS_THAN, lessThanRule->op)
- << "for " << density << "dpi LESS_THAN rule";
- EXPECT_EQ(Rule::SCREEN_DENSITY, lessThanRule->key)
- << "for " << density << "dpi LESS_THAN rule";
- if (lessThanRule->longArgs.size() == 1) {
- EXPECT_EQ(lessThan, lessThanRule->longArgs[0])
- << "for " << density << "dpi LESS_THAN rule";
- } else {
- EXPECT_EQ(1u, lessThanRule->longArgs.size())
- << "for " << density << "dpi LESS_THAN rule";
- }
- }
-}
-
-static void expectAbiRule(const Vector<abi::Variant>& abis, abi::Variant variant, const Vector<const char*>& matches) {
- const abi::Variant* iter = std::find(abis.begin(), abis.end(), variant);
- if (abis.end() == iter) {
- ADD_FAILURE() << abi::toString(variant) << " was not in the abi list.";
- return;
- }
-
- sp<Rule> rule = RuleGenerator::generateAbi(abis, iter - abis.begin());
-
- EXPECT_EQ(Rule::CONTAINS_ANY, rule->op)
- << "for " << abi::toString(variant) << " rule";
- EXPECT_EQ(Rule::NATIVE_PLATFORM, rule->key)
- << " for " << abi::toString(variant) << " rule";
- EXPECT_EQ(matches.size(), rule->stringArgs.size())
- << " for " << abi::toString(variant) << " rule";
-
- const size_t matchCount = matches.size();
- for (size_t i = 0; i < matchCount; i++) {
- const char* match = matches[i];
- if (rule->stringArgs.end() ==
- std::find(rule->stringArgs.begin(), rule->stringArgs.end(), String8(match))) {
- ADD_FAILURE() << "Rule for abi " << abi::toString(variant)
- << " does not contain match for expected abi " << match;
- }
- }
-}
-
-static void expectAbiRule(const Vector<abi::Variant>& abis, abi::Variant variant, const char* a) {
- Vector<const char*> matches;
- matches.add(a);
- expectAbiRule(abis, variant, matches);
-}
-
-static void expectAbiRule(const Vector<abi::Variant>& abis, abi::Variant variant, const char* a, const char* b) {
- Vector<const char*> matches;
- matches.add(a);
- matches.add(b);
- expectAbiRule(abis, variant, matches);
+ // We expect AlwaysTrue because anydpi always has attached v21 to the configuration
+ // and the rest of the rule generation code generates the sdk version checks.
+ EXPECT_RULES_EQ(RuleGenerator::generateDensity(densities, anyIndex), AlwaysTrue());
}
} // namespace split