revert coverage calculation and work on coverage

This commit is contained in:
Thomas Fussell 2016-06-13 23:36:26 -04:00
parent cf72ea5d5d
commit 23f65602de
13 changed files with 267 additions and 11 deletions

View File

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

View File

@ -24,6 +24,7 @@
#pragma once
#include <functional>
#include <iterator>
#include <memory>
#include <string>
#include <unordered_map>
@ -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<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_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<std::string> get_sheet_names() const;

View File

@ -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<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_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_;

View File

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

View File

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

View File

@ -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<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_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_;

View File

@ -23,6 +23,7 @@
// @author: see AUTHORS file
#pragma once
#include <iterator>
#include <memory>
#include <string>
#include <unordered_map>
@ -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<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_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);

View File

@ -0,0 +1,36 @@
#pragma once
#include <cxxtest/TestSuite.h>
#include <xlnt/utils/utf8string.hpp>
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());
}
};

View File

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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,9 @@
#include <cxxtest/TestSuite.h>
#include <xlnt/serialization/worksheet_serializer.hpp>
#include <xlnt/worksheet/footer.hpp>
#include <xlnt/worksheet/header.hpp>
#include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/worksheet.hpp>
class test_worksheet : public CxxTest::TestSuite
@ -689,4 +692,100 @@ public:
ws.append(std::vector<int> { 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<std::string>(), "A1");
const auto last_row = *(--rows.end());
const auto last_cell = *(--last_row.end());
TS_ASSERT_EQUALS(last_cell.get_value<std::string>(), "C2");
for (const auto row : rows)
{
for (const auto cell : row)
{
TS_ASSERT_EQUALS(cell.get_value<std::string>(), 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<std::string>(), "C2");
const auto last_row = *(--rows.rend());
const auto last_cell = *(--last_row.rend());
TS_ASSERT_EQUALS(last_cell.get_value<std::string>(), "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<std::string>(), 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());
}
};