add meta tests (tests that test test functions), optimize sha calls, test incorrect passwords

This commit is contained in:
Thomas Fussell 2017-04-18 18:30:54 -04:00
parent b3cc07e5db
commit adda7b877a
22 changed files with 906 additions and 793 deletions

View File

@ -132,6 +132,7 @@ target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR}/../third-party/libstu
if(MSVC) if(MSVC)
set_target_properties(xlnt PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\" /wd\"4068\" /MP") set_target_properties(xlnt PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\" /wd\"4068\" /MP")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/miniz.cpp PROPERTIES COMPILE_FLAGS "/wd\"4244\" /wd\"4334\" /wd\"4127\"") set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/miniz.cpp PROPERTIES COMPILE_FLAGS "/wd\"4244\" /wd\"4334\" /wd\"4127\"")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/crypto/aes.cpp PROPERTIES COMPILE_FLAGS "/wd\"4996\"")
endif() endif()
source_group(xlnt FILES ${ROOT_HEADERS}) source_group(xlnt FILES ${ROOT_HEADERS})

View File

@ -39,22 +39,22 @@ extern void sha512_hash(const uint8_t *message, size_t len, uint64_t hash[8]);
namespace { namespace {
#ifdef _MSC_VER #ifdef _MSC_VER
inline std::uint32_t byteswap(std::uint32_t i) inline std::uint32_t byteswap32(std::uint32_t i)
{ {
return _byteswap_ulong(i); return _byteswap_ulong(i);
} }
inline std::uint64_t byteswap(std::uint64_t i) inline std::uint64_t byteswap64(std::uint64_t i)
{ {
return _byteswap_uint64(i); return _byteswap_uint64(i);
} }
#else #else
inline std::uint32_t byteswap(std::uint32_t i) inline std::uint32_t byteswap32(std::uint32_t i)
{ {
return __builtin_bswap32(i); return __builtin_bswap32(i);
} }
inline std::uint64_t byteswap(std::uint64_t i) inline std::uint64_t byteswap64(std::uint64_t i)
{ {
return __builtin_bswap64(i); return __builtin_bswap64(i);
} }
@ -64,46 +64,40 @@ inline std::uint64_t byteswap(std::uint64_t i)
namespace xlnt { namespace xlnt {
namespace detail { namespace detail {
std::vector<std::uint8_t> sha1(const std::vector<std::uint8_t> &data) void sha1(const std::vector<std::uint8_t> &input, std::vector<std::uint8_t> &output)
{ {
std::array<std::uint32_t, 5> hash; static const auto sha1_bytes = 20;
sha1_hash(data.data(), data.size(), hash.data());
std::vector<std::uint8_t> result(20, 0); output.resize(sha1_bytes);
auto result_iterator = result.begin(); auto output_pointer_u32 = reinterpret_cast<std::uint32_t *>(output.data());
for (auto i : hash) sha1_hash(input.data(), input.size(), output_pointer_u32);
{
auto swapped = byteswap(i); // change hash output from big-endian to little-endian
std::copy( // TODO (harder): try to change the algorithm itself so this isn't necessary
reinterpret_cast<std::uint8_t *>(&swapped), // TODO (easier): check platform endianness before doing this
reinterpret_cast<std::uint8_t *>(&swapped + 1), std::transform(output_pointer_u32,
&*result_iterator); output_pointer_u32 + sha1_bytes / sizeof(std::uint32_t),
result_iterator += 4; output_pointer_u32,
byteswap32);
} }
return result; void sha512(const std::vector<std::uint8_t> &input, std::vector<std::uint8_t> &output)
}
std::vector<std::uint8_t> sha512(const std::vector<std::uint8_t> &data)
{ {
std::array<std::uint64_t, 8> hash; static const auto sha512_bytes = 64;
sha512_hash(data.data(), data.size(), hash.data());
std::vector<std::uint8_t> result(64, 0); output.resize(sha512_bytes);
auto result_iterator = result.begin(); auto output_pointer_u64 = reinterpret_cast<std::uint64_t *>(output.data());
for (auto i : hash) sha512_hash(input.data(), input.size(), output_pointer_u64);
{
auto swapped = byteswap(i);
std::copy(
reinterpret_cast<std::uint8_t *>(&swapped),
reinterpret_cast<std::uint8_t *>(&swapped + 1),
&*result_iterator);
result_iterator += 8;
}
return result; // change hash output from big-endian to little-endian
// TODO (harder): try to change the algorithm itself so this isn't necessary
// TODO (easier): check platform endianness before doing this
std::transform(output_pointer_u64,
output_pointer_u64 + sha512_bytes / sizeof(std::uint64_t),
output_pointer_u64,
byteswap64);
} }
} // namespace detail } // namespace detail

View File

@ -28,8 +28,8 @@
namespace xlnt { namespace xlnt {
namespace detail { namespace detail {
std::vector<std::uint8_t> sha1(const std::vector<std::uint8_t> &data); void sha1(const std::vector<std::uint8_t> &input, std::vector<std::uint8_t> &output);
std::vector<std::uint8_t> sha512(const std::vector<std::uint8_t> &data); void sha512(const std::vector<std::uint8_t> &data, std::vector<std::uint8_t> &output);
}; // namespace detail }; // namespace detail
}; // namespace xlnt }; // namespace xlnt

View File

@ -137,18 +137,28 @@ auto read_int(std::size_t &index, const std::vector<std::uint8_t> &raw_data)
return result; return result;
} }
std::vector<std::uint8_t> hash(hash_algorithm algorithm, const std::vector<std::uint8_t> &input) void hash(hash_algorithm algorithm, const std::vector<std::uint8_t> &input, std::vector<std::uint8_t> &output)
{ {
if (algorithm == hash_algorithm::sha512) if (algorithm == hash_algorithm::sha512)
{ {
return xlnt::detail::sha512(input); xlnt::detail::sha512(input, output);
} }
else if (algorithm == hash_algorithm::sha1) else if (algorithm == hash_algorithm::sha1)
{ {
return xlnt::detail::sha1(input); xlnt::detail::sha1(input, output);
}
else
{
throw xlnt::exception("unsupported hash algorithm");
}
} }
throw xlnt::exception("unsupported hash algorithm"); std::vector<std::uint8_t> hash(hash_algorithm algorithm, const std::vector<std::uint8_t> &input)
{
auto output = std::vector<std::uint8_t>();
hash(algorithm, input, output);
return output;
} }
std::vector<std::uint8_t> file(POLE::Storage &storage, const std::string &name) std::vector<std::uint8_t> file(POLE::Storage &storage, const std::string &name)
@ -242,7 +252,7 @@ std::vector<std::uint8_t> decrypt_xlsx_standard(
salt_plus_password.insert(salt_plus_password.end(), reinterpret_cast<char *>(&c), salt_plus_password.insert(salt_plus_password.end(), reinterpret_cast<char *>(&c),
reinterpret_cast<char *>(&c) + sizeof(std::uint16_t)); reinterpret_cast<char *>(&c) + sizeof(std::uint16_t));
}); });
std::vector<std::uint8_t> h_0 = hash(info.hash, salt_plus_password); auto h_0 = hash(info.hash, salt_plus_password);
// H_n = H(iterator + H_n-1) // H_n = H(iterator + H_n-1)
std::vector<std::uint8_t> iterator_plus_h_n(4, 0); std::vector<std::uint8_t> iterator_plus_h_n(4, 0);
@ -251,7 +261,7 @@ std::vector<std::uint8_t> decrypt_xlsx_standard(
std::vector<std::uint8_t> h_n; std::vector<std::uint8_t> h_n;
for (iterator = 0; iterator < info.spin_count; ++iterator) for (iterator = 0; iterator < info.spin_count; ++iterator)
{ {
h_n = hash(info.hash, iterator_plus_h_n); hash(info.hash, iterator_plus_h_n, h_n);
std::copy(h_n.begin(), h_n.end(), iterator_plus_h_n.begin() + 4); std::copy(h_n.begin(), h_n.end(), iterator_plus_h_n.begin() + 4);
} }
@ -476,10 +486,9 @@ std::vector<std::uint8_t> decrypt_xlsx_agile(
iterator_plus_h_n.insert(iterator_plus_h_n.end(), h_0.begin(), h_0.end()); iterator_plus_h_n.insert(iterator_plus_h_n.end(), h_0.begin(), h_0.end());
std::uint32_t &iterator = *reinterpret_cast<std::uint32_t *>(iterator_plus_h_n.data()); std::uint32_t &iterator = *reinterpret_cast<std::uint32_t *>(iterator_plus_h_n.data());
std::vector<std::uint8_t> h_n; std::vector<std::uint8_t> h_n;
for (iterator = 0; iterator < result.key_encryptor.spin_count; ++iterator) for (iterator = 0; iterator < result.key_encryptor.spin_count; ++iterator)
{ {
h_n = hash(result.key_encryptor.hash, iterator_plus_h_n); hash(result.key_encryptor.hash, iterator_plus_h_n, h_n);
std::copy(h_n.begin(), h_n.end(), iterator_plus_h_n.begin() + 4); std::copy(h_n.begin(), h_n.end(), iterator_plus_h_n.begin() + 4);
} }

View File

@ -76,43 +76,43 @@ private:
auto cell = ws.cell("A1"); auto cell = ws.cell("A1");
cell.value("4.2", true); cell.value("4.2", true);
assert(cell.value<long double>() == 4.2L); xlnt_assert(cell.value<long double>() == 4.2L);
cell.value("-42.000", true); cell.value("-42.000", true);
assert(cell.value<int>() == -42); xlnt_assert(cell.value<int>() == -42);
cell.value("0", true); cell.value("0", true);
assert(cell.value<int>() == 0); xlnt_assert(cell.value<int>() == 0);
cell.value("0.9999", true); cell.value("0.9999", true);
assert(cell.value<long double>() == 0.9999L); xlnt_assert(cell.value<long double>() == 0.9999L);
cell.value("99E-02", true); cell.value("99E-02", true);
assert(cell.value<long double>() == 0.99L); xlnt_assert(cell.value<long double>() == 0.99L);
cell.value("4", true); cell.value("4", true);
assert(cell.value<int>() == 4); xlnt_assert(cell.value<int>() == 4);
cell.value("-1E3", true); cell.value("-1E3", true);
assert(cell.value<int>() == -1000); xlnt_assert(cell.value<int>() == -1000);
cell.value("2e+2", true); cell.value("2e+2", true);
assert(cell.value<int>() == 200); xlnt_assert(cell.value<int>() == 200);
cell.value("3.1%", true); cell.value("3.1%", true);
assert(cell.value<long double>() == 0.031L); xlnt_assert(cell.value<long double>() == 0.031L);
cell.value("03:40:16", true); cell.value("03:40:16", true);
assert(cell.value<xlnt::time>() == xlnt::time(3, 40, 16)); xlnt_assert(cell.value<xlnt::time>() == xlnt::time(3, 40, 16));
cell.value("03:", true); cell.value("03:", true);
assert_equals(cell.value<std::string>(), "03:"); xlnt_assert_equals(cell.value<std::string>(), "03:");
cell.value("03:40", true); cell.value("03:40", true);
assert(cell.value<xlnt::time>() == xlnt::time(3, 40)); xlnt_assert(cell.value<xlnt::time>() == xlnt::time(3, 40));
cell.value("30:33.865633336", true); cell.value("30:33.865633336", true);
assert(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633)); xlnt_assert(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
} }
void test_constructor() void test_constructor()
@ -121,11 +121,11 @@ private:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference("A", 1)); auto cell = ws.cell(xlnt::cell_reference("A", 1));
assert(cell.data_type() == xlnt::cell::type::null); xlnt_assert(cell.data_type() == xlnt::cell::type::null);
assert(cell.column() == "A"); xlnt_assert(cell.column() == "A");
assert(cell.row() == 1); xlnt_assert(cell.row() == 1);
assert(cell.reference() == "A1"); xlnt_assert(cell.reference() == "A1");
assert(!cell.has_value()); xlnt_assert(!cell.has_value());
} }
void test_null() void test_null()
@ -148,9 +148,9 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.data_type(datatype); cell.data_type(datatype);
assert(cell.data_type() == datatype); xlnt_assert(cell.data_type() == datatype);
cell.clear_value(); cell.clear_value();
assert(cell.data_type() == xlnt::cell::type::null); xlnt_assert(cell.data_type() == xlnt::cell::type::null);
} }
} }
@ -161,13 +161,13 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.value("hello"); cell.value("hello");
assert(cell.data_type() == xlnt::cell::type::string); xlnt_assert(cell.data_type() == xlnt::cell::type::string);
cell.value("."); cell.value(".");
assert(cell.data_type() == xlnt::cell::type::string); xlnt_assert(cell.data_type() == xlnt::cell::type::string);
cell.value("0800"); cell.value("0800");
assert(cell.data_type() == xlnt::cell::type::string); xlnt_assert(cell.data_type() == xlnt::cell::type::string);
} }
void test_formula1() void test_formula1()
@ -177,7 +177,7 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.value("=42", true); cell.value("=42", true);
assert(cell.data_type() == xlnt::cell::type::formula); xlnt_assert(cell.data_type() == xlnt::cell::type::formula);
} }
void test_formula2() void test_formula2()
@ -187,7 +187,7 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.value("=if(A1<4;-1;1)", true); cell.value("=if(A1<4;-1;1)", true);
assert(cell.data_type() == xlnt::cell::type::formula); xlnt_assert(cell.data_type() == xlnt::cell::type::formula);
} }
void test_formula3() void test_formula3()
@ -196,14 +196,14 @@ private:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
assert(!cell.has_formula()); xlnt_assert(!cell.has_formula());
assert_throws_nothing(cell.formula("")); xlnt_assert_throws_nothing(cell.formula(""));
assert(!cell.has_formula()); xlnt_assert(!cell.has_formula());
cell.formula("=42"); cell.formula("=42");
assert(cell.has_formula()); xlnt_assert(cell.has_formula());
assert_equals(cell.formula(), "42"); xlnt_assert_equals(cell.formula(), "42");
cell.clear_formula(); cell.clear_formula();
assert(!cell.has_formula()); xlnt_assert(!cell.has_formula());
} }
@ -214,9 +214,9 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.value("="); cell.value("=");
assert(cell.data_type() == xlnt::cell::type::string); xlnt_assert(cell.data_type() == xlnt::cell::type::string);
assert(cell.value<std::string>() == "="); xlnt_assert(cell.value<std::string>() == "=");
assert(!cell.has_formula()); xlnt_assert(!cell.has_formula());
} }
void test_boolean() void test_boolean()
@ -228,7 +228,7 @@ private:
for (auto value : { true, false }) for (auto value : { true, false })
{ {
cell.value(value); cell.value(value);
assert(cell.data_type() == xlnt::cell::type::boolean); xlnt_assert(cell.data_type() == xlnt::cell::type::boolean);
} }
} }
@ -241,7 +241,7 @@ private:
for (auto error_code : xlnt::cell::error_codes()) for (auto error_code : xlnt::cell::error_codes())
{ {
cell.value(error_code.first, true); cell.value(error_code.first, true);
assert(cell.data_type() == xlnt::cell::type::error); xlnt_assert(cell.data_type() == xlnt::cell::type::error);
} }
} }
@ -253,10 +253,10 @@ private:
cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41)); cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
assert(cell.data_type() == xlnt::cell::type::numeric); xlnt_assert(cell.data_type() == xlnt::cell::type::numeric);
assert(cell.value<long double>() == 40372.27616898148L); xlnt_assert(cell.value<long double>() == 40372.27616898148L);
assert(cell.is_date()); xlnt_assert(cell.is_date());
assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss"); xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
} }
void test_insert_date() void test_insert_date()
@ -266,10 +266,10 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.value(xlnt::date(2010, 7, 13)); cell.value(xlnt::date(2010, 7, 13));
assert(cell.data_type() == xlnt::cell::type::numeric); xlnt_assert(cell.data_type() == xlnt::cell::type::numeric);
assert(cell.value<long double>() == 40372.L); xlnt_assert(cell.value<long double>() == 40372.L);
assert(cell.is_date()); xlnt_assert(cell.is_date());
assert(cell.number_format().format_string() == "yyyy-mm-dd"); xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd");
} }
void test_insert_time() void test_insert_time()
@ -279,10 +279,10 @@ private:
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.value(xlnt::time(1, 3)); cell.value(xlnt::time(1, 3));
assert(cell.data_type() == xlnt::cell::type::numeric); xlnt_assert(cell.data_type() == xlnt::cell::type::numeric);
assert(cell.value<long double>() == 0.04375L); xlnt_assert(cell.value<long double>() == 0.04375L);
assert(cell.is_date()); xlnt_assert(cell.is_date());
assert(cell.number_format().format_string() == "h:mm:ss"); xlnt_assert(cell.number_format().format_string() == "h:mm:ss");
} }
void test_cell_formatted_as_date1() void test_cell_formatted_as_date1()
@ -293,8 +293,8 @@ private:
cell.value(xlnt::datetime::today()); cell.value(xlnt::datetime::today());
cell.clear_value(); cell.clear_value();
assert(!cell.is_date()); // disagree with openpyxl xlnt_assert(!cell.is_date()); // disagree with openpyxl
assert(!cell.has_value()); xlnt_assert(!cell.has_value());
} }
void test_cell_formatted_as_date2() void test_cell_formatted_as_date2()
@ -305,8 +305,8 @@ private:
cell.value(xlnt::datetime::today()); cell.value(xlnt::datetime::today());
cell.value("testme"); cell.value("testme");
assert(!cell.is_date()); xlnt_assert(!cell.is_date());
assert(cell.value<std::string>() == "testme"); xlnt_assert(cell.value<std::string>() == "testme");
} }
void test_cell_formatted_as_date3() void test_cell_formatted_as_date3()
@ -317,8 +317,8 @@ private:
cell.value(xlnt::datetime::today()); cell.value(xlnt::datetime::today());
cell.value(true); cell.value(true);
assert(!cell.is_date()); xlnt_assert(!cell.is_date());
assert(cell.value<bool>() == true); xlnt_assert(cell.value<bool>() == true);
} }
void test_illegal_characters() void test_illegal_characters()
@ -334,7 +334,7 @@ private:
for (auto i : illegal_chrs) for (auto i : illegal_chrs)
{ {
std::string str(1, i); std::string str(1, i);
assert_throws(cell.value(str), xlnt::illegal_character); xlnt_assert_throws(cell.value(str), xlnt::illegal_character);
} }
cell.value(std::string(1, 33)); cell.value(std::string(1, 33));
@ -354,10 +354,10 @@ private:
cell.value(xlnt::timedelta(1, 3, 0, 0, 0)); cell.value(xlnt::timedelta(1, 3, 0, 0, 0));
assert(cell.value<long double>() == 1.125); xlnt_assert(cell.value<long double>() == 1.125);
assert(cell.data_type() == xlnt::cell::type::numeric); xlnt_assert(cell.data_type() == xlnt::cell::type::numeric);
assert(!cell.is_date()); xlnt_assert(!cell.is_date());
assert(cell.number_format().format_string() == "[hh]:mm:ss"); xlnt_assert(cell.number_format().format_string() == "[hh]:mm:ss");
} }
void test_cell_offset() void test_cell_offset()
@ -365,7 +365,7 @@ private:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
assert(cell.offset(1, 2).reference() == "B3"); xlnt_assert(cell.offset(1, 2).reference() == "B3");
} }
void test_font() void test_font()
@ -378,9 +378,9 @@ private:
cell.font(font); cell.font(font);
assert(cell.has_format()); xlnt_assert(cell.has_format());
assert(cell.format().font_applied()); xlnt_assert(cell.format().font_applied());
assert_equals(cell.font(), font); xlnt_assert_equals(cell.font(), font);
} }
void test_fill() void test_fill()
@ -394,9 +394,9 @@ private:
.foreground(xlnt::color::red())); .foreground(xlnt::color::red()));
cell.fill(fill); cell.fill(fill);
assert(cell.has_format()); xlnt_assert(cell.has_format());
assert(cell.format().fill_applied()); xlnt_assert(cell.format().fill_applied());
assert_equals(cell.fill(), fill); xlnt_assert_equals(cell.fill(), fill);
} }
void test_border() void test_border()
@ -408,9 +408,9 @@ private:
xlnt::border border; xlnt::border border;
cell.border(border); cell.border(border);
assert(cell.has_format()); xlnt_assert(cell.has_format());
assert(cell.format().border_applied()); xlnt_assert(cell.format().border_applied());
assert_equals(cell.border(), border); xlnt_assert_equals(cell.border(), border);
} }
void test_number_format() void test_number_format()
@ -422,9 +422,9 @@ private:
xlnt::number_format format("dd--hh--mm"); xlnt::number_format format("dd--hh--mm");
cell.number_format(format); cell.number_format(format);
assert(cell.has_format()); xlnt_assert(cell.has_format());
assert(cell.format().number_format_applied()); xlnt_assert(cell.format().number_format_applied());
assert_equals(cell.number_format().format_string(), "dd--hh--mm"); xlnt_assert_equals(cell.number_format().format_string(), "dd--hh--mm");
} }
void test_alignment() void test_alignment()
@ -438,9 +438,9 @@ private:
cell.alignment(align); cell.alignment(align);
assert(cell.has_format()); xlnt_assert(cell.has_format());
assert(cell.format().alignment_applied()); xlnt_assert(cell.format().alignment_applied());
assert_equals(cell.alignment(), align); xlnt_assert_equals(cell.alignment(), align);
} }
void test_protection() void test_protection()
@ -449,18 +449,18 @@ private:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell("A1"); auto cell = ws.cell("A1");
assert(!cell.has_format()); xlnt_assert(!cell.has_format());
auto protection = xlnt::protection().locked(false).hidden(true); auto protection = xlnt::protection().locked(false).hidden(true);
cell.protection(protection); cell.protection(protection);
assert(cell.has_format()); xlnt_assert(cell.has_format());
assert(cell.format().protection_applied()); xlnt_assert(cell.format().protection_applied());
assert_equals(cell.protection(), protection); xlnt_assert_equals(cell.protection(), protection);
assert(cell.has_format()); xlnt_assert(cell.has_format());
cell.clear_format(); cell.clear_format();
assert(!cell.has_format()); xlnt_assert(!cell.has_format());
} }
void test_style() void test_style()
@ -469,36 +469,36 @@ private:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell("A1"); auto cell = ws.cell("A1");
assert(!cell.has_style()); xlnt_assert(!cell.has_style());
auto test_style = wb.create_style("test_style"); auto test_style = wb.create_style("test_style");
test_style.number_format(xlnt::number_format::date_ddmmyyyy(), true); test_style.number_format(xlnt::number_format::date_ddmmyyyy(), true);
cell.style(test_style); cell.style(test_style);
assert(cell.has_style()); xlnt_assert(cell.has_style());
assert_equals(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy()); xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy());
assert_equals(cell.style(), test_style); xlnt_assert_equals(cell.style(), test_style);
auto other_style = wb.create_style("other_style"); auto other_style = wb.create_style("other_style");
other_style.number_format(xlnt::number_format::date_time2(), true); other_style.number_format(xlnt::number_format::date_time2(), true);
cell.style("other_style"); cell.style("other_style");
assert_equals(cell.style().number_format(), xlnt::number_format::date_time2()); xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::date_time2());
assert_equals(cell.style(), other_style); xlnt_assert_equals(cell.style(), other_style);
auto last_style = wb.create_style("last_style"); auto last_style = wb.create_style("last_style");
last_style.number_format(xlnt::number_format::percentage(), true); last_style.number_format(xlnt::number_format::percentage(), true);
cell.style(last_style); cell.style(last_style);
assert_equals(cell.style().number_format(), xlnt::number_format::percentage()); xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::percentage());
assert_equals(cell.style(), last_style); xlnt_assert_equals(cell.style(), last_style);
assert_throws(cell.style("doesn't exist"), xlnt::key_not_found); xlnt_assert_throws(cell.style("doesn't exist"), xlnt::key_not_found);
cell.clear_style(); cell.clear_style();
assert(!cell.has_style()); xlnt_assert(!cell.has_style());
assert_throws(cell.style(), xlnt::invalid_attribute); xlnt_assert_throws(cell.style(), xlnt::invalid_attribute);
} }
void test_print() void test_print()
@ -514,8 +514,8 @@ private:
auto stream_string = ss.str(); auto stream_string = ss.str();
assert_equals(cell.to_string(), stream_string); xlnt_assert_equals(cell.to_string(), stream_string);
assert_equals(stream_string, ""); xlnt_assert_equals(stream_string, "");
} }
{ {
@ -528,8 +528,8 @@ private:
auto stream_string = ss.str(); auto stream_string = ss.str();
assert_equals(cell.to_string(), stream_string); xlnt_assert_equals(cell.to_string(), stream_string);
assert_equals(stream_string, "FALSE"); xlnt_assert_equals(stream_string, "FALSE");
} }
{ {
@ -542,8 +542,8 @@ private:
auto stream_string = ss.str(); auto stream_string = ss.str();
assert_equals(cell.to_string(), stream_string); xlnt_assert_equals(cell.to_string(), stream_string);
assert_equals(stream_string, "TRUE"); xlnt_assert_equals(stream_string, "TRUE");
} }
{ {
@ -556,8 +556,8 @@ private:
auto stream_string = ss.str(); auto stream_string = ss.str();
assert_equals(cell.to_string(), stream_string); xlnt_assert_equals(cell.to_string(), stream_string);
assert_equals(stream_string, "1.234"); xlnt_assert_equals(stream_string, "1.234");
} }
{ {
@ -570,8 +570,8 @@ private:
auto stream_string = ss.str(); auto stream_string = ss.str();
assert_equals(cell.to_string(), stream_string); xlnt_assert_equals(cell.to_string(), stream_string);
assert_equals(stream_string, "#REF"); xlnt_assert_equals(stream_string, "#REF");
} }
{ {
@ -584,8 +584,8 @@ private:
auto stream_string = ss.str(); auto stream_string = ss.str();
assert_equals(cell.to_string(), stream_string); xlnt_assert_equals(cell.to_string(), stream_string);
assert_equals(stream_string, "test"); xlnt_assert_equals(stream_string, "test");
} }
} }
@ -596,49 +596,49 @@ private:
auto cell = ws.cell("A1"); auto cell = ws.cell("A1");
cell.value(static_cast<int>(4)); cell.value(static_cast<int>(4));
assert_equals(cell.value<int>(), 4); xlnt_assert_equals(cell.value<int>(), 4);
cell.value(static_cast<unsigned int>(3)); cell.value(static_cast<unsigned int>(3));
assert_equals(cell.value<unsigned>(), 3); xlnt_assert_equals(cell.value<unsigned>(), 3);
cell.value(static_cast<unsigned long long>(4)); cell.value(static_cast<unsigned long long>(4));
assert_equals(cell.value<unsigned long long>(), 4); xlnt_assert_equals(cell.value<unsigned long long>(), 4);
cell.value(static_cast<long long int>(3)); cell.value(static_cast<long long int>(3));
assert_equals(cell.value<long long int>(), 3); xlnt_assert_equals(cell.value<long long int>(), 3);
cell.value(static_cast<float>(3.14)); cell.value(static_cast<float>(3.14));
assert_delta(cell.value<float>(), 3.14, 0.001); xlnt_assert_delta(cell.value<float>(), 3.14, 0.001);
cell.value(static_cast<double>(4.1415)); cell.value(static_cast<double>(4.1415));
assert_equals(cell.value<double>(), 4.1415); xlnt_assert_equals(cell.value<double>(), 4.1415);
cell.value(static_cast<long double>(3.141592)); cell.value(static_cast<long double>(3.141592));
assert_equals(cell.value<long double>(), 3.141592); xlnt_assert_equals(cell.value<long double>(), 3.141592);
auto cell2 = ws.cell("A2"); auto cell2 = ws.cell("A2");
cell2.value(std::string(100'000, 'a')); cell2.value(std::string(100'000, 'a'));
cell.value(cell2); cell.value(cell2);
assert_equals(cell.value<std::string>(), std::string(32'767, 'a')); xlnt_assert_equals(cell.value<std::string>(), std::string(32'767, 'a'));
} }
void test_reference() void test_reference()
{ {
xlnt::cell_reference_hash hash; xlnt::cell_reference_hash hash;
assert_differs(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1))); xlnt_assert_differs(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1)));
assert_equals(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2))); xlnt_assert_equals(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2)));
assert_equals((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2")); xlnt_assert_equals((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2"));
assert_throws(xlnt::cell_reference("A1&"), xlnt::invalid_cell_reference); xlnt_assert_throws(xlnt::cell_reference("A1&"), xlnt::invalid_cell_reference);
assert_throws(xlnt::cell_reference("A"), xlnt::invalid_cell_reference); xlnt_assert_throws(xlnt::cell_reference("A"), xlnt::invalid_cell_reference);
auto ref = xlnt::cell_reference("$B$7"); auto ref = xlnt::cell_reference("$B$7");
assert(ref.row_absolute()); xlnt_assert(ref.row_absolute());
assert(ref.column_absolute()); xlnt_assert(ref.column_absolute());
assert(xlnt::cell_reference("A1") == "A1"); xlnt_assert(xlnt::cell_reference("A1") == "A1");
assert(xlnt::cell_reference("A1") != "A2"); xlnt_assert(xlnt::cell_reference("A1") != "A2");
} }
void test_anchor() void test_anchor()
@ -646,21 +646,21 @@ private:
xlnt::workbook wb; xlnt::workbook wb;
auto cell = wb.active_sheet().cell("A1"); auto cell = wb.active_sheet().cell("A1");
auto anchor = cell.anchor(); auto anchor = cell.anchor();
assert_equals(anchor.first, 0); xlnt_assert_equals(anchor.first, 0);
assert_equals(anchor.second, 0); xlnt_assert_equals(anchor.second, 0);
} }
void test_hyperlink() void test_hyperlink()
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto cell = wb.active_sheet().cell("A1"); auto cell = wb.active_sheet().cell("A1");
assert(!cell.has_hyperlink()); xlnt_assert(!cell.has_hyperlink());
assert_throws(cell.hyperlink(), xlnt::invalid_attribute); xlnt_assert_throws(cell.hyperlink(), xlnt::invalid_attribute);
assert_throws(cell.hyperlink("notaurl"), xlnt::invalid_parameter); xlnt_assert_throws(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
assert_throws(cell.hyperlink(""), xlnt::invalid_parameter); xlnt_assert_throws(cell.hyperlink(""), xlnt::invalid_parameter);
cell.hyperlink("http://example.com"); cell.hyperlink("http://example.com");
assert(cell.has_hyperlink()); xlnt_assert(cell.has_hyperlink());
assert_equals(cell.hyperlink(), "http://example.com"); xlnt_assert_equals(cell.hyperlink(), "http://example.com");
} }
void test_comment() void test_comment()
@ -668,13 +668,13 @@ private:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell("A1"); auto cell = ws.cell("A1");
assert(!cell.has_comment()); xlnt_assert(!cell.has_comment());
assert_throws(cell.comment(), xlnt::exception); xlnt_assert_throws(cell.comment(), xlnt::exception);
cell.comment(xlnt::comment("comment", "author")); cell.comment(xlnt::comment("comment", "author"));
assert(cell.has_comment()); xlnt_assert(cell.has_comment());
assert_equals(cell.comment(), xlnt::comment("comment", "author")); xlnt_assert_equals(cell.comment(), xlnt::comment("comment", "author"));
cell.clear_comment(); cell.clear_comment();
assert(!cell.has_comment()); xlnt_assert(!cell.has_comment());
assert_throws(cell.comment(), xlnt::exception); xlnt_assert_throws(cell.comment(), xlnt::exception);
} }
}; };

View File

@ -42,25 +42,25 @@ public:
void test_bad_string_empty() void test_bad_string_empty()
{ {
assert_throws(xlnt::column_t::column_index_from_string(""), xlnt_assert_throws(xlnt::column_t::column_index_from_string(""),
xlnt::invalid_column_index); xlnt::invalid_column_index);
} }
void test_bad_string_too_long() void test_bad_string_too_long()
{ {
assert_throws(xlnt::column_t::column_index_from_string("ABCD"), xlnt_assert_throws(xlnt::column_t::column_index_from_string("ABCD"),
xlnt::invalid_column_index); xlnt::invalid_column_index);
} }
void test_bad_string_numbers() void test_bad_string_numbers()
{ {
assert_throws(xlnt::column_t::column_index_from_string("123"), xlnt_assert_throws(xlnt::column_t::column_index_from_string("123"),
xlnt::invalid_column_index); xlnt::invalid_column_index);
} }
void test_bad_index_zero() void test_bad_index_zero()
{ {
assert_throws(xlnt::column_t::column_string_from_index(0), xlnt_assert_throws(xlnt::column_t::column_string_from_index(0),
xlnt::invalid_column_index); xlnt::invalid_column_index);
} }
@ -73,33 +73,33 @@ public:
const auto d = std::string("D"); const auto d = std::string("D");
c2 = d; c2 = d;
assert(c1 != c2); xlnt_assert(c1 != c2);
assert(c1 == static_cast<xlnt::column_t::index_t>(2)); xlnt_assert(c1 == static_cast<xlnt::column_t::index_t>(2));
assert(c2 == d); xlnt_assert(c2 == d);
assert(c1 != 3); xlnt_assert(c1 != 3);
assert(c1 != static_cast<xlnt::column_t::index_t>(5)); xlnt_assert(c1 != static_cast<xlnt::column_t::index_t>(5));
assert(c1 != "D"); xlnt_assert(c1 != "D");
assert(c1 != d); xlnt_assert(c1 != d);
assert(c2 >= c1); xlnt_assert(c2 >= c1);
assert(c2 > c1); xlnt_assert(c2 > c1);
assert(c1 < c2); xlnt_assert(c1 < c2);
assert(c1 <= c2); xlnt_assert(c1 <= c2);
assert_equals(--c2, 3); xlnt_assert_equals(--c2, 3);
assert_equals(c2--, 3); xlnt_assert_equals(c2--, 3);
assert_equals(c2, 2); xlnt_assert_equals(c2, 2);
c2 = 4; c2 = 4;
c1 = 3; c1 = 3;
assert(c2 <= 4); xlnt_assert(c2 <= 4);
assert(!(c2 < 3)); xlnt_assert(!(c2 < 3));
assert(c1 >= 3); xlnt_assert(c1 >= 3);
assert(!(c1 > 4)); xlnt_assert(!(c1 > 4));
assert(4 >= c2); xlnt_assert(4 >= c2);
assert(!(3 >= c2)); xlnt_assert(!(3 >= c2));
assert(3 <= c1); xlnt_assert(3 <= c1);
assert(!(4 <= c1)); xlnt_assert(!(4 <= c1));
} }
}; };

View File

@ -42,12 +42,12 @@ public:
{ {
xlnt::rich_text text1; xlnt::rich_text text1;
xlnt::rich_text text2; xlnt::rich_text text2;
assert_equals(text1, text2); xlnt_assert_equals(text1, text2);
xlnt::rich_text_run run_default; xlnt::rich_text_run run_default;
text1.add_run(run_default); text1.add_run(run_default);
assert_differs(text1, text2); xlnt_assert_differs(text1, text2);
text2.add_run(run_default); text2.add_run(run_default);
assert_equals(text1, text2); xlnt_assert_equals(text1, text2);
xlnt::rich_text_run run_formatted; xlnt::rich_text_run run_formatted;
xlnt::font run_font; xlnt::font run_font;
@ -67,7 +67,7 @@ public:
run_color_differs.second = run_font; run_color_differs.second = run_font;
xlnt::rich_text text_color_differs; xlnt::rich_text text_color_differs;
text_color_differs.add_run(run_color_differs); text_color_differs.add_run(run_color_differs);
assert_differs(text_formatted, text_color_differs); xlnt_assert_differs(text_formatted, text_color_differs);
xlnt::rich_text_run run_font_differs = run_formatted; xlnt::rich_text_run run_font_differs = run_formatted;
run_font = xlnt::font(); run_font = xlnt::font();
@ -75,7 +75,7 @@ public:
run_font_differs.second = run_font; run_font_differs.second = run_font;
xlnt::rich_text text_font_differs; xlnt::rich_text text_font_differs;
text_font_differs.add_run(run_font_differs); text_font_differs.add_run(run_font_differs);
assert_differs(text_formatted, text_font_differs); xlnt_assert_differs(text_formatted, text_font_differs);
xlnt::rich_text_run run_scheme_differs = run_formatted; xlnt::rich_text_run run_scheme_differs = run_formatted;
run_font = xlnt::font(); run_font = xlnt::font();
@ -83,7 +83,7 @@ public:
run_scheme_differs.second = run_font; run_scheme_differs.second = run_font;
xlnt::rich_text text_scheme_differs; xlnt::rich_text text_scheme_differs;
text_scheme_differs.add_run(run_scheme_differs); text_scheme_differs.add_run(run_scheme_differs);
assert_differs(text_formatted, text_scheme_differs); xlnt_assert_differs(text_formatted, text_scheme_differs);
xlnt::rich_text_run run_size_differs = run_formatted; xlnt::rich_text_run run_size_differs = run_formatted;
run_font = xlnt::font(); run_font = xlnt::font();
@ -91,7 +91,7 @@ public:
run_size_differs.second = run_font; run_size_differs.second = run_font;
xlnt::rich_text text_size_differs; xlnt::rich_text text_size_differs;
text_size_differs.add_run(run_size_differs); text_size_differs.add_run(run_size_differs);
assert_differs(text_formatted, text_size_differs); xlnt_assert_differs(text_formatted, text_size_differs);
xlnt::rich_text_run run_family_differs = run_formatted; xlnt::rich_text_run run_family_differs = run_formatted;
run_font = xlnt::font(); run_font = xlnt::font();
@ -99,6 +99,6 @@ public:
run_family_differs.second = run_font; run_family_differs.second = run_font;
xlnt::rich_text text_family_differs; xlnt::rich_text text_family_differs;
text_family_differs.add_run(run_family_differs); text_family_differs.add_run(run_family_differs);
assert_differs(text_formatted, text_family_differs); xlnt_assert_differs(text_formatted, text_family_differs);
} }
}; };

View File

@ -3,27 +3,28 @@
#include <cmath> #include <cmath>
#include <exception> #include <exception>
#define assert(expression) do\ #define xlnt_assert(expression) do\
{\ {\
try { if (expression) break; }\ try { if (expression) break; }\
catch (...) {}\ catch (...) {}\
throw std::exception();\ throw xlnt::exception("test failed");\
} while (false) } while (false)
#define assert_throws_nothing(expression) do\ #define xlnt_assert_throws_nothing(expression) do\
{\ {\
try { expression; break; }\ try { expression; break; }\
catch (...) {}\ catch (...) {}\
throw std::exception();\ throw xlnt::exception("test failed");\
} while (false) } while (false)
#define assert_throws(expression, exception_type) do\ #define xlnt_assert_throws(expression, exception_type) do\
{\ {\
try { expression; }\ try { expression; }\
catch (exception_type) { break; }\ catch (exception_type) { break; }\
throw std::exception();\ catch (...) {}\
throw xlnt::exception("test failed");\
} while (false) } while (false)
#define assert_equals(left, right) assert(left == right) #define xlnt_assert_equals(left, right) xlnt_assert(left == right)
#define assert_differs(left, right) assert(left != right) #define xlnt_assert_differs(left, right) xlnt_assert(left != right)
#define assert_delta(left, right, delta) assert(std::abs(left - right) <= delta) #define xlnt_assert_delta(left, right, delta) xlnt_assert(std::abs(left - right) <= delta)

View File

@ -40,9 +40,9 @@ public:
{ {
xlnt::alignment alignment; xlnt::alignment alignment;
assert(!alignment.horizontal().is_set()); xlnt_assert(!alignment.horizontal().is_set());
assert(!alignment.vertical().is_set()); xlnt_assert(!alignment.vertical().is_set());
assert(!alignment.shrink()); xlnt_assert(!alignment.shrink());
assert(!alignment.wrap()); xlnt_assert(!alignment.wrap());
} }
}; };

View File

@ -55,22 +55,22 @@ public:
for (auto pair : known_colors) for (auto pair : known_colors)
{ {
assert_equals(pair.first.rgb().hex_string(), pair.second); xlnt_assert_equals(pair.first.rgb().hex_string(), pair.second);
} }
} }
void test_non_rgb_colors() void test_non_rgb_colors()
{ {
xlnt::color indexed = xlnt::indexed_color(1); xlnt::color indexed = xlnt::indexed_color(1);
assert(!indexed.auto_()); xlnt_assert(!indexed.auto_());
assert_equals(indexed.indexed().index(), 1); xlnt_assert_equals(indexed.indexed().index(), 1);
assert_throws(indexed.theme(), xlnt::invalid_attribute); xlnt_assert_throws(indexed.theme(), xlnt::invalid_attribute);
assert_throws(indexed.rgb(), xlnt::invalid_attribute); xlnt_assert_throws(indexed.rgb(), xlnt::invalid_attribute);
xlnt::color theme = xlnt::theme_color(3); xlnt::color theme = xlnt::theme_color(3);
assert(!theme.auto_()); xlnt_assert(!theme.auto_());
assert_equals(theme.theme().index(), 3); xlnt_assert_equals(theme.theme().index(), 3);
assert_throws(theme.indexed(), xlnt::invalid_attribute); xlnt_assert_throws(theme.indexed(), xlnt::invalid_attribute);
assert_throws(theme.rgb(), xlnt::invalid_attribute); xlnt_assert_throws(theme.rgb(), xlnt::invalid_attribute);
} }
}; };

View File

@ -42,37 +42,37 @@ public:
{ {
xlnt::fill fill; xlnt::fill fill;
assert_equals(fill.type(), xlnt::fill_type::pattern); xlnt_assert_equals(fill.type(), xlnt::fill_type::pattern);
fill = xlnt::fill(xlnt::gradient_fill()); fill = xlnt::fill(xlnt::gradient_fill());
assert_equals(fill.type(), xlnt::fill_type::gradient); xlnt_assert_equals(fill.type(), xlnt::fill_type::gradient);
assert_equals(fill.gradient_fill().type(), xlnt::gradient_fill_type::linear); xlnt_assert_equals(fill.gradient_fill().type(), xlnt::gradient_fill_type::linear);
assert_equals(fill.gradient_fill().left(), 0); xlnt_assert_equals(fill.gradient_fill().left(), 0);
assert_equals(fill.gradient_fill().right(), 0); xlnt_assert_equals(fill.gradient_fill().right(), 0);
assert_equals(fill.gradient_fill().top(), 0); xlnt_assert_equals(fill.gradient_fill().top(), 0);
assert_equals(fill.gradient_fill().bottom(), 0); xlnt_assert_equals(fill.gradient_fill().bottom(), 0);
assert_throws(fill.pattern_fill(), xlnt::invalid_attribute); xlnt_assert_throws(fill.pattern_fill(), xlnt::invalid_attribute);
assert_equals(fill.gradient_fill().degree(), 0); xlnt_assert_equals(fill.gradient_fill().degree(), 0);
fill = fill.gradient_fill().degree(1); fill = fill.gradient_fill().degree(1);
assert_equals(fill.gradient_fill().degree(), 1); xlnt_assert_equals(fill.gradient_fill().degree(), 1);
fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid); fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
fill = fill.pattern_fill().foreground(xlnt::color::black()); fill = fill.pattern_fill().foreground(xlnt::color::black());
assert(fill.pattern_fill().foreground().is_set()); xlnt_assert(fill.pattern_fill().foreground().is_set());
assert_equals(fill.pattern_fill().foreground().get().rgb().hex_string(), xlnt_assert_equals(fill.pattern_fill().foreground().get().rgb().hex_string(),
xlnt::color::black().rgb().hex_string()); xlnt::color::black().rgb().hex_string());
fill = fill.pattern_fill().background(xlnt::color::green()); fill = fill.pattern_fill().background(xlnt::color::green());
assert(fill.pattern_fill().background().is_set()); xlnt_assert(fill.pattern_fill().background().is_set());
assert_equals(fill.pattern_fill().background().get().rgb().hex_string(), xlnt_assert_equals(fill.pattern_fill().background().get().rgb().hex_string(),
xlnt::color::green().rgb().hex_string()); xlnt::color::green().rgb().hex_string());
const auto &const_fill = fill; const auto &const_fill = fill;
assert(const_fill.pattern_fill().foreground().is_set()); xlnt_assert(const_fill.pattern_fill().foreground().is_set());
assert(const_fill.pattern_fill().background().is_set()); xlnt_assert(const_fill.pattern_fill().background().is_set());
} }
void test_comparison() void test_comparison()
@ -81,9 +81,9 @@ public:
xlnt::fill gradient_fill_linear = xlnt::gradient_fill().type(xlnt::gradient_fill_type::linear); 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); xlnt::fill gradient_fill_path = xlnt::gradient_fill().type(xlnt::gradient_fill_type::path);
assert_differs(pattern_fill, gradient_fill_linear); xlnt_assert_differs(pattern_fill, gradient_fill_linear);
assert_differs(gradient_fill_linear, gradient_fill_path); xlnt_assert_differs(gradient_fill_linear, gradient_fill_path);
assert_differs(gradient_fill_path, pattern_fill); xlnt_assert_differs(gradient_fill_path, pattern_fill);
} }
void test_two_fills() void test_two_fills()
@ -100,7 +100,7 @@ public:
cell2.fill(xlnt::fill::solid(xlnt::color::green())); cell2.fill(xlnt::fill::solid(xlnt::color::green()));
cell2.value(xlnt::date(2010, 7, 13)); cell2.value(xlnt::date(2010, 7, 13));
assert_equals(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow())); xlnt_assert_equals(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow()));
assert_equals(cell2.fill(), xlnt::fill::solid(xlnt::color::green())); xlnt_assert_equals(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
} }
}; };

View File

@ -117,16 +117,16 @@ public:
void test_basic() void test_basic()
{ {
xlnt::number_format no_id("#\\x\\y\\z"); xlnt::number_format no_id("#\\x\\y\\z");
assert_throws(no_id.id(), std::runtime_error); xlnt_assert_throws(no_id.id(), std::runtime_error);
xlnt::number_format id("General", 200); xlnt::number_format id("General", 200);
assert_equals(id.id(), 200); xlnt_assert_equals(id.id(), 200);
assert_equals(id.format_string(), "General"); xlnt_assert_equals(id.format_string(), "General");
xlnt::number_format general(0); xlnt::number_format general(0);
assert_equals(general, xlnt::number_format::general()); xlnt_assert_equals(general, xlnt::number_format::general());
assert_equals(general.id(), 0); xlnt_assert_equals(general.id(), 0);
assert_equals(general.format_string(), "General"); xlnt_assert_equals(general.format_string(), "General");
} }
void test_simple_format() void test_simple_format()
@ -135,21 +135,21 @@ public:
nf.format_string("\"positive\"General;\"negative\"General"); nf.format_string("\"positive\"General;\"negative\"General");
auto formatted = nf.format(3.14, xlnt::calendar::windows_1900); auto formatted = nf.format(3.14, xlnt::calendar::windows_1900);
assert_equals(formatted, "positive3.14"); xlnt_assert_equals(formatted, "positive3.14");
formatted = nf.format(-3.14, xlnt::calendar::windows_1900); formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
assert_equals(formatted, "negative3.14"); xlnt_assert_equals(formatted, "negative3.14");
nf.format_string("\"any\"General"); nf.format_string("\"any\"General");
formatted = nf.format(-3.14, xlnt::calendar::windows_1900); formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
assert_equals(formatted, "-any3.14"); xlnt_assert_equals(formatted, "-any3.14");
nf.format_string("\"positive\"General;\"negative\"General;\"zero\"General"); nf.format_string("\"positive\"General;\"negative\"General;\"zero\"General");
formatted = nf.format(3.14, xlnt::calendar::windows_1900); formatted = nf.format(3.14, xlnt::calendar::windows_1900);
assert_equals(formatted, "positive3.14"); xlnt_assert_equals(formatted, "positive3.14");
formatted = nf.format(-3.14, xlnt::calendar::windows_1900); formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
assert_equals(formatted, "negative3.14"); xlnt_assert_equals(formatted, "negative3.14");
formatted = nf.format(0, xlnt::calendar::windows_1900); formatted = nf.format(0, xlnt::calendar::windows_1900);
assert_equals(formatted, "zero0"); xlnt_assert_equals(formatted, "zero0");
} }
void test_simple_date() void test_simple_date()
@ -160,7 +160,7 @@ public:
xlnt::number_format nf = xlnt::number_format::date_ddmmyyyy(); xlnt::number_format nf = xlnt::number_format::date_ddmmyyyy();
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "18/06/16"); xlnt_assert_equals(formatted, "18/06/16");
} }
void test_short_month() void test_short_month()
@ -172,7 +172,7 @@ public:
nf.format_string("m"); nf.format_string("m");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
} }
void test_month_abbreviation() void test_month_abbreviation()
@ -184,7 +184,7 @@ public:
nf.format_string("mmm"); nf.format_string("mmm");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "Jun"); xlnt_assert_equals(formatted, "Jun");
} }
void test_month_name() void test_month_name()
@ -196,7 +196,7 @@ public:
nf.format_string("mmmm"); nf.format_string("mmmm");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "June"); xlnt_assert_equals(formatted, "June");
} }
void test_short_day() void test_short_day()
@ -208,7 +208,7 @@ public:
nf.format_string("d"); nf.format_string("d");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "8"); xlnt_assert_equals(formatted, "8");
} }
void test_long_day() void test_long_day()
@ -220,7 +220,7 @@ public:
nf.format_string("dd"); nf.format_string("dd");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "08"); xlnt_assert_equals(formatted, "08");
} }
void test_long_year() void test_long_year()
@ -232,7 +232,7 @@ public:
nf.format_string("yyyy"); nf.format_string("yyyy");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "2016"); xlnt_assert_equals(formatted, "2016");
} }
void test_day_name() void test_day_name()
@ -244,7 +244,7 @@ public:
nf.format_string("dddd"); nf.format_string("dddd");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "Sunday"); xlnt_assert_equals(formatted, "Sunday");
} }
void test_day_abbreviation() void test_day_abbreviation()
@ -256,7 +256,7 @@ public:
nf.format_string("ddd"); nf.format_string("ddd");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "Sun"); xlnt_assert_equals(formatted, "Sun");
} }
void test_month_letter() void test_month_letter()
@ -268,7 +268,7 @@ public:
nf.format_string("mmmmm"); nf.format_string("mmmmm");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "J"); xlnt_assert_equals(formatted, "J");
} }
void test_time_24_hour() void test_time_24_hour()
@ -279,7 +279,7 @@ public:
xlnt::number_format nf = xlnt::number_format::date_time4(); xlnt::number_format nf = xlnt::number_format::date_time4();
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20:15:10"); xlnt_assert_equals(formatted, "20:15:10");
} }
void test_elapsed_minutes() void test_elapsed_minutes()
@ -290,7 +290,7 @@ public:
xlnt::number_format nf("[mm]:ss"); xlnt::number_format nf("[mm]:ss");
auto formatted = nf.format(period_number, xlnt::calendar::windows_1900); auto formatted = nf.format(period_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "1563:04"); xlnt_assert_equals(formatted, "1563:04");
} }
void test_second_fractional_leading_zero() void test_second_fractional_leading_zero()
@ -301,7 +301,7 @@ public:
xlnt::number_format nf("ss.0"); xlnt::number_format nf("ss.0");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "03.4"); xlnt_assert_equals(formatted, "03.4");
} }
void test_second_fractional() void test_second_fractional()
@ -312,7 +312,7 @@ public:
xlnt::number_format nf("s.0"); xlnt::number_format nf("s.0");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "3.4"); xlnt_assert_equals(formatted, "3.4");
} }
void test_elapsed_seconds() void test_elapsed_seconds()
@ -323,7 +323,7 @@ public:
xlnt::number_format nf("[ss]"); xlnt::number_format nf("[ss]");
auto formatted = nf.format(period_number, xlnt::calendar::windows_1900); auto formatted = nf.format(period_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "93784"); xlnt_assert_equals(formatted, "93784");
} }
void test_time_12_hour_am() void test_time_12_hour_am()
@ -334,7 +334,7 @@ public:
xlnt::number_format nf = xlnt::number_format::date_time2(); xlnt::number_format nf = xlnt::number_format::date_time2();
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "8:15:10 AM"); xlnt_assert_equals(formatted, "8:15:10 AM");
} }
void test_time_12_hour_pm() void test_time_12_hour_pm()
@ -345,7 +345,7 @@ public:
xlnt::number_format nf = xlnt::number_format::date_time2(); xlnt::number_format nf = xlnt::number_format::date_time2();
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "8:15:10 PM"); xlnt_assert_equals(formatted, "8:15:10 PM");
} }
void test_long_hour_12_hour() void test_long_hour_12_hour()
@ -357,7 +357,7 @@ public:
nf.format_string("hh AM/PM"); nf.format_string("hh AM/PM");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "08 PM"); xlnt_assert_equals(formatted, "08 PM");
} }
void test_long_hour_12_hour_ap() void test_long_hour_12_hour_ap()
@ -371,10 +371,10 @@ public:
xlnt::number_format nf("hh A/P"); xlnt::number_format nf("hh A/P");
auto formatted = nf.format(time1_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time1_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "08 P"); xlnt_assert_equals(formatted, "08 P");
formatted = nf.format(time2_number, xlnt::calendar::windows_1900); formatted = nf.format(time2_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "08 A"); xlnt_assert_equals(formatted, "08 A");
} }
void test_long_hour_24_hour() void test_long_hour_24_hour()
@ -386,7 +386,7 @@ public:
nf.format_string("hh"); nf.format_string("hh");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20"); xlnt_assert_equals(formatted, "20");
} }
void test_short_minute() void test_short_minute()
@ -398,7 +398,7 @@ public:
nf.format_string("h:m"); nf.format_string("h:m");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20:5"); xlnt_assert_equals(formatted, "20:5");
} }
void test_long_minute() void test_long_minute()
@ -410,7 +410,7 @@ public:
nf.format_string("h:mm"); nf.format_string("h:mm");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20:05"); xlnt_assert_equals(formatted, "20:05");
} }
void test_short_second() void test_short_second()
@ -422,7 +422,7 @@ public:
nf.format_string("h:m:s"); nf.format_string("h:m:s");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20:15:1"); xlnt_assert_equals(formatted, "20:15:1");
} }
void test_long_second() void test_long_second()
@ -434,7 +434,7 @@ public:
nf.format_string("h:m:ss"); nf.format_string("h:m:ss");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20:15:01"); xlnt_assert_equals(formatted, "20:15:01");
} }
void test_trailing_space() void test_trailing_space()
@ -446,7 +446,7 @@ public:
nf.format_string("h:m:ss "); nf.format_string("h:m:ss ");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
assert_equals(formatted, "20:15:01 "); xlnt_assert_equals(formatted, "20:15:01 ");
} }
void test_text_section_string() void test_text_section_string()
@ -456,7 +456,7 @@ public:
auto formatted = nf.format("text"); auto formatted = nf.format("text");
assert_equals(formatted, "atextb"); xlnt_assert_equals(formatted, "atextb");
} }
void test_text_section_no_string() void test_text_section_no_string()
@ -466,7 +466,7 @@ public:
auto formatted = nf.format("text"); auto formatted = nf.format("text");
assert_equals(formatted, "ab"); xlnt_assert_equals(formatted, "ab");
} }
void test_text_section_no_text() void test_text_section_no_text()
@ -476,7 +476,7 @@ public:
auto formatted = nf.format("text"); auto formatted = nf.format("text");
assert_equals(formatted, "text"); xlnt_assert_equals(formatted, "text");
} }
void test_conditional_format() void test_conditional_format()
@ -485,77 +485,77 @@ public:
nf.format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General"); nf.format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6first"); xlnt_assert_equals(formatted, "6first");
formatted = nf.format(4, xlnt::calendar::windows_1900); formatted = nf.format(4, xlnt::calendar::windows_1900);
assert_equals(formatted, "second4"); xlnt_assert_equals(formatted, "second4");
formatted = nf.format(5, xlnt::calendar::windows_1900); formatted = nf.format(5, xlnt::calendar::windows_1900);
assert_equals(formatted, "second5"); xlnt_assert_equals(formatted, "second5");
formatted = nf.format(3, xlnt::calendar::windows_1900); formatted = nf.format(3, xlnt::calendar::windows_1900);
assert_equals(formatted, "third3"); xlnt_assert_equals(formatted, "third3");
formatted = nf.format(2, xlnt::calendar::windows_1900); formatted = nf.format(2, xlnt::calendar::windows_1900);
assert_equals(formatted, "third2"); xlnt_assert_equals(formatted, "third2");
nf.format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General"); nf.format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General");
formatted = nf.format(5, xlnt::calendar::windows_1900); formatted = nf.format(5, xlnt::calendar::windows_1900);
assert_equals(formatted, "first5"); xlnt_assert_equals(formatted, "first5");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "first6"); xlnt_assert_equals(formatted, "first6");
formatted = nf.format(4, xlnt::calendar::windows_1900); formatted = nf.format(4, xlnt::calendar::windows_1900);
assert_equals(formatted, "second4"); xlnt_assert_equals(formatted, "second4");
formatted = nf.format(3, xlnt::calendar::windows_1900); formatted = nf.format(3, xlnt::calendar::windows_1900);
assert_equals(formatted, "second3"); xlnt_assert_equals(formatted, "second3");
formatted = nf.format(2, xlnt::calendar::windows_1900); formatted = nf.format(2, xlnt::calendar::windows_1900);
assert_equals(formatted, "third2"); xlnt_assert_equals(formatted, "third2");
nf.format_string("[>=5]\"first\"General"); nf.format_string("[>=5]\"first\"General");
formatted = nf.format(4, xlnt::calendar::windows_1900); formatted = nf.format(4, xlnt::calendar::windows_1900);
assert_equals(formatted, "###########"); xlnt_assert_equals(formatted, "###########");
nf.format_string("[>=5]\"first\"General;[>=4]\"second\"General"); nf.format_string("[>=5]\"first\"General;[>=4]\"second\"General");
formatted = nf.format(3, xlnt::calendar::windows_1900); formatted = nf.format(3, xlnt::calendar::windows_1900);
assert_equals(formatted, "###########"); xlnt_assert_equals(formatted, "###########");
nf.format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General"); nf.format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General");
formatted = nf.format(0, xlnt::calendar::windows_1900); formatted = nf.format(0, xlnt::calendar::windows_1900);
assert_equals(formatted, "first0"); xlnt_assert_equals(formatted, "first0");
formatted = nf.format(1, xlnt::calendar::windows_1900); formatted = nf.format(1, xlnt::calendar::windows_1900);
assert_equals(formatted, "second1"); xlnt_assert_equals(formatted, "second1");
formatted = nf.format(5, xlnt::calendar::windows_1900); formatted = nf.format(5, xlnt::calendar::windows_1900);
assert_equals(formatted, "third5"); xlnt_assert_equals(formatted, "third5");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "third6"); xlnt_assert_equals(formatted, "third6");
nf.format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General"); nf.format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General");
formatted = nf.format(-1000, xlnt::calendar::windows_1900); formatted = nf.format(-1000, xlnt::calendar::windows_1900);
assert_equals(formatted, "-first1000"); xlnt_assert_equals(formatted, "-first1000");
formatted = nf.format(0, xlnt::calendar::windows_1900); formatted = nf.format(0, xlnt::calendar::windows_1900);
assert_equals(formatted, "first0"); xlnt_assert_equals(formatted, "first0");
formatted = nf.format(1, xlnt::calendar::windows_1900); formatted = nf.format(1, xlnt::calendar::windows_1900);
assert_equals(formatted, "first1"); xlnt_assert_equals(formatted, "first1");
formatted = nf.format(4, xlnt::calendar::windows_1900); formatted = nf.format(4, xlnt::calendar::windows_1900);
assert_equals(formatted, "second4"); xlnt_assert_equals(formatted, "second4");
formatted = nf.format(5, xlnt::calendar::windows_1900); formatted = nf.format(5, xlnt::calendar::windows_1900);
assert_equals(formatted, "second5"); xlnt_assert_equals(formatted, "second5");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "third6"); xlnt_assert_equals(formatted, "third6");
formatted = nf.format(1000, xlnt::calendar::windows_1900); formatted = nf.format(1000, xlnt::calendar::windows_1900);
assert_equals(formatted, "third1000"); xlnt_assert_equals(formatted, "third1000");
nf.format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General"); nf.format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General");
formatted = nf.format(1, xlnt::calendar::windows_1900); formatted = nf.format(1, xlnt::calendar::windows_1900);
assert_equals(formatted, "first1"); xlnt_assert_equals(formatted, "first1");
formatted = nf.format(2, xlnt::calendar::windows_1900); formatted = nf.format(2, xlnt::calendar::windows_1900);
assert_equals(formatted, "second2"); xlnt_assert_equals(formatted, "second2");
formatted = nf.format(3, xlnt::calendar::windows_1900); formatted = nf.format(3, xlnt::calendar::windows_1900);
assert_equals(formatted, "third3"); xlnt_assert_equals(formatted, "third3");
formatted = nf.format(0, xlnt::calendar::windows_1900); formatted = nf.format(0, xlnt::calendar::windows_1900);
assert_equals(formatted, "third0"); xlnt_assert_equals(formatted, "third0");
nf.format_string("[<>1]\"first\"General;[<>2]\"second\"General"); nf.format_string("[<>1]\"first\"General;[<>2]\"second\"General");
formatted = nf.format(2, xlnt::calendar::windows_1900); formatted = nf.format(2, xlnt::calendar::windows_1900);
assert_equals(formatted, "first2"); xlnt_assert_equals(formatted, "first2");
formatted = nf.format(1, xlnt::calendar::windows_1900); formatted = nf.format(1, xlnt::calendar::windows_1900);
assert_equals(formatted, "second1"); xlnt_assert_equals(formatted, "second1");
} }
void test_space() void test_space()
@ -563,7 +563,7 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("_(General_)"); nf.format_string("_(General_)");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, " 6 "); xlnt_assert_equals(formatted, " 6 ");
} }
void test_fill() void test_fill()
@ -571,15 +571,15 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("*-General"); nf.format_string("*-General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "----------6"); xlnt_assert_equals(formatted, "----------6");
nf.format_string("General*-"); nf.format_string("General*-");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6----------"); xlnt_assert_equals(formatted, "6----------");
nf.format_string("\\a*-\\b"); nf.format_string("\\a*-\\b");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "a---------b"); xlnt_assert_equals(formatted, "a---------b");
} }
void test_placeholders_zero() void test_placeholders_zero()
@ -587,11 +587,11 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("00"); nf.format_string("00");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "06"); xlnt_assert_equals(formatted, "06");
nf.format_string("00"); nf.format_string("00");
formatted = nf.format(63, xlnt::calendar::windows_1900); formatted = nf.format(63, xlnt::calendar::windows_1900);
assert_equals(formatted, "63"); xlnt_assert_equals(formatted, "63");
} }
void test_placeholders_space() void test_placeholders_space()
@ -599,25 +599,25 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("?0"); nf.format_string("?0");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, " 6"); xlnt_assert_equals(formatted, " 6");
nf.format_string("?0"); nf.format_string("?0");
formatted = nf.format(63, xlnt::calendar::windows_1900); formatted = nf.format(63, xlnt::calendar::windows_1900);
assert_equals(formatted, "63"); xlnt_assert_equals(formatted, "63");
nf.format_string("?0"); nf.format_string("?0");
formatted = nf.format(637, xlnt::calendar::windows_1900); formatted = nf.format(637, xlnt::calendar::windows_1900);
assert_equals(formatted, "637"); xlnt_assert_equals(formatted, "637");
nf.format_string("0.?"); nf.format_string("0.?");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6. "); xlnt_assert_equals(formatted, "6. ");
nf.format_string("0.0?"); nf.format_string("0.0?");
formatted = nf.format(6.3, xlnt::calendar::windows_1900); formatted = nf.format(6.3, xlnt::calendar::windows_1900);
assert_equals(formatted, "6.3 "); xlnt_assert_equals(formatted, "6.3 ");
formatted = nf.format(6.34, xlnt::calendar::windows_1900); formatted = nf.format(6.34, xlnt::calendar::windows_1900);
assert_equals(formatted, "6.34"); xlnt_assert_equals(formatted, "6.34");
} }
void test_scientific() void test_scientific()
@ -625,7 +625,7 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("0.0E-0"); nf.format_string("0.0E-0");
auto formatted = nf.format(6.1, xlnt::calendar::windows_1900); auto formatted = nf.format(6.1, xlnt::calendar::windows_1900);
assert_equals(formatted, "6.1E0"); xlnt_assert_equals(formatted, "6.1E0");
} }
void test_locale_currency() void test_locale_currency()
@ -634,11 +634,11 @@ public:
nf.format_string("[$€-407]#,##0.00"); nf.format_string("[$€-407]#,##0.00");
auto formatted = nf.format(-45000.1, xlnt::calendar::windows_1900); auto formatted = nf.format(-45000.1, xlnt::calendar::windows_1900);
assert_equals(formatted, "-€45,000.10"); xlnt_assert_equals(formatted, "-€45,000.10");
nf.format_string("[$$-1009]#,##0.00"); nf.format_string("[$$-1009]#,##0.00");
formatted = nf.format(-45000.1, xlnt::calendar::windows_1900); formatted = nf.format(-45000.1, xlnt::calendar::windows_1900);
assert_equals(formatted, "-$45,000.10"); xlnt_assert_equals(formatted, "-$45,000.10");
} }
void test_bad_country() void test_bad_country()
@ -646,16 +646,16 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("[$-]#,##0.00"); nf.format_string("[$-]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[$-G]#,##0.00"); nf.format_string("[$-G]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[$-4002]#,##0.00"); nf.format_string("[$-4002]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[-4001]#,##0.00"); nf.format_string("[-4001]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
} }
void test_duplicate_bracket_sections() void test_duplicate_bracket_sections()
@ -663,13 +663,13 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("[Red][Green]#,##0.00"); nf.format_string("[Red][Green]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[$-403][$-4001]#,##0.00"); nf.format_string("[$-403][$-4001]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[>3][>4]#,##0.00"); nf.format_string("[>3][>4]#,##0.00");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
} }
void test_escaped_quote_string() void test_escaped_quote_string()
@ -678,7 +678,7 @@ public:
nf.format_string("\"\\\"\"General"); nf.format_string("\"\\\"\"General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "\"6"); xlnt_assert_equals(formatted, "\"6");
} }
void test_thousands_scale() void test_thousands_scale()
@ -687,7 +687,7 @@ public:
nf.format_string("#,"); nf.format_string("#,");
auto formatted = nf.format(61234, xlnt::calendar::windows_1900); auto formatted = nf.format(61234, xlnt::calendar::windows_1900);
assert_equals(formatted, "61"); xlnt_assert_equals(formatted, "61");
} }
void test_colors() void test_colors()
@ -696,43 +696,43 @@ public:
nf.format_string("[Black]#"); nf.format_string("[Black]#");
auto formatted = nf.format(6, xlnt::calendar::windows_1900); auto formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Black]#"); nf.format_string("[Black]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Blue]#"); nf.format_string("[Blue]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Green]#"); nf.format_string("[Green]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Red]#"); nf.format_string("[Red]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Cyan]#"); nf.format_string("[Cyan]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Magenta]#"); nf.format_string("[Magenta]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Yellow]#"); nf.format_string("[Yellow]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[White]#"); nf.format_string("[White]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
nf.format_string("[Color15]#"); nf.format_string("[Color15]#");
formatted = nf.format(6, xlnt::calendar::windows_1900); formatted = nf.format(6, xlnt::calendar::windows_1900);
assert_equals(formatted, "6"); xlnt_assert_equals(formatted, "6");
} }
void test_bad_format() void test_bad_format()
@ -740,31 +740,31 @@ public:
xlnt::number_format nf; xlnt::number_format nf;
nf.format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General"); nf.format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General"); nf.format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("["); nf.format_string("[");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[]"); nf.format_string("[]");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[Redd]"); nf.format_string("[Redd]");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("[$1]#"); nf.format_string("[$1]#");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("Gee"); nf.format_string("Gee");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("!"); nf.format_string("!");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.format_string("A/"); nf.format_string("A/");
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); xlnt_assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
} }
void format_and_test(const xlnt::number_format &nf, const std::array<std::string, 4> &expect) void format_and_test(const xlnt::number_format &nf, const std::array<std::string, 4> &expect)
@ -775,10 +775,10 @@ public:
const std::string text = "text"; const std::string text = "text";
xlnt::calendar calendar = xlnt::calendar::windows_1900; xlnt::calendar calendar = xlnt::calendar::windows_1900;
assert_equals(nf.format(positive, calendar), expect[0]); xlnt_assert_equals(nf.format(positive, calendar), expect[0]);
assert_equals(nf.format(negative, calendar), expect[1]); xlnt_assert_equals(nf.format(negative, calendar), expect[1]);
assert_equals(nf.format(zero, calendar), expect[2]); xlnt_assert_equals(nf.format(zero, calendar), expect[2]);
assert_equals(nf.format(text), expect[3]); xlnt_assert_equals(nf.format(text), expect[3]);
} }
// General // General

View File

@ -45,15 +45,15 @@ public:
void test_from_string() void test_from_string()
{ {
xlnt::time t("10:35:45"); xlnt::time t("10:35:45");
assert_equals(t.hour, 10); xlnt_assert_equals(t.hour, 10);
assert_equals(t.minute, 35); xlnt_assert_equals(t.minute, 35);
assert_equals(t.second, 45); xlnt_assert_equals(t.second, 45);
} }
void test_to_string() void test_to_string()
{ {
xlnt::datetime dt(2016, 7, 16, 9, 11, 32, 999999); xlnt::datetime dt(2016, 7, 16, 9, 11, 32, 999999);
assert_equals(dt.to_string(), "2016/7/16 9:11:32:999999"); xlnt_assert_equals(dt.to_string(), "2016/7/16 9:11:32:999999");
} }
void test_carry() void test_carry()
@ -68,28 +68,28 @@ public:
number += (0.6 / 1000000) / 60 / 60 / 24; number += (0.6 / 1000000) / 60 / 60 / 24;
auto rollover = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900); auto rollover = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900);
assert_equals(rollover.hour, 11); xlnt_assert_equals(rollover.hour, 11);
assert_equals(rollover.minute, 00); xlnt_assert_equals(rollover.minute, 00);
assert_equals(rollover.second, 00); xlnt_assert_equals(rollover.second, 00);
assert_equals(rollover.microsecond, 00); xlnt_assert_equals(rollover.microsecond, 00);
} }
void test_leap_year_bug() void test_leap_year_bug()
{ {
xlnt::datetime dt(1900, 2, 29, 0, 0, 0, 0); xlnt::datetime dt(1900, 2, 29, 0, 0, 0, 0);
auto number = dt.to_number(xlnt::calendar::windows_1900); auto number = dt.to_number(xlnt::calendar::windows_1900);
assert_equals(static_cast<int>(number), 60); xlnt_assert_equals(static_cast<int>(number), 60);
auto converted = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900); auto converted = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900);
assert_equals(dt, converted); xlnt_assert_equals(dt, converted);
} }
void test_early_date() void test_early_date()
{ {
xlnt::date d(1900, 1, 29); xlnt::date d(1900, 1, 29);
auto number = d.to_number(xlnt::calendar::windows_1900); auto number = d.to_number(xlnt::calendar::windows_1900);
assert_equals(number, 29); xlnt_assert_equals(number, 29);
auto converted = xlnt::date::from_number(number, xlnt::calendar::windows_1900); auto converted = xlnt::date::from_number(number, xlnt::calendar::windows_1900);
assert_equals(d, converted); xlnt_assert_equals(d, converted);
} }
void test_mac_calendar() void test_mac_calendar()
@ -97,12 +97,12 @@ public:
xlnt::date d(2016, 7, 16); xlnt::date d(2016, 7, 16);
auto number_1900 = d.to_number(xlnt::calendar::windows_1900); auto number_1900 = d.to_number(xlnt::calendar::windows_1900);
auto number_1904 = d.to_number(xlnt::calendar::mac_1904); auto number_1904 = d.to_number(xlnt::calendar::mac_1904);
assert_equals(number_1900, 42567); xlnt_assert_equals(number_1900, 42567);
assert_equals(number_1904, 41105); xlnt_assert_equals(number_1904, 41105);
auto converted_1900 = xlnt::date::from_number(number_1900, xlnt::calendar::windows_1900); auto converted_1900 = xlnt::date::from_number(number_1900, xlnt::calendar::windows_1900);
auto converted_1904 = xlnt::date::from_number(number_1904, xlnt::calendar::mac_1904); auto converted_1904 = xlnt::date::from_number(number_1904, xlnt::calendar::mac_1904);
assert_equals(converted_1900, d); xlnt_assert_equals(converted_1900, d);
assert_equals(converted_1904, d); xlnt_assert_equals(converted_1904, d);
} }
void test_operators() void test_operators()
@ -110,7 +110,7 @@ public:
xlnt::date d1(2016, 7, 16); xlnt::date d1(2016, 7, 16);
xlnt::date d2(2016, 7, 16); xlnt::date d2(2016, 7, 16);
xlnt::date d3(2016, 7, 15); xlnt::date d3(2016, 7, 15);
assert_equals(d1, d2); xlnt_assert_equals(d1, d2);
assert_differs(d1, d3); xlnt_assert_differs(d1, d3);
} }
}; };

View File

@ -24,29 +24,133 @@
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <stdexcept>
#include <helpers/test_suite.hpp> #include <helpers/test_suite.hpp>
#include <helpers/xml_helper.hpp> #include <helpers/xml_helper.hpp>
#include <helpers/assertions.hpp>
class helper_test_suite : public test_suite class helper_test_suite : public test_suite
{ {
public: public:
helper_test_suite() helper_test_suite()
{ {
register_test(test_bootstrap_asserts);
register_test(test_other_asserts);
register_test(test_compare); register_test(test_compare);
} }
// bootstrap asserts are used by other assert tests so they need to be tested first
// without using themselves
void test_bootstrap_asserts()
{
auto function_that_throws = []()
{
throw std::runtime_error("test");
};
auto function_that_doesnt_throw = []()
{
return std::string("abc");
};
// 1. function that throws no exception shouldn't cause exception to be thrown in xlnt_assert_throws_nothing
try
{
xlnt_assert_throws_nothing(function_that_doesnt_throw());
// good
}
catch (...)
{
throw xlnt::exception("test failed");
}
// 2. function that throws an exception should cause exception to be thrown in xlnt_assert_throws_nothing
try
{
xlnt_assert_throws_nothing(function_that_throws());
}
catch (std::runtime_error)
{
// good
}
catch (...)
{
throw xlnt::exception("test failed");
}
// 3. function that doesn't throw an exception should cause exception to be thrown in xlnt_assert_throws
try
{
xlnt_assert_throws(function_that_throws(), std::runtime_error);
// good
}
catch (...)
{
throw xlnt::exception("test failed");
}
// 4. function that doesn't throw an exception should cause exception to be thrown in xlnt_assert_throws
try
{
xlnt_assert_throws(function_that_doesnt_throw(), std::runtime_error);
throw xlnt::exception("test failed");
}
catch (xlnt::exception)
{
// good
}
catch (...)
{
throw xlnt::exception("test failed");
}
// 5. function that doesn't throw an exception should cause exception to be thrown in xlnt_assert_throws
try
{
xlnt_assert_throws(function_that_throws(), xlnt::exception);
throw xlnt::exception("test failed");
}
catch (xlnt::exception)
{
// good
}
catch (...)
{
throw xlnt::exception("test failed");
}
}
void test_other_asserts()
{
xlnt_assert_throws_nothing(xlnt_assert(true));
xlnt_assert_throws(xlnt_assert(false), xlnt::exception);
xlnt_assert_throws_nothing(xlnt_assert_equals(1, 1));
xlnt_assert_throws(xlnt_assert_equals(1, 2), xlnt::exception);
xlnt_assert_throws_nothing(xlnt_assert_differs(1, 2));
xlnt_assert_throws(xlnt_assert_differs(1, 1), xlnt::exception);
xlnt_assert_throws_nothing(xlnt_assert_delta(1.0, 1.05, 0.06));
xlnt_assert_throws(xlnt_assert_delta(1.0, 1.05, 0.04), xlnt::exception);
}
void test_compare() void test_compare()
{ {
assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
assert(!xml_helper::compare_xml_exact("<a c=\"4\"/>", "<a b=\"4\"/>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a c=\"4\"/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"4\"/>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a>txet</a>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a>txet</a>", true));
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a><b>txet</b></a>", true)); xlnt_assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a><b>txet</b></a>", true));
assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true)); xlnt_assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
assert(xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"3\"></a>", true)); xlnt_assert(xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"3\"></a>", true));
assert(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true)); xlnt_assert(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true));
} }
}; };

View File

@ -47,8 +47,8 @@ public:
path_helper::delete_file(temp.get_path()); path_helper::delete_file(temp.get_path());
} }
assert(!temp.get_path().exists()); xlnt_assert(!temp.get_path().exists());
std::ofstream stream(temp.get_path().string()); std::ofstream stream(temp.get_path().string());
assert(temp.get_path().exists()); xlnt_assert(temp.get_path().exists());
} }
}; };

View File

@ -42,11 +42,11 @@ public:
{ {
auto td = xlnt::timedelta::from_number(1.0423726852L); auto td = xlnt::timedelta::from_number(1.0423726852L);
assert(td.days == 1); xlnt_assert(td.days == 1);
assert(td.hours == 1); xlnt_assert(td.hours == 1);
assert(td.minutes == 1); xlnt_assert(td.minutes == 1);
assert(td.seconds == 1); xlnt_assert(td.seconds == 1);
assert(td.microseconds == 1); xlnt_assert(td.microseconds == 1);
} }
void test_round_trip() void test_round_trip()
@ -54,13 +54,13 @@ public:
long double time = 3.14159265359L; long double time = 3.14159265359L;
auto td = xlnt::timedelta::from_number(time); auto td = xlnt::timedelta::from_number(time);
auto time_rt = td.to_number(); auto time_rt = td.to_number();
assert_equals(time, time_rt); xlnt_assert_equals(time, time_rt);
} }
void test_to_number() void test_to_number()
{ {
xlnt::timedelta td(1, 1, 1, 1, 1); xlnt::timedelta td(1, 1, 1, 1, 1);
assert_equals(td.to_number(), 1.0423726852L); xlnt_assert_equals(td.to_number(), 1.0423726852L);
} }
void test_carry() void test_carry()
@ -75,10 +75,10 @@ public:
number += (0.6 / 1000000) / 60 / 60 / 24; number += (0.6 / 1000000) / 60 / 60 / 24;
auto rollover = xlnt::timedelta::from_number(number); auto rollover = xlnt::timedelta::from_number(number);
assert_equals(rollover.days, 2); xlnt_assert_equals(rollover.days, 2);
assert_equals(rollover.hours, 0); xlnt_assert_equals(rollover.hours, 0);
assert_equals(rollover.minutes, 0); xlnt_assert_equals(rollover.minutes, 0);
assert_equals(rollover.seconds, 0); xlnt_assert_equals(rollover.seconds, 0);
assert_equals(rollover.microseconds, 0); xlnt_assert_equals(rollover.microseconds, 0);
} }
}; };

View File

@ -57,19 +57,19 @@ public:
for(auto pair : expected_pairs) for(auto pair : expected_pairs)
{ {
assert_equals(xlnt::split_named_range(pair.first), pair.second); xlnt_assert_equals(xlnt::split_named_range(pair.first), pair.second);
} }
*/ */
} }
void test_split_no_quotes() void test_split_no_quotes()
{ {
/*assert_equals([("HYPOTHESES", "$B$3:$L$3"), ], split_named_range("HYPOTHESES!$B$3:$L$3"))*/ /*xlnt_assert_equals([("HYPOTHESES", "$B$3:$L$3"), ], split_named_range("HYPOTHESES!$B$3:$L$3"))*/
} }
void test_bad_range_name() void test_bad_range_name()
{ {
/*assert_raises(NamedRangeException, split_named_range, "HYPOTHESES$B$3")*/ /*xlnt_assert_raises(NamedRangeException, split_named_range, "HYPOTHESES$B$3")*/
} }
void test_range_name_worksheet_special_chars() void test_range_name_worksheet_special_chars()
@ -100,9 +100,9 @@ public:
{ {
content = handle.read() content = handle.read()
named_ranges = read_named_ranges(content, DummyWB()) named_ranges = read_named_ranges(content, DummyWB())
assert_equals(1, len(named_ranges)) xlnt_assert_equals(1, len(named_ranges))
ok_(isinstance(named_ranges[0], NamedRange)) ok_(isinstance(named_ranges[0], NamedRange))
assert_equals([(ws, "$U$16:$U$24"), (ws, "$V$28:$V$36")], named_ranges[0].destinations) xlnt_assert_equals([(ws, "$U$16:$U$24"), (ws, "$V$28:$V$36")], named_ranges[0].destinations)
} }
finally finally
{ {
@ -135,7 +135,7 @@ public:
try : try :
content = handle.read() content = handle.read()
named_ranges = read_named_ranges(content, DummyWB()) named_ranges = read_named_ranges(content, DummyWB())
assert_equals(["My Sheeet!$D$8"], [str(range) for range in named_ranges]) xlnt_assert_equals(["My Sheeet!$D$8"], [str(range) for range in named_ranges])
finally : finally :
handle.close()*/ handle.close()*/
} }
@ -149,7 +149,7 @@ public:
//void check_ranges(ws, count, range_name) //void check_ranges(ws, count, range_name)
//{ //{
// /*assert_equals(count, len(ws.range(range_name))) // /*xlnt_assert_equals(count, len(ws.range(range_name)))
// wb = load_workbook(os.path.join(DATADIR, "genuine", "merge_range.xlsx"), // wb = load_workbook(os.path.join(DATADIR, "genuine", "merge_range.xlsx"),
// use_iterators = False) // use_iterators = False)
@ -172,9 +172,9 @@ public:
cell = ws.range("TRAP_3") cell = ws.range("TRAP_3")
assert_equals("B15", cell.get_coordinate()) xlnt_assert_equals("B15", cell.get_coordinate())
assert_equals(10, cell.value)*/ xlnt_assert_equals(10, cell.value)*/
} }
void setUp() void setUp()
@ -192,20 +192,20 @@ public:
void test_has_ranges() void test_has_ranges()
{ {
/*ranges = wb.get_named_ranges() /*ranges = wb.get_named_ranges()
assert_equals(["MyRef", "MySheetRef", "MySheetRef", "MySheetValue", "MySheetValue", "MyValue"], [range.name for range in ranges])*/ xlnt_assert_equals(["MyRef", "MySheetRef", "MySheetRef", "MySheetValue", "MySheetValue", "MyValue"], [range.name for range in ranges])*/
} }
void test_workbook_has_normal_range() void test_workbook_has_normal_range()
{ {
/*normal_range = wb.get_named_range("MyRef") /*normal_range = wb.get_named_range("MyRef")
assert_equals("MyRef", normal_range.name)*/ xlnt_assert_equals("MyRef", normal_range.name)*/
} }
void test_workbook_has_value_range() void test_workbook_has_value_range()
{ {
/*value_range = wb.get_named_range("MyValue") /*value_range = wb.get_named_range("MyValue")
assert_equals("MyValue", value_range.name) xlnt_assert_equals("MyValue", value_range.name)
assert_equals("9.99", value_range.value)*/ xlnt_assert_equals("9.99", value_range.value)*/
} }
void test_worksheet_range() void test_worksheet_range()
@ -215,7 +215,7 @@ public:
void test_worksheet_range_error_on_value_range() void test_worksheet_range_error_on_value_range()
{ {
/*assert_raises(NamedRangeException, ws.range, "MyValue")*/ /*xlnt_assert_raises(NamedRangeException, ws.range, "MyValue")*/
} }
//void range_as_string(self, range, include_value = False) //void range_as_string(self, range, include_value = False)
@ -243,7 +243,7 @@ public:
void test_handles_scope() void test_handles_scope()
{ {
/*ranges = wb.get_named_ranges() /*ranges = wb.get_named_ranges()
assert_equals(["MyRef: Workbook", "MySheetRef: Sheet1", "MySheetRef: Sheet2", "MySheetValue: Sheet1", "MySheetValue: Sheet2", "MyValue: Workbook"], xlnt_assert_equals(["MyRef: Workbook", "MySheetRef: Sheet1", "MySheetRef: Sheet2", "MySheetValue: Sheet1", "MySheetValue: Sheet2", "MyValue: Workbook"],
[range_as_string(range) for range in ranges])*/ [range_as_string(range) for range in ranges])*/
} }
@ -253,7 +253,7 @@ public:
wb.save(FNAME) wb.save(FNAME)
wbcopy = load_workbook(FNAME) wbcopy = load_workbook(FNAME)
assert_equals(["MyRef: Workbook=[range]", "MySheetRef: Sheet1=[range]", "MySheetRef: Sheet2=[range]", "MySheetValue: Sheet1=3.33", "MySheetValue: Sheet2=14.4", "MyValue: Workbook=9.99"], xlnt_assert_equals(["MyRef: Workbook=[range]", "MySheetRef: Sheet1=[range]", "MySheetRef: Sheet2=[range]", "MySheetValue: Sheet1=3.33", "MySheetValue: Sheet2=14.4", "MyValue: Workbook=9.99"],
[range_as_string(range, include_value = True) for range in wbcopy.get_named_ranges()])*/ [range_as_string(range, include_value = True) for range in wbcopy.get_named_ranges()])*/
} }
}; };

View File

@ -79,7 +79,7 @@ public:
{ {
xlnt::workbook wb; xlnt::workbook wb;
const auto path = path_helper::test_file("3_default.xlsx"); const auto path = path_helper::test_file("3_default.xlsx");
assert(workbook_matches_file(wb, path)); xlnt_assert(workbook_matches_file(wb, path));
} }
void test_produce_simple_excel() void test_produce_simple_excel()
@ -147,25 +147,25 @@ public:
std::vector<std::uint8_t> temp_buffer; std::vector<std::uint8_t> temp_buffer;
wb.save(temp_buffer); wb.save(temp_buffer);
assert(!temp_buffer.empty()); xlnt_assert(!temp_buffer.empty());
} }
void test_save_after_sheet_deletion() void test_save_after_sheet_deletion()
{ {
xlnt::workbook workbook; xlnt::workbook workbook;
assert_equals(workbook.sheet_titles().size(), 1); xlnt_assert_equals(workbook.sheet_titles().size(), 1);
auto sheet = workbook.create_sheet(); auto sheet = workbook.create_sheet();
sheet.title("XXX1"); sheet.title("XXX1");
assert_equals(workbook.sheet_titles().size(), 2); xlnt_assert_equals(workbook.sheet_titles().size(), 2);
workbook.remove_sheet(workbook.sheet_by_title("XXX1")); workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
assert_equals(workbook.sheet_titles().size(), 1); xlnt_assert_equals(workbook.sheet_titles().size(), 1);
std::vector<std::uint8_t> temp_buffer; std::vector<std::uint8_t> temp_buffer;
assert_throws_nothing(workbook.save(temp_buffer)); xlnt_assert_throws_nothing(workbook.save(temp_buffer));
assert(!temp_buffer.empty()); xlnt_assert(!temp_buffer.empty());
} }
void test_write_comments_hyperlinks_formulae() void test_write_comments_hyperlinks_formulae()
@ -203,7 +203,7 @@ public:
sheet2.cell("C3").value(3); sheet2.cell("C3").value(3);
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx"); const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
assert(workbook_matches_file(wb, path)); xlnt_assert(workbook_matches_file(wb, path));
} }
void test_save_after_clear_all_formulae() void test_save_after_clear_all_formulae()
@ -213,13 +213,13 @@ public:
wb.load(path); wb.load(path);
auto ws1 = wb.sheet_by_index(0); auto ws1 = wb.sheet_by_index(0);
assert(ws1.cell("C1").has_formula()); xlnt_assert(ws1.cell("C1").has_formula());
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)"); xlnt_assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
ws1.cell("C1").clear_formula(); ws1.cell("C1").clear_formula();
auto ws2 = wb.sheet_by_index(1); auto ws2 = wb.sheet_by_index(1);
assert(ws2.cell("C1").has_formula()); xlnt_assert(ws2.cell("C1").has_formula());
assert_equals(ws2.cell("C1").formula(), "C2*C3"); xlnt_assert_equals(ws2.cell("C1").formula(), "C2*C3");
ws2.cell("C1").clear_formula(); ws2.cell("C1").clear_formula();
wb.save("clear_formulae.xlsx"); wb.save("clear_formulae.xlsx");
@ -229,35 +229,39 @@ public:
{ {
xlnt::workbook wb; xlnt::workbook wb;
const auto path = path_helper::test_file("1_powerpoint_presentation.xlsx"); const auto path = path_helper::test_file("1_powerpoint_presentation.xlsx");
assert_throws(wb.load(path), xlnt::invalid_file); xlnt_assert_throws(wb.load(path), xlnt::invalid_file);
} }
void test_decrypt_agile() void test_decrypt_agile()
{ {
xlnt::workbook wb; xlnt::workbook wb;
const auto path = path_helper::test_file("5_encrypted_agile.xlsx"); const auto path = path_helper::test_file("5_encrypted_agile.xlsx");
assert_throws_nothing(wb.load(path, "secret")); xlnt_assert_throws(wb.load(path, "incorrect"), xlnt::exception);
xlnt_assert_throws_nothing(wb.load(path, "secret"));
} }
void test_decrypt_libre_office() void test_decrypt_libre_office()
{ {
xlnt::workbook wb; xlnt::workbook wb;
const auto path = path_helper::test_file("6_encrypted_libre.xlsx"); const auto path = path_helper::test_file("6_encrypted_libre.xlsx");
assert_throws_nothing(wb.load(path, u8"пароль")); xlnt_assert_throws(wb.load(path, "incorrect"), xlnt::exception);
xlnt_assert_throws_nothing(wb.load(path, u8"пароль"));
} }
void test_decrypt_standard() void test_decrypt_standard()
{ {
xlnt::workbook wb; xlnt::workbook wb;
const auto path = path_helper::test_file("7_encrypted_standard.xlsx"); const auto path = path_helper::test_file("7_encrypted_standard.xlsx");
assert_throws_nothing(wb.load(path, "password")); xlnt_assert_throws(wb.load(path, "incorrect"), xlnt::exception);
xlnt_assert_throws_nothing(wb.load(path, "password"));
} }
void test_decrypt_numbers() void test_decrypt_numbers()
{ {
xlnt::workbook wb; xlnt::workbook wb;
const auto path = path_helper::test_file("8_encrypted_numbers.xlsx"); const auto path = path_helper::test_file("8_encrypted_numbers.xlsx");
assert_throws_nothing(wb.load(path, "secret")); xlnt_assert_throws(wb.load(path, "incorrect"), xlnt::exception);
xlnt_assert_throws_nothing(wb.load(path, "secret"));
} }
void test_read_unicode_filename() void test_read_unicode_filename()
@ -266,14 +270,14 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx"; const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
wb.load(path); wb.load(path);
assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!"); xlnt_assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif #endif
#ifndef __MINGW32__ #ifndef __MINGW32__
xlnt::workbook wb2; xlnt::workbook wb2;
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx"; const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
wb2.load(path2); wb2.load(path2);
assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!"); xlnt_assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif #endif
} }
@ -284,14 +288,14 @@ public:
wb.load(path); wb.load(path);
auto sheet1 = wb[0]; auto sheet1 = wb[0];
assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1"); xlnt_assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment"); xlnt_assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User"); xlnt_assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User");
auto sheet2 = wb[1]; auto sheet2 = wb[1];
assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1"); xlnt_assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment"); xlnt_assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User"); xlnt_assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User");
} }
void test_read_hyperlink() void test_read_hyperlink()
@ -301,19 +305,19 @@ public:
wb.load(path); wb.load(path);
auto ws1 = wb.sheet_by_index(0); auto ws1 = wb.sheet_by_index(0);
assert_equals(ws1.title(), "Sheet1"); xlnt_assert_equals(ws1.title(), "Sheet1");
assert(ws1.cell("A4").has_hyperlink()); xlnt_assert(ws1.cell("A4").has_hyperlink());
assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1"); xlnt_assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1");
assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/"); xlnt_assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
assert(ws1.cell("A5").has_hyperlink()); xlnt_assert(ws1.cell("A5").has_hyperlink());
assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/"); xlnt_assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/");
assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/"); xlnt_assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/");
//assert(ws1.cell("A6").has_hyperlink()); //xlnt_assert(ws1.cell("A6").has_hyperlink());
assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1"); xlnt_assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
//assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1"); //xlnt_assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1");
assert(ws1.cell("A7").has_hyperlink()); xlnt_assert(ws1.cell("A7").has_hyperlink());
assert_equals(ws1.cell("A7").value<std::string>(), "mailto:invalid@example.com?subject=important"); xlnt_assert_equals(ws1.cell("A7").value<std::string>(), "mailto:invalid@example.com?subject=important");
assert_equals(ws1.cell("A7").hyperlink(), "mailto:invalid@example.com?subject=important"); xlnt_assert_equals(ws1.cell("A7").hyperlink(), "mailto:invalid@example.com?subject=important");
} }
@ -324,18 +328,18 @@ public:
wb.load(path); wb.load(path);
auto ws1 = wb.sheet_by_index(0); auto ws1 = wb.sheet_by_index(0);
assert_equals(ws1.cell("C1").value<std::string>(), "ab"); xlnt_assert_equals(ws1.cell("C1").value<std::string>(), "ab");
assert(ws1.cell("C1").has_formula()); xlnt_assert(ws1.cell("C1").has_formula());
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)"); xlnt_assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
assert_equals(ws1.cell("C2").value<std::string>(), "a"); xlnt_assert_equals(ws1.cell("C2").value<std::string>(), "a");
assert_equals(ws1.cell("C3").value<std::string>(), "b"); xlnt_assert_equals(ws1.cell("C3").value<std::string>(), "b");
auto ws2 = wb.sheet_by_index(1); auto ws2 = wb.sheet_by_index(1);
assert_equals(ws2.cell("C1").value<int>(), 6); xlnt_assert_equals(ws2.cell("C1").value<int>(), 6);
assert(ws2.cell("C1").has_formula()); xlnt_assert(ws2.cell("C1").has_formula());
assert_equals(ws2.cell("C1").formula(), "C2*C3"); xlnt_assert_equals(ws2.cell("C1").formula(), "C2*C3");
assert_equals(ws2.cell("C2").value<int>(), 2); xlnt_assert_equals(ws2.cell("C2").value<int>(), 2);
assert_equals(ws2.cell("C3").value<int>(), 3); xlnt_assert_equals(ws2.cell("C3").value<int>(), 3);
} }
void test_read_headers_and_footers() void test_read_headers_and_footers()
@ -344,38 +348,38 @@ public:
wb.load(path_helper::test_file("11_print_settings.xlsx")); wb.load(path_helper::test_file("11_print_settings.xlsx"));
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.cell("A1").value<std::string>(), "header"); xlnt_assert_equals(ws.cell("A1").value<std::string>(), "header");
assert_equals(ws.cell("A2").value<std::string>(), "and"); xlnt_assert_equals(ws.cell("A2").value<std::string>(), "and");
assert_equals(ws.cell("A3").value<std::string>(), "footer"); xlnt_assert_equals(ws.cell("A3").value<std::string>(), "footer");
assert_equals(ws.cell("A4").value<std::string>(), "page1"); xlnt_assert_equals(ws.cell("A4").value<std::string>(), "page1");
assert_equals(ws.cell("A43").value<std::string>(), "page2"); xlnt_assert_equals(ws.cell("A43").value<std::string>(), "page2");
assert(ws.has_header_footer()); xlnt_assert(ws.has_header_footer());
assert(ws.header_footer().align_with_margins()); xlnt_assert(ws.header_footer().align_with_margins());
assert(ws.header_footer().scale_with_doc()); xlnt_assert(ws.header_footer().scale_with_doc());
assert(!ws.header_footer().different_first()); xlnt_assert(!ws.header_footer().different_first());
assert(!ws.header_footer().different_odd_even()); xlnt_assert(!ws.header_footer().different_odd_even());
assert(ws.header_footer().has_header(xlnt::header_footer::location::left)); xlnt_assert(ws.header_footer().has_header(xlnt::header_footer::location::left));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::left).plain_text(), "left header"); xlnt_assert_equals(ws.header_footer().header(xlnt::header_footer::location::left).plain_text(), "left header");
assert(ws.header_footer().has_header(xlnt::header_footer::location::center)); xlnt_assert(ws.header_footer().has_header(xlnt::header_footer::location::center));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::center).plain_text(), "center header"); xlnt_assert_equals(ws.header_footer().header(xlnt::header_footer::location::center).plain_text(), "center header");
assert(ws.header_footer().has_header(xlnt::header_footer::location::right)); xlnt_assert(ws.header_footer().has_header(xlnt::header_footer::location::right));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::right).plain_text(), "right header"); xlnt_assert_equals(ws.header_footer().header(xlnt::header_footer::location::right).plain_text(), "right header");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::left)); xlnt_assert(ws.header_footer().has_footer(xlnt::header_footer::location::left));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::left).plain_text(), "left && footer"); xlnt_assert_equals(ws.header_footer().footer(xlnt::header_footer::location::left).plain_text(), "left && footer");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::center)); xlnt_assert(ws.header_footer().has_footer(xlnt::header_footer::location::center));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::center).plain_text(), "center footer"); xlnt_assert_equals(ws.header_footer().footer(xlnt::header_footer::location::center).plain_text(), "center footer");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::right)); xlnt_assert(ws.header_footer().has_footer(xlnt::header_footer::location::right));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::right).plain_text(), "right footer"); xlnt_assert_equals(ws.header_footer().footer(xlnt::header_footer::location::right).plain_text(), "right footer");
} }
void test_read_custom_properties() void test_read_custom_properties()
{ {
xlnt::workbook wb; xlnt::workbook wb;
wb.load(path_helper::test_file("12_advanced_properties.xlsx")); wb.load(path_helper::test_file("12_advanced_properties.xlsx"));
assert(wb.has_custom_property("Client")); xlnt_assert(wb.has_custom_property("Client"));
assert_equals(wb.custom_property("Client").get<std::string>(), "me!"); xlnt_assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
} }
/// <summary> /// <summary>
@ -436,7 +440,7 @@ public:
for (const auto file : files) for (const auto file : files)
{ {
auto path = path_helper::test_file(file + ".xlsx"); auto path = path_helper::test_file(file + ".xlsx");
assert(round_trip_matches_rw(path)); xlnt_assert(round_trip_matches_rw(path));
} }
} }
@ -456,7 +460,7 @@ public:
auto password = std::string(file == "7_encrypted_standard" ? "password" auto password = std::string(file == "7_encrypted_standard" ? "password"
: file == "6_encrypted_libre" ? u8"пароль" : file == "6_encrypted_libre" ? u8"пароль"
: "secret"); : "secret");
assert(round_trip_matches_rw(path, password)); xlnt_assert(round_trip_matches_rw(path, password));
} }
} }
}; };

View File

@ -61,7 +61,7 @@ public:
void test_active_sheet() void test_active_sheet()
{ {
xlnt::workbook wb; xlnt::workbook wb;
assert_equals(wb.active_sheet(), wb[0]); xlnt_assert_equals(wb.active_sheet(), wb[0]);
} }
void test_create_sheet() void test_create_sheet()
@ -69,7 +69,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto new_sheet = wb.create_sheet(); auto new_sheet = wb.create_sheet();
auto last = std::distance(wb.begin(), wb.end()) - 1; auto last = std::distance(wb.begin(), wb.end()) - 1;
assert_equals(new_sheet, wb[last]); xlnt_assert_equals(new_sheet, wb[last]);
} }
void test_add_correct_sheet() void test_add_correct_sheet()
@ -78,17 +78,17 @@ public:
auto new_sheet = wb.create_sheet(); auto new_sheet = wb.create_sheet();
new_sheet.cell("A6").value(1.498); new_sheet.cell("A6").value(1.498);
wb.copy_sheet(new_sheet); wb.copy_sheet(new_sheet);
assert(wb[1].compare(wb[2], false)); xlnt_assert(wb[1].compare(wb[2], false));
wb.create_sheet().cell("A6").value(1.497); wb.create_sheet().cell("A6").value(1.497);
assert(!wb[1].compare(wb[3], false)); xlnt_assert(!wb[1].compare(wb[3], false));
} }
void test_add_sheet_from_other_workbook() void test_add_sheet_from_other_workbook()
{ {
xlnt::workbook wb1, wb2; xlnt::workbook wb1, wb2;
auto new_sheet = wb1.active_sheet(); auto new_sheet = wb1.active_sheet();
assert_throws(wb2.copy_sheet(new_sheet), xlnt::invalid_parameter); xlnt_assert_throws(wb2.copy_sheet(new_sheet), xlnt::invalid_parameter);
assert_throws(wb2.index(new_sheet), std::runtime_error); xlnt_assert_throws(wb2.index(new_sheet), std::runtime_error);
} }
void test_add_sheet_at_index() void test_add_sheet_at_index()
@ -98,10 +98,10 @@ public:
ws.cell("B3").value(2); ws.cell("B3").value(2);
ws.title("Active"); ws.title("Active");
wb.copy_sheet(ws, 0); wb.copy_sheet(ws, 0);
assert_equals(wb.sheet_titles().at(0), "Sheet1"); xlnt_assert_equals(wb.sheet_titles().at(0), "Sheet1");
assert_equals(wb.sheet_by_index(0).cell("B3").value<int>(), 2); xlnt_assert_equals(wb.sheet_by_index(0).cell("B3").value<int>(), 2);
assert_equals(wb.sheet_titles().at(1), "Active"); xlnt_assert_equals(wb.sheet_titles().at(1), "Active");
assert_equals(wb.sheet_by_index(1).cell("B3").value<int>(), 2); xlnt_assert_equals(wb.sheet_by_index(1).cell("B3").value<int>(), 2);
} }
void test_remove_sheet() void test_remove_sheet()
@ -110,8 +110,8 @@ public:
auto new_sheet = wb.create_sheet(0); auto new_sheet = wb.create_sheet(0);
new_sheet.title("removed"); new_sheet.title("removed");
wb.remove_sheet(new_sheet); wb.remove_sheet(new_sheet);
assert(!wb.contains("removed")); xlnt_assert(!wb.contains("removed"));
assert_throws(wb.remove_sheet(wb2.active_sheet()), std::runtime_error); xlnt_assert_throws(wb.remove_sheet(wb2.active_sheet()), std::runtime_error);
} }
void test_get_sheet_by_title() void test_get_sheet_by_title()
@ -121,10 +121,10 @@ public:
std::string title = "my sheet"; std::string title = "my sheet";
new_sheet.title(title); new_sheet.title(title);
auto found_sheet = wb.sheet_by_title(title); auto found_sheet = wb.sheet_by_title(title);
assert_equals(new_sheet, found_sheet); xlnt_assert_equals(new_sheet, found_sheet);
assert_throws(wb.sheet_by_title("error"), xlnt::key_not_found); xlnt_assert_throws(wb.sheet_by_title("error"), xlnt::key_not_found);
const auto &wb_const = wb; const auto &wb_const = wb;
assert_throws(wb_const.sheet_by_title("error"), xlnt::key_not_found); xlnt_assert_throws(wb_const.sheet_by_title("error"), xlnt::key_not_found);
} }
void test_get_sheet_by_title_const() void test_get_sheet_by_title_const()
@ -135,21 +135,21 @@ public:
new_sheet.title(title); new_sheet.title(title);
const xlnt::workbook& wbconst = wb; const xlnt::workbook& wbconst = wb;
auto found_sheet = wbconst.sheet_by_title(title); auto found_sheet = wbconst.sheet_by_title(title);
assert_equals(new_sheet, found_sheet); xlnt_assert_equals(new_sheet, found_sheet);
} }
void test_index_operator() // test_getitem void test_index_operator() // test_getitem
{ {
xlnt::workbook wb; xlnt::workbook wb;
assert_throws_nothing(wb["Sheet1"]); xlnt_assert_throws_nothing(wb["Sheet1"]);
assert_throws(wb["NotThere"], xlnt::key_not_found); xlnt_assert_throws(wb["NotThere"], xlnt::key_not_found);
} }
void test_contains() void test_contains()
{ {
xlnt::workbook wb; xlnt::workbook wb;
assert(wb.contains("Sheet1")); xlnt_assert(wb.contains("Sheet1"));
assert(!wb.contains("NotThere")); xlnt_assert(!wb.contains("NotThere"));
} }
void test_iter() void test_iter()
@ -158,7 +158,7 @@ public:
for(auto ws : wb) for(auto ws : wb)
{ {
assert_equals(ws.title(), "Sheet1"); xlnt_assert_equals(ws.title(), "Sheet1");
} }
} }
@ -169,10 +169,10 @@ public:
wb.create_sheet().title("2"); wb.create_sheet().title("2");
auto sheet_index = wb.index(wb.sheet_by_title("1")); auto sheet_index = wb.index(wb.sheet_by_title("1"));
assert_equals(sheet_index, 1); xlnt_assert_equals(sheet_index, 1);
sheet_index = wb.index(wb.sheet_by_title("2")); sheet_index = wb.index(wb.sheet_by_title("2"));
assert_equals(sheet_index, 2); xlnt_assert_equals(sheet_index, 2);
} }
void test_get_sheet_names() void test_get_sheet_names()
@ -182,7 +182,7 @@ public:
const std::vector<std::string> expected_titles = { "Sheet1", "test_get_sheet_titles" }; const std::vector<std::string> expected_titles = { "Sheet1", "test_get_sheet_titles" };
assert_equals(wb.sheet_titles(), expected_titles); xlnt_assert_equals(wb.sheet_titles(), expected_titles);
} }
void test_add_named_range() void test_add_named_range()
@ -190,9 +190,9 @@ public:
xlnt::workbook wb, wb2; xlnt::workbook wb, wb2;
auto new_sheet = wb.create_sheet(); auto new_sheet = wb.create_sheet();
wb.create_named_range("test_nr", new_sheet, "A1"); wb.create_named_range("test_nr", new_sheet, "A1");
assert(new_sheet.has_named_range("test_nr")); xlnt_assert(new_sheet.has_named_range("test_nr"));
assert(wb.has_named_range("test_nr")); xlnt_assert(wb.has_named_range("test_nr"));
assert_throws(wb2.create_named_range("test_nr", new_sheet, "A1"), std::runtime_error); xlnt_assert_throws(wb2.create_named_range("test_nr", new_sheet, "A1"), std::runtime_error);
} }
void test_get_named_range() void test_get_named_range()
@ -202,8 +202,8 @@ public:
wb.create_named_range("test_nr", new_sheet, "A1"); wb.create_named_range("test_nr", new_sheet, "A1");
auto found_range = wb.named_range("test_nr"); auto found_range = wb.named_range("test_nr");
auto expected_range = new_sheet.range("A1"); auto expected_range = new_sheet.range("A1");
assert_equals(expected_range, found_range); xlnt_assert_equals(expected_range, found_range);
assert_throws(wb.named_range("test_nr2"), std::runtime_error); xlnt_assert_throws(wb.named_range("test_nr2"), std::runtime_error);
} }
void test_remove_named_range() void test_remove_named_range()
@ -212,9 +212,9 @@ public:
auto new_sheet = wb.create_sheet(); auto new_sheet = wb.create_sheet();
wb.create_named_range("test_nr", new_sheet, "A1"); wb.create_named_range("test_nr", new_sheet, "A1");
wb.remove_named_range("test_nr"); wb.remove_named_range("test_nr");
assert(!new_sheet.has_named_range("test_nr")); xlnt_assert(!new_sheet.has_named_range("test_nr"));
assert(!wb.has_named_range("test_nr")); xlnt_assert(!wb.has_named_range("test_nr"));
assert_throws(wb.remove_named_range("test_nr2"), std::runtime_error); xlnt_assert_throws(wb.remove_named_range("test_nr2"), std::runtime_error);
} }
void test_post_increment_iterator() void test_post_increment_iterator()
@ -226,19 +226,19 @@ public:
auto iter = wb.begin(); auto iter = wb.begin();
assert_equals((*(iter++)).title(), "Sheet1"); xlnt_assert_equals((*(iter++)).title(), "Sheet1");
assert_equals((*(iter++)).title(), "Sheet2"); xlnt_assert_equals((*(iter++)).title(), "Sheet2");
assert_equals((*(iter++)).title(), "Sheet3"); xlnt_assert_equals((*(iter++)).title(), "Sheet3");
assert_equals(iter, wb.end()); xlnt_assert_equals(iter, wb.end());
const auto wb_const = wb; const auto wb_const = wb;
auto const_iter = wb_const.begin(); auto const_iter = wb_const.begin();
assert_equals((*(const_iter++)).title(), "Sheet1"); xlnt_assert_equals((*(const_iter++)).title(), "Sheet1");
assert_equals((*(const_iter++)).title(), "Sheet2"); xlnt_assert_equals((*(const_iter++)).title(), "Sheet2");
assert_equals((*(const_iter++)).title(), "Sheet3"); xlnt_assert_equals((*(const_iter++)).title(), "Sheet3");
assert_equals(const_iter, wb_const.end()); xlnt_assert_equals(const_iter, wb_const.end());
} }
void test_copy_iterator() void test_copy_iterator()
@ -249,32 +249,32 @@ public:
wb.create_sheet().title("Sheet3"); wb.create_sheet().title("Sheet3");
auto iter = wb.begin(); auto iter = wb.begin();
assert_equals((*iter).title(), "Sheet1"); xlnt_assert_equals((*iter).title(), "Sheet1");
iter++; iter++;
assert_equals((*iter).title(), "Sheet2"); xlnt_assert_equals((*iter).title(), "Sheet2");
auto copy = wb.begin(); auto copy = wb.begin();
copy = iter; copy = iter;
assert_equals((*iter).title(), "Sheet2"); xlnt_assert_equals((*iter).title(), "Sheet2");
assert_equals(iter, copy); xlnt_assert_equals(iter, copy);
iter++; iter++;
assert_equals((*iter).title(), "Sheet3"); xlnt_assert_equals((*iter).title(), "Sheet3");
assert_differs(iter, copy); xlnt_assert_differs(iter, copy);
copy++; copy++;
assert_equals((*iter).title(), "Sheet3"); xlnt_assert_equals((*iter).title(), "Sheet3");
assert_equals(iter, copy); xlnt_assert_equals(iter, copy);
} }
void test_manifest() void test_manifest()
{ {
xlnt::manifest m; xlnt::manifest m;
assert(!m.has_default_type("xml")); xlnt_assert(!m.has_default_type("xml"));
assert_throws(m.default_type("xml"), xlnt::key_not_found); xlnt_assert_throws(m.default_type("xml"), xlnt::key_not_found);
assert(!m.has_relationship(xlnt::path("/"), xlnt::relationship_type::office_document)); xlnt_assert(!m.has_relationship(xlnt::path("/"), xlnt::relationship_type::office_document));
assert(m.relationships(xlnt::path("xl/workbook.xml")).empty()); xlnt_assert(m.relationships(xlnt::path("xl/workbook.xml")).empty());
} }
void test_memory() void test_memory()
@ -282,10 +282,10 @@ public:
xlnt::workbook wb, wb2; xlnt::workbook wb, wb2;
wb.active_sheet().title("swap"); wb.active_sheet().title("swap");
std::swap(wb, wb2); std::swap(wb, wb2);
assert_equals(wb.active_sheet().title(), "Sheet1"); xlnt_assert_equals(wb.active_sheet().title(), "Sheet1");
assert_equals(wb2.active_sheet().title(), "swap"); xlnt_assert_equals(wb2.active_sheet().title(), "swap");
wb = wb2; wb = wb2;
assert_equals(wb.active_sheet().title(), "swap"); xlnt_assert_equals(wb.active_sheet().title(), "swap");
} }
void test_clear() void test_clear()
@ -294,34 +294,34 @@ public:
xlnt::style s = wb.create_style("s"); xlnt::style s = wb.create_style("s");
wb.active_sheet().cell("B2").value("B2"); wb.active_sheet().cell("B2").value("B2");
wb.active_sheet().cell("B2").style(s); wb.active_sheet().cell("B2").style(s);
assert(wb.active_sheet().cell("B2").has_style()); xlnt_assert(wb.active_sheet().cell("B2").has_style());
wb.clear_styles(); wb.clear_styles();
assert(!wb.active_sheet().cell("B2").has_style()); xlnt_assert(!wb.active_sheet().cell("B2").has_style());
xlnt::format format = wb.create_format(); xlnt::format format = wb.create_format();
xlnt::font font; xlnt::font font;
font.size(41); font.size(41);
format.font(font, true); format.font(font, true);
wb.active_sheet().cell("B2").format(format); wb.active_sheet().cell("B2").format(format);
assert(wb.active_sheet().cell("B2").has_format()); xlnt_assert(wb.active_sheet().cell("B2").has_format());
wb.clear_formats(); wb.clear_formats();
assert(!wb.active_sheet().cell("B2").has_format()); xlnt_assert(!wb.active_sheet().cell("B2").has_format());
wb.clear(); wb.clear();
assert(wb.sheet_titles().empty()); xlnt_assert(wb.sheet_titles().empty());
} }
void test_comparison() void test_comparison()
{ {
xlnt::workbook wb, wb2; xlnt::workbook wb, wb2;
assert(wb == wb); xlnt_assert(wb == wb);
assert(!(wb != wb)); xlnt_assert(!(wb != wb));
assert(!(wb == wb2)); xlnt_assert(!(wb == wb2));
assert(wb != wb2); xlnt_assert(wb != wb2);
const auto &wb_const = wb; const auto &wb_const = wb;
//TODO these aren't tests... //TODO these aren't tests...
wb_const.manifest(); wb_const.manifest();
assert(wb.has_theme()); xlnt_assert(wb.has_theme());
wb.create_style("style1"); wb.create_style("style1");
wb.style("style1"); wb.style("style1");

View File

@ -40,32 +40,32 @@ public:
{ {
xlnt::page_setup ps; xlnt::page_setup ps;
assert_equals(ps.paper_size(), xlnt::paper_size::letter); xlnt_assert_equals(ps.paper_size(), xlnt::paper_size::letter);
ps.paper_size(xlnt::paper_size::executive); ps.paper_size(xlnt::paper_size::executive);
assert_equals(ps.paper_size(), xlnt::paper_size::executive); xlnt_assert_equals(ps.paper_size(), xlnt::paper_size::executive);
assert_equals(ps.orientation(), xlnt::orientation::portrait); xlnt_assert_equals(ps.orientation(), xlnt::orientation::portrait);
ps.orientation(xlnt::orientation::landscape); ps.orientation(xlnt::orientation::landscape);
assert_equals(ps.orientation(), xlnt::orientation::landscape); xlnt_assert_equals(ps.orientation(), xlnt::orientation::landscape);
assert(!ps.fit_to_page()); xlnt_assert(!ps.fit_to_page());
ps.fit_to_page(true); ps.fit_to_page(true);
assert(ps.fit_to_page()); xlnt_assert(ps.fit_to_page());
assert(!ps.fit_to_height()); xlnt_assert(!ps.fit_to_height());
ps.fit_to_height(true); ps.fit_to_height(true);
assert(ps.fit_to_height()); xlnt_assert(ps.fit_to_height());
assert(!ps.fit_to_width()); xlnt_assert(!ps.fit_to_width());
ps.fit_to_width(true); ps.fit_to_width(true);
assert(ps.fit_to_width()); xlnt_assert(ps.fit_to_width());
assert(!ps.horizontal_centered()); xlnt_assert(!ps.horizontal_centered());
ps.horizontal_centered(true); ps.horizontal_centered(true);
assert(ps.horizontal_centered()); xlnt_assert(ps.horizontal_centered());
assert(!ps.vertical_centered()); xlnt_assert(!ps.vertical_centered());
ps.vertical_centered(true); ps.vertical_centered(true);
assert(ps.vertical_centered()); xlnt_assert(ps.vertical_centered());
} }
}; };

View File

@ -55,15 +55,15 @@ public:
ws.range("A1:A10").font(xlnt::font().name("Arial")); ws.range("A1:A10").font(xlnt::font().name("Arial"));
ws.range("A1:J1").font(xlnt::font().bold(true)); ws.range("A1:J1").font(xlnt::font().bold(true));
assert_equals(ws.cell("A1").font().name(), "Calibri"); xlnt_assert_equals(ws.cell("A1").font().name(), "Calibri");
assert(ws.cell("A1").font().bold()); xlnt_assert(ws.cell("A1").font().bold());
assert_equals(ws.cell("A2").font().name(), "Arial"); xlnt_assert_equals(ws.cell("A2").font().name(), "Arial");
assert(!ws.cell("A2").font().bold()); xlnt_assert(!ws.cell("A2").font().bold());
assert_equals(ws.cell("B1").font().name(), "Calibri"); xlnt_assert_equals(ws.cell("B1").font().name(), "Calibri");
assert(ws.cell("B1").font().bold()); xlnt_assert(ws.cell("B1").font().bold());
assert(!ws.cell("B2").has_format()); xlnt_assert(!ws.cell("B2").has_format());
} }
}; };

View File

@ -99,7 +99,7 @@ public:
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert(ws.workbook() == wb); xlnt_assert(ws.workbook() == wb);
} }
void test_cell() void test_cell()
@ -107,12 +107,12 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1)); auto cell = ws.cell(xlnt::cell_reference(1, 1));
assert_equals(cell.reference(), "A1"); xlnt_assert_equals(cell.reference(), "A1");
} }
void test_invalid_cell() void test_invalid_cell()
{ {
assert_throws(xlnt::cell_reference(xlnt::column_t((xlnt::column_t::index_t)0), 0), xlnt_assert_throws(xlnt::cell_reference(xlnt::column_t((xlnt::column_t::index_t)0), 0),
xlnt::invalid_cell_reference); xlnt::invalid_cell_reference);
} }
@ -121,9 +121,9 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals("A1:A1", ws.calculate_dimension()); xlnt_assert_equals("A1:A1", ws.calculate_dimension());
ws.cell("B12").value("AAA"); ws.cell("B12").value("AAA");
assert_equals("B12:B12", ws.calculate_dimension()); xlnt_assert_equals("B12:B12", ws.calculate_dimension());
} }
void test_fill_rows() void test_fill_rows()
@ -138,14 +138,14 @@ public:
ws.cell("A1").value("first"); ws.cell("A1").value("first");
ws.cell("C9").value("last"); ws.cell("C9").value("last");
assert_equals(ws.calculate_dimension(), "A1:C9"); xlnt_assert_equals(ws.calculate_dimension(), "A1:C9");
assert_equals(ws.rows(false)[row][column].reference(), coordinate); xlnt_assert_equals(ws.rows(false)[row][column].reference(), coordinate);
row = 8; row = 8;
column = 2; column = 2;
coordinate = "C9"; coordinate = "C9";
assert_equals(ws.rows(false)[row][column].reference(), coordinate); xlnt_assert_equals(ws.rows(false)[row][column].reference(), coordinate);
} }
void test_get_named_range() void test_get_named_range()
@ -154,22 +154,22 @@ public:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
wb.create_named_range("test_range", ws, "C5"); wb.create_named_range("test_range", ws, "C5");
auto xlrange = ws.named_range("test_range"); auto xlrange = ws.named_range("test_range");
assert_equals(1, xlrange.length()); xlnt_assert_equals(1, xlrange.length());
assert_equals(1, xlrange[0].length()); xlnt_assert_equals(1, xlrange[0].length());
assert_equals(5, xlrange[0][0].row()); xlnt_assert_equals(5, xlrange[0][0].row());
ws.create_named_range("test_range2", "C6"); ws.create_named_range("test_range2", "C6");
auto xlrange2 = ws.named_range("test_range2"); auto xlrange2 = ws.named_range("test_range2");
assert_equals(1, xlrange2.length()); xlnt_assert_equals(1, xlrange2.length());
assert_equals(1, xlrange2[0].length()); xlnt_assert_equals(1, xlrange2[0].length());
assert_equals(6, xlrange2[0][0].row()); xlnt_assert_equals(6, xlrange2[0][0].row());
} }
void test_get_bad_named_range() void test_get_bad_named_range()
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_throws(ws.named_range("bad_range"), xlnt::key_not_found); xlnt_assert_throws(ws.named_range("bad_range"), xlnt::key_not_found);
} }
void test_get_named_range_wrong_sheet() void test_get_named_range_wrong_sheet()
@ -180,14 +180,14 @@ public:
auto ws1 = wb[0]; auto ws1 = wb[0];
auto ws2 = wb[1]; auto ws2 = wb[1];
wb.create_named_range("wrong_sheet_range", ws1, "C5"); wb.create_named_range("wrong_sheet_range", ws1, "C5");
assert_throws(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found); xlnt_assert_throws(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found);
} }
void test_remove_named_range_bad() void test_remove_named_range_bad()
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_throws(ws.remove_named_range("bad_range"), std::runtime_error); xlnt_assert_throws(ws.remove_named_range("bad_range"), std::runtime_error);
} }
void test_cell_alternate_coordinates() void test_cell_alternate_coordinates()
@ -195,7 +195,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(4, 8)); auto cell = ws.cell(xlnt::cell_reference(4, 8));
assert_equals(cell.reference(), "D8"); xlnt_assert_equals(cell.reference(), "D8");
} }
// void test_cell_insufficient_coordinates() {} // void test_cell_insufficient_coordinates() {}
@ -208,8 +208,8 @@ public:
auto c_range_name = ws.named_range("test_range_single"); auto c_range_name = ws.named_range("test_range_single");
auto c_range_coord = ws.range("B12"); auto c_range_coord = ws.range("B12");
auto c_cell = ws.cell("B12"); auto c_cell = ws.cell("B12");
assert_equals(c_range_coord, c_range_name); xlnt_assert_equals(c_range_coord, c_range_name);
assert(c_range_coord[0][0] == c_cell); xlnt_assert(c_range_coord[0][0] == c_cell);
} }
void test_hyperlink_value() void test_hyperlink_value()
@ -217,11 +217,11 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.cell("A1").hyperlink("http://test.com"); ws.cell("A1").hyperlink("http://test.com");
assert_equals(ws.cell("A1").hyperlink(), "http://test.com"); xlnt_assert_equals(ws.cell("A1").hyperlink(), "http://test.com");
assert_equals(ws.cell("A1").value<std::string>(), ""); xlnt_assert_equals(ws.cell("A1").value<std::string>(), "");
ws.cell("A1").value("test"); ws.cell("A1").value("test");
assert_equals("test", ws.cell("A1").value<std::string>()); xlnt_assert_equals("test", ws.cell("A1").value<std::string>());
assert_equals(ws.cell("A1").hyperlink(), "http://test.com"); xlnt_assert_equals(ws.cell("A1").hyperlink(), "http://test.com");
} }
void test_rows() void test_rows()
@ -234,14 +234,14 @@ public:
auto rows = ws.rows(); auto rows = ws.rows();
assert_equals(rows.length(), 9); xlnt_assert_equals(rows.length(), 9);
auto first_row = rows[0]; auto first_row = rows[0];
auto last_row = rows[8]; auto last_row = rows[8];
assert_equals(first_row[0].value<std::string>(), "first"); xlnt_assert_equals(first_row[0].value<std::string>(), "first");
assert_equals(first_row[0].reference(), "A1"); xlnt_assert_equals(first_row[0].reference(), "A1");
assert_equals(last_row[2].value<std::string>(), "last"); xlnt_assert_equals(last_row[2].value<std::string>(), "last");
} }
void test_no_rows() void test_no_rows()
@ -249,8 +249,8 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.rows().length(), 1); xlnt_assert_equals(ws.rows().length(), 1);
assert_equals(ws.rows()[0].length(), 1); xlnt_assert_equals(ws.rows()[0].length(), 1);
} }
void test_no_cols() void test_no_cols()
@ -258,8 +258,8 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.columns().length(), 1); xlnt_assert_equals(ws.columns().length(), 1);
assert_equals(ws.columns()[0].length(), 1); xlnt_assert_equals(ws.columns()[0].length(), 1);
} }
void test_one_cell() void test_one_cell()
@ -269,9 +269,9 @@ public:
auto cell = ws.cell("A1"); auto cell = ws.cell("A1");
assert_equals(ws.columns().length(), 1); xlnt_assert_equals(ws.columns().length(), 1);
assert_equals(ws.columns()[0].length(), 1); xlnt_assert_equals(ws.columns()[0].length(), 1);
assert_equals(ws.columns()[0][0], cell); xlnt_assert_equals(ws.columns()[0][0], cell);
} }
// void test_by_col() {} // void test_by_col() {}
@ -286,10 +286,10 @@ public:
auto cols = ws.columns(); auto cols = ws.columns();
assert_equals(cols.length(), 3); xlnt_assert_equals(cols.length(), 3);
assert_equals(cols[0][0].value<std::string>(), "first"); xlnt_assert_equals(cols[0][0].value<std::string>(), "first");
assert_equals(cols[2][8].value<std::string>(), "last"); xlnt_assert_equals(cols[2][8].value<std::string>(), "last");
} }
void test_auto_filter() void test_auto_filter()
@ -298,13 +298,13 @@ public:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.auto_filter(ws.range("a1:f1")); ws.auto_filter(ws.range("a1:f1"));
assert_equals(ws.auto_filter(), "A1:F1"); xlnt_assert_equals(ws.auto_filter(), "A1:F1");
ws.clear_auto_filter(); ws.clear_auto_filter();
assert(!ws.has_auto_filter()); xlnt_assert(!ws.has_auto_filter());
ws.auto_filter("c1:g9"); ws.auto_filter("c1:g9");
assert_equals(ws.auto_filter(), "C1:G9"); xlnt_assert_equals(ws.auto_filter(), "C1:G9");
} }
void test_getitem() void test_getitem()
@ -312,8 +312,8 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
xlnt::cell cell = ws[xlnt::cell_reference("A1")]; xlnt::cell cell = ws[xlnt::cell_reference("A1")];
assert_equals(cell.reference().to_string(), "A1"); xlnt_assert_equals(cell.reference().to_string(), "A1");
assert_equals(cell.data_type(), xlnt::cell::type::null); xlnt_assert_equals(cell.data_type(), xlnt::cell::type::null);
} }
void test_setitem() void test_setitem()
@ -321,7 +321,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws[xlnt::cell_reference("A12")].value(5); ws[xlnt::cell_reference("A12")].value(5);
assert(ws[xlnt::cell_reference("A12")].value<int>() == 5); xlnt_assert(ws[xlnt::cell_reference("A12")].value<int>() == 5);
} }
void test_getslice() void test_getslice()
@ -329,10 +329,10 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto cell_range = ws.range("A1:B2"); auto cell_range = ws.range("A1:B2");
assert_equals(cell_range[0][0], ws.cell("A1")); xlnt_assert_equals(cell_range[0][0], ws.cell("A1"));
assert_equals(cell_range[1][0], ws.cell("A2")); xlnt_assert_equals(cell_range[1][0], ws.cell("A2"));
assert_equals(cell_range[0][1], ws.cell("B1")); xlnt_assert_equals(cell_range[0][1], ws.cell("B1"));
assert_equals(cell_range[1][1], ws.cell("B2")); xlnt_assert_equals(cell_range[1][1], ws.cell("B2"));
} }
void test_freeze() void test_freeze()
@ -341,16 +341,16 @@ public:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.freeze_panes(ws.cell("b2")); ws.freeze_panes(ws.cell("b2"));
assert_equals(ws.frozen_panes(), "B2"); xlnt_assert_equals(ws.frozen_panes(), "B2");
ws.unfreeze_panes(); ws.unfreeze_panes();
assert(!ws.has_frozen_panes()); xlnt_assert(!ws.has_frozen_panes());
ws.freeze_panes("c5"); ws.freeze_panes("c5");
assert_equals(ws.frozen_panes(), "C5"); xlnt_assert_equals(ws.frozen_panes(), "C5");
ws.freeze_panes(ws.cell("A1")); ws.freeze_panes(ws.cell("A1"));
assert(!ws.has_frozen_panes()); xlnt_assert(!ws.has_frozen_panes());
} }
void test_merged_cells_lookup() void test_merged_cells_lookup()
@ -360,12 +360,12 @@ public:
ws.cell("A2").value("test"); ws.cell("A2").value("test");
ws.merge_cells("A1:N50"); ws.merge_cells("A1:N50");
auto all_merged = ws.merged_ranges(); auto all_merged = ws.merged_ranges();
assert_equals(all_merged.size(), 1); xlnt_assert_equals(all_merged.size(), 1);
auto merged = ws.range(all_merged[0]); auto merged = ws.range(all_merged[0]);
assert(merged.contains("A1")); xlnt_assert(merged.contains("A1"));
assert(merged.contains("N50")); xlnt_assert(merged.contains("N50"));
assert(!merged.contains("A51")); xlnt_assert(!merged.contains("A51"));
assert(!merged.contains("O1")); xlnt_assert(!merged.contains("O1"));
} }
@ -373,7 +373,7 @@ public:
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.merged_ranges().size(), 0); xlnt_assert_equals(ws.merged_ranges().size(), 0);
} }
void test_merge_range_string() void test_merge_range_string()
@ -384,8 +384,8 @@ public:
ws.cell("D4").value(16); ws.cell("D4").value(16);
ws.merge_cells("A1:D4"); ws.merge_cells("A1:D4");
std::vector<xlnt::range_reference> expected = { xlnt::range_reference("A1:D4") }; std::vector<xlnt::range_reference> expected = { xlnt::range_reference("A1:D4") };
assert_equals(ws.merged_ranges(), expected); xlnt_assert_equals(ws.merged_ranges(), expected);
assert(!ws.cell("D4").has_value()); xlnt_assert(!ws.cell("D4").has_value());
} }
void test_unmerge_bad() void test_unmerge_bad()
@ -393,7 +393,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_throws(ws.unmerge_cells("A1:D3"), std::runtime_error); xlnt_assert_throws(ws.unmerge_cells("A1:D3"), std::runtime_error);
} }
void test_unmerge_range_string() void test_unmerge_range_string()
@ -401,9 +401,9 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.merge_cells("A1:D4"); ws.merge_cells("A1:D4");
assert_equals(ws.merged_ranges().size(), 1); xlnt_assert_equals(ws.merged_ranges().size(), 1);
ws.unmerge_cells("A1:D4"); ws.unmerge_cells("A1:D4");
assert_equals(ws.merged_ranges().size(), 0); xlnt_assert_equals(ws.merged_ranges().size(), 0);
} }
void test_print_titles_old() void test_print_titles_old()
@ -412,11 +412,11 @@ public:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.print_title_rows(3); ws.print_title_rows(3);
assert_equals(ws.print_titles(), "Sheet1!1:3"); xlnt_assert_equals(ws.print_titles(), "Sheet1!1:3");
auto ws2 = wb.create_sheet(); auto ws2 = wb.create_sheet();
ws2.print_title_cols(4); ws2.print_title_cols(4);
assert_equals(ws2.print_titles(), "Sheet2!A:D"); xlnt_assert_equals(ws2.print_titles(), "Sheet2!A:D");
} }
void test_print_titles_new() void test_print_titles_new()
@ -425,16 +425,16 @@ public:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.print_title_rows(4); ws.print_title_rows(4);
assert_equals(ws.print_titles(), "Sheet1!1:4"); xlnt_assert_equals(ws.print_titles(), "Sheet1!1:4");
auto ws2 = wb.create_sheet(); auto ws2 = wb.create_sheet();
ws2.print_title_cols("F"); ws2.print_title_cols("F");
assert_equals(ws2.print_titles(), "Sheet2!A:F"); xlnt_assert_equals(ws2.print_titles(), "Sheet2!A:F");
auto ws3 = wb.create_sheet(); auto ws3 = wb.create_sheet();
ws3.print_title_rows(2, 3); ws3.print_title_rows(2, 3);
ws3.print_title_cols("C", "D"); ws3.print_title_cols("C", "D");
assert_equals(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D"); xlnt_assert_equals(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D");
} }
void test_print_area() void test_print_area()
@ -442,7 +442,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.print_area("A1:F5"); ws.print_area("A1:F5");
assert_equals(ws.print_area(), "$A$1:$F$5"); xlnt_assert_equals(ws.print_area(), "$A$1:$F$5");
} }
void test_freeze_panes_horiz() void test_freeze_panes_horiz()
@ -452,14 +452,14 @@ public:
ws.freeze_panes("A4"); ws.freeze_panes("A4");
auto view = ws.view(); auto view = ws.view();
assert_equals(view.selections().size(), 2); xlnt_assert_equals(view.selections().size(), 2);
assert_equals(view.selections()[0].active_cell(), "A3"); xlnt_assert_equals(view.selections()[0].active_cell(), "A3");
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::bottom_left); xlnt_assert_equals(view.selections()[0].pane(), xlnt::pane_corner::bottom_left);
assert_equals(view.selections()[0].sqref(), "A1"); xlnt_assert_equals(view.selections()[0].sqref(), "A1");
assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_left); xlnt_assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_left);
assert_equals(view.pane().state, xlnt::pane_state::frozen); xlnt_assert_equals(view.pane().state, xlnt::pane_state::frozen);
assert_equals(view.pane().top_left_cell.get(), "A4"); xlnt_assert_equals(view.pane().top_left_cell.get(), "A4");
assert_equals(view.pane().y_split, 3); xlnt_assert_equals(view.pane().y_split, 3);
} }
void test_freeze_panes_vert() void test_freeze_panes_vert()
@ -469,14 +469,14 @@ public:
ws.freeze_panes("D1"); ws.freeze_panes("D1");
auto view = ws.view(); auto view = ws.view();
assert_equals(view.selections().size(), 2); xlnt_assert_equals(view.selections().size(), 2);
assert_equals(view.selections()[0].active_cell(), "C1"); xlnt_assert_equals(view.selections()[0].active_cell(), "C1");
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right); xlnt_assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right);
assert_equals(view.selections()[0].sqref(), "A1"); xlnt_assert_equals(view.selections()[0].sqref(), "A1");
assert_equals(view.pane().active_pane, xlnt::pane_corner::top_right); xlnt_assert_equals(view.pane().active_pane, xlnt::pane_corner::top_right);
assert_equals(view.pane().state, xlnt::pane_state::frozen); xlnt_assert_equals(view.pane().state, xlnt::pane_state::frozen);
assert_equals(view.pane().top_left_cell.get(), "D1"); xlnt_assert_equals(view.pane().top_left_cell.get(), "D1");
assert_equals(view.pane().x_split, 3); xlnt_assert_equals(view.pane().x_split, 3);
} }
void test_freeze_panes_both() void test_freeze_panes_both()
@ -486,24 +486,24 @@ public:
ws.freeze_panes("D4"); ws.freeze_panes("D4");
auto view = ws.view(); auto view = ws.view();
assert_equals(view.selections().size(), 3); xlnt_assert_equals(view.selections().size(), 3);
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right); xlnt_assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right);
assert_equals(view.selections()[1].pane(), xlnt::pane_corner::bottom_left); xlnt_assert_equals(view.selections()[1].pane(), xlnt::pane_corner::bottom_left);
assert_equals(view.selections()[2].active_cell(), "D4"); xlnt_assert_equals(view.selections()[2].active_cell(), "D4");
assert_equals(view.selections()[2].pane(), xlnt::pane_corner::bottom_right); xlnt_assert_equals(view.selections()[2].pane(), xlnt::pane_corner::bottom_right);
assert_equals(view.selections()[2].sqref(), "A1"); xlnt_assert_equals(view.selections()[2].sqref(), "A1");
assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_right); xlnt_assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_right);
assert_equals(view.pane().state, xlnt::pane_state::frozen); xlnt_assert_equals(view.pane().state, xlnt::pane_state::frozen);
assert_equals(view.pane().top_left_cell.get(), "D4"); xlnt_assert_equals(view.pane().top_left_cell.get(), "D4");
assert_equals(view.pane().x_split, 3); xlnt_assert_equals(view.pane().x_split, 3);
assert_equals(view.pane().y_split, 3); xlnt_assert_equals(view.pane().y_split, 3);
} }
void test_min_column() void test_min_column()
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.lowest_column(), 1); xlnt_assert_equals(ws.lowest_column(), 1);
} }
void test_max_column() void test_max_column()
@ -514,14 +514,14 @@ public:
ws[xlnt::cell_reference("F2")].value(32); ws[xlnt::cell_reference("F2")].value(32);
ws[xlnt::cell_reference("F3")].formula("=F1+F2"); ws[xlnt::cell_reference("F3")].formula("=F1+F2");
ws[xlnt::cell_reference("A4")].formula("=A1+A2+A3"); ws[xlnt::cell_reference("A4")].formula("=A1+A2+A3");
assert_equals(ws.highest_column(), 6); xlnt_assert_equals(ws.highest_column(), 6);
} }
void test_min_row() void test_min_row()
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.lowest_row(), 1); xlnt_assert_equals(ws.lowest_row(), 1);
} }
void test_max_row() void test_max_row()
@ -529,7 +529,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
ws.cell("D4").value("D4"); ws.cell("D4").value("D4");
assert_equals(ws.highest_row(), 4); xlnt_assert_equals(ws.highest_row(), 4);
} }
void test_const_iterators() void test_const_iterators()
@ -549,19 +549,19 @@ public:
const auto first_row = rows.front(); const auto first_row = rows.front();
const auto first_cell = first_row.front(); const auto first_cell = first_row.front();
assert_equals(first_cell.reference(), "A1"); xlnt_assert_equals(first_cell.reference(), "A1");
assert_equals(first_cell.value<std::string>(), "A1"); xlnt_assert_equals(first_cell.value<std::string>(), "A1");
const auto last_row = rows.back(); const auto last_row = rows.back();
const auto last_cell = last_row.back(); const auto last_cell = last_row.back();
assert_equals(last_cell.reference(), "C2"); xlnt_assert_equals(last_cell.reference(), "C2");
assert_equals(last_cell.value<std::string>(), "C2"); xlnt_assert_equals(last_cell.value<std::string>(), "C2");
for (const auto row : rows) for (const auto row : rows)
{ {
for (const auto cell : row) for (const auto cell : row)
{ {
assert_equals(cell.value<std::string>(), cell.reference().to_string()); xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
} }
} }
} }
@ -583,7 +583,7 @@ public:
const auto first_row = *rows.rbegin(); const auto first_row = *rows.rbegin();
const auto first_cell = *first_row.rbegin(); const auto first_cell = *first_row.rbegin();
assert_equals(first_cell.value<std::string>(), "C2"); xlnt_assert_equals(first_cell.value<std::string>(), "C2");
auto row_iter = rows.rend(); auto row_iter = rows.rend();
row_iter--; row_iter--;
@ -591,7 +591,7 @@ public:
auto cell_iter = last_row.rend(); auto cell_iter = last_row.rend();
cell_iter--; cell_iter--;
const auto last_cell = *cell_iter; const auto last_cell = *cell_iter;
assert_equals(last_cell.value<std::string>(), "A1"); xlnt_assert_equals(last_cell.value<std::string>(), "A1");
for (auto ws_iter = rows.rbegin(); ws_iter != rows.rend(); ws_iter++) for (auto ws_iter = rows.rbegin(); ws_iter != rows.rend(); ws_iter++)
{ {
@ -600,7 +600,7 @@ public:
for (auto row_iter = row.rbegin(); row_iter != row.rend(); row_iter++) for (auto row_iter = row.rbegin(); row_iter != row.rend(); row_iter++)
{ {
const auto cell = *row_iter; const auto cell = *row_iter;
assert_equals(cell.value<std::string>(), cell.reference().to_string()); xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
} }
} }
} }
@ -622,28 +622,28 @@ public:
auto first_column = *columns.begin(); auto first_column = *columns.begin();
auto first_column_iter = first_column.begin(); auto first_column_iter = first_column.begin();
auto first_cell = *first_column_iter; auto first_cell = *first_column_iter;
assert_equals(first_cell.value<std::string>(), "A1"); xlnt_assert_equals(first_cell.value<std::string>(), "A1");
first_column_iter++; first_column_iter++;
auto second_cell = *first_column_iter; auto second_cell = *first_column_iter;
assert_equals(second_cell.value<std::string>(), "A2"); xlnt_assert_equals(second_cell.value<std::string>(), "A2");
assert_equals(first_cell, first_column.front()); xlnt_assert_equals(first_cell, first_column.front());
assert_equals(second_cell, first_column.back()); xlnt_assert_equals(second_cell, first_column.back());
auto last_column = *(--columns.end()); auto last_column = *(--columns.end());
auto last_column_iter = last_column.end(); auto last_column_iter = last_column.end();
last_column_iter--; last_column_iter--;
auto last_cell = *last_column_iter; auto last_cell = *last_column_iter;
assert_equals(last_cell.value<std::string>(), "C2"); xlnt_assert_equals(last_cell.value<std::string>(), "C2");
last_column_iter--; last_column_iter--;
auto penultimate_cell = *last_column_iter; auto penultimate_cell = *last_column_iter;
assert_equals(penultimate_cell.value<std::string>(), "C1"); xlnt_assert_equals(penultimate_cell.value<std::string>(), "C1");
for (auto column : columns) for (auto column : columns)
{ {
for (auto cell : column) for (auto cell : column)
{ {
assert_equals(cell.value<std::string>(), cell.reference().to_string()); xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
} }
} }
} }
@ -667,19 +667,19 @@ public:
auto first_column_iter = first_column.rbegin(); auto first_column_iter = first_column.rbegin();
auto first_cell = *first_column_iter; auto first_cell = *first_column_iter;
assert_equals(first_cell.value<std::string>(), "C2"); xlnt_assert_equals(first_cell.value<std::string>(), "C2");
first_column_iter++; first_column_iter++;
auto second_cell = *first_column_iter; auto second_cell = *first_column_iter;
assert_equals(second_cell.value<std::string>(), "C1"); xlnt_assert_equals(second_cell.value<std::string>(), "C1");
auto last_column = *(--columns.rend()); auto last_column = *(--columns.rend());
auto last_column_iter = last_column.rend(); auto last_column_iter = last_column.rend();
last_column_iter--; last_column_iter--;
auto last_cell = *last_column_iter; auto last_cell = *last_column_iter;
assert_equals(last_cell.value<std::string>(), "A1"); xlnt_assert_equals(last_cell.value<std::string>(), "A1");
last_column_iter--; last_column_iter--;
auto penultimate_cell = *last_column_iter; auto penultimate_cell = *last_column_iter;
assert_equals(penultimate_cell.value<std::string>(), "A2"); xlnt_assert_equals(penultimate_cell.value<std::string>(), "A2");
for (auto column_iter = columns.rbegin(); column_iter != columns.rend(); ++column_iter) for (auto column_iter = columns.rbegin(); column_iter != columns.rend(); ++column_iter)
{ {
@ -689,7 +689,7 @@ public:
{ {
auto cell = *cell_iter; auto cell = *cell_iter;
assert_equals(cell.value<std::string>(), cell.reference().to_string()); xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
} }
} }
} }
@ -712,25 +712,25 @@ public:
const auto first_column = *columns.begin(); const auto first_column = *columns.begin();
auto first_column_iter = first_column.begin(); auto first_column_iter = first_column.begin();
const auto first_cell = *first_column_iter; const auto first_cell = *first_column_iter;
assert_equals(first_cell.value<std::string>(), "A1"); xlnt_assert_equals(first_cell.value<std::string>(), "A1");
first_column_iter++; first_column_iter++;
const auto second_cell = *first_column_iter; const auto second_cell = *first_column_iter;
assert_equals(second_cell.value<std::string>(), "A2"); xlnt_assert_equals(second_cell.value<std::string>(), "A2");
const auto last_column = *(--columns.end()); const auto last_column = *(--columns.end());
auto last_column_iter = last_column.end(); auto last_column_iter = last_column.end();
last_column_iter--; last_column_iter--;
const auto last_cell = *last_column_iter; const auto last_cell = *last_column_iter;
assert_equals(last_cell.value<std::string>(), "C2"); xlnt_assert_equals(last_cell.value<std::string>(), "C2");
last_column_iter--; last_column_iter--;
const auto penultimate_cell = *last_column_iter; const auto penultimate_cell = *last_column_iter;
assert_equals(penultimate_cell.value<std::string>(), "C1"); xlnt_assert_equals(penultimate_cell.value<std::string>(), "C1");
for (const auto column : columns) for (const auto column : columns)
{ {
for (const auto cell : column) for (const auto cell : column)
{ {
assert_equals(cell.value<std::string>(), cell.reference().to_string()); xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
} }
} }
} }
@ -753,19 +753,19 @@ public:
const auto first_column = *columns.crbegin(); const auto first_column = *columns.crbegin();
auto first_column_iter = first_column.crbegin(); auto first_column_iter = first_column.crbegin();
const auto first_cell = *first_column_iter; const auto first_cell = *first_column_iter;
assert_equals(first_cell.value<std::string>(), "C2"); xlnt_assert_equals(first_cell.value<std::string>(), "C2");
first_column_iter++; first_column_iter++;
const auto second_cell = *first_column_iter; const auto second_cell = *first_column_iter;
assert_equals(second_cell.value<std::string>(), "C1"); xlnt_assert_equals(second_cell.value<std::string>(), "C1");
const auto last_column = *(--columns.crend()); const auto last_column = *(--columns.crend());
auto last_column_iter = last_column.crend(); auto last_column_iter = last_column.crend();
last_column_iter--; last_column_iter--;
const auto last_cell = *last_column_iter; const auto last_cell = *last_column_iter;
assert_equals(last_cell.value<std::string>(), "A1"); xlnt_assert_equals(last_cell.value<std::string>(), "A1");
last_column_iter--; last_column_iter--;
const auto penultimate_cell = *last_column_iter; const auto penultimate_cell = *last_column_iter;
assert_equals(penultimate_cell.value<std::string>(), "A2"); xlnt_assert_equals(penultimate_cell.value<std::string>(), "A2");
for (auto column_iter = columns.crbegin(); column_iter != columns.crend(); ++column_iter) for (auto column_iter = columns.crbegin(); column_iter != columns.crend(); ++column_iter)
{ {
@ -775,7 +775,7 @@ public:
{ {
const auto cell = *cell_iter; const auto cell = *cell_iter;
assert_equals(cell.value<std::string>(), cell.reference().to_string()); xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
} }
} }
} }
@ -787,21 +787,21 @@ public:
for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right }) for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right })
{ {
assert(!hf.has_header(location)); xlnt_assert(!hf.has_header(location));
assert(!hf.has_odd_even_header(location)); xlnt_assert(!hf.has_odd_even_header(location));
assert(!hf.has_first_page_header(location)); xlnt_assert(!hf.has_first_page_header(location));
hf.header(location, "abc"); hf.header(location, "abc");
assert(hf.has_header(location)); xlnt_assert(hf.has_header(location));
assert(!hf.has_odd_even_header(location)); xlnt_assert(!hf.has_odd_even_header(location));
assert(!hf.has_first_page_header(location)); xlnt_assert(!hf.has_first_page_header(location));
assert_equals(hf.header(location), "abc"); xlnt_assert_equals(hf.header(location), "abc");
hf.clear_header(location); hf.clear_header(location);
assert(!hf.has_header(location)); xlnt_assert(!hf.has_header(location));
} }
} }
@ -812,21 +812,21 @@ public:
for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right }) for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right })
{ {
assert(!hf.has_footer(location)); xlnt_assert(!hf.has_footer(location));
assert(!hf.has_odd_even_footer(location)); xlnt_assert(!hf.has_odd_even_footer(location));
assert(!hf.has_first_page_footer(location)); xlnt_assert(!hf.has_first_page_footer(location));
hf.footer(location, "abc"); hf.footer(location, "abc");
assert(hf.has_footer(location)); xlnt_assert(hf.has_footer(location));
assert(!hf.has_odd_even_footer(location)); xlnt_assert(!hf.has_odd_even_footer(location));
assert(!hf.has_first_page_footer(location)); xlnt_assert(!hf.has_first_page_footer(location));
assert_equals(hf.footer(location), "abc"); xlnt_assert_equals(hf.footer(location), "abc");
hf.clear_footer(location); hf.clear_footer(location);
assert(!hf.has_footer(location)); xlnt_assert(!hf.has_footer(location));
} }
} }
@ -834,9 +834,9 @@ public:
{ {
xlnt::page_setup setup; xlnt::page_setup setup;
setup.page_break(xlnt::page_break::column); setup.page_break(xlnt::page_break::column);
assert_equals(setup.page_break(), xlnt::page_break::column); xlnt_assert_equals(setup.page_break(), xlnt::page_break::column);
setup.scale(1.23); setup.scale(1.23);
assert_equals(setup.scale(), 1.23); xlnt_assert_equals(setup.scale(), 1.23);
} }
void test_unique_sheet_name() void test_unique_sheet_name()
@ -846,7 +846,7 @@ public:
auto first_created = wb.create_sheet(); auto first_created = wb.create_sheet();
auto second_created = wb.create_sheet(); auto second_created = wb.create_sheet();
assert_differs(first_created.title(), second_created.title()); xlnt_assert_differs(first_created.title(), second_created.title());
} }
void test_page_margins() void test_page_margins()
@ -865,13 +865,13 @@ public:
ws.page_margins(margins); ws.page_margins(margins);
assert(ws.has_page_margins()); xlnt_assert(ws.has_page_margins());
assert_equals(ws.page_margins().top(), 0); xlnt_assert_equals(ws.page_margins().top(), 0);
assert_equals(ws.page_margins().bottom(), 1); xlnt_assert_equals(ws.page_margins().bottom(), 1);
assert_equals(ws.page_margins().header(), 2); xlnt_assert_equals(ws.page_margins().header(), 2);
assert_equals(ws.page_margins().footer(), 3); xlnt_assert_equals(ws.page_margins().footer(), 3);
assert_equals(ws.page_margins().left(), 4); xlnt_assert_equals(ws.page_margins().left(), 4);
assert_equals(ws.page_margins().right(), 5); xlnt_assert_equals(ws.page_margins().right(), 5);
} }
void test_garbage_collect() void test_garbage_collect()
@ -880,13 +880,13 @@ public:
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
auto dimensions = ws.calculate_dimension(); auto dimensions = ws.calculate_dimension();
assert_equals(dimensions, xlnt::range_reference("A1", "A1")); xlnt_assert_equals(dimensions, xlnt::range_reference("A1", "A1"));
ws.cell("B2").value("text"); ws.cell("B2").value("text");
ws.garbage_collect(); ws.garbage_collect();
dimensions = ws.calculate_dimension(); dimensions = ws.calculate_dimension();
assert_equals(dimensions, xlnt::range_reference("B2", "B2")); xlnt_assert_equals(dimensions, xlnt::range_reference("B2", "B2"));
} }
void test_has_cell() void test_has_cell()
@ -896,8 +896,8 @@ public:
ws.cell("A3").value("test"); ws.cell("A3").value("test");
assert(!ws.has_cell("A2")); xlnt_assert(!ws.has_cell("A2"));
assert(ws.has_cell("A3")); xlnt_assert(ws.has_cell("A3"));
} }
void test_get_range_by_string() void test_get_range_by_string()
@ -914,27 +914,27 @@ public:
auto range_iter = range.begin(); auto range_iter = range.begin();
auto row = *range_iter; auto row = *range_iter;
auto row_iter = row.begin(); auto row_iter = row.begin();
assert_equals((*row_iter).value<double>(), 3.14); xlnt_assert_equals((*row_iter).value<double>(), 3.14);
assert_equals((*row_iter).reference(), "A2"); xlnt_assert_equals((*row_iter).reference(), "A2");
assert_equals((*row_iter), row.front()); xlnt_assert_equals((*row_iter), row.front());
row_iter++; row_iter++;
assert_equals((*row_iter).value<std::string>(), "text"); xlnt_assert_equals((*row_iter).value<std::string>(), "text");
assert_equals((*row_iter).reference(), "B2"); xlnt_assert_equals((*row_iter).reference(), "B2");
assert_equals((*row_iter), row.back()); xlnt_assert_equals((*row_iter), row.back());
range_iter++; range_iter++;
row = *range_iter; row = *range_iter;
row_iter = row.begin(); row_iter = row.begin();
assert_equals((*row_iter).value<bool>(), true); xlnt_assert_equals((*row_iter).value<bool>(), true);
assert_equals((*row_iter).reference(), "A3"); xlnt_assert_equals((*row_iter).reference(), "A3");
range_iter = range.end(); range_iter = range.end();
range_iter--; range_iter--;
row = *range_iter; row = *range_iter;
row_iter = row.end(); row_iter = row.end();
row_iter--; row_iter--;
assert_equals((*row_iter).value<bool>(), false); xlnt_assert_equals((*row_iter).value<bool>(), false);
} }
void test_operators() void test_operators()
@ -947,19 +947,19 @@ public:
auto ws1 = wb[1]; auto ws1 = wb[1];
auto ws2 = wb[2]; auto ws2 = wb[2];
assert_differs(ws1, ws2); xlnt_assert_differs(ws1, ws2);
ws1[xlnt::cell_reference("A2")].value(true); ws1[xlnt::cell_reference("A2")].value(true);
assert_equals(ws1[xlnt::cell_reference("A2")].value<bool>(), true); xlnt_assert_equals(ws1[xlnt::cell_reference("A2")].value<bool>(), true);
assert_equals((*(*ws1.range("A2:A2").begin()).begin()).value<bool>(), true); xlnt_assert_equals((*(*ws1.range("A2:A2").begin()).begin()).value<bool>(), true);
ws1.create_named_range("rangey", "A2:A2"); ws1.create_named_range("rangey", "A2:A2");
assert_equals(ws1.range("rangey"), ws1.range("A2:A2")); xlnt_assert_equals(ws1.range("rangey"), ws1.range("A2:A2"));
assert_equals(ws1.range("A2:A2"), ws1.range("A2:A2")); xlnt_assert_equals(ws1.range("A2:A2"), ws1.range("A2:A2"));
assert(ws1.range("rangey") != ws1.range("A2:A3")); xlnt_assert(ws1.range("rangey") != ws1.range("A2:A3"));
assert_equals(ws1.range("rangey").cell("A1"), ws1.cell("A2")); xlnt_assert_equals(ws1.range("rangey").cell("A1"), ws1.cell("A2"));
} }
void test_reserve() void test_reserve()
@ -985,7 +985,7 @@ public:
{ {
if (cell.has_value()) if (cell.has_value())
{ {
assert_equals(cell.reference().to_string(), cell.value<std::string>()); xlnt_assert_equals(cell.reference().to_string(), cell.value<std::string>());
} }
} }
} }
@ -998,7 +998,7 @@ public:
{ {
if (cell.has_value()) if (cell.has_value())
{ {
assert_equals(cell.reference().to_string(), cell.value<std::string>()); xlnt_assert_equals(cell.reference().to_string(), cell.value<std::string>());
} }
} }
} }
@ -1007,26 +1007,26 @@ public:
auto const_range_iter = const_range.cbegin(); auto const_range_iter = const_range.cbegin();
const_range_iter++; const_range_iter++;
const_range_iter--; const_range_iter--;
assert_equals(const_range_iter, const_range.begin()); xlnt_assert_equals(const_range_iter, const_range.begin());
} }
void test_range_reference() void test_range_reference()
{ {
xlnt::range_reference ref1("A1:A1"); xlnt::range_reference ref1("A1:A1");
assert(ref1.is_single_cell()); xlnt_assert(ref1.is_single_cell());
xlnt::range_reference ref2("A1:B2"); xlnt::range_reference ref2("A1:B2");
assert(!ref2.is_single_cell()); xlnt_assert(!ref2.is_single_cell());
assert(ref1 == xlnt::range_reference("A1:A1")); xlnt_assert(ref1 == xlnt::range_reference("A1:A1"));
assert(ref1 != ref2); xlnt_assert(ref1 != ref2);
assert(ref1 == "A1:A1"); xlnt_assert(ref1 == "A1:A1");
assert(ref1 == std::string("A1:A1")); xlnt_assert(ref1 == std::string("A1:A1"));
assert(std::string("A1:A1") == ref1); xlnt_assert(std::string("A1:A1") == ref1);
assert("A1:A1" == ref1); xlnt_assert("A1:A1" == ref1);
assert(ref1 != "A1:B2"); xlnt_assert(ref1 != "A1:B2");
assert(ref1 != std::string("A1:B2")); xlnt_assert(ref1 != std::string("A1:B2"));
assert(std::string("A1:B2") != ref1); xlnt_assert(std::string("A1:B2") != ref1);
assert("A1:B2" != ref1); xlnt_assert("A1:B2" != ref1);
} }
void test_get_point_pos() void test_get_point_pos()
@ -1034,17 +1034,17 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_equals(ws.point_pos(0, 0), "A1"); xlnt_assert_equals(ws.point_pos(0, 0), "A1");
} }
void test_named_range_named_cell_reference() void test_named_range_named_cell_reference()
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.active_sheet(); auto ws = wb.active_sheet();
assert_throws(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter); xlnt_assert_throws(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter);
assert_throws(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter); xlnt_assert_throws(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter);
assert_throws_nothing(ws.create_named_range("XFE1048576", "A2")); xlnt_assert_throws_nothing(ws.create_named_range("XFE1048576", "A2"));
assert_throws_nothing(ws.create_named_range("XFD1048577", "A2")); xlnt_assert_throws_nothing(ws.create_named_range("XFD1048577", "A2"));
} }
void test_iteration_skip_empty() void test_iteration_skip_empty()
@ -1065,9 +1065,9 @@ public:
} }
} }
assert_equals(cells.size(), 2); xlnt_assert_equals(cells.size(), 2);
assert_equals(cells[0].value<std::string>(), "A1"); xlnt_assert_equals(cells[0].value<std::string>(), "A1");
assert_equals(cells[1].value<std::string>(), "F6"); xlnt_assert_equals(cells[1].value<std::string>(), "F6");
} }
const auto ws_const = ws; const auto ws_const = ws;
@ -1083,9 +1083,9 @@ public:
} }
} }
assert_equals(cells.size(), 2); xlnt_assert_equals(cells.size(), 2);
assert_equals(cells[0].value<std::string>(), "A1"); xlnt_assert_equals(cells[0].value<std::string>(), "A1");
assert_equals(cells[1].value<std::string>(), "F6"); xlnt_assert_equals(cells[1].value<std::string>(), "F6");
} }
} }
}; };