From 23f65602de3e63a5c952fb7f83bf5a4da0553e1e Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Mon, 13 Jun 2016 23:36:26 -0400 Subject: [PATCH] revert coverage calculation and work on coverage --- .travis.yml | 14 +-- include/xlnt/workbook/workbook.hpp | 12 +++ include/xlnt/worksheet/cell_vector.hpp | 11 +++ .../xlnt/worksheet/const_cell_iterator.hpp | 2 +- .../xlnt/worksheet/const_range_iterator.hpp | 2 +- include/xlnt/worksheet/range.hpp | 11 +++ include/xlnt/worksheet/worksheet.hpp | 12 +++ source/utils/tests/test_utf8string.hpp | 36 +++++++ source/worksheet/cell_vector.cpp | 30 ++++++ source/worksheet/const_cell_iterator.cpp | 5 + source/worksheet/const_range_iterator.cpp | 14 +++ source/worksheet/range.cpp | 30 ++++++ source/worksheet/tests/test_worksheet.hpp | 99 +++++++++++++++++++ 13 files changed, 267 insertions(+), 11 deletions(-) create mode 100644 source/utils/tests/test_utf8string.hpp diff --git a/.travis.yml b/.travis.yml index 26371182..b5ce7133 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,8 +21,6 @@ matrix: - g++-4.9 - valgrind - python-pip - - python-yaml - - cmake before_script: - pip install --user git+git://github.com/eddyxu/cpp-coveralls.git env: @@ -34,11 +32,9 @@ matrix: apt: sources: - ubuntu-toolchain-r-test - - george-edison55/cmake-3.x packages: - g++-5 - valgrind - - cmake env: - COMPILER=g++-5 @@ -54,10 +50,10 @@ after_success: - if [ "$COMPILER" = "g++-4.9" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 90 ; fi - if [ "$COMPILER" = "g++-4.9" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 90 ; fi - if [ "$COMPILER" = "g++-4.9" ]; then sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90 ; fi - - if [ "$COMPILER" = "g++-4.9" ]; then cmake -D DEBUG=1 -D COVERAGE=1 -D SHARED=0 -D STATIC=1 -D TESTS=1 .. ; fi - - if [ "$COMPILER" = "g++-4.9" ]; then cmake --build . ; fi - - if [ "$COMPILER" = "g++-4.9" ]; then ./bin/xlnt.test ; fi - - if [ "$COMPILER" = "g++-4.9" ]; then cd .. ; fi + - if [ "$COMPILER" = "g++-4.9" ]; then rm -rf ./* ; fi + - if [ "$COMPILER" = "g++-4.9" ]; then cmake -G "Unix Makefiles" -D DEBUG=1 -D COVERAGE=1 -D SHARED=0 -D STATIC=1 -D TESTS=1 .. ; fi + - if [ "$COMPILER" = "g++-4.9" ]; then make VERBOSE=1 ; fi + - if [ "$COMPILER" = "g++-4.9" ]; then cd .. && ./build/bin/xlnt.test ; fi - if [ "$COMPILER" = "g++-4.9" ]; then export OLDWD=$(pwd) ; fi - - if [ "$COMPILER" = "g++-4.9" ]; then cd "build/CMakeFiles/xlnt.static.dir$(pwd)" ; fi + - if [ "$COMPILER" = "g++-4.9" ]; then cd "build/CMakeFiles/xlnt.static.dir$(pwd)" ; pwd ; fi - if [ "$COMPILER" = "g++-4.9" ]; then coveralls --root $OLDWD --verbose -x ".cpp" --gcov-options '\-p' --exclude include --exclude third-party --exclude tests --exclude samples --exclude benchmarks ; fi diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 2d968c8b..551fb6f9 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include #include #include @@ -79,6 +80,8 @@ class XLNT_CLASS workbook public: using iterator = worksheet_iterator; using const_iterator = const_worksheet_iterator; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; static std::size_t index_from_ws_filename(const std::string &filename); @@ -141,6 +144,15 @@ public: const_iterator cbegin() const; const_iterator cend() const; + + reverse_iterator rbegin(); + reverse_iterator rend(); + + const_reverse_iterator rbegin() const; + const_reverse_iterator rend() const; + + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; std::vector get_sheet_names() const; diff --git a/include/xlnt/worksheet/cell_vector.hpp b/include/xlnt/worksheet/cell_vector.hpp index 917098d5..547787aa 100644 --- a/include/xlnt/worksheet/cell_vector.hpp +++ b/include/xlnt/worksheet/cell_vector.hpp @@ -48,6 +48,8 @@ class XLNT_CLASS cell_vector public: using iterator = cell_iterator; using const_iterator = const_cell_iterator; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row); @@ -80,6 +82,15 @@ public: const_iterator end() const; const_iterator cend() const; + reverse_iterator rbegin(); + reverse_iterator rend(); + + const_reverse_iterator rbegin() const; + const_reverse_iterator rend() const; + + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; + private: worksheet ws_; range_reference ref_; diff --git a/include/xlnt/worksheet/const_cell_iterator.hpp b/include/xlnt/worksheet/const_cell_iterator.hpp index b5cebe01..64ad84f0 100644 --- a/include/xlnt/worksheet/const_cell_iterator.hpp +++ b/include/xlnt/worksheet/const_cell_iterator.hpp @@ -46,7 +46,7 @@ public: const_cell_iterator(const const_cell_iterator &other); - const cell operator*(); + const cell operator*() const; bool operator==(const const_cell_iterator &other) const; diff --git a/include/xlnt/worksheet/const_range_iterator.hpp b/include/xlnt/worksheet/const_range_iterator.hpp index aa0b4843..640dfe7a 100644 --- a/include/xlnt/worksheet/const_range_iterator.hpp +++ b/include/xlnt/worksheet/const_range_iterator.hpp @@ -48,7 +48,7 @@ public: const_range_iterator(const const_range_iterator &other); - const cell_vector operator*(); + const cell_vector operator*() const; bool operator==(const const_range_iterator &other) const; diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index 6e6d7709..f764bc48 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -48,6 +48,8 @@ class XLNT_CLASS range public: using iterator = range_iterator; using const_iterator = const_range_iterator; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; range(worksheet ws, const range_reference &reference, major_order order = major_order::row, bool skip_null = false); @@ -83,6 +85,15 @@ public: const_iterator cbegin() const; const_iterator cend() const; + + reverse_iterator rbegin(); + reverse_iterator rend(); + + const_reverse_iterator rbegin() const; + const_reverse_iterator rend() const; + + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; private: worksheet ws_; diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index 14678bfc..4ee7b44b 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -23,6 +23,7 @@ // @author: see AUTHORS file #pragma once +#include #include #include #include @@ -66,6 +67,8 @@ class XLNT_CLASS worksheet public: using iterator = range_iterator; using const_iterator = const_range_iterator; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; worksheet(); worksheet(const worksheet &rhs); @@ -218,6 +221,15 @@ public: const_iterator cbegin() const; const_iterator cend() const; + + reverse_iterator rbegin(); + reverse_iterator rend(); + + const_reverse_iterator rbegin() const; + const_reverse_iterator rend() const; + + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; range iter_cells(bool skip_null); diff --git a/source/utils/tests/test_utf8string.hpp b/source/utils/tests/test_utf8string.hpp new file mode 100644 index 00000000..0e847bad --- /dev/null +++ b/source/utils/tests/test_utf8string.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include + +class test_utf8string : public CxxTest::TestSuite +{ +public: + void test_utf8() + { + auto utf8_valid = xlnt::utf8string::from_utf8("abc"); + auto utf8_invalid = xlnt::utf8string::from_utf8("\xc3\x28"); + + TS_ASSERT(utf8_valid.is_valid()); + TS_ASSERT(!utf8_invalid.is_valid()); + } + + void test_latin1() + { + auto latin1_valid = xlnt::utf8string::from_latin1("abc"); + TS_ASSERT(latin1_valid.is_valid()); + } + + void test_utf16() + { + auto utf16_valid = xlnt::utf8string::from_utf16("abc"); + TS_ASSERT(utf16_valid.is_valid()); + } + + void test_utf32() + { + auto utf32_valid = xlnt::utf8string::from_utf32("abc"); + TS_ASSERT(utf32_valid.is_valid()); + } +}; diff --git a/source/worksheet/cell_vector.cpp b/source/worksheet/cell_vector.cpp index 9d16543e..6ecd57ff 100644 --- a/source/worksheet/cell_vector.cpp +++ b/source/worksheet/cell_vector.cpp @@ -129,4 +129,34 @@ cell_vector::const_iterator cell_vector::end() const return cend(); } +cell_vector::reverse_iterator cell_vector::rbegin() +{ + return reverse_iterator(end()); +} + +cell_vector::reverse_iterator cell_vector::rend() +{ + return reverse_iterator(begin()); +} + +cell_vector::const_reverse_iterator cell_vector::crbegin() const +{ + return const_reverse_iterator(cend()); +} + +cell_vector::const_reverse_iterator cell_vector::rbegin() const +{ + return crbegin(); +} + +cell_vector::const_reverse_iterator cell_vector::crend() const +{ + return const_reverse_iterator(cbegin()); +} + +cell_vector::const_reverse_iterator cell_vector::rend() const +{ + return crend(); +} + } // namespace xlnt diff --git a/source/worksheet/const_cell_iterator.cpp b/source/worksheet/const_cell_iterator.cpp index 14b1e9b6..7258b5a0 100644 --- a/source/worksheet/const_cell_iterator.cpp +++ b/source/worksheet/const_cell_iterator.cpp @@ -89,4 +89,9 @@ const_cell_iterator const_cell_iterator::operator++(int) return old; } +const cell const_cell_iterator::operator*() const +{ + return ws_.get_cell(current_cell_); +} + } // namespace xlnt diff --git a/source/worksheet/const_range_iterator.cpp b/source/worksheet/const_range_iterator.cpp index 8a50edc8..dade7bb9 100644 --- a/source/worksheet/const_range_iterator.cpp +++ b/source/worksheet/const_range_iterator.cpp @@ -92,4 +92,18 @@ const_range_iterator const_range_iterator::operator++(int) return old; } +const cell_vector const_range_iterator::operator*() const +{ + if (order_ == major_order::row) + { + range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(), + range_.get_bottom_right().get_column_index(), current_cell_.get_row()); + return cell_vector(ws_, reference, order_); + } + + range_reference reference(current_cell_.get_column_index(), range_.get_top_left().get_row(), + current_cell_.get_column_index(), range_.get_bottom_right().get_row()); + return cell_vector(ws_, reference, order_); +} + } // namespace xlnt diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index c1e1ac4c..8b405b0f 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -172,4 +172,34 @@ range::const_iterator range::end() const return cend(); } +range::reverse_iterator range::rbegin() +{ + return reverse_iterator(end()); +} + +range::reverse_iterator range::rend() +{ + return reverse_iterator(begin()); +} + +range::const_reverse_iterator range::crbegin() const +{ + return const_reverse_iterator(cend()); +} + +range::const_reverse_iterator range::rbegin() const +{ + return crbegin(); +} + +range::const_reverse_iterator range::crend() const +{ + return const_reverse_iterator(cbegin()); +} + +range::const_reverse_iterator range::rend() const +{ + return crend(); +} + } // namespace xlnt diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 5d0e63d2..e5faddda 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include class test_worksheet : public CxxTest::TestSuite @@ -689,4 +692,100 @@ public: ws.append(std::vector { 4 }); TS_ASSERT_EQUALS(ws.get_highest_row(), 4); } + + void test_const_iterators() + { + xlnt::workbook wb; + xlnt::worksheet ws(wb); + + ws.append({"A1", "B1", "C1"}); + ws.append({"A2", "B2", "C2"}); + + const xlnt::worksheet ws_const = ws; + const auto rows = ws_const.rows(); + + const auto first_row = *rows.begin(); + const auto first_cell = *first_row.begin(); + TS_ASSERT_EQUALS(first_cell.get_value(), "A1"); + + const auto last_row = *(--rows.end()); + const auto last_cell = *(--last_row.end()); + TS_ASSERT_EQUALS(last_cell.get_value(), "C2"); + + for (const auto row : rows) + { + for (const auto cell : row) + { + TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + } + } + } + + void test_const_reverse_iterators() + { + xlnt::workbook wb; + xlnt::worksheet ws(wb); + + ws.append({"A1", "B1", "C1"}); + ws.append({"A2", "B2", "C2"}); + + const xlnt::worksheet ws_const = ws; + const auto rows = ws_const.rows(); + + const auto first_row = *rows.rbegin(); + const auto first_cell = *first_row.rbegin(); + TS_ASSERT_EQUALS(first_cell.get_value(), "C2"); + + const auto last_row = *(--rows.rend()); + const auto last_cell = *(--last_row.rend()); + TS_ASSERT_EQUALS(last_cell.get_value(), "A1"); + + for (auto ws_iter = rows.rbegin(); ws_iter != rows.rend(); ++ws_iter) + { + const auto row = *ws_iter; + + for (auto row_iter = row.rbegin(); row_iter != row.rend(); ++row_iter) + { + const auto cell = *row_iter; + TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + } + } + } + + void test_header() + { + xlnt::workbook wb; + auto ws = wb.get_active_sheet(); + TS_ASSERT(ws.get_header_footer().get_center_header().is_default()); + ws.get_header_footer().get_center_header().set_text("abc"); + ws.get_header_footer().get_center_header().set_font_name("def"); + ws.get_header_footer().get_center_header().set_font_size(121); + ws.get_header_footer().get_center_header().set_font_color("ghi"); + TS_ASSERT(!ws.get_header_footer().get_center_header().is_default()); + } + + void test_footer() + { + xlnt::workbook wb; + auto ws = wb.get_active_sheet(); + TS_ASSERT(ws.get_header_footer().get_center_footer().is_default()); + ws.get_header_footer().get_center_footer().set_text("abc"); + ws.get_header_footer().get_center_footer().set_font_name("def"); + ws.get_header_footer().get_center_footer().set_font_size(121); + ws.get_header_footer().get_center_footer().set_font_color("ghi"); + TS_ASSERT(!ws.get_header_footer().get_center_footer().is_default()); + } + + void test_page_setup() + { + xlnt::workbook wb; + auto ws = wb.get_active_sheet(); + TS_ASSERT(ws.get_page_setup().is_default()); + ws.get_page_setup().set_break(xlnt::page_break::column); + TS_ASSERT_EQUALS(ws.get_page_setup().get_break(), xlnt::page_break::column); + TS_ASSERT(!ws.get_page_setup().is_default()); + ws.get_page_setup().set_scale(1.23); + TS_ASSERT_EQUALS(ws.get_page_setup().get_scale(), 1.23); + TS_ASSERT(!ws.get_page_setup().is_default()); + } };