blob: 98cf68d489a4585ea9e7ac4d289e794c26c64d3b (
plain) (
blame)
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/storage/bucketmover/htmltable.h>
#include <tests/common/testhelper.h>
namespace storage {
struct HtmlTableTest : public CppUnit::TestFixture {
void testPercentageColumn();
void testByteSizeColumn();
CPPUNIT_TEST_SUITE(HtmlTableTest);
CPPUNIT_TEST(testPercentageColumn);
CPPUNIT_TEST(testByteSizeColumn);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(HtmlTableTest);
void HtmlTableTest::testPercentageColumn()
{
// With total hardcoded to 100
{
HtmlTable table("disk");
PercentageColumn perc("fillrate", 100);
perc.addColorLimit(70, Column::LIGHT_GREEN);
perc.addColorLimit(85, Column::LIGHT_YELLOW);
perc.addColorLimit(100, Column::LIGHT_RED);
table.addColumn(perc);
table.addRow(0);
table.addRow(1);
table.addRow(2);
perc[0] = 30;
perc[1] = 80;
perc[2] = 100;
std::ostringstream ost;
table.print(ost);
std::string expected(
"<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\">\n"
"<tr><th>disk</th><th>fillrate</th></tr>\n"
"<tr><td>0</td><td bgcolor=\"#a0ffa0\" align=\"right\">30.00 %</td></tr>\n"
"<tr><td>1</td><td bgcolor=\"#ffffa0\" align=\"right\">80.00 %</td></tr>\n"
"<tr><td>2</td><td bgcolor=\"#ffa0a0\" align=\"right\">100.00 %</td></tr>\n"
"</table>\n");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
}
// With automatically gathered total
{
HtmlTable table("disk");
PercentageColumn perc("fillrate");
table.addColumn(perc);
table.addRow(0);
table.addRow(1);
table.addRow(2);
perc[0] = 30;
perc[1] = 80;
perc[2] = 100;
std::ostringstream ost;
table.print(ost);
std::string expected(
"<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\">\n"
"<tr><th>disk</th><th>fillrate</th></tr>\n"
"<tr><td>0</td><td align=\"right\">14.29 %</td></tr>\n"
"<tr><td>1</td><td align=\"right\">38.10 %</td></tr>\n"
"<tr><td>2</td><td align=\"right\">47.62 %</td></tr>\n"
"</table>\n");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
}
}
void HtmlTableTest::testByteSizeColumn()
{
{
HtmlTable table("disk");
ByteSizeColumn size("size");
table.addColumn(size);
table.addRow(0);
table.addRow(1);
table.addRow(2);
// Biggest value enforce the denomination
size[0] = 42123;
size[1] = 124123151;
size[2] = 6131231;
std::ostringstream ost;
table.print(ost);
std::string expected(
"<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\">\n"
"<tr><th>disk</th><th>size</th></tr>\n"
"<tr><td>0</td><td align=\"right\">0 MB</td></tr>\n"
"<tr><td>1</td><td align=\"right\">118 MB</td></tr>\n"
"<tr><td>2</td><td align=\"right\">5 MB</td></tr>\n"
"</table>\n");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
}
}
} // storage
|