2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "SplitDescription.h"
20 #include "TestRules.h"
23 #include <gtest/gtest.h>
25 #include <utils/String8.h>
27 using namespace android;
28 using namespace split::test;
32 TEST(RuleTest, generatesValidJson) {
34 .add(EqRule(Rule::SDK_VERSION, 7))
36 .add(GtRule(Rule::SCREEN_DENSITY, 10))
37 .add(LtRule(Rule::SCREEN_DENSITY, 5))
44 " \"op\": \"AND_SUBRULES\","
47 " \"op\": \"EQUALS\","
48 " \"property\": \"SDK_VERSION\","
52 " \"op\": \"OR_SUBRULES\","
55 " \"op\": \"GREATER_THAN\","
56 " \"property\": \"SCREEN_DENSITY\","
60 " \"op\": \"LESS_THAN\","
61 " \"property\": \"SCREEN_DENSITY\","
68 expected.erase(std::remove_if(expected.begin(), expected.end(), ::isspace), expected.end());
71 std::string result(rule.toJson().string());
72 result.erase(std::remove_if(result.begin(), result.end(), ::isspace), result.end());
74 ASSERT_EQ(expected, result);
77 TEST(RuleTest, simplifiesSingleSubruleRules) {
78 sp<Rule> rule = new Rule(AndRule()
79 .add(EqRule(Rule::SDK_VERSION, 7))
82 EXPECT_RULES_EQ(Rule::simplify(rule), EqRule(Rule::SDK_VERSION, 7));
85 TEST(RuleTest, simplifiesNestedSameOpSubrules) {
86 sp<Rule> rule = new Rule(AndRule()
88 .add(EqRule(Rule::SDK_VERSION, 7))
90 .add(EqRule(Rule::SDK_VERSION, 8))
93 EXPECT_RULES_EQ(Rule::simplify(rule),
95 .add(EqRule(Rule::SDK_VERSION, 7))
96 .add(EqRule(Rule::SDK_VERSION, 8))