mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Merge pull request #307 from Crzyrndm/dev-test-suite-improvements
Test suite improvements
This commit is contained in:
commit
c0a90ccb7f
|
@ -14,12 +14,12 @@ if(STATIC_CRT)
|
|||
ucm_set_runtime(STATIC)
|
||||
endif()
|
||||
|
||||
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)
|
||||
file(GLOB CELL_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/cell/*.cpp)
|
||||
file(GLOB PACKAGING_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/*.cpp)
|
||||
file(GLOB STYLES_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/styles/*.cpp)
|
||||
file(GLOB UTILS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.cpp)
|
||||
file(GLOB WORKBOOK_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/workbook/*.cpp)
|
||||
file(GLOB WORKSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/worksheet/*.cpp)
|
||||
|
||||
set(TESTS
|
||||
${CELL_TESTS}
|
||||
|
|
|
@ -21,13 +21,26 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <helpers/assertions.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/hyperlink.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/alignment.hpp>
|
||||
#include <xlnt/styles/border.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/styles/format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
#include <xlnt/utils/timedelta.hpp>
|
||||
|
||||
class cell_test_suite : public test_suite
|
||||
{
|
||||
|
@ -134,14 +147,13 @@ private:
|
|||
xlnt::workbook wb;
|
||||
|
||||
const auto datatypes =
|
||||
{
|
||||
xlnt::cell::type::empty,
|
||||
xlnt::cell::type::boolean,
|
||||
xlnt::cell::type::error,
|
||||
xlnt::cell::type::formula_string,
|
||||
xlnt::cell::type::number,
|
||||
xlnt::cell::type::shared_string
|
||||
};
|
||||
{
|
||||
xlnt::cell::type::empty,
|
||||
xlnt::cell::type::boolean,
|
||||
xlnt::cell::type::error,
|
||||
xlnt::cell::type::formula_string,
|
||||
xlnt::cell::type::number,
|
||||
xlnt::cell::type::shared_string};
|
||||
|
||||
for (const auto &datatype : datatypes)
|
||||
{
|
||||
|
@ -209,7 +221,6 @@ private:
|
|||
xlnt_assert(!cell.has_formula());
|
||||
}
|
||||
|
||||
|
||||
void test_not_formula()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -228,7 +239,7 @@ private:
|
|||
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);
|
||||
xlnt_assert(cell.data_type() == xlnt::cell::type::boolean);
|
||||
|
@ -331,8 +342,8 @@ private:
|
|||
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 };
|
||||
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)
|
||||
{
|
||||
|
@ -341,9 +352,9 @@ private:
|
|||
}
|
||||
|
||||
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(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 ");
|
||||
}
|
||||
|
||||
|
@ -393,8 +404,8 @@ private:
|
|||
auto cell = ws.cell("A1");
|
||||
|
||||
xlnt::fill fill(xlnt::pattern_fill()
|
||||
.type(xlnt::pattern_fill_type::solid)
|
||||
.foreground(xlnt::color::red()));
|
||||
.type(xlnt::pattern_fill_type::solid)
|
||||
.foreground(xlnt::color::red()));
|
||||
cell.fill(fill);
|
||||
|
||||
xlnt_assert(cell.has_format());
|
||||
|
@ -678,3 +689,5 @@ private:
|
|||
xlnt_assert_throws(cell.comment(), xlnt::exception);
|
||||
}
|
||||
};
|
||||
|
||||
static cell_test_suite x{};
|
|
@ -21,12 +21,10 @@
|
|||
// @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 index_types_test_suite : public test_suite
|
||||
{
|
||||
|
@ -103,3 +101,5 @@ public:
|
|||
xlnt_assert(!(4 <= c1));
|
||||
}
|
||||
};
|
||||
|
||||
static index_types_test_suite x{};
|
|
@ -21,14 +21,13 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
#include <xlnt/cell/rich_text.hpp>
|
||||
|
||||
class rich_text_test_suite : public test_suite
|
||||
{
|
||||
|
@ -102,3 +101,4 @@ public:
|
|||
xlnt_assert_differs(text_formatted, text_family_differs);
|
||||
}
|
||||
};
|
||||
static rich_text_test_suite x{};
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
|
||||
#define XLNT_STRINGIFYX(x) #x
|
||||
#define XLNT_STRINGIFY(x) XLNT_STRINGIFYX(x)
|
||||
|
|
48
tests/helpers/test_suite.cpp
Normal file
48
tests/helpers/test_suite.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "test_suite.hpp"
|
||||
#include <iostream>
|
||||
|
||||
std::vector<std::pair<std::function<void(void)>, std::string>> &test_suite::tests()
|
||||
{
|
||||
static std::vector<std::pair<std::function<void(void)>, std::string>> all_tests;
|
||||
return all_tests;
|
||||
}
|
||||
|
||||
std::string build_name(const std::string &pretty, const std::string &method)
|
||||
{
|
||||
return pretty.substr(0, pretty.find("::") + 2) + method;
|
||||
}
|
||||
|
||||
test_status test_suite::go()
|
||||
{
|
||||
test_status status;
|
||||
|
||||
for (auto test : tests())
|
||||
{
|
||||
try
|
||||
{
|
||||
test.first();
|
||||
std::cout << '.';
|
||||
status.tests_passed++;
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
std::string fail_msg = test.second + " failed with:\n" + std::string(ex.what());
|
||||
std::cout << "*\n"
|
||||
<< fail_msg << '\n';
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(fail_msg);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "*\n"
|
||||
<< test.second << " failed\n";
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(test.second);
|
||||
}
|
||||
|
||||
std::cout.flush();
|
||||
status.tests_run++;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
|
@ -8,6 +8,11 @@
|
|||
#include <vector>
|
||||
|
||||
#include <helpers/assertions.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
//#include <helpers/temporary_directory.hpp>
|
||||
//#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/timing.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
struct test_status
|
||||
{
|
||||
|
@ -17,56 +22,21 @@ struct test_status
|
|||
std::vector<std::string> failures;
|
||||
};
|
||||
|
||||
std::string build_name(const std::string &pretty, const std::string &method)
|
||||
{
|
||||
return pretty.substr(0, pretty.find("::") + 2) + method;
|
||||
}
|
||||
std::string build_name(const std::string &pretty, const std::string &method);
|
||||
|
||||
#define register_test(test) register_test_internal([this]() { test(); }, build_name(__FUNCTION__, #test));
|
||||
|
||||
class test_suite
|
||||
{
|
||||
public:
|
||||
test_status go()
|
||||
{
|
||||
test_status status;
|
||||
|
||||
for (auto test : tests)
|
||||
{
|
||||
try
|
||||
{
|
||||
test.first();
|
||||
std::cout << ".";
|
||||
status.tests_passed++;
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
std::string fail_msg = test.second + " failed with:\n" + std::string(ex.what());
|
||||
std::cout << "*\n"
|
||||
<< fail_msg << '\n';
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(fail_msg);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "*\n" << test.second << " failed\n";
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(test.second);
|
||||
}
|
||||
|
||||
std::cout.flush();
|
||||
status.tests_run++;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
static test_status go();
|
||||
|
||||
protected:
|
||||
void register_test_internal(std::function<void()> t, const std::string &function)
|
||||
static void register_test_internal(std::function<void()> t, const std::string &function)
|
||||
{
|
||||
tests.push_back(std::make_pair(t, function));
|
||||
tests().push_back(std::make_pair(t, function));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::function<void(void)>, std::string>> tests;
|
||||
static std::vector<std::pair<std::function<void(void)>, std::string>> &tests();
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace xlnt {
|
||||
namespace benchmarks {
|
||||
|
||||
std::size_t current_time()
|
||||
inline std::size_t current_time()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto time_since_epoch = now.time_since_epoch();
|
||||
|
|
|
@ -22,50 +22,17 @@
|
|||
// @author: see AUTHORS file
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <cell/cell_test_suite.hpp>
|
||||
#include <cell/index_types_test_suite.hpp>
|
||||
#include <cell/rich_text_test_suite.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/datetime_test_suite.hpp>
|
||||
#include <utils/path_test_suite.hpp>
|
||||
#include <utils/helper_test_suite.hpp>
|
||||
#include <utils/timedelta_test_suite.hpp>
|
||||
|
||||
#include <workbook/named_range_test_suite.hpp>
|
||||
#include <workbook/serialization_test_suite.hpp>
|
||||
#include <workbook/workbook_test_suite.hpp>
|
||||
|
||||
#include <worksheet/page_setup_test_suite.hpp>
|
||||
#include <worksheet/range_test_suite.hpp>
|
||||
#include <worksheet/worksheet_test_suite.hpp>
|
||||
|
||||
#include <detail/cryptography/compound_document.hpp>
|
||||
|
||||
test_status overall_status;
|
||||
|
||||
template<typename T>
|
||||
void run_tests()
|
||||
{
|
||||
auto status = T{}.go();
|
||||
|
||||
overall_status.tests_run += status.tests_run;
|
||||
overall_status.tests_passed += status.tests_passed;
|
||||
overall_status.tests_failed += status.tests_failed;
|
||||
|
||||
std::copy(status.failures.begin(), status.failures.end(), std::back_inserter(overall_status.failures));
|
||||
}
|
||||
|
||||
void print_summary()
|
||||
void print_summary(const test_status& results)
|
||||
{
|
||||
std::cout << "\n\n";
|
||||
|
||||
for (auto failure : overall_status.failures)
|
||||
std::cout << "Run: " << results.tests_run << '\n';
|
||||
std::cout << "Passed: " << results.tests_passed << '\n';
|
||||
std::cout << "Failed: " << results.tests_failed << '\n' << '\n';
|
||||
|
||||
for (auto failure : results.failures)
|
||||
{
|
||||
std::cout << failure << "\n\n";
|
||||
}
|
||||
|
@ -73,34 +40,9 @@ void print_summary()
|
|||
|
||||
int main()
|
||||
{
|
||||
// cell
|
||||
run_tests<cell_test_suite>();
|
||||
run_tests<index_types_test_suite>();
|
||||
run_tests<rich_text_test_suite>();
|
||||
test_status overall_status = test_suite::go();
|
||||
|
||||
// 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();
|
||||
print_summary(overall_status);
|
||||
|
||||
return static_cast<int>(overall_status.tests_failed);
|
||||
}
|
||||
|
|
|
@ -21,12 +21,10 @@
|
|||
// @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>
|
||||
#include <xlnt/styles/alignment.hpp>
|
||||
|
||||
class alignment_test_suite : public test_suite
|
||||
{
|
||||
|
@ -46,3 +44,4 @@ public:
|
|||
xlnt_assert(!alignment.wrap());
|
||||
}
|
||||
};
|
||||
static alignment_test_suite x;
|
|
@ -21,12 +21,11 @@
|
|||
// @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>
|
||||
|
||||
#include <xlnt/styles/color.hpp>
|
||||
|
||||
class color_test_suite : public test_suite
|
||||
{
|
||||
|
@ -74,3 +73,4 @@ public:
|
|||
xlnt_assert_throws(theme.rgb(), xlnt::invalid_attribute);
|
||||
}
|
||||
};
|
||||
static color_test_suite x;
|
|
@ -21,12 +21,14 @@
|
|||
// @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>
|
||||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
class fill_test_suite : public test_suite
|
||||
{
|
||||
|
@ -104,3 +106,4 @@ public:
|
|||
xlnt_assert_equals(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
|
||||
}
|
||||
};
|
||||
static fill_test_suite x;
|
|
@ -21,12 +21,14 @@
|
|||
// @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>
|
||||
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
#include <xlnt/utils/timedelta.hpp>
|
||||
|
||||
class number_format_test_suite : public test_suite
|
||||
{
|
||||
|
@ -991,3 +993,4 @@ public:
|
|||
format_and_test(xlnt::number_format::date_myminus(), {{"5-16", "###########", "1-00", "text"}});
|
||||
}
|
||||
};
|
||||
static number_format_test_suite x;
|
|
@ -21,12 +21,12 @@
|
|||
// @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>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
|
||||
class datetime_test_suite : public test_suite
|
||||
{
|
||||
|
@ -114,3 +114,4 @@ public:
|
|||
xlnt_assert_differs(d1, d3);
|
||||
}
|
||||
};
|
||||
static datetime_test_suite x;
|
|
@ -21,8 +21,6 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
|
@ -30,6 +28,8 @@
|
|||
#include <helpers/xml_helper.hpp>
|
||||
#include <helpers/assertions.hpp>
|
||||
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
|
||||
class helper_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
|
@ -154,3 +154,4 @@ public:
|
|||
xlnt_assert(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true));
|
||||
}
|
||||
};
|
||||
static helper_test_suite x;
|
|
@ -21,14 +21,11 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class path_test_suite : public test_suite
|
||||
{
|
||||
|
@ -52,3 +49,4 @@ public:
|
|||
xlnt_assert(temp.get_path().exists());
|
||||
}
|
||||
};
|
||||
static path_test_suite x;
|
|
@ -21,12 +21,12 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/utils/timedelta.hpp>
|
||||
|
||||
class timedelta_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
|
@ -82,3 +82,4 @@ public:
|
|||
xlnt_assert_equals(rollover.microseconds, 0);
|
||||
}
|
||||
};
|
||||
static timedelta_test_suite x;
|
|
@ -21,8 +21,6 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
@ -257,3 +255,4 @@ public:
|
|||
[range_as_string(range, include_value = True) for range in wbcopy.get_named_ranges()])*/
|
||||
}
|
||||
};
|
||||
static named_range_test_suite x;
|
|
@ -21,20 +21,37 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <detail/serialization/vector_streambuf.hpp>
|
||||
#include <detail/cryptography/xlsx_crypto_consumer.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/worksheet/sheet_format_properties.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/hyperlink.hpp>
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/styles/font.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/styles/format.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/border.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
#include <xlnt/utils/timedelta.hpp>
|
||||
#include <xlnt/utils/variant.hpp>
|
||||
#include <xlnt/workbook/streaming_workbook_reader.hpp>
|
||||
#include <xlnt/workbook/streaming_workbook_writer.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/workbook/metadata_property.hpp>
|
||||
#include <xlnt/worksheet/column_properties.hpp>
|
||||
#include <xlnt/worksheet/row_properties.hpp>
|
||||
#include <xlnt/worksheet/sheet_format_properties.hpp>
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <detail/cryptography/xlsx_crypto_consumer.hpp>
|
||||
#include <detail/serialization/vector_streambuf.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
class serialization_test_suite : public test_suite
|
||||
{
|
||||
|
@ -75,8 +92,8 @@ public:
|
|||
register_test(test_streaming_write);
|
||||
}
|
||||
|
||||
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
|
||||
{
|
||||
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
|
||||
{
|
||||
std::vector<std::uint8_t> wb_data;
|
||||
wb.save(wb_data);
|
||||
wb.save("temp.xlsx");
|
||||
|
@ -84,109 +101,109 @@ public:
|
|||
std::ifstream file_stream(file.string(), std::ios::binary);
|
||||
auto file_data = xlnt::detail::to_vector(file_stream);
|
||||
|
||||
return xml_helper::xlsx_archives_match(wb_data, file_data);
|
||||
}
|
||||
return xml_helper::xlsx_archives_match(wb_data, file_data);
|
||||
}
|
||||
|
||||
void test_produce_empty()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
void test_produce_empty()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::test_file("3_default.xlsx");
|
||||
xlnt_assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
xlnt_assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_produce_simple_excel()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
void test_produce_simple_excel()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
auto bold_font = xlnt::font().bold(true);
|
||||
auto bold_font = xlnt::font().bold(true);
|
||||
|
||||
ws.cell("A1").value("Type");
|
||||
ws.cell("A1").font(bold_font);
|
||||
ws.cell("A1").value("Type");
|
||||
ws.cell("A1").font(bold_font);
|
||||
|
||||
ws.cell("B1").value("Value");
|
||||
ws.cell("B1").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("A2").value("null");
|
||||
ws.cell("B2").value(nullptr);
|
||||
|
||||
ws.cell("A3").value("bool (true)");
|
||||
ws.cell("B3").value(true);
|
||||
ws.cell("A3").value("bool (true)");
|
||||
ws.cell("B3").value(true);
|
||||
|
||||
ws.cell("A4").value("bool (false)");
|
||||
ws.cell("B4").value(false);
|
||||
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 (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("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 (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("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("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("A14").value("number (double)");
|
||||
ws.cell("B14").value(std::numeric_limits<double>::max());
|
||||
|
||||
ws.cell("A16").value("text (char *)");
|
||||
ws.cell("B16").value("string");
|
||||
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("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("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("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("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.cell("A21").value("timedelta");
|
||||
ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5));
|
||||
|
||||
ws.freeze_panes("B2");
|
||||
ws.freeze_panes("B2");
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
wb.save(temp_buffer);
|
||||
xlnt_assert(!temp_buffer.empty());
|
||||
}
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
wb.save(temp_buffer);
|
||||
xlnt_assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_save_after_sheet_deletion()
|
||||
{
|
||||
xlnt::workbook workbook;
|
||||
void test_save_after_sheet_deletion()
|
||||
{
|
||||
xlnt::workbook workbook;
|
||||
|
||||
xlnt_assert_equals(workbook.sheet_titles().size(), 1);
|
||||
xlnt_assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
auto sheet = workbook.create_sheet();
|
||||
sheet.title("XXX1");
|
||||
xlnt_assert_equals(workbook.sheet_titles().size(), 2);
|
||||
auto sheet = workbook.create_sheet();
|
||||
sheet.title("XXX1");
|
||||
xlnt_assert_equals(workbook.sheet_titles().size(), 2);
|
||||
|
||||
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
|
||||
xlnt_assert_equals(workbook.sheet_titles().size(), 1);
|
||||
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
|
||||
xlnt_assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
xlnt_assert_throws_nothing(workbook.save(temp_buffer));
|
||||
xlnt_assert(!temp_buffer.empty());
|
||||
}
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
xlnt_assert_throws_nothing(workbook.save(temp_buffer));
|
||||
xlnt_assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_write_comments_hyperlinks_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
void test_write_comments_hyperlinks_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
||||
xlnt::sheet_format_properties format_properties;
|
||||
format_properties.base_col_width = 10.0;
|
||||
format_properties.default_row_height = 16.0;
|
||||
format_properties.dy_descent = 0.2;
|
||||
|
||||
auto sheet1 = wb.active_sheet();
|
||||
auto sheet1 = wb.active_sheet();
|
||||
sheet1.format_properties(format_properties);
|
||||
|
||||
auto selection = xlnt::selection();
|
||||
|
@ -196,10 +213,10 @@ public:
|
|||
|
||||
// comments
|
||||
auto comment_font = xlnt::font()
|
||||
.bold(true)
|
||||
.size(10)
|
||||
.color(xlnt::indexed_color(81))
|
||||
.name("Calibri");
|
||||
.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");
|
||||
|
||||
|
@ -208,12 +225,12 @@ public:
|
|||
|
||||
// hyperlinks
|
||||
auto hyperlink_font = xlnt::font()
|
||||
.size(12)
|
||||
.color(xlnt::theme_color(10))
|
||||
.name("Calibri")
|
||||
.family(2)
|
||||
.scheme("minor")
|
||||
.underline(xlnt::font::underline_style::single);
|
||||
.size(12)
|
||||
.color(xlnt::theme_color(10))
|
||||
.name("Calibri")
|
||||
.family(2)
|
||||
.scheme("minor")
|
||||
.underline(xlnt::font::underline_style::single);
|
||||
auto hyperlink_style = wb.create_builtin_style(8);
|
||||
hyperlink_style.font(hyperlink_font);
|
||||
hyperlink_style.number_format(hyperlink_style.number_format(), false);
|
||||
|
@ -245,7 +262,7 @@ public:
|
|||
sheet1.row_properties(i).dy_descent = 0.2;
|
||||
}
|
||||
|
||||
auto sheet2 = wb.create_sheet();
|
||||
auto sheet2 = wb.create_sheet();
|
||||
sheet2.format_properties(format_properties);
|
||||
sheet2.add_view(xlnt::sheet_view());
|
||||
sheet2.view().add_selection(selection);
|
||||
|
@ -278,8 +295,8 @@ public:
|
|||
wb.core_property(xlnt::core_property::modified, "2018-03-18T20:59:53Z");
|
||||
|
||||
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
|
||||
xlnt_assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
xlnt_assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_save_after_clear_all_formulae()
|
||||
{
|
||||
|
@ -457,7 +474,7 @@ public:
|
|||
xlnt_assert(wb.has_custom_property("Client"));
|
||||
xlnt_assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
|
||||
}
|
||||
|
||||
|
||||
void test_read_custom_heights_widths()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -584,7 +601,7 @@ public:
|
|||
std::vector<std::uint8_t> destination_data;
|
||||
//source_workbook.save(destination_data, password);
|
||||
source_workbook.save("encrypted.xlsx", password);
|
||||
|
||||
|
||||
//xlnt::workbook temp;
|
||||
//temp.load("encrypted.xlsx", password);
|
||||
|
||||
|
@ -592,22 +609,22 @@ public:
|
|||
//return source_data == destination_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_minimal()
|
||||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("2_minimal.xlsx")));
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_default()
|
||||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("3_default.xlsx")));
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_every_style()
|
||||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("4_every_style.xlsx")));
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_unicode()
|
||||
{
|
||||
// u8"/9_unicode_Λ.xlsx" doesn't use 0xc3aa for the capital lambda...
|
||||
|
@ -624,7 +641,7 @@ public:
|
|||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("11_print_settings.xlsx")));
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_advanced_properties()
|
||||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("12_advanced_properties.xlsx")));
|
||||
|
@ -634,12 +651,12 @@ public:
|
|||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("13_custom_heights_widths.xlsx")));
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_encrypted_agile()
|
||||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("5_encrypted_agile.xlsx"), "secret"));
|
||||
}
|
||||
|
||||
|
||||
void test_round_trip_rw_encrypted_libre()
|
||||
{
|
||||
xlnt_assert(round_trip_matches_rw(path_helper::test_file("6_encrypted_libre.xlsx"), u8"\u043F\u0430\u0440\u043E\u043B\u044C")); // u8"пароль"
|
||||
|
@ -692,3 +709,4 @@ public:
|
|||
c3.value("C3!");
|
||||
}
|
||||
};
|
||||
static serialization_test_suite x;
|
|
@ -21,8 +21,6 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -31,6 +29,14 @@
|
|||
#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/styles/format.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/workbook/worksheet_iterator.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
class workbook_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
|
@ -461,3 +467,4 @@ public:
|
|||
xlnt_assert_equals(wb_path, wb_load5);
|
||||
}
|
||||
};
|
||||
static workbook_test_suite x;
|
|
@ -21,12 +21,10 @@
|
|||
// @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>
|
||||
#include <xlnt/worksheet/page_setup.hpp>
|
||||
|
||||
class page_setup_test_suite : public test_suite
|
||||
{
|
||||
|
@ -61,3 +59,4 @@ public:
|
|||
xlnt_assert(ps.fit_to_width());
|
||||
}
|
||||
};
|
||||
static page_setup_test_suite x;
|
|
@ -21,13 +21,15 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/styles/font.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
class range_test_suite : public test_suite
|
||||
|
@ -83,3 +85,4 @@ public:
|
|||
xlnt_assert_equals(ws.calculate_dimension(), xlnt::range_reference(1, 1, 1, 3));
|
||||
}
|
||||
};
|
||||
static range_test_suite x;
|
|
@ -21,11 +21,15 @@
|
|||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/hyperlink.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/column_properties.hpp>
|
||||
#include <xlnt/worksheet/row_properties.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
@ -1296,3 +1300,4 @@ public:
|
|||
xlnt_assert(ws2_title == ws2.title());
|
||||
}
|
||||
};
|
||||
static worksheet_test_suite x;
|
Loading…
Reference in New Issue
Block a user