• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "TestRules.h"
18 
19 #include <utils/String8.h>
20 
21 using android::String8;
22 using android::sp;
23 
24 namespace split {
25 namespace test {
26 
EqRule(Rule::Key key,long value)27 const Rule EqRule(Rule::Key key, long value) {
28     Rule rule;
29     rule.op = Rule::EQUALS;
30     rule.key = key;
31     rule.longArgs.add(value);
32     return rule;
33 }
34 
GtRule(Rule::Key key,long value)35 const Rule GtRule(Rule::Key key, long value) {
36     Rule rule;
37     rule.op = Rule::GREATER_THAN;
38     rule.key = key;
39     rule.longArgs.add(value);
40     return rule;
41 }
42 
LtRule(Rule::Key key,long value)43 const Rule LtRule(Rule::Key key, long value) {
44     Rule rule;
45     rule.op = Rule::LESS_THAN;
46     rule.key = key;
47     rule.longArgs.add(value);
48     return rule;
49 }
50 
ContainsAnyRule(Rule::Key key,const char * str1)51 const Rule ContainsAnyRule(Rule::Key key, const char* str1) {
52     Rule rule;
53     rule.op = Rule::CONTAINS_ANY;
54     rule.key = key;
55     rule.stringArgs.add(String8(str1));
56     return rule;
57 }
58 
ContainsAnyRule(Rule::Key key,const char * str1,const char * str2)59 const Rule ContainsAnyRule(Rule::Key key, const char* str1, const char* str2) {
60     Rule rule;
61     rule.op = Rule::CONTAINS_ANY;
62     rule.key = key;
63     rule.stringArgs.add(String8(str1));
64     rule.stringArgs.add(String8(str2));
65     return rule;
66 }
67 
AlwaysTrue()68 const Rule AlwaysTrue() {
69     Rule rule;
70     rule.op = Rule::ALWAYS_TRUE;
71     return rule;
72 }
73 
RulePredFormat(const char *,const char *,const sp<Rule> & actual,const Rule & expected)74 ::testing::AssertionResult RulePredFormat(
75         const char*, const char*,
76         const sp<Rule>& actual, const Rule& expected) {
77     const String8 expectedStr(expected.toJson());
78     const String8 actualStr(actual != NULL ? actual->toJson() : String8());
79 
80     if (expectedStr != actualStr) {
81         return ::testing::AssertionFailure() << "Expected: " << expectedStr.c_str() << "\n"
82                                              << "  Actual: " << actualStr.c_str();
83     }
84     return ::testing::AssertionSuccess();
85 }
86 
87 
88 } // namespace test
89 } // namespace split
90