start rewiring tests

This commit is contained in:
Thomas Fussell 2017-04-13 19:01:30 -04:00
parent 62f659b901
commit b85680c5ed
46 changed files with 1735 additions and 1031 deletions

View File

@ -14,7 +14,7 @@ std::size_t random_index(std::size_t max)
static std::random_device rd;
static std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, max - 1);
std::uniform_int_distribution<> dis(0, static_cast<int>(max - 1));
return dis(gen);
}

View File

@ -39,7 +39,7 @@ void writer(int cols, int rows)
// Create a timeit call to a function and pass in keyword arguments.
// The function is called twice, once using the standard workbook, then with the optimised one.
// Time from the best of three is taken.
int timer(std::function<void(int, int)> fn, int cols, int rows)
void timer(std::function<void(int, int)> fn, int cols, int rows)
{
const auto repeat = std::size_t(3);
auto time = std::numeric_limits<std::size_t>::max();
@ -54,8 +54,6 @@ int timer(std::function<void(int, int)> fn, int cols, int rows)
}
std::cout << time / 1000.0 << std::endl;
return time;
}
int main()

View File

@ -74,7 +74,9 @@ xlnt::workbook build_workbook_cf(const pixmap &image)
// The reference to the cell which is being operated upon
auto current_cell = xlnt::cell_reference("A1");
// The range of cells which will be modified. This is required for conditional formats
auto range = ws.range(xlnt::range_reference(1, 1, image[0].size(), image.size()));
auto range = ws.range(xlnt::range_reference(1, 1,
static_cast<xlnt::column_t::index_t>(image[0].size()),
static_cast<xlnt::row_t>(image.size())));
// Track the previously created conditonal formats so they are only created once
std::unordered_set<std::string> defined_colors;

View File

@ -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})

View File

@ -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

View File

@ -274,11 +274,12 @@ std::string SHA1::final_()
uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8;
/* Padding */
buffer += static_cast<char>(0x80);
size_t orig_size = buffer.size();
buffer.append(1, static_cast<char>(0x80u));
auto orig_size = buffer.size();
while (buffer.size() < BLOCK_BYTES)
{
buffer += static_cast<char>(0x00);
buffer.append(1, '\0');
}
uint32_t block[BLOCK_INTS];

View File

@ -301,7 +301,10 @@ std::vector<std::uint8_t> decrypt_xlsx_standard(
encryption_info generate_encryption_info(const std::u16string &password)
{
encryption_info result;
result.agile.key_data.salt_value.assign(password.begin(), password.end());
result.agile.key_data.salt_value.assign(
reinterpret_cast<const std::uint8_t *>(password.data()),
reinterpret_cast<const std::uint8_t *>(password.data() + password.size()));
return result;
}

View File

@ -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,7 +33,7 @@ if(COVERAGE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
add_executable(xlnt.test ${RUNNER} ${HELPERS} $<TARGET_OBJECTS:libstudxml>)
add_executable(xlnt.test ${RUNNER} ${TESTS} ${HELPERS})
target_link_libraries(xlnt.test PRIVATE xlnt)
target_include_directories(xlnt.test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
@ -43,7 +43,12 @@ target_include_directories(xlnt.test
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})

View File

@ -1,3 +1,28 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <sstream>
#include <helpers/test_suite.hpp>

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
@ -5,10 +28,10 @@
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_index_types : public test_suite
class index_types_test_suite : public test_suite
{
public:
test_index_types()
index_types_test_suite()
{
register_test(test_bad_string_empty);
register_test(test_bad_string_too_long);

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <ctime>
@ -7,10 +30,10 @@
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_rich_text : public test_suite
class rich_text_test_suite : public test_suite
{
public:
test_rich_text()
rich_text_test_suite()
{
register_test(test_operators);
}

View File

@ -7,6 +7,8 @@
#include <utility>
#include <vector>
#include <helpers/assertions.hpp>
struct test_status
{
std::size_t tests_run = 0;
@ -20,7 +22,7 @@ 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
{

View File

@ -1,31 +1,27 @@
#include <cell/test_cell.hpp>
#include <cell/test_index_types.hpp>
#include <cell/test_rich_text.hpp>
#include <cell/cell_test_suite.hpp>
#include <cell/index_types_test_suite.hpp>
#include <cell/rich_text_test_suite.hpp>
#include <styles/test_alignment.hpp>
#include <styles/test_color.hpp>
#include <styles/test_fill.hpp>
#include <styles/test_number_format.hpp>
#include <styles/alignment_test_suite.hpp>
#include <styles/color_test_suite.hpp>
#include <styles/fill_test_suite.hpp>
#include <styles/number_format_test_suite.hpp>
#include <utils/test_datetime.hpp>
#include <utils/test_path.hpp>
#include <utils/test_tests.hpp>
#include <utils/test_timedelta.hpp>
#include <utils/test_units.hpp>
#include <utils/datetime_test_suite.hpp>
#include <utils/path_test_suite.hpp>
#include <utils/helper_test_suite.hpp>
#include <utils/timedelta_test_suite.hpp>
#include <workbook/test_consume_xlsx.hpp>
#include <workbook/test_named_range.hpp>
#include <workbook/test_produce_xlsx.hpp>
#include <workbook/test_protection.hpp>
#include <workbook/test_round_trip.hpp>
#include <workbook/test_theme.hpp>
#include <workbook/test_vba.hpp>
#include <workbook/test_workbook.hpp>
#include <workbook/named_range_test_suite.hpp>
#include <workbook/protection_test_suite.hpp>
#include <workbook/serialization_test_suite.hpp>
#include <workbook/theme_test_suite.hpp>
#include <workbook/vba_test_suite.hpp>
#include <workbook/workbook_test_suite.hpp>
#include <worksheet/test_datavalidation.hpp>
#include <worksheet/test_page_setup.hpp>
#include <worksheet/test_range.hpp>
#include <worksheet/test_worksheet.hpp>
#include <worksheet/page_setup_test_suite.hpp>
#include <worksheet/range_test_suite.hpp>
#include <worksheet/worksheet_test_suite.hpp>
test_status overall_status;
@ -53,11 +49,34 @@ void print_summary()
int main()
{
// cell
run_tests<cell_test_suite>();
run_tests<test_index_types>();
run_tests<test_worksheet>();
run_tests<index_types_test_suite>();
run_tests<rich_text_test_suite>();
// styles
run_tests<alignment_test_suite>();
run_tests<color_test_suite>();
run_tests<fill_test_suite>();
run_tests<number_format_test_suite>();
// utils
run_tests<datetime_test_suite>();
run_tests<path_test_suite>();
run_tests<helper_test_suite>();
run_tests<timedelta_test_suite>();
// workbook
run_tests<named_range_test_suite>();
run_tests<serialization_test_suite>();
run_tests<workbook_test_suite>();
// worksheet
run_tests<page_setup_test_suite>();
run_tests<range_test_suite>();
run_tests<worksheet_test_suite>();
print_summary();
return overall_status.tests_failed;
return static_cast<int>(overall_status.tests_failed);
}

View File

@ -0,0 +1,48 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class alignment_test_suite : public test_suite
{
public:
alignment_test_suite()
{
register_test(test_all);
}
void test_all()
{
xlnt::alignment alignment;
assert(!alignment.horizontal().is_set());
assert(!alignment.vertical().is_set());
assert(!alignment.shrink());
assert(!alignment.wrap());
}
};

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
@ -5,9 +28,15 @@
#include <xlnt/xlnt.hpp>
class test_color : public test_suite
class color_test_suite : public test_suite
{
public:
color_test_suite()
{
register_test(test_known_colors);
register_test(test_non_rgb_colors);
}
void test_known_colors()
{
const std::vector<std::pair<xlnt::color, std::string>> known_colors

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
@ -5,9 +28,16 @@
#include <xlnt/xlnt.hpp>
class test_fill : public test_suite
class fill_test_suite : public test_suite
{
public:
fill_test_suite()
{
register_test(test_properties);
register_test(test_comparison);
register_test(test_two_fills);
}
void test_properties()
{
xlnt::fill fill;

View File

@ -1,13 +1,119 @@
#pragma once
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_number_format : public test_suite
class number_format_test_suite : public test_suite
{
public:
number_format_test_suite()
{
register_test(test_basic);
register_test(test_simple_format);
register_test(test_simple_date);
register_test(test_short_month);
register_test(test_month_abbreviation);
register_test(test_month_name);
register_test(test_basic);
register_test(test_simple_format);
register_test(test_simple_date);
register_test(test_short_day);
register_test(test_long_day);
register_test(test_long_year);
register_test(test_day_name);
register_test(test_day_abbreviation);
register_test(test_month_letter);
register_test(test_time_24_hour);
register_test(test_elapsed_minutes);
register_test(test_second_fractional_leading_zero);
register_test(test_second_fractional);
register_test(test_elapsed_seconds);
register_test(test_time_12_hour_am);
register_test(test_time_12_hour_pm);
register_test(test_long_hour_12_hour);
register_test(test_long_hour_12_hour_ap);
register_test(test_long_hour_24_hour);
register_test(test_short_minute);
register_test(test_long_minute);
register_test(test_short_second);
register_test(test_long_second);
register_test(test_trailing_space);
register_test(test_text_section_string);
register_test(test_text_section_no_string);
register_test(test_text_section_no_text);
register_test(test_conditional_format);
register_test(test_space);
register_test(test_fill);
register_test(test_placeholders_zero);
register_test(test_placeholders_space);
register_test(test_scientific);
register_test(test_locale_currency);
register_test(test_bad_country);
register_test(test_duplicate_bracket_sections);
register_test(test_escaped_quote_string);
register_test(test_thousands_scale);
register_test(test_colors);
register_test(test_bad_format);
register_test(test_builtin_format_0);
register_test(test_builtin_format_1);
register_test(test_builtin_format_2);
register_test(test_builtin_format_3);
register_test(test_builtin_format_4);
register_test(test_builtin_format_9);
register_test(test_builtin_format_10);
register_test(test_builtin_format_11);
register_test(test_builtin_format_12);
register_test(test_builtin_format_13);
register_test(test_builtin_format_14);
register_test(test_builtin_format_15);
register_test(test_builtin_format_16);
register_test(test_builtin_format_17);
register_test(test_builtin_format_18);
register_test(test_builtin_format_19);
register_test(test_builtin_format_20);
register_test(test_builtin_format_21);
register_test(test_builtin_format_22);
register_test(test_builtin_format_37);
register_test(test_builtin_format_38);
register_test(test_builtin_format_39);
register_test(test_builtin_format_40);
register_test(test_builtin_format_45);
register_test(test_builtin_format_46);
register_test(test_builtin_format_47);
register_test(test_builtin_format_48);
register_test(test_builtin_format_49);
register_test(test_builtin_format_date_yyyymmdd);
register_test(test_builtin_format_date_dmyslash);
register_test(test_builtin_format_date_dmyminus);
register_test(test_builtin_format_date_dmminus);
register_test(test_builtin_format_date_myminus);
}
void test_basic()
{
xlnt::number_format no_id("#\\x\\y\\z");

View File

@ -1,20 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_alignment : public test_suite
{
public:
void test_all()
{
xlnt::alignment alignment;
assert(!alignment.horizontal().is_set());
assert(!alignment.vertical().is_set());
assert(!alignment.shrink());
assert(!alignment.wrap());
}
};

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
@ -5,7 +28,7 @@
#include <xlnt/xlnt.hpp>
class test_datetime : public test_suite
class datetime_test_suite : public test_suite
{
public:
void test_from_string()

View File

@ -0,0 +1,47 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <helpers/xml_helper.hpp>
class helper_test_suite : public test_suite
{
public:
void test_compare()
{
assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
assert(!xml_helper::compare_xml_exact("<a c=\"4\"/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a>txet</a>", true));
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a><b>txet</b></a>", true));
assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
assert(xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"3\"></a>", true));
assert(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true));
}
};

View File

@ -0,0 +1,49 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/temporary_file.hpp>
#include <xlnt/xlnt.hpp>
class path_test_suite : public test_suite
{
public:
void test_exists()
{
temporary_file temp;
if (temp.get_path().exists())
{
path_helper::delete_file(temp.get_path());
}
assert(!temp.get_path().exists());
std::ofstream stream(temp.get_path().string());
assert(temp.get_path().exists());
}
};

View File

@ -1,26 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/temporary_file.hpp>
#include <xlnt/xlnt.hpp>
class test_path : public test_suite
{
public:
void test_exists()
{
temporary_file temp;
if (temp.get_path().exists())
{
path_helper::delete_file(temp.get_path());
}
assert(!temp.get_path().exists());
std::ofstream stream(temp.get_path().string());
assert(temp.get_path().exists());
}
};

View File

@ -1,24 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <helpers/xml_helper.hpp>
class test_tests : public test_suite
{
public:
void test_compare()
{
assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
assert(!xml_helper::compare_xml_exact("<a c=\"4\"/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"4\"/>", true));
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a>txet</a>", true));
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a><b>txet</b></a>", true));
assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
assert(xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"3\"></a>", true));
assert(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true));
}
};

View File

@ -1,10 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_units : public test_suite
{
};

View File

@ -1,9 +1,32 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
class test_timedelta : public test_suite
class timedelta_test_suite : public test_suite
{
public:
void test_from_number()

View File

@ -0,0 +1,33 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class units_test_suite : public test_suite
{
};

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
@ -5,7 +28,7 @@
#include <xlnt/workbook/named_range.hpp>
class test_named_range : public test_suite
class named_range_test_suite : public test_suite
{
public:
void test_split()

View File

@ -0,0 +1,33 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_password_hash : public test_suite
{
};

View File

@ -0,0 +1,40 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <fstream>
#include <iostream>
#include <helpers/test_suite.hpp>
#include <detail/vector_streambuf.hpp>
#include <detail/crypto/xlsx_crypto.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/xml_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_round_trip : public test_suite
{
public:
};

View File

@ -0,0 +1,440 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <detail/vector_streambuf.hpp>
#include <detail/crypto/xlsx_crypto.hpp>
#include <helpers/temporary_file.hpp>
#include <helpers/test_suite.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/xml_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
class serialization_test_suite : public test_suite
{
public:
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
{
std::vector<std::uint8_t> wb_data;
wb.save(wb_data);
std::ifstream file_stream(file.string(), std::ios::binary);
std::vector<std::uint8_t> file_data;
{
xlnt::detail::vector_ostreambuf file_data_buffer(file_data);
std::ostream file_data_stream(&file_data_buffer);
file_data_stream << file_stream.rdbuf();
}
return xml_helper::xlsx_archives_match(wb_data, file_data);
}
void test_produce_empty()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("3_default.xlsx");
assert(workbook_matches_file(wb, path));
}
void test_produce_simple_excel()
{
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto bold_font = xlnt::font().bold(true);
ws.cell("A1").value("Type");
ws.cell("A1").font(bold_font);
ws.cell("B1").value("Value");
ws.cell("B1").font(bold_font);
ws.cell("A2").value("null");
ws.cell("B2").value(nullptr);
ws.cell("A3").value("bool (true)");
ws.cell("B3").value(true);
ws.cell("A4").value("bool (false)");
ws.cell("B4").value(false);
ws.cell("A5").value("number (int)");
ws.cell("B5").value(std::numeric_limits<int>::max());
ws.cell("A5").value("number (unsigned int)");
ws.cell("B5").value(std::numeric_limits<unsigned int>::max());
ws.cell("A6").value("number (long long int)");
ws.cell("B6").value(std::numeric_limits<long long int>::max());
ws.cell("A6").value("number (unsigned long long int)");
ws.cell("B6").value(std::numeric_limits<unsigned long long int>::max());
ws.cell("A13").value("number (float)");
ws.cell("B13").value(std::numeric_limits<float>::max());
ws.cell("A14").value("number (double)");
ws.cell("B14").value(std::numeric_limits<double>::max());
ws.cell("A15").value("number (long double)");
ws.cell("B15").value(std::numeric_limits<long double>::max());
ws.cell("A16").value("text (char *)");
ws.cell("B16").value("string");
ws.cell("A17").value("text (std::string)");
ws.cell("B17").value(std::string("string"));
ws.cell("A18").value("date");
ws.cell("B18").value(xlnt::date(2016, 2, 3));
ws.cell("A19").value("time");
ws.cell("B19").value(xlnt::time(1, 2, 3, 4));
ws.cell("A20").value("datetime");
ws.cell("B20").value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4));
ws.cell("A21").value("timedelta");
ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5));
ws.freeze_panes("B2");
std::vector<std::uint8_t> temp_buffer;
wb.save(temp_buffer);
assert(!temp_buffer.empty());
}
void test_save_after_sheet_deletion()
{
xlnt::workbook workbook;
assert_equals(workbook.sheet_titles().size(), 1);
auto sheet = workbook.create_sheet();
sheet.title("XXX1");
assert_equals(workbook.sheet_titles().size(), 2);
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
assert_equals(workbook.sheet_titles().size(), 1);
std::vector<std::uint8_t> temp_buffer;
assert_throws_nothing(workbook.save(temp_buffer));
assert(!temp_buffer.empty());
}
void test_write_comments_hyperlinks_formulae()
{
xlnt::workbook wb;
auto sheet1 = wb.active_sheet();
auto comment_font = xlnt::font().bold(true).size(10).color(xlnt::indexed_color(81)).name("Calibri");
sheet1.cell("A1").value("Sheet1!A1");
sheet1.cell("A1").comment("Sheet1 comment", comment_font, "Microsoft Office User");
sheet1.cell("A2").value("Sheet1!A2");
sheet1.cell("A2").comment("Sheet1 comment2", comment_font, "Microsoft Office User");
sheet1.cell("A4").hyperlink("https://microsoft.com", "hyperlink1");
sheet1.cell("A5").hyperlink("https://google.com");
sheet1.cell("A6").hyperlink(sheet1.cell("A1"));
sheet1.cell("A7").hyperlink("mailto:invalid@example.com?subject=important");
sheet1.cell("C1").formula("=CONCATENATE(C2,C3)");
sheet1.cell("C2").value("a");
sheet1.cell("C3").value("b");
auto sheet2 = wb.create_sheet();
sheet2.cell("A1").value("Sheet2!A1");
sheet2.cell("A2").comment("Sheet2 comment", comment_font, "Microsoft Office User");
sheet2.cell("A2").value("Sheet2!A2");
sheet2.cell("A2").comment("Sheet2 comment2", comment_font, "Microsoft Office User");
sheet2.cell("A4").hyperlink("https://apple.com", "hyperlink2");
sheet2.cell("C1").formula("=C2*C3");
sheet2.cell("C2").value(2);
sheet2.cell("C3").value(3);
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
assert(workbook_matches_file(wb, path));
}
void test_save_after_clear_all_formulae()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto ws1 = wb.sheet_by_index(0);
assert(ws1.cell("C1").has_formula());
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
ws1.cell("C1").clear_formula();
auto ws2 = wb.sheet_by_index(1);
assert(ws2.cell("C1").has_formula());
assert_equals(ws2.cell("C1").formula(), "C2*C3");
ws2.cell("C1").clear_formula();
wb.save("clear_formulae.xlsx");
}
void test_non_xlsx()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
assert_throws(wb.load(path), xlnt::invalid_file);
}
void test_decrypt_agile()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("5_encrypted_agile.xlsx");
assert_throws_nothing(wb.load(path, "secret"));
}
void test_decrypt_libre_office()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("6_encrypted_libre.xlsx");
assert_throws_nothing(wb.load(path, u8"пароль"));
}
void test_decrypt_standard()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("7_encrypted_standard.xlsx");
assert_throws_nothing(wb.load(path, "password"));
}
void test_decrypt_numbers()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("8_encrypted_numbers.xlsx");
assert_throws_nothing(wb.load(path, "secret"));
}
void test_read_unicode_filename()
{
#ifdef _MSC_VER
xlnt::workbook wb;
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
wb.load(path);
assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif
#ifndef __MINGW32__
xlnt::workbook wb2;
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
wb2.load(path2);
assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif
}
void test_comments()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto sheet1 = wb[0];
assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User");
auto sheet2 = wb[1];
assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User");
}
void test_read_hyperlink()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto ws1 = wb.sheet_by_index(0);
assert_equals(ws1.title(), "Sheet1");
assert(ws1.cell("A4").has_hyperlink());
assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1");
assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
assert(ws1.cell("A5").has_hyperlink());
assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/");
assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/");
//assert(ws1.cell("A6").has_hyperlink());
assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
//assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1");
assert(ws1.cell("A7").has_hyperlink());
assert_equals(ws1.cell("A7").value<std::string>(), "mailto:invalid@example.com?subject=important");
assert_equals(ws1.cell("A7").hyperlink(), "mailto:invalid@example.com?subject=important");
}
void test_read_formulae()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto ws1 = wb.sheet_by_index(0);
assert_equals(ws1.cell("C1").value<std::string>(), "ab");
assert(ws1.cell("C1").has_formula());
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
assert_equals(ws1.cell("C2").value<std::string>(), "a");
assert_equals(ws1.cell("C3").value<std::string>(), "b");
auto ws2 = wb.sheet_by_index(1);
assert_equals(ws2.cell("C1").value<int>(), 6);
assert(ws2.cell("C1").has_formula());
assert_equals(ws2.cell("C1").formula(), "C2*C3");
assert_equals(ws2.cell("C2").value<int>(), 2);
assert_equals(ws2.cell("C3").value<int>(), 3);
}
void test_read_headers_and_footers()
{
xlnt::workbook wb;
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
auto ws = wb.active_sheet();
assert_equals(ws.cell("A1").value<std::string>(), "header");
assert_equals(ws.cell("A2").value<std::string>(), "and");
assert_equals(ws.cell("A3").value<std::string>(), "footer");
assert_equals(ws.cell("A4").value<std::string>(), "page1");
assert_equals(ws.cell("A43").value<std::string>(), "page2");
assert(ws.has_header_footer());
assert(ws.header_footer().align_with_margins());
assert(ws.header_footer().scale_with_doc());
assert(!ws.header_footer().different_first());
assert(!ws.header_footer().different_odd_even());
assert(ws.header_footer().has_header(xlnt::header_footer::location::left));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::left).plain_text(), "left header");
assert(ws.header_footer().has_header(xlnt::header_footer::location::center));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::center).plain_text(), "center header");
assert(ws.header_footer().has_header(xlnt::header_footer::location::right));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::right).plain_text(), "right header");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::left));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::left).plain_text(), "left && footer");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::center));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::center).plain_text(), "center footer");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::right));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::right).plain_text(), "right footer");
}
void test_read_custom_properties()
{
xlnt::workbook wb;
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
assert(wb.has_custom_property("Client"));
assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
}
/// <summary>
/// Read file as an XLSX-formatted ZIP file in the filesystem to a workbook,
/// write the workbook back to memory, then ensure that the contents of the two files are equivalent.
/// </summary>
bool round_trip_matches_rw(const xlnt::path &source)
{
xlnt::workbook source_workbook;
source_workbook.load(source);
std::vector<std::uint8_t> destination;
source_workbook.save(destination);
source_workbook.save("temp.xlsx");
#ifdef _MSC_VER
std::ifstream source_stream(source.wstring(), std::ios::binary);
#else
std::ifstream source_stream(source.string(), std::ios::binary);
#endif
return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination);
}
bool round_trip_matches_rw(const xlnt::path &source, const std::string &password)
{
xlnt::workbook source_workbook;
source_workbook.load(source, password);
std::vector<std::uint8_t> destination;
source_workbook.save(destination);
#ifdef _MSC_VER
std::ifstream source_stream(source.wstring(), std::ios::binary);
#else
std::ifstream source_stream(source.string(), std::ios::binary);
#endif
const auto source_decrypted = xlnt::detail::decrypt_xlsx(
xlnt::detail::to_vector(source_stream), password);
return xml_helper::xlsx_archives_match(source_decrypted, destination);
}
void test_round_trip_rw()
{
const auto files = std::vector<std::string>
{
"2_minimal",
"3_default",
"4_every_style",
u8"9_unicode_Λ",
"10_comments_hyperlinks_formulae",
"11_print_settings",
"12_advanced_properties"
};
for (const auto file : files)
{
auto path = path_helper::data_directory(file + ".xlsx");
assert(round_trip_matches_rw(path));
}
}
void test_round_trip_rw_encrypted()
{
const auto files = std::vector<std::string>
{
"5_encrypted_agile",
"6_encrypted_libre",
"7_encrypted_standard",
"8_encrypted_numbers"
};
for (const auto file : files)
{
auto path = path_helper::data_directory(file + ".xlsx");
auto password = std::string(file == "7_encrypted_standard" ? "password"
: file == "6_encrypted_libre" ? u8"пароль"
: "secret");
assert(round_trip_matches_rw(path, password));
}
}
};

View File

@ -1,4 +1,27 @@
#pragma once
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <fstream>
#include <iostream>
@ -10,156 +33,5 @@
class test_consume_xlsx : public test_suite
{
public:
void test_non_xlsx()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
assert_throws(wb.load(path), xlnt::invalid_file);
}
void test_decrypt_agile()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("5_encrypted_agile.xlsx");
assert_throws_nothing(wb.load(path, "secret"));
}
void test_decrypt_libre_office()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("6_encrypted_libre.xlsx");
assert_throws_nothing(wb.load(path, u8"пароль"));
}
void test_decrypt_standard()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("7_encrypted_standard.xlsx");
assert_throws_nothing(wb.load(path, "password"));
}
void test_decrypt_numbers()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("8_encrypted_numbers.xlsx");
assert_throws_nothing(wb.load(path, "secret"));
}
void test_read_unicode_filename()
{
#ifdef _MSC_VER
xlnt::workbook wb;
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
wb.load(path);
assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif
#ifndef __MINGW32__
xlnt::workbook wb2;
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
wb2.load(path2);
assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif
}
void test_comments()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto sheet1 = wb[0];
assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User");
auto sheet2 = wb[1];
assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User");
}
void test_read_hyperlink()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto ws1 = wb.sheet_by_index(0);
assert_equals(ws1.title(), "Sheet1");
assert(ws1.cell("A4").has_hyperlink());
assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1");
assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
assert(ws1.cell("A5").has_hyperlink());
assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/");
assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/");
//assert(ws1.cell("A6").has_hyperlink());
assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
//assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1");
assert(ws1.cell("A7").has_hyperlink());
assert_equals(ws1.cell("A7").value<std::string>(), "mailto:invalid@example.com?subject=important");
assert_equals(ws1.cell("A7").hyperlink(), "mailto:invalid@example.com?subject=important");
}
void test_read_formulae()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto ws1 = wb.sheet_by_index(0);
assert_equals(ws1.cell("C1").value<std::string>(), "ab");
assert(ws1.cell("C1").has_formula());
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
assert_equals(ws1.cell("C2").value<std::string>(), "a");
assert_equals(ws1.cell("C3").value<std::string>(), "b");
auto ws2 = wb.sheet_by_index(1);
assert_equals(ws2.cell("C1").value<int>(), 6);
assert(ws2.cell("C1").has_formula());
assert_equals(ws2.cell("C1").formula(), "C2*C3");
assert_equals(ws2.cell("C2").value<int>(), 2);
assert_equals(ws2.cell("C3").value<int>(), 3);
}
void test_read_headers_and_footers()
{
xlnt::workbook wb;
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
auto ws = wb.active_sheet();
assert_equals(ws.cell("A1").value<std::string>(), "header");
assert_equals(ws.cell("A2").value<std::string>(), "and");
assert_equals(ws.cell("A3").value<std::string>(), "footer");
assert_equals(ws.cell("A4").value<std::string>(), "page1");
assert_equals(ws.cell("A43").value<std::string>(), "page2");
assert(ws.has_header_footer());
assert(ws.header_footer().align_with_margins());
assert(ws.header_footer().scale_with_doc());
assert(!ws.header_footer().different_first());
assert(!ws.header_footer().different_odd_even());
assert(ws.header_footer().has_header(xlnt::header_footer::location::left));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::left).plain_text(), "left header");
assert(ws.header_footer().has_header(xlnt::header_footer::location::center));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::center).plain_text(), "center header");
assert(ws.header_footer().has_header(xlnt::header_footer::location::right));
assert_equals(ws.header_footer().header(xlnt::header_footer::location::right).plain_text(), "right header");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::left));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::left).plain_text(), "left && footer");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::center));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::center).plain_text(), "center footer");
assert(ws.header_footer().has_footer(xlnt::header_footer::location::right));
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::right).plain_text(), "right footer");
}
void test_read_custom_properties()
{
xlnt::workbook wb;
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
assert(wb.has_custom_property("Client"));
assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
}
};

View File

@ -1,181 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <detail/vector_streambuf.hpp>
#include <helpers/temporary_file.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/xml_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_produce_xlsx : public test_suite
{
public:
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
{
std::vector<std::uint8_t> wb_data;
wb.save(wb_data);
std::ifstream file_stream(file.string(), std::ios::binary);
std::vector<std::uint8_t> file_data;
{
xlnt::detail::vector_ostreambuf file_data_buffer(file_data);
std::ostream file_data_stream(&file_data_buffer);
file_data_stream << file_stream.rdbuf();
}
return xml_helper::xlsx_archives_match(wb_data, file_data);
}
void test_produce_empty()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("3_default.xlsx");
assert(workbook_matches_file(wb, path));
}
void test_produce_simple_excel()
{
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto bold_font = xlnt::font().bold(true);
ws.cell("A1").value("Type");
ws.cell("A1").font(bold_font);
ws.cell("B1").value("Value");
ws.cell("B1").font(bold_font);
ws.cell("A2").value("null");
ws.cell("B2").value(nullptr);
ws.cell("A3").value("bool (true)");
ws.cell("B3").value(true);
ws.cell("A4").value("bool (false)");
ws.cell("B4").value(false);
ws.cell("A5").value("number (int)");
ws.cell("B5").value(std::numeric_limits<int>::max());
ws.cell("A5").value("number (unsigned int)");
ws.cell("B5").value(std::numeric_limits<unsigned int>::max());
ws.cell("A6").value("number (long long int)");
ws.cell("B6").value(std::numeric_limits<long long int>::max());
ws.cell("A6").value("number (unsigned long long int)");
ws.cell("B6").value(std::numeric_limits<unsigned long long int>::max());
ws.cell("A13").value("number (float)");
ws.cell("B13").value(std::numeric_limits<float>::max());
ws.cell("A14").value("number (double)");
ws.cell("B14").value(std::numeric_limits<double>::max());
ws.cell("A15").value("number (long double)");
ws.cell("B15").value(std::numeric_limits<long double>::max());
ws.cell("A16").value("text (char *)");
ws.cell("B16").value("string");
ws.cell("A17").value("text (std::string)");
ws.cell("B17").value(std::string("string"));
ws.cell("A18").value("date");
ws.cell("B18").value(xlnt::date(2016, 2, 3));
ws.cell("A19").value("time");
ws.cell("B19").value(xlnt::time(1, 2, 3, 4));
ws.cell("A20").value("datetime");
ws.cell("B20").value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4));
ws.cell("A21").value("timedelta");
ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5));
ws.freeze_panes("B2");
std::vector<std::uint8_t> temp_buffer;
wb.save(temp_buffer);
assert(!temp_buffer.empty());
}
void test_save_after_sheet_deletion()
{
xlnt::workbook workbook;
assert_equals(workbook.sheet_titles().size(), 1);
auto sheet = workbook.create_sheet();
sheet.title("XXX1");
assert_equals(workbook.sheet_titles().size(), 2);
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
assert_equals(workbook.sheet_titles().size(), 1);
std::vector<std::uint8_t> temp_buffer;
assert_throws_nothing(workbook.save(temp_buffer));
assert(!temp_buffer.empty());
}
void test_write_comments_hyperlinks_formulae()
{
xlnt::workbook wb;
auto sheet1 = wb.active_sheet();
auto comment_font = xlnt::font().bold(true).size(10).color(xlnt::indexed_color(81)).name("Calibri");
sheet1.cell("A1").value("Sheet1!A1");
sheet1.cell("A1").comment("Sheet1 comment", comment_font, "Microsoft Office User");
sheet1.cell("A2").value("Sheet1!A2");
sheet1.cell("A2").comment("Sheet1 comment2", comment_font, "Microsoft Office User");
sheet1.cell("A4").hyperlink("https://microsoft.com", "hyperlink1");
sheet1.cell("A5").hyperlink("https://google.com");
sheet1.cell("A6").hyperlink(sheet1.cell("A1"));
sheet1.cell("A7").hyperlink("mailto:invalid@example.com?subject=important");
sheet1.cell("C1").formula("=CONCATENATE(C2,C3)");
sheet1.cell("C2").value("a");
sheet1.cell("C3").value("b");
auto sheet2 = wb.create_sheet();
sheet2.cell("A1").value("Sheet2!A1");
sheet2.cell("A2").comment("Sheet2 comment", comment_font, "Microsoft Office User");
sheet2.cell("A2").value("Sheet2!A2");
sheet2.cell("A2").comment("Sheet2 comment2", comment_font, "Microsoft Office User");
sheet2.cell("A4").hyperlink("https://apple.com", "hyperlink2");
sheet2.cell("C1").formula("=C2*C3");
sheet2.cell("C2").value(2);
sheet2.cell("C3").value(3);
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
assert(workbook_matches_file(wb, path));
}
void test_save_after_clear_all_formulae()
{
xlnt::workbook wb;
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
wb.load(path);
auto ws1 = wb.sheet_by_index(0);
assert(ws1.cell("C1").has_formula());
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
ws1.cell("C1").clear_formula();
auto ws2 = wb.sheet_by_index(1);
assert(ws2.cell("C1").has_formula());
assert_equals(ws2.cell("C1").formula(), "C2*C3");
ws2.cell("C1").clear_formula();
wb.save("clear_formulae.xlsx");
}
};

View File

@ -1,10 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_password_hash : public test_suite
{
};

View File

@ -1,97 +0,0 @@
#pragma once
#include <fstream>
#include <iostream>
#include <helpers/test_suite.hpp>
#include <detail/vector_streambuf.hpp>
#include <detail/crypto/xlsx_crypto.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/xml_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_round_trip : public test_suite
{
public:
/// <summary>
/// Read file as an XLSX-formatted ZIP file in the filesystem to a workbook,
/// write the workbook back to memory, then ensure that the contents of the two files are equivalent.
/// </summary>
bool round_trip_matches_rw(const xlnt::path &source)
{
xlnt::workbook source_workbook;
source_workbook.load(source);
std::vector<std::uint8_t> destination;
source_workbook.save(destination);
source_workbook.save("temp.xlsx");
#ifdef _MSC_VER
std::ifstream source_stream(source.wstring(), std::ios::binary);
#else
std::ifstream source_stream(source.string(), std::ios::binary);
#endif
return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination);
}
bool round_trip_matches_rw(const xlnt::path &source, const std::string &password)
{
xlnt::workbook source_workbook;
source_workbook.load(source, password);
std::vector<std::uint8_t> destination;
source_workbook.save(destination);
#ifdef _MSC_VER
std::ifstream source_stream(source.wstring(), std::ios::binary);
#else
std::ifstream source_stream(source.string(), std::ios::binary);
#endif
const auto source_decrypted = xlnt::detail::decrypt_xlsx(
xlnt::detail::to_vector(source_stream), password);
return xml_helper::xlsx_archives_match(source_decrypted, destination);
}
void test_round_trip_rw()
{
const auto files = std::vector<std::string>
{
"2_minimal",
"3_default",
"4_every_style",
u8"9_unicode_Λ",
"10_comments_hyperlinks_formulae",
"11_print_settings",
"12_advanced_properties"
};
for (const auto file : files)
{
auto path = path_helper::data_directory(file + ".xlsx");
assert(round_trip_matches_rw(path));
}
}
void test_round_trip_rw_encrypted()
{
const auto files = std::vector<std::string>
{
"5_encrypted_agile",
"6_encrypted_libre",
"7_encrypted_standard",
"8_encrypted_numbers"
};
for (const auto file : files)
{
auto path = path_helper::data_directory(file + ".xlsx");
auto password = std::string(file == "7_encrypted_standard" ? "password"
: file == "6_encrypted_libre" ? u8"пароль"
: "secret");
assert(round_trip_matches_rw(path, password));
}
}
};

View File

@ -1,12 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/xml_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_theme : public test_suite
{
};

View File

@ -1,10 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_vba : public test_suite
{
};

View File

@ -0,0 +1,35 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <helpers/path_helper.hpp>
#include <helpers/xml_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_theme : public test_suite
{
};

View File

@ -0,0 +1,33 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_vba : public test_suite
{
};

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <algorithm>
@ -7,11 +30,14 @@
#include <xlnt/xlnt.hpp>
#include "helpers/temporary_file.hpp"
//checked with 52f25d6
class test_workbook : public test_suite
class workbook_test_suite : public test_suite
{
public:
workbook_test_suite()
{
register_test(test_active_sheet);
}
void test_active_sheet()
{
xlnt::workbook wb;

View File

@ -0,0 +1,34 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_datavalidation : public test_suite
{
public:
};

View File

@ -0,0 +1,66 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class page_setup_test_suite : public test_suite
{
public:
void test_properties()
{
xlnt::page_setup ps;
assert_equals(ps.paper_size(), xlnt::paper_size::letter);
ps.paper_size(xlnt::paper_size::executive);
assert_equals(ps.paper_size(), xlnt::paper_size::executive);
assert_equals(ps.orientation(), xlnt::orientation::portrait);
ps.orientation(xlnt::orientation::landscape);
assert_equals(ps.orientation(), xlnt::orientation::landscape);
assert(!ps.fit_to_page());
ps.fit_to_page(true);
assert(ps.fit_to_page());
assert(!ps.fit_to_height());
ps.fit_to_height(true);
assert(ps.fit_to_height());
assert(!ps.fit_to_width());
ps.fit_to_width(true);
assert(ps.fit_to_width());
assert(!ps.horizontal_centered());
ps.horizontal_centered(true);
assert(ps.horizontal_centered());
assert(!ps.vertical_centered());
ps.vertical_centered(true);
assert(ps.vertical_centered());
}
};

View File

@ -0,0 +1,64 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/worksheet.hpp>
#include <xlnt/workbook/workbook.hpp>
class range_test_suite : public test_suite
{
public:
void test_batch_formatting()
{
xlnt::workbook wb;
auto ws = wb.active_sheet();
for (auto row = 1; row <= 10; ++row)
{
for (auto column = 1; column <= 10; ++column)
{
auto ref = xlnt::cell_reference(column, row);
ws[ref].value(ref.to_string());
}
}
ws.range("A1:A10").font(xlnt::font().name("Arial"));
ws.range("A1:J1").font(xlnt::font().bold(true));
assert_equals(ws.cell("A1").font().name(), "Calibri");
assert(ws.cell("A1").font().bold());
assert_equals(ws.cell("A2").font().name(), "Arial");
assert(!ws.cell("A2").font().bold());
assert_equals(ws.cell("B1").font().name(), "Calibri");
assert(ws.cell("B1").font().bold());
assert(!ws.cell("B2").has_format());
}
};

View File

@ -1,11 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_datavalidation : public test_suite
{
public:
};

View File

@ -1,43 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/xlnt.hpp>
class test_page_setup : public test_suite
{
public:
void test_properties()
{
xlnt::page_setup ps;
assert_equals(ps.paper_size(), xlnt::paper_size::letter);
ps.paper_size(xlnt::paper_size::executive);
assert_equals(ps.paper_size(), xlnt::paper_size::executive);
assert_equals(ps.orientation(), xlnt::orientation::portrait);
ps.orientation(xlnt::orientation::landscape);
assert_equals(ps.orientation(), xlnt::orientation::landscape);
assert(!ps.fit_to_page());
ps.fit_to_page(true);
assert(ps.fit_to_page());
assert(!ps.fit_to_height());
ps.fit_to_height(true);
assert(ps.fit_to_height());
assert(!ps.fit_to_width());
ps.fit_to_width(true);
assert(ps.fit_to_width());
assert(!ps.horizontal_centered());
ps.horizontal_centered(true);
assert(ps.horizontal_centered());
assert(!ps.vertical_centered());
ps.vertical_centered(true);
assert(ps.vertical_centered());
}
};

View File

@ -1,41 +0,0 @@
#pragma once
#include <iostream>
#include <helpers/test_suite.hpp>
#include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/worksheet.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_range : public test_suite
{
public:
void test_batch_formatting()
{
xlnt::workbook wb;
auto ws = wb.active_sheet();
for (auto row = 1; row <= 10; ++row)
{
for (auto column = 1; column <= 10; ++column)
{
auto ref = xlnt::cell_reference(column, row);
ws[ref].value(ref.to_string());
}
}
ws.range("A1:A10").font(xlnt::font().name("Arial"));
ws.range("A1:J1").font(xlnt::font().bold(true));
assert_equals(ws.cell("A1").font().name(), "Calibri");
assert(ws.cell("A1").font().bold());
assert_equals(ws.cell("A2").font().name(), "Arial");
assert(!ws.cell("A2").font().bold());
assert_equals(ws.cell("B1").font().name(), "Calibri");
assert(ws.cell("B1").font().bold());
assert(!ws.cell("B2").has_format());
}
};

View File

@ -1,3 +1,26 @@
// Copyright (c) 2014-2017 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iostream>
@ -7,10 +30,10 @@
#include <xlnt/worksheet/worksheet.hpp>
#include <xlnt/workbook/workbook.hpp>
class test_worksheet : public test_suite
class worksheet_test_suite : public test_suite
{
public:
test_worksheet()
worksheet_test_suite()
{
register_test(test_new_worksheet);
register_test(test_cell);