blob: 86ccd6a25c1834f40c80ff4056e313777904350f [file] [log] [blame]
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -08001/*
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
21using android::String8;
22using android::sp;
23
24namespace split {
25namespace test {
26
27const 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
35const 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
43const 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
51const 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
59const 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
68const Rule AlwaysTrue() {
69 Rule rule;
70 rule.op = Rule::ALWAYS_TRUE;
71 return rule;
72}
73
74::testing::AssertionResult RulePredFormat(
75 const char*, const char*,
76 const sp<Rule>& actual, const Rule& expected) {
77 const String8 expectedStr(expected.toJson());
Adam Lesinskic3344e8a2014-11-10 17:32:27 -080078 const String8 actualStr(actual != NULL ? actual->toJson() : String8());
Adam Lesinskidcdfe9f2014-11-06 12:54:36 -080079
80 if (expectedStr != actualStr) {
81 return ::testing::AssertionFailure()
82 << "Expected: " << expectedStr.string() << "\n"
83 << " Actual: " << actualStr.string();
84 }
85 return ::testing::AssertionSuccess();
86}
87
88
89} // namespace test
90} // namespace split