mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Add tests for functionality added to implement declared functionality
This commit is contained in:
parent
03020cc793
commit
ddab6551b0
|
@ -608,9 +608,9 @@ public:
|
|||
bool operator==(const cell &comparand) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this cell is uninitialized.
|
||||
/// Returns false if this cell the same cell as comparand (compared by reference).
|
||||
/// </summary>
|
||||
bool operator==(std::nullptr_t) const;
|
||||
bool operator!=(const cell &comparand) const;
|
||||
|
||||
private:
|
||||
friend class style;
|
||||
|
@ -646,6 +646,11 @@ private:
|
|||
/// </summary>
|
||||
XLNT_API bool operator==(std::nullptr_t, const cell &cell);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this cell is uninitialized.
|
||||
/// </summary>
|
||||
XLNT_API bool operator==(const cell &cell, std::nullptr_t);
|
||||
|
||||
/// <summary>
|
||||
/// Convenience function for writing cell to an ostream.
|
||||
/// Uses cell::to_string() internally.
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace xlnt {
|
|||
/// <summary>
|
||||
/// Typedef a rich_text_run as a pair of string and optional font.
|
||||
/// </summary>
|
||||
struct rich_text_run
|
||||
struct XLNT_API rich_text_run
|
||||
{
|
||||
std::string first;
|
||||
optional<font> second;
|
||||
|
|
|
@ -252,19 +252,37 @@ public:
|
|||
/// Returns the internal indexed color representing this color. If this is not an RGB color,
|
||||
/// an invalid_attribute exception will be thrown.
|
||||
/// </summary>
|
||||
rgb_color rgb() const;
|
||||
const rgb_color& rgb() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal indexed color representing this color. If this is not an RGB color,
|
||||
/// an invalid_attribute exception will be thrown.
|
||||
/// </summary>
|
||||
rgb_color &rgb();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal indexed color representing this color. If this is not an indexed color,
|
||||
/// an invalid_attribute exception will be thrown.
|
||||
/// </summary>
|
||||
indexed_color indexed() const;
|
||||
const indexed_color& indexed() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal indexed color representing this color. If this is not an indexed color,
|
||||
/// an invalid_attribute exception will be thrown.
|
||||
/// </summary>
|
||||
indexed_color &indexed();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal indexed color representing this color. If this is not a theme color,
|
||||
/// an invalid_attribute exception will be thrown.
|
||||
/// </summary>
|
||||
theme_color theme() const;
|
||||
const theme_color& theme() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal indexed color representing this color. If this is not a theme color,
|
||||
/// an invalid_attribute exception will be thrown.
|
||||
/// </summary>
|
||||
theme_color& theme();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the tint of this color.
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
/// Create a string representing this path separated by the provided
|
||||
/// separator or the system-default separator if not provided.
|
||||
/// </summary>
|
||||
std::string string() const;
|
||||
const std::string& string() const;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/// <summary>
|
||||
|
@ -176,6 +176,11 @@ public:
|
|||
/// </summary>
|
||||
bool operator==(const path &other) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if left path is equal to right path.
|
||||
/// </summary>
|
||||
bool operator!=(const path &other) const;
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// Returns the character that separates directories in the path.
|
||||
|
|
|
@ -341,32 +341,18 @@ cell_reference cell::reference() const
|
|||
return {d_->column_, d_->row_};
|
||||
}
|
||||
|
||||
bool cell::operator==(std::nullptr_t) const
|
||||
{
|
||||
return d_ == nullptr;
|
||||
}
|
||||
|
||||
bool cell::operator==(const cell &comparand) const
|
||||
{
|
||||
return d_ == comparand.d_;
|
||||
}
|
||||
|
||||
cell &cell::operator=(const cell &rhs)
|
||||
bool cell::operator!=(const cell &comparand) const
|
||||
{
|
||||
d_->column_ = rhs.d_->column_;
|
||||
d_->format_ = rhs.d_->format_;
|
||||
d_->formula_ = rhs.d_->formula_;
|
||||
d_->hyperlink_ = rhs.d_->hyperlink_;
|
||||
d_->is_merged_ = rhs.d_->is_merged_;
|
||||
d_->parent_ = rhs.d_->parent_;
|
||||
d_->row_ = rhs.d_->row_;
|
||||
d_->type_ = rhs.d_->type_;
|
||||
d_->value_numeric_ = rhs.d_->value_numeric_;
|
||||
d_->value_text_ = rhs.d_->value_text_;
|
||||
|
||||
return *this;
|
||||
return d_ != comparand.d_;
|
||||
}
|
||||
|
||||
cell &cell::operator=(const cell &rhs) = default;
|
||||
|
||||
hyperlink cell::hyperlink() const
|
||||
{
|
||||
return xlnt::hyperlink(&d_->hyperlink_.get());
|
||||
|
@ -437,7 +423,7 @@ void cell::hyperlink(xlnt::cell target, const std::string& display)
|
|||
void cell::hyperlink(xlnt::range target, const std::string &display)
|
||||
{
|
||||
// TODO: should this computed value be a method on a cell?
|
||||
const auto range_address = target.worksheet().title() + "!" + target.reference().to_string();
|
||||
const auto range_address = target.target_worksheet().title() + "!" + target.reference().to_string();
|
||||
|
||||
d_->hyperlink_ = detail::hyperlink_impl();
|
||||
d_->hyperlink_.get().relationship = xlnt::relationship("", relationship_type::hyperlink,
|
||||
|
@ -778,6 +764,11 @@ bool operator==(std::nullptr_t, const cell &cell)
|
|||
return cell.data_type() == cell::type::empty;
|
||||
}
|
||||
|
||||
bool operator==(const cell &cell, std::nullptr_t)
|
||||
{
|
||||
return nullptr == cell;
|
||||
}
|
||||
|
||||
XLNT_API std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
|
||||
{
|
||||
return stream << cell.to_string();
|
||||
|
|
|
@ -27,22 +27,26 @@
|
|||
|
||||
#include <xlnt/cell/cell_type.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/rich_text.hpp>
|
||||
#include <xlnt/cell/index_types.hpp>
|
||||
#include <xlnt/cell/rich_text.hpp>
|
||||
#include <xlnt/packaging/relationship.hpp>
|
||||
#include <xlnt/utils/optional.hpp>
|
||||
#include <detail/implementations/format_impl.hpp>
|
||||
#include <detail/implementations/hyperlink_impl.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
namespace detail {
|
||||
|
||||
struct format_impl;
|
||||
struct worksheet_impl;
|
||||
|
||||
struct cell_impl
|
||||
{
|
||||
cell_impl();
|
||||
|
||||
cell_impl(const cell_impl &other) = default;
|
||||
cell_impl(cell_impl &&other) = default;
|
||||
cell_impl &operator=(const cell_impl &other) = default;
|
||||
cell_impl &operator=(cell_impl &&other) = default;
|
||||
|
||||
cell_type type_;
|
||||
|
||||
worksheet_impl *parent_;
|
||||
|
@ -72,9 +76,8 @@ inline bool operator==(const cell_impl &lhs, const cell_impl &rhs)
|
|||
&& lhs.value_numeric_ == rhs.value_numeric_
|
||||
&& lhs.formula_ == rhs.formula_
|
||||
&& lhs.hyperlink_ == rhs.hyperlink_
|
||||
// comparing pointers is unlikely to be what is wanted
|
||||
/*&& lhs.format_ == rhs.format_
|
||||
&& lhs.comment_ == rhs.comment_*/;
|
||||
&& (lhs.format_.is_set() == rhs.format_.is_set() && (!lhs.format_.is_set() || *lhs.format_.get() == *rhs.format_.get()))
|
||||
&& (lhs.comment_.is_set() == rhs.comment_.is_set() && (!lhs.comment_.is_set() || *lhs.comment_.get() == *rhs.comment_.get()));
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
|
|
@ -233,19 +233,37 @@ void color::auto_(bool value)
|
|||
auto__ = value;
|
||||
}
|
||||
|
||||
indexed_color color::indexed() const
|
||||
const indexed_color& color::indexed() const
|
||||
{
|
||||
assert_type(color_type::indexed);
|
||||
return indexed_;
|
||||
}
|
||||
|
||||
theme_color color::theme() const
|
||||
indexed_color &color::indexed()
|
||||
{
|
||||
assert_type(color_type::indexed);
|
||||
return indexed_;
|
||||
}
|
||||
|
||||
const theme_color& color::theme() const
|
||||
{
|
||||
assert_type(color_type::theme);
|
||||
return theme_;
|
||||
}
|
||||
|
||||
rgb_color color::rgb() const
|
||||
theme_color &color::theme()
|
||||
{
|
||||
assert_type(color_type::theme);
|
||||
return theme_;
|
||||
}
|
||||
|
||||
const rgb_color& color::rgb() const
|
||||
{
|
||||
assert_type(color_type::rgb);
|
||||
return rgb_;
|
||||
}
|
||||
|
||||
rgb_color &color::rgb()
|
||||
{
|
||||
assert_type(color_type::rgb);
|
||||
return rgb_;
|
||||
|
|
|
@ -92,6 +92,11 @@ bool style::operator==(const style &other) const
|
|||
return name() == other.name();
|
||||
}
|
||||
|
||||
bool style::operator!=(const style &other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
xlnt::alignment style::alignment() const
|
||||
{
|
||||
return d_->parent->alignments.at(d_->alignment_id.get());
|
||||
|
|
|
@ -221,7 +221,7 @@ std::pair<std::string, std::string> path::split_extension() const
|
|||
|
||||
// conversion
|
||||
|
||||
std::string path::string() const
|
||||
const std::string& path::string() const
|
||||
{
|
||||
return internal_;
|
||||
}
|
||||
|
@ -347,4 +347,9 @@ bool path::operator==(const path &other) const
|
|||
return internal_ == other.internal_;
|
||||
}
|
||||
|
||||
bool path::operator!=(const path &other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -27,9 +27,8 @@
|
|||
namespace xlnt {
|
||||
|
||||
variant::variant()
|
||||
{
|
||||
|
||||
}
|
||||
: type_(type::null)
|
||||
{}
|
||||
|
||||
variant::variant(const std::string &value)
|
||||
: type_(type::lpstr),
|
||||
|
|
|
@ -29,20 +29,20 @@
|
|||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/hyperlink.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/alignment.hpp>
|
||||
#include <xlnt/styles/border.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/styles/format.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
#include <xlnt/utils/timedelta.hpp>
|
||||
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
class cell_test_suite : public test_suite
|
||||
{
|
||||
|
@ -81,6 +81,7 @@ public:
|
|||
register_test(test_anchor);
|
||||
register_test(test_hyperlink);
|
||||
register_test(test_comment);
|
||||
register_test(test_copy_and_compare);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -253,11 +254,27 @@ private:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
// error string can't be empty
|
||||
xlnt_assert_throws(cell.error(""), xlnt::exception);
|
||||
// error string has to have a leading '#'
|
||||
xlnt_assert_throws(cell.error("not an error"), xlnt::exception);
|
||||
|
||||
for (auto error_code : xlnt::cell::error_codes())
|
||||
{
|
||||
// error type from the string format
|
||||
cell.value(error_code.first, true);
|
||||
xlnt_assert(cell.data_type() == xlnt::cell::type::error);
|
||||
std::string error;
|
||||
xlnt_assert_throws_nothing(error = cell.error());
|
||||
xlnt_assert_equals(error, error_code.first);
|
||||
// clearing the value clears the error state
|
||||
cell.clear_value();
|
||||
xlnt_assert_throws(cell.error(), xlnt::exception);
|
||||
// can explicitly set the error
|
||||
xlnt_assert_throws_nothing(cell.error(error_code.first));
|
||||
std::string error2;
|
||||
xlnt_assert_throws_nothing(error2 = cell.error());
|
||||
xlnt_assert_equals(error2, error_code.first);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -667,7 +684,7 @@ private:
|
|||
{
|
||||
xlnt::workbook wb;
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
cell.value(123);
|
||||
|
||||
xlnt_assert(!cell.has_hyperlink());
|
||||
xlnt_assert_throws(cell.hyperlink(), xlnt::invalid_attribute);
|
||||
xlnt_assert_throws(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
|
||||
|
@ -680,7 +697,8 @@ private:
|
|||
xlnt_assert_equals(cell.hyperlink().url(), link1);
|
||||
xlnt_assert_equals(cell.hyperlink().relationship().target().to_string(), link1);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), link1);
|
||||
// link with display
|
||||
cell.clear_value();
|
||||
// link with display
|
||||
const std::string link2("http://example2.com");
|
||||
const std::string display_txt("notaurl");
|
||||
cell.hyperlink(link2, display_txt);
|
||||
|
@ -689,6 +707,14 @@ private:
|
|||
xlnt_assert_equals(cell.hyperlink().url(), link2);
|
||||
xlnt_assert_equals(cell.hyperlink().relationship().target().to_string(), link2);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), display_txt);
|
||||
// value
|
||||
int cell_test_val = 123;
|
||||
cell.value(cell_test_val);
|
||||
std::string cell_value_str = std::to_string(cell_test_val);
|
||||
cell.hyperlink(link2, display_txt);
|
||||
xlnt_assert_equals(cell.value<int>(), 123);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), cell_value_str); // display text ignored
|
||||
cell.clear_value();
|
||||
// cell overload without display
|
||||
const std::string cell_target_str("A2");
|
||||
auto cell_target = wb.active_sheet().cell(cell_target_str);
|
||||
|
@ -698,12 +724,19 @@ private:
|
|||
xlnt_assert(!cell.hyperlink().external());
|
||||
xlnt_assert_equals(cell.hyperlink().target_range(), link3);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), link3);
|
||||
cell.clear_value();
|
||||
// cell overload with display
|
||||
cell.hyperlink(cell_target, display_txt);
|
||||
xlnt_assert(cell.has_hyperlink());
|
||||
xlnt_assert(!cell.hyperlink().external());
|
||||
xlnt_assert_equals(cell.hyperlink().target_range(), link3);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), display_txt);
|
||||
// value
|
||||
cell.value(cell_test_val);
|
||||
cell.hyperlink(cell_target, display_txt);
|
||||
xlnt_assert_equals(cell.value<int>(), 123);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), cell_value_str); // display text ignored
|
||||
cell.clear_value();
|
||||
// range overload without display
|
||||
const std::string range_target_str("A2:A5");
|
||||
xlnt::range range_target(wb.active_sheet(), xlnt::range_reference(range_target_str));
|
||||
|
@ -713,14 +746,19 @@ private:
|
|||
xlnt_assert(!cell.hyperlink().external());
|
||||
xlnt_assert_equals(cell.hyperlink().target_range(), link4);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), link4);
|
||||
cell.clear_value();
|
||||
// range overload with display
|
||||
cell.hyperlink(range_target, display_txt);
|
||||
xlnt_assert(cell.has_hyperlink());
|
||||
xlnt_assert(!cell.hyperlink().external());
|
||||
xlnt_assert_equals(cell.hyperlink().target_range(), link4);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), display_txt);
|
||||
// value not touched
|
||||
// value
|
||||
cell.value(cell_test_val);
|
||||
cell.hyperlink(range_target, display_txt);
|
||||
xlnt_assert_equals(cell.value<int>(), 123);
|
||||
xlnt_assert_equals(cell.hyperlink().display(), cell_value_str); // display text ignored
|
||||
cell.clear_value();
|
||||
}
|
||||
|
||||
void test_comment()
|
||||
|
@ -737,6 +775,31 @@ private:
|
|||
xlnt_assert(!cell.has_comment());
|
||||
xlnt_assert_throws(cell.comment(), xlnt::exception);
|
||||
}
|
||||
|
||||
void test_copy_and_compare()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell1 = ws.cell("A1");
|
||||
auto cell2 = ws.cell("A2");
|
||||
|
||||
xlnt_assert_equals(cell1, cell1);
|
||||
xlnt_assert_equals(cell2, cell2);
|
||||
xlnt_assert_differs(cell1, cell2);
|
||||
xlnt_assert_differs(cell2, cell1);
|
||||
// nullptr equality
|
||||
xlnt_assert(nullptr == cell1);
|
||||
xlnt_assert(cell1 == nullptr);
|
||||
cell1.value("test");
|
||||
xlnt_assert(!(nullptr == cell1));
|
||||
xlnt_assert(!(cell1 == nullptr));
|
||||
// copy
|
||||
xlnt::cell cell3(cell1);
|
||||
xlnt_assert_equals(cell1, cell3);
|
||||
// assign
|
||||
cell3 = cell2;
|
||||
xlnt_assert_equals(cell2, cell3);
|
||||
}
|
||||
};
|
||||
|
||||
static cell_test_suite x{};
|
|
@ -35,6 +35,7 @@ public:
|
|||
rich_text_test_suite()
|
||||
{
|
||||
register_test(test_operators);
|
||||
register_test(test_runs);
|
||||
}
|
||||
|
||||
void test_operators()
|
||||
|
@ -100,5 +101,19 @@ public:
|
|||
text_family_differs.add_run(run_family_differs);
|
||||
xlnt_assert_differs(text_formatted, text_family_differs);
|
||||
}
|
||||
|
||||
void test_runs()
|
||||
{
|
||||
xlnt::rich_text rt;
|
||||
xlnt_assert(rt.runs().empty());
|
||||
std::vector<xlnt::rich_text_run> test_runs{xlnt::rich_text_run{"1_abc_test_123"}, xlnt::rich_text_run{"2_abc_test_123"}, xlnt::rich_text_run{"3_abc_test_123"}};
|
||||
// just one
|
||||
rt.add_run(test_runs[0]);
|
||||
xlnt_assert_equals(1, rt.runs().size());
|
||||
xlnt_assert_equals(test_runs[0], rt.runs()[0]);
|
||||
// whole set
|
||||
rt.runs(test_runs);
|
||||
xlnt_assert_equals(test_runs, rt.runs());
|
||||
}
|
||||
};
|
||||
static rich_text_test_suite x{};
|
|
@ -38,37 +38,39 @@ public:
|
|||
|
||||
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" }
|
||||
};
|
||||
|
||||
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"}};
|
||||
|
||||
for (auto pair : known_colors)
|
||||
{
|
||||
xlnt_assert_equals(pair.first.rgb().hex_string(), pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_non_rgb_colors()
|
||||
{
|
||||
xlnt::color indexed = xlnt::indexed_color(1);
|
||||
xlnt_assert(!indexed.auto_());
|
||||
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);
|
||||
|
||||
xlnt::color theme = xlnt::theme_color(3);
|
||||
xlnt_assert(!theme.auto_());
|
||||
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);
|
||||
}
|
||||
|
|
64
tests/styles/conditional_format_test_suite.cpp
Normal file
64
tests/styles/conditional_format_test_suite.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
// Copyright (c) 2014-2018 Thomas Fussell
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <xlnt/styles/conditional_format.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class conditional_format_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
conditional_format_test_suite()
|
||||
{
|
||||
register_test(test_all);
|
||||
}
|
||||
|
||||
void test_all()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto format = ws.conditional_format(xlnt::range_reference("A1:A10"), xlnt::condition::text_contains("test"));
|
||||
xlnt_assert(!format.has_border());
|
||||
xlnt_assert(!format.has_fill());
|
||||
xlnt_assert(!format.has_font());
|
||||
// set border
|
||||
auto border = xlnt::border().diagonal(xlnt::diagonal_direction::both);
|
||||
format.border(border);
|
||||
xlnt_assert(format.has_border());
|
||||
xlnt_assert_equals(format.border(), border);
|
||||
// set fill
|
||||
auto fill = xlnt::fill(xlnt::gradient_fill().type(xlnt::gradient_fill_type::path));
|
||||
format.fill(fill);
|
||||
xlnt_assert(format.has_fill());
|
||||
xlnt_assert_equals(format.fill(), fill);
|
||||
// set font
|
||||
auto font = xlnt::font().color(xlnt::color::darkblue());
|
||||
format.font(font);
|
||||
xlnt_assert(format.has_font());
|
||||
xlnt_assert_equals(format.font(), font);
|
||||
// copy ctor
|
||||
auto format_copy(format);
|
||||
xlnt_assert_equals(format, format_copy);
|
||||
}
|
||||
};
|
||||
static conditional_format_test_suite x;
|
55
tests/styles/protection_test_suite.cpp
Normal file
55
tests/styles/protection_test_suite.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2014-2018 Thomas Fussell
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class protection_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
protection_test_suite()
|
||||
{
|
||||
register_test(test_all);
|
||||
}
|
||||
|
||||
void test_all()
|
||||
{
|
||||
auto prot = xlnt::protection::unlocked_and_visible();
|
||||
xlnt_assert(!prot.hidden());
|
||||
xlnt_assert(!prot.locked());
|
||||
|
||||
prot = xlnt::protection::locked_and_visible();
|
||||
xlnt_assert(!prot.hidden());
|
||||
xlnt_assert(prot.locked());
|
||||
|
||||
prot = xlnt::protection::unlocked_and_hidden();
|
||||
xlnt_assert(prot.hidden());
|
||||
xlnt_assert(!prot.locked());
|
||||
|
||||
prot = xlnt::protection::locked_and_hidden();
|
||||
xlnt_assert(prot.hidden());
|
||||
xlnt_assert(prot.locked());
|
||||
}
|
||||
};
|
||||
static protection_test_suite x;
|
66
tests/styles/style_test_suite.cpp
Normal file
66
tests/styles/style_test_suite.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Copyright (c) 2014-2018 Thomas Fussell
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
class style_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
style_test_suite()
|
||||
{
|
||||
register_test(test_all);
|
||||
}
|
||||
|
||||
void test_all()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto test_style = wb.create_style("test_style");
|
||||
test_style.number_format(xlnt::number_format::date_ddmmyyyy());
|
||||
|
||||
auto copy_style(test_style);
|
||||
xlnt_assert_equals(test_style, copy_style);
|
||||
|
||||
// number format
|
||||
xlnt_assert_equals(copy_style.name(), "test_style");
|
||||
xlnt_assert_equals(copy_style.number_format(), xlnt::number_format::date_ddmmyyyy());
|
||||
//xlnt_assert(!copy_style.number_format_applied()); // this doesn't seem to have sensible behaviour?
|
||||
copy_style.number_format(xlnt::number_format::date_datetime(), true); // true applied param
|
||||
xlnt_assert_equals(copy_style.number_format(), xlnt::number_format::date_datetime());
|
||||
xlnt_assert(copy_style.number_format_applied());
|
||||
copy_style.number_format(xlnt::number_format::date_dmminus(), false); // false applied param
|
||||
xlnt_assert_equals(copy_style.number_format(), xlnt::number_format::date_dmminus());
|
||||
xlnt_assert(!copy_style.number_format_applied());
|
||||
|
||||
xlnt_assert(!copy_style.pivot_button());
|
||||
copy_style.pivot_button(true);
|
||||
xlnt_assert(copy_style.pivot_button());
|
||||
|
||||
xlnt_assert(!copy_style.quote_prefix());
|
||||
copy_style.quote_prefix(true);
|
||||
xlnt_assert(copy_style.quote_prefix());
|
||||
}
|
||||
};
|
||||
static style_test_suite x;
|
|
@ -26,6 +26,7 @@
|
|||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/utils/path.hpp>
|
||||
|
||||
class path_test_suite : public test_suite
|
||||
{
|
||||
|
|
69
tests/utils/variant_tests.cpp
Normal file
69
tests/utils/variant_tests.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Copyright (c) 2014-2018 Thomas Fussell
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <xlnt/utils/variant.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
class variant_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
variant_test_suite()
|
||||
: test_suite()
|
||||
{
|
||||
register_test(test_null);
|
||||
register_test(test_int32);
|
||||
register_test(test_string);
|
||||
}
|
||||
|
||||
void test_null()
|
||||
{
|
||||
xlnt::variant var_null;
|
||||
xlnt_assert_equals(var_null.value_type(), xlnt::variant::type::null);
|
||||
xlnt_assert(var_null.is(xlnt::variant::type::null));
|
||||
}
|
||||
|
||||
void test_int32()
|
||||
{
|
||||
xlnt::variant var_int(std::int32_t(10));
|
||||
xlnt_assert_equals(var_int.value_type(), xlnt::variant::type::i4);
|
||||
xlnt_assert(var_int.is(xlnt::variant::type::i4));
|
||||
xlnt_assert_throws_nothing(var_int.get<std::int32_t>());
|
||||
xlnt_assert_equals(10, var_int.get<std::int32_t>());
|
||||
}
|
||||
|
||||
void test_string()
|
||||
{
|
||||
xlnt::variant var_str1("test1");
|
||||
xlnt_assert_equals(var_str1.value_type(), xlnt::variant::type::lpstr);
|
||||
xlnt_assert(var_str1.is(xlnt::variant::type::lpstr));
|
||||
xlnt_assert_throws_nothing(var_str1.get<std::string>());
|
||||
xlnt_assert_equals("test1", var_str1.get<std::string>());
|
||||
|
||||
xlnt::variant var_str2(std::string("test2"));
|
||||
xlnt_assert_equals(var_str2.value_type(), xlnt::variant::type::lpstr);
|
||||
xlnt_assert(var_str2.is(xlnt::variant::type::lpstr));
|
||||
xlnt_assert_throws_nothing(var_str2.get<std::string>());
|
||||
xlnt_assert_equals("test2", var_str2.get<std::string>());
|
||||
}
|
||||
};
|
||||
static variant_test_suite x;
|
|
@ -37,10 +37,40 @@ class range_test_suite : public test_suite
|
|||
public:
|
||||
range_test_suite()
|
||||
{
|
||||
register_test(test_construction);
|
||||
register_test(test_batch_formatting);
|
||||
register_test(test_clear_cells);
|
||||
}
|
||||
|
||||
void test_construction()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
xlnt::range range_1(ws, xlnt::range_reference("A1:D10"));
|
||||
xlnt_assert_equals(range_1.target_worksheet(), ws);
|
||||
xlnt_assert_equals(1, range_1.front()[0].row()); // NOTE: querying row/column here desperately needs some shortcuts
|
||||
xlnt_assert_equals(xlnt::column_t("D"), range_1.front().back().column());
|
||||
xlnt_assert_equals(10, range_1.back()[0].row());
|
||||
xlnt_assert_equals(xlnt::column_t("D"), range_1.back().back().column());
|
||||
// assert default parameters in ctor
|
||||
xlnt::range range_2(ws, xlnt::range_reference("A1:D10"), xlnt::major_order::row, false);
|
||||
xlnt_assert_equals(range_1, range_2);
|
||||
// assert copy
|
||||
xlnt::range range_3(range_2);
|
||||
xlnt_assert_equals(range_1, range_3);
|
||||
|
||||
// column order
|
||||
xlnt::range range_4(ws, xlnt::range_reference("A1:D10"), xlnt::major_order::column);
|
||||
xlnt_assert_equals(xlnt::column_t("A"), range_4.front()[0].column()); // NOTE: querying row/column here desperately needs some shortcuts
|
||||
xlnt_assert_equals(10, range_4.front().back().row());
|
||||
xlnt_assert_equals(xlnt::column_t("D"), range_4.back()[0].column());
|
||||
xlnt_assert_equals(10, range_4.back().back().row());
|
||||
// assignment
|
||||
range_3 = range_4;
|
||||
xlnt_assert_equals(range_3, range_4);
|
||||
}
|
||||
|
||||
void test_batch_formatting()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
|
Loading…
Reference in New Issue
Block a user