aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/storageutil/charttest.cpp
blob: d16f3f1174709fceca269a940185522fb6ad2b84 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/storage/storageutil/piechart.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <fstream>

namespace storage {

struct PieChartTest : public CppUnit::TestFixture
{
    void testWriteHtmlFile();

    CPPUNIT_TEST_SUITE(PieChartTest);
    CPPUNIT_TEST(testWriteHtmlFile);
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(PieChartTest);

namespace {
    void printHtmlFile(const std::string& filename, const PieChart& chart) {
        std::ofstream out(filename.c_str());
        out << "<html>\n"
            << "  <head>\n"
            << "    ";
        PieChart::printHtmlHeadAdditions(out, "    ");
        out << "\n  <title>Pie example</title>\n"
            << "  </head>\n"
            << "  <body>\n"
            << "    ";
        chart.printCanvas(out, 500, 400);
        out << "\n    ";
        chart.printScript(out, "    ");
        out << "\n  </body>\n"
            << "</html>\n";
        out.close();
    }
}

void
PieChartTest::testWriteHtmlFile()
{
    {
        PieChart chart("mypie");
        chart.add(10, "put");
        chart.add(20, "get");
        chart.add(50, "free");

        printHtmlFile("piefile.html", chart);
    }
    {
        PieChart chart("mypie", PieChart::SCHEME_CUSTOM);
        chart.add(10, "put", PieChart::RED);
        chart.add(20, "get", PieChart::GREEN);
        chart.add(50, "free", PieChart::BLUE);

        printHtmlFile("piefile-customcols.html", chart);
    }
}

} // storage