summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests/Selector.cpp
blob: 73af1a9623d8f7330afd8dc6c1cc53a3c6c81d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

#include "qpid/broker/SelectorToken.h"
#include "qpid/broker/Selector.h"
#include "qpid/broker/SelectorValue.h"

#include "unit_test.h"

#include <string>
#include <map>
#include <boost/ptr_container/ptr_vector.hpp>

using std::string;
using std::map;
using std::vector;

namespace qb = qpid::broker;

using qpid::broker::Token;
using qpid::broker::TokenType;
using qpid::broker::Tokeniser;
using qpid::broker::tokenise;

namespace qpid {
namespace tests {

QPID_AUTO_TEST_SUITE(SelectorSuite)

typedef bool (*TokeniseF)(string::const_iterator&,string::const_iterator&,Token&);

bool tokeniseEos(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    Token t1;
    std::string::const_iterator t = s;
    bool r = tokenise(t, e, t1);
    if (r && (t1.type==qb::T_EOS)) {tok = t1; s = t; return true;}
    return false;
}

bool tokeniseParens(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    Token t1;
    std::string::const_iterator t = s;
    bool r = tokenise(t, e, t1);
    if (r && (t1.type==qb::T_LPAREN || t1.type==qb::T_RPAREN)) {tok = t1; s = t; return true;}
    return false;
}

bool tokeniseOperator(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    Token t1;
    std::string::const_iterator t = s;
    bool r = tokenise(t, e, t1);
    if (r && (t1.type>=qb::T_PLUS && t1.type<=qb::T_GREQ)) {tok = t1; s = t; return true;}
    return false;
}

bool tokeniseString(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    Token t1;
    std::string::const_iterator t = s;
    bool r = tokenise(t, e, t1);
    if (r && (t1.type==qb::T_STRING)) {tok = t1; s = t; return true;}
    return false;
}

bool tokeniseIdentifier(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    Token t1;
    std::string::const_iterator t = s;
    bool r = tokenise(t, e, t1);
    if (r && (t1.type==qb::T_IDENTIFIER)) {tok = t1; s = t; return true;}
    return false;
}

bool tokeniseReservedWord(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    std::string::const_iterator t = s;
    Token t1;
    if (tokenise(t, e, t1)) {
    switch (t1.type) {
    case qb::T_AND:
    case qb::T_BETWEEN:
    case qb::T_ESCAPE:
    case qb::T_FALSE:
    case qb::T_IN:
    case qb::T_IS:
    case qb::T_LIKE:
    case qb::T_NOT:
    case qb::T_NULL:
    case qb::T_OR:
    case qb::T_TRUE:
        tok = t1;
        s = t;
        return true;
    default:
        break;
    }
    }
    return false;
}

bool tokeniseNumeric(std::string::const_iterator& s, std::string::const_iterator& e, Token& tok)
{
    Token t1;
    std::string::const_iterator t = s;
    bool r = tokenise(t, e, t1);
    if (r && (t1.type==qb::T_NUMERIC_EXACT || t1.type==qb::T_NUMERIC_APPROX)) {tok = t1; s = t; return true;}
    return false;
}


void verifyTokeniserSuccess(TokeniseF t, const char* ss, TokenType tt, const char* tv, const char* fs) {
    Token tok;
    string s(ss);
    string::const_iterator sb = s.begin();
    string::const_iterator se = s.end();
    BOOST_CHECK(t(sb, se, tok));
    BOOST_CHECK_EQUAL(tok, Token(tt, tv));
    BOOST_CHECK_EQUAL(string(sb, se), fs);
}

void verifyTokeniserFail(TokeniseF t, const char* c) {
    Token tok;
    string s(c);
    string::const_iterator sb = s.begin();
    string::const_iterator se = s.end();
    BOOST_CHECK(!t(sb, se, tok));
    BOOST_CHECK_EQUAL(string(sb, se), c);
}

QPID_AUTO_TEST_CASE(tokeniseSuccess)
{
    verifyTokeniserSuccess(&tokenise, "", qb::T_EOS, "", "");
    verifyTokeniserSuccess(&tokenise, " ", qb::T_EOS, "", "");
    verifyTokeniserSuccess(&tokenise, "null_123+blah", qb::T_IDENTIFIER, "null_123", "+blah");
    verifyTokeniserSuccess(&tokenise, "\"null-123\"+blah", qb::T_IDENTIFIER, "null-123", "+blah");
    verifyTokeniserSuccess(&tokenise, "\"This is an \"\"odd!\"\" identifier\"+blah", qb::T_IDENTIFIER, "This is an \"odd!\" identifier", "+blah");
    verifyTokeniserSuccess(&tokenise, "null+blah", qb::T_NULL, "null", "+blah");
    verifyTokeniserSuccess(&tokenise, "null+blah", qb::T_NULL, "null", "+blah");
    verifyTokeniserSuccess(&tokenise, "Is nOt null", qb::T_IS, "Is", " nOt null");
    verifyTokeniserSuccess(&tokenise, "nOt null", qb::T_NOT, "nOt", " null");
    verifyTokeniserSuccess(&tokenise, "Is nOt null", qb::T_IS, "Is", " nOt null");
    verifyTokeniserSuccess(&tokenise, "'Hello World'", qb::T_STRING, "Hello World", "");
    verifyTokeniserSuccess(&tokenise, "'Hello World''s end'a bit more", qb::T_STRING, "Hello World's end", "a bit more");
    verifyTokeniserSuccess(&tokenise, "=blah", qb::T_EQUAL, "=", "blah");
    verifyTokeniserSuccess(&tokenise, "<> Identifier", qb::T_NEQ, "<>", " Identifier");
    verifyTokeniserSuccess(&tokenise, "(a and b) not c", qb::T_LPAREN, "(", "a and b) not c");
    verifyTokeniserSuccess(&tokenise, ") not c", qb::T_RPAREN, ")", " not c");
    verifyTokeniserSuccess(&tokenise, "019kill", qb::T_NUMERIC_EXACT, "019", "kill");
    verifyTokeniserSuccess(&tokenise, "0kill", qb::T_NUMERIC_EXACT, "0", "kill");
    verifyTokeniserSuccess(&tokenise, "0.kill", qb::T_NUMERIC_APPROX, "0.", "kill");
    verifyTokeniserSuccess(&tokenise, "3.1415=pi", qb::T_NUMERIC_APPROX, "3.1415", "=pi");
    verifyTokeniserSuccess(&tokenise, ".25.kill", qb::T_NUMERIC_APPROX, ".25", ".kill");
    verifyTokeniserSuccess(&tokenise, "2e5.kill", qb::T_NUMERIC_APPROX, "2e5", ".kill");
    verifyTokeniserSuccess(&tokenise, "3.e50easy to kill", qb::T_NUMERIC_APPROX, "3.e50", "easy to kill");
    verifyTokeniserSuccess(&tokenise, "34.25e+50easy to kill", qb::T_NUMERIC_APPROX, "34.25e+50", "easy to kill");
    verifyTokeniserSuccess(&tokenise, "34.e-50easy to kill", qb::T_NUMERIC_APPROX, "34.e-50", "easy to kill");
}

QPID_AUTO_TEST_CASE(tokeniseFailure)
{
    verifyTokeniserFail(&tokeniseEos, "hb23");
    verifyTokeniserFail(&tokeniseIdentifier, "123");
    verifyTokeniserFail(&tokeniseIdentifier, "'Embedded 123'");
    verifyTokeniserFail(&tokeniseReservedWord, "1.2e5");
    verifyTokeniserFail(&tokeniseReservedWord, "'Stringy thing'");
    verifyTokeniserFail(&tokeniseReservedWord, "oR_andsomething");
    verifyTokeniserFail(&tokeniseString, "'Embedded 123");
    verifyTokeniserFail(&tokeniseString, "'This isn''t fair");
    verifyTokeniserFail(&tokeniseOperator, "123");
    verifyTokeniserFail(&tokeniseOperator, "'Stringy thing'");
    verifyTokeniserFail(&tokeniseOperator, "NoT");
    verifyTokeniserFail(&tokeniseOperator, "(a and b)");
    verifyTokeniserFail(&tokeniseOperator, ")");
    verifyTokeniserFail(&tokeniseParens, "=");
    verifyTokeniserFail(&tokeniseParens, "what ho!");
    verifyTokeniserFail(&tokeniseNumeric, "kill");
    verifyTokeniserFail(&tokeniseNumeric, "e3");
    verifyTokeniserFail(&tokeniseNumeric, "1.e.5");
    verifyTokeniserFail(&tokeniseNumeric, ".e5");
    verifyTokeniserFail(&tokeniseNumeric, "34e");
    verifyTokeniserFail(&tokeniseNumeric, ".3e+");
    verifyTokeniserFail(&tokeniseNumeric, ".3e-.");
}

QPID_AUTO_TEST_CASE(tokenString)
{

    string exp("  a =b");
    string::const_iterator s = exp.begin();
    string::const_iterator e = exp.end();
    Tokeniser t(s, e);

    BOOST_CHECK_EQUAL(t.nextToken(), Token(qb::T_IDENTIFIER, "a"));
    BOOST_CHECK_EQUAL(t.nextToken(), Token(qb::T_EQUAL, "="));
    BOOST_CHECK_EQUAL(t.nextToken(), Token(qb::T_IDENTIFIER, "b"));
    BOOST_CHECK_EQUAL(t.nextToken(), Token(qb::T_EOS, ""));

    exp = " not 'hello kitty''s friend' = Is null       ";
    s = exp.begin();
    e = exp.end();
    Tokeniser u(s, e);

    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_NOT, "not"));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_STRING, "hello kitty's friend"));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_EQUAL, "="));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_IS, "Is"));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_NULL, "null"));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_EOS, ""));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_EOS, ""));

    u.returnTokens(3);
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_IS, "Is"));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_NULL, "null"));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_EOS, ""));
    BOOST_CHECK_EQUAL(u.nextToken(), Token(qb::T_EOS, ""));

    exp = "(a+6)*7.5/1e6";
    s = exp.begin();
    e = exp.end();
    Tokeniser v(s, e);

    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_LPAREN, "("));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_IDENTIFIER, "a"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_PLUS, "+"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_NUMERIC_EXACT, "6"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_RPAREN, ")"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_MULT, "*"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_NUMERIC_APPROX, "7.5"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_DIV, "/"));
    BOOST_CHECK_EQUAL(v.nextToken(), Token(qb::T_NUMERIC_APPROX, "1e6"));
}

QPID_AUTO_TEST_CASE(parseStringFail)
{
    BOOST_CHECK_THROW(qb::Selector e("hello world"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("hello ^ world"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A is null not"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A is null or not"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A is null or and"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A is null and (B='hello out there'"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("in='hello kitty'"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A like 234"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A not 234 escape"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A not like 'eclecti_' escape 'happy'"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A not like 'eclecti_' escape happy"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A not like 'eclecti_' escape '%'"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A BETWEEN AND 'true'"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A NOT BETWEEN 34 OR 3.9"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A IN ()"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A NOT IN ()"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A IN 'hello', 'there', 1, true, (1-17))"), std::range_error);
    BOOST_CHECK_THROW(qb::Selector e("A IN ('hello', 'there' 1, true, (1-17))"), std::range_error);
}

QPID_AUTO_TEST_CASE(parseString)
{
    BOOST_CHECK_NO_THROW(qb::Selector e("'Daft' is not null"));
    BOOST_CHECK_NO_THROW(qb::Selector e("42 is null"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A is not null"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A is null"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A = C"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A <> C"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A='hello kitty'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A<>'hello kitty'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A=B"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A<>B"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A='hello kitty' OR B='Bye, bye cruel world'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("B='hello kitty' AnD A='Bye, bye cruel world'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A is null or A='Bye, bye cruel world'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("Z is null OR A is not null and A<>'Bye, bye cruel world'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("(Z is null OR A is not null) and A<>'Bye, bye cruel world'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("NOT C is not null OR C is null"));
    BOOST_CHECK_NO_THROW(qb::Selector e("Not A='' or B=z"));
    BOOST_CHECK_NO_THROW(qb::Selector e("Not A=17 or B=5.6"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A<>17 and B=5.6e17"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A LIKE 'excep%ional'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("B NOT LIKE 'excep%ional'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A LIKE 'excep%ional' EScape '\'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A BETWEEN 13 AND 'true'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A NOT BETWEEN 100 AND 3.9"));
    BOOST_CHECK_NO_THROW(qb::Selector e("true"));
    BOOST_CHECK_NO_THROW(qb::Selector e("-354"));
    BOOST_CHECK_NO_THROW(qb::Selector e("-(X or Y)"));
    BOOST_CHECK_NO_THROW(qb::Selector e("-687 or 567"));
    BOOST_CHECK_NO_THROW(qb::Selector e("(354.6)"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A is null and 'hello out there'"));
    BOOST_CHECK_NO_THROW(qb::Selector e("17/4>4"));
    BOOST_CHECK_NO_THROW(qb::Selector e("17/4>+4"));
    BOOST_CHECK_NO_THROW(qb::Selector e("17/4>-4"));
    BOOST_CHECK_NO_THROW(qb::Selector e("A IN ('hello', 'there', 1 , true, (1-17))"));
}

class TestSelectorEnv : public qpid::broker::SelectorEnv {
    mutable map<string, qb::Value> values;
    boost::ptr_vector<string> strings;
    static const qb::Value EMPTY;

    const qb::Value& value(const string& v) const {
        const qb::Value& r = values.find(v)!=values.end() ? values[v] : EMPTY;
        return r;
    }

public:
    void set(const string& id, const char* value) {
        strings.push_back(new string(value));
        values[id] = strings[strings.size()-1];
    }

    void set(const string& id, const qb::Value& value) {
        if (value.type==qb::Value::T_STRING) {
            strings.push_back(new string(*value.s));
            values[id] = strings[strings.size()-1];
        } else {
            values[id] = value;
        }
    }
};

const qb::Value TestSelectorEnv::EMPTY;

QPID_AUTO_TEST_CASE(simpleEval)
{
    TestSelectorEnv env;
    env.set("A", "Bye, bye cruel world");
    env.set("B", "hello kitty");

    BOOST_CHECK(qb::Selector("").eval(env));
    BOOST_CHECK(qb::Selector(" ").eval(env));
    BOOST_CHECK(qb::Selector("A is not null").eval(env));
    BOOST_CHECK(!qb::Selector("A is null").eval(env));
    BOOST_CHECK(!qb::Selector("A = C").eval(env));
    BOOST_CHECK(!qb::Selector("A <> C").eval(env));
    BOOST_CHECK(!qb::Selector("C is not null").eval(env));
    BOOST_CHECK(qb::Selector("C is null").eval(env));
    BOOST_CHECK(qb::Selector("A='Bye, bye cruel world'").eval(env));
    BOOST_CHECK(!qb::Selector("A<>'Bye, bye cruel world'").eval(env));
    BOOST_CHECK(!qb::Selector("A='hello kitty'").eval(env));
    BOOST_CHECK(qb::Selector("A<>'hello kitty'").eval(env));
    BOOST_CHECK(!qb::Selector("A=B").eval(env));
    BOOST_CHECK(qb::Selector("A<>B").eval(env));
    BOOST_CHECK(!qb::Selector("A='hello kitty' OR B='Bye, bye cruel world'").eval(env));
    BOOST_CHECK(qb::Selector("B='hello kitty' OR A='Bye, bye cruel world'").eval(env));
    BOOST_CHECK(qb::Selector("B='hello kitty' AnD A='Bye, bye cruel world'").eval(env));
    BOOST_CHECK(!qb::Selector("B='hello kitty' AnD B='Bye, bye cruel world'").eval(env));
    BOOST_CHECK(qb::Selector("A is null or A='Bye, bye cruel world'").eval(env));
    BOOST_CHECK(qb::Selector("Z is null OR A is not null and A<>'Bye, bye cruel world'").eval(env));
    BOOST_CHECK(!qb::Selector("(Z is null OR A is not null) and A<>'Bye, bye cruel world'").eval(env));
    BOOST_CHECK(qb::Selector("NOT C is not null OR C is null").eval(env));
    BOOST_CHECK(qb::Selector("Not A='' or B=z").eval(env));
    BOOST_CHECK(qb::Selector("Not A=17 or B=5.6").eval(env));
    BOOST_CHECK(!qb::Selector("A<>17 and B=5.6e17").eval(env));
    BOOST_CHECK(!qb::Selector("C=D").eval(env));
    BOOST_CHECK(qb::Selector("13 is not null").eval(env));
    BOOST_CHECK(!qb::Selector("'boo!' is null").eval(env));
    BOOST_CHECK(qb::Selector("A LIKE '%cru_l%'").eval(env));
    BOOST_CHECK(qb::Selector("'_%%_hello.th_re%' LIKE 'z_%.%z_%z%' escape 'z'").eval(env));
    BOOST_CHECK(qb::Selector("A NOT LIKE 'z_%.%z_%z%' escape 'z'").eval(env));
    BOOST_CHECK(qb::Selector("'{}[]<>,.!\"$%^&*()_-+=?/|\\' LIKE '{}[]<>,.!\"$z%^&*()z_-+=?/|\\' escape 'z'").eval(env));
}

QPID_AUTO_TEST_CASE(numericEval)
{
    TestSelectorEnv env;
    env.set("A", 42.0);
    env.set("B", 39);

    BOOST_CHECK(qb::Selector("A>B").eval(env));
    BOOST_CHECK(qb::Selector("A=42").eval(env));
    BOOST_CHECK(qb::Selector("B=39.0").eval(env));
    BOOST_CHECK(qb::Selector("Not A=17 or B=5.6").eval(env));
    BOOST_CHECK(!qb::Selector("A<>17 and B=5.6e17").eval(env));
    BOOST_CHECK(qb::Selector("3 BETWEEN -17 and 98.5").eval(env));
    BOOST_CHECK(qb::Selector("A BETWEEN B and 98.5").eval(env));
    BOOST_CHECK(!qb::Selector("B NOT BETWEEN 35 AND 100").eval(env));
    BOOST_CHECK(!qb::Selector("A BETWEEN B and 40").eval(env));
    BOOST_CHECK(!qb::Selector("A BETWEEN C and 40").eval(env));
    BOOST_CHECK(!qb::Selector("A BETWEEN 45 and C").eval(env));
    BOOST_CHECK(qb::Selector("(A BETWEEN 40 and C) IS NULL").eval(env));
    BOOST_CHECK(qb::Selector("(A BETWEEN C and 45) IS NULL").eval(env));
    BOOST_CHECK(qb::Selector("17/4=4").eval(env));
    BOOST_CHECK(!qb::Selector("A/0=0").eval(env));
    BOOST_CHECK(qb::Selector("A*B+19<A*(B+19)").eval(env));
    BOOST_CHECK(qb::Selector("-A=0-A").eval(env));
}

QPID_AUTO_TEST_CASE(comparisonEval)
{
    TestSelectorEnv env;

    BOOST_CHECK(!qb::Selector("17 > 19.0").eval(env));
    BOOST_CHECK(!qb::Selector("'hello' > 19.0").eval(env));
    BOOST_CHECK(!qb::Selector("'hello' < 19.0").eval(env));
    BOOST_CHECK(!qb::Selector("'hello' = 19.0").eval(env));
    BOOST_CHECK(!qb::Selector("'hello'>42 and 'hello'<42 and 'hello'=42 and 'hello'<>42").eval(env));
    BOOST_CHECK(qb::Selector("20 >= 19.0 and 20 > 19").eval(env));
    BOOST_CHECK(qb::Selector("42 <= 42.0 and 37.0 >= 37").eval(env));
    BOOST_CHECK(qb::Selector("(A IN ('hello', 'there', 1 , true, (1-17))) IS NULL").eval(env));
    BOOST_CHECK(qb::Selector("'hello' IN ('hello', 'there', 1 , true, (1-17))").eval(env));
    BOOST_CHECK(qb::Selector("TRUE IN ('hello', 'there', 1 , true, (1-17))").eval(env));
    BOOST_CHECK(qb::Selector("-16 IN ('hello', 'there', 1 , true, (1-17))").eval(env));
    BOOST_CHECK(!qb::Selector("'hell' IN ('hello', 'there', 1 , true, (1-17))").eval(env));
    BOOST_CHECK(qb::Selector("('hell' IN ('hello', 'there', 1 , true, (1-17), A)) IS NULL").eval(env));
}

QPID_AUTO_TEST_CASE(NullEval)
{
    TestSelectorEnv env;

    BOOST_CHECK(qb::Selector("P > 19.0 or (P is null)").eval(env));
    BOOST_CHECK(qb::Selector("P is null or P=''").eval(env));
    BOOST_CHECK(!qb::Selector("P=Q").eval(env));
    BOOST_CHECK(!qb::Selector("not P=Q").eval(env));
    BOOST_CHECK(!qb::Selector("not P=Q and not P=Q").eval(env));
    BOOST_CHECK(!qb::Selector("P=Q or not P=Q").eval(env));
    BOOST_CHECK(!qb::Selector("P > 19.0 or P <= 19.0").eval(env));
    BOOST_CHECK(qb::Selector("P > 19.0 or 17 <= 19.0").eval(env));
}

QPID_AUTO_TEST_SUITE_END()

}}