1 /* Copyright (C) 2011 Jan Kundrát <kundratj@fzu.cz>
3 * This file is part of the Deska, a tool for central administration of a grid site
4 * http://projects.flaska.net/projects/show/deska
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or the version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include <boost/foreach.hpp>
23 #define BOOST_TEST_MODULE api_filters
24 #include <boost/test/unit_test.hpp>
25 #include "deska/db/Filter.h"
26 #include "deska/db/AdditionalValueStreamOperators.h"
29 using namespace Deska::Db
;
32 void verifyFilterObject(const std::string
&str
, const T
&value
)
34 std::ostringstream ss
;
36 BOOST_CHECK_EQUAL(str
, ss
.str());
41 BOOST_CHECK_EQUAL(str
, ss
.str());
42 BOOST_CHECK_EQUAL(Filter(value
), Filter(value
));
45 /** @short Test stream dumping of the filters */
46 BOOST_AUTO_TEST_CASE(filter_dumping
)
48 // We don't put these items into a liast because we really want to test without casting to a wrapping filter
49 MetadataExpression
e1(FILTER_COLUMN_EQ
, "revision", RevisionId(123));
50 string s1
= "MetadataExpression(revision == MetadataValue<RevisionId>(r123))";
51 MetadataExpression
e2(FILTER_COLUMN_NE
, "changeset", TemporaryChangesetId(666));
52 string s2
= "MetadataExpression(changeset != MetadataValue<TemporaryChangesetId>(tmp666))";
53 MetadataExpression
e3(FILTER_COLUMN_LT
, "state", PendingChangeset::ATTACH_DETACHED
);
54 string s3
= "MetadataExpression(state < MetadataValue<PendingChangeset::AttachStatus>(DETACHED))";
55 MetadataExpression
e4(FILTER_COLUMN_LE
, "author", Value(std::string("foo")));
56 string s4
= "MetadataExpression(author <= MetadataValue<Value>(Value<string>(foo)))";
57 AttributeExpression
e5(FILTER_COLUMN_GT
, "kind", "attr", Value(123));
58 string s5
= "AttributeExpression(kind.attr > Value<int>(123))";
63 string s6
= "AndFilter([" + s1
+ ", " + s2
+ ", ])";
68 string s7
= "OrFilter([" + s3
+ ", " + s4
+ ", ])";
74 string s8
= "AndFilter([" + s5
+ ", " + s6
+ ", " + s7
+ ", ])";
75 AttributeExpression
e9(FILTER_COLUMN_CONTAINS
, "kind", "attr", Value(std::string("key")));
76 string s9
= "AttributeExpression(kind.attr contains Value<string>(key))";
77 std::set
<Identifier
> roles
;
80 AttributeExpression
e10(FILTER_COLUMN_NOT_CONTAINS
, "host", "role", Value(roles
));
81 string s10
= "AttributeExpression(host.role not contains Value<identifier_set>([bar, foo]))";
82 SpecialExpression
e11(FILTER_SPECIAL_EMBEDDED_LAST_ONE
, "interface");
83 string s11
= "SpecialExpression(interface embeddedLastOne)";
85 verifyFilterObject(s1
, e1
);
86 verifyFilterObject(s2
, e2
);
87 verifyFilterObject(s3
, e3
);
88 verifyFilterObject(s4
, e4
);
89 verifyFilterObject(s5
, e5
);
90 verifyFilterObject(s6
, e6
);
91 verifyFilterObject(s7
, e7
);
92 verifyFilterObject(s8
, e8
);
93 verifyFilterObject(s9
, e9
);
94 verifyFilterObject(s10
, e10
);
95 verifyFilterObject(s11
, e11
);