finish testing fill

This commit is contained in:
Thomas Fussell 2016-06-19 21:30:15 +01:00
parent f28e09d9a3
commit 7b6b5517d9
3 changed files with 79 additions and 1 deletions

View File

@ -45,6 +45,7 @@ public:
enum class gradient_type
{
none,
linear,
path
};
@ -98,10 +99,14 @@ public:
const std::experimental::optional<color> &get_background_color() const;
void set_start_color(const color &c);
std::experimental::optional<color> &get_start_color();
const std::experimental::optional<color> &get_start_color() const;
void set_end_color(const color &c);
std::experimental::optional<color> &get_end_color();
const std::experimental::optional<color> &get_end_color() const;

View File

@ -29,7 +29,7 @@ namespace xlnt {
fill::fill()
: type_(type::pattern),
pattern_type_(pattern_type::none),
gradient_type_(gradient_type::linear),
gradient_type_(gradient_type::none),
rotation_(0),
gradient_path_left_(0),
gradient_path_right_(0),
@ -219,4 +219,14 @@ void fill::set_background_color(const color &c)
background_color_ = c;
}
void fill::set_start_color(const color &c)
{
start_color_ = c;
}
void fill::set_end_color(const color &c)
{
end_color_ = c;
}
} // namespace xlnt

View File

@ -0,0 +1,63 @@
#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;
TS_ASSERT_EQUALS(fill.get_gradient_type(), xlnt::fill::gradient_type::none);
fill.set_gradient_type(xlnt::fill::gradient_type::linear);
TS_ASSERT_EQUALS(fill.get_gradient_type(), xlnt::fill::gradient_type::linear);
TS_ASSERT(!fill.get_foreground_color());
fill.set_foreground_color(xlnt::color::black());
TS_ASSERT(fill.get_foreground_color());
TS_ASSERT(!fill.get_background_color());
fill.set_background_color(xlnt::color::black());
TS_ASSERT(fill.get_background_color());
TS_ASSERT(!fill.get_start_color());
fill.set_start_color(xlnt::color::black());
TS_ASSERT(fill.get_start_color());
TS_ASSERT(!fill.get_end_color());
fill.set_end_color(xlnt::color::black());
TS_ASSERT(fill.get_end_color());
TS_ASSERT_EQUALS(fill.get_rotation(), 0);
fill.set_rotation(1);
TS_ASSERT_EQUALS(fill.get_rotation(), 1);
TS_ASSERT_EQUALS(fill.get_gradient_bottom(), 0);
TS_ASSERT_EQUALS(fill.get_gradient_left(), 0);
TS_ASSERT_EQUALS(fill.get_gradient_top(), 0);
TS_ASSERT_EQUALS(fill.get_gradient_right(), 0);
}
void test_hash()
{
xlnt::fill none_fill;
xlnt::fill solid_fill;
solid_fill.set_type(xlnt::fill::type::solid);
xlnt::fill pattern_fill;
pattern_fill.set_type(xlnt::fill::type::pattern);
xlnt::fill gradient_fill;
gradient_fill.set_type(xlnt::fill::type::gradient);
TS_ASSERT_DIFFERS(none_fill.hash(), solid_fill.hash());
TS_ASSERT_DIFFERS(solid_fill.hash(), pattern_fill.hash());
TS_ASSERT_DIFFERS(pattern_fill.hash(), gradient_fill.hash());
TS_ASSERT_DIFFERS(gradient_fill.hash(), none_fill.hash());
}
};