summaryrefslogtreecommitdiffstats
path: root/svx/qa/unit/removewhichrange.cxx
blob: d5856f6c70e90975c4d92328170261fe4b671cfb (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <sal/config.h>

#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>

#include <sal/types.h>
#include <svx/svdetc.hxx>

namespace
{
class TestRemoveWhichRange : public CppUnit::TestFixture
{
    CPPUNIT_TEST_SUITE(TestRemoveWhichRange);
    CPPUNIT_TEST(testRemoveWhichRange);
    CPPUNIT_TEST_SUITE_END();

    void testRemoveWhichRange()
    {
        {
            WhichRangesContainer in;
            auto const out = RemoveWhichRange(in, 10, 20);
            CPPUNIT_ASSERT(out.empty());
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 0, 20);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[0].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 10, 20);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[0].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 15, 20);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(14), out[0].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[1].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 30, 40);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 30, 50);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 30, 35);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(36), out[1].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 15, 35);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(14), out[0].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(36), out[1].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 12, 15);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(11), out[0].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(16), out[1].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[1].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), out[2].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[2].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 30, 40>);
            auto const out = RemoveWhichRange(in, 0, 100);
            CPPUNIT_ASSERT(out.empty());
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 40, 50>);
            auto const out = RemoveWhichRange(in, 25, 35);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(50), out[1].second);
        }
        {
            WhichRangesContainer in(svl::Items<10, 20, 40, 50>);
            auto const out = RemoveWhichRange(in, 50, 100);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(10), out[0].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), out[0].second);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(40), out[1].first);
            CPPUNIT_ASSERT_EQUAL(sal_uInt16(49), out[1].second);
        }
    }
};

CPPUNIT_TEST_SUITE_REGISTRATION(TestRemoveWhichRange);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */