2018-01-22 22:38:48 +08:00
|
|
|
// Copyright (c) 2014-2018 Thomas Fussell
|
2017-04-14 07:01:30 +08:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE
|
|
|
|
//
|
|
|
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
// @author: see AUTHORS file
|
|
|
|
|
2017-04-14 02:51:35 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-04-14 07:24:20 +08:00
|
|
|
#include <helpers/test_suite.hpp>
|
2018-07-05 17:26:29 +08:00
|
|
|
|
|
|
|
#include <xlnt/cell/cell.hpp>
|
|
|
|
#include <xlnt/styles/fill.hpp>
|
|
|
|
#include <xlnt/utils/date.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2017-04-14 02:51:35 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
class fill_test_suite : public test_suite
|
2017-04-14 02:51:35 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-04-14 07:01:30 +08:00
|
|
|
fill_test_suite()
|
|
|
|
{
|
|
|
|
register_test(test_properties);
|
|
|
|
register_test(test_comparison);
|
|
|
|
register_test(test_two_fills);
|
|
|
|
}
|
|
|
|
|
2017-04-14 02:51:35 +08:00
|
|
|
void test_properties()
|
|
|
|
{
|
|
|
|
xlnt::fill fill;
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(fill.type(), xlnt::fill_type::pattern);
|
2017-04-14 02:51:35 +08:00
|
|
|
fill = xlnt::fill(xlnt::gradient_fill());
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(fill.type(), xlnt::fill_type::gradient);
|
|
|
|
xlnt_assert_equals(fill.gradient_fill().type(), xlnt::gradient_fill_type::linear);
|
2017-04-14 02:51:35 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(fill.gradient_fill().left(), 0);
|
|
|
|
xlnt_assert_equals(fill.gradient_fill().right(), 0);
|
|
|
|
xlnt_assert_equals(fill.gradient_fill().top(), 0);
|
|
|
|
xlnt_assert_equals(fill.gradient_fill().bottom(), 0);
|
2017-04-14 02:51:35 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_throws(fill.pattern_fill(), xlnt::invalid_attribute);
|
2017-04-14 02:51:35 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(fill.gradient_fill().degree(), 0);
|
2017-04-14 02:51:35 +08:00
|
|
|
fill = fill.gradient_fill().degree(1);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(fill.gradient_fill().degree(), 1);
|
2017-04-14 02:51:35 +08:00
|
|
|
|
|
|
|
fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
|
|
|
|
|
|
|
fill = fill.pattern_fill().foreground(xlnt::color::black());
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(fill.pattern_fill().foreground().is_set());
|
|
|
|
xlnt_assert_equals(fill.pattern_fill().foreground().get().rgb().hex_string(),
|
2017-04-14 02:51:35 +08:00
|
|
|
xlnt::color::black().rgb().hex_string());
|
|
|
|
|
|
|
|
fill = fill.pattern_fill().background(xlnt::color::green());
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(fill.pattern_fill().background().is_set());
|
|
|
|
xlnt_assert_equals(fill.pattern_fill().background().get().rgb().hex_string(),
|
2017-04-14 02:51:35 +08:00
|
|
|
xlnt::color::green().rgb().hex_string());
|
|
|
|
|
|
|
|
const auto &const_fill = fill;
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(const_fill.pattern_fill().foreground().is_set());
|
|
|
|
xlnt_assert(const_fill.pattern_fill().background().is_set());
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_comparison()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_differs(pattern_fill, gradient_fill_linear);
|
|
|
|
xlnt_assert_differs(gradient_fill_linear, gradient_fill_path);
|
|
|
|
xlnt_assert_differs(gradient_fill_path, pattern_fill);
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_two_fills()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws1 = wb.active_sheet();
|
|
|
|
|
|
|
|
auto cell1 = ws1.cell("A10");
|
|
|
|
auto cell2 = ws1.cell("A11");
|
|
|
|
|
|
|
|
cell1.fill(xlnt::fill::solid(xlnt::color::yellow()));
|
|
|
|
cell1.value("Fill Yellow");
|
|
|
|
|
|
|
|
cell2.fill(xlnt::fill::solid(xlnt::color::green()));
|
|
|
|
cell2.value(xlnt::date(2010, 7, 13));
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow()));
|
|
|
|
xlnt_assert_equals(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
|
|
|
};
|
2018-07-05 16:47:24 +08:00
|
|
|
static fill_test_suite x;
|