mirror of https://github.com/tfussell/xlnt
start rewiring tests
parent
62f659b901
commit
b85680c5ed
|
@ -14,7 +14,7 @@ std::size_t random_index(std::size_t max)
|
|||
static std::random_device rd;
|
||||
static std::mt19937 gen(rd());
|
||||
|
||||
std::uniform_int_distribution<> dis(0, max - 1);
|
||||
std::uniform_int_distribution<> dis(0, static_cast<int>(max - 1));
|
||||
|
||||
return dis(gen);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ void writer(int cols, int rows)
|
|||
// Create a timeit call to a function and pass in keyword arguments.
|
||||
// The function is called twice, once using the standard workbook, then with the optimised one.
|
||||
// Time from the best of three is taken.
|
||||
int timer(std::function<void(int, int)> fn, int cols, int rows)
|
||||
void timer(std::function<void(int, int)> fn, int cols, int rows)
|
||||
{
|
||||
const auto repeat = std::size_t(3);
|
||||
auto time = std::numeric_limits<std::size_t>::max();
|
||||
|
@ -54,8 +54,6 @@ int timer(std::function<void(int, int)> fn, int cols, int rows)
|
|||
}
|
||||
|
||||
std::cout << time / 1000.0 << std::endl;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
|
@ -74,7 +74,9 @@ xlnt::workbook build_workbook_cf(const pixmap &image)
|
|||
// The reference to the cell which is being operated upon
|
||||
auto current_cell = xlnt::cell_reference("A1");
|
||||
// The range of cells which will be modified. This is required for conditional formats
|
||||
auto range = ws.range(xlnt::range_reference(1, 1, image[0].size(), image.size()));
|
||||
auto range = ws.range(xlnt::range_reference(1, 1,
|
||||
static_cast<xlnt::column_t::index_t>(image[0].size()),
|
||||
static_cast<xlnt::row_t>(image.size())));
|
||||
|
||||
// Track the previously created conditonal formats so they are only created once
|
||||
std::unordered_set<std::string> defined_colors;
|
||||
|
|
|
@ -131,6 +131,7 @@ target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR}/../third-party/libstu
|
|||
|
||||
if(MSVC)
|
||||
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\"")
|
||||
endif()
|
||||
|
||||
source_group(xlnt FILES ${ROOT_HEADERS})
|
||||
|
|
|
@ -87,4 +87,14 @@ bool rich_text::operator==(const std::string &rhs) const
|
|||
return *this == rich_text(rhs);
|
||||
}
|
||||
|
||||
bool rich_text::operator!=(const rich_text &rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
bool rich_text::operator!=(const std::string &rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -274,11 +274,12 @@ std::string SHA1::final_()
|
|||
uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8;
|
||||
|
||||
/* Padding */
|
||||
buffer += static_cast<char>(0x80);
|
||||
size_t orig_size = buffer.size();
|
||||
buffer.append(1, static_cast<char>(0x80u));
|
||||
auto orig_size = buffer.size();
|
||||
|
||||
while (buffer.size() < BLOCK_BYTES)
|
||||
{
|
||||
buffer += static_cast<char>(0x00);
|
||||
buffer.append(1, '\0');
|
||||
}
|
||||
|
||||
uint32_t block[BLOCK_INTS];
|
||||
|
|
|
@ -301,7 +301,10 @@ std::vector<std::uint8_t> decrypt_xlsx_standard(
|
|||
encryption_info generate_encryption_info(const std::u16string &password)
|
||||
{
|
||||
encryption_info result;
|
||||
result.agile.key_data.salt_value.assign(password.begin(), password.end());
|
||||
|
||||
result.agile.key_data.salt_value.assign(
|
||||
reinterpret_cast<const std::uint8_t *>(password.data()),
|
||||
reinterpret_cast<const std::uint8_t *>(password.data() + password.size()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ if(NOT COMBINED_PROJECT)
|
|||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source)
|
||||
endif()
|
||||
|
||||
file(GLOB CELL_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/cell/test_*.hpp)
|
||||
file(GLOB PACKAGING_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/test_*.hpp)
|
||||
file(GLOB STYLES_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/styles/test_*.hpp)
|
||||
file(GLOB UTILS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/utils/test_*.hpp)
|
||||
file(GLOB WORKBOOK_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/workbook/test_*.hpp)
|
||||
file(GLOB WORKSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/worksheet/test_*.hpp)
|
||||
file(GLOB CELL_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/cell/*.hpp)
|
||||
file(GLOB PACKAGING_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/*.hpp)
|
||||
file(GLOB STYLES_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/styles/*.hpp)
|
||||
file(GLOB UTILS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.hpp)
|
||||
file(GLOB WORKBOOK_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/workbook/*.hpp)
|
||||
file(GLOB WORKSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/worksheet/*.hpp)
|
||||
|
||||
set(TESTS
|
||||
${CELL_TESTS}
|
||||
|
@ -33,17 +33,22 @@ if(COVERAGE)
|
|||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
||||
add_executable(xlnt.test ${RUNNER} ${HELPERS} $<TARGET_OBJECTS:libstudxml>)
|
||||
add_executable(xlnt.test ${RUNNER} ${TESTS} ${HELPERS})
|
||||
target_link_libraries(xlnt.test PRIVATE xlnt)
|
||||
target_include_directories(xlnt.test
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../source
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/libstudxml)
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/libstudxml)
|
||||
|
||||
set(XLNT_TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
target_compile_definitions(xlnt.test PRIVATE XLNT_TEST_DATA_DIR=${XLNT_TEST_DATA_DIR})
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(xlnt.test PROPERTIES COMPILE_FLAGS "/wd\"4068\" /bigobj")
|
||||
endif()
|
||||
|
||||
source_group(helpers FILES ${HELPERS})
|
||||
source_group(runner FILES ${RUNNER})
|
||||
source_group(tests\\cell FILES ${CELL_TESTS})
|
||||
source_group(tests\\packaging FILES ${PACKAGING_TESTS})
|
||||
source_group(tests\\serialization FILES ${SERIALIZATION_TESTS})
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
@ -10,86 +35,86 @@ class cell_test_suite : public test_suite
|
|||
public:
|
||||
cell_test_suite()
|
||||
{
|
||||
register_test(test_infer_numeric);
|
||||
register_test(test_constructor);
|
||||
register_test(test_null);
|
||||
register_test(test_string);
|
||||
register_test(test_formula1);
|
||||
register_test(test_formula2);
|
||||
register_test(test_formula3);
|
||||
register_test(test_not_formula);
|
||||
register_test(test_boolean);
|
||||
register_test(test_error_codes);
|
||||
register_test(test_insert_datetime);
|
||||
register_test(test_insert_date);
|
||||
register_test(test_insert_time);
|
||||
register_test(test_cell_formatted_as_date1);
|
||||
register_test(test_cell_formatted_as_date2);
|
||||
register_test(test_cell_formatted_as_date3);
|
||||
register_test(test_illegal_characters);
|
||||
register_test(test_timedelta);
|
||||
register_test(test_cell_offset);
|
||||
register_test(test_font);
|
||||
register_test(test_fill);
|
||||
register_test(test_border);
|
||||
register_test(test_number_format);
|
||||
register_test(test_alignment);
|
||||
register_test(test_protection);
|
||||
register_test(test_style);
|
||||
register_test(test_print);
|
||||
register_test(test_values);
|
||||
register_test(test_reference);
|
||||
register_test(test_anchor);
|
||||
register_test(test_hyperlink);
|
||||
register_test(test_comment);
|
||||
register_test(test_infer_numeric);
|
||||
register_test(test_constructor);
|
||||
register_test(test_null);
|
||||
register_test(test_string);
|
||||
register_test(test_formula1);
|
||||
register_test(test_formula2);
|
||||
register_test(test_formula3);
|
||||
register_test(test_not_formula);
|
||||
register_test(test_boolean);
|
||||
register_test(test_error_codes);
|
||||
register_test(test_insert_datetime);
|
||||
register_test(test_insert_date);
|
||||
register_test(test_insert_time);
|
||||
register_test(test_cell_formatted_as_date1);
|
||||
register_test(test_cell_formatted_as_date2);
|
||||
register_test(test_cell_formatted_as_date3);
|
||||
register_test(test_illegal_characters);
|
||||
register_test(test_timedelta);
|
||||
register_test(test_cell_offset);
|
||||
register_test(test_font);
|
||||
register_test(test_fill);
|
||||
register_test(test_border);
|
||||
register_test(test_number_format);
|
||||
register_test(test_alignment);
|
||||
register_test(test_protection);
|
||||
register_test(test_style);
|
||||
register_test(test_print);
|
||||
register_test(test_values);
|
||||
register_test(test_reference);
|
||||
register_test(test_anchor);
|
||||
register_test(test_hyperlink);
|
||||
register_test(test_comment);
|
||||
}
|
||||
|
||||
private:
|
||||
void test_infer_numeric()
|
||||
{
|
||||
assert(1 == 0);
|
||||
|
||||
assert(1 == 0);
|
||||
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
cell.value("4.2", true);
|
||||
assert(cell.value<long double>() == 4.2L);
|
||||
cell.value("4.2", true);
|
||||
assert(cell.value<long double>() == 4.2L);
|
||||
|
||||
cell.value("-42.000", true);
|
||||
assert(cell.value<int>() == -42);
|
||||
cell.value("-42.000", true);
|
||||
assert(cell.value<int>() == -42);
|
||||
|
||||
cell.value("0", true);
|
||||
assert(cell.value<int>() == 0);
|
||||
cell.value("0", true);
|
||||
assert(cell.value<int>() == 0);
|
||||
|
||||
cell.value("0.9999", true);
|
||||
assert(cell.value<long double>() == 0.9999L);
|
||||
cell.value("0.9999", true);
|
||||
assert(cell.value<long double>() == 0.9999L);
|
||||
|
||||
cell.value("99E-02", true);
|
||||
assert(cell.value<long double>() == 0.99L);
|
||||
cell.value("99E-02", true);
|
||||
assert(cell.value<long double>() == 0.99L);
|
||||
|
||||
cell.value("4", true);
|
||||
assert(cell.value<int>() == 4);
|
||||
cell.value("4", true);
|
||||
assert(cell.value<int>() == 4);
|
||||
|
||||
cell.value("-1E3", true);
|
||||
assert(cell.value<int>() == -1000);
|
||||
cell.value("-1E3", true);
|
||||
assert(cell.value<int>() == -1000);
|
||||
|
||||
cell.value("2e+2", true);
|
||||
assert(cell.value<int>() == 200);
|
||||
cell.value("2e+2", true);
|
||||
assert(cell.value<int>() == 200);
|
||||
|
||||
cell.value("3.1%", true);
|
||||
assert(cell.value<long double>() == 0.031L);
|
||||
cell.value("3.1%", true);
|
||||
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));
|
||||
|
||||
cell.value("03:", true);
|
||||
cell.value("03:", true);
|
||||
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));
|
||||
|
||||
cell.value("30:33.865633336", true);
|
||||
cell.value("30:33.865633336", true);
|
||||
assert(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
|
||||
}
|
||||
|
||||
|
@ -98,7 +123,7 @@ private:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference("A", 1));
|
||||
|
||||
|
||||
assert(cell.data_type() == xlnt::cell::type::null);
|
||||
assert(cell.column() == "A");
|
||||
assert(cell.row() == 1);
|
||||
|
@ -111,43 +136,43 @@ private:
|
|||
xlnt::workbook wb;
|
||||
|
||||
const auto datatypes =
|
||||
{
|
||||
xlnt::cell::type::null,
|
||||
xlnt::cell::type::boolean,
|
||||
xlnt::cell::type::error,
|
||||
xlnt::cell::type::formula,
|
||||
xlnt::cell::type::numeric,
|
||||
xlnt::cell::type::string
|
||||
};
|
||||
|
||||
for(const auto &datatype : datatypes)
|
||||
{
|
||||
xlnt::cell::type::null,
|
||||
xlnt::cell::type::boolean,
|
||||
xlnt::cell::type::error,
|
||||
xlnt::cell::type::formula,
|
||||
xlnt::cell::type::numeric,
|
||||
xlnt::cell::type::string
|
||||
};
|
||||
|
||||
for (const auto &datatype : datatypes)
|
||||
{
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.data_type(datatype);
|
||||
assert(cell.data_type() == datatype);
|
||||
cell.clear_value();
|
||||
assert(cell.data_type() == xlnt::cell::type::null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_string()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value("hello");
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
|
||||
|
||||
cell.value(".");
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
|
||||
|
||||
cell.value("0800");
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
}
|
||||
|
||||
|
||||
void test_formula1()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -157,13 +182,13 @@ private:
|
|||
cell.value("=42", true);
|
||||
assert(cell.data_type() == xlnt::cell::type::formula);
|
||||
}
|
||||
|
||||
|
||||
void test_formula2()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value("=if(A1<4;-1;1)", true);
|
||||
assert(cell.data_type() == xlnt::cell::type::formula);
|
||||
}
|
||||
|
@ -184,39 +209,39 @@ private:
|
|||
assert(!cell.has_formula());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_not_formula()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value("=");
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
assert(cell.value<std::string>() == "=");
|
||||
assert(!cell.has_formula());
|
||||
}
|
||||
|
||||
|
||||
void test_boolean()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
for(auto value : {true, false})
|
||||
|
||||
for (auto value : { true, false })
|
||||
{
|
||||
cell.value(value);
|
||||
assert(cell.data_type() == xlnt::cell::type::boolean);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_error_codes()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
for(auto error_code : xlnt::cell::error_codes())
|
||||
|
||||
for (auto error_code : xlnt::cell::error_codes())
|
||||
{
|
||||
cell.value(error_code.first, true);
|
||||
assert(cell.data_type() == xlnt::cell::type::error);
|
||||
|
@ -228,7 +253,7 @@ private:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
|
||||
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
|
@ -236,100 +261,100 @@ private:
|
|||
assert(cell.is_date());
|
||||
assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
|
||||
}
|
||||
|
||||
|
||||
void test_insert_date()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::date(2010, 7, 13));
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
assert(cell.value<long double>() == 40372.L);
|
||||
assert(cell.is_date());
|
||||
assert(cell.number_format().format_string() == "yyyy-mm-dd");
|
||||
}
|
||||
|
||||
|
||||
void test_insert_time()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::time(1, 3));
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
assert(cell.value<long double>() == 0.04375L);
|
||||
assert(cell.is_date());
|
||||
assert(cell.number_format().format_string() == "h:mm:ss");
|
||||
}
|
||||
|
||||
|
||||
void test_cell_formatted_as_date1()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::datetime::today());
|
||||
cell.clear_value();
|
||||
assert(!cell.is_date()); // disagree with openpyxl
|
||||
assert(!cell.has_value());
|
||||
}
|
||||
|
||||
|
||||
void test_cell_formatted_as_date2()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::datetime::today());
|
||||
cell.value("testme");
|
||||
assert(!cell.is_date());
|
||||
assert(cell.value<std::string>() == "testme");
|
||||
}
|
||||
|
||||
|
||||
void test_cell_formatted_as_date3()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::datetime::today());
|
||||
cell.value(true);
|
||||
assert(!cell.is_date());
|
||||
assert(cell.value<bool>() == true);
|
||||
}
|
||||
|
||||
|
||||
void test_illegal_characters()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
// The bytes 0x00 through 0x1F inclusive must be manually escaped in values.
|
||||
auto illegal_chrs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
|
||||
|
||||
for(auto i : illegal_chrs)
|
||||
auto illegal_chrs = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
|
||||
|
||||
for (auto i : illegal_chrs)
|
||||
{
|
||||
std::string str(1, i);
|
||||
assert_throws(cell.value(str), xlnt::illegal_character);
|
||||
}
|
||||
|
||||
|
||||
cell.value(std::string(1, 33));
|
||||
cell.value(std::string(1, 9)); // Tab
|
||||
cell.value(std::string(1, 10)); // Newline
|
||||
cell.value(std::string(1, 13)); // Carriage return
|
||||
cell.value(" Leading and trailing spaces are legal ");
|
||||
}
|
||||
|
||||
|
||||
// void test_time_regex() {}
|
||||
|
||||
|
||||
void test_timedelta()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
|
||||
cell.value(xlnt::timedelta(1, 3, 0, 0, 0));
|
||||
|
||||
assert(cell.value<long double>() == 1.125);
|
||||
|
@ -345,82 +370,82 @@ private:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
assert(cell.offset(1, 2).reference() == "B3");
|
||||
}
|
||||
|
||||
|
||||
void test_font()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
auto font = xlnt::font().bold(true);
|
||||
|
||||
auto font = xlnt::font().bold(true);
|
||||
|
||||
cell.font(font);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().font_applied());
|
||||
assert_equals(cell.font(), font);
|
||||
}
|
||||
|
||||
|
||||
void test_fill()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
xlnt::fill fill(xlnt::pattern_fill()
|
||||
.type(xlnt::pattern_fill_type::solid)
|
||||
.foreground(xlnt::color::red()));
|
||||
|
||||
xlnt::fill fill(xlnt::pattern_fill()
|
||||
.type(xlnt::pattern_fill_type::solid)
|
||||
.foreground(xlnt::color::red()));
|
||||
cell.fill(fill);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().fill_applied());
|
||||
assert_equals(cell.fill(), fill);
|
||||
}
|
||||
|
||||
|
||||
void test_border()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
|
||||
xlnt::border border;
|
||||
cell.border(border);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().border_applied());
|
||||
assert_equals(cell.border(), border);
|
||||
}
|
||||
|
||||
|
||||
void test_number_format()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
|
||||
xlnt::number_format format("dd--hh--mm");
|
||||
cell.number_format(format);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().number_format_applied());
|
||||
assert_equals(cell.number_format().format_string(), "dd--hh--mm");
|
||||
}
|
||||
|
||||
|
||||
void test_alignment()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
|
||||
xlnt::alignment align;
|
||||
align.wrap(true);
|
||||
|
||||
|
||||
cell.alignment(align);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().alignment_applied());
|
||||
assert_equals(cell.alignment(), align);
|
||||
}
|
||||
|
||||
|
||||
void test_protection()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -429,29 +454,29 @@ private:
|
|||
|
||||
assert(!cell.has_format());
|
||||
|
||||
auto protection = xlnt::protection().locked(false).hidden(true);
|
||||
auto protection = xlnt::protection().locked(false).hidden(true);
|
||||
cell.protection(protection);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().protection_applied());
|
||||
assert_equals(cell.protection(), protection);
|
||||
|
||||
|
||||
assert(cell.has_format());
|
||||
cell.clear_format();
|
||||
assert(!cell.has_format());
|
||||
}
|
||||
|
||||
|
||||
void test_style()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
|
||||
assert(!cell.has_style());
|
||||
|
||||
|
||||
auto test_style = wb.create_style("test_style");
|
||||
test_style.number_format(xlnt::number_format::date_ddmmyyyy(), true);
|
||||
|
||||
|
||||
cell.style(test_style);
|
||||
assert(cell.has_style());
|
||||
assert_equals(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy());
|
||||
|
@ -459,26 +484,26 @@ private:
|
|||
|
||||
auto other_style = wb.create_style("other_style");
|
||||
other_style.number_format(xlnt::number_format::date_time2(), true);
|
||||
|
||||
|
||||
cell.style("other_style");
|
||||
assert_equals(cell.style().number_format(), xlnt::number_format::date_time2());
|
||||
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);
|
||||
|
||||
|
||||
cell.style(last_style);
|
||||
assert_equals(cell.style().number_format(), xlnt::number_format::percentage());
|
||||
assert_equals(cell.style(), last_style);
|
||||
|
||||
|
||||
assert_throws(cell.style("doesn't exist"), xlnt::key_not_found);
|
||||
|
||||
|
||||
cell.clear_style();
|
||||
|
||||
|
||||
assert(!cell.has_style());
|
||||
assert_throws(cell.style(), xlnt::invalid_attribute);
|
||||
}
|
||||
|
||||
|
||||
void test_print()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -509,7 +534,7 @@ private:
|
|||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "FALSE");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
auto cell = ws.cell("A3");
|
||||
|
||||
|
@ -523,7 +548,7 @@ private:
|
|||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "TRUE");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
auto cell = ws.cell("A4");
|
||||
|
||||
|
@ -537,7 +562,7 @@ private:
|
|||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "1.234");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
auto cell = ws.cell("A5");
|
||||
|
||||
|
@ -551,7 +576,7 @@ private:
|
|||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "#REF");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
auto cell = ws.cell("A6");
|
||||
|
||||
|
@ -622,7 +647,7 @@ private:
|
|||
void test_anchor()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
auto anchor = cell.anchor();
|
||||
assert_equals(anchor.first, 0);
|
||||
assert_equals(anchor.second, 0);
|
||||
|
@ -631,7 +656,7 @@ private:
|
|||
void test_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
assert(!cell.has_hyperlink());
|
||||
assert_throws(cell.hyperlink(), xlnt::invalid_attribute);
|
||||
assert_throws(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
@ -5,16 +28,16 @@
|
|||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_index_types : public test_suite
|
||||
class index_types_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
test_index_types()
|
||||
index_types_test_suite()
|
||||
{
|
||||
register_test(test_bad_string_empty);
|
||||
register_test(test_bad_string_too_long);
|
||||
register_test(test_bad_string_numbers);
|
||||
register_test(test_bad_index_zero);
|
||||
register_test(test_column_operators);
|
||||
register_test(test_bad_string_empty);
|
||||
register_test(test_bad_string_too_long);
|
||||
register_test(test_bad_string_numbers);
|
||||
register_test(test_bad_index_zero);
|
||||
register_test(test_column_operators);
|
||||
}
|
||||
|
||||
void test_bad_string_empty()
|
||||
|
@ -22,13 +45,13 @@ public:
|
|||
assert_throws(xlnt::column_t::column_index_from_string(""),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
|
||||
void test_bad_string_too_long()
|
||||
{
|
||||
assert_throws(xlnt::column_t::column_index_from_string("ABCD"),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
|
||||
void test_bad_string_numbers()
|
||||
{
|
||||
assert_throws(xlnt::column_t::column_index_from_string("123"),
|
||||
|
@ -61,14 +84,14 @@ public:
|
|||
assert(c2 > c1);
|
||||
assert(c1 < c2);
|
||||
assert(c1 <= c2);
|
||||
|
||||
|
||||
assert_equals(--c2, 3);
|
||||
assert_equals(c2--, 3);
|
||||
assert_equals(c2, 2);
|
||||
|
||||
|
||||
c2 = 4;
|
||||
c1 = 3;
|
||||
|
||||
|
||||
assert(c2 <= 4);
|
||||
assert(!(c2 < 3));
|
||||
assert(c1 >= 3);
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
|
@ -7,12 +30,12 @@
|
|||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_rich_text : public test_suite
|
||||
class rich_text_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
test_rich_text()
|
||||
rich_text_test_suite()
|
||||
{
|
||||
register_test(test_operators);
|
||||
register_test(test_operators);
|
||||
}
|
||||
|
||||
void test_operators()
|
|
@ -7,6 +7,8 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <helpers/assertions.hpp>
|
||||
|
||||
struct test_status
|
||||
{
|
||||
std::size_t tests_run = 0;
|
||||
|
@ -20,41 +22,41 @@ std::string build_name(const std::string &pretty, const std::string &method)
|
|||
return pretty.substr(0, pretty.find("::") + 2) + method;
|
||||
}
|
||||
|
||||
#define register_test(test) register_test_internal([this]() { test(); }, build_name(__PRETTY_FUNCTION__, #test));
|
||||
#define register_test(test) register_test_internal([this]() { test(); }, build_name(__FUNCTION__, #test));
|
||||
|
||||
class test_suite
|
||||
{
|
||||
public:
|
||||
test_status go()
|
||||
{
|
||||
test_status status;
|
||||
test_status status;
|
||||
|
||||
for (auto test : tests)
|
||||
{
|
||||
try
|
||||
{
|
||||
test.first();
|
||||
std::cout << ".";
|
||||
status.tests_passed++;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "*";
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(test.second);
|
||||
}
|
||||
for (auto test : tests)
|
||||
{
|
||||
try
|
||||
{
|
||||
test.first();
|
||||
std::cout << ".";
|
||||
status.tests_passed++;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "*";
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(test.second);
|
||||
}
|
||||
|
||||
std::cout.flush();
|
||||
status.tests_run++;
|
||||
}
|
||||
std::cout.flush();
|
||||
status.tests_run++;
|
||||
}
|
||||
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
protected:
|
||||
void register_test_internal(std::function<void()> t, const std::string &function)
|
||||
{
|
||||
tests.push_back(std::make_pair(t, function));
|
||||
tests.push_back(std::make_pair(t, function));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,31 +1,27 @@
|
|||
#include <cell/test_cell.hpp>
|
||||
#include <cell/test_index_types.hpp>
|
||||
#include <cell/test_rich_text.hpp>
|
||||
#include <cell/cell_test_suite.hpp>
|
||||
#include <cell/index_types_test_suite.hpp>
|
||||
#include <cell/rich_text_test_suite.hpp>
|
||||
|
||||
#include <styles/test_alignment.hpp>
|
||||
#include <styles/test_color.hpp>
|
||||
#include <styles/test_fill.hpp>
|
||||
#include <styles/test_number_format.hpp>
|
||||
#include <styles/alignment_test_suite.hpp>
|
||||
#include <styles/color_test_suite.hpp>
|
||||
#include <styles/fill_test_suite.hpp>
|
||||
#include <styles/number_format_test_suite.hpp>
|
||||
|
||||
#include <utils/test_datetime.hpp>
|
||||
#include <utils/test_path.hpp>
|
||||
#include <utils/test_tests.hpp>
|
||||
#include <utils/test_timedelta.hpp>
|
||||
#include <utils/test_units.hpp>
|
||||
#include <utils/datetime_test_suite.hpp>
|
||||
#include <utils/path_test_suite.hpp>
|
||||
#include <utils/helper_test_suite.hpp>
|
||||
#include <utils/timedelta_test_suite.hpp>
|
||||
|
||||
#include <workbook/test_consume_xlsx.hpp>
|
||||
#include <workbook/test_named_range.hpp>
|
||||
#include <workbook/test_produce_xlsx.hpp>
|
||||
#include <workbook/test_protection.hpp>
|
||||
#include <workbook/test_round_trip.hpp>
|
||||
#include <workbook/test_theme.hpp>
|
||||
#include <workbook/test_vba.hpp>
|
||||
#include <workbook/test_workbook.hpp>
|
||||
#include <workbook/named_range_test_suite.hpp>
|
||||
#include <workbook/protection_test_suite.hpp>
|
||||
#include <workbook/serialization_test_suite.hpp>
|
||||
#include <workbook/theme_test_suite.hpp>
|
||||
#include <workbook/vba_test_suite.hpp>
|
||||
#include <workbook/workbook_test_suite.hpp>
|
||||
|
||||
#include <worksheet/test_datavalidation.hpp>
|
||||
#include <worksheet/test_page_setup.hpp>
|
||||
#include <worksheet/test_range.hpp>
|
||||
#include <worksheet/test_worksheet.hpp>
|
||||
#include <worksheet/page_setup_test_suite.hpp>
|
||||
#include <worksheet/range_test_suite.hpp>
|
||||
#include <worksheet/worksheet_test_suite.hpp>
|
||||
|
||||
test_status overall_status;
|
||||
|
||||
|
@ -53,11 +49,34 @@ void print_summary()
|
|||
|
||||
int main()
|
||||
{
|
||||
// cell
|
||||
run_tests<cell_test_suite>();
|
||||
run_tests<test_index_types>();
|
||||
run_tests<test_worksheet>();
|
||||
run_tests<index_types_test_suite>();
|
||||
run_tests<rich_text_test_suite>();
|
||||
|
||||
// styles
|
||||
run_tests<alignment_test_suite>();
|
||||
run_tests<color_test_suite>();
|
||||
run_tests<fill_test_suite>();
|
||||
run_tests<number_format_test_suite>();
|
||||
|
||||
// utils
|
||||
run_tests<datetime_test_suite>();
|
||||
run_tests<path_test_suite>();
|
||||
run_tests<helper_test_suite>();
|
||||
run_tests<timedelta_test_suite>();
|
||||
|
||||
// workbook
|
||||
run_tests<named_range_test_suite>();
|
||||
run_tests<serialization_test_suite>();
|
||||
run_tests<workbook_test_suite>();
|
||||
|
||||
// worksheet
|
||||
run_tests<page_setup_test_suite>();
|
||||
run_tests<range_test_suite>();
|
||||
run_tests<worksheet_test_suite>();
|
||||
|
||||
print_summary();
|
||||
|
||||
return overall_status.tests_failed;
|
||||
return static_cast<int>(overall_status.tests_failed);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class alignment_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
alignment_test_suite()
|
||||
{
|
||||
register_test(test_all);
|
||||
}
|
||||
|
||||
void test_all()
|
||||
{
|
||||
xlnt::alignment alignment;
|
||||
|
||||
assert(!alignment.horizontal().is_set());
|
||||
assert(!alignment.vertical().is_set());
|
||||
assert(!alignment.shrink());
|
||||
assert(!alignment.wrap());
|
||||
}
|
||||
};
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
@ -5,9 +28,15 @@
|
|||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_color : public test_suite
|
||||
class color_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
color_test_suite()
|
||||
{
|
||||
register_test(test_known_colors);
|
||||
register_test(test_non_rgb_colors);
|
||||
}
|
||||
|
||||
void test_known_colors()
|
||||
{
|
||||
const std::vector<std::pair<xlnt::color, std::string>> known_colors
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
@ -5,9 +28,16 @@
|
|||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_fill : public test_suite
|
||||
class fill_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
fill_test_suite()
|
||||
{
|
||||
register_test(test_properties);
|
||||
register_test(test_comparison);
|
||||
register_test(test_two_fills);
|
||||
}
|
||||
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::fill fill;
|
|
@ -1,13 +1,119 @@
|
|||
#pragma once
|
||||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_number_format : public test_suite
|
||||
class number_format_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
number_format_test_suite()
|
||||
{
|
||||
register_test(test_basic);
|
||||
register_test(test_simple_format);
|
||||
register_test(test_simple_date);
|
||||
register_test(test_short_month);
|
||||
register_test(test_month_abbreviation);
|
||||
register_test(test_month_name);
|
||||
register_test(test_basic);
|
||||
register_test(test_simple_format);
|
||||
register_test(test_simple_date);
|
||||
register_test(test_short_day);
|
||||
register_test(test_long_day);
|
||||
register_test(test_long_year);
|
||||
register_test(test_day_name);
|
||||
register_test(test_day_abbreviation);
|
||||
register_test(test_month_letter);
|
||||
register_test(test_time_24_hour);
|
||||
register_test(test_elapsed_minutes);
|
||||
register_test(test_second_fractional_leading_zero);
|
||||
register_test(test_second_fractional);
|
||||
register_test(test_elapsed_seconds);
|
||||
register_test(test_time_12_hour_am);
|
||||
register_test(test_time_12_hour_pm);
|
||||
register_test(test_long_hour_12_hour);
|
||||
register_test(test_long_hour_12_hour_ap);
|
||||
register_test(test_long_hour_24_hour);
|
||||
register_test(test_short_minute);
|
||||
register_test(test_long_minute);
|
||||
register_test(test_short_second);
|
||||
register_test(test_long_second);
|
||||
register_test(test_trailing_space);
|
||||
register_test(test_text_section_string);
|
||||
register_test(test_text_section_no_string);
|
||||
register_test(test_text_section_no_text);
|
||||
register_test(test_conditional_format);
|
||||
register_test(test_space);
|
||||
register_test(test_fill);
|
||||
register_test(test_placeholders_zero);
|
||||
register_test(test_placeholders_space);
|
||||
register_test(test_scientific);
|
||||
register_test(test_locale_currency);
|
||||
register_test(test_bad_country);
|
||||
register_test(test_duplicate_bracket_sections);
|
||||
register_test(test_escaped_quote_string);
|
||||
register_test(test_thousands_scale);
|
||||
register_test(test_colors);
|
||||
register_test(test_bad_format);
|
||||
register_test(test_builtin_format_0);
|
||||
register_test(test_builtin_format_1);
|
||||
register_test(test_builtin_format_2);
|
||||
register_test(test_builtin_format_3);
|
||||
register_test(test_builtin_format_4);
|
||||
register_test(test_builtin_format_9);
|
||||
register_test(test_builtin_format_10);
|
||||
register_test(test_builtin_format_11);
|
||||
register_test(test_builtin_format_12);
|
||||
register_test(test_builtin_format_13);
|
||||
register_test(test_builtin_format_14);
|
||||
register_test(test_builtin_format_15);
|
||||
register_test(test_builtin_format_16);
|
||||
register_test(test_builtin_format_17);
|
||||
register_test(test_builtin_format_18);
|
||||
register_test(test_builtin_format_19);
|
||||
register_test(test_builtin_format_20);
|
||||
register_test(test_builtin_format_21);
|
||||
register_test(test_builtin_format_22);
|
||||
register_test(test_builtin_format_37);
|
||||
register_test(test_builtin_format_38);
|
||||
register_test(test_builtin_format_39);
|
||||
register_test(test_builtin_format_40);
|
||||
register_test(test_builtin_format_45);
|
||||
register_test(test_builtin_format_46);
|
||||
register_test(test_builtin_format_47);
|
||||
register_test(test_builtin_format_48);
|
||||
register_test(test_builtin_format_49);
|
||||
register_test(test_builtin_format_date_yyyymmdd);
|
||||
register_test(test_builtin_format_date_dmyslash);
|
||||
register_test(test_builtin_format_date_dmyminus);
|
||||
register_test(test_builtin_format_date_dmminus);
|
||||
register_test(test_builtin_format_date_myminus);
|
||||
}
|
||||
|
||||
void test_basic()
|
||||
{
|
||||
xlnt::number_format no_id("#\\x\\y\\z");
|
|
@ -1,20 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_alignment : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_all()
|
||||
{
|
||||
xlnt::alignment alignment;
|
||||
|
||||
assert(!alignment.horizontal().is_set());
|
||||
assert(!alignment.vertical().is_set());
|
||||
assert(!alignment.shrink());
|
||||
assert(!alignment.wrap());
|
||||
}
|
||||
};
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
@ -5,7 +28,7 @@
|
|||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_datetime : public test_suite
|
||||
class datetime_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_from_string()
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
class helper_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_compare()
|
||||
{
|
||||
assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
|
||||
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));
|
||||
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));
|
||||
assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
|
||||
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));
|
||||
}
|
||||
};
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class path_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_exists()
|
||||
{
|
||||
temporary_file temp;
|
||||
|
||||
if (temp.get_path().exists())
|
||||
{
|
||||
path_helper::delete_file(temp.get_path());
|
||||
}
|
||||
|
||||
assert(!temp.get_path().exists());
|
||||
std::ofstream stream(temp.get_path().string());
|
||||
assert(temp.get_path().exists());
|
||||
}
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_path : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_exists()
|
||||
{
|
||||
temporary_file temp;
|
||||
|
||||
if (temp.get_path().exists())
|
||||
{
|
||||
path_helper::delete_file(temp.get_path());
|
||||
}
|
||||
|
||||
assert(!temp.get_path().exists());
|
||||
std::ofstream stream(temp.get_path().string());
|
||||
assert(temp.get_path().exists());
|
||||
}
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
class test_tests : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_compare()
|
||||
{
|
||||
assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
|
||||
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));
|
||||
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));
|
||||
assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
|
||||
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));
|
||||
}
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_units : public test_suite
|
||||
{
|
||||
};
|
|
@ -1,9 +1,32 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
class test_timedelta : public test_suite
|
||||
class timedelta_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_from_number()
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class units_test_suite : public test_suite
|
||||
{
|
||||
};
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
@ -5,7 +28,7 @@
|
|||
|
||||
#include <xlnt/workbook/named_range.hpp>
|
||||
|
||||
class test_named_range : public test_suite
|
||||
class named_range_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_split()
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_password_hash : public test_suite
|
||||
{
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
#include <detail/crypto/xlsx_crypto.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_round_trip : public test_suite
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
|
@ -0,0 +1,440 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
#include <detail/crypto/xlsx_crypto.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class serialization_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
|
||||
{
|
||||
std::vector<std::uint8_t> wb_data;
|
||||
wb.save(wb_data);
|
||||
|
||||
std::ifstream file_stream(file.string(), std::ios::binary);
|
||||
std::vector<std::uint8_t> file_data;
|
||||
|
||||
{
|
||||
xlnt::detail::vector_ostreambuf file_data_buffer(file_data);
|
||||
std::ostream file_data_stream(&file_data_buffer);
|
||||
file_data_stream << file_stream.rdbuf();
|
||||
}
|
||||
|
||||
return xml_helper::xlsx_archives_match(wb_data, file_data);
|
||||
}
|
||||
|
||||
void test_produce_empty()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("3_default.xlsx");
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_produce_simple_excel()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto bold_font = xlnt::font().bold(true);
|
||||
|
||||
ws.cell("A1").value("Type");
|
||||
ws.cell("A1").font(bold_font);
|
||||
|
||||
ws.cell("B1").value("Value");
|
||||
ws.cell("B1").font(bold_font);
|
||||
|
||||
ws.cell("A2").value("null");
|
||||
ws.cell("B2").value(nullptr);
|
||||
|
||||
ws.cell("A3").value("bool (true)");
|
||||
ws.cell("B3").value(true);
|
||||
|
||||
ws.cell("A4").value("bool (false)");
|
||||
ws.cell("B4").value(false);
|
||||
|
||||
ws.cell("A5").value("number (int)");
|
||||
ws.cell("B5").value(std::numeric_limits<int>::max());
|
||||
|
||||
ws.cell("A5").value("number (unsigned int)");
|
||||
ws.cell("B5").value(std::numeric_limits<unsigned int>::max());
|
||||
|
||||
ws.cell("A6").value("number (long long int)");
|
||||
ws.cell("B6").value(std::numeric_limits<long long int>::max());
|
||||
|
||||
ws.cell("A6").value("number (unsigned long long int)");
|
||||
ws.cell("B6").value(std::numeric_limits<unsigned long long int>::max());
|
||||
|
||||
ws.cell("A13").value("number (float)");
|
||||
ws.cell("B13").value(std::numeric_limits<float>::max());
|
||||
|
||||
ws.cell("A14").value("number (double)");
|
||||
ws.cell("B14").value(std::numeric_limits<double>::max());
|
||||
|
||||
ws.cell("A15").value("number (long double)");
|
||||
ws.cell("B15").value(std::numeric_limits<long double>::max());
|
||||
|
||||
ws.cell("A16").value("text (char *)");
|
||||
ws.cell("B16").value("string");
|
||||
|
||||
ws.cell("A17").value("text (std::string)");
|
||||
ws.cell("B17").value(std::string("string"));
|
||||
|
||||
ws.cell("A18").value("date");
|
||||
ws.cell("B18").value(xlnt::date(2016, 2, 3));
|
||||
|
||||
ws.cell("A19").value("time");
|
||||
ws.cell("B19").value(xlnt::time(1, 2, 3, 4));
|
||||
|
||||
ws.cell("A20").value("datetime");
|
||||
ws.cell("B20").value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4));
|
||||
|
||||
ws.cell("A21").value("timedelta");
|
||||
ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5));
|
||||
|
||||
ws.freeze_panes("B2");
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
wb.save(temp_buffer);
|
||||
assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_save_after_sheet_deletion()
|
||||
{
|
||||
xlnt::workbook workbook;
|
||||
|
||||
assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
auto sheet = workbook.create_sheet();
|
||||
sheet.title("XXX1");
|
||||
assert_equals(workbook.sheet_titles().size(), 2);
|
||||
|
||||
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
|
||||
assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
assert_throws_nothing(workbook.save(temp_buffer));
|
||||
assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_write_comments_hyperlinks_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto sheet1 = wb.active_sheet();
|
||||
auto comment_font = xlnt::font().bold(true).size(10).color(xlnt::indexed_color(81)).name("Calibri");
|
||||
|
||||
sheet1.cell("A1").value("Sheet1!A1");
|
||||
sheet1.cell("A1").comment("Sheet1 comment", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet1.cell("A2").value("Sheet1!A2");
|
||||
sheet1.cell("A2").comment("Sheet1 comment2", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet1.cell("A4").hyperlink("https://microsoft.com", "hyperlink1");
|
||||
sheet1.cell("A5").hyperlink("https://google.com");
|
||||
sheet1.cell("A6").hyperlink(sheet1.cell("A1"));
|
||||
sheet1.cell("A7").hyperlink("mailto:invalid@example.com?subject=important");
|
||||
|
||||
sheet1.cell("C1").formula("=CONCATENATE(C2,C3)");
|
||||
sheet1.cell("C2").value("a");
|
||||
sheet1.cell("C3").value("b");
|
||||
|
||||
auto sheet2 = wb.create_sheet();
|
||||
sheet2.cell("A1").value("Sheet2!A1");
|
||||
sheet2.cell("A2").comment("Sheet2 comment", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet2.cell("A2").value("Sheet2!A2");
|
||||
sheet2.cell("A2").comment("Sheet2 comment2", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet2.cell("A4").hyperlink("https://apple.com", "hyperlink2");
|
||||
|
||||
sheet2.cell("C1").formula("=C2*C3");
|
||||
sheet2.cell("C2").value(2);
|
||||
sheet2.cell("C3").value(3);
|
||||
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_save_after_clear_all_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert(ws1.cell("C1").has_formula());
|
||||
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
ws1.cell("C1").clear_formula();
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
assert(ws2.cell("C1").has_formula());
|
||||
assert_equals(ws2.cell("C1").formula(), "C2*C3");
|
||||
ws2.cell("C1").clear_formula();
|
||||
|
||||
wb.save("clear_formulae.xlsx");
|
||||
}
|
||||
|
||||
void test_non_xlsx()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
|
||||
assert_throws(wb.load(path), xlnt::invalid_file);
|
||||
}
|
||||
|
||||
void test_decrypt_agile()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("5_encrypted_agile.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_decrypt_libre_office()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("6_encrypted_libre.xlsx");
|
||||
assert_throws_nothing(wb.load(path, u8"пароль"));
|
||||
}
|
||||
|
||||
void test_decrypt_standard()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("7_encrypted_standard.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "password"));
|
||||
}
|
||||
|
||||
void test_decrypt_numbers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("8_encrypted_numbers.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_read_unicode_filename()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
xlnt::workbook wb;
|
||||
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
|
||||
wb.load(path);
|
||||
assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
|
||||
#ifndef __MINGW32__
|
||||
xlnt::workbook wb2;
|
||||
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
|
||||
wb2.load(path2);
|
||||
assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_comments()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto sheet1 = wb[0];
|
||||
assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
|
||||
assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
|
||||
assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User");
|
||||
|
||||
auto sheet2 = wb[1];
|
||||
assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
|
||||
assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
|
||||
assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User");
|
||||
}
|
||||
|
||||
void test_read_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert_equals(ws1.title(), "Sheet1");
|
||||
assert(ws1.cell("A4").has_hyperlink());
|
||||
assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1");
|
||||
assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
|
||||
assert(ws1.cell("A5").has_hyperlink());
|
||||
assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/");
|
||||
assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/");
|
||||
//assert(ws1.cell("A6").has_hyperlink());
|
||||
assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
|
||||
//assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1");
|
||||
assert(ws1.cell("A7").has_hyperlink());
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
void test_read_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert_equals(ws1.cell("C1").value<std::string>(), "ab");
|
||||
assert(ws1.cell("C1").has_formula());
|
||||
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
assert_equals(ws1.cell("C2").value<std::string>(), "a");
|
||||
assert_equals(ws1.cell("C3").value<std::string>(), "b");
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
assert_equals(ws2.cell("C1").value<int>(), 6);
|
||||
assert(ws2.cell("C1").has_formula());
|
||||
assert_equals(ws2.cell("C1").formula(), "C2*C3");
|
||||
assert_equals(ws2.cell("C2").value<int>(), 2);
|
||||
assert_equals(ws2.cell("C3").value<int>(), 3);
|
||||
}
|
||||
|
||||
void test_read_headers_and_footers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
assert_equals(ws.cell("A1").value<std::string>(), "header");
|
||||
assert_equals(ws.cell("A2").value<std::string>(), "and");
|
||||
assert_equals(ws.cell("A3").value<std::string>(), "footer");
|
||||
assert_equals(ws.cell("A4").value<std::string>(), "page1");
|
||||
assert_equals(ws.cell("A43").value<std::string>(), "page2");
|
||||
|
||||
assert(ws.has_header_footer());
|
||||
assert(ws.header_footer().align_with_margins());
|
||||
assert(ws.header_footer().scale_with_doc());
|
||||
assert(!ws.header_footer().different_first());
|
||||
assert(!ws.header_footer().different_odd_even());
|
||||
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
void test_read_custom_properties()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
|
||||
assert(wb.has_custom_property("Client"));
|
||||
assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read file as an XLSX-formatted ZIP file in the filesystem to a workbook,
|
||||
/// write the workbook back to memory, then ensure that the contents of the two files are equivalent.
|
||||
/// </summary>
|
||||
bool round_trip_matches_rw(const xlnt::path &source)
|
||||
{
|
||||
xlnt::workbook source_workbook;
|
||||
source_workbook.load(source);
|
||||
|
||||
std::vector<std::uint8_t> destination;
|
||||
source_workbook.save(destination);
|
||||
source_workbook.save("temp.xlsx");
|
||||
|
||||
#ifdef _MSC_VER
|
||||
std::ifstream source_stream(source.wstring(), std::ios::binary);
|
||||
#else
|
||||
std::ifstream source_stream(source.string(), std::ios::binary);
|
||||
#endif
|
||||
|
||||
return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination);
|
||||
}
|
||||
|
||||
bool round_trip_matches_rw(const xlnt::path &source, const std::string &password)
|
||||
{
|
||||
xlnt::workbook source_workbook;
|
||||
source_workbook.load(source, password);
|
||||
|
||||
std::vector<std::uint8_t> destination;
|
||||
source_workbook.save(destination);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
std::ifstream source_stream(source.wstring(), std::ios::binary);
|
||||
#else
|
||||
std::ifstream source_stream(source.string(), std::ios::binary);
|
||||
#endif
|
||||
|
||||
const auto source_decrypted = xlnt::detail::decrypt_xlsx(
|
||||
xlnt::detail::to_vector(source_stream), password);
|
||||
|
||||
return xml_helper::xlsx_archives_match(source_decrypted, destination);
|
||||
}
|
||||
|
||||
void test_round_trip_rw()
|
||||
{
|
||||
const auto files = std::vector<std::string>
|
||||
{
|
||||
"2_minimal",
|
||||
"3_default",
|
||||
"4_every_style",
|
||||
u8"9_unicode_Λ",
|
||||
"10_comments_hyperlinks_formulae",
|
||||
"11_print_settings",
|
||||
"12_advanced_properties"
|
||||
};
|
||||
|
||||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
assert(round_trip_matches_rw(path));
|
||||
}
|
||||
}
|
||||
|
||||
void test_round_trip_rw_encrypted()
|
||||
{
|
||||
const auto files = std::vector<std::string>
|
||||
{
|
||||
"5_encrypted_agile",
|
||||
"6_encrypted_libre",
|
||||
"7_encrypted_standard",
|
||||
"8_encrypted_numbers"
|
||||
};
|
||||
|
||||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
auto password = std::string(file == "7_encrypted_standard" ? "password"
|
||||
: file == "6_encrypted_libre" ? u8"пароль"
|
||||
: "secret");
|
||||
assert(round_trip_matches_rw(path, password));
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,4 +1,27 @@
|
|||
#pragma once
|
||||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -10,156 +33,5 @@
|
|||
class test_consume_xlsx : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_non_xlsx()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
|
||||
assert_throws(wb.load(path), xlnt::invalid_file);
|
||||
}
|
||||
|
||||
void test_decrypt_agile()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("5_encrypted_agile.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_decrypt_libre_office()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("6_encrypted_libre.xlsx");
|
||||
assert_throws_nothing(wb.load(path, u8"пароль"));
|
||||
}
|
||||
|
||||
void test_decrypt_standard()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("7_encrypted_standard.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "password"));
|
||||
}
|
||||
|
||||
void test_decrypt_numbers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("8_encrypted_numbers.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_read_unicode_filename()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
xlnt::workbook wb;
|
||||
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
|
||||
wb.load(path);
|
||||
assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
|
||||
#ifndef __MINGW32__
|
||||
xlnt::workbook wb2;
|
||||
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
|
||||
wb2.load(path2);
|
||||
assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_comments()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto sheet1 = wb[0];
|
||||
assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
|
||||
assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
|
||||
assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User");
|
||||
|
||||
auto sheet2 = wb[1];
|
||||
assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
|
||||
assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
|
||||
assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User");
|
||||
}
|
||||
|
||||
void test_read_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert_equals(ws1.title(), "Sheet1");
|
||||
assert(ws1.cell("A4").has_hyperlink());
|
||||
assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1");
|
||||
assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
|
||||
assert(ws1.cell("A5").has_hyperlink());
|
||||
assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/");
|
||||
assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/");
|
||||
//assert(ws1.cell("A6").has_hyperlink());
|
||||
assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
|
||||
//assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1");
|
||||
assert(ws1.cell("A7").has_hyperlink());
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
void test_read_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert_equals(ws1.cell("C1").value<std::string>(), "ab");
|
||||
assert(ws1.cell("C1").has_formula());
|
||||
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
assert_equals(ws1.cell("C2").value<std::string>(), "a");
|
||||
assert_equals(ws1.cell("C3").value<std::string>(), "b");
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
assert_equals(ws2.cell("C1").value<int>(), 6);
|
||||
assert(ws2.cell("C1").has_formula());
|
||||
assert_equals(ws2.cell("C1").formula(), "C2*C3");
|
||||
assert_equals(ws2.cell("C2").value<int>(), 2);
|
||||
assert_equals(ws2.cell("C3").value<int>(), 3);
|
||||
}
|
||||
|
||||
void test_read_headers_and_footers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
assert_equals(ws.cell("A1").value<std::string>(), "header");
|
||||
assert_equals(ws.cell("A2").value<std::string>(), "and");
|
||||
assert_equals(ws.cell("A3").value<std::string>(), "footer");
|
||||
assert_equals(ws.cell("A4").value<std::string>(), "page1");
|
||||
assert_equals(ws.cell("A43").value<std::string>(), "page2");
|
||||
|
||||
assert(ws.has_header_footer());
|
||||
assert(ws.header_footer().align_with_margins());
|
||||
assert(ws.header_footer().scale_with_doc());
|
||||
assert(!ws.header_footer().different_first());
|
||||
assert(!ws.header_footer().different_odd_even());
|
||||
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
void test_read_custom_properties()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
|
||||
assert(wb.has_custom_property("Client"));
|
||||
assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,181 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_produce_xlsx : public test_suite
|
||||
{
|
||||
public:
|
||||
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
|
||||
{
|
||||
std::vector<std::uint8_t> wb_data;
|
||||
wb.save(wb_data);
|
||||
|
||||
std::ifstream file_stream(file.string(), std::ios::binary);
|
||||
std::vector<std::uint8_t> file_data;
|
||||
|
||||
{
|
||||
xlnt::detail::vector_ostreambuf file_data_buffer(file_data);
|
||||
std::ostream file_data_stream(&file_data_buffer);
|
||||
file_data_stream << file_stream.rdbuf();
|
||||
}
|
||||
|
||||
return xml_helper::xlsx_archives_match(wb_data, file_data);
|
||||
}
|
||||
|
||||
void test_produce_empty()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("3_default.xlsx");
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_produce_simple_excel()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto bold_font = xlnt::font().bold(true);
|
||||
|
||||
ws.cell("A1").value("Type");
|
||||
ws.cell("A1").font(bold_font);
|
||||
|
||||
ws.cell("B1").value("Value");
|
||||
ws.cell("B1").font(bold_font);
|
||||
|
||||
ws.cell("A2").value("null");
|
||||
ws.cell("B2").value(nullptr);
|
||||
|
||||
ws.cell("A3").value("bool (true)");
|
||||
ws.cell("B3").value(true);
|
||||
|
||||
ws.cell("A4").value("bool (false)");
|
||||
ws.cell("B4").value(false);
|
||||
|
||||
ws.cell("A5").value("number (int)");
|
||||
ws.cell("B5").value(std::numeric_limits<int>::max());
|
||||
|
||||
ws.cell("A5").value("number (unsigned int)");
|
||||
ws.cell("B5").value(std::numeric_limits<unsigned int>::max());
|
||||
|
||||
ws.cell("A6").value("number (long long int)");
|
||||
ws.cell("B6").value(std::numeric_limits<long long int>::max());
|
||||
|
||||
ws.cell("A6").value("number (unsigned long long int)");
|
||||
ws.cell("B6").value(std::numeric_limits<unsigned long long int>::max());
|
||||
|
||||
ws.cell("A13").value("number (float)");
|
||||
ws.cell("B13").value(std::numeric_limits<float>::max());
|
||||
|
||||
ws.cell("A14").value("number (double)");
|
||||
ws.cell("B14").value(std::numeric_limits<double>::max());
|
||||
|
||||
ws.cell("A15").value("number (long double)");
|
||||
ws.cell("B15").value(std::numeric_limits<long double>::max());
|
||||
|
||||
ws.cell("A16").value("text (char *)");
|
||||
ws.cell("B16").value("string");
|
||||
|
||||
ws.cell("A17").value("text (std::string)");
|
||||
ws.cell("B17").value(std::string("string"));
|
||||
|
||||
ws.cell("A18").value("date");
|
||||
ws.cell("B18").value(xlnt::date(2016, 2, 3));
|
||||
|
||||
ws.cell("A19").value("time");
|
||||
ws.cell("B19").value(xlnt::time(1, 2, 3, 4));
|
||||
|
||||
ws.cell("A20").value("datetime");
|
||||
ws.cell("B20").value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4));
|
||||
|
||||
ws.cell("A21").value("timedelta");
|
||||
ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5));
|
||||
|
||||
ws.freeze_panes("B2");
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
wb.save(temp_buffer);
|
||||
assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_save_after_sheet_deletion()
|
||||
{
|
||||
xlnt::workbook workbook;
|
||||
|
||||
assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
auto sheet = workbook.create_sheet();
|
||||
sheet.title("XXX1");
|
||||
assert_equals(workbook.sheet_titles().size(), 2);
|
||||
|
||||
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
|
||||
assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
assert_throws_nothing(workbook.save(temp_buffer));
|
||||
assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_write_comments_hyperlinks_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto sheet1 = wb.active_sheet();
|
||||
auto comment_font = xlnt::font().bold(true).size(10).color(xlnt::indexed_color(81)).name("Calibri");
|
||||
|
||||
sheet1.cell("A1").value("Sheet1!A1");
|
||||
sheet1.cell("A1").comment("Sheet1 comment", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet1.cell("A2").value("Sheet1!A2");
|
||||
sheet1.cell("A2").comment("Sheet1 comment2", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet1.cell("A4").hyperlink("https://microsoft.com", "hyperlink1");
|
||||
sheet1.cell("A5").hyperlink("https://google.com");
|
||||
sheet1.cell("A6").hyperlink(sheet1.cell("A1"));
|
||||
sheet1.cell("A7").hyperlink("mailto:invalid@example.com?subject=important");
|
||||
|
||||
sheet1.cell("C1").formula("=CONCATENATE(C2,C3)");
|
||||
sheet1.cell("C2").value("a");
|
||||
sheet1.cell("C3").value("b");
|
||||
|
||||
auto sheet2 = wb.create_sheet();
|
||||
sheet2.cell("A1").value("Sheet2!A1");
|
||||
sheet2.cell("A2").comment("Sheet2 comment", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet2.cell("A2").value("Sheet2!A2");
|
||||
sheet2.cell("A2").comment("Sheet2 comment2", comment_font, "Microsoft Office User");
|
||||
|
||||
sheet2.cell("A4").hyperlink("https://apple.com", "hyperlink2");
|
||||
|
||||
sheet2.cell("C1").formula("=C2*C3");
|
||||
sheet2.cell("C2").value(2);
|
||||
sheet2.cell("C3").value(3);
|
||||
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_save_after_clear_all_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert(ws1.cell("C1").has_formula());
|
||||
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
ws1.cell("C1").clear_formula();
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
assert(ws2.cell("C1").has_formula());
|
||||
assert_equals(ws2.cell("C1").formula(), "C2*C3");
|
||||
ws2.cell("C1").clear_formula();
|
||||
|
||||
wb.save("clear_formulae.xlsx");
|
||||
}
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_password_hash : public test_suite
|
||||
{
|
||||
};
|
|
@ -1,97 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
#include <detail/crypto/xlsx_crypto.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_round_trip : public test_suite
|
||||
{
|
||||
public:
|
||||
/// <summary>
|
||||
/// Read file as an XLSX-formatted ZIP file in the filesystem to a workbook,
|
||||
/// write the workbook back to memory, then ensure that the contents of the two files are equivalent.
|
||||
/// </summary>
|
||||
bool round_trip_matches_rw(const xlnt::path &source)
|
||||
{
|
||||
xlnt::workbook source_workbook;
|
||||
source_workbook.load(source);
|
||||
|
||||
std::vector<std::uint8_t> destination;
|
||||
source_workbook.save(destination);
|
||||
source_workbook.save("temp.xlsx");
|
||||
|
||||
#ifdef _MSC_VER
|
||||
std::ifstream source_stream(source.wstring(), std::ios::binary);
|
||||
#else
|
||||
std::ifstream source_stream(source.string(), std::ios::binary);
|
||||
#endif
|
||||
|
||||
return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination);
|
||||
}
|
||||
|
||||
bool round_trip_matches_rw(const xlnt::path &source, const std::string &password)
|
||||
{
|
||||
xlnt::workbook source_workbook;
|
||||
source_workbook.load(source, password);
|
||||
|
||||
std::vector<std::uint8_t> destination;
|
||||
source_workbook.save(destination);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
std::ifstream source_stream(source.wstring(), std::ios::binary);
|
||||
#else
|
||||
std::ifstream source_stream(source.string(), std::ios::binary);
|
||||
#endif
|
||||
|
||||
const auto source_decrypted = xlnt::detail::decrypt_xlsx(
|
||||
xlnt::detail::to_vector(source_stream), password);
|
||||
|
||||
return xml_helper::xlsx_archives_match(source_decrypted, destination);
|
||||
}
|
||||
|
||||
void test_round_trip_rw()
|
||||
{
|
||||
const auto files = std::vector<std::string>
|
||||
{
|
||||
"2_minimal",
|
||||
"3_default",
|
||||
"4_every_style",
|
||||
u8"9_unicode_Λ",
|
||||
"10_comments_hyperlinks_formulae",
|
||||
"11_print_settings",
|
||||
"12_advanced_properties"
|
||||
};
|
||||
|
||||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
assert(round_trip_matches_rw(path));
|
||||
}
|
||||
}
|
||||
|
||||
void test_round_trip_rw_encrypted()
|
||||
{
|
||||
const auto files = std::vector<std::string>
|
||||
{
|
||||
"5_encrypted_agile",
|
||||
"6_encrypted_libre",
|
||||
"7_encrypted_standard",
|
||||
"8_encrypted_numbers"
|
||||
};
|
||||
|
||||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
auto password = std::string(file == "7_encrypted_standard" ? "password"
|
||||
: file == "6_encrypted_libre" ? u8"пароль"
|
||||
: "secret");
|
||||
assert(round_trip_matches_rw(path, password));
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_theme : public test_suite
|
||||
{
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_vba : public test_suite
|
||||
{
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_theme : public test_suite
|
||||
{
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_vba : public test_suite
|
||||
{
|
||||
};
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -7,11 +30,14 @@
|
|||
#include <xlnt/xlnt.hpp>
|
||||
#include "helpers/temporary_file.hpp"
|
||||
|
||||
//checked with 52f25d6
|
||||
|
||||
class test_workbook : public test_suite
|
||||
class workbook_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
workbook_test_suite()
|
||||
{
|
||||
register_test(test_active_sheet);
|
||||
}
|
||||
|
||||
void test_active_sheet()
|
||||
{
|
||||
xlnt::workbook wb;
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_datavalidation : public test_suite
|
||||
{
|
||||
public:
|
||||
};
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class page_setup_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::page_setup ps;
|
||||
|
||||
assert_equals(ps.paper_size(), xlnt::paper_size::letter);
|
||||
ps.paper_size(xlnt::paper_size::executive);
|
||||
assert_equals(ps.paper_size(), xlnt::paper_size::executive);
|
||||
|
||||
assert_equals(ps.orientation(), xlnt::orientation::portrait);
|
||||
ps.orientation(xlnt::orientation::landscape);
|
||||
assert_equals(ps.orientation(), xlnt::orientation::landscape);
|
||||
|
||||
assert(!ps.fit_to_page());
|
||||
ps.fit_to_page(true);
|
||||
assert(ps.fit_to_page());
|
||||
|
||||
assert(!ps.fit_to_height());
|
||||
ps.fit_to_height(true);
|
||||
assert(ps.fit_to_height());
|
||||
|
||||
assert(!ps.fit_to_width());
|
||||
ps.fit_to_width(true);
|
||||
assert(ps.fit_to_width());
|
||||
|
||||
assert(!ps.horizontal_centered());
|
||||
ps.horizontal_centered(true);
|
||||
assert(ps.horizontal_centered());
|
||||
|
||||
assert(!ps.vertical_centered());
|
||||
ps.vertical_centered(true);
|
||||
assert(ps.vertical_centered());
|
||||
}
|
||||
};
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class range_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_batch_formatting()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
for (auto row = 1; row <= 10; ++row)
|
||||
{
|
||||
for (auto column = 1; column <= 10; ++column)
|
||||
{
|
||||
auto ref = xlnt::cell_reference(column, row);
|
||||
ws[ref].value(ref.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
ws.range("A1:A10").font(xlnt::font().name("Arial"));
|
||||
ws.range("A1:J1").font(xlnt::font().bold(true));
|
||||
|
||||
assert_equals(ws.cell("A1").font().name(), "Calibri");
|
||||
assert(ws.cell("A1").font().bold());
|
||||
|
||||
assert_equals(ws.cell("A2").font().name(), "Arial");
|
||||
assert(!ws.cell("A2").font().bold());
|
||||
|
||||
assert_equals(ws.cell("B1").font().name(), "Calibri");
|
||||
assert(ws.cell("B1").font().bold());
|
||||
|
||||
assert(!ws.cell("B2").has_format());
|
||||
}
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_datavalidation : public test_suite
|
||||
{
|
||||
public:
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_page_setup : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::page_setup ps;
|
||||
|
||||
assert_equals(ps.paper_size(), xlnt::paper_size::letter);
|
||||
ps.paper_size(xlnt::paper_size::executive);
|
||||
assert_equals(ps.paper_size(), xlnt::paper_size::executive);
|
||||
|
||||
assert_equals(ps.orientation(), xlnt::orientation::portrait);
|
||||
ps.orientation(xlnt::orientation::landscape);
|
||||
assert_equals(ps.orientation(), xlnt::orientation::landscape);
|
||||
|
||||
assert(!ps.fit_to_page());
|
||||
ps.fit_to_page(true);
|
||||
assert(ps.fit_to_page());
|
||||
|
||||
assert(!ps.fit_to_height());
|
||||
ps.fit_to_height(true);
|
||||
assert(ps.fit_to_height());
|
||||
|
||||
assert(!ps.fit_to_width());
|
||||
ps.fit_to_width(true);
|
||||
assert(ps.fit_to_width());
|
||||
|
||||
assert(!ps.horizontal_centered());
|
||||
ps.horizontal_centered(true);
|
||||
assert(ps.horizontal_centered());
|
||||
|
||||
assert(!ps.vertical_centered());
|
||||
ps.vertical_centered(true);
|
||||
assert(ps.vertical_centered());
|
||||
}
|
||||
};
|
|
@ -1,41 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_range : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_batch_formatting()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
for (auto row = 1; row <= 10; ++row)
|
||||
{
|
||||
for (auto column = 1; column <= 10; ++column)
|
||||
{
|
||||
auto ref = xlnt::cell_reference(column, row);
|
||||
ws[ref].value(ref.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
ws.range("A1:A10").font(xlnt::font().name("Arial"));
|
||||
ws.range("A1:J1").font(xlnt::font().bold(true));
|
||||
|
||||
assert_equals(ws.cell("A1").font().name(), "Calibri");
|
||||
assert(ws.cell("A1").font().bold());
|
||||
|
||||
assert_equals(ws.cell("A2").font().name(), "Arial");
|
||||
assert(!ws.cell("A2").font().bold());
|
||||
|
||||
assert_equals(ws.cell("B1").font().name(), "Calibri");
|
||||
assert(ws.cell("B1").font().bold());
|
||||
|
||||
assert(!ws.cell("B2").has_format());
|
||||
}
|
||||
};
|
|
@ -1,3 +1,26 @@
|
|||
// Copyright (c) 2014-2017 Thomas Fussell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
@ -7,69 +30,69 @@
|
|||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_worksheet : public test_suite
|
||||
class worksheet_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
test_worksheet()
|
||||
worksheet_test_suite()
|
||||
{
|
||||
register_test(test_new_worksheet);
|
||||
register_test(test_cell);
|
||||
register_test(test_invalid_cell);
|
||||
register_test(test_worksheet_dimension);
|
||||
register_test(test_fill_rows);
|
||||
register_test(test_get_named_range);
|
||||
register_test(test_get_bad_named_range);
|
||||
register_test(test_get_named_range_wrong_sheet);
|
||||
register_test(test_remove_named_range_bad);
|
||||
register_test(test_cell_alternate_coordinates);
|
||||
register_test(test_cell_range_name);
|
||||
register_test(test_hyperlink_value);
|
||||
register_test(test_rows);
|
||||
register_test(test_no_rows);
|
||||
register_test(test_no_cols);
|
||||
register_test(test_one_cell);
|
||||
register_test(test_cols);
|
||||
register_test(test_auto_filter);
|
||||
register_test(test_getitem);
|
||||
register_test(test_setitem);
|
||||
register_test(test_getslice);
|
||||
register_test(test_freeze);
|
||||
register_test(test_merged_cells_lookup);
|
||||
register_test(test_merged_cell_ranges);
|
||||
register_test(test_merge_range_string);
|
||||
register_test(test_unmerge_bad);
|
||||
register_test(test_unmerge_range_string);
|
||||
register_test(test_print_titles_old);
|
||||
register_test(test_print_titles_new);
|
||||
register_test(test_print_area);
|
||||
register_test(test_freeze_panes_horiz);
|
||||
register_test(test_freeze_panes_vert);
|
||||
register_test(test_freeze_panes_both);
|
||||
register_test(test_min_column);
|
||||
register_test(test_max_column);
|
||||
register_test(test_min_row);
|
||||
register_test(test_max_row);
|
||||
register_test(test_const_iterators);
|
||||
register_test(test_const_reverse_iterators);
|
||||
register_test(test_column_major_iterators);
|
||||
register_test(test_reverse_column_major_iterators);
|
||||
register_test(test_const_column_major_iterators);
|
||||
register_test(test_const_reverse_column_major_iterators);
|
||||
register_test(test_header);
|
||||
register_test(test_footer);
|
||||
register_test(test_page_setup);
|
||||
register_test(test_unique_sheet_name);
|
||||
register_test(test_page_margins);
|
||||
register_test(test_garbage_collect);
|
||||
register_test(test_has_cell);
|
||||
register_test(test_get_range_by_string);
|
||||
register_test(test_operators);
|
||||
register_test(test_reserve);
|
||||
register_test(test_iterate);
|
||||
register_test(test_range_reference);
|
||||
register_test(test_get_point_pos);
|
||||
register_test(test_named_range_named_cell_reference);
|
||||
register_test(test_iteration_skip_empty);
|
||||
register_test(test_new_worksheet);
|
||||
register_test(test_cell);
|
||||
register_test(test_invalid_cell);
|
||||
register_test(test_worksheet_dimension);
|
||||
register_test(test_fill_rows);
|
||||
register_test(test_get_named_range);
|
||||
register_test(test_get_bad_named_range);
|
||||
register_test(test_get_named_range_wrong_sheet);
|
||||
register_test(test_remove_named_range_bad);
|
||||
register_test(test_cell_alternate_coordinates);
|
||||
register_test(test_cell_range_name);
|
||||
register_test(test_hyperlink_value);
|
||||
register_test(test_rows);
|
||||
register_test(test_no_rows);
|
||||
register_test(test_no_cols);
|
||||
register_test(test_one_cell);
|
||||
register_test(test_cols);
|
||||
register_test(test_auto_filter);
|
||||
register_test(test_getitem);
|
||||
register_test(test_setitem);
|
||||
register_test(test_getslice);
|
||||
register_test(test_freeze);
|
||||
register_test(test_merged_cells_lookup);
|
||||
register_test(test_merged_cell_ranges);
|
||||
register_test(test_merge_range_string);
|
||||
register_test(test_unmerge_bad);
|
||||
register_test(test_unmerge_range_string);
|
||||
register_test(test_print_titles_old);
|
||||
register_test(test_print_titles_new);
|
||||
register_test(test_print_area);
|
||||
register_test(test_freeze_panes_horiz);
|
||||
register_test(test_freeze_panes_vert);
|
||||
register_test(test_freeze_panes_both);
|
||||
register_test(test_min_column);
|
||||
register_test(test_max_column);
|
||||
register_test(test_min_row);
|
||||
register_test(test_max_row);
|
||||
register_test(test_const_iterators);
|
||||
register_test(test_const_reverse_iterators);
|
||||
register_test(test_column_major_iterators);
|
||||
register_test(test_reverse_column_major_iterators);
|
||||
register_test(test_const_column_major_iterators);
|
||||
register_test(test_const_reverse_column_major_iterators);
|
||||
register_test(test_header);
|
||||
register_test(test_footer);
|
||||
register_test(test_page_setup);
|
||||
register_test(test_unique_sheet_name);
|
||||
register_test(test_page_margins);
|
||||
register_test(test_garbage_collect);
|
||||
register_test(test_has_cell);
|
||||
register_test(test_get_range_by_string);
|
||||
register_test(test_operators);
|
||||
register_test(test_reserve);
|
||||
register_test(test_iterate);
|
||||
register_test(test_range_reference);
|
||||
register_test(test_get_point_pos);
|
||||
register_test(test_named_range_named_cell_reference);
|
||||
register_test(test_iteration_skip_empty);
|
||||
}
|
||||
|
||||
void test_new_worksheet()
|
||||
|
@ -78,7 +101,7 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
assert(ws.workbook() == wb);
|
||||
}
|
||||
|
||||
|
||||
void test_cell()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -86,42 +109,42 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
assert_equals(cell.reference(), "A1");
|
||||
}
|
||||
|
||||
|
||||
void test_invalid_cell()
|
||||
{
|
||||
assert_throws(xlnt::cell_reference(xlnt::column_t((xlnt::column_t::index_t)0), 0),
|
||||
xlnt::invalid_cell_reference);
|
||||
}
|
||||
|
||||
|
||||
void test_worksheet_dimension()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
|
||||
assert_equals("A1:A1", ws.calculate_dimension());
|
||||
ws.cell("B12").value("AAA");
|
||||
assert_equals("B12:B12", ws.calculate_dimension());
|
||||
}
|
||||
|
||||
|
||||
void test_fill_rows()
|
||||
{
|
||||
std::size_t row = 0;
|
||||
std::size_t column = 0;
|
||||
std::string coordinate = "A1";
|
||||
|
||||
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
|
||||
ws.cell("A1").value("first");
|
||||
ws.cell("C9").value("last");
|
||||
|
||||
|
||||
assert_equals(ws.calculate_dimension(), "A1:C9");
|
||||
assert_equals(ws.rows(false)[row][column].reference(), coordinate);
|
||||
|
||||
|
||||
row = 8;
|
||||
column = 2;
|
||||
coordinate = "C9";
|
||||
|
||||
|
||||
assert_equals(ws.rows(false)[row][column].reference(), coordinate);
|
||||
}
|
||||
|
||||
|
@ -141,14 +164,14 @@ public:
|
|||
assert_equals(1, xlrange2[0].length());
|
||||
assert_equals(6, xlrange2[0][0].row());
|
||||
}
|
||||
|
||||
|
||||
void test_get_bad_named_range()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
assert_throws(ws.named_range("bad_range"), xlnt::key_not_found);
|
||||
}
|
||||
|
||||
|
||||
void test_get_named_range_wrong_sheet()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -159,7 +182,7 @@ public:
|
|||
wb.create_named_range("wrong_sheet_range", ws1, "C5");
|
||||
assert_throws(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found);
|
||||
}
|
||||
|
||||
|
||||
void test_remove_named_range_bad()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -174,9 +197,9 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(4, 8));
|
||||
assert_equals(cell.reference(), "D8");
|
||||
}
|
||||
|
||||
|
||||
// void test_cell_insufficient_coordinates() {}
|
||||
|
||||
|
||||
void test_cell_range_name()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -188,7 +211,7 @@ public:
|
|||
assert_equals(c_range_coord, c_range_name);
|
||||
assert(c_range_coord[0][0] == c_cell);
|
||||
}
|
||||
|
||||
|
||||
void test_hyperlink_value()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -205,89 +228,89 @@ public:
|
|||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
|
||||
ws.cell("A1").value("first");
|
||||
ws.cell("C9").value("last");
|
||||
|
||||
|
||||
auto rows = ws.rows();
|
||||
|
||||
|
||||
assert_equals(rows.length(), 9);
|
||||
|
||||
|
||||
auto first_row = rows[0];
|
||||
auto last_row = rows[8];
|
||||
|
||||
|
||||
assert_equals(first_row[0].value<std::string>(), "first");
|
||||
assert_equals(first_row[0].reference(), "A1");
|
||||
assert_equals(last_row[2].value<std::string>(), "last");
|
||||
}
|
||||
|
||||
|
||||
void test_no_rows()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
assert_equals(ws.rows().length(), 1);
|
||||
assert_equals(ws.rows()[0].length(), 1);
|
||||
}
|
||||
|
||||
|
||||
void test_no_cols()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
assert_equals(ws.columns().length(), 1);
|
||||
assert_equals(ws.columns()[0].length(), 1);
|
||||
}
|
||||
|
||||
|
||||
void test_one_cell()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
|
||||
assert_equals(ws.columns().length(), 1);
|
||||
assert_equals(ws.columns()[0].length(), 1);
|
||||
assert_equals(ws.columns()[0][0], cell);
|
||||
}
|
||||
|
||||
|
||||
// void test_by_col() {}
|
||||
|
||||
|
||||
void test_cols()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.cell("A1").value("first");
|
||||
ws.cell("C9").value("last");
|
||||
|
||||
|
||||
auto cols = ws.columns();
|
||||
|
||||
|
||||
assert_equals(cols.length(), 3);
|
||||
|
||||
|
||||
assert_equals(cols[0][0].value<std::string>(), "first");
|
||||
assert_equals(cols[2][8].value<std::string>(), "last");
|
||||
}
|
||||
|
||||
|
||||
void test_auto_filter()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.auto_filter(ws.range("a1:f1"));
|
||||
assert_equals(ws.auto_filter(), "A1:F1");
|
||||
|
||||
|
||||
ws.clear_auto_filter();
|
||||
assert(!ws.has_auto_filter());
|
||||
|
||||
|
||||
ws.auto_filter("c1:g9");
|
||||
assert_equals(ws.auto_filter(), "C1:G9");
|
||||
}
|
||||
|
||||
|
||||
void test_getitem()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto ws = wb.active_sheet();
|
||||
xlnt::cell cell = ws[xlnt::cell_reference("A1")];
|
||||
assert_equals(cell.reference().to_string(), "A1");
|
||||
assert_equals(cell.data_type(), xlnt::cell::type::null);
|
||||
|
@ -296,15 +319,15 @@ public:
|
|||
void test_setitem()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto ws = wb.active_sheet();
|
||||
ws[xlnt::cell_reference("A12")].value(5);
|
||||
assert(ws[xlnt::cell_reference("A12")].value<int>() == 5);
|
||||
}
|
||||
|
||||
|
||||
void test_getslice()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell_range = ws.range("A1:B2");
|
||||
assert_equals(cell_range[0][0], ws.cell("A1"));
|
||||
assert_equals(cell_range[1][0], ws.cell("A2"));
|
||||
|
@ -315,25 +338,25 @@ public:
|
|||
void test_freeze()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.freeze_panes(ws.cell("b2"));
|
||||
assert_equals(ws.frozen_panes(), "B2");
|
||||
|
||||
|
||||
ws.unfreeze_panes();
|
||||
assert(!ws.has_frozen_panes());
|
||||
|
||||
|
||||
ws.freeze_panes("c5");
|
||||
assert_equals(ws.frozen_panes(), "C5");
|
||||
|
||||
|
||||
ws.freeze_panes(ws.cell("A1"));
|
||||
assert(!ws.has_frozen_panes());
|
||||
}
|
||||
|
||||
|
||||
void test_merged_cells_lookup()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto ws = wb.active_sheet();
|
||||
ws.cell("A2").value("test");
|
||||
ws.merge_cells("A1:N50");
|
||||
auto all_merged = ws.merged_ranges();
|
||||
|
@ -344,15 +367,15 @@ public:
|
|||
assert(!merged.contains("A51"));
|
||||
assert(!merged.contains("O1"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void test_merged_cell_ranges()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
assert_equals(ws.merged_ranges().size(), 0);
|
||||
}
|
||||
|
||||
|
||||
void test_merge_range_string()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -364,7 +387,7 @@ public:
|
|||
assert_equals(ws.merged_ranges(), expected);
|
||||
assert(!ws.cell("D4").has_value());
|
||||
}
|
||||
|
||||
|
||||
void test_unmerge_bad()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -390,16 +413,16 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
ws.print_title_rows(3);
|
||||
assert_equals(ws.print_titles(), "Sheet1!1:3");
|
||||
|
||||
|
||||
auto ws2 = wb.create_sheet();
|
||||
ws2.print_title_cols(4);
|
||||
assert_equals(ws2.print_titles(), "Sheet2!A:D");
|
||||
}
|
||||
|
||||
|
||||
void test_print_titles_new()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
||||
|
||||
auto ws = wb.active_sheet();
|
||||
ws.print_title_rows(4);
|
||||
assert_equals(ws.print_titles(), "Sheet1!1:4");
|
||||
|
@ -413,7 +436,7 @@ public:
|
|||
ws3.print_title_cols("C", "D");
|
||||
assert_equals(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D");
|
||||
}
|
||||
|
||||
|
||||
void test_print_area()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -421,13 +444,13 @@ public:
|
|||
ws.print_area("A1:F5");
|
||||
assert_equals(ws.print_area(), "$A$1:$F$5");
|
||||
}
|
||||
|
||||
|
||||
void test_freeze_panes_horiz()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.freeze_panes("A4");
|
||||
|
||||
|
||||
auto view = ws.view();
|
||||
assert_equals(view.selections().size(), 2);
|
||||
assert_equals(view.selections()[0].active_cell(), "A3");
|
||||
|
@ -438,13 +461,13 @@ public:
|
|||
assert_equals(view.pane().top_left_cell.get(), "A4");
|
||||
assert_equals(view.pane().y_split, 3);
|
||||
}
|
||||
|
||||
|
||||
void test_freeze_panes_vert()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.freeze_panes("D1");
|
||||
|
||||
|
||||
auto view = ws.view();
|
||||
assert_equals(view.selections().size(), 2);
|
||||
assert_equals(view.selections()[0].active_cell(), "C1");
|
||||
|
@ -455,13 +478,13 @@ public:
|
|||
assert_equals(view.pane().top_left_cell.get(), "D1");
|
||||
assert_equals(view.pane().x_split, 3);
|
||||
}
|
||||
|
||||
|
||||
void test_freeze_panes_both()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.freeze_panes("D4");
|
||||
|
||||
|
||||
auto view = ws.view();
|
||||
assert_equals(view.selections().size(), 3);
|
||||
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
||||
|
@ -475,14 +498,14 @@ public:
|
|||
assert_equals(view.pane().x_split, 3);
|
||||
assert_equals(view.pane().y_split, 3);
|
||||
}
|
||||
|
||||
|
||||
void test_min_column()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
assert_equals(ws.lowest_column(), 1);
|
||||
}
|
||||
|
||||
|
||||
void test_max_column()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -500,7 +523,7 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
assert_equals(ws.lowest_row(), 1);
|
||||
}
|
||||
|
||||
|
||||
void test_max_row()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -508,7 +531,7 @@ public:
|
|||
ws.cell("D4").value("D4");
|
||||
assert_equals(ws.highest_row(), 4);
|
||||
}
|
||||
|
||||
|
||||
void test_const_iterators()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -542,7 +565,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_const_reverse_iterators()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -581,7 +604,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_column_major_iterators()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -661,7 +684,7 @@ public:
|
|||
for (auto column_iter = columns.rbegin(); column_iter != columns.rend(); ++column_iter)
|
||||
{
|
||||
auto column = *column_iter;
|
||||
|
||||
|
||||
for (auto cell_iter = column.rbegin(); cell_iter != column.rend(); ++cell_iter)
|
||||
{
|
||||
auto cell = *cell_iter;
|
||||
|
@ -711,7 +734,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_const_reverse_column_major_iterators()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -747,7 +770,7 @@ public:
|
|||
for (auto column_iter = columns.crbegin(); column_iter != columns.crend(); ++column_iter)
|
||||
{
|
||||
const auto column = *column_iter;
|
||||
|
||||
|
||||
for (auto cell_iter = column.crbegin(); cell_iter != column.crend(); ++cell_iter)
|
||||
{
|
||||
const auto cell = *cell_iter;
|
||||
|
@ -756,7 +779,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_header()
|
||||
{
|
||||
xlnt::header_footer hf;
|
||||
|
@ -767,7 +790,7 @@ public:
|
|||
assert(!hf.has_header(location));
|
||||
assert(!hf.has_odd_even_header(location));
|
||||
assert(!hf.has_first_page_header(location));
|
||||
|
||||
|
||||
hf.header(location, "abc");
|
||||
|
||||
assert(hf.has_header(location));
|
||||
|
@ -781,7 +804,7 @@ public:
|
|||
assert(!hf.has_header(location));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_footer()
|
||||
{
|
||||
xlnt::header_footer hf;
|
||||
|
@ -792,7 +815,7 @@ public:
|
|||
assert(!hf.has_footer(location));
|
||||
assert(!hf.has_odd_even_footer(location));
|
||||
assert(!hf.has_first_page_footer(location));
|
||||
|
||||
|
||||
hf.footer(location, "abc");
|
||||
|
||||
assert(hf.has_footer(location));
|
||||
|
@ -806,13 +829,13 @@ public:
|
|||
assert(!hf.has_footer(location));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_page_setup()
|
||||
{
|
||||
xlnt::page_setup setup;
|
||||
setup.page_break(xlnt::page_break::column);
|
||||
xlnt::page_setup setup;
|
||||
setup.page_break(xlnt::page_break::column);
|
||||
assert_equals(setup.page_break(), xlnt::page_break::column);
|
||||
setup.scale(1.23);
|
||||
setup.scale(1.23);
|
||||
assert_equals(setup.scale(), 1.23);
|
||||
}
|
||||
|
||||
|
@ -841,7 +864,7 @@ public:
|
|||
margins.right(5);
|
||||
|
||||
ws.page_margins(margins);
|
||||
|
||||
|
||||
assert(ws.has_page_margins());
|
||||
assert_equals(ws.page_margins().top(), 0);
|
||||
assert_equals(ws.page_margins().bottom(), 1);
|
||||
|
@ -1014,15 +1037,15 @@ public:
|
|||
assert_equals(ws.point_pos(0, 0), "A1");
|
||||
}
|
||||
|
||||
void test_named_range_named_cell_reference()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
assert_throws(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter);
|
||||
assert_throws(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter);
|
||||
assert_throws_nothing(ws.create_named_range("XFE1048576", "A2"));
|
||||
assert_throws_nothing(ws.create_named_range("XFD1048577", "A2"));
|
||||
}
|
||||
void test_named_range_named_cell_reference()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
assert_throws(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter);
|
||||
assert_throws(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter);
|
||||
assert_throws_nothing(ws.create_named_range("XFE1048576", "A2"));
|
||||
assert_throws_nothing(ws.create_named_range("XFD1048577", "A2"));
|
||||
}
|
||||
|
||||
void test_iteration_skip_empty()
|
||||
{
|
Loading…
Reference in New Issue