From c68aa8fc842da4720d82673cbae42b0c22bd768b Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Thu, 13 Apr 2017 19:24:20 -0400 Subject: [PATCH] finish wiring up tests --- source/utils/date.cpp | 5 ++++ tests/cell/cell_test_suite.hpp | 3 --- tests/runner.cpp | 25 +++++++++++++++++- tests/styles/alignment_test_suite.hpp | 2 +- tests/styles/color_test_suite.hpp | 2 +- tests/styles/fill_test_suite.hpp | 2 +- tests/styles/number_format_test_suite.hpp | 2 +- tests/utils/datetime_test_suite.hpp | 13 +++++++++- tests/utils/helper_test_suite.hpp | 7 +++++- tests/utils/path_test_suite.hpp | 7 +++++- tests/utils/timedelta_test_suite.hpp | 9 +++++++ tests/workbook/named_range_test_suite.hpp | 2 +- tests/workbook/serialization_test_suite.hpp | 24 +++++++++++++++++- tests/workbook/workbook_test_suite.hpp | 28 +++++++++++++++++---- tests/worksheet/page_setup_test_suite.hpp | 7 +++++- tests/worksheet/range_test_suite.hpp | 9 +++++-- tests/worksheet/worksheet_test_suite.hpp | 4 +-- 17 files changed, 128 insertions(+), 23 deletions(-) diff --git a/source/utils/date.cpp b/source/utils/date.cpp index 3aa35b5c..a21d343d 100644 --- a/source/utils/date.cpp +++ b/source/utils/date.cpp @@ -89,6 +89,11 @@ bool date::operator==(const date &comparand) const return year == comparand.year && month == comparand.month && day == comparand.day; } +bool date::operator!=(const date &comparand) const +{ + return !(*this == comparand); +} + int date::to_number(calendar base_date) const { if (day == 29 && month == 2 && year == 1900) diff --git a/tests/cell/cell_test_suite.hpp b/tests/cell/cell_test_suite.hpp index 986d9cc2..eab6b339 100644 --- a/tests/cell/cell_test_suite.hpp +++ b/tests/cell/cell_test_suite.hpp @@ -27,7 +27,6 @@ #include #include - #include class cell_test_suite : public test_suite @@ -72,8 +71,6 @@ public: private: void test_infer_numeric() { - assert(1 == 0); - xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell("A1"); diff --git a/tests/runner.cpp b/tests/runner.cpp index 8fa8f7c7..39556a7c 100644 --- a/tests/runner.cpp +++ b/tests/runner.cpp @@ -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 + #include #include #include @@ -40,7 +63,7 @@ void print_summary() for (auto failure : overall_status.failures) { - std::cout << failure << " failed" << std::endl; + std::cout << failure << " failed" << std::endl; } } diff --git a/tests/styles/alignment_test_suite.hpp b/tests/styles/alignment_test_suite.hpp index 711f69c3..51b0c6ba 100644 --- a/tests/styles/alignment_test_suite.hpp +++ b/tests/styles/alignment_test_suite.hpp @@ -24,8 +24,8 @@ #pragma once #include -#include +#include #include class alignment_test_suite : public test_suite diff --git a/tests/styles/color_test_suite.hpp b/tests/styles/color_test_suite.hpp index 1dc55f01..e8df1462 100644 --- a/tests/styles/color_test_suite.hpp +++ b/tests/styles/color_test_suite.hpp @@ -24,8 +24,8 @@ #pragma once #include -#include +#include #include class color_test_suite : public test_suite diff --git a/tests/styles/fill_test_suite.hpp b/tests/styles/fill_test_suite.hpp index 3f22cafb..6929570f 100644 --- a/tests/styles/fill_test_suite.hpp +++ b/tests/styles/fill_test_suite.hpp @@ -24,8 +24,8 @@ #pragma once #include -#include +#include #include class fill_test_suite : public test_suite diff --git a/tests/styles/number_format_test_suite.hpp b/tests/styles/number_format_test_suite.hpp index 7c5c5cde..6ce43564 100644 --- a/tests/styles/number_format_test_suite.hpp +++ b/tests/styles/number_format_test_suite.hpp @@ -24,8 +24,8 @@ #pragma once #include -#include +#include #include class number_format_test_suite : public test_suite diff --git a/tests/utils/datetime_test_suite.hpp b/tests/utils/datetime_test_suite.hpp index f8916355..ef0cb993 100644 --- a/tests/utils/datetime_test_suite.hpp +++ b/tests/utils/datetime_test_suite.hpp @@ -24,13 +24,24 @@ #pragma once #include -#include +#include #include class datetime_test_suite : public test_suite { public: + datetime_test_suite() + { + register_test(test_from_string); + register_test(test_to_string); + register_test(test_carry); + register_test(test_leap_year_bug); + register_test(test_early_date); + register_test(test_mac_calendar); + register_test(test_operators); + } + void test_from_string() { xlnt::time t("10:35:45"); diff --git a/tests/utils/helper_test_suite.hpp b/tests/utils/helper_test_suite.hpp index c96f6678..4ace5e59 100644 --- a/tests/utils/helper_test_suite.hpp +++ b/tests/utils/helper_test_suite.hpp @@ -24,13 +24,18 @@ #pragma once #include -#include +#include #include class helper_test_suite : public test_suite { public: + helper_test_suite() + { + register_test(test_compare); + } + void test_compare() { assert(!xml_helper::compare_xml_exact("", "", true)); diff --git a/tests/utils/path_test_suite.hpp b/tests/utils/path_test_suite.hpp index 71d564a3..05fda9ff 100644 --- a/tests/utils/path_test_suite.hpp +++ b/tests/utils/path_test_suite.hpp @@ -24,15 +24,20 @@ #pragma once #include -#include #include #include +#include #include class path_test_suite : public test_suite { public: + path_test_suite() + { + register_test(test_exists); + } + void test_exists() { temporary_file temp; diff --git a/tests/utils/timedelta_test_suite.hpp b/tests/utils/timedelta_test_suite.hpp index c5bc9e0f..f3d8685c 100644 --- a/tests/utils/timedelta_test_suite.hpp +++ b/tests/utils/timedelta_test_suite.hpp @@ -24,11 +24,20 @@ #pragma once #include + #include class timedelta_test_suite : public test_suite { public: + timedelta_test_suite() + { + register_test(test_from_number); + register_test(test_round_trip); + register_test(test_to_number); + register_test(test_carry); + } + void test_from_number() { auto td = xlnt::timedelta::from_number(1.0423726852L); diff --git a/tests/workbook/named_range_test_suite.hpp b/tests/workbook/named_range_test_suite.hpp index c8e3f68d..39f280d7 100644 --- a/tests/workbook/named_range_test_suite.hpp +++ b/tests/workbook/named_range_test_suite.hpp @@ -24,8 +24,8 @@ #pragma once #include -#include +#include #include class named_range_test_suite : public test_suite diff --git a/tests/workbook/serialization_test_suite.hpp b/tests/workbook/serialization_test_suite.hpp index 47958539..9cea90f5 100644 --- a/tests/workbook/serialization_test_suite.hpp +++ b/tests/workbook/serialization_test_suite.hpp @@ -36,6 +36,28 @@ class serialization_test_suite : public test_suite { public: + serialization_test_suite() + { + register_test(test_produce_empty); + register_test(test_produce_simple_excel); + register_test(test_save_after_sheet_deletion); + register_test(test_write_comments_hyperlinks_formulae); + register_test(test_save_after_clear_all_formulae); + register_test(test_load_non_xlsx); + register_test(test_decrypt_agile); + register_test(test_decrypt_libre_office); + register_test(test_decrypt_standard); + register_test(test_decrypt_numbers); + register_test(test_read_unicode_filename); + register_test(test_comments); + register_test(test_read_hyperlink); + register_test(test_read_formulae); + register_test(test_read_headers_and_footers); + register_test(test_read_custom_properties); + register_test(test_round_trip_rw); + register_test(test_round_trip_rw_encrypted); + } + bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file) { std::vector wb_data; @@ -203,7 +225,7 @@ public: wb.save("clear_formulae.xlsx"); } - void test_non_xlsx() + void test_load_non_xlsx() { xlnt::workbook wb; const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx"); diff --git a/tests/workbook/workbook_test_suite.hpp b/tests/workbook/workbook_test_suite.hpp index 45e4bfe2..8c5fe66a 100644 --- a/tests/workbook/workbook_test_suite.hpp +++ b/tests/workbook/workbook_test_suite.hpp @@ -25,10 +25,10 @@ #include #include -#include +#include +#include #include -#include "helpers/temporary_file.hpp" class workbook_test_suite : public test_suite { @@ -36,6 +36,26 @@ public: workbook_test_suite() { register_test(test_active_sheet); + register_test(test_create_sheet); + register_test(test_add_correct_sheet); + register_test(test_add_sheet_from_other_workbook); + register_test(test_add_sheet_at_index); + register_test(test_get_sheet_by_title); + register_test(test_get_sheet_by_title_const); + register_test(test_index_operator); + register_test(test_contains); + register_test(test_iter); + register_test(test_get_index); + register_test(test_get_sheet_names); + register_test(test_add_named_range); + register_test(test_get_named_range); + register_test(test_remove_named_range); + register_test(test_post_increment_iterator); + register_test(test_copy_iterator); + register_test(test_manifest); + register_test(test_memory); + register_test(test_clear); + register_test(test_comparison); } void test_active_sheet() @@ -124,9 +144,7 @@ public: assert_throws_nothing(wb["Sheet1"]); assert_throws(wb["NotThere"], xlnt::key_not_found); } - - // void test_delitem() {} doesn't make sense in c++ - + void test_contains() { xlnt::workbook wb; diff --git a/tests/worksheet/page_setup_test_suite.hpp b/tests/worksheet/page_setup_test_suite.hpp index b27a9a13..d940806f 100644 --- a/tests/worksheet/page_setup_test_suite.hpp +++ b/tests/worksheet/page_setup_test_suite.hpp @@ -24,13 +24,18 @@ #pragma once #include -#include +#include #include class page_setup_test_suite : public test_suite { public: + page_setup_test_suite() + { + register_test(test_properties); + } + void test_properties() { xlnt::page_setup ps; diff --git a/tests/worksheet/range_test_suite.hpp b/tests/worksheet/range_test_suite.hpp index 0659d272..9377b972 100644 --- a/tests/worksheet/range_test_suite.hpp +++ b/tests/worksheet/range_test_suite.hpp @@ -24,15 +24,20 @@ #pragma once #include -#include +#include +#include #include #include -#include class range_test_suite : public test_suite { public: + range_test_suite() + { + register_test(test_batch_formatting); + } + void test_batch_formatting() { xlnt::workbook wb; diff --git a/tests/worksheet/worksheet_test_suite.hpp b/tests/worksheet/worksheet_test_suite.hpp index dc0359f6..033a20df 100644 --- a/tests/worksheet/worksheet_test_suite.hpp +++ b/tests/worksheet/worksheet_test_suite.hpp @@ -24,11 +24,11 @@ #pragma once #include -#include +#include +#include #include #include -#include class worksheet_test_suite : public test_suite {