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.
17 #include "TestRules.h"
19 #include <utils/String8.h>
21 using android::String8;
27 const Rule EqRule(Rule::Key key, long value) {
29 rule.op = Rule::EQUALS;
31 rule.longArgs.add(value);
35 const Rule GtRule(Rule::Key key, long value) {
37 rule.op = Rule::GREATER_THAN;
39 rule.longArgs.add(value);
43 const Rule LtRule(Rule::Key key, long value) {
45 rule.op = Rule::LESS_THAN;
47 rule.longArgs.add(value);
51 const Rule ContainsAnyRule(Rule::Key key, const char* str1) {
53 rule.op = Rule::CONTAINS_ANY;
55 rule.stringArgs.add(String8(str1));
59 const Rule ContainsAnyRule(Rule::Key key, const char* str1, const char* str2) {
61 rule.op = Rule::CONTAINS_ANY;
63 rule.stringArgs.add(String8(str1));
64 rule.stringArgs.add(String8(str2));
68 const Rule AlwaysTrue() {
70 rule.op = Rule::ALWAYS_TRUE;
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());
80 if (expectedStr != actualStr) {
81 return ::testing::AssertionFailure()
82 << "Expected: " << expectedStr.string() << "\n"
83 << " Actual: " << actualStr.string();
85 return ::testing::AssertionSuccess();