mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
finish renaming test helpers and fix windows errors
This commit is contained in:
parent
0c9bde91b7
commit
894c46c920
|
@ -19,7 +19,7 @@ public:
|
||||||
|
|
||||||
void remove_temp_file()
|
void remove_temp_file()
|
||||||
{
|
{
|
||||||
std::remove(temp_file.GetFilename().c_str());
|
std::remove(temp_file.get_filename().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void make_temp_directory()
|
void make_temp_directory()
|
||||||
|
@ -54,8 +54,8 @@ public:
|
||||||
{
|
{
|
||||||
remove_temp_file();
|
remove_temp_file();
|
||||||
xlnt::zip_file f(existing_file);
|
xlnt::zip_file f(existing_file);
|
||||||
f.save(temp_file.GetFilename());
|
f.save(temp_file.get_filename());
|
||||||
TS_ASSERT(files_equal(existing_file, temp_file.GetFilename()));
|
TS_ASSERT(files_equal(existing_file, temp_file.get_filename()));
|
||||||
remove_temp_file();
|
remove_temp_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +65,10 @@ public:
|
||||||
{
|
{
|
||||||
std::ifstream in_stream(existing_file, std::ios::binary);
|
std::ifstream in_stream(existing_file, std::ios::binary);
|
||||||
xlnt::zip_file f(in_stream);
|
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);
|
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();
|
remove_temp_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +82,10 @@ public:
|
||||||
source_bytes.push_back((unsigned char)in_stream.get());
|
source_bytes.push_back((unsigned char)in_stream.get());
|
||||||
}
|
}
|
||||||
xlnt::zip_file f(source_bytes);
|
xlnt::zip_file f(source_bytes);
|
||||||
f.save(temp_file.GetFilename());
|
f.save(temp_file.get_filename());
|
||||||
|
|
||||||
xlnt::zip_file f2;
|
xlnt::zip_file f2;
|
||||||
f2.load(temp_file.GetFilename());
|
f2.load(temp_file.get_filename());
|
||||||
result_bytes = std::vector<unsigned char>();
|
result_bytes = std::vector<unsigned char>();
|
||||||
f2.save(result_bytes);
|
f2.save(result_bytes);
|
||||||
|
|
||||||
|
@ -229,9 +229,9 @@ public:
|
||||||
auto text_file = path_helper::get_data_directory("/reader/sharedStrings.xml");
|
auto text_file = path_helper::get_data_directory("/reader/sharedStrings.xml");
|
||||||
f.write(text_file);
|
f.write(text_file);
|
||||||
f.write(text_file, "sharedStrings2.xml");
|
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())
|
for(auto &info : f2.infolist())
|
||||||
{
|
{
|
||||||
|
@ -258,9 +258,9 @@ public:
|
||||||
info.filename = "b.txt";
|
info.filename = "b.txt";
|
||||||
info.date_time.year = 2014;
|
info.date_time.year = 2014;
|
||||||
f.writestr(info, "b\nb");
|
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("a.txt") == "a\na");
|
||||||
TS_ASSERT(f2.read(f2.getinfo("b.txt")) == "b\nb");
|
TS_ASSERT(f2.read(f2.getinfo("b.txt")) == "b\nb");
|
||||||
|
|
||||||
|
@ -273,9 +273,9 @@ public:
|
||||||
|
|
||||||
xlnt::zip_file f;
|
xlnt::zip_file f;
|
||||||
f.comment = "comment";
|
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");
|
TS_ASSERT(f2.comment == "comment");
|
||||||
|
|
||||||
xlnt::zip_file f3;
|
xlnt::zip_file f3;
|
||||||
|
@ -305,7 +305,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TemporaryFile temp_file;
|
temporary_file temp_file;
|
||||||
std::string existing_file;
|
std::string existing_file;
|
||||||
std::string expected_content_types_string;
|
std::string expected_content_types_string;
|
||||||
std::string expected_atxt_string;
|
std::string expected_atxt_string;
|
||||||
|
|
|
@ -217,11 +217,11 @@ public:
|
||||||
xlnt::workbook book;
|
xlnt::workbook book;
|
||||||
auto sheet = book.get_active_sheet();
|
auto sheet = book.get_active_sheet();
|
||||||
sheet.get_cell("A1").set_value(today);
|
sheet.get_cell("A1").set_value(today);
|
||||||
TemporaryFile temp_file;
|
temporary_file temp_file;
|
||||||
book.save(temp_file.GetFilename());
|
book.save(temp_file.get_filename());
|
||||||
|
|
||||||
xlnt::workbook test_book;
|
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();
|
auto test_sheet = test_book.get_active_sheet();
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(test_sheet.get_cell("A1").get_value<xlnt::datetime>(), today);
|
TS_ASSERT_EQUALS(test_sheet.get_cell("A1").get_value<xlnt::datetime>(), today);
|
||||||
|
@ -234,11 +234,11 @@ public:
|
||||||
xlnt::workbook book;
|
xlnt::workbook book;
|
||||||
auto sheet = book.get_active_sheet();
|
auto sheet = book.get_active_sheet();
|
||||||
sheet.get_cell("A1").set_value(float_value);
|
sheet.get_cell("A1").set_value(float_value);
|
||||||
TemporaryFile temp_file;
|
temporary_file temp_file;
|
||||||
book.save(temp_file.GetFilename());
|
book.save(temp_file.get_filename());
|
||||||
|
|
||||||
xlnt::workbook test_book;
|
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();
|
auto test_sheet = test_book.get_active_sheet();
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(test_sheet.get_cell("A1").get_value<long double>(), float_value);
|
TS_ASSERT_EQUALS(test_sheet.get_cell("A1").get_value<long double>(), float_value);
|
||||||
|
|
|
@ -21,16 +21,16 @@ public:
|
||||||
wbk.get_active_sheet().get_cell("A2").set_value("xlnt");
|
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_value(88);
|
||||||
wbk.get_active_sheet().get_cell("B5").set_number_format(xlnt::number_format::percentage_00());
|
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()));
|
TS_ASSERT(!path_helper::file_exists(temp_file.get_filename()));
|
||||||
wb_.save(temp_file.GetFilename());
|
wb_.save(temp_file.get_filename());
|
||||||
TS_ASSERT(path_helper::file_exists(temp_file.GetFilename()));
|
TS_ASSERT(path_helper::file_exists(temp_file.get_filename()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_write_virtual_workbook()
|
void test_write_virtual_workbook()
|
||||||
|
@ -293,6 +293,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TemporaryFile temp_file;
|
temporary_file temp_file;
|
||||||
xlnt::workbook wb_;
|
xlnt::workbook wb_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,12 +73,12 @@ public:
|
||||||
void test_write_empty_workbook()
|
void test_write_empty_workbook()
|
||||||
{
|
{
|
||||||
xlnt::workbook wb;
|
xlnt::workbook wb;
|
||||||
TemporaryFile file;
|
temporary_file file;
|
||||||
|
|
||||||
xlnt::excel_serializer serializer(wb);
|
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()
|
void test_write_virtual_workbook()
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
#include "PathHelper.h"
|
#include "PathHelper.h"
|
||||||
|
|
||||||
class TemporaryDirectory
|
class temporary_directory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string CreateTemporaryFilename()
|
static std::string create()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::array<TCHAR, MAX_PATH> buffer;
|
std::array<TCHAR, MAX_PATH> buffer;
|
||||||
|
@ -25,23 +25,23 @@ public:
|
||||||
throw std::runtime_error("GetTempPath failed");
|
throw std::runtime_error("GetTempPath failed");
|
||||||
}
|
}
|
||||||
std::string directory(buffer.begin(), buffer.begin() + result);
|
std::string directory(buffer.begin(), buffer.begin() + result);
|
||||||
return PathHelper::WindowsToUniversalPath(directory + "xlnt");
|
return path_helper::windows_to_universal_path(directory + "xlnt");
|
||||||
#else
|
#else
|
||||||
return "/tmp/xlsx";
|
return "/tmp/xlsx";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TemporaryDirectory() : filename_(CreateTemporaryFilename())
|
temporary_directory() : filename_(create())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~TemporaryDirectory()
|
~temporary_directory()
|
||||||
{
|
{
|
||||||
remove(filename_.c_str());
|
remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetFilename() const { return filename_; }
|
std::string get_filename() const { return filename_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string filename_;
|
const std::string filename_;
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
#include <detail/include_windows.hpp>
|
#include <detail/include_windows.hpp>
|
||||||
#include <helpers/path_helper.hpp>
|
#include <helpers/path_helper.hpp>
|
||||||
|
|
||||||
class TemporaryFile
|
class temporary_file
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string CreateTemporaryFilename()
|
static std::string create()
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
std::array<TCHAR, MAX_PATH> buffer;
|
std::array<TCHAR, MAX_PATH> buffer;
|
||||||
|
@ -27,27 +27,26 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string directory(buffer.begin(), buffer.begin() + result);
|
std::string directory(buffer.begin(), buffer.begin() + result);
|
||||||
|
return path_helper::windows_to_universal_path(directory + "xlnt.xlsx");
|
||||||
return PathHelper::WindowsToUniversalPath(directory + "xlnt.xlsx");
|
|
||||||
#else
|
#else
|
||||||
return "/tmp/xlnt.xlsx";
|
return "/tmp/xlnt.xlsx";
|
||||||
#endif
|
#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());
|
std::remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~TemporaryFile()
|
~temporary_file()
|
||||||
{
|
{
|
||||||
std::remove(filename_.c_str());
|
std::remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetFilename() const { return filename_; }
|
std::string get_filename() const { return filename_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string filename_;
|
const std::string filename_;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user