diff --git a/benchmarks/styles.cpp b/benchmarks/styles.cpp index 237bae84..6955c1ef 100644 --- a/benchmarks/styles.cpp +++ b/benchmarks/styles.cpp @@ -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(max - 1)); return dis(gen); } diff --git a/benchmarks/writer.cpp b/benchmarks/writer.cpp index ce18ca93..40655449 100644 --- a/benchmarks/writer.cpp +++ b/benchmarks/writer.cpp @@ -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 fn, int cols, int rows) +void timer(std::function fn, int cols, int rows) { const auto repeat = std::size_t(3); auto time = std::numeric_limits::max(); @@ -54,8 +54,6 @@ int timer(std::function fn, int cols, int rows) } std::cout << time / 1000.0 << std::endl; - - return time; } int main() diff --git a/samples/img2xlsx.cpp b/samples/img2xlsx.cpp index fcc01042..493f7722 100644 --- a/samples/img2xlsx.cpp +++ b/samples/img2xlsx.cpp @@ -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(image[0].size()), + static_cast(image.size()))); // Track the previously created conditonal formats so they are only created once std::unordered_set defined_colors; diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 2ccc82e0..8a5250b2 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -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}) diff --git a/source/cell/rich_text.cpp b/source/cell/rich_text.cpp index f2ef8689..44bb5583 100644 --- a/source/cell/rich_text.cpp +++ b/source/cell/rich_text.cpp @@ -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 diff --git a/source/detail/crypto/sha.cpp b/source/detail/crypto/sha.cpp index b38ba3bb..935c90ce 100755 --- a/source/detail/crypto/sha.cpp +++ b/source/detail/crypto/sha.cpp @@ -274,11 +274,12 @@ std::string SHA1::final_() uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8; /* Padding */ - buffer += static_cast(0x80); - size_t orig_size = buffer.size(); + buffer.append(1, static_cast(0x80u)); + auto orig_size = buffer.size(); + while (buffer.size() < BLOCK_BYTES) { - buffer += static_cast(0x00); + buffer.append(1, '\0'); } uint32_t block[BLOCK_INTS]; diff --git a/source/detail/crypto/xlsx_crypto.cpp b/source/detail/crypto/xlsx_crypto.cpp index 09745f04..573dab4f 100644 --- a/source/detail/crypto/xlsx_crypto.cpp +++ b/source/detail/crypto/xlsx_crypto.cpp @@ -301,7 +301,10 @@ std::vector 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(password.data()), + reinterpret_cast(password.data() + password.size())); return result; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0a46bcd6..d460521d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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} $) +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}) diff --git a/tests/cell/test_cell.hpp b/tests/cell/cell_test_suite.hpp similarity index 77% rename from tests/cell/test_cell.hpp rename to tests/cell/cell_test_suite.hpp index ccd915db..986d9cc2 100644 --- a/tests/cell/test_cell.hpp +++ b/tests/cell/cell_test_suite.hpp @@ -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 #include @@ -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() == 4.2L); + cell.value("4.2", true); + assert(cell.value() == 4.2L); - cell.value("-42.000", true); - assert(cell.value() == -42); + cell.value("-42.000", true); + assert(cell.value() == -42); - cell.value("0", true); - assert(cell.value() == 0); + cell.value("0", true); + assert(cell.value() == 0); - cell.value("0.9999", true); - assert(cell.value() == 0.9999L); + cell.value("0.9999", true); + assert(cell.value() == 0.9999L); - cell.value("99E-02", true); - assert(cell.value() == 0.99L); + cell.value("99E-02", true); + assert(cell.value() == 0.99L); - cell.value("4", true); - assert(cell.value() == 4); + cell.value("4", true); + assert(cell.value() == 4); - cell.value("-1E3", true); - assert(cell.value() == -1000); + cell.value("-1E3", true); + assert(cell.value() == -1000); - cell.value("2e+2", true); - assert(cell.value() == 200); + cell.value("2e+2", true); + assert(cell.value() == 200); - cell.value("3.1%", true); - assert(cell.value() == 0.031L); + cell.value("3.1%", true); + assert(cell.value() == 0.031L); - cell.value("03:40:16", true); + cell.value("03:40:16", true); assert(cell.value() == xlnt::time(3, 40, 16)); - cell.value("03:", true); + cell.value("03:", true); assert_equals(cell.value(), "03:"); - cell.value("03:40", true); + cell.value("03:40", true); assert(cell.value() == xlnt::time(3, 40)); - cell.value("30:33.865633336", true); + cell.value("30:33.865633336", true); assert(cell.value() == 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() == "="); 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() == 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() == 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() == "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() == 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() == 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); diff --git a/tests/cell/test_index_types.hpp b/tests/cell/index_types_test_suite.hpp similarity index 51% rename from tests/cell/test_index_types.hpp rename to tests/cell/index_types_test_suite.hpp index e38105f8..99701be1 100644 --- a/tests/cell/test_index_types.hpp +++ b/tests/cell/index_types_test_suite.hpp @@ -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 @@ -5,16 +28,16 @@ #include #include -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); diff --git a/tests/cell/test_rich_text.hpp b/tests/cell/rich_text_test_suite.hpp similarity index 65% rename from tests/cell/test_rich_text.hpp rename to tests/cell/rich_text_test_suite.hpp index 6c2a223c..6c8bf035 100644 --- a/tests/cell/test_rich_text.hpp +++ b/tests/cell/rich_text_test_suite.hpp @@ -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 @@ -7,12 +30,12 @@ #include #include -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() diff --git a/tests/helpers/test_suite.hpp b/tests/helpers/test_suite.hpp index 44024003..7de32f6e 100644 --- a/tests/helpers/test_suite.hpp +++ b/tests/helpers/test_suite.hpp @@ -7,6 +7,8 @@ #include #include +#include + 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 t, const std::string &function) { - tests.push_back(std::make_pair(t, function)); + tests.push_back(std::make_pair(t, function)); } private: diff --git a/tests/runner.cpp b/tests/runner.cpp index 17ff08dd..8f225f7b 100644 --- a/tests/runner.cpp +++ b/tests/runner.cpp @@ -1,31 +1,27 @@ -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include test_status overall_status; @@ -53,11 +49,34 @@ void print_summary() int main() { + // cell run_tests(); - run_tests(); - run_tests(); + run_tests(); + run_tests(); + + // styles + run_tests(); + run_tests(); + run_tests(); + run_tests(); + + // utils + run_tests(); + run_tests(); + run_tests(); + run_tests(); + + // workbook + run_tests(); + run_tests(); + run_tests(); + + // worksheet + run_tests(); + run_tests(); + run_tests(); print_summary(); - return overall_status.tests_failed; + return static_cast(overall_status.tests_failed); } diff --git a/tests/styles/alignment_test_suite.hpp b/tests/styles/alignment_test_suite.hpp new file mode 100644 index 00000000..711f69c3 --- /dev/null +++ b/tests/styles/alignment_test_suite.hpp @@ -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 +#include + +#include + +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()); + } +}; diff --git a/tests/styles/test_color.hpp b/tests/styles/color_test_suite.hpp similarity index 51% rename from tests/styles/test_color.hpp rename to tests/styles/color_test_suite.hpp index df9b3609..1dc55f01 100644 --- a/tests/styles/test_color.hpp +++ b/tests/styles/color_test_suite.hpp @@ -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 @@ -5,9 +28,15 @@ #include -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> known_colors diff --git a/tests/styles/test_fill.hpp b/tests/styles/fill_test_suite.hpp similarity index 66% rename from tests/styles/test_fill.hpp rename to tests/styles/fill_test_suite.hpp index f881ff49..3f22cafb 100644 --- a/tests/styles/test_fill.hpp +++ b/tests/styles/fill_test_suite.hpp @@ -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 @@ -5,9 +28,16 @@ #include -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; diff --git a/tests/styles/test_number_format.hpp b/tests/styles/number_format_test_suite.hpp similarity index 85% rename from tests/styles/test_number_format.hpp rename to tests/styles/number_format_test_suite.hpp index 9ee278f7..7c5c5cde 100644 --- a/tests/styles/test_number_format.hpp +++ b/tests/styles/number_format_test_suite.hpp @@ -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 #include #include -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"); diff --git a/tests/styles/test_alignment.hpp b/tests/styles/test_alignment.hpp deleted file mode 100644 index 7813fa51..00000000 --- a/tests/styles/test_alignment.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include - -#include - -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()); - } -}; diff --git a/tests/utils/test_datetime.hpp b/tests/utils/datetime_test_suite.hpp similarity index 68% rename from tests/utils/test_datetime.hpp rename to tests/utils/datetime_test_suite.hpp index 2a125c40..f8916355 100644 --- a/tests/utils/test_datetime.hpp +++ b/tests/utils/datetime_test_suite.hpp @@ -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 @@ -5,7 +28,7 @@ #include -class test_datetime : public test_suite +class datetime_test_suite : public test_suite { public: void test_from_string() diff --git a/tests/utils/helper_test_suite.hpp b/tests/utils/helper_test_suite.hpp new file mode 100644 index 00000000..c96f6678 --- /dev/null +++ b/tests/utils/helper_test_suite.hpp @@ -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 +#include + +#include + +class helper_test_suite : public test_suite +{ +public: + void test_compare() + { + assert(!xml_helper::compare_xml_exact("", "", true)); + assert(!xml_helper::compare_xml_exact("", "", true)); + assert(!xml_helper::compare_xml_exact("", "", true)); + assert(!xml_helper::compare_xml_exact("", "", true)); + assert(!xml_helper::compare_xml_exact("", "", true)); + assert(!xml_helper::compare_xml_exact("text", "txet", true)); + assert(!xml_helper::compare_xml_exact("text", "txet", true)); + assert(xml_helper::compare_xml_exact("", " ", true)); + assert(xml_helper::compare_xml_exact("", "", true)); + assert(xml_helper::compare_xml_exact("text", "text", true)); + } +}; diff --git a/tests/utils/path_test_suite.hpp b/tests/utils/path_test_suite.hpp new file mode 100644 index 00000000..71d564a3 --- /dev/null +++ b/tests/utils/path_test_suite.hpp @@ -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 +#include + +#include +#include +#include + +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()); + } +}; diff --git a/tests/utils/test_path.hpp b/tests/utils/test_path.hpp deleted file mode 100644 index b358d155..00000000 --- a/tests/utils/test_path.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include - -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()); - } -}; diff --git a/tests/utils/test_tests.hpp b/tests/utils/test_tests.hpp deleted file mode 100644 index a4622652..00000000 --- a/tests/utils/test_tests.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_tests : public test_suite -{ -public: - void test_compare() - { - assert(!xml_helper::compare_xml_exact("", "", true)); - assert(!xml_helper::compare_xml_exact("", "", true)); - assert(!xml_helper::compare_xml_exact("", "", true)); - assert(!xml_helper::compare_xml_exact("", "", true)); - assert(!xml_helper::compare_xml_exact("", "", true)); - assert(!xml_helper::compare_xml_exact("text", "txet", true)); - assert(!xml_helper::compare_xml_exact("text", "txet", true)); - assert(xml_helper::compare_xml_exact("", " ", true)); - assert(xml_helper::compare_xml_exact("", "", true)); - assert(xml_helper::compare_xml_exact("text", "text", true)); - } -}; diff --git a/tests/utils/test_units.hpp b/tests/utils/test_units.hpp deleted file mode 100644 index 4c5a6eb1..00000000 --- a/tests/utils/test_units.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_units : public test_suite -{ -}; diff --git a/tests/utils/test_timedelta.hpp b/tests/utils/timedelta_test_suite.hpp similarity index 54% rename from tests/utils/test_timedelta.hpp rename to tests/utils/timedelta_test_suite.hpp index a18ab9b0..c5bc9e0f 100644 --- a/tests/utils/test_timedelta.hpp +++ b/tests/utils/timedelta_test_suite.hpp @@ -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 #include -class test_timedelta : public test_suite +class timedelta_test_suite : public test_suite { public: void test_from_number() diff --git a/tests/utils/units_test_suite.hpp b/tests/utils/units_test_suite.hpp new file mode 100644 index 00000000..b81f45e7 --- /dev/null +++ b/tests/utils/units_test_suite.hpp @@ -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 +#include + +#include + +class units_test_suite : public test_suite +{ +}; diff --git a/tests/workbook/test_named_range.hpp b/tests/workbook/named_range_test_suite.hpp similarity index 83% rename from tests/workbook/test_named_range.hpp rename to tests/workbook/named_range_test_suite.hpp index 12f10e64..c8e3f68d 100644 --- a/tests/workbook/test_named_range.hpp +++ b/tests/workbook/named_range_test_suite.hpp @@ -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 @@ -5,7 +28,7 @@ #include -class test_named_range : public test_suite +class named_range_test_suite : public test_suite { public: void test_split() diff --git a/tests/workbook/protection_test_suite.hpp b/tests/workbook/protection_test_suite.hpp new file mode 100644 index 00000000..e997b3dd --- /dev/null +++ b/tests/workbook/protection_test_suite.hpp @@ -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 +#include + +#include + +class test_password_hash : public test_suite +{ +}; diff --git a/tests/workbook/round_trip_test_suite.hpp b/tests/workbook/round_trip_test_suite.hpp new file mode 100644 index 00000000..a5cbc1c3 --- /dev/null +++ b/tests/workbook/round_trip_test_suite.hpp @@ -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 +#include +#include + +#include +#include +#include +#include +#include + +class test_round_trip : public test_suite +{ +public: + +}; diff --git a/tests/workbook/serialization_test_suite.hpp b/tests/workbook/serialization_test_suite.hpp new file mode 100644 index 00000000..47958539 --- /dev/null +++ b/tests/workbook/serialization_test_suite.hpp @@ -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 + +#include +#include +#include +#include +#include +#include +#include + +class serialization_test_suite : public test_suite +{ +public: + bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file) + { + std::vector wb_data; + wb.save(wb_data); + + std::ifstream file_stream(file.string(), std::ios::binary); + std::vector 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::max()); + + ws.cell("A5").value("number (unsigned int)"); + ws.cell("B5").value(std::numeric_limits::max()); + + ws.cell("A6").value("number (long long int)"); + ws.cell("B6").value(std::numeric_limits::max()); + + ws.cell("A6").value("number (unsigned long long int)"); + ws.cell("B6").value(std::numeric_limits::max()); + + ws.cell("A13").value("number (float)"); + ws.cell("B13").value(std::numeric_limits::max()); + + ws.cell("A14").value("number (double)"); + ws.cell("B14").value(std::numeric_limits::max()); + + ws.cell("A15").value("number (long double)"); + ws.cell("B15").value(std::numeric_limits::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 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 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(), 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(), 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(), "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(), "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(), "hyperlink1"); + assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/"); + assert(ws1.cell("A5").has_hyperlink()); + assert_equals(ws1.cell("A5").value(), "https://google.com/"); + assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/"); + //assert(ws1.cell("A6").has_hyperlink()); + assert_equals(ws1.cell("A6").value(), "Sheet1!A1"); + //assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1"); + assert(ws1.cell("A7").has_hyperlink()); + assert_equals(ws1.cell("A7").value(), "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(), "ab"); + assert(ws1.cell("C1").has_formula()); + assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)"); + assert_equals(ws1.cell("C2").value(), "a"); + assert_equals(ws1.cell("C3").value(), "b"); + + auto ws2 = wb.sheet_by_index(1); + assert_equals(ws2.cell("C1").value(), 6); + assert(ws2.cell("C1").has_formula()); + assert_equals(ws2.cell("C1").formula(), "C2*C3"); + assert_equals(ws2.cell("C2").value(), 2); + assert_equals(ws2.cell("C3").value(), 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(), "header"); + assert_equals(ws.cell("A2").value(), "and"); + assert_equals(ws.cell("A3").value(), "footer"); + assert_equals(ws.cell("A4").value(), "page1"); + assert_equals(ws.cell("A43").value(), "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(), "me!"); + } + + /// + /// 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. + /// + bool round_trip_matches_rw(const xlnt::path &source) + { + xlnt::workbook source_workbook; + source_workbook.load(source); + + std::vector 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 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 + { + "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 + { + "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)); + } + } +}; diff --git a/tests/workbook/test_consume_xlsx.hpp b/tests/workbook/test_consume_xlsx.hpp index 6ad265ea..f1ad8cfb 100644 --- a/tests/workbook/test_consume_xlsx.hpp +++ b/tests/workbook/test_consume_xlsx.hpp @@ -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 #include @@ -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(), 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(), 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(), "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(), "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(), "hyperlink1"); - assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/"); - assert(ws1.cell("A5").has_hyperlink()); - assert_equals(ws1.cell("A5").value(), "https://google.com/"); - assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/"); - //assert(ws1.cell("A6").has_hyperlink()); - assert_equals(ws1.cell("A6").value(), "Sheet1!A1"); - //assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1"); - assert(ws1.cell("A7").has_hyperlink()); - assert_equals(ws1.cell("A7").value(), "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(), "ab"); - assert(ws1.cell("C1").has_formula()); - assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)"); - assert_equals(ws1.cell("C2").value(), "a"); - assert_equals(ws1.cell("C3").value(), "b"); - - auto ws2 = wb.sheet_by_index(1); - assert_equals(ws2.cell("C1").value(), 6); - assert(ws2.cell("C1").has_formula()); - assert_equals(ws2.cell("C1").formula(), "C2*C3"); - assert_equals(ws2.cell("C2").value(), 2); - assert_equals(ws2.cell("C3").value(), 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(), "header"); - assert_equals(ws.cell("A2").value(), "and"); - assert_equals(ws.cell("A3").value(), "footer"); - assert_equals(ws.cell("A4").value(), "page1"); - assert_equals(ws.cell("A43").value(), "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(), "me!"); - } }; diff --git a/tests/workbook/test_produce_xlsx.hpp b/tests/workbook/test_produce_xlsx.hpp deleted file mode 100644 index 955bd120..00000000 --- a/tests/workbook/test_produce_xlsx.hpp +++ /dev/null @@ -1,181 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -class test_produce_xlsx : public test_suite -{ -public: - bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file) - { - std::vector wb_data; - wb.save(wb_data); - - std::ifstream file_stream(file.string(), std::ios::binary); - std::vector 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::max()); - - ws.cell("A5").value("number (unsigned int)"); - ws.cell("B5").value(std::numeric_limits::max()); - - ws.cell("A6").value("number (long long int)"); - ws.cell("B6").value(std::numeric_limits::max()); - - ws.cell("A6").value("number (unsigned long long int)"); - ws.cell("B6").value(std::numeric_limits::max()); - - ws.cell("A13").value("number (float)"); - ws.cell("B13").value(std::numeric_limits::max()); - - ws.cell("A14").value("number (double)"); - ws.cell("B14").value(std::numeric_limits::max()); - - ws.cell("A15").value("number (long double)"); - ws.cell("B15").value(std::numeric_limits::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 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 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"); - } -}; diff --git a/tests/workbook/test_protection.hpp b/tests/workbook/test_protection.hpp deleted file mode 100644 index 8bbd68ff..00000000 --- a/tests/workbook/test_protection.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_password_hash : public test_suite -{ -}; diff --git a/tests/workbook/test_round_trip.hpp b/tests/workbook/test_round_trip.hpp deleted file mode 100644 index 03b34306..00000000 --- a/tests/workbook/test_round_trip.hpp +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - -class test_round_trip : public test_suite -{ -public: - /// - /// 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. - /// - bool round_trip_matches_rw(const xlnt::path &source) - { - xlnt::workbook source_workbook; - source_workbook.load(source); - - std::vector 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 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 - { - "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 - { - "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)); - } - } -}; diff --git a/tests/workbook/test_theme.hpp b/tests/workbook/test_theme.hpp deleted file mode 100644 index ca3d9898..00000000 --- a/tests/workbook/test_theme.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include - -class test_theme : public test_suite -{ -}; diff --git a/tests/workbook/test_vba.hpp b/tests/workbook/test_vba.hpp deleted file mode 100644 index a1c2b807..00000000 --- a/tests/workbook/test_vba.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_vba : public test_suite -{ -}; diff --git a/tests/workbook/theme_test_suite.hpp b/tests/workbook/theme_test_suite.hpp new file mode 100644 index 00000000..21031667 --- /dev/null +++ b/tests/workbook/theme_test_suite.hpp @@ -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 +#include + +#include +#include +#include + +class test_theme : public test_suite +{ +}; diff --git a/tests/workbook/vba_test_suite.hpp b/tests/workbook/vba_test_suite.hpp new file mode 100644 index 00000000..baa583ce --- /dev/null +++ b/tests/workbook/vba_test_suite.hpp @@ -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 +#include + +#include + +class test_vba : public test_suite +{ +}; diff --git a/tests/workbook/test_workbook.hpp b/tests/workbook/workbook_test_suite.hpp similarity index 86% rename from tests/workbook/test_workbook.hpp rename to tests/workbook/workbook_test_suite.hpp index b4a15d41..45e4bfe2 100644 --- a/tests/workbook/test_workbook.hpp +++ b/tests/workbook/workbook_test_suite.hpp @@ -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 @@ -7,11 +30,14 @@ #include #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; diff --git a/tests/worksheet/data_validation_test_suite.hpp b/tests/worksheet/data_validation_test_suite.hpp new file mode 100644 index 00000000..69eda93c --- /dev/null +++ b/tests/worksheet/data_validation_test_suite.hpp @@ -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 +#include + +#include + +class test_datavalidation : public test_suite +{ +public: +}; diff --git a/tests/worksheet/page_setup_test_suite.hpp b/tests/worksheet/page_setup_test_suite.hpp new file mode 100644 index 00000000..b27a9a13 --- /dev/null +++ b/tests/worksheet/page_setup_test_suite.hpp @@ -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 +#include + +#include + +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()); + } +}; diff --git a/tests/worksheet/range_test_suite.hpp b/tests/worksheet/range_test_suite.hpp new file mode 100644 index 00000000..0659d272 --- /dev/null +++ b/tests/worksheet/range_test_suite.hpp @@ -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 +#include + +#include +#include +#include + +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()); + } +}; diff --git a/tests/worksheet/test_datavalidation.hpp b/tests/worksheet/test_datavalidation.hpp deleted file mode 100644 index d9db076c..00000000 --- a/tests/worksheet/test_datavalidation.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_datavalidation : public test_suite -{ -public: -}; diff --git a/tests/worksheet/test_page_setup.hpp b/tests/worksheet/test_page_setup.hpp deleted file mode 100644 index babfd7b3..00000000 --- a/tests/worksheet/test_page_setup.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include - -#include - -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()); - } -}; diff --git a/tests/worksheet/test_range.hpp b/tests/worksheet/test_range.hpp deleted file mode 100644 index f1e89f1b..00000000 --- a/tests/worksheet/test_range.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include - -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()); - } -}; diff --git a/tests/worksheet/test_worksheet.hpp b/tests/worksheet/worksheet_test_suite.hpp similarity index 85% rename from tests/worksheet/test_worksheet.hpp rename to tests/worksheet/worksheet_test_suite.hpp index 75caa9fd..dc0359f6 100644 --- a/tests/worksheet/test_worksheet.hpp +++ b/tests/worksheet/worksheet_test_suite.hpp @@ -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 @@ -7,69 +30,69 @@ #include #include -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(), "first"); assert_equals(first_row[0].reference(), "A1"); assert_equals(last_row[2].value(), "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(), "first"); assert_equals(cols[2][8].value(), "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() == 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() {