2016-06-19 21:30:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
|
|
#include <xlnt/xlnt.hpp>
|
|
|
|
|
|
|
|
class test_fill : public CxxTest::TestSuite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void test_properties()
|
|
|
|
{
|
|
|
|
xlnt::fill fill;
|
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
TS_ASSERT_EQUALS(fill.type(), xlnt::fill_type::pattern);
|
|
|
|
fill = xlnt::fill(xlnt::gradient_fill());
|
|
|
|
TS_ASSERT_EQUALS(fill.type(), xlnt::fill_type::gradient);
|
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().type(), xlnt::gradient_fill_type::linear);
|
2016-07-14 22:09:57 -04:00
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().left(), 0);
|
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().right(), 0);
|
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().top(), 0);
|
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().bottom(), 0);
|
2016-07-14 22:09:57 -04:00
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
TS_ASSERT_THROWS(fill.pattern_fill(), xlnt::invalid_attribute);
|
2016-07-14 22:09:57 -04:00
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().degree(), 0);
|
|
|
|
fill = fill.gradient_fill().degree(1);
|
|
|
|
TS_ASSERT_EQUALS(fill.gradient_fill().degree(), 1);
|
2016-07-14 22:09:57 -04:00
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
2016-07-14 22:09:57 -04:00
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
fill = fill.pattern_fill().foreground(xlnt::color::black());
|
|
|
|
TS_ASSERT(fill.pattern_fill().foreground());
|
2016-12-29 19:00:27 -05:00
|
|
|
TS_ASSERT_EQUALS(fill.pattern_fill().foreground().get().rgb().hex_string(), xlnt::color::black().rgb().hex_string());
|
2016-08-01 18:33:43 -04:00
|
|
|
|
2016-08-16 00:23:49 -04:00
|
|
|
fill = fill.pattern_fill().background(xlnt::color::green());
|
|
|
|
TS_ASSERT(fill.pattern_fill().background());
|
2016-12-29 19:00:27 -05:00
|
|
|
TS_ASSERT_EQUALS(fill.pattern_fill().background().get().rgb().hex_string(), xlnt::color::green().rgb().hex_string());
|
2016-06-19 21:58:55 +01:00
|
|
|
|
|
|
|
const auto &const_fill = fill;
|
2016-08-16 00:23:49 -04:00
|
|
|
TS_ASSERT(const_fill.pattern_fill().foreground());
|
|
|
|
TS_ASSERT(const_fill.pattern_fill().background());
|
2016-06-19 21:30:15 +01:00
|
|
|
}
|
|
|
|
|
2016-10-31 20:48:43 -04:00
|
|
|
void test_comparison()
|
2016-06-19 21:30:15 +01:00
|
|
|
{
|
2016-08-16 00:23:49 -04:00
|
|
|
xlnt::fill pattern_fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
|
|
|
xlnt::fill gradient_fill_linear = xlnt::gradient_fill().type(xlnt::gradient_fill_type::linear);
|
|
|
|
xlnt::fill gradient_fill_path = xlnt::gradient_fill().type(xlnt::gradient_fill_type::path);
|
2016-06-19 21:30:15 +01:00
|
|
|
|
2016-10-31 20:48:43 -04:00
|
|
|
TS_ASSERT_DIFFERS(pattern_fill, gradient_fill_linear);
|
|
|
|
TS_ASSERT_DIFFERS(gradient_fill_linear, gradient_fill_path);
|
|
|
|
TS_ASSERT_DIFFERS(gradient_fill_path, pattern_fill);
|
2016-06-19 21:30:15 +01:00
|
|
|
}
|
2016-11-01 08:50:29 -04:00
|
|
|
|
|
|
|
void test_two_fills()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 14:37:50 +01:00
|
|
|
auto ws1 = wb.active_sheet();
|
2016-11-01 08:50:29 -04:00
|
|
|
|
2016-12-02 14:37:50 +01:00
|
|
|
auto cell1 = ws1.cell("A10");
|
|
|
|
auto cell2 = ws1.cell("A11");
|
2016-11-01 08:50:29 -04:00
|
|
|
|
2016-12-02 14:37:50 +01:00
|
|
|
cell1.fill(xlnt::fill::solid(xlnt::color::yellow()));
|
|
|
|
cell1.value("Fill Yellow");
|
2016-11-01 08:50:29 -04:00
|
|
|
|
2016-12-02 14:37:50 +01:00
|
|
|
cell2.fill(xlnt::fill::solid(xlnt::color::green()));
|
|
|
|
cell2.value(xlnt::date(2010, 7, 13));
|
2016-11-01 08:50:29 -04:00
|
|
|
|
2016-12-02 14:37:50 +01:00
|
|
|
TS_ASSERT_EQUALS(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow()));
|
|
|
|
TS_ASSERT_EQUALS(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
|
2016-11-01 08:50:29 -04:00
|
|
|
}
|
2016-06-19 21:30:15 +01:00
|
|
|
};
|