From 894c46c920558ba8094ad9ecfbbd643e5c872772 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Wed, 20 Jul 2016 19:54:24 -0400 Subject: [PATCH] finish renaming test helpers and fix windows errors --- source/utils/tests/test_zip_file.hpp | 28 +++++++++---------- source/workbook/tests/test_workbook.hpp | 12 ++++---- source/workbook/tests/test_write.hpp | 14 +++++----- source/workbook/tests/test_write_workbook.hpp | 6 ++-- tests/helpers/temporary_directory.hpp | 12 ++++---- tests/helpers/temporary_file.hpp | 15 +++++----- 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/source/utils/tests/test_zip_file.hpp b/source/utils/tests/test_zip_file.hpp index cd1b1261..9e5c2acd 100644 --- a/source/utils/tests/test_zip_file.hpp +++ b/source/utils/tests/test_zip_file.hpp @@ -19,7 +19,7 @@ public: void remove_temp_file() { - std::remove(temp_file.GetFilename().c_str()); + std::remove(temp_file.get_filename().c_str()); } void make_temp_directory() @@ -54,8 +54,8 @@ public: { remove_temp_file(); xlnt::zip_file f(existing_file); - f.save(temp_file.GetFilename()); - TS_ASSERT(files_equal(existing_file, temp_file.GetFilename())); + f.save(temp_file.get_filename()); + TS_ASSERT(files_equal(existing_file, temp_file.get_filename())); remove_temp_file(); } @@ -65,10 +65,10 @@ public: { std::ifstream in_stream(existing_file, std::ios::binary); xlnt::zip_file f(in_stream); - std::ofstream out_stream(temp_file.GetFilename(), std::ios::binary); + std::ofstream out_stream(temp_file.get_filename(), std::ios::binary); f.save(out_stream); } - TS_ASSERT(files_equal(existing_file, temp_file.GetFilename())); + TS_ASSERT(files_equal(existing_file, temp_file.get_filename())); remove_temp_file(); } @@ -82,10 +82,10 @@ public: source_bytes.push_back((unsigned char)in_stream.get()); } xlnt::zip_file f(source_bytes); - f.save(temp_file.GetFilename()); + f.save(temp_file.get_filename()); xlnt::zip_file f2; - f2.load(temp_file.GetFilename()); + f2.load(temp_file.get_filename()); result_bytes = std::vector(); f2.save(result_bytes); @@ -229,9 +229,9 @@ public: auto text_file = path_helper::get_data_directory("/reader/sharedStrings.xml"); f.write(text_file); f.write(text_file, "sharedStrings2.xml"); - f.save(temp_file.GetFilename()); + f.save(temp_file.get_filename()); - xlnt::zip_file f2(temp_file.GetFilename()); + xlnt::zip_file f2(temp_file.get_filename()); for(auto &info : f2.infolist()) { @@ -258,9 +258,9 @@ public: info.filename = "b.txt"; info.date_time.year = 2014; f.writestr(info, "b\nb"); - f.save(temp_file.GetFilename()); + f.save(temp_file.get_filename()); - xlnt::zip_file f2(temp_file.GetFilename()); + xlnt::zip_file f2(temp_file.get_filename()); TS_ASSERT(f2.read("a.txt") == "a\na"); TS_ASSERT(f2.read(f2.getinfo("b.txt")) == "b\nb"); @@ -273,9 +273,9 @@ public: xlnt::zip_file f; f.comment = "comment"; - f.save(temp_file.GetFilename()); + f.save(temp_file.get_filename()); - xlnt::zip_file f2(temp_file.GetFilename()); + xlnt::zip_file f2(temp_file.get_filename()); TS_ASSERT(f2.comment == "comment"); xlnt::zip_file f3; @@ -305,7 +305,7 @@ public: } private: - TemporaryFile temp_file; + temporary_file temp_file; std::string existing_file; std::string expected_content_types_string; std::string expected_atxt_string; diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 14a1f891..477efc72 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -217,11 +217,11 @@ public: xlnt::workbook book; auto sheet = book.get_active_sheet(); sheet.get_cell("A1").set_value(today); - TemporaryFile temp_file; - book.save(temp_file.GetFilename()); + temporary_file temp_file; + book.save(temp_file.get_filename()); xlnt::workbook test_book; - test_book.load(temp_file.GetFilename()); + test_book.load(temp_file.get_filename()); auto test_sheet = test_book.get_active_sheet(); TS_ASSERT_EQUALS(test_sheet.get_cell("A1").get_value(), today); @@ -234,11 +234,11 @@ public: xlnt::workbook book; auto sheet = book.get_active_sheet(); sheet.get_cell("A1").set_value(float_value); - TemporaryFile temp_file; - book.save(temp_file.GetFilename()); + temporary_file temp_file; + book.save(temp_file.get_filename()); xlnt::workbook test_book; - test_book.load(temp_file.GetFilename()); + test_book.load(temp_file.get_filename()); auto test_sheet = test_book.get_active_sheet(); TS_ASSERT_EQUALS(test_sheet.get_cell("A1").get_value(), float_value); diff --git a/source/workbook/tests/test_write.hpp b/source/workbook/tests/test_write.hpp index 68ca6936..2e3bf34e 100644 --- a/source/workbook/tests/test_write.hpp +++ b/source/workbook/tests/test_write.hpp @@ -21,16 +21,16 @@ public: wbk.get_active_sheet().get_cell("A2").set_value("xlnt"); wbk.get_active_sheet().get_cell("B5").set_value(88); wbk.get_active_sheet().get_cell("B5").set_number_format(xlnt::number_format::percentage_00()); - wbk.save(temp_file.GetFilename()); + wbk.save(temp_file.get_filename()); - if(path_helper::file_exists(temp_file.GetFilename())) + if(path_helper::file_exists(temp_file.get_filename())) { - path_helper::delete_file(temp_file.GetFilename()); + path_helper::delete_file(temp_file.get_filename()); } - TS_ASSERT(!path_helper::file_exists(temp_file.GetFilename())); - wb_.save(temp_file.GetFilename()); - TS_ASSERT(path_helper::file_exists(temp_file.GetFilename())); + TS_ASSERT(!path_helper::file_exists(temp_file.get_filename())); + wb_.save(temp_file.get_filename()); + TS_ASSERT(path_helper::file_exists(temp_file.get_filename())); } void test_write_virtual_workbook() @@ -293,6 +293,6 @@ public: } private: - TemporaryFile temp_file; + temporary_file temp_file; xlnt::workbook wb_; }; diff --git a/source/workbook/tests/test_write_workbook.hpp b/source/workbook/tests/test_write_workbook.hpp index cc3ad379..0d3487e8 100644 --- a/source/workbook/tests/test_write_workbook.hpp +++ b/source/workbook/tests/test_write_workbook.hpp @@ -73,12 +73,12 @@ public: void test_write_empty_workbook() { xlnt::workbook wb; - TemporaryFile file; + temporary_file file; xlnt::excel_serializer serializer(wb); - serializer.save_workbook(file.GetFilename()); + serializer.save_workbook(file.get_filename()); - TS_ASSERT(path_helper::file_exists(file.GetFilename())); + TS_ASSERT(path_helper::file_exists(file.get_filename())); } void test_write_virtual_workbook() diff --git a/tests/helpers/temporary_directory.hpp b/tests/helpers/temporary_directory.hpp index 9d9a91d6..307e4a2b 100644 --- a/tests/helpers/temporary_directory.hpp +++ b/tests/helpers/temporary_directory.hpp @@ -8,10 +8,10 @@ #include "PathHelper.h" -class TemporaryDirectory +class temporary_directory { public: - static std::string CreateTemporaryFilename() + static std::string create() { #ifdef _WIN32 std::array buffer; @@ -25,23 +25,23 @@ public: throw std::runtime_error("GetTempPath failed"); } std::string directory(buffer.begin(), buffer.begin() + result); - return PathHelper::WindowsToUniversalPath(directory + "xlnt"); + return path_helper::windows_to_universal_path(directory + "xlnt"); #else return "/tmp/xlsx"; #endif } - TemporaryDirectory() : filename_(CreateTemporaryFilename()) + temporary_directory() : filename_(create()) { } - ~TemporaryDirectory() + ~temporary_directory() { remove(filename_.c_str()); } - std::string GetFilename() const { return filename_; } + std::string get_filename() const { return filename_; } private: const std::string filename_; diff --git a/tests/helpers/temporary_file.hpp b/tests/helpers/temporary_file.hpp index 1553f4fb..b710783d 100644 --- a/tests/helpers/temporary_file.hpp +++ b/tests/helpers/temporary_file.hpp @@ -7,10 +7,10 @@ #include #include -class TemporaryFile +class temporary_file { public: - static std::string CreateTemporaryFilename() + static std::string create() { #ifdef _MSC_VER std::array buffer; @@ -27,27 +27,26 @@ public: } std::string directory(buffer.begin(), buffer.begin() + result); - - return PathHelper::WindowsToUniversalPath(directory + "xlnt.xlsx"); + return path_helper::windows_to_universal_path(directory + "xlnt.xlsx"); #else return "/tmp/xlnt.xlsx"; #endif } - TemporaryFile() : filename_(CreateTemporaryFilename()) + temporary_file() : filename_(create()) { - if(path_helper::file_exists(GetFilename())) + if(path_helper::file_exists(get_filename())) { std::remove(filename_.c_str()); } } - ~TemporaryFile() + ~temporary_file() { std::remove(filename_.c_str()); } - std::string GetFilename() const { return filename_; } + std::string get_filename() const { return filename_; } private: const std::string filename_;