diff --git a/python/python_streambuf.hpp b/python/python_streambuf.hpp index 6ddc0674..38a23ed0 100644 --- a/python/python_streambuf.hpp +++ b/python/python_streambuf.hpp @@ -310,7 +310,7 @@ class python_streambuf : public std::basic_streambuf upper_bound = reinterpret_cast(farthest_pptr) + 1; } else { - throw std::runtime_error("unreachable"); + throw xlnt::exception("unreachable"); } // Sought position in "buffer coordinate" @@ -325,7 +325,7 @@ class python_streambuf : public std::basic_streambuf return failure; } else { - throw std::runtime_error("unreachable"); + throw xlnt::exception("unreachable"); } // if the sought position is not in the buffer, give up diff --git a/python/xlntpyarrow.lib.cpp b/python/xlntpyarrow.lib.cpp index 230cd8e2..14c90271 100644 --- a/python/xlntpyarrow.lib.cpp +++ b/python/xlntpyarrow.lib.cpp @@ -38,7 +38,7 @@ void import_pyarrow() { if (arrow::py::import_pyarrow() != 0) { - throw std::runtime_error("Import of pyarrow failed."); + throw xlnt::exception("Import of pyarrow failed."); } imported = true; @@ -156,7 +156,7 @@ arrow::ArrayBuilder *make_array_builder(arrow::Type::type type) break; */ default: - throw std::runtime_error("not implemented"); + throw xlnt::exception("not implemented"); } return builder; @@ -322,7 +322,7 @@ void append_cell_value(arrow::ArrayBuilder *builder, arrow::Type::type type, xln break; */ default: - throw std::runtime_error("not implemented"); + throw xlnt::exception("not implemented"); } } diff --git a/samples/img2xlsx.cpp b/samples/img2xlsx.cpp index 416d4b0e..74c67106 100644 --- a/samples/img2xlsx.cpp +++ b/samples/img2xlsx.cpp @@ -59,7 +59,7 @@ pixmap load_image(const std::string &filename) if (image_data == nullptr) { - throw std::runtime_error("bad image or file not found: " + filename); + throw xlnt::exception("bad image or file not found: " + filename); } pixmap result; @@ -99,8 +99,8 @@ xlnt::workbook build_workbook_cf(const pixmap &image) // The reference to the cell which is being operated upon auto current_cell = xlnt::cell_reference("A1"); // The range of cells which will be modified. This is required for conditional formats - auto range = ws.range(xlnt::range_reference(1, 1, - static_cast(image[0].size()), + auto range = ws.range(xlnt::range_reference(1, 1, + static_cast(image[0].size()), static_cast(image.size()))); // Track the previously created conditonal formats so they are only created once @@ -119,7 +119,7 @@ xlnt::workbook build_workbook_cf(const pixmap &image) if (defined_colors.count(color.hex_string()) == 0) { // The condition under which the conditional format applies to a cell - // In this case, the condition is satisfied when the text of the cell + // In this case, the condition is satisfied when the text of the cell // contains the hex string representing the pixel color. const auto condition = xlnt::condition::text_contains(color.hex_string()); // Create a new conditional format with the above condition on the image pixel range @@ -144,7 +144,7 @@ xlnt::workbook build_workbook_cf(const pixmap &image) // Show some progress, it can take a while... std::cout << current_cell.row() << " " << defined_colors.size() << std::endl; } - + // Return the resulting workbook return wb; } diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index 1e47202f..6a0545a3 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -323,7 +323,9 @@ bool cell::is_merged() const bool cell::is_date() const { - return data_type() == type::number && has_format() && number_format().is_date_format(); + return data_type() == type::number + && has_format() + && number_format().is_date_format(); } cell_reference cell::reference() const @@ -364,7 +366,8 @@ std::string cell::hyperlink() const void cell::hyperlink(const std::string &hyperlink) { - if (hyperlink.length() == 0 || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end()) + if (hyperlink.length() == 0 + || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end()) { throw invalid_parameter(); } @@ -400,7 +403,7 @@ void cell::formula(const std::string &formula) } data_type(type::number); - + worksheet().register_calc_chain_in_manifest(); } diff --git a/source/cell/cell_reference.cpp b/source/cell/cell_reference.cpp index 159af274..42bea3fc 100644 --- a/source/cell/cell_reference.cpp +++ b/source/cell/cell_reference.cpp @@ -66,7 +66,10 @@ cell_reference::cell_reference(const char *reference_string) cell_reference::cell_reference(column_t column_index, row_t row) : column_(column_index), row_(row), absolute_row_(false), absolute_column_(false) { - if (row_ == 0 || column_ == 0 || !(row_ <= constants::max_row()) || !(column_ <= constants::max_column())) + if (row_ == 0 + || column_ == 0 + || !(row_ <= constants::max_row()) + || !(column_ <= constants::max_column())) { throw invalid_cell_reference(column_, row_); } @@ -264,12 +267,15 @@ cell_reference cell_reference::make_offset(int column_offset, int row_offset) co // TODO: check for overflow/underflow auto relative_column = static_cast(static_cast(column_.index) + column_offset); auto relative_row = static_cast(static_cast(row_) + row_offset); + return cell_reference(relative_column, relative_row); } bool cell_reference::operator==(const cell_reference &comparand) const { - return comparand.column_ == column_ && comparand.row_ == row_ && absolute_column_ == comparand.absolute_column_ + return comparand.column_ == column_ + && comparand.row_ == row_ + && absolute_column_ == comparand.absolute_column_ && absolute_row_ == comparand.absolute_row_; } diff --git a/source/detail/constants.cpp b/source/detail/constants.cpp index af6928e4..759511eb 100644 --- a/source/detail/constants.cpp +++ b/source/detail/constants.cpp @@ -54,22 +54,27 @@ const path constants::package_properties() { return path("docProps"); } + const path constants::package_xl() { return path("/xl"); } + const path constants::package_root_rels() { return path(std::string("_rels")); } + const path constants::package_theme() { return package_xl().append("theme"); } + const path constants::package_worksheets() { return package_xl().append("worksheets"); } + const path constants::package_drawings() { return package_xl().append("drawings"); @@ -79,30 +84,37 @@ const path constants::part_content_types() { return path("[Content_Types].xml"); } + const path constants::part_root_relationships() { return package_root_rels().append(".rels"); } + const path constants::part_core() { return package_properties().append("core.xml"); } + const path constants::part_app() { return package_properties().append("app.xml"); } + const path constants::part_workbook() { return package_xl().append("workbook.xml"); } + const path constants::part_styles() { return package_xl().append("styles.xml"); } + const path constants::part_theme() { return package_theme().append("theme1.xml"); } + const path constants::part_shared_strings() { return package_xl().append("sharedStrings.xml"); @@ -140,7 +152,8 @@ const std::unordered_map &constants::namespaces() {"xml", "http://www.w3.org/XML/1998/namespace"}, {"xsi", "http://www.w3.org/2001/XMLSchema-instance"}, - {"loext", "http://schemas.libreoffice.org/"}}; + {"loext", "http://schemas.libreoffice.org/"} + }; return *namespaces; } @@ -156,4 +169,5 @@ const std::string &constants::ns(const std::string &id) return match->second; } -} + +} // namespace xlnt diff --git a/source/detail/cryptography/aes.cpp b/source/detail/cryptography/aes.cpp index 7569c82f..d88c66ba 100644 --- a/source/detail/cryptography/aes.cpp +++ b/source/detail/cryptography/aes.cpp @@ -31,7 +31,8 @@ #include #include -#include "aes.hpp" +#include +#include namespace { @@ -959,7 +960,9 @@ rijndael_key rijndael_setup(const std::vector &key_data) if (key_data.size() != 16 && key_data.size() != 24 && key_data.size() != 32) { - throw std::runtime_error(""); + throw xlnt::exception("Invalid AES key length (" + + std::to_string(key_data.size()) + + " bytes). Must be 16, 24 or 32 bytes."); } skey.Nr = 10 + ((static_cast(key_data.size())/8)-2)*2; @@ -1029,8 +1032,6 @@ rijndael_key rijndael_setup(const std::vector &key_data) rk[15] = rk[ 7] ^ rk[14]; rk += 8; } - } else { - throw std::runtime_error(""); } /* setup the inverse key now */ @@ -1347,7 +1348,9 @@ std::vector aes_ecb_encrypt( if (len % 16 != 0) { - throw std::runtime_error(""); + throw xlnt::exception("Invalid ECB plaintext length (" + + std::to_string(len) + + " bytes). Must be a multiple of 16 bytes."); } auto ciphertext = std::vector(len); @@ -1378,7 +1381,9 @@ std::vector aes_ecb_decrypt( if (len % 16 != 0) { - throw std::runtime_error(""); + throw xlnt::exception("Invalid ECB ciphertext length (" + + std::to_string(len) + + " bytes). Must be a multiple of 16 bytes."); } auto plaintext = std::vector(len); @@ -1410,7 +1415,9 @@ std::vector aes_cbc_encrypt( if (len % 16 != 0) { - throw std::runtime_error(""); + throw xlnt::exception("Invalid CBC plaintext length (" + + std::to_string(len) + + " bytes). Must be a multiple of 16 bytes."); } auto ciphertext = std::vector(len); @@ -1454,7 +1461,9 @@ std::vector aes_cbc_decrypt( if (ciphertext.size() % 16 != 0) { - throw std::runtime_error(""); + throw xlnt::exception("Invalid ECB ciphertext length (" + + std::to_string(len) + + " bytes). Must be a multiple of 16 bytes."); } std::array temporary{{0}}; diff --git a/source/detail/cryptography/base64.cpp b/source/detail/cryptography/base64.cpp index 33f2820e..90c7a83e 100644 --- a/source/detail/cryptography/base64.cpp +++ b/source/detail/cryptography/base64.cpp @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include #include namespace xlnt { @@ -31,15 +32,15 @@ std::string encode_base64(const std::vector &input) auto output = std::string(encoded_length, '\0'); auto input_iterator = input.begin(); auto output_iterator = output.begin(); - - int i = 0, j = 0; - unsigned char a3[3]; - unsigned char a4[4]; - - const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - + auto i = std::size_t(0); + auto j = std::size_t(0); + std::array a3{{0}}; + std::array a4{{0}}; + + const std::string alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"); + while (input_iterator != input.end()) { a3[i++] = *input_iterator++; @@ -47,60 +48,68 @@ std::string encode_base64(const std::vector &input) if (i == 3) { a4[0] = (a3[0] & 0xfc) >> 2; - a4[1] = static_cast(((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4)); - a4[2] = static_cast(((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6)); + a4[1] = static_cast(((a3[0] & 0x03) << 4) + + ((a3[1] & 0xf0) >> 4)); + a4[2] = static_cast(((a3[1] & 0x0f) << 2) + + ((a3[2] & 0xc0) >> 6)); a4[3] = (a3[2] & 0x3f); - + for (i = 0; i < 4; i++) { - *output_iterator++ = kBase64Alphabet[a4[i]]; + *output_iterator++ = alphabet[a4[i]]; } - + i = 0; } } - - if (i) + + if (i != 0) { for (j = i; j < 3; j++) { - a3[j] = '\0'; + a3[j] = 0; } - + a4[0] = (a3[0] & 0xfc) >> 2; - a4[1] = static_cast(((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4)); - a4[2] = static_cast(((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6)); + a4[1] = static_cast(((a3[0] & 0x03) << 4) + + ((a3[1] & 0xf0) >> 4)); + a4[2] = static_cast(((a3[1] & 0x0f) << 2) + + ((a3[2] & 0xc0) >> 6)); a4[3] = (a3[2] & 0x3f); - + for (j = 0; j < i + 1; j++) { - *output_iterator++ = kBase64Alphabet[a4[j]]; + *output_iterator++ = alphabet[a4[j]]; } - - while ((i++ < 3)) + + while (i++ < 3) { *output_iterator++ = '='; } } - + return output; } std::vector decode_base64(const std::string &input) { - std::size_t numEq = 0; + std::size_t padding_count = 0; auto in_end = input.data() + input.size(); - while (*--in_end == '=') ++numEq; - auto decoded_length = ((6 * input.size()) / 8) - numEq; + + while (*--in_end == '=') + { + ++padding_count; + } + + auto decoded_length = ((6 * input.size()) / 8) - padding_count; auto output = std::vector(decoded_length); - auto input_iterator = input.begin(); auto output_iterator = output.begin(); - - int i = 0, j = 0; - std::uint8_t a3[3]; - std::uint8_t a4[4]; - + auto i = std::size_t(0); + auto j = std::size_t(0); + std::array a3{{0}}; + std::array a4{{0}}; + auto b64_lookup = [](std::uint8_t c) -> std::uint8_t { if(c >='A' && c <='Z') return c - 'A'; @@ -110,58 +119,64 @@ std::vector decode_base64(const std::string &input) if(c == '/') return 63; return 255; }; - + while (input_iterator != input.end()) { if (*input_iterator == '=') { break; } - + a4[i++] = static_cast(*(input_iterator++)); if (i == 4) { - for (i = 0; i <4; i++) + for (i = 0; i < 4; i++) { a4[i] = b64_lookup(a4[i]); } - - a3[0] = static_cast(a4[0] << 2) + static_cast((a4[1] & 0x30) >> 4); - a3[1] = static_cast((a4[1] & 0xf) << 4) + static_cast((a4[2] & 0x3c) >> 2); - a3[2] = static_cast((a4[2] & 0x3) << 6) + static_cast(a4[3]); - + + a3[0] = static_cast(a4[0] << 2) + + static_cast((a4[1] & 0x30) >> 4); + a3[1] = static_cast((a4[1] & 0xf) << 4) + + static_cast((a4[2] & 0x3c) >> 2); + a3[2] = static_cast((a4[2] & 0x3) << 6) + + static_cast(a4[3]); + for (i = 0; i < 3; i++) { *output_iterator++ = a3[i]; } - + i = 0; } } - - if (i) + + if (i != 0) { for (j = i; j < 4; j++) { - a4[j] = '\0'; + a4[j] = 0; } - + for (j = 0; j < 4; j++) { a4[j] = b64_lookup(a4[j]); } - - a3[0] = static_cast(a4[0] << 2) + static_cast((a4[1] & 0x30) >> 4); - a3[1] = static_cast((a4[1] & 0xf) << 4) + static_cast((a4[2] & 0x3c) >> 2); - a3[2] = static_cast((a4[2] & 0x3) << 6) + static_cast(a4[3]); - + + a3[0] = static_cast(a4[0] << 2) + + static_cast((a4[1] & 0x30) >> 4); + a3[1] = static_cast((a4[1] & 0xf) << 4) + + static_cast((a4[2] & 0x3c) >> 2); + a3[2] = static_cast((a4[2] & 0x3) << 6) + + static_cast(a4[3]); + for (j = 0; j < i - 1; j++) { *output_iterator++ = a3[j]; } } - + return output; } diff --git a/source/detail/cryptography/compound_document.cpp b/source/detail/cryptography/compound_document.cpp index 9a48cd27..3815f17b 100644 --- a/source/detail/cryptography/compound_document.cpp +++ b/source/detail/cryptography/compound_document.cpp @@ -21,7 +21,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + #include #include #include @@ -45,6 +45,7 @@ int compare_keys(const std::string &left, const std::string &right) { static const auto *locale = new std::locale(); std::use_facet>(*locale).tolower(&s[0], &s[0] + s.size()); + return s; }; @@ -112,7 +113,7 @@ public: compound_document_istreambuf(const compound_document_istreambuf &) = delete; compound_document_istreambuf &operator=(const compound_document_istreambuf &) = delete; - + ~compound_document_istreambuf() override; private: @@ -135,7 +136,7 @@ private: document_.read_short_sector(current_sector, sector_writer_); } - const auto available = std::min(entry_.size - position_, + const auto available = std::min(entry_.size - position_, document_.short_sector_size() - position_ % document_.short_sector_size()); const auto to_read = std::min(available, std::size_t(remaining)); @@ -402,14 +403,14 @@ private: chain_.push_back(next_sector); document_.write_sat(); } - + auto value = static_cast(c); if (c != traits_type::eof()) { current_sector_[position_ % current_sector_.size()] = value; } - + pbump(1); return traits_type::to_int_type(static_cast(value)); @@ -641,7 +642,7 @@ void compound_document::read_short_sector(sector_id id, binary_writer &writer const auto container_chain = follow_chain(entries_[0].start, sat_); auto container = std::vector(); auto container_writer = binary_writer(container); - + for (auto sector : container_chain) { read_sector(sector, container_writer); @@ -677,7 +678,7 @@ sector_id compound_document::allocate_sector() { const auto sectors_per_sector = sector_size() / sizeof(sector_id); auto next_free_iter = std::find(sat_.begin(), sat_.end(), FreeSector); - + if (next_free_iter == sat_.end()) { auto next_msat_index = header_.num_msat_sectors; @@ -699,16 +700,16 @@ sector_id compound_document::allocate_sector() next_free_iter = std::find(sat_.begin(), sat_.end(), FreeSector); } - + auto next_free = sector_id(next_free_iter - sat_.begin()); sat_[static_cast(next_free)] = EndOfChain; write_sat(); - + auto empty_sector = std::vector(sector_size()); auto empty_sector_reader = binary_reader(empty_sector); write_sector(empty_sector_reader, next_free); - + return next_free; } @@ -726,7 +727,7 @@ sector_chain compound_document::allocate_sectors(std::size_t count) sat_[static_cast(current)] = next; current = next; } - + chain.push_back(current); write_sat(); @@ -761,7 +762,7 @@ sector_chain compound_document::allocate_short_sectors(std::size_t count) ssat_[static_cast(current)] = next; current = next; } - + chain.push_back(current); write_ssat(); @@ -772,11 +773,11 @@ sector_id compound_document::allocate_short_sector() { const auto sectors_per_sector = sector_size() / sizeof(sector_id); auto next_free_iter = std::find(ssat_.begin(), ssat_.end(), FreeSector); - + if (next_free_iter == ssat_.end()) { auto new_ssat_sector_id = allocate_sector(); - + if (header_.ssat_start < 0) { header_.ssat_start = new_ssat_sector_id; @@ -787,9 +788,9 @@ sector_id compound_document::allocate_short_sector() sat_[static_cast(ssat_chain.back())] = new_ssat_sector_id; write_sat(); } - + write_header(); - + auto old_size = ssat_.size(); ssat_.resize(old_size + sectors_per_sector, FreeSector); @@ -807,10 +808,10 @@ sector_id compound_document::allocate_short_sector() ssat_[static_cast(next_free)] = EndOfChain; write_ssat(); - + const auto short_sectors_per_sector = sector_size() / short_sector_size(); const auto required_container_sectors = static_cast(next_free) / short_sectors_per_sector + std::size_t(1); - + if (required_container_sectors > 0) { if (entries_[0].start < 0) @@ -818,16 +819,16 @@ sector_id compound_document::allocate_short_sector() entries_[0].start = allocate_sector(); write_entry(0); } - + auto container_chain = follow_chain(entries_[0].start, sat_); - + if (required_container_sectors > container_chain.size()) { sat_[static_cast(container_chain.back())] = allocate_sector(); write_sat(); } } - + return next_free; } @@ -858,7 +859,7 @@ directory_id compound_document::next_empty_entry() write_sat(); } - const auto entries_per_sector = sector_size() + const auto entries_per_sector = sector_size() / sizeof(compound_document_entry); for (auto i = std::size_t(0); i < entries_per_sector; ++i) diff --git a/source/detail/number_format/number_formatter.cpp b/source/detail/number_format/number_formatter.cpp index d7497320..5b533ee9 100644 --- a/source/detail/number_format/number_formatter.cpp +++ b/source/detail/number_format/number_formatter.cpp @@ -143,7 +143,7 @@ void number_format_parser::parse() { if (section.has_color || section.has_condition || section.has_locale || !section.parts.empty()) { - throw std::runtime_error("color should be the first part of a format"); + throw xlnt::exception("color should be the first part of a format"); } section.has_color = true; @@ -156,7 +156,7 @@ void number_format_parser::parse() { if (section.has_locale) { - throw std::runtime_error("multiple locales"); + throw xlnt::exception("multiple locales"); } section.has_locale = true; @@ -178,7 +178,7 @@ void number_format_parser::parse() { if (section.has_condition) { - throw std::runtime_error("multiple conditions"); + throw xlnt::exception("multiple conditions"); } section.has_condition = true; @@ -623,12 +623,12 @@ number_format_token number_format_parser::parse_next_token() case '[': if (position_ == format_string_.size()) { - throw std::runtime_error("missing ]"); + throw xlnt::exception("missing ]"); } if (format_string_[position_] == ']') { - throw std::runtime_error("empty []"); + throw xlnt::exception("empty []"); } do @@ -670,7 +670,7 @@ number_format_token number_format_parser::parse_next_token() case 'G': if (format_string_.substr(position_ - 1, 7) != "General") { - throw std::runtime_error("expected General"); + throw xlnt::exception("expected General"); } token.type = number_format_token::token_type::number; @@ -744,7 +744,7 @@ number_format_token number_format_parser::parse_next_token() } else { - throw std::runtime_error("expected AM/PM or A/P"); + throw xlnt::exception("expected AM/PM or A/P"); } break; @@ -839,7 +839,7 @@ number_format_token number_format_parser::parse_next_token() break; default: - throw std::runtime_error("unexpected character"); + throw xlnt::exception("unexpected character"); } return token; @@ -849,14 +849,14 @@ void number_format_parser::validate() { if (codes_.size() > 4) { - throw std::runtime_error("too many format codes"); + throw xlnt::exception("too many format codes"); } if (codes_.size() > 2) { if (codes_[0].has_condition && codes_[1].has_condition && codes_[2].has_condition) { - throw std::runtime_error("format should have a maximum of two codes with conditions"); + throw xlnt::exception("format should have a maximum of two codes with conditions"); } } } @@ -1029,7 +1029,7 @@ std::pair number_format_parser::locale_from_string(c if (locale_string.empty() || locale_string.front() != '$' || hyphen_index == std::string::npos) { - throw std::runtime_error("bad locale: " + locale_string); + throw xlnt::exception("bad locale: " + locale_string); } std::pair result; @@ -1043,14 +1043,14 @@ std::pair number_format_parser::locale_from_string(c if (country_code_string.empty()) { - throw std::runtime_error("bad locale: " + locale_string); + throw xlnt::exception("bad locale: " + locale_string); } for (auto c : country_code_string) { if (!((c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9'))) { - throw std::runtime_error("bad locale: " + locale_string); + throw xlnt::exception("bad locale: " + locale_string); } } @@ -1065,7 +1065,7 @@ std::pair number_format_parser::locale_from_string(c } } - throw std::runtime_error("unknown country code: " + country_code_string); + throw xlnt::exception("unknown country code: " + country_code_string); } number_formatter::number_formatter(const std::string &format_string, xlnt::calendar calendar) diff --git a/tests/helpers/path_helper.hpp b/tests/helpers/path_helper.hpp index 1ec6e5cc..6d0e1ee2 100644 --- a/tests/helpers/path_helper.hpp +++ b/tests/helpers/path_helper.hpp @@ -57,17 +57,17 @@ public: { return sample_data_directory().append(xlnt::path(filename)); } - + static void copy_file(const xlnt::path &source, const xlnt::path &destination, bool overwrite) { if(!overwrite && destination.exists()) { - throw std::runtime_error("destination file already exists and overwrite==false"); + throw xlnt::exception("destination file already exists and overwrite==false"); } - + std::ifstream src(source.string(), std::ios::binary); std::ofstream dst(destination.string(), std::ios::binary); - + dst << src.rdbuf(); } diff --git a/tests/helpers/temporary_directory.hpp b/tests/helpers/temporary_directory.hpp index 307e4a2b..da42bf5c 100644 --- a/tests/helpers/temporary_directory.hpp +++ b/tests/helpers/temporary_directory.hpp @@ -18,11 +18,11 @@ public: DWORD result = GetTempPath(static_cast(buffer.size()), buffer.data()); if(result > MAX_PATH) { - throw std::runtime_error("buffer is too small"); + throw xlnt::exception("buffer is too small"); } if(result == 0) { - throw std::runtime_error("GetTempPath failed"); + throw xlnt::exception("GetTempPath failed"); } std::string directory(buffer.begin(), buffer.begin() + result); return path_helper::windows_to_universal_path(directory + "xlnt"); diff --git a/tests/utils/helper_test_suite.hpp b/tests/utils/helper_test_suite.hpp index 3f504a10..61180438 100644 --- a/tests/utils/helper_test_suite.hpp +++ b/tests/utils/helper_test_suite.hpp @@ -46,7 +46,7 @@ public: { auto function_that_throws = []() { - throw std::runtime_error("test"); + throw xlnt::exception("test"); }; auto function_that_doesnt_throw = []()