Changeset View
Changeset View
Standalone View
Standalone View
tests/simpleiplisttest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2018 Bruce Anderson <banderson19com@san.rr.com> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public License as | ||||
6 | published by the Free Software Foundation; either version 2 of | ||||
7 | the License or (at your option) version 3 or any later version | ||||
8 | accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | defined in Section 14 of version 3 of the license. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "simpleiplistvalidator.h" | ||||
22 | #include <QTest> | ||||
23 | | ||||
24 | class SimpleipListTest : public QObject | ||||
25 | { | ||||
26 | Q_OBJECT | ||||
27 | | ||||
28 | public: | ||||
29 | SimpleipListTest(); | ||||
30 | | ||||
31 | private slots: | ||||
32 | void baseTest(); | ||||
33 | void baseTest_data(); | ||||
34 | void cidrTest(); | ||||
35 | void cidrTest_data(); | ||||
36 | void portTest(); | ||||
37 | void portTest_data(); | ||||
38 | | ||||
39 | private: | ||||
40 | SimpleIpListValidator m_vb; | ||||
41 | SimpleIpListValidator m_vc; | ||||
42 | SimpleIpListValidator m_vp; | ||||
43 | }; | ||||
44 | | ||||
45 | SimpleipListTest::SimpleipListTest() | ||||
46 | : m_vb(nullptr, SimpleIpListValidator::AddressStyle::Base) | ||||
47 | , m_vc(nullptr, SimpleIpListValidator::AddressStyle::WithCidr) | ||||
48 | , m_vp(nullptr, SimpleIpListValidator::AddressStyle::WithPort) | ||||
49 | { | ||||
50 | } | ||||
51 | | ||||
52 | Q_DECLARE_METATYPE(QValidator::State) | ||||
53 | | ||||
54 | void SimpleipListTest::baseTest_data() | ||||
55 | { | ||||
56 | QTest::addColumn<QString>("address"); | ||||
57 | QTest::addColumn<QValidator::State>("result"); | ||||
58 | | ||||
59 | QTest::newRow("") << "" << QValidator::Intermediate; | ||||
60 | QTest::newRow("123.12.2") << "123.12.2" << QValidator::Intermediate; | ||||
61 | QTest::newRow("123.12.2,") << "123.12.2," << QValidator::Invalid; | ||||
62 | QTest::newRow("123.45.22.9") << "123.45.22.9" << QValidator::Acceptable; | ||||
63 | QTest::newRow("123.45.22.9,") << "123.45.22.9," << QValidator::Intermediate; | ||||
64 | QTest::newRow("123.45.22.9, ") << "123.45.22.9, " << QValidator::Intermediate; | ||||
65 | QTest::newRow("123.45.22,") << "123.45.22," << QValidator::Invalid; | ||||
66 | QTest::newRow("123.45.22.9, BBEf:0112") << "123.45.22.9, BBEf:0112" << QValidator::Intermediate; | ||||
67 | QTest::newRow("123.45.22.9, BBEf:0112::1") << "123.45.22.9, BBEf:0112::1" << QValidator::Acceptable; | ||||
68 | QTest::newRow("123.45.22.9, BBEf:0112:,") << "123.45.22.9, BBEf:0112:," << QValidator::Invalid; | ||||
69 | QTest::newRow("123.45.22.9, BBEf:0112::1,") << "123.45.22.9, BBEf:0112::1," << QValidator::Intermediate; | ||||
70 | QTest::newRow("123.45.22.9, BBEf:0112::1/123,") << "123.45.22.9, BBEf:0112::1/123," << QValidator::Invalid; | ||||
71 | QTest::newRow("123.45.22.9, BBEf:0112::1,1.2.3.4") << "123.45.22.9, BBEf:0112::1,1.2.3.4" << QValidator::Acceptable; | ||||
72 | } | ||||
73 | | ||||
74 | void SimpleipListTest::baseTest() | ||||
75 | { | ||||
76 | int pos; | ||||
77 | | ||||
78 | QFETCH(QString, address); | ||||
79 | QFETCH(QValidator::State, result); | ||||
80 | | ||||
81 | QCOMPARE(m_vb.validate(address, pos), result); | ||||
82 | } | ||||
83 | | ||||
84 | void SimpleipListTest::cidrTest_data() | ||||
85 | { | ||||
86 | QTest::addColumn<QString>("address"); | ||||
87 | QTest::addColumn<QValidator::State>("result"); | ||||
88 | | ||||
89 | QTest::newRow("10.77.18.4/32") << "10.77.18.4/32" << QValidator::Acceptable; | ||||
90 | QTest::newRow("10.77.18.4/32,") << "10.77.18.4/32," << QValidator::Intermediate; | ||||
91 | QTest::newRow("10.77.18.4/32,Be00:e00:0:") << "10.77.18.4/32,Be00:e00:0:" << QValidator::Intermediate; | ||||
92 | QTest::newRow("10.77.18.4/32,Be00:e00:0:21/3") << "10.77.18.4/32,Be00:e00:0:21/3" << QValidator::Invalid; | ||||
93 | QTest::newRow("10.77.18.4/32,Be00:e00::0:21/128") << "10.77.18.4/32,Be00:e00::0:21/128" << QValidator::Acceptable; | ||||
94 | QTest::newRow("10.77.18.4/32,Be00:e00::0:21/129") << "10.77.18.4/32,Be00:e00::0:21/129" << QValidator::Invalid; | ||||
95 | } | ||||
96 | | ||||
97 | void SimpleipListTest::cidrTest() | ||||
98 | { | ||||
99 | int pos; | ||||
100 | | ||||
101 | QFETCH(QString, address); | ||||
102 | QFETCH(QValidator::State, result); | ||||
103 | | ||||
104 | QCOMPARE(m_vc.validate(address, pos), result); | ||||
105 | } | ||||
106 | | ||||
107 | void SimpleipListTest::portTest_data() | ||||
108 | { | ||||
109 | QTest::addColumn<QString>("address"); | ||||
110 | QTest::addColumn<QValidator::State>("result"); | ||||
111 | | ||||
112 | QTest::newRow("10.77.18.4:32") << "10.77.18.4:32" << QValidator::Acceptable; | ||||
113 | QTest::newRow("10.77.18.4:,") << "10.77.18.4:," << QValidator::Invalid; | ||||
114 | QTest::newRow("10.77.18.4:234, 1") << "10.77.18.4:234, 1" << QValidator::Intermediate; | ||||
115 | QTest::newRow("10.77.18.4:234, 1b") << "10.77.18.4:234, 1b" << QValidator::Invalid; | ||||
116 | QTest::newRow("10.77.18.4:234, [1b") << "10.77.18.4:234, [1b" << QValidator::Intermediate; | ||||
117 | QTest::newRow("10.77.18.4:234, [10:33:22::1") << "10.77.18.4:234, [10:33:22::1" << QValidator::Intermediate; | ||||
118 | QTest::newRow("10.77.18.4:234, [10:33:22::1]") << "10.77.18.4:234, [10:33:22::1]" << QValidator::Intermediate; | ||||
119 | QTest::newRow("10.77.18.4:234, [10:33:22::1]:") << "10.77.18.4:234, [10:33:22::1]:" << QValidator::Intermediate; | ||||
120 | QTest::newRow("10.77.18.4:234, [10:33:22::1]:22") << "10.77.18.4:234, [10:33:22::1]:22" << QValidator::Acceptable; | ||||
121 | QTest::newRow("10.77.18.4:234, [10:33:22::1]:22,12.23.34.45:65535") << "10.77.18.4:234, [10:33:22::1]:22,12.23.34.45:65535" << QValidator::Acceptable; | ||||
122 | } | ||||
123 | | ||||
124 | void SimpleipListTest::portTest() | ||||
125 | { | ||||
126 | int pos; | ||||
127 | | ||||
128 | QFETCH(QString, address); | ||||
129 | QFETCH(QValidator::State, result); | ||||
130 | | ||||
131 | QCOMPARE(m_vp.validate(address, pos), result); | ||||
132 | } | ||||
133 | | ||||
134 | QTEST_GUILESS_MAIN(SimpleipListTest) | ||||
135 | | ||||
136 | #include "simpleiplisttest.moc" |