From 51db47e2a82ce2a0c62b96a5b2b1760bcc7b90b4 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sat, 23 Jul 2016 19:43:24 -0400 Subject: [PATCH] test workbook and fix mising template specialization --- include/xlnt/workbook/workbook.hpp | 5 +--- source/cell/cell.cpp | 10 +++++-- source/detail/excel_serializer.cpp | 2 +- source/detail/workbook_serializer.cpp | 2 +- source/workbook/tests/test_workbook.hpp | 22 ++++++++++++++ source/workbook/workbook.cpp | 39 ++----------------------- 6 files changed, 35 insertions(+), 45 deletions(-) diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 99a80b0d..eb323fc2 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -124,7 +124,6 @@ public: worksheet create_sheet(std::size_t index); worksheet create_sheet(const std::string &title); worksheet create_sheet(std::size_t index, const std::string &title); - worksheet create_sheet(const std::string &title, const relationship &rel); void copy_sheet(worksheet worksheet); void copy_sheet(worksheet worksheet, std::size_t index); @@ -237,10 +236,8 @@ public: const format &get_format(std::size_t format_index) const; std::size_t add_format(const format &new_format); void clear_formats(); - std::vector &get_formats(); - const std::vector &get_formats() const; - // named styles + // styles bool has_style(const std::string &name) const; style &get_style(const std::string &name); diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index fc818e4e..be0385f8 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -781,9 +781,15 @@ XLNT_FUNCTION std::uint64_t cell::get_value() const #ifdef __linux template <> -XLNT_FUNCTION long long int cell::get_value() const +XLNT_FUNCTION long long cell::get_value() const { - return static_cast(d_->value_numeric_); + return static_cast(d_->value_numeric_); +} + +template <> +XLNT_FUNCTION unsigned long long cell::get_value() const +{ + return static_cast(d_->value_numeric_); } #endif diff --git a/source/detail/excel_serializer.cpp b/source/detail/excel_serializer.cpp index 2eb5b358..bb7193d9 100644 --- a/source/detail/excel_serializer.cpp +++ b/source/detail/excel_serializer.cpp @@ -158,7 +158,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl continue; } - auto ws = wb.create_sheet(sheet_node.attribute("name").value(), rel); + auto ws = wb.create_sheet(sheet_node.attribute("name").value()); xlnt::worksheet_serializer worksheet_serializer(ws); pugi::xml_document worksheet_xml; worksheet_xml.load(archive.read("xl/" + rel.get_target_uri()).c_str()); diff --git a/source/detail/workbook_serializer.cpp b/source/detail/workbook_serializer.cpp index ed1378d7..2ee5586d 100644 --- a/source/detail/workbook_serializer.cpp +++ b/source/detail/workbook_serializer.cpp @@ -190,7 +190,7 @@ void workbook_serializer::write_properties_app(pugi::xml_document &xml) const root_node.append_attribute("xmlns").set_value("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"); root_node.append_attribute("xmlns:vt").set_value("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); - auto &properties = workbook_.get_app_properties(); + const auto &properties = workbook_.get_app_properties(); root_node.append_child("Application").text().set(properties.application.c_str()); root_node.append_child("DocSecurity").text().set(std::to_string(properties.doc_security).c_str()); diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 97acd01a..05058316 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -103,6 +103,7 @@ public: new_sheet.set_title(title); auto found_sheet = wb.get_sheet_by_name(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); + TS_ASSERT_THROWS(wb.get_sheet_by_name("error"), xlnt::key_error); } void test_get_sheet_by_name_const() @@ -348,4 +349,25 @@ public: wb.clear(); TS_ASSERT(wb.get_sheet_names().empty()); } + + void test_comparison() + { + xlnt::workbook wb, wb2; + TS_ASSERT(wb == wb); + TS_ASSERT(!(wb != wb)); + TS_ASSERT(!(wb == wb2)); + TS_ASSERT(wb != wb2) + + const auto &wb_const = wb; + //TODO these aren't tests... + wb_const.get_app_properties(); + wb_const.get_manifest(); + + TS_ASSERT(!wb.has_loaded_theme()); + + wb.create_style("style1"); + wb.get_style("style1"); + wb_const.get_style("style1"); + wb.get_style_by_id(0); + } }; diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index bb4f2ce8..84f982cc 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -210,13 +210,7 @@ void workbook::create_named_range(const std::string &name, worksheet range_owner void workbook::create_named_range(const std::string &name, worksheet range_owner, const range_reference &reference) { - auto match = get_sheet_by_name(range_owner.get_title()); - if (match != nullptr) - { - match.create_named_range(name, reference); - return; - } - throw std::runtime_error("worksheet isn't owned by this workbook"); + get_sheet_by_name(range_owner.get_title()).create_named_range(name, reference); } void workbook::remove_named_range(const std::string &name) @@ -350,20 +344,6 @@ std::size_t workbook::index_from_ws_filename(const std::string &ws_filename) return sheet_index; } -worksheet workbook::create_sheet(const std::string &title, const relationship &rel) -{ - d_->worksheets_.push_back(detail::worksheet_impl(this, title)); - - auto index = index_from_ws_filename(rel.get_target_uri()); - if (index != d_->worksheets_.size() - 1) - { - std::swap(d_->worksheets_.back(), d_->worksheets_[index]); - d_->worksheets_.pop_back(); - } - - return worksheet(&d_->worksheets_[index]); -} - worksheet workbook::create_sheet(std::size_t index, const std::string &title) { auto ws = create_sheet(index); @@ -458,12 +438,7 @@ worksheet workbook::operator[](const std::string &name) worksheet workbook::operator[](std::size_t index) { - if (index > d_->worksheets_.size()) - { - throw key_error(); - } - - return worksheet(&d_->worksheets_[index]); + return worksheet(&d_->worksheets_.at(index)); } void workbook::clear() @@ -762,16 +737,6 @@ style &workbook::create_style(const std::string &name) return d_->stylesheet_.styles.back(); } -std::vector &workbook::get_formats() -{ - return d_->stylesheet_.formats; -} - -const std::vector &workbook::get_formats() const -{ - return d_->stylesheet_.formats; -} - style &workbook::get_style(const std::string &name) { return *std::find_if(d_->stylesheet_.styles.begin(), d_->stylesheet_.styles.end(),