Merge pull request #307 from Crzyrndm/dev-test-suite-improvements

Test suite improvements
This commit is contained in:
Crzyrndm 2018-07-13 11:56:55 +12:00 committed by GitHub
commit c0a90ccb7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 286 additions and 275 deletions

View File

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

View File

@ -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
{
@ -140,8 +153,7 @@ private:
xlnt::cell::type::error,
xlnt::cell::type::formula_string,
xlnt::cell::type::number,
xlnt::cell::type::shared_string
};
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)
{
@ -678,3 +689,5 @@ private:
xlnt_assert_throws(cell.comment(), xlnt::exception);
}
};
static cell_test_suite x{};

View File

@ -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{};

View File

@ -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{};

View File

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

View 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;
}

View File

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

View File

@ -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();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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
{
@ -692,3 +709,4 @@ public:
c3.value("C3!");
}
};
static serialization_test_suite x;

View File

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

View File

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

View File

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

View File

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