finish renaming test helpers and fix windows errors

This commit is contained in:
Thomas Fussell 2016-07-20 19:54:24 -04:00
parent 0c9bde91b7
commit 894c46c920
6 changed files with 43 additions and 44 deletions

View File

@ -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<unsigned char>();
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;

View File

@ -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<xlnt::datetime>(), 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<long double>(), float_value);

View File

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

View File

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

View File

@ -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<TCHAR, MAX_PATH> 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_;

View File

@ -7,10 +7,10 @@
#include <detail/include_windows.hpp>
#include <helpers/path_helper.hpp>
class TemporaryFile
class temporary_file
{
public:
static std::string CreateTemporaryFilename()
static std::string create()
{
#ifdef _MSC_VER
std::array<TCHAR, MAX_PATH> 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_;