summaryrefslogtreecommitdiff
path: root/cpp/src/tests/QueueDepth.cpp
blob: 09b221b3a8bd6a3dca319802c4866b1bb1af7fb3 (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
/*
 *
 * Copyright (c) 2006 The Apache Software Foundation
 *
 * Licensed 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/QueueDepth.h"

#include "unit_test.h"

namespace qpid {
namespace tests {

QPID_AUTO_TEST_SUITE(QueueDepthTestSuite)

using namespace qpid::broker;

QPID_AUTO_TEST_CASE(testCompare)
{
    QueueDepth a(0, 0);
    QueueDepth b(1, 1);
    QueueDepth c(2, 2);
    QueueDepth d(1, 1);

    BOOST_CHECK(a < b);
    BOOST_CHECK(b < c);
    BOOST_CHECK(a < c);

    BOOST_CHECK(b > a);
    BOOST_CHECK(c > b);
    BOOST_CHECK(c > a);

    BOOST_CHECK(b == d);
    BOOST_CHECK(d == b);
    BOOST_CHECK(a != b);
    BOOST_CHECK(b != a);

    QueueDepth e; e.setCount(1);
    QueueDepth f; f.setCount(2);
    BOOST_CHECK(e < f);
    BOOST_CHECK(f > e);

    QueueDepth g; g.setSize(1);
    QueueDepth h; h.setSize(2);
    BOOST_CHECK(g < h);
    BOOST_CHECK(h > g);
}

QPID_AUTO_TEST_CASE(testIncrement)
{
    QueueDepth a(5, 10);
    QueueDepth b(3, 6);
    QueueDepth c(8, 16);
    a += b;
    BOOST_CHECK(a == c);
    BOOST_CHECK_EQUAL(8u, a.getCount());
    BOOST_CHECK_EQUAL(16u, a.getSize());
}

QPID_AUTO_TEST_CASE(testDecrement)
{
    QueueDepth a(5, 10);
    QueueDepth b(3, 6);
    QueueDepth c(2, 4);
    a -= b;
    BOOST_CHECK(a == c);
    BOOST_CHECK_EQUAL(2u, a.getCount());
    BOOST_CHECK_EQUAL(4u, a.getSize());
}

QPID_AUTO_TEST_CASE(testAddition)
{
    QueueDepth a(5, 10);
    QueueDepth b(3, 6);

    QueueDepth c = a + b;
    BOOST_CHECK_EQUAL(8u, c.getCount());
    BOOST_CHECK_EQUAL(16u, c.getSize());
}

QPID_AUTO_TEST_CASE(testSubtraction)
{
    QueueDepth a(5, 10);
    QueueDepth b(3, 6);

    QueueDepth c = a - b;
    BOOST_CHECK_EQUAL(2u, c.getCount());
    BOOST_CHECK_EQUAL(4u, c.getSize());
}

QPID_AUTO_TEST_SUITE_END()

}} // namespace qpid::tests