Skip to content

Commit 989c2ad

Browse files
committed
Added tests for WTable
Two of them (moveRow2 and moveColumn2) do not pass because of a bug in the WTable's code, which is not adressed in this commit. That's why these ones are disabled. The tests are not that comprehensive and were created to test the correctnes of code in future commits adressing WTable's performance.
1 parent 72bb202 commit 989c2ad

File tree

2 files changed

+270
-0
lines changed

2 files changed

+270
-0
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ IF(ENABLE_LIBWTTEST)
3232
utils/Base64Test.C
3333
utils/EraseWord.C
3434
utils/ParseNumber.C
35+
widgets/WTableTest.C
3536
widgets/WSpinBoxTest.C
3637
length/WLengthTest.C
3738
color/WColorTest.C

test/widgets/WTableTest.C

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
/*
2+
* Copyright (C) 2010 Emweb bvba, Kessel-Lo, Belgium.
3+
*
4+
* See the LICENSE file for terms of use.
5+
*/
6+
#include <boost/test/unit_test.hpp>
7+
8+
#include <Wt/WApplication.h>
9+
#include <Wt/WTable.h>
10+
#include <Wt/Test/WTestEnvironment.h>
11+
12+
using namespace Wt;
13+
14+
namespace {
15+
Wt::Test::WTestEnvironment environment;
16+
Wt::WApplication testApp(environment);
17+
18+
void CheckRowNumbers(WTable* table)
19+
{
20+
for (auto i = 0; i < table->rowCount(); ++i) {
21+
BOOST_REQUIRE_EQUAL(table->rowAt(i)->rowNum(), i);
22+
}
23+
}
24+
void CheckColumnNumbers(WTable* table)
25+
{
26+
for (auto i = 0; i < table->columnCount(); ++i) {
27+
BOOST_REQUIRE_EQUAL(table->columnAt(i)->columnNum(), i);
28+
}
29+
}
30+
}
31+
32+
BOOST_AUTO_TEST_SUITE( WTableTest )
33+
34+
BOOST_AUTO_TEST_CASE( elementAt1 )
35+
{
36+
auto table = cpp14::make_unique<WTable>();
37+
BOOST_REQUIRE_NO_THROW(table->elementAt(5, 1));
38+
39+
auto rowCount = table->rowCount();
40+
41+
BOOST_REQUIRE_EQUAL(rowCount, 6);
42+
CheckRowNumbers(table.get());
43+
}
44+
45+
BOOST_AUTO_TEST_CASE( elementAt2 )
46+
{
47+
auto table = cpp14::make_unique<WTable>();
48+
BOOST_REQUIRE_NO_THROW(table->elementAt(1, 5));
49+
50+
auto columnCount = table->columnCount();
51+
52+
BOOST_REQUIRE_EQUAL(columnCount, 6);
53+
CheckColumnNumbers(table.get());
54+
}
55+
56+
BOOST_AUTO_TEST_CASE( elementAt3 )
57+
{
58+
auto table = cpp14::make_unique<WTable>();
59+
BOOST_REQUIRE_NO_THROW(table->elementAt(5, 4));
60+
61+
auto rowCount = table->rowCount();
62+
auto columnCount = table->columnCount();
63+
64+
BOOST_REQUIRE_EQUAL(rowCount, 6);
65+
BOOST_REQUIRE_EQUAL(columnCount, 5);
66+
CheckRowNumbers(table.get());
67+
CheckColumnNumbers(table.get());
68+
}
69+
70+
BOOST_AUTO_TEST_CASE( rowAt )
71+
{
72+
auto table = cpp14::make_unique<WTable>();
73+
BOOST_REQUIRE_NO_THROW(table->rowAt(5));
74+
75+
auto rowCount = table->rowCount();
76+
77+
BOOST_REQUIRE_EQUAL(rowCount, 6);
78+
CheckRowNumbers(table.get());
79+
}
80+
81+
BOOST_AUTO_TEST_CASE( columnAt )
82+
{
83+
auto table = cpp14::make_unique<WTable>();
84+
BOOST_REQUIRE_NO_THROW(table->columnAt(5));
85+
86+
auto columnCount = table->columnCount();
87+
88+
BOOST_REQUIRE_EQUAL(columnCount, 6);
89+
CheckColumnNumbers(table.get());
90+
}
91+
92+
BOOST_AUTO_TEST_CASE( insertRow1 )
93+
{
94+
auto table = cpp14::make_unique<WTable>();
95+
table->rowAt(2);
96+
BOOST_REQUIRE_NO_THROW(table->insertRow(1));
97+
98+
auto rowCount = table->rowCount();
99+
100+
BOOST_REQUIRE_EQUAL(rowCount, 4);
101+
CheckRowNumbers(table.get());
102+
}
103+
104+
BOOST_AUTO_TEST_CASE( insertRow2 )
105+
{
106+
auto table = cpp14::make_unique<WTable>();
107+
table->rowAt(2);
108+
BOOST_REQUIRE_NO_THROW(table->insertRow(3));
109+
110+
auto rowCount = table->rowCount();
111+
112+
BOOST_REQUIRE_EQUAL(rowCount, 4);
113+
CheckRowNumbers(table.get());
114+
}
115+
116+
BOOST_AUTO_TEST_CASE( insertRow3 )
117+
{
118+
auto table = cpp14::make_unique<WTable>();
119+
BOOST_REQUIRE_NO_THROW(table->insertRow(0));
120+
}
121+
122+
BOOST_AUTO_TEST_CASE( insertColumn1 )
123+
{
124+
auto table = cpp14::make_unique<WTable>();
125+
table->columnAt(2);
126+
BOOST_REQUIRE_NO_THROW(table->insertColumn(1));
127+
128+
auto columnCount = table->columnCount();
129+
130+
BOOST_REQUIRE_EQUAL(columnCount, 4);
131+
CheckColumnNumbers(table.get());
132+
}
133+
134+
BOOST_AUTO_TEST_CASE( insertColumn2 )
135+
{
136+
auto table = cpp14::make_unique<WTable>();
137+
table->columnAt(2);
138+
BOOST_REQUIRE_NO_THROW(table->insertColumn(3));
139+
140+
auto columnCount = table->columnCount();
141+
142+
BOOST_REQUIRE_EQUAL(columnCount, 4);
143+
CheckColumnNumbers(table.get());
144+
}
145+
146+
BOOST_AUTO_TEST_CASE( insertColumn3 )
147+
{
148+
auto table = cpp14::make_unique<WTable>();
149+
BOOST_REQUIRE_NO_THROW(table->insertColumn(0));
150+
}
151+
152+
BOOST_AUTO_TEST_CASE( removeRow1 )
153+
{
154+
auto table = cpp14::make_unique<WTable>();
155+
table->rowAt(5);
156+
BOOST_REQUIRE_NO_THROW(table->removeRow(2));
157+
158+
auto rowCount = table->rowCount();
159+
160+
BOOST_REQUIRE_EQUAL(rowCount, 5);
161+
CheckRowNumbers(table.get());
162+
}
163+
164+
BOOST_AUTO_TEST_CASE( removeRow2 )
165+
{
166+
auto table = cpp14::make_unique<WTable>();
167+
table->rowAt(0);
168+
BOOST_REQUIRE_NO_THROW(table->removeRow(0));
169+
}
170+
171+
BOOST_AUTO_TEST_CASE( removeColumn1 )
172+
{
173+
auto table = cpp14::make_unique<WTable>();
174+
table->columnAt(5);
175+
BOOST_REQUIRE_NO_THROW(table->removeColumn(2));
176+
177+
auto columnCount = table->columnCount();
178+
179+
BOOST_REQUIRE_EQUAL(columnCount, 5);
180+
CheckColumnNumbers(table.get());
181+
}
182+
183+
BOOST_AUTO_TEST_CASE( removeColumn2 )
184+
{
185+
auto table = cpp14::make_unique<WTable>();
186+
table->columnAt(0);
187+
BOOST_REQUIRE_NO_THROW(table->removeColumn(0));
188+
}
189+
190+
BOOST_AUTO_TEST_CASE( moveRow1 )
191+
{
192+
auto table = cpp14::make_unique<WTable>();
193+
table->rowAt(5);
194+
195+
WTableCell* cell2 = table->elementAt(2, 0);
196+
WTableCell* cell0 = table->elementAt(0, 0);
197+
198+
BOOST_REQUIRE_NO_THROW(table->moveRow(2, 0));
199+
200+
BOOST_REQUIRE_EQUAL(table->elementAt(0, 0), cell2);
201+
BOOST_REQUIRE_EQUAL(table->elementAt(1, 0), cell0);
202+
BOOST_REQUIRE_NE(table->elementAt(2, 0), cell2);
203+
204+
BOOST_REQUIRE_EQUAL(table->rowCount(), 6);
205+
CheckRowNumbers(table.get());
206+
}
207+
208+
BOOST_AUTO_TEST_CASE( moveRow2, * boost::unit_test::disabled() )
209+
{
210+
auto table = cpp14::make_unique<WTable>();
211+
table->rowAt(5);
212+
213+
WTableCell* cell2 = table->elementAt(2, 0);
214+
215+
BOOST_REQUIRE_NO_THROW(table->moveRow(2, 7));
216+
217+
BOOST_REQUIRE_NE(table->elementAt(2, 0), cell2);
218+
BOOST_REQUIRE_EQUAL(table->elementAt(7, 0), cell2);
219+
220+
BOOST_REQUIRE_EQUAL(table->rowCount(), 8);
221+
CheckRowNumbers(table.get());
222+
}
223+
224+
BOOST_AUTO_TEST_CASE( moveColumn1 )
225+
{
226+
auto table = cpp14::make_unique<WTable>();
227+
table->columnAt(5);
228+
229+
WTableCell* cell2 = table->elementAt(0, 2);
230+
WTableCell* cell0 = table->elementAt(0, 0);
231+
232+
BOOST_REQUIRE_NO_THROW(table->moveColumn(2, 0));
233+
234+
BOOST_REQUIRE_EQUAL(table->elementAt(0, 0), cell2);
235+
BOOST_REQUIRE_EQUAL(table->elementAt(0, 1), cell0);
236+
BOOST_REQUIRE_NE(table->elementAt(0, 2), cell2);
237+
238+
BOOST_REQUIRE_EQUAL(table->columnCount(), 6);
239+
CheckColumnNumbers(table.get());
240+
}
241+
242+
BOOST_AUTO_TEST_CASE( moveColumn2, * boost::unit_test::disabled() )
243+
{
244+
auto table = cpp14::make_unique<WTable>();
245+
table->columnAt(5);
246+
247+
WTableCell* cell2 = table->elementAt(0, 2);
248+
249+
BOOST_REQUIRE_NO_THROW(table->moveColumn(2, 7));
250+
251+
BOOST_REQUIRE_EQUAL(table->elementAt(0, 7), cell2);
252+
BOOST_REQUIRE_NE(table->elementAt(0, 2), cell2);
253+
254+
BOOST_REQUIRE_EQUAL(table->columnCount(), 8);
255+
CheckColumnNumbers(table.get());
256+
}
257+
258+
BOOST_AUTO_TEST_CASE( clear )
259+
{
260+
auto table = cpp14::make_unique<WTable>();
261+
table->elementAt(4, 4);
262+
263+
BOOST_REQUIRE_NO_THROW(table->clear());
264+
265+
BOOST_REQUIRE_EQUAL(table->rowCount(), 0);
266+
BOOST_REQUIRE_EQUAL(table->columnCount(), 0);
267+
}
268+
269+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)