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 | #include <QDir> | ||||
24 | | ||||
25 | class SimpleipListTest : public QObject | ||||
26 | { | ||||
27 | Q_OBJECT | ||||
28 | | ||||
29 | private slots: | ||||
30 | void initTestCase(); | ||||
31 | void baseTest(); | ||||
32 | void cidrTest(); | ||||
33 | void portTest(); | ||||
34 | | ||||
35 | private: | ||||
36 | SimpleIpListValidator* vb; | ||||
37 | SimpleIpListValidator* vc; | ||||
38 | SimpleIpListValidator* vp; | ||||
39 | }; | ||||
40 | | ||||
41 | void SimpleipListTest::initTestCase() | ||||
42 | { | ||||
43 | vb = new SimpleIpListValidator(nullptr, SimpleIpListValidator::AddressStyle::Base); | ||||
44 | vc = new SimpleIpListValidator(nullptr, SimpleIpListValidator::AddressStyle::WithCidr); | ||||
45 | vp = new SimpleIpListValidator(nullptr, SimpleIpListValidator::AddressStyle::WithPort); | ||||
46 | } | ||||
47 | | ||||
48 | void SimpleipListTest::baseTest() | ||||
49 | { | ||||
50 | int pos = 0; | ||||
51 | // Null string is intermediate because it's waiting for input | ||||
52 | QString tstr(""); | ||||
53 | QVERIFY(vb->validate(tstr, pos) == QValidator::Intermediate); | ||||
54 | | ||||
55 | tstr = "123.12.2"; | ||||
56 | QVERIFY(vb->validate(tstr, pos) == QValidator::Intermediate); | ||||
57 | | ||||
58 | tstr = "123.12.2,"; | ||||
59 | QVERIFY(vb->validate(tstr, pos) == QValidator::Invalid); | ||||
60 | | ||||
61 | tstr = "123.45.22.9"; | ||||
62 | QVERIFY(vb->validate(tstr, pos) == QValidator::Acceptable); | ||||
63 | | ||||
64 | tstr = "123.45.22.9,"; | ||||
65 | QVERIFY(vb->validate(tstr, pos) == QValidator::Intermediate); | ||||
66 | | ||||
67 | tstr = "123.45.22.9, "; | ||||
68 | QVERIFY(vb->validate(tstr, pos) == QValidator::Intermediate); | ||||
69 | | ||||
70 | tstr = "123.45.22,"; | ||||
71 | QVERIFY(vb->validate(tstr, pos) == QValidator::Invalid); | ||||
72 | | ||||
73 | tstr = "123.45.22.9, BBEf:0112"; | ||||
74 | QVERIFY(vb->validate(tstr, pos) == QValidator::Intermediate); | ||||
75 | | ||||
76 | tstr = "123.45.22.9, BBEf:0112::1"; | ||||
77 | QVERIFY(vb->validate(tstr, pos) == QValidator::Acceptable); | ||||
78 | | ||||
79 | tstr = "123.45.22.9, BBEf:0112:,"; | ||||
80 | QVERIFY(vb->validate(tstr, pos) == QValidator::Invalid); | ||||
81 | | ||||
82 | tstr = "123.45.22.9, BBEf:0112::1,"; | ||||
83 | QVERIFY(vb->validate(tstr, pos) == QValidator::Intermediate); | ||||
84 | | ||||
85 | tstr = "123.45.22.9, BBEf:0112::1/123,"; | ||||
86 | QVERIFY(vb->validate(tstr, pos) == QValidator::Invalid); | ||||
87 | | ||||
88 | tstr = "123.45.22.9, BBEf:0112::1,1.2.3.4"; | ||||
89 | QVERIFY(vb->validate(tstr, pos) == QValidator::Acceptable); | ||||
90 | } | ||||
91 | | ||||
92 | void SimpleipListTest::cidrTest() | ||||
93 | { | ||||
94 | int pos = 0; | ||||
95 | | ||||
96 | QString tstr("10.77.18.4/32"); | ||||
97 | QVERIFY(vc->validate(tstr, pos) == QValidator::Acceptable); | ||||
98 | | ||||
99 | tstr = "10.77.18.4/32,"; | ||||
100 | QVERIFY(vc->validate(tstr, pos) == QValidator::Intermediate); | ||||
101 | | ||||
102 | tstr = "10.77.18.4/32,Be00:e00:0:"; | ||||
103 | QVERIFY(vc->validate(tstr, pos) == QValidator::Intermediate); | ||||
104 | | ||||
105 | tstr = "10.77.18.4/32,Be00:e00:0:21/3"; | ||||
106 | QVERIFY(vc->validate(tstr, pos) == QValidator::Invalid); | ||||
107 | | ||||
108 | tstr = "10.77.18.4/32,Be00:e00::0:21/128"; | ||||
109 | QVERIFY(vc->validate(tstr, pos) == QValidator::Acceptable); | ||||
110 | | ||||
111 | tstr = "10.77.18.4/32,Be00:e00::0:21/129"; | ||||
112 | QVERIFY(vc->validate(tstr, pos) == QValidator::Invalid); | ||||
113 | } | ||||
114 | | ||||
115 | void SimpleipListTest::portTest() | ||||
116 | { | ||||
117 | int pos = 0; | ||||
118 | | ||||
119 | QString tstr("10.77.18.4:32"); | ||||
120 | QVERIFY(vp->validate(tstr, pos) == QValidator::Acceptable); | ||||
121 | | ||||
122 | tstr = "10.77.18.4:,"; | ||||
123 | QVERIFY(vp->validate(tstr, pos) == QValidator::Invalid); | ||||
124 | | ||||
125 | tstr = "10.77.18.4:234, 1"; | ||||
126 | QVERIFY(vp->validate(tstr, pos) == QValidator::Intermediate); | ||||
127 | | ||||
128 | tstr = "10.77.18.4:234, 1b"; | ||||
129 | QVERIFY(vp->validate(tstr, pos) == QValidator::Invalid); | ||||
130 | | ||||
131 | tstr = "10.77.18.4:234, [1b"; | ||||
132 | QVERIFY(vp->validate(tstr, pos) == QValidator::Intermediate); | ||||
133 | | ||||
134 | tstr = "10.77.18.4:234, [10:33:22::1"; | ||||
135 | QVERIFY(vp->validate(tstr, pos) == QValidator::Intermediate); | ||||
136 | | ||||
137 | tstr = "10.77.18.4:234, [10:33:22::1]"; | ||||
138 | QVERIFY(vp->validate(tstr, pos) == QValidator::Intermediate); | ||||
139 | | ||||
140 | tstr = "10.77.18.4:234, [10:33:22::1]:"; | ||||
141 | QVERIFY(vp->validate(tstr, pos) == QValidator::Intermediate); | ||||
142 | | ||||
143 | tstr = "10.77.18.4:234, [10:33:22::1]:22"; | ||||
144 | QVERIFY(vp->validate(tstr, pos) == QValidator::Acceptable); | ||||
145 | | ||||
146 | tstr = "10.77.18.4:234, [10:33:22::1]:22,12.23.34.45:65535"; | ||||
147 | QVERIFY(vp->validate(tstr, pos) == QValidator::Acceptable); | ||||
148 | } | ||||
149 | | ||||
150 | QTEST_GUILESS_MAIN(SimpleipListTest) | ||||
151 | | ||||
152 | #include "simpleiplisttest.moc" |