aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/frameworkimpl/status/htmltabletest.cpp
blob: 22babc5d1009c3c8c0a88ba0a4bb8968a2ee65ff (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/storage/frameworkimpl/thread/htmltable.h>
#include <gtest/gtest.h>

namespace storage {

TEST(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");
        EXPECT_EQ(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");
        EXPECT_EQ(expected, ost.str());
    }
}

TEST(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");
        EXPECT_EQ(expected, ost.str());
    }

}

} // storage