From 9a6bcdfc540a3ee09675713afeb48da898ca245d Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sat, 23 Jul 2016 21:24:25 -0400 Subject: [PATCH] fix range iterator tests --- include/xlnt/utils/utf8string.hpp | 2 -- include/xlnt/xlnt_config.hpp | 6 ------ source/cell/cell_reference.cpp | 2 +- source/cell/tests/test_cell.hpp | 2 -- source/cell/tests/test_index_types.hpp | 1 - source/detail/constants.cpp | 17 +--------------- source/utils/tests/test_utf8string.hpp | 4 ++-- source/utils/utf8string.cpp | 5 ----- source/workbook/tests/test_workbook.hpp | 5 +++++ source/workbook/workbook.cpp | 6 +++--- source/worksheet/tests/test_worksheet.hpp | 24 +++++++++++++++-------- 11 files changed, 28 insertions(+), 46 deletions(-) diff --git a/include/xlnt/utils/utf8string.hpp b/include/xlnt/utils/utf8string.hpp index f83e01ba..a849e9a5 100644 --- a/include/xlnt/utils/utf8string.hpp +++ b/include/xlnt/utils/utf8string.hpp @@ -39,8 +39,6 @@ public: static utf8string from_utf16(const std::vector &s); static utf8string from_utf32(const std::vector &s); - static bool is_valid(const std::string &s); - bool is_valid() const; private: diff --git a/include/xlnt/xlnt_config.hpp b/include/xlnt/xlnt_config.hpp index ac8ddce8..da3f0f80 100644 --- a/include/xlnt/xlnt_config.hpp +++ b/include/xlnt/xlnt_config.hpp @@ -48,12 +48,6 @@ enum class limit_style maximum }; -/// -/// The style of limits to use for reading and writing XLSX files. -/// See limit_style for more information. -/// -const limit_style xlnt_limit_style = limit_style::openpyxl; - #ifndef XLNT_API #if !defined(XLNT_STATIC) && defined(_MSC_VER) #ifdef XLNT_EXPORT diff --git a/source/cell/cell_reference.cpp b/source/cell/cell_reference.cpp index fd33e35f..16bd0e52 100644 --- a/source/cell/cell_reference.cpp +++ b/source/cell/cell_reference.cpp @@ -73,7 +73,7 @@ cell_reference::cell_reference(column_t column_index, row_t row) { throw value_error(); } - + if (!(row_ <= constants::max_row()) || !(column_ <= constants::max_column())) { throw cell_coordinates_error(column_, row_); diff --git a/source/cell/tests/test_cell.hpp b/source/cell/tests/test_cell.hpp index d3ae5476..e1813163 100644 --- a/source/cell/tests/test_cell.hpp +++ b/source/cell/tests/test_cell.hpp @@ -630,8 +630,6 @@ public: TS_ASSERT_DIFFERS(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1))); TS_ASSERT_EQUALS(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2))); - TS_ASSERT_THROWS(xlnt::cell_reference(10000000, 10000000), xlnt::cell_coordinates_error); - TS_ASSERT_EQUALS((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2")); TS_ASSERT_THROWS(xlnt::cell_reference("A1&"), xlnt::cell_coordinates_error); diff --git a/source/cell/tests/test_index_types.hpp b/source/cell/tests/test_index_types.hpp index 505c069a..91e0c651 100644 --- a/source/cell/tests/test_index_types.hpp +++ b/source/cell/tests/test_index_types.hpp @@ -18,7 +18,6 @@ public: void test_bad_column() { TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(0), xlnt::column_string_index_error); - TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(10000000), xlnt::column_string_index_error); } void test_column_operators() diff --git a/source/detail/constants.cpp b/source/detail/constants.cpp index ef8857d2..8045b6a6 100644 --- a/source/detail/constants.cpp +++ b/source/detail/constants.cpp @@ -35,11 +35,6 @@ const row_t constants::min_row() const row_t constants::max_row() { - if(xlnt_limit_style == limit_style::excel) - { - return 1u << 20; - } - return std::numeric_limits::max(); } @@ -50,17 +45,7 @@ const column_t constants::min_column() const column_t constants::max_column() { - switch (xlnt_limit_style) - { - case limit_style::excel: - return column_t(1u << 14); - - case limit_style::openpyxl: - return column_t(18'278); - - default: - return column_t(std::numeric_limits::max()); - } + return column_t(std::numeric_limits::max()); } // constants diff --git a/source/utils/tests/test_utf8string.hpp b/source/utils/tests/test_utf8string.hpp index e1d82b47..cd630c44 100644 --- a/source/utils/tests/test_utf8string.hpp +++ b/source/utils/tests/test_utf8string.hpp @@ -21,13 +21,13 @@ public: auto latin1_valid = xlnt::utf8string::from_latin1("abc"); TS_ASSERT(latin1_valid.is_valid()); } - + void test_utf16() { auto utf16_valid = xlnt::utf8string::from_utf16({ 'a', 'b', 'c' }); TS_ASSERT(utf16_valid.is_valid()); } - + void test_utf32() { auto utf32_valid = xlnt::utf8string::from_utf32({ 'a', 'b', 'c' }); diff --git a/source/utils/utf8string.cpp b/source/utils/utf8string.cpp index b78dc991..fd88aea2 100644 --- a/source/utils/utf8string.cpp +++ b/source/utils/utf8string.cpp @@ -56,11 +56,6 @@ utf8string utf8string::from_utf32(const std::vector &s) return result; } -bool utf8string::is_valid(const std::string &s) -{ - return utf8::is_valid(s.begin(), s.end()); -} - bool utf8string::is_valid() const { return utf8::is_valid(bytes_.begin(), bytes_.end()); diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 752dcf91..7e98f606 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -372,4 +372,9 @@ public: wb_const.get_style("style1"); wb.get_style_by_id(0); } + + void test_limits() + { + + } }; diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 84f982cc..413c4774 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -158,14 +158,14 @@ worksheet workbook::create_sheet() title = "Sheet" + std::to_string(++index); } - std::string sheet_filename = "worksheets/sheet" + std::to_string(d_->worksheets_.size() + 1) + ".xml"; + std::string sheet_filename = "sheet" + std::to_string(d_->worksheets_.size() + 1) + ".xml"; d_->worksheets_.push_back(detail::worksheet_impl(this, title)); create_relationship("rId" + std::to_string(d_->relationships_.size() + 1), - sheet_filename, + "worksheets/" + sheet_filename, relationship::type::worksheet); - d_->manifest_.add_override_type("/xl/" + sheet_filename, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); + d_->manifest_.add_override_type("/" + constants::package_worksheets() + "/" + sheet_filename, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); return worksheet(&d_->worksheets_.back()); } diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 192ba24c..14a8d223 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -795,6 +795,9 @@ public: auto second_cell = *first_column_iter; TS_ASSERT_EQUALS(second_cell.get_value(), "A2"); + TS_ASSERT_EQUALS(first_cell, first_column.front()); + TS_ASSERT_EQUALS(second_cell, first_column.back()); + auto last_column = *(--columns.end()); auto last_column_iter = last_column.end(); last_column_iter--; @@ -1070,22 +1073,27 @@ public: auto range_iter = range.begin(); auto row = *range_iter; auto row_iter = row.begin(); - auto cell = *row_iter; - TS_ASSERT_EQUALS(cell.get_value(), 3.14); - TS_ASSERT_EQUALS(row.front().get_reference(), "A2"); + TS_ASSERT_EQUALS((*row_iter).get_value(), 3.14); + TS_ASSERT_EQUALS((*row_iter).get_reference(), "A2"); + TS_ASSERT_EQUALS((*row_iter), row.front()); row_iter++; - cell = *row_iter; - TS_ASSERT_EQUALS(cell.get_value(), "text"); - TS_ASSERT_EQUALS(row.back().get_reference(), "B2"); + TS_ASSERT_EQUALS((*row_iter).get_value(), "text"); + TS_ASSERT_EQUALS((*row_iter).get_reference(), "B2"); + TS_ASSERT_EQUALS((*row_iter), row.back()); + + range_iter++; + row = *range_iter; + row_iter = row.begin(); + TS_ASSERT_EQUALS((*row_iter).get_value(), true); + TS_ASSERT_EQUALS((*row_iter).get_reference(), "A3"); range_iter = range.end(); range_iter--; row = *range_iter; row_iter = row.end(); row_iter--; - cell = *row_iter; - TS_ASSERT_EQUALS(cell.get_value(), false); + TS_ASSERT_EQUALS((*row_iter).get_value(), false); } void test_get_squared_range()