xlnt/tests/styles/color_test_suite.cpp

78 lines
3.0 KiB
C++
Raw Normal View History

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
2016-06-20 04:06:12 +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/styles/color.hpp>
2016-06-20 04:06:12 +08:00
2017-04-14 07:01:30 +08:00
class color_test_suite : public test_suite
2016-06-20 04:06:12 +08:00
{
public:
2017-04-14 07:01:30 +08:00
color_test_suite()
{
register_test(test_known_colors);
register_test(test_non_rgb_colors);
}
2016-06-20 04:06:12 +08:00
void test_known_colors()
{
const std::vector<std::pair<xlnt::color, std::string>> known_colors{
{xlnt::color::black(), "FF000000"},
{xlnt::color::white(), "FFFFFFFF"},
{xlnt::color::red(), "FFFF0000"},
{xlnt::color::darkred(), "FF8B0000"},
{xlnt::color::blue(), "FF0000FF"},
{xlnt::color::darkblue(), "FF00008B"},
{xlnt::color::green(), "FF00FF00"},
{xlnt::color::darkgreen(), "FF008B00"},
{xlnt::color::yellow(), "FFFFFF00"},
{xlnt::color::darkyellow(), "FFCCCC00"}};
2016-06-20 04:06:12 +08:00
for (auto pair : known_colors)
{
xlnt_assert_equals(pair.first.rgb().hex_string(), pair.second);
2016-06-20 04:06:12 +08:00
}
}
2016-06-20 04:06:12 +08:00
void test_non_rgb_colors()
{
xlnt::color indexed = xlnt::indexed_color(1);
xlnt_assert(!indexed.auto_());
xlnt_assert_equals(indexed.indexed().index(), 1);
indexed.indexed().index(2);
xlnt_assert_equals(indexed.indexed().index(), 2);
xlnt_assert_throws(indexed.theme(), xlnt::invalid_attribute);
xlnt_assert_throws(indexed.rgb(), xlnt::invalid_attribute);
2016-06-20 04:06:12 +08:00
xlnt::color theme = xlnt::theme_color(3);
xlnt_assert(!theme.auto_());
xlnt_assert_equals(theme.theme().index(), 3);
theme.theme().index(4);
xlnt_assert_equals(theme.theme().index(), 4);
xlnt_assert_throws(theme.indexed(), xlnt::invalid_attribute);
xlnt_assert_throws(theme.rgb(), xlnt::invalid_attribute);
2016-06-20 04:06:12 +08:00
}
};
static color_test_suite x;